Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

only use instructions area for showing binding errors

Scott Petrovic1ebbaeb4d8d0
diff --git a/src/index.html b/src/index.html
index 1dbed29..a51d293 100644
--- a/src/index.html
+++ b/src/index.html
@@ -50,8 +50,8 @@
<div style="text-align: center; font-size: 1.5rem">or</div>
- <div style="background-color: #0f2f3d; padding: 1rem;">
- <label>Sample:</label>
+ <div style="display: flex; flex-direction: column; gap: 1rem; background-color: #0f2f3d; padding: 1rem;">
+ <p style="margin: 0">Upload sample model:</p>
<select id="model-selection">
<option value="models/human-simple.glb">Human Cartoon</option>
<option value="models/fox.glb">Fox</option>
@@ -104,36 +104,19 @@
</div>
- <!-- 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; ">
- <span>Bone Controls:</span>
-
- <input type="radio" id="translate-mode" name="tool-selection" value="translation" checked style="display: none">
- <label for="translate-mode">
- <span class="material-symbols-outlined transform-icons">open_with</span>
- </label>
- <input type="radio" id="rotation-mode" name="tool-selection" value="rotation" style="display: none">
- <label for="rotation-mode">
- <span class="material-symbols-outlined transform-icons" >refresh</span>
- </label>
- </div> -->
+ <span id="skeleton-step-actions">
- <p class="step-instructions">Right click on a joint to select and move it with controls.</p>
-
- <div style="display: flex; flex-direction: row">
- <input type="checkbox" id="mirror-skeleton" name="mirror-skeleton" value="mirror" checked>
- <label for="mirror-skeleton">Mirror Left/Right Joints</label>
- </div>
+ <p class="step-instructions">Right click on a joint to select and move it with controls.</p>
- <hr />
+ <div style="display: flex; flex-direction: row">
+ <input type="checkbox" id="mirror-skeleton" name="mirror-skeleton" value="mirror" checked>
+ <label for="mirror-skeleton">Mirror Left/Right Joints</label>
</div>
-
- <span id="skeleton-step-actions">
+ <hr />
<!-- change camera to orthographic views to help position skeleton-->
<div style="display: flex; flex-direction: row; align-items: center; column-gap: 5px; ">
@@ -149,7 +132,7 @@
<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">
<span class="suffix-unit">%</span>
- <button id="scale-skeleton-button" class="secondary-button" >Scale entire skeleton</button>
+ <button id="scale-skeleton-button" class="secondary-button" >Scale skeleton</button>
</div>
<!-- hide this move to origin for now as is it seems to cause more trouble than it helps -->
@@ -283,7 +266,6 @@
<!-- info panel for messages and information-->
<div id="info-panel">
<div id="info-messaging"> </div>
-
</div>
diff --git a/src/lib/UI.ts b/src/lib/UI.ts
index 705cebf..25e8f22 100644
--- a/src/lib/UI.ts
+++ b/src/lib/UI.ts
@@ -3,7 +3,6 @@ import { type AnimationClip } from 'three'
export class UI {
dom_current_step_index: HTMLElement | null = null
dom_current_step_element: HTMLElement | null = null
- dom_transform_controls_switch: HTMLElement | null = null
dom_load_model_tools: HTMLElement | null = null
dom_upload_model_button: HTMLButtonElement | null = null
dom_load_model_button: HTMLButtonElement | null = null
@@ -28,7 +27,10 @@ export class UI {
dom_enable_skin_debugging: HTMLInputElement | null = null
dom_animation_clip_list: HTMLElement | null = null
dom_export_button: HTMLButtonElement | null = null
+
+ dom_info_container: HTMLElement | null = null
dom_info_panel: HTMLElement | null = null
+
dom_import_animations_button: HTMLButtonElement | null = null
dom_extend_arm_input: HTMLElement | null = null
dom_extend_arm_button: HTMLButtonElement | null = null
@@ -51,7 +53,6 @@ export class UI {
// grab all UI Elements from page that we need to interact with
this.dom_current_step_index = document.querySelector('#current-step-index')
this.dom_current_step_element = document.querySelector('#current-step-label')
- this.dom_transform_controls_switch = document.querySelector('#transform-controls')
// UI controls for loading the model
this.dom_load_model_tools = document.querySelector('#load-model-tools')
@@ -91,6 +92,8 @@ export class UI {
// UI Controls for working with animation list/selection and export
this.dom_animation_clip_list = document.querySelector('#animations-items')
this.dom_export_button = document.querySelector('#export-button')
+
+ this.dom_info_container = document.querySelector('#info-panel')
this.dom_info_panel = document.querySelector('#info-messaging')
this.dom_extend_arm_input = document.querySelector('#extend-arm-input')
@@ -113,9 +116,6 @@ export class UI {
}
public hide_all_elements (): void {
- if (this.dom_transform_controls_switch != null) {
- this.dom_transform_controls_switch.style.display = 'none'
- }
if (this.dom_load_model_tools != null) {
this.dom_load_model_tools.style.display = 'none'
}
diff --git a/src/lib/processes/StepAnimationsListing.ts b/src/lib/processes/StepAnimationsListing.ts
index 6258b00..d9a5293 100644
--- a/src/lib/processes/StepAnimationsListing.ts
+++ b/src/lib/processes/StepAnimationsListing.ts
@@ -52,11 +52,6 @@ export class StepAnimationsListing extends EventTarget {
this.add_event_listeners()
}
- public instructions_text (): string {
- return `<div>Instructions</div>
- <div>Test and export animations to GLB format</div>`
- }
-
public mixer (): AnimationMixer {
return this.animation_mixer
}
diff --git a/src/lib/processes/StepEditSkeleton.ts b/src/lib/processes/StepEditSkeleton.ts
index 48fa45f..5622b5e 100644
--- a/src/lib/processes/StepEditSkeleton.ts
+++ b/src/lib/processes/StepEditSkeleton.ts
@@ -24,11 +24,7 @@ export class StepEditSkeleton extends EventTarget {
}
if (this.ui.dom_current_step_element != null) {
- this.ui.dom_current_step_element.innerHTML = 'Move joints inside mesh'
- }
-
- if (this.ui.dom_transform_controls_switch != null) {
- this.ui.dom_transform_controls_switch.style.display = 'flex'
+ this.ui.dom_current_step_element.innerHTML = 'Position Joints'
}
if (this.ui.dom_skeleton_edit_tools != null) {
@@ -44,10 +40,6 @@ export class StepEditSkeleton extends EventTarget {
this.add_event_listeners()
}
- public instructions_text (): string {
- return `<div>Instructions</div>
- <div>Position skeleton into correct postion</div>`
- }
private update_bind_button_text (): void {
if (this.show_debug && this.ui.dom_bind_pose_button !== null) {
diff --git a/src/lib/processes/StepLoadModel.ts b/src/lib/processes/StepLoadModel.ts
index 9016a1a..6b64357 100644
--- a/src/lib/processes/StepLoadModel.ts
+++ b/src/lib/processes/StepLoadModel.ts
@@ -112,11 +112,6 @@ export class StepLoadModel extends EventTarget {
}
}
- public instructions_text (): string {
- return `<div>Instructions</div>
- <div>Select existing models or upload your own.</div>
-`
- }
private load_model_file (model_file_path: string): void {
const max_height = 1.5 // have 3d model scaled to be 1.5 units tall. helps normalize the models to work with
diff --git a/src/lib/processes/StepLoadSkeleton.ts b/src/lib/processes/StepLoadSkeleton.ts
index 2b644a0..620f746 100644
--- a/src/lib/processes/StepLoadSkeleton.ts
+++ b/src/lib/processes/StepLoadSkeleton.ts
@@ -36,12 +36,6 @@ export class StepLoadSkeleton extends EventTarget {
this.add_event_listeners()
}
- public instructions_text (): string {
- return `<div>Instructions</div>
- <div>Select skeleton based off model type.</div>
-`
- }
-
private add_event_listeners (): void {
if (this.ui.dom_load_skeleton_button !== null) {
this.ui.dom_load_skeleton_button.addEventListener('click', () => {
diff --git a/src/lib/processes/StepWeightSkin.ts b/src/lib/processes/StepWeightSkin.ts
index 0518e01..ba6b12c 100644
--- a/src/lib/processes/StepWeightSkin.ts
+++ b/src/lib/processes/StepWeightSkin.ts
@@ -40,15 +40,6 @@ export class StepWeightSkin extends EventTarget {
}
}
- public instructions_text (): string {
- return `<div>Instructions</div>
- <div>Visualize the results of the skinning. Currently only supported for Bone Envelope</div>
- <ol>
- <li>Green vertices indicate vertex is inside a bone cage</li>
- <li>Red vertex indicates there is no bone found, so relies on closest distance to bone.</li>
- <li>Modifying the position of the bones to be closer to the middle of the mesh can improve results</li>
- </ol>`
- }
public create_bone_formula_object (editable_armature: Object3D, skinning_formula: string, skeleton_type: SkeletonType): any {
this.skinning_armature = editable_armature.clone()
diff --git a/src/script.ts b/src/script.ts
index c7c1d5c..2cb3d96 100644
--- a/src/script.ts
+++ b/src/script.ts
@@ -125,6 +125,11 @@ export class Bootstrap {
}
private show_skin_failure_message (bone_names_with_errors: string[], error_point_positions: Vector3[]): void {
+ // show the DOM HTML container to see error messages for each bone that isn't inside the mesh
+ if (this.ui.dom_info_container !== null) {
+ this.ui.dom_info_container.style.display = 'block'
+ }
+
// add the bone vertices as X markers to debugging object
const error_markers: Group = Generators.create_x_markers(error_point_positions, 0.02, 0xff0000)
this.debugging_visual_object.add(error_markers)
@@ -135,7 +140,7 @@ export class Bootstrap {
return
}
- this.ui.dom_info_panel.innerHTML = 'Some bones are outside the mesh. Fix them up and try to bind again'
+ this.ui.dom_info_panel.innerHTML = 'Somebones are outside the mesh and are marked with red. Fix them and try again.'
this.ui.dom_info_panel.innerHTML += '<br>'
// display the bones names in an HTML list
@@ -155,35 +160,34 @@ export class Bootstrap {
// clean up any event listeners from the previous steps
this.edit_skeleton_step.remove_event_listeners()
+ // hide the info container by default
+ if (this.ui.dom_info_container !== null) {
+ this.ui.dom_info_container.style.display = 'none'
+ }
+
switch (process_step) {
case ProcessStep.LoadModel:
process_step = ProcessStep.LoadModel
this.load_model_step.begin()
- this.ui.dom_info_panel.innerHTML = this.load_model_step.instructions_text()
break
case ProcessStep.LoadSkeleton:
process_step = ProcessStep.LoadSkeleton
this.load_skeleton_step.begin()
- this.ui.dom_info_panel.innerHTML = this.load_skeleton_step.instructions_text()
break
case ProcessStep.EditSkeleton:
process_step = ProcessStep.EditSkeleton
this.edit_skeleton_step.begin()
this.transform_controls.enabled = true
this.transform_controls.setMode('translate')
- this.ui.dom_transform_controls_switch.style.display = 'none' // hide the UI control until we have a bone selected
- this.ui.dom_info_panel.innerHTML = this.edit_skeleton_step.instructions_text()
break
case ProcessStep.BindPose:
this.process_step = ProcessStep.BindPose
- this.ui.dom_info_panel.innerHTML = this.weight_skin_step.instructions_text()
this.weight_skin_step.begin()
this.transform_controls.enabled = false // shouldn't be editing bones
this.start_skin_weighting_step()
break
case ProcessStep.AnimationsListing:
this.process_step = ProcessStep.AnimationsListing
- this.ui.dom_info_panel.innerHTML = this.animations_listing_step.instructions_text()
this.animations_listing_step.begin()
this.transform_controls.setMode('rotate')
this.animations_listing_step.load_and_apply_default_animation_to_skinned_mesh(this.weight_skin_step.final_skinned_meshes(),
@@ -244,7 +248,6 @@ export class Bootstrap {
if (closest_bone !== null) {
this.transform_controls.attach(closest_bone)
this.weight_skin_step.set_bone_index_to_test(closest_bone_index)
- this.ui.dom_transform_controls_switch.style.display = 'flex'
}
}
@@ -332,20 +335,6 @@ export class Bootstrap {
this.load_model_step.model_meshes().visible = true // show the unskinned mesh again
})
- this.ui.dom_transform_controls_switch.addEventListener('click', function (event) {
- const targetElement = event.target
-
- if (targetElement.value === undefined) {
- return // half of events for this are returning null for some reason
- }
-
- if (targetElement.value === 'translation') {
- this.transform_controls.setMode('translate')
- } else if (targetElement.value === 'rotation') {
- this.transform_controls.setMode('rotate')
- }
- })
-
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'))
diff --git a/src/styles.css b/src/styles.css
index ec87b13..b17ebe5 100644
--- a/src/styles.css
+++ b/src/styles.css
@@ -183,6 +183,7 @@ option {
padding: 0.5rem;
font-size: 13px;
color: #d0c8c8;
+ border: 1px solid red;
}
#load-model-tools, #load-skeleton-tools, #transform-controls, #skeleton-step-actions {
@@ -378,5 +379,5 @@ input[type="file"] {
}
.step-instructions {
- max-width: 250px;
+ max-width: 180px;
}
\ No newline at end of file