Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

FBX is going to take more troubleshooting as the Mesh data is somewhat different. Just disable for now and come back to later

Scott Petrovic1eb5403c725c
diff --git a/src/index.html b/src/index.html
index 8256e64..32f7d97 100644
--- a/src/index.html
+++ b/src/index.html
@@ -40,7 +40,7 @@
<div id="load-model-tools">
- <p class="step-instructions">Supports GLTF,GLB and FBX files.</p>
+ <p class="step-instructions">Supports GLTF or GLB model files.</p>
<label for="model-upload" class="button" >
<span class="button-icon-group">
@@ -48,7 +48,7 @@
<span>Upload Custom Model</span>
</span>
</label>
- <input id="model-upload" type="file" name="file-upload" accept=".glb, .gltf, .fbx" />
+ <input id="model-upload" type="file" name="file-upload" accept=".glb, .gltf" />
<div style="text-align: center; font-size: 1.5rem">or</div>
diff --git a/src/lib/processes/StepLoadModel.ts b/src/lib/processes/StepLoadModel.ts
index 0a6c92c..0c3e3ee 100644
--- a/src/lib/processes/StepLoadModel.ts
+++ b/src/lib/processes/StepLoadModel.ts
@@ -155,25 +155,25 @@ export class StepLoadModel extends EventTarget {
}
}
- private process_loaded_scene(loaded_scene: Scene, max_height: number): void {
+ private process_loaded_scene (loaded_scene: Scene, max_height: number): void {
this.original_model_data = loaded_scene.clone()
this.original_model_data.name = 'Cloned Scene'
- this.original_model_data.traverse((child) => {
- child.castShadow = true
- })
-
// strip out stuff that we are not bringing into the model step
const clean_scene_with_only_models = this.strip_out_all_unecessary_model_data(this.original_model_data)
- this.scale_model_on_import(clean_scene_with_only_models, max_height) // if we have multiple objects, we want to scale them all the same
+ // this.scale_model_on_import(clean_scene_with_only_models, max_height) // if we have multiple objects, we want to scale them all the same
- // loop through each child in scene and reset rotation
- // if we don't the skinning process doesn't take rotation into account
- // and creates odd results
+ // additional data cleanup and normalization
clean_scene_with_only_models.traverse((child) => {
- child.rotation.set(0, 0, 0)
- })
+ // make sure all the meshes can cast shadow onto the ground
+ child.castShadow = true
+ // make sure all the meshes have a scale of 1,1,1
+ // this should also update the buffer geometry data
+ if (child.type === 'Mesh') {
+ child.scale.set(1, 1, 1)
+ }
+ })
console.log('Model loaded', clean_scene_with_only_models)
// assign the final cleaned up model to the original model data
@@ -216,6 +216,7 @@ export class StepLoadModel extends EventTarget {
return new_scene
}
+ // unused for now until I figure out what to do with this...or even if we need it
private scale_model_on_import (scene_object: Scene, max_height = 1.0): void {
let scale_factor: number = 1.0