Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

GLTFs contain multiple files, so we cannot just import a GLB.

Scott Petrovic55da558b1707
diff --git a/src/index.html b/src/index.html
index 7ae6c42..902df69 100644
--- a/src/index.html
+++ b/src/index.html
@@ -63,7 +63,7 @@
<span>Upload</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, .zip, .fbx" />
<div style="text-align: center; font-size: 1.5rem">or</div>
diff --git a/src/lib/processes/load-model/StepLoadModel.ts b/src/lib/processes/load-model/StepLoadModel.ts
index 638ab8e..41b0f2a 100644
--- a/src/lib/processes/load-model/StepLoadModel.ts
+++ b/src/lib/processes/load-model/StepLoadModel.ts
@@ -30,7 +30,6 @@ export class StepLoadModel extends EventTarget {
triangle_count = 0
objects_count = 0
-
// function that goes through all our geometry data and calculates how many triangles we have
private calculate_mesh_metrics (): void {
let triangle_count = 0
@@ -155,13 +154,15 @@ export class StepLoadModel extends EventTarget {
loaded_scene.add(fbx)
this.process_loaded_scene(loaded_scene)
})
- } else if (file_extension === 'gltf' || file_extension === 'glb') {
+ } else if (file_extension === 'glb') {
this.gltf_loader.load(model_file_path, (gltf) => {
const loaded_scene: Scene = gltf.scene
this.process_loaded_scene(loaded_scene)
})
+ } else if (file_extension === 'zip') {
+ console.log('try to load a GLTF file with separate BIN file from ZIP')
} else {
- console.error('Unsupported file format to load. Only acccepts FBX, GLTF, GLB:', model_file_path)
+ console.error('Unsupported file format to load. Only acccepts FBX, (ZIP)GLTF+BIN, GLB:', model_file_path)
}
}
@@ -310,12 +311,11 @@ export class StepLoadModel extends EventTarget {
return this.material_list
}
-
/**
* Rotate all geometry data in the model by the given angle (in degrees) around the specified axis.
* This directly modifies the geometry vertices.
*/
- public rotate_model_geometry(axis: 'x' | 'y' | 'z', angle: number): void {
+ public rotate_model_geometry (axis: 'x' | 'y' | 'z', angle: number): void {
const radians = MathUtils.degToRad(angle)
this.final_mesh_data.traverse((obj: Object3D) => {
if (obj.type === 'Mesh') {
diff --git a/static/test-files/fox-model-GLTF-BIN.zip b/static/test-files/fox-model-GLTF-BIN.zip
new file mode 100644
index 0000000..44f538a
Binary files /dev/null and b/static/test-files/fox-model-GLTF-BIN.zip differ