Import a 3D Model and automatically assign and export animations
TypeScript
Add reset buttons for a-pose and skeleton scale.
Scott Petrovic2702c0d6b991
diff --git a/src/create.html b/src/create.htmlindex b459ab8..ee9410b 100644--- a/src/create.html+++ b/src/create.html@@ -89,7 +89,7 @@<div style="text-align: center; font-size: 1.5rem">or</div><div class="alternate-background-section">- <p style="margin: 0">Reference model:</p>+ <p style="margin: 0">Reference model</p><select id="model-selection"><option value="models/model-human.glb">Human</option><option value="models/model-fox.glb">Fox</option>@@ -136,7 +136,7 @@<div style="display: flex; flex-direction: column; gap: 1rem;">- <span>Skeleton template:</span>+ <span>Skeleton template</span><select id="skeleton-selection"><option value="select-skeleton">Select a skeleton</option><option value="human">Human</option>@@ -150,8 +150,8 @@<!-- Hand skeleton options for human skeleton --><div id="hand-skeleton-options" class="alternate-background-section" >- <span>- Hand Options:+ <span style="display: flex; gap: 1rem;">+ <span>Hand Options</span><span class="material-symbols-outlined" data-tippy-content="Variations on which finger bones you want to keep. Single Hand Bone removes all fingers and keeps only the hand bone.">help</span></span>@@ -166,9 +166,21 @@<!-- scale skeleton to get it close to the model size --><div id="scale-skeleton-controls" style="display: none; flex-direction: column;">- <div style="display: flex; flex-direction: row; align-items: center;">+ <div style="+ display: flex;+ flex-direction: row;+ align-items: center;+ justify-content: center;+ gap: 1rem;+ ">+<label style="display:inline-flex">Scale skeleton</label><span class="material-symbols-outlined" data-tippy-content="Adjust the overall scale of the skeleton">help</span>++ <button class="secondary-button" id="reset-skeleton-scale-button">+ <img src="images/icons/reset.svg" alt="Reset Skeleton Scale" width="20" height="20" />+ </button>+</div><div style="display: flex; flex-direction: row; gap: 1rem; justify-content: flex-start; align-items: center;"><span id="scale-skeleton-percentage-display">100%</span>@@ -272,8 +284,8 @@<span class="material-symbols-outlined" data-tippy-content="If you are having issues with the arms distorting your head (e.g. chibi characters), use a divider to help define the head area.">help</span></div>- <div style="display: flex; align-items: center; gap: 0.5rem;">- <label for="preview-plane-height-input">Plane Height:</label>+ <div id="preview-plane-setting-container" style="display: flex; align-items: center; gap: 0.5rem;">+ <label for="preview-plane-height-input">Height:</label><input type="range" id="preview-plane-height-input" min="0.20" max="2.00" step="0.01" value="0.50" /><span id="preview-plane-height-label" style="width: 2rem;">0.50</span></div>@@ -320,9 +332,19 @@<!-- slider to control arm extension (hide this feature until the base functionality is more stable) --><div id="a-pose-correction-options">- <div style="display: flex; flex-direction: row; align-items: center;">+ <div style="+ display: flex;+ flex-direction: row;+ align-items: center;+ gap: 1rem;+ justify-content: center;+ "><label style="display:inline-flex">A-Pose Correction - Open Arms</label>- <span class="material-symbols-outlined" data-tippy-content="If your model uses an A-Pose, this will help expand/contract arms for all animations">help</span>+ <span class="material-symbols-outlined" data-tippy-content="If your model uses an A-Pose, this will help expand/contract arms for all animations">help</span>++ <button class="secondary-button" id="reset-a-pose-button">+ <img src="images/icons/reset.svg" alt="Reset A-Pose" width="20" height="20" />+ </button></div><div style="display: flex; flex-direction: row; gap: 1rem; justify-content: flex-start; align-items: center;">diff --git a/src/lib/UI.ts b/src/lib/UI.tsindex 7f808ab..fad006e 100644--- a/src/lib/UI.ts+++ b/src/lib/UI.ts@@ -32,6 +32,7 @@ export class UI {dom_scale_skeleton_input: HTMLInputElement | null = nulldom_scale_skeleton_percentage_display: HTMLElement | null = nulldom_scale_skeleton_controls: HTMLElement | null = null+ dom_reset_skeleton_scale_button: HTMLButtonElement | null = null// edit skeleton UI step controlsdom_selected_bone_label: HTMLElement | null = null@@ -43,6 +44,7 @@ export class UI {dom_preview_plane_checkbox: HTMLInputElement | null = nulldom_preview_plane_height_input: HTMLInputElement | null = nulldom_preview_plane_height_label: HTMLElement | null = null+ dom_preview_plane_setting_container: HTMLElement | null = nulldom_skinning_algorithm_selection: HTMLElement | null = nulldom_skinned_mesh_tools: HTMLElement | null = null@@ -60,6 +62,7 @@ export class UI {dom_export_button: HTMLButtonElement | null = nulldom_mirror_animations_checkbox: HTMLInputElement | null = null+ dom_reset_a_pose_button: HTMLButtonElement | null = null// Animation player controlsdom_animation_player: HTMLElement | null = null@@ -117,6 +120,8 @@ export class UI {this.dom_hand_skeleton_selection = document.querySelector('#hand-skeleton-selection')this.dom_mirror_skeleton_checkbox = document.querySelector('#mirror-skeleton')this.dom_scale_skeleton_button = document.querySelector('#scale-skeleton-button')+ this.dom_reset_skeleton_scale_button = document.querySelector('#reset-skeleton-scale-button')+this.dom_undo_button = document.querySelector('#undo-button')this.dom_redo_button = document.querySelector('#redo-button')@@ -130,6 +135,7 @@ export class UI {this.dom_preview_plane_checkbox = document.querySelector('#preview-plane-checkbox')this.dom_preview_plane_height_input = document.querySelector('#preview-plane-height-input')this.dom_preview_plane_height_label = document.querySelector('#preview-plane-height-label')+ this.dom_preview_plane_setting_container = document.querySelector('#preview-plane-setting-container')this.dom_bind_pose_button = document.querySelector('#action_bind_pose')// this.dom_scale_skeleton_input_box = document.querySelector('#scale-input')@@ -158,6 +164,7 @@ export class UI {this.dom_export_button = document.querySelector('#export-button')this.dom_import_animations_button = document.querySelector('#mirror-animations-checkbox')this.dom_mirror_animations_checkbox = document.querySelector('#mirror-animations-checkbox')+ this.dom_reset_a_pose_button = document.querySelector('#reset-a-pose-button')// Animation player controlsthis.dom_animation_player = document.querySelector('#animation-player')diff --git a/src/lib/processes/animations-listing/StepAnimationsListing.ts b/src/lib/processes/animations-listing/StepAnimationsListing.tsindex 220ba78..32fbf96 100644--- a/src/lib/processes/animations-listing/StepAnimationsListing.ts+++ b/src/lib/processes/animations-listing/StepAnimationsListing.ts@@ -296,28 +296,33 @@ export class StepAnimationsListing extends EventTarget {})}+ // reset A-Pose arm extension button+ this.ui.dom_reset_a_pose_button?.addEventListener('click', (event) => {+ const extend_arm_value: number = 0 // reset to zero+ if (this.ui.dom_extend_arm_numeric_input !== null) {+ this.ui.dom_extend_arm_numeric_input.value = extend_arm_value.toString()+ }+ if (this.ui.dom_extend_arm_range_input !== null) {+ this.ui.dom_extend_arm_range_input.value = extend_arm_value.toString()+ }+ this.update_a_pose_value(extend_arm_value)+ })+// A-Pose arm extension event listenerthis.ui.dom_extend_arm_numeric_input?.addEventListener('input', (event) => {const extend_arm_value: number = Utility.parse_input_number(this.ui.dom_extend_arm_numeric_input?.value)if (this.ui.dom_extend_arm_range_input !== null) {- // Copy the value from the numeric onto the slider input.this.ui.dom_extend_arm_range_input.value = extend_arm_value.toString()}- this.warp_arm_amount = extend_arm_value-- this.rebuild_warped_animations()- this.play_animation(this.current_playing_index)+ this.update_a_pose_value(extend_arm_value)})+this.ui.dom_extend_arm_range_input?.addEventListener('input', (event) => {const extend_arm_value: number = Utility.parse_input_number(this.ui.dom_extend_arm_range_input?.value)if (this.ui.dom_extend_arm_numeric_input !== null) {- // Copy the value from the slider onto the numeric input.this.ui.dom_extend_arm_numeric_input.value = extend_arm_value.toString()}- this.warp_arm_amount = extend_arm_value-- this.rebuild_warped_animations()- this.play_animation(this.current_playing_index)+ this.update_a_pose_value(extend_arm_value)})// check for changes to mirror animations checkbox@@ -333,6 +338,13 @@ export class StepAnimationsListing extends EventTarget {this.has_added_event_listeners = true}+ // three different things might update this value: numeric input, range input, or reset button+ private update_a_pose_value (new_value: number): void {+ this.warp_arm_amount = new_value+ this.rebuild_warped_animations()+ this.play_animation(this.current_playing_index)+ }+public build_animation_clip_ui (animation_clips_to_load: AnimationClip[], theme_manager: ThemeManager): void {// Initialize AnimationSearch if not already done// we could switch skeleton types using navigation, so need to re-create in case this happensdiff --git a/src/lib/processes/edit-skeleton/StepEditSkeleton.ts b/src/lib/processes/edit-skeleton/StepEditSkeleton.tsindex e056e31..02c92c1 100644--- a/src/lib/processes/edit-skeleton/StepEditSkeleton.ts+++ b/src/lib/processes/edit-skeleton/StepEditSkeleton.ts@@ -108,6 +108,9 @@ export class StepEditSkeleton extends EventTarget {this.enable_head_weight_correction = false // force setting to false in case it was enabled before}}++ // show/hide settings for the head correct depending on if it is checked+ this.show_preview_plane_options()}public begin (main_scene: Scene, skeleton_type: SkeletonType): void {@@ -289,6 +292,8 @@ export class StepEditSkeleton extends EventTarget {this.ui.dom_preview_plane_checkbox?.addEventListener('change', (event) => {const target = event.target as HTMLInputElementthis.set_use_head_weight_correction(target.checked)++ this.show_preview_plane_options()})this.ui.dom_preview_plane_height_input?.addEventListener('input', (event) => {@@ -306,6 +311,12 @@ export class StepEditSkeleton extends EventTarget {})}+ private show_preview_plane_options (): void {+ if (this.ui.dom_preview_plane_setting_container !== null) {+ this.ui.dom_preview_plane_setting_container.style.display = this.use_head_weight_correction() ? 'flex' : 'none'+ }+ }+// returning back to edit skeleton step later will call this to reset undo statepublic clear_undo_history (): void {this.undo_redo_system.clear_history()diff --git a/src/lib/processes/load-skeleton/StepLoadSkeleton.ts b/src/lib/processes/load-skeleton/StepLoadSkeleton.tsindex 994fd8d..d1e32b0 100644--- a/src/lib/processes/load-skeleton/StepLoadSkeleton.ts+++ b/src/lib/processes/load-skeleton/StepLoadSkeleton.ts@@ -185,16 +185,28 @@ export class StepLoadSkeleton extends EventTarget {// scale skeleton controlsthis.ui.dom_scale_skeleton_input?.addEventListener('input', (event) => {// range sliders have rounding errors, so we round the value to avoid issues- this.skeleton_scale_percentage = parseFloat((event.target as HTMLInputElement).value)+ const new_value: number = Number((event.target as HTMLInputElement).value)+ this.update_skeleton_scale_to_value(new_value)+ })++ // reset the skeleton scale button+ this.ui.dom_reset_skeleton_scale_button?.addEventListener('click', () => {+ this.update_skeleton_scale_to_value(1.0)+ })+ }- const display_value: string = Math.round(this.skeleton_scale_percentage * 100).toString() + '%'- this.ui.dom_scale_skeleton_percentage_display!.textContent = display_value+ private update_skeleton_scale_to_value (new_value: number): void {+ this.skeleton_scale_percentage = Number(new_value)+ const display_value: string = Math.round(new_value * 100).toString() + '%'- // re-add the preview skeleton with the new scale- add_preview_skeleton(this._main_scene, this.skeleton_file_path(), this.hand_skeleton_type(), this.skeleton_scale_percentage).catch((err) => {+ if (this.ui.dom_scale_skeleton_percentage_display !== null) {+ this.ui.dom_scale_skeleton_percentage_display.textContent = display_value+ }+ // re-add the preview skeleton with the new scale+ add_preview_skeleton(this._main_scene, this.skeleton_file_path(), this.hand_skeleton_type(), this.skeleton_scale_percentage)+ .catch((err) => {console.error('error loading preview skeleton: ', err)})- })}public load_skeleton_file (file_path: string): void {