Import a 3D Model and automatically assign and export animations
TypeScript
Normalize model cleanup function to take in and return a scene
Scott Petrovicdad02f3af210
diff --git a/src/lib/processes/load-model/ModelCleanupUtility.ts b/src/lib/processes/load-model/ModelCleanupUtility.tsindex 5da82d5..0bb8be9 100644--- a/src/lib/processes/load-model/ModelCleanupUtility.ts+++ b/src/lib/processes/load-model/ModelCleanupUtility.ts@@ -108,12 +108,12 @@ export class ModelCleanupUtility {* We need to keep parents of skinned meshes and bones for retargeting* This is because the hierarchy is important for retargeting to work properly* @param model_data Scene or Group containing the model- * @returns Group with everything needed for retargeting (SkinnedMesh, Bones, and their parents)+ * @returns Scene with everything needed for retargeting (SkinnedMesh, Bones, and their parents)*/- public static strip_out_retargeting_model_data (model_data: Scene | Group): Group<Object3DEventMap> {- // Create a new Group to hold only the objects we want to keep- const filtered_group = new Group()- filtered_group.name = 'Filtered Retargeting Data'+ public static strip_out_retargeting_model_data (model_data: Scene): Scene {+ // Create a new Scene to hold only the objects we want to keep+ const filtered_scene = new Scene()+ filtered_scene.name = 'Filtered Retargeting Data'// Find SkinnedMesh objects and preserve their complete bone hierarchyconst skinned_meshes: SkinnedMesh[] = []@@ -131,9 +131,9 @@ export class ModelCleanupUtility {// The clone should preserve the skeleton with proper bone hierarchy// Since we're cloning, the skeleton hierarchy should remain intact- filtered_group.add(cloned_skinned_mesh)+ filtered_scene.add(cloned_skinned_mesh)})- return filtered_group+ return filtered_scene}}diff --git a/src/lib/processes/load-model/StepLoadModel.ts b/src/lib/processes/load-model/StepLoadModel.tsindex 2b2dac9..95a6191 100644--- a/src/lib/processes/load-model/StepLoadModel.ts+++ b/src/lib/processes/load-model/StepLoadModel.ts@@ -19,7 +19,7 @@ export class StepLoadModel extends EventTarget {private final_mesh_data: Scene = new Scene() // mesh data used when creating the skinned mesh// model data used for retargeting process. Only used during retargeting processes- private final_retargetable_model_data: Group<Object3DEventMap> = new Group()+ private final_retargetable_model_data: Scene = new Scene()private debug_model_loading: boolean = falseprivate model_display_name: string = 'Imported Model'@@ -46,7 +46,7 @@ export class StepLoadModel extends EventTarget {* Skinned mesh data that will be used for retargeting* @returns Loaded Skinned mesh data that will be used for retargeting*/- public get_final_retargetable_model_data (): Group<Object3DEventMap> {+ public get_final_retargetable_model_data (): Scene {return this.final_retargetable_model_data}@@ -313,8 +313,7 @@ export class StepLoadModel extends EventTarget {})// strip out things differently if we need to preserve skinned meshes or regular meshes- // retargeting mesh could be a Group object, so accept both and share this variable- let clean_scene_with_only_models: Scene | Group<Object3DEventMap>+ let clean_scene_with_only_models: Sceneif (this.preserve_skinned_mesh) {clean_scene_with_only_models = ModelCleanupUtility.strip_out_retargeting_model_data(this.original_model_data)} else {@@ -335,7 +334,7 @@ export class StepLoadModel extends EventTarget {// assign the final retargetable model data to the cleaned scene with skinned meshes// any scaling or further processing can be donw as part of the retargeting processif (this.preserve_skinned_mesh) {- this.final_retargetable_model_data = clean_scene_with_only_models as Group<Object3DEventMap>+ this.final_retargetable_model_data = clean_scene_with_only_modelsthis.dispatchEvent(new CustomEvent('modelLoadedForRetargeting'))return}