Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Load in Quaternius skeleton and load animations. Ignore root bone with skinning

Scott Petrovic474438bd81d7
diff --git a/src/index.html b/src/index.html
index 5901d55..2a4a7f0 100644
--- a/src/index.html
+++ b/src/index.html
@@ -78,9 +78,8 @@
<label>Skeleton Type to use:</label>
<select id="skeleton-selection">
- <option value="bipedal-simple">Simplified Human</option>
+ <option value="human">Human</option>
<option value="quadraped">4 Leg Creature</option>
- <option value="bipedal-full">Mixamo Human</option>
</select>
diff --git a/src/lib/enums/SkeletonType.ts b/src/lib/enums/SkeletonType.ts
index 9e7d75e..3be8bf3 100644
--- a/src/lib/enums/SkeletonType.ts
+++ b/src/lib/enums/SkeletonType.ts
@@ -2,6 +2,5 @@
// the file names for the skeleton types are associated with the const
export enum SkeletonType {
Quadraped = 'skeletons/skeleton-quadraped.glb',
- BipedalSimple = 'skeletons/skeleton-bipedal-simple.glb',
- BipedalFull = 'skeletons/skeleton-mecanim-full.glb'
+ Human = 'skeletons/human-skeleton.glb'
}
diff --git a/src/lib/processes/StepAnimationsListing.ts b/src/lib/processes/StepAnimationsListing.ts
index 89ae267..d779948 100644
--- a/src/lib/processes/StepAnimationsListing.ts
+++ b/src/lib/processes/StepAnimationsListing.ts
@@ -66,15 +66,12 @@ export class StepAnimationsListing extends EventTarget {
let animations_to_load_filepath: string = ''
switch (skeleton_type) {
- case SkeletonType.BipedalSimple:
- animations_to_load_filepath = 'animations/character-simple-multiple.glb'
+ case SkeletonType.Human:
+ animations_to_load_filepath = 'animations/human-base-animations.glb'
break
case SkeletonType.Quadraped:
animations_to_load_filepath = 'animations/quad-creature-animations.glb'
break
- case SkeletonType.BipedalFull:
- animations_to_load_filepath = 'animations/animations-mixamo-default.glb'
- break
}
this.gltf_animation_loader = new GLTFLoader()
@@ -85,9 +82,7 @@ export class StepAnimationsListing extends EventTarget {
this.animation_clips_loaded = this.deep_clone_animation_clips(gltf.animations)
// only keep position tracks
- this.remove_position_tracks(this.animation_clips_loaded)
-
- console.log(this.animation_clips_loaded)
+ this.remove_position_tracks(this.animation_clips_loaded, true)
// create user interface with all available animation clips
this.ui.build_animation_clip_ui(this.animation_clips_loaded)
@@ -100,10 +95,19 @@ export class StepAnimationsListing extends EventTarget {
}
// mutates the animation clips passed in and only keeps rotation/quaternion tracks
- private remove_position_tracks (animation_clips: AnimationClip[]): void {
+ // also removes scale tracks
+ private remove_position_tracks (animation_clips: AnimationClip[], preserve_root_position: boolean = false): void {
animation_clips.forEach((animation_clip: AnimationClip) => {
- const rotation_tracks = animation_clip.tracks.filter(x => x.name.includes('quaternion'))
- animation_clip.tracks = rotation_tracks
+ // remove all position nodes except root
+ let rotation_tracks: KeyframeTrack[] = []
+ if (preserve_root_position) {
+ rotation_tracks = animation_clip.tracks.filter((x: KeyframeTrack) => x.name.includes('quaternion') || x.name.includes('root.position'))
+ } else {
+ rotation_tracks = animation_clip.tracks.filter((x: KeyframeTrack) => x.name.includes('quaternion'))
+ }
+
+ animation_clip.tracks = rotation_tracks // update track data
+ //console.log(animation_clip.tracks)
})
}
@@ -322,11 +326,11 @@ export class StepAnimationsListing extends EventTarget {
const cloned_track: AnimationClip = this.deep_clone_animation_clips([animation_clip])[0]
// only keep the rotation tracks...and the root bone position track
- const rotation_tracks = cloned_track.tracks.filter(x => x.name.includes('quaternion'))
+ const rotation_tracks = cloned_track.tracks.filter((x: KeyframeTrack) => x.name.includes('quaternion'))
cloned_track.tracks = rotation_tracks
// keep the root bone position track
- const root_position_track = animation_clip.tracks.filter(x => x.name === 'root.position')[0]
+ const root_position_track = animation_clip.tracks.filter((x: KeyframeTrack) => x.name === 'root.position')[0]
if (root_position_track !== undefined) {
cloned_track.tracks.push(root_position_track)
@@ -398,7 +402,7 @@ export class StepAnimationsListing extends EventTarget {
// with the simple skeleton, there are many bones that are not used from the full mixamo animation
// remove unmapped bones since they won't be used
if (this.skeleton_type === SkeletonType.BipedalSimple) {
- animation_clip.tracks = animation_clip.tracks.filter(x => !x.name.includes('mixamorig'))
+ animation_clip.tracks = animation_clip.tracks.filter((x: KeyframeTrack) => !x.name.includes('mixamorig'))
}
})
}
diff --git a/src/lib/processes/StepLoadSkeleton.ts b/src/lib/processes/StepLoadSkeleton.ts
index 620f746..50d4037 100644
--- a/src/lib/processes/StepLoadSkeleton.ts
+++ b/src/lib/processes/StepLoadSkeleton.ts
@@ -55,22 +55,21 @@ export class StepLoadSkeleton extends EventTarget {
case 'quadraped':
this.skeleton_t = SkeletonType.Quadraped
break
- case 'bipedal-simple':
- this.skeleton_t = SkeletonType.BipedalSimple
- break
- case 'bipedal-full':
- this.skeleton_t = SkeletonType.BipedalFull
+ case 'human':
+ this.skeleton_t = SkeletonType.Human
break
}
// load skeleton from GLB file
+ console.log('trying to load skeleton', this.skeleton_t)
this.loader.load(this.skeleton_t, (gltf) => {
// traverse scene and find first bone object
// we will go to the parent and mark that as the original armature
let armature_found = false
let original_armature: Object3D = new Object3D()
- gltf.scene.traverse((child) => {
+
+ gltf.scene.traverse((child: Object3D) => {
if (child.type === 'Bone' && !armature_found) {
armature_found = true
@@ -82,6 +81,9 @@ export class StepLoadSkeleton extends EventTarget {
}
})
+ console.log('is armature found?', armature_found)
+ console.log(gltf)
+
this.loaded_armature = original_armature.clone()
this.loaded_armature.name = 'Loaded Armature'
diff --git a/src/lib/solvers/BoneWeightsByDistance.ts b/src/lib/solvers/BoneWeightsByDistance.ts
index 164b079..f3aedae 100644
--- a/src/lib/solvers/BoneWeightsByDistance.ts
+++ b/src/lib/solvers/BoneWeightsByDistance.ts
@@ -11,7 +11,7 @@ export default class BoneWeightsByDistance implements IAutoSkinSolver {
private show_debug: boolean = false
private bone_idx_test: number = -1
private debugging_scene_object: Object3D = new Object3D()
- private skeleton_type: SkeletonType = SkeletonType.BipedalSimple
+ private skeleton_type: SkeletonType | null = null
constructor (bone_hier: Object3D, skeleton_type: SkeletonType) {
this.set_skeleton_type(skeleton_type)
@@ -51,6 +51,13 @@ export default class BoneWeightsByDistance implements IAutoSkinSolver {
let closest_bone_index: number = 0
this.bones_master_data.forEach((bone, idx) => {
+ // our human skeleton has a root controller bone that isn't in the mesh. Don't assign weights to this?
+ if (this.skeleton_type === SkeletonType.Human) {
+ if (bone.bone_object.name === 'root') {
+ return
+ }
+ }
+
const distance: number = Utility.world_position_from_object(bone.bone_object).distanceTo(vertex_position)
if (distance < closest_bone_distance) {
diff --git a/static/animations/character-simple-multiple.glb b/static/animations/character-simple-multiple.glb
deleted file mode 100644
index 30afde8..0000000
Binary files a/static/animations/character-simple-multiple.glb and /dev/null differ
diff --git a/static/animations/human-base-animations.glb b/static/animations/human-base-animations.glb
new file mode 100644
index 0000000..8ce6762
Binary files /dev/null and b/static/animations/human-base-animations.glb differ
diff --git a/static/skeletons/human-skeleton.glb b/static/skeletons/human-skeleton.glb
new file mode 100644
index 0000000..53b15a1
Binary files /dev/null and b/static/skeletons/human-skeleton.glb differ
diff --git a/static/skeletons/skeleton-bipedal-simple.glb b/static/skeletons/skeleton-bipedal-simple.glb
deleted file mode 100644
index 45e2553..0000000
Binary files a/static/skeletons/skeleton-bipedal-simple.glb and /dev/null differ
diff --git a/static/skeletons/skeleton-mecanim-full.glb b/static/skeletons/skeleton-mecanim-full.glb
deleted file mode 100644
index 800b6d8..0000000
Binary files a/static/skeletons/skeleton-mecanim-full.glb and /dev/null differ