Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Implement logic to move mesh geometry data above floor

Scott Petrovicb00f43554aba
diff --git a/src/index.html b/src/index.html
index 41d2983..96151ee 100644
--- a/src/index.html
+++ b/src/index.html
@@ -81,36 +81,32 @@
<div id="load-skeleton-tools">
- <p class="step-instructions">Pick base skeleton type to work with. You will modify joints to fit mesh in next step.</p>
-
- <label>Skeleton Type to use:</label>
- <select id="skeleton-selection">
- <option value="human">Human</option>
- <option value="quadraped">4 Leg Creature</option>
- <option value="bird">Bird</option>
- </select>
-
-
+ <span>
+ <span style="max-width: 220px">Rotate Model to face front <br/> (blue origin line)</span>
+ <div style="display: flex; flex-direction: row">
+ <button class="secondary-button" id="rotate-model-x-button">X</button>
+ <button class="secondary-button" id="rotate-model-y-button">Y</button>
+ <button class="secondary-button" id="rotate-model-z-button">Z</button>
+ </div>
+ </span>
<hr />
- <span>
- <span>Rotate Model to face front</span>
- <div style="display: flex; flex-direction: row">
- <button class="secondary-button" id="rotate-model-x-button">X</button>
- <button class="secondary-button" id="rotate-model-y-button">Y</button>
- <button class="secondary-button" id="rotate-model-z-button">Z</button>
+ <span style="max-width: 220px">
+ <span>If model is below the ground floor</span>
+ <div style="display: flex; flex-direction: row">
+ <button class="secondary-button" id="move-model-to-floor-button">Move</button>
</div>
</span>
<hr />
- <span>
- <span>Move model above floor</span>
- <div style="display: flex; flex-direction: row">
- <button class="secondary-button" id="move-model-to-floor-button">Move</button>
- </div>
- </span>
+ <label>Skeleton Type to use:</label>
+ <select id="skeleton-selection">
+ <option value="human">Human</option>
+ <option value="quadraped">4 Leg Creature</option>
+ <option value="bird">Bird</option>
+ </select>
<hr />
@@ -123,7 +119,7 @@
<span id="skeleton-step-actions">
- <p class="step-instructions">Right click on a joint to select and move it with controls.</p>
+ <p class="step-instructions">Right-click to select joints. Move bones into position.</p>
<p id="bone-selection-section">
<span>Selected Bone: <span id="edit-selected-bone-label">None</span></span>
@@ -193,12 +189,6 @@
<button id="action_back_to_edit_skeleton" >&#x2039; Back to edit skeleton</button>
- <!-- checkbox option to show skeleton -->
- <div class="styled-checkbox">
- <input type="checkbox" id="show-skeleton-checkbox" name="show-skeleton" value="show" checked>
- <label for="show-skeleton-checkbox">Show skeleton</label>
- </div>
-
</span>
@@ -206,7 +196,7 @@
<div id="animations-listing">
<div id="animations-listing-header">
- <span>Animations</span>
+ <span>Animation name</span>
<div style="margin-right: 1rem;">Export</div>
</div>
@@ -231,6 +221,14 @@
</div>
<hr />
+
+ <!-- checkbox option to show skeleton -->
+ <div class="styled-checkbox">
+ <input type="checkbox" id="show-skeleton-checkbox" name="show-skeleton" value="show" checked>
+ <label for="show-skeleton-checkbox">Show skeleton</label>
+ </div>
+
+ <hr />
<!-- Imports new animations. Hide this for now until base functionality is more stable
diff --git a/src/lib/processes/StepLoadModel.ts b/src/lib/processes/StepLoadModel.ts
index ee38119..418d429 100644
--- a/src/lib/processes/StepLoadModel.ts
+++ b/src/lib/processes/StepLoadModel.ts
@@ -313,6 +313,35 @@ export class StepLoadModel extends EventTarget {
}
public move_model_to_floor (): void {
- console.log('moving model to floor here')
+ // go through all the meshes and find out the lowest point
+ // to use later. A model could contain multiple meshes
+ // and we want to make sure the offset is the same between all of them
+ let final_lowest_point: number = 0
+ this.final_mesh_data.traverse((obj: Object3D) => {
+ // if object is a mesh, rotate the geometry data
+ if (obj.type === 'Mesh') {
+ const mesh_obj: Mesh = obj as Mesh
+ const bounding_box = new Box3().setFromObject(mesh_obj)
+
+ if (bounding_box.min.y < final_lowest_point) {
+ final_lowest_point = bounding_box.min.y
+ }
+ }
+ })
+
+ // move all the meshes to the floor by the amount we calculated above
+ this.final_mesh_data.traverse((obj: Object3D) => {
+ // if object is a mesh, rotate the geometry data
+ if (obj.type === 'Mesh') {
+ const mesh_obj: Mesh = obj as Mesh
+
+ // this actually updates the geometry, so the origin will still be at 0,0,0
+ // maybe need to recompute the bounding box and sphere internally after translate
+ const offset = final_lowest_point * -1
+ mesh_obj.geometry.translate(0, offset, 0)
+ mesh_obj.geometry.computeBoundingBox()
+ mesh_obj.geometry.computeBoundingSphere()
+ }
+ })
}
}