Skip to content

Commit 749fe5d

Browse files
Julien Moreau-Mathisjulien-moreau
authored andcommitted
fix: concat UVs and offset indices in case of multiple meshes per node
1 parent 4d921a9 commit 749fe5d

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

editor/src/loader/mesh.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,34 @@ export function parseMesh(runtime: AssimpJSRuntime, data: IAssimpJSNodeData): Me
2929
const textureCoordsLength = m.texturecoords?.length ?? 0;
3030
for (let i = 0; i < textureCoordsLength; ++i) {
3131
const uvs = i > 0 ? `uvs${i + 1}` : "uvs";
32-
vertexData[uvs] = m.texturecoords![i];
32+
if (vertexData[uvs]) {
33+
vertexData[uvs] = vertexData[uvs].concat(m.texturecoords![i]);
34+
} else {
35+
vertexData[uvs] = m.texturecoords![i];
36+
}
3337
}
3438
});
3539

3640
// Indices
3741
const indices = meshes.map((m) => m.faces.flat());
3842

3943
let offset = 0;
44+
let indicesOffset = 0;
4045
indices.forEach((i, index) => {
4146
const verticesStart = offset;
4247
const verticesCount = i.length;
4348

4449
const indicesStart = offset;
4550
const indicesCount = i.length;
4651

52+
if (index > 0) {
53+
indicesOffset += meshes[index - 1].vertices.length / 3;
54+
55+
for (let j = 0, len = i.length; j < len; ++j) {
56+
i[j] += indicesOffset;
57+
}
58+
}
59+
4760
subMeshes.push(new SubMesh(index, verticesStart, verticesCount, indicesStart, indicesCount, mesh, mesh, false, true));
4861

4962
offset += i.length;

0 commit comments

Comments
 (0)