Skip to content

Commit 02bf773

Browse files
author
Yuri Pourre
committed
Fix loading bones
1 parent cdde35a commit 02bf773

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

editor/src/electron/assimp/assimpjs-worker.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,26 @@ import { workerData, parentPort } from "worker_threads";
33

44
const assimpjs = require("assimpjs")();
55

6+
// Assimp post-processing flags constants
7+
const AssimpPostProcessFlags = {
8+
aiProcess_Triangulate: 0x8,
9+
aiProcess_FlipUVs: 0x800000,
10+
aiProcess_GenNormals: 0x20,
11+
aiProcess_LimitBoneWeights: 0x200000,
12+
} as const;
13+
614
assimpjs.then((ajs) => {
715
const fileList = new ajs.FileList();
816
fileList.AddFile(basename(workerData.absolutePath), new Uint8Array(workerData.content));
917

10-
const result = ajs.ConvertFileList(fileList, "assjson");
18+
// Use processing flags to preserve skeletal data
19+
const postProcessFlags =
20+
AssimpPostProcessFlags.aiProcess_Triangulate |
21+
AssimpPostProcessFlags.aiProcess_FlipUVs |
22+
AssimpPostProcessFlags.aiProcess_GenNormals |
23+
AssimpPostProcessFlags.aiProcess_LimitBoneWeights;
24+
const result = ajs.ConvertFileList(fileList, "assjson", postProcessFlags);
25+
1126
if (!result.IsSuccess() || result.FileCount() === 0) {
1227
console.log(result.GetErrorCode());
1328
return parentPort?.postMessage(null);

editor/src/loader/animation.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,12 @@ function getNodeFromContainerByName(container: AssetContainer, name: string): Tr
9595
return mesh;
9696
}
9797

98+
for (const skeleton of container.skeletons) {
99+
const bone = skeleton.bones.find((b) => b.name === name);
100+
if (bone) {
101+
return bone;
102+
}
103+
}
104+
98105
return null;
99106
}

editor/src/loader/mesh.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export function parseMesh(runtime: AssimpJSRuntime, data: IAssimpJSNodeData): Me
6161
}
6262

6363
// Bones
64-
const hasBones = !meshes.find((m) => !m.bones);
64+
const hasBones = meshes.some((m) => m.bones && m.bones.length > 0);
6565

6666
if (hasBones) {
6767
const skeleton = new Skeleton(data.name, Tools.RandomId(), runtime.scene);

0 commit comments

Comments
 (0)