Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Initial pass at adding orthographic shortcuts for positioning bones

Scott Petrovic467bfb4e63a8
diff --git a/src/index.html b/src/index.html
index eec4f39..dea39db 100644
--- a/src/index.html
+++ b/src/index.html
@@ -71,7 +71,7 @@
<!-- radio buttons to toggle between rotation and translate -->
<div id="transform-controls">
- <div style="display: flex; flex-direction: row; align-items: center; column-gap: 5px; ">
+ <!-- <div style="display: flex; flex-direction: row; align-items: center; column-gap: 5px; ">
<span>Bone Controls:</span>
<input type="radio" id="translate-mode" name="tool-selection" value="translation" checked style="display: none">
@@ -83,10 +83,9 @@
<label for="rotation-mode">
<span class="material-symbols-outlined transform-icons" >refresh</span>
</label>
- </div>
-
-
+ </div> -->
+
<div style="display: flex; flex-direction: row">
<input type="checkbox" id="mirror-skeleton" name="mirror-skeleton" value="mirror" checked>
<label for="mirror-skeleton">Mirror</label>
@@ -99,6 +98,12 @@
<span id="skeleton-step-actions">
+ <!-- change camera to orthographic views to help position skeleton-->
+ <div style="display: flex; flex-direction: row; align-items: center; column-gap: 5px; ">
+ <span>View:</span>
+ <div id="view-buttons-container" style="display: flex; gap: 5px;"></div>
+ </div>
+
<!-- add number input for changing scale of skeleton-->
<div style="display: flex; flex-direction: row; justify-content: space-evenly; align-items: center;">
<input type="number" id="scale-input" name="scale-input" value="-3" min="-90" max="90" step="1.0">
diff --git a/src/lib/UI.ts b/src/lib/UI.ts
index a29a2fa..7a56684 100644
--- a/src/lib/UI.ts
+++ b/src/lib/UI.ts
@@ -37,6 +37,8 @@ export class UI {
dom_animation_import_options: HTMLElement | null = null
dom_import_animations_buton: HTMLButtonElement | null = null
dom_import_animation_upload: HTMLElement | null = null
+ public readonly dom_transform_controls: HTMLElement | null = document.getElementById('transform-controls')
+ public readonly dom_view_buttons_container: HTMLElement | null = document.getElementById('view-buttons-container')
constructor () {
this.initialize_dom_elements()
diff --git a/src/script.ts b/src/script.ts
index 48208fc..0183097 100644
--- a/src/script.ts
+++ b/src/script.ts
@@ -97,6 +97,8 @@ export class Bootstrap {
const fog_far = 80
const fog_color = 0x0d2525
this.scene.fog = new THREE.Fog(fog_color, fog_near, fog_far)
+
+ this.add_view_switching_buttons();
} // end setup_environment()
private regenerate_skeleton_helper (new_skeleton: Skeleton, helper_name = 'Skeleton Helper'): void {
@@ -442,6 +444,56 @@ export class Bootstrap {
return true
}
+
+ private switchToView (view: 'front' | 'side' | 'top'): void {
+ if (this.controls === undefined) {
+ console.log('switching to view failed: controls are undefined')
+ return
+ }
+
+ const distance = 10
+ switch (view) {
+ case 'front':
+ this.camera.position.set(0, 0, distance)
+ break
+ case 'side':
+ this.camera.position.set(distance, 0, 0)
+ break
+ case 'top':
+ this.camera.position.set(0, distance, 0)
+ break
+ }
+ this.controls.target.set(0, 0, 0) // look at origin
+
+ // how to pan up 1/2 the height of the model?
+ const bounding_box = this.load_model_step.model_meshes().children[0].geometry.boundingBox
+ const model_height = bounding_box.max.y - bounding_box.min.y
+ this.controls.target.y += model_height / 2
+
+ this.controls.update() // update the camera position
+ }
+
+ private add_view_switching_buttons(): void {
+ if (!this.ui.dom_view_buttons_container) return;
+
+ // Create buttons for each view
+ const frontBtn = document.createElement('button');
+ frontBtn.textContent = 'Front';
+ frontBtn.addEventListener('click', () => this.switchToView('front'));
+
+ const sideBtn = document.createElement('button');
+ sideBtn.textContent = 'Side';
+ sideBtn.addEventListener('click', () => this.switchToView('side'));
+
+ const topBtn = document.createElement('button');
+ topBtn.textContent = 'Top';
+ topBtn.addEventListener('click', () => this.switchToView('top'));
+
+ // Add buttons to container
+ this.ui.dom_view_buttons_container.appendChild(frontBtn);
+ this.ui.dom_view_buttons_container.appendChild(sideBtn);
+ this.ui.dom_view_buttons_container.appendChild(topBtn);
+ }
} // end Bootstrap class
// Create an instance of the Bootstrap class when the script is loaded