mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +02:00
fix: vec4 tangents
This commit is contained in:
1 parent
75bacd5586
commit
7e0fb82905
2 files changed
+42
-40
No files matched your search
@@ -518,9 +518,9 @@ if (allTargets || targets?.includes('tankModels')) {
|
|||||||
// if (id !== 4417) continue; // amx m4 mle
|
// if (id !== 4417) continue; // amx m4 mle
|
||||||
// if (id !== 7297) continue; // 60tp
|
// if (id !== 7297) continue; // 60tp
|
||||||
// if (id !== 1) continue; // t-34
|
// if (id !== 1) continue; // t-34
|
||||||
// if (id !== 6753) continue; // type 71
|
if (id !== 6753) continue; // type 71
|
||||||
// if (id !== 5137) continue; // tiger ii
|
// if (id !== 5137) continue; // tiger ii
|
||||||
if (id !== 6225) continue; // fv215b
|
// if (id !== 6225) continue; // fv215b
|
||||||
|
|
||||||
console.log(`Building model ${id} @ ${nation}/${tankIndex}`);
|
console.log(`Building model ${id} @ ${nation}/${tankIndex}`);
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,12 @@ const vertexAttributeGLTFName: Partial<Record<VertexAttribute, string>> = {
|
|||||||
[VertexAttribute.JOINTWEIGHT]: 'WEIGHT_0',
|
[VertexAttribute.JOINTWEIGHT]: 'WEIGHT_0',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const vertexAttributeGltfVectorSizes = {
|
||||||
|
...vertexAttributeVectorSizes,
|
||||||
|
|
||||||
|
[VertexAttribute.TANGENT]: 4,
|
||||||
|
} as const;
|
||||||
|
|
||||||
export async function extractModel(
|
export async function extractModel(
|
||||||
data: string,
|
data: string,
|
||||||
path: string,
|
path: string,
|
||||||
@@ -234,56 +240,52 @@ export async function extractModel(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const indexedVertexAttributes: VertexAttribute[] = [];
|
|
||||||
const unpackedVertices: Partial<Record<VertexAttribute, number[]>> =
|
|
||||||
{};
|
|
||||||
|
|
||||||
polygonGroup.vertices.forEach((vertex) => {
|
|
||||||
vertex.map((vertexItem) => {
|
|
||||||
if (!(vertexItem.attribute in unpackedVertices)) {
|
|
||||||
unpackedVertices[vertexItem.attribute] = [];
|
|
||||||
indexedVertexAttributes.push(vertexItem.attribute);
|
|
||||||
}
|
|
||||||
|
|
||||||
unpackedVertices[vertexItem.attribute]!.push(
|
|
||||||
...vertexItem.value,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
const indexAccessor = document
|
|
||||||
.createAccessor()
|
|
||||||
.setType('SCALAR')
|
|
||||||
.setArray(new Uint16Array(polygonGroup.indices))
|
|
||||||
.setBuffer(buffer);
|
|
||||||
const material = materials.get(batch['rb.nmatname']);
|
const material = materials.get(batch['rb.nmatname']);
|
||||||
|
|
||||||
if (!(material instanceof Material)) {
|
if (!(material instanceof Material)) {
|
||||||
throw new Error(`Material ${batch['rb.nmatname']} is unresolved`);
|
throw new Error(`Material ${batch['rb.nmatname']} is unresolved`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const indicesAccessor = document
|
||||||
|
.createAccessor()
|
||||||
|
.setType('SCALAR')
|
||||||
|
.setArray(new Uint16Array(polygonGroup.indices))
|
||||||
|
.setBuffer(buffer);
|
||||||
const primitive = document
|
const primitive = document
|
||||||
.createPrimitive()
|
.createPrimitive()
|
||||||
.setIndices(indexAccessor)
|
.setIndices(indicesAccessor)
|
||||||
.setMaterial(material);
|
.setMaterial(material);
|
||||||
|
const attributes: Partial<Record<VertexAttribute, number[][]>> = {};
|
||||||
|
const indexedAttributes: VertexAttribute[] = [];
|
||||||
|
|
||||||
indexedVertexAttributes.forEach((attribute) => {
|
polygonGroup.vertices.forEach((vertex) => {
|
||||||
if (!(attribute in vertexAttributeGLTFName)) return;
|
vertex.forEach(({ attribute, value }) => {
|
||||||
|
if (attributes[attribute] === undefined) {
|
||||||
|
attributes[attribute] = [];
|
||||||
|
indexedAttributes.push(attribute);
|
||||||
|
}
|
||||||
|
|
||||||
const vertexSize = vertexAttributeVectorSizes[attribute];
|
attributes[attribute]!.push(value);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
if (
|
if (indexedAttributes.includes(VertexAttribute.TANGENT)) {
|
||||||
!primitive.getAttribute(vertexAttributeGLTFName[attribute]!)
|
attributes[VertexAttribute.TANGENT] = attributes[
|
||||||
) {
|
VertexAttribute.TANGENT
|
||||||
primitive.setAttribute(
|
]!.map((tangent) => [...tangent, 1]);
|
||||||
vertexAttributeGLTFName[attribute]!,
|
}
|
||||||
document
|
|
||||||
.createAccessor()
|
indexedAttributes.forEach((attribute) => {
|
||||||
.setType(vertexSize === 1 ? 'SCALAR' : `VEC${vertexSize}`)
|
const name = vertexAttributeGLTFName[attribute];
|
||||||
.setArray(new Float32Array(unpackedVertices[attribute]!))
|
if (!name) return; // no equivalent GLTF attribute
|
||||||
.setBuffer(buffer),
|
const vertexSize = vertexAttributeGltfVectorSizes[attribute];
|
||||||
);
|
|
||||||
}
|
const attributeAccessor = document
|
||||||
|
.createAccessor(name)
|
||||||
|
.setType(vertexSize === 1 ? 'SCALAR' : `VEC${vertexSize}`)
|
||||||
|
.setArray(new Float32Array(attributes[attribute]!.flat()))
|
||||||
|
.setBuffer(buffer);
|
||||||
|
primitive.setAttribute(name, attributeAccessor);
|
||||||
});
|
});
|
||||||
|
|
||||||
const mesh = document
|
const mesh = document
|
||||||
|
|||||||
Reference in new issue
Block a user