Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Get new snake rig imported in

Scott Petrovicd433fe5d6b65
diff --git a/src/lib/processes/animations-listing/AnimationUtility.ts b/src/lib/processes/animations-listing/AnimationUtility.ts
index 54deaaf..62b9063 100644
--- a/src/lib/processes/animations-listing/AnimationUtility.ts
+++ b/src/lib/processes/animations-listing/AnimationUtility.ts
@@ -46,12 +46,14 @@ export class AnimationUtility {
rotation_tracks = animation_clip.tracks
.filter((x: KeyframeTrack) => x.name.includes('quaternion') ||
x.name.toLowerCase().includes('hips.position') ||
+ x.name.toLowerCase().includes('head.position') ||
x.name.toLowerCase().includes('pelvis.position') ||
x.name.toLowerCase().includes('root.position'))
} else {
rotation_tracks = animation_clip.tracks
.filter((x: KeyframeTrack) => x.name.includes('quaternion') ||
x.name.toLowerCase().includes('hips.position') ||
+ x.name.toLowerCase().includes('head.position') ||
x.name.toLowerCase().includes('pelvis.position'))
}
diff --git a/src/lib/solvers/WeightCalculator.ts b/src/lib/solvers/WeightCalculator.ts
index 4052f00..6f1fc27 100644
--- a/src/lib/solvers/WeightCalculator.ts
+++ b/src/lib/solvers/WeightCalculator.ts
@@ -103,13 +103,23 @@ export class WeightCalculator {
// every vertex checks to see if it is below the hips area,
// so do this calculation once and cache it for the lookup later
private calculate_distance_to_bottom_of_hip (): number {
- const hip_bone_object: Bone | undefined = this.bones.find(b => {
+ let hip_bone_object: Bone | undefined = this.bones.find(b => {
const name = b.name.toLowerCase()
return name.includes('hips') || name.includes('pelvis')
})
if (hip_bone_object === undefined) {
- throw new Error('Hip bone not found')
+
+
+ // if there are no hips bones, we are going to assume it is a rig
+ // that doesnt' have hips like a snake. Let's check the head
+ // that will be used for the distance calculation instead and hope for the best
+ hip_bone_object = this.bones.find(b => b.name.toLowerCase().includes('head'))
+ if (hip_bone_object === undefined) {
+ throw new Error('Hip bone (or head bone) not found')
+ }
+
}
+
const intesection_point: Vector3 | null = this.cast_intersection_ray_down_from_bone(hip_bone_object)
// get the distance from the bone point to the intersection point
diff --git a/static/animations/snake-animations.glb b/static/animations/snake-animations.glb
index 024447d..25c0c79 100644
Binary files a/static/animations/snake-animations.glb and b/static/animations/snake-animations.glb differ
diff --git a/static/models/model-snake.glb b/static/models/model-snake.glb
index ab8fdbb..c334e06 100644
Binary files a/static/models/model-snake.glb and b/static/models/model-snake.glb differ
diff --git a/static/rigs/rig-snake.glb b/static/rigs/rig-snake.glb
index 1e237cc..6a10578 100644
Binary files a/static/rigs/rig-snake.glb and b/static/rigs/rig-snake.glb differ