-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correction step to add root bone if missing from skeleton (#25)
- Loading branch information
1 parent
ea1fbcd
commit bd30712
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
tools/gltf-avatar-exporter/src/scene/correction-steps/connectRoot.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters