Import a 3D Model and automatically assign and export animations
TypeScript
Create debugging option for model importer to to help test inverted faces
Scott Petrovic40c2674fb7d7
diff --git a/src/index.html b/src/index.htmlindex bdf17d8..d9338bf 100644--- a/src/index.html+++ b/src/index.html@@ -39,6 +39,11 @@</label><input id="model-upload" type="file" name="file-upload" accept=".glb, .gltf" />+ <div style="display: flex; flex-direction: row">+ <input type="checkbox" id="load-model-debug-checkbox" name="load-model-debug-checkbox" >+ <label for="load-model-debug-checkbox">Debug</label>+ </div>+</div><div id="load-skeleton-tools">diff --git a/src/lib/Generators.ts b/src/lib/Generators.tsindex d9dec1a..4ee6c48 100644--- a/src/lib/Generators.ts+++ b/src/lib/Generators.ts@@ -19,7 +19,10 @@ export class Generators{// create floor mesh and add to scene to help with shadowsconst floor_geometry = new PlaneGeometry(100, 100, 10, 10);- const floor_material = Generators.create_material(false, 0x4e4e7a);+ const floor_material = new MeshPhongMaterial({ color: 0x4e4e7a, wireframe: false, opacity: 0.2, transparent: true });+ floor_material.side = DoubleSide; // helps us see that we are below the character++const floor_mesh = new Mesh(floor_geometry, floor_material);floor_mesh.name = 'Floor Mesh';floor_mesh.rotation.x = -Math.PI / 2;diff --git a/src/lib/UI.js b/src/lib/UI.jsindex d38f025..8656018 100644--- a/src/lib/UI.js+++ b/src/lib/UI.js@@ -15,6 +15,7 @@ export class UI {this.dom_load_model_tools = document.querySelector('#load-model-tools')this.dom_upload_model_button = document.querySelector('#model-upload')this.dom_load_model_button = document.querySelector('#load-model-button')+ this.dom_load_model_debug_checkbox = document.querySelector('#load-model-debug-checkbox')// UI controls for loading/working with skeletonthis.dom_load_skeleton_tools = document.querySelector('#load-skeleton-tools')diff --git a/src/lib/processes/StepLoadModel.js b/src/lib/processes/StepLoadModel.jsindex 1128432..d01011b 100644--- a/src/lib/processes/StepLoadModel.js+++ b/src/lib/processes/StepLoadModel.js@@ -10,6 +10,7 @@ export class StepLoadModel extends EventTargetloader = nullui = nulloriginal_model_data = null+ debug_model_loading = false// there can be multiple objects in a model, so store them in a listgeometry_list = []@@ -43,6 +44,11 @@ export class StepLoadModel extends EventTarget});+ this.ui.dom_load_model_debug_checkbox.addEventListener('change', (event) => {+ const debug_mode = event.target.checked;+ this.debug_model_loading = debug_mode;+ });+this.ui.dom_load_model_button.addEventListener('click', () => {// get currently selected option out of the model-selection drop-down@@ -62,6 +68,7 @@ export class StepLoadModel extends EventTarget<li>Models with multiple objects won't be rigged correct</li><li>Mouse primary drag to move view</li><li>Mouse context drag to pan view</li>+ <li>Debugging allows you to test odd material artifacts by using a 'Normal' material instead of what is included in the mesh</li></ol>`;}@@ -100,17 +107,30 @@ export class StepLoadModel extends EventTargetnew_scene.name = 'New Scene';model_data.traverse((child) => {+ let new_mesh;+// if the schild is a skinned mesh, create a new mesh object and apply the geometry and materialif(child.type === 'SkinnedMesh'){- const new_mesh = new THREE.Mesh(child.geometry, child.material);+ new_mesh = new THREE.Mesh(child.geometry, child.material);+ new_mesh.name = child.name;+ new_scene.add(new_mesh);+ }+ else if(child.type === 'Mesh')+ {+ new_mesh = child.clone()new_mesh.name = child.name;new_scene.add(new_mesh);}- if(child.type === 'Mesh')+ // potentially use normal material to help debugging models that look odd+ // some materials have some odd transparency or back-face things that make it look odd+ let material_to_use;+ if(this.debug_model_loading && new_mesh !== undefined){- new_scene.add(child.clone());+ material_to_use = new THREE.MeshNormalMaterial()+ material_to_use.side = THREE.FrontSide;+ new_mesh.material = material_to_use;}})