mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-12-05 07:43:49 +01:00
Merge branch 'main' into data-driven
This commit is contained in:
7 files changed
+62
-12
No files matched your search
@@ -1,5 +1,3 @@
|
|||||||
precision mediump float;
|
|
||||||
|
|
||||||
varying vec3 vNormal;
|
varying vec3 vNormal;
|
||||||
varying vec3 vViewPosition;
|
varying vec3 vViewPosition;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
precision mediump float;
|
|
||||||
|
|
||||||
varying vec3 vNormal;
|
varying vec3 vNormal;
|
||||||
varying vec3 vViewPosition;
|
varying vec3 vViewPosition;
|
||||||
varying float vThickness;
|
varying float vThickness;
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
precision mediump float;
|
|
||||||
|
|
||||||
uniform float thickness;
|
uniform float thickness;
|
||||||
uniform float penetration;
|
uniform float penetration;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
precision mediump float;
|
|
||||||
|
|
||||||
#include <batching_pars_vertex>
|
#include <batching_pars_vertex>
|
||||||
#include <clipping_planes_pars_vertex>
|
#include <clipping_planes_pars_vertex>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
precision mediump float;
|
|
||||||
|
|
||||||
varying vec3 vNormal;
|
varying vec3 vNormal;
|
||||||
varying vec3 vViewPosition;
|
varying vec3 vViewPosition;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
precision mediump float;
|
|
||||||
|
|
||||||
varying vec3 vNormal;
|
varying vec3 vNormal;
|
||||||
varying vec3 vViewPosition;
|
varying vec3 vViewPosition;
|
||||||
varying float vThickness;
|
varying float vThickness;
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ import {
|
|||||||
Node,
|
Node,
|
||||||
NodeIO,
|
NodeIO,
|
||||||
Scene,
|
Scene,
|
||||||
|
type Accessor,
|
||||||
|
type Primitive,
|
||||||
|
type TypedArray,
|
||||||
} from "@gltf-transform/core";
|
} from "@gltf-transform/core";
|
||||||
import { ALL_EXTENSIONS } from "@gltf-transform/extensions";
|
import { ALL_EXTENSIONS } from "@gltf-transform/extensions";
|
||||||
import { dedup, prune } from "@gltf-transform/functions";
|
import { dedup, prune } from "@gltf-transform/functions";
|
||||||
@@ -137,6 +140,65 @@ export async function extractModel(
|
|||||||
|
|
||||||
await document.transform(prune({ keepAttributes: true }), dedup());
|
await document.transform(prune({ keepAttributes: true }), dedup());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The website batches a model's primitives by material, and a batch needs
|
||||||
|
* every primitive to have the same attributes. A primitive missing one that
|
||||||
|
* another of its material has (say TEXCOORD_1) gets it zero-filled, which is
|
||||||
|
* what the shader read for the missing attribute anyway. Parts aren't
|
||||||
|
* batched so their bones can animate.
|
||||||
|
*/
|
||||||
|
if (!isPart) {
|
||||||
|
const groups = new Map<Material | null, Primitive[]>();
|
||||||
|
|
||||||
|
for (const mesh of document.getRoot().listMeshes()) {
|
||||||
|
for (const primitive of mesh.listPrimitives()) {
|
||||||
|
const material = primitive.getMaterial();
|
||||||
|
let group = groups.get(material);
|
||||||
|
|
||||||
|
if (!group) {
|
||||||
|
group = [];
|
||||||
|
groups.set(material, group);
|
||||||
|
}
|
||||||
|
|
||||||
|
group.push(primitive);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const primitives of groups.values()) {
|
||||||
|
const references = new Map<string, Accessor>();
|
||||||
|
|
||||||
|
for (const primitive of primitives) {
|
||||||
|
for (const name of primitive.listSemantics()) {
|
||||||
|
if (!references.has(name)) {
|
||||||
|
references.set(name, primitive.getAttribute(name)!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const primitive of primitives) {
|
||||||
|
const count = primitive.getAttribute("POSITION")!.getCount();
|
||||||
|
|
||||||
|
for (const [name, reference] of references) {
|
||||||
|
if (primitive.getAttribute(name) !== null) continue;
|
||||||
|
|
||||||
|
const Array = reference.getArray()!.constructor as new (
|
||||||
|
length: number,
|
||||||
|
) => TypedArray;
|
||||||
|
|
||||||
|
primitive.setAttribute(
|
||||||
|
name,
|
||||||
|
document
|
||||||
|
.createAccessor(name)
|
||||||
|
.setType(reference.getType())
|
||||||
|
.setNormalized(reference.getNormalized())
|
||||||
|
.setArray(new Array(count * reference.getElementSize()))
|
||||||
|
.setBuffer(buffer),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return document;
|
return document;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user