Import a 3D Model and automatically assign and export animations
TypeScript
Start adding load logic to use Mesh2Motion step
Scott Petrovic2a9c18a1d571
diff --git a/src/lib/processes/load-model/StepLoadModel.ts b/src/lib/processes/load-model/StepLoadModel.tsindex 9253d45..d066338 100644--- a/src/lib/processes/load-model/StepLoadModel.ts+++ b/src/lib/processes/load-model/StepLoadModel.ts@@ -32,6 +32,9 @@ export class StepLoadModel extends EventTarget {// will mess up model and need to just replace the entire materialprivate mesh_has_broken_material: boolean = false+ // controls whether to preserve all objects (bones, lights, etc.) or strip to meshes only+ private preserve_all_objects: boolean = false+// for debugging, let's count these to help us test performance things bettervertex_count = 0triangle_count = 0@@ -197,6 +200,15 @@ export class StepLoadModel extends EventTarget {this.triangle_count = 0this.objects_count = 0this.mesh_has_broken_material = false+ this.preserve_all_objects = false+ }++ /**+ *+ * @param preserve+ */+ public set_preserve_all_objects (preserve: boolean): void {+ this.preserve_all_objects = preserve}public load_model_file (model_file_path: string | ArrayBuffer | null, file_extension: string): void {@@ -315,6 +327,11 @@ export class StepLoadModel extends EventTarget {}private strip_out_all_unecessary_model_data (model_data: Scene): Scene {+ // retargeting needs all the objects, so don't do any stripping+ if (this.preserve_all_objects) {+ return model_data+ }+// create a new scene object, and only include meshesconst new_scene = new Scene()new_scene.name = this.model_display_namediff --git a/src/retarget/retarget.ts b/src/retarget/retarget.tsindex 1ea77f2..8091fca 100644--- a/src/retarget/retarget.ts+++ b/src/retarget/retarget.ts@@ -28,8 +28,47 @@ class RetargetModule {if (target.files && target.files.length > 0) {const file = target.files[0]console.log('File selected:', file.name, 'Size:', file.size, 'Type:', file.type)++ // Get file extension+ const file_name = file.name.toLowerCase()+ let file_extension = ''+ if (file_name.endsWith('.glb')) {+ file_extension = 'glb'+ } else if (file_name.endsWith('.fbx')) {+ file_extension = 'fbx'+ } else if (file_name.endsWith('.zip')) {+ file_extension = 'zip'+ } else {+ console.error('Unsupported file type')+ this.showErrorDialog('Unsupported file type. Please select a GLB, FBX, or ZIP file.')+ return+ }++ // Configure the model loader to preserve all objects (bones, etc.)+ this.mesh2motion_engine.load_model_step.set_preserve_all_objects(true)++ // Create a URL for the file and load it+ const file_url = URL.createObjectURL(file)++ try {+ this.mesh2motion_engine.load_model_step.load_model_file(file_url, file_extension)+ console.log('Model loading initiated...')++ // TODO: Add listener for load completion+ // TODO: Validate that the model contains skeletal data+ // TODO: Show error dialog if no bones found+ } catch (error) {+ console.error('Error loading model:', error)+ this.showErrorDialog('Error loading model file.')+ URL.revokeObjectURL(file_url) // Clean up the URL+ }}}++ private showErrorDialog (message: string): void {+ // Simple alert for now - could be replaced with a proper modal dialog later+ alert(message)+ }}// Initialize when DOM is ready