Skip to content

Commit

Permalink
Correction step to add root bone if missing from skeleton (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusLongmuir authored Dec 7, 2023
1 parent ea1fbcd commit bd30712
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import * as THREE from "three";
import { Group } from "three";

import { LogMessage, Step } from "./types";

export const connectRootCorrectionStep: Step = {
name: "connectRoot",
action: (group: Group) => {
const rootBone = group.getObjectByName("root") as THREE.Bone;
if (!rootBone) {
return {
didApply: false,
topLevelMessage: {
level: "error",
message: "Could not find root bone. Cannot connect root.",
},
};
}
const logs: Array<LogMessage> = [];
group.traverse((child) => {
const asSkinnedMesh = child as THREE.SkinnedMesh;
if (asSkinnedMesh.isSkinnedMesh) {
const skeleton = asSkinnedMesh.skeleton;
if (skeleton.bones.indexOf(rootBone) === -1) {
skeleton.bones.push(rootBone);
logs.push({
level: "info",
message: `Added root bone to ${asSkinnedMesh.name}.`,
});
}
}
});

if (logs.length === 0) {
return {
didApply: false,
topLevelMessage: {
level: "info",
message: "No skinned meshes with missing roots to fix.",
},
logs,
};
}
return {
didApply: true,
topLevelMessage: {
level: "info",
message: "Applied root to skinned meshes.",
},
logs,
};
},
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { boneDedupingCorrectionStep } from "./boneDeduping";
import { connectRootCorrectionStep } from "./connectRoot";
import { fixBonesScaleCorrectionStep } from "./fixBonesScale";
import { fixMeshScaleCorrectionStep } from "./fixMeshScale";
import { levelOfDetailDedupingCorrectionStep } from "./lodDeduping";
Expand All @@ -20,6 +21,7 @@ export const correctionSteps = [
fixMeshScaleCorrectionStep,
fixBonesScaleCorrectionStep,
boneDedupingCorrectionStep,
connectRootCorrectionStep,
rotateRootCorrectionStep,
rotatePelvisCorrectionStep,
removeVertexColorsCorrectionStep,
Expand Down

0 comments on commit bd30712

Please sign in to comment.