Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Keep track of selected bone when editing skeleton and show on UI

Scott Petrovic154eacf72502
diff --git a/src/index.html b/src/index.html
index d82ead9..8d4c22e 100644
--- a/src/index.html
+++ b/src/index.html
@@ -114,6 +114,7 @@
<p class="step-instructions">Right click on a joint to select and move it with controls.</p>
+ <p id="bone-selection-section">Selected Bone: <span id="edit-selected-bone-label">None</span></p>
<div class="styled-checkbox">
<input type="checkbox" id="mirror-skeleton" name="mirror-skeleton" value="mirror" checked>
diff --git a/src/lib/EventListeners.ts b/src/lib/EventListeners.ts
index caeb32d..e05d5b6 100644
--- a/src/lib/EventListeners.ts
+++ b/src/lib/EventListeners.ts
@@ -15,6 +15,12 @@ export class EventListeners {
this.bootstrap.renderer.domElement.addEventListener('mousedown', (event: MouseEvent) => {
this.bootstrap.handle_transform_controls_mouse_down(event)
+
+ // update UI with current bone name
+ if (this.bootstrap.ui.dom_selected_bone_label !== null) {
+ this.bootstrap.ui.dom_selected_bone_label.innerHTML =
+ this.bootstrap.edit_skeleton_step.get_currently_selected_bone().name
+ }
}, false)
if (this.bootstrap.transform_controls !== undefined) {
@@ -77,6 +83,10 @@ export class EventListeners {
this.bootstrap.process_step = this.bootstrap.process_step_changed(ProcessStep.EditSkeleton)
this.bootstrap.regenerate_skeleton_helper(this.bootstrap.edit_skeleton_step.skeleton())
this.bootstrap.load_model_step.model_meshes().visible = true
+
+ // reset current bone selection for edit skeleton step
+ this.bootstrap.edit_skeleton_step.set_currently_selected_bone(null)
+ this.bootstrap.ui.dom_selected_bone_label.innerHTML = 'None'
})
if (this.bootstrap.ui.dom_view_front_change !== null) {
diff --git a/src/lib/UI.ts b/src/lib/UI.ts
index c36b0a8..fa657c8 100644
--- a/src/lib/UI.ts
+++ b/src/lib/UI.ts
@@ -19,6 +19,8 @@ export class UI {
dom_bind_pose_button: HTMLButtonElement | null = null
dom_scale_skeleton_input_box: HTMLElement | null = null
dom_move_to_origin_button: HTMLButtonElement | null = null
+ dom_selected_bone_label: HTMLElement | null = null
+
dom_skinning_algorithm_selection: HTMLElement | null = null
dom_skinned_mesh_tools: HTMLElement | null = null
dom_skinned_mesh_animation_tools: HTMLElement | null = null
@@ -72,6 +74,8 @@ export class UI {
this.dom_mirror_skeleton_checkbox = document.querySelector('#mirror-skeleton')
this.dom_scale_skeleton_button = document.querySelector('#scale-skeleton-button')
+ this.dom_selected_bone_label = document.querySelector('#edit-selected-bone-label')
+
this.dom_bind_pose_button = document.querySelector('#action_bind_pose')
this.dom_scale_skeleton_input_box = document.querySelector('#scale-input')
this.dom_move_to_origin_button = document.querySelector('#action_move_to_origin')
diff --git a/src/lib/processes/StepEditSkeleton.ts b/src/lib/processes/StepEditSkeleton.ts
index 415cab7..eb76d36 100644
--- a/src/lib/processes/StepEditSkeleton.ts
+++ b/src/lib/processes/StepEditSkeleton.ts
@@ -24,6 +24,8 @@ export class StepEditSkeleton extends EventTarget {
private skinning_algorithm: string | null = null
private show_debug: boolean = true
+ private currently_selected_bone: Bone | null = null
+
constructor () {
super()
this.ui = new UI()
@@ -76,6 +78,19 @@ export class StepEditSkeleton extends EventTarget {
return this.show_debug
}
+ /**
+ * @param bone The currently selected bone
+ * @description This is the bone that is currently selected in the UI while editing
+ * the skeleton.
+ */
+ public set_currently_selected_bone (bone: Bone): void {
+ this.currently_selected_bone = bone
+ }
+
+ public get_currently_selected_bone (): Bone | null {
+ return this.currently_selected_bone
+ }
+
public set_mirror_mode_enabled (value: boolean): void {
this.mirror_mode_enabled = value
}
diff --git a/src/script.ts b/src/script.ts
index f5b9d9c..1ade1f7 100644
--- a/src/script.ts
+++ b/src/script.ts
@@ -246,7 +246,10 @@ export class Bootstrap {
if (closest_bone !== null) {
this.transform_controls.attach(closest_bone)
+ this.edit_skeleton_step.set_currently_selected_bone(closest_bone)
this.weight_skin_step.set_bone_index_to_test(closest_bone_index)
+ } else {
+ this.edit_skeleton_step.set_currently_selected_bone(null)
}
}
diff --git a/src/styles.css b/src/styles.css
index c36241c..e513966 100644
--- a/src/styles.css
+++ b/src/styles.css
@@ -409,4 +409,12 @@ input[type="file"] {
cursor: pointer; /* Make the label clickable */
padding: 0.2rem 0.5rem; /* Add padding for a larger clickable area */
font-size: 1rem; /* Adjust font size for better readability */
+}
+
+#bone-selection-section {
+ margin: 0;
+ background: #223031;
+ padding: 0.5rem;
+ border-radius: 3px;
+ color: #d5d5d5;
}
\ No newline at end of file