Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Fix loading animation previews if we change skeletons later using navigation

Scott Petrovicba62c3029bcf
diff --git a/src/lib/processes/animations-listing/StepAnimationsListing.ts b/src/lib/processes/animations-listing/StepAnimationsListing.ts
index a3f0d0b..d6f8316 100644
--- a/src/lib/processes/animations-listing/StepAnimationsListing.ts
+++ b/src/lib/processes/animations-listing/StepAnimationsListing.ts
@@ -82,7 +82,7 @@ export class StepAnimationsListing extends EventTarget {
this.theme_manager = theme_manager
}
- public begin (): void {
+ public begin (skeleton_type: SkeletonType): void {
if (this.ui.dom_current_step_index != null) {
this.ui.dom_current_step_index.innerHTML = '4'
}
@@ -101,6 +101,8 @@ export class StepAnimationsListing extends EventTarget {
this.reset_step_data()
+ this.skeleton_type = skeleton_type
+
// if we are navigating back to this step, we don't want to add the event listeners again
if (!this._added_event_listeners) {
this.add_event_listeners()
@@ -140,12 +142,11 @@ export class StepAnimationsListing extends EventTarget {
return this.animation_clips_loaded.map(clip => clip.display_animation_clip)
}
- public load_and_apply_default_animation_to_skinned_mesh (final_skinned_meshes: SkinnedMesh[], skeleton_type: SkeletonType): void {
+ public load_and_apply_default_animation_to_skinned_mesh (final_skinned_meshes: SkinnedMesh[]): void {
this.skinned_meshes_to_animate = final_skinned_meshes
- this.skeleton_type = skeleton_type
let animations_to_load_filepaths: string[] = []
- switch (skeleton_type) {
+ switch (this.skeleton_type) {
case SkeletonType.Human:
animations_to_load_filepaths = ['animations/human-base-animations.glb', 'animations/human-addon-animations.glb']
break
@@ -207,8 +208,7 @@ export class StepAnimationsListing extends EventTarget {
// create user interface with all available animation clips
this.build_animation_clip_ui(
this.animation_clips_loaded.map(clip => clip.display_animation_clip),
- this.theme_manager,
- this.skeleton_type,
+ this.theme_manager
)
// add event listener to listem for checkbox changes when we change
@@ -403,11 +403,10 @@ export class StepAnimationsListing extends EventTarget {
this.has_added_event_listeners = true
}
- public build_animation_clip_ui (animation_clips_to_load: AnimationClip[], theme_manager: ThemeManager, skeleton_type: SkeletonType): void {
+ public build_animation_clip_ui (animation_clips_to_load: AnimationClip[], theme_manager: ThemeManager): void {
// Initialize AnimationSearch if not already done
- if (this.animation_search === null) {
- this.animation_search = new AnimationSearch('animation-filter', 'animations-items', theme_manager, skeleton_type)
- }
+ // we could switch skeleton types using navigation, so need to re-create in case this happens
+ this.animation_search = new AnimationSearch('animation-filter', 'animations-items', theme_manager, this.skeleton_type)
// Use the animation search class to handle the UI
this.animation_search.initialize_animations(animation_clips_to_load)
diff --git a/src/script.ts b/src/script.ts
index 838e55e..e0ce4ab 100644
--- a/src/script.ts
+++ b/src/script.ts
@@ -282,13 +282,13 @@ export class Bootstrap {
break
case ProcessStep.AnimationsListing:
this.process_step = ProcessStep.AnimationsListing
- this.animations_listing_step.begin()
+ this.animations_listing_step.begin(this.load_skeleton_step.skeleton_type())
this.skeleton_helper?.setJointsVisible(false)
// hide skeleton by default in animations listing step
if (this.ui.dom_show_skeleton_checkbox !== null) {
- this.ui.dom_show_skeleton_checkbox.checked = false
+ this.ui.dom_show_skeleton_checkbox.checked = false
}
// Show/hide A-Pose correction options based on skeleton type
@@ -300,8 +300,7 @@ export class Bootstrap {
this.edit_skeleton_step.armature())
}
- this.animations_listing_step.load_and_apply_default_animation_to_skinned_mesh(this.weight_skin_step.final_skinned_meshes(),
- this.load_skeleton_step.skeleton_type())
+ this.animations_listing_step.load_and_apply_default_animation_to_skinned_mesh(this.weight_skin_step.final_skinned_meshes())
if (this.skeleton_helper !== undefined) {
this.skeleton_helper.hide() // hide skeleton helper in animations listing step