Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Make UI for view switching similar to the rest of the code

Scott Petrovic0761feed845b
diff --git a/src/index.html b/src/index.html
index dea39db..91f39d5 100644
--- a/src/index.html
+++ b/src/index.html
@@ -101,7 +101,11 @@
<!-- 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 id="view-buttons-container" style="display: flex; gap: 5px;">
+ <button id="front-view-button">Front</button>
+ <button id="side-view-button">Side</button>
+ <button id="top-view-button">Top</button>
+ </div>
</div>
<!-- add number input for changing scale of skeleton-->
diff --git a/src/lib/UI.ts b/src/lib/UI.ts
index 7a56684..705cebf 100644
--- a/src/lib/UI.ts
+++ b/src/lib/UI.ts
@@ -37,8 +37,11 @@ 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')
+
+ // changing views buttons when editing skeleton
+ dom_view_front_change: HTMLButtonElement | null = null
+ dom_view_side_change: HTMLButtonElement | null = null
+ dom_view_top_change: HTMLButtonElement | null = null
constructor () {
this.initialize_dom_elements()
@@ -73,6 +76,11 @@ export class UI {
this.dom_move_to_origin_button = document.querySelector('#action_move_to_origin')
this.dom_skinning_algorithm_selection = document.querySelector('#skinning-algorithm-options')
+ // UI controls for changing views
+ this.dom_view_front_change = document.querySelector('#front-view-button')
+ this.dom_view_side_change = document.querySelector('#side-view-button')
+ this.dom_view_top_change = document.querySelector('#top-view-button')
+
// UI controls for working with skinned mesh
this.dom_skinned_mesh_tools = document.querySelector('#skinned-step-tools')
this.dom_skinned_mesh_animation_tools = document.querySelector('#skinned-step-animation-export-options')
diff --git a/src/script.ts b/src/script.ts
index 0183097..dbeae5f 100644
--- a/src/script.ts
+++ b/src/script.ts
@@ -97,8 +97,6 @@ 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 {
@@ -341,6 +339,10 @@ export class Bootstrap {
}
})
+ this.ui.dom_view_front_change.addEventListener('click', () => this.switchToView('front'))
+ this.ui.dom_view_side_change.addEventListener('click', () => this.switchToView('side'))
+ this.ui.dom_view_top_change.addEventListener('click', () => this.switchToView('top'))
+
window.addEventListener('click', (event: MouseEvent) => {
this.handle_closing_drop_down_ui(event)
}, false)
@@ -472,28 +474,6 @@ export class Bootstrap {
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