Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

small UI tweaks with weight painting

Scott Petroviccd1b34a36152
diff --git a/src/Mesh2MotionEngine.ts b/src/Mesh2MotionEngine.ts
index d040e67..c476f18 100644
--- a/src/Mesh2MotionEngine.ts
+++ b/src/Mesh2MotionEngine.ts
@@ -466,12 +466,12 @@ export class Mesh2MotionEngine {
}
/** Shows the bone the picker would select under the pointer. */
- public update_weight_paint_picker_hover (event: PointerEvent): void {
+ public update_weight_paint_picker_hover (event: PointerEvent, shift_pick_active: boolean = false): void {
if (this.process_step !== ProcessStep.WeightPainting) { return }
const intersection = this.weight_paint_intersection(event,
this.weight_painting_step.active_skinned_meshes())
- this.weight_painting_step.update_picker_hover(intersection)
+ this.weight_painting_step.update_picker_hover(intersection, shift_pick_active)
}
public handle_weight_paint_pointer_up (event: PointerEvent): void {
diff --git a/src/create.html b/src/create.html
index 61214a3..ecf97f9 100644
--- a/src/create.html
+++ b/src/create.html
@@ -416,11 +416,10 @@
<div style="display: flex; align-items: center; gap: 0.5rem;">
<button id="weight-paint-step-pick-bone" class="secondary-button" type="button" aria-pressed="false"
aria-label="Pick a bone by clicking the model"
- title="Pick a bone by clicking the model. Shortcut: Shift + click on the model."
data-tippy-content="Pick a bone by clicking the model. Shortcut: Shift + click on the model.">
<img src="images/icons/color-picker.svg" alt="" width="20" height="20" />
</button>
- <span id="weight-paint-step-bone-name" class="weight-paint-bone-name">&mdash;</span>
+ <select id="weight-paint-step-bone-name" class="weight-paint-bone-name" aria-label="Bone"></select>
</div>
</div>
diff --git a/src/lib/EventListeners.ts b/src/lib/EventListeners.ts
index 7fe60a2..f8ef1d0 100644
--- a/src/lib/EventListeners.ts
+++ b/src/lib/EventListeners.ts
@@ -16,8 +16,18 @@ export class EventListeners {
constructor (private readonly bootstrap: Mesh2MotionEngine) {}
- private update_weight_painting_cursor (): void {
- if (this.bootstrap.weight_painting_step.is_bone_picking_enabled()) {
+ /**
+ * Shift + click picks a bone while the brush is active, so holding Shift
+ * should look like the picker. Ignored mid-stroke so the stroke keeps painting.
+ */
+ private is_shift_pick_available (): boolean {
+ return this.bootstrap.process_step === ProcessStep.WeightPainting &&
+ this.bootstrap.weight_painting_step.is_draw_mode_active() &&
+ this.active_canvas_pointer_id === null
+ }
+
+ private update_weight_painting_cursor (shift_pick_active: boolean = false): void {
+ if (this.bootstrap.weight_painting_step.is_bone_picking_enabled() || shift_pick_active) {
const icon = document.querySelector<HTMLImageElement>('#weight-paint-step-pick-bone img')
let icon_url = 'images/icons/color-picker-cursor.svg'
if (icon !== null) {
@@ -170,7 +180,10 @@ export class EventListeners {
event.preventDefault()
event.stopImmediatePropagation()
- if (!weight_painting_step_picking) {
+ if (weight_painting_step_painting && event.shiftKey) {
+ // Shift + click picked a bone; keep the picker cursor until Shift is released
+ this.update_weight_painting_cursor(true)
+ } else if (!weight_painting_step_picking) {
this.bootstrap.renderer.domElement.style.cursor = 'crosshair'
}
this.active_canvas_pointer_id = event.pointerId
@@ -219,6 +232,12 @@ export class EventListeners {
return
}
event.preventDefault()
+ if (event.shiftKey && this.is_shift_pick_available()) {
+ this.bootstrap.weight_painting_step.hide_brush_cursor()
+ this.update_weight_painting_cursor(true)
+ this.bootstrap.update_weight_paint_picker_hover(event, true)
+ return
+ }
const over_mesh = this.active_canvas_pointer_id !== null
? this.bootstrap.handle_weight_paint_pointer_move(event)
: this.bootstrap.update_weight_paint_brush_cursor(event)
@@ -310,7 +329,7 @@ export class EventListeners {
this.active_canvas_pointer_id = null
this.bootstrap.ui.hide_selected_bone_overlay()
- this.update_weight_painting_cursor()
+ this.update_weight_painting_cursor(event.shiftKey && this.is_shift_pick_available())
})
document.addEventListener('pointercancel', (event: PointerEvent) => {
@@ -546,6 +565,23 @@ export class EventListeners {
}
})
+ // swap to/from the picker cursor as Shift is pressed, without waiting for a pointer move
+ const sync_shift_pick_cursor = (event: KeyboardEvent): void => {
+ if (event.key !== 'Shift' || this.is_typing_target(event.target)) { return }
+ if (!this.is_shift_pick_available() || !this.bootstrap.renderer.domElement.matches(':hover')) { return }
+
+ if (event.shiftKey) {
+ this.bootstrap.weight_painting_step.hide_brush_cursor()
+ this.update_weight_painting_cursor(true)
+ } else {
+ // the brush ring and crosshair come back on the next pointer move
+ this.bootstrap.weight_painting_step.hide_picker_hover()
+ this.update_weight_painting_cursor()
+ }
+ }
+ document.addEventListener('keydown', sync_shift_pick_cursor)
+ document.addEventListener('keyup', sync_shift_pick_cursor)
+
// Keyboard shortcuts for undo/redo
document.addEventListener('keydown', (event: KeyboardEvent) => {
const is_edit_step = this.bootstrap.process_step === ProcessStep.EditSkeleton
diff --git a/src/lib/processes/weight-painting/StepWeightPainting.ts b/src/lib/processes/weight-painting/StepWeightPainting.ts
index 2095ad3..60a384e 100644
--- a/src/lib/processes/weight-painting/StepWeightPainting.ts
+++ b/src/lib/processes/weight-painting/StepWeightPainting.ts
@@ -327,9 +327,11 @@ export class StepWeightPainting extends EventTarget {
/**
* While the picker is armed, show which bone is under the pointer before the
* user clicks. The engine feeds this with the current ray intersection.
+ * @param shift_pick_active true while Shift is held to pick without arming the picker
*/
- public update_picker_hover (intersection: Intersection | null): void {
- if (!this.is_active || this.active_mode !== 'paint' || !this.bone_picking_enabled) { return }
+ public update_picker_hover (intersection: Intersection | null, shift_pick_active: boolean = false): void {
+ if (!this.is_active || this.active_mode !== 'paint') { return }
+ if (!this.bone_picking_enabled && !shift_pick_active) { return }
if (intersection === null) {
this.hide_picker_hover()
return
@@ -355,11 +357,16 @@ export class StepWeightPainting extends EventTarget {
const best_bone_name = this.bone_name_at_intersection(intersection)
if (best_bone_name === null) { return }
- this.weight_paint_bone_name = best_bone_name
- this.update_bone_name_display()
- this.update_weight_paint_overlay_colors(best_bone_name)
+ this.select_bone(best_bone_name)
this.set_bone_picking_enabled(false)
- this.show_picked_bone_overlay(best_bone_name)
+ }
+
+ /** Make a bone the paint target, whether picked on the model or chosen from the list. */
+ private select_bone (bone_name: string): void {
+ this.weight_paint_bone_name = bone_name
+ this.update_bone_name_display()
+ this.update_weight_paint_overlay_colors(bone_name)
+ this.show_picked_bone_overlay(bone_name)
this.update_weight_paint_ui()
}
@@ -623,13 +630,19 @@ export class StepWeightPainting extends EventTarget {
: (this.bone_names[0] ?? null)
}
+ const select = document.getElementById('weight-paint-step-bone-name') as HTMLSelectElement | null
+ if (select !== null) {
+ select.replaceChildren(...this.bone_names.map(name => new Option(name, name)))
+ select.disabled = this.bone_names.length === 0
+ }
+
this.update_bone_name_display()
}
private update_bone_name_display (): void {
- const element = document.getElementById('weight-paint-step-bone-name')
- if (element !== null) {
- element.textContent = this.weight_paint_bone_name ?? '—'
+ const select = document.getElementById('weight-paint-step-bone-name') as HTMLSelectElement | null
+ if (select !== null) {
+ select.value = this.weight_paint_bone_name ?? ''
}
}
@@ -667,12 +680,7 @@ export class StepWeightPainting extends EventTarget {
private update_weight_paint_ui (): void {
const pick_button = document.getElementById('weight-paint-step-pick-bone') as HTMLButtonElement | null
if (pick_button !== null) {
- const pick_label = this.bone_picking_enabled
- ? 'Click a bone on the model'
- : 'Pick a bone by clicking the model (Shift + click for a quick switch)'
- pick_button.setAttribute('aria-pressed', String(this.bone_picking_enabled))
- pick_button.setAttribute('aria-label', pick_label)
- pick_button.title = pick_label
+
pick_button.disabled = this.skinned_meshes.length === 0 || this.bone_names.length === 0
}
@@ -810,7 +818,7 @@ export class StepWeightPainting extends EventTarget {
color: 0x8a8a8a,
wireframe: true,
transparent: true,
- opacity: 0.35,
+ opacity: 0.25,
depthWrite: false
})
material.toneMapped = false
@@ -932,6 +940,11 @@ export class StepWeightPainting extends EventTarget {
document.getElementById('weight-paint-step-pick-bone')?.addEventListener('click', () => {
this.set_bone_picking_enabled(!this.bone_picking_enabled)
})
+ // the picker can't reach bones without weights (e.g. pelvis), so the list covers every selectable bone
+ document.getElementById('weight-paint-step-bone-name')?.addEventListener('change', (event) => {
+ const bone_name = (event.target as HTMLSelectElement).value
+ if (this.bone_names.includes(bone_name)) { this.select_bone(bone_name) }
+ })
document.getElementById('weight-paint-step-mirror')?.addEventListener('change', (event) => {
if (this.weight_paint_brush === null) { return }
this.weight_paint_brush.mirror_enabled = (event.target as HTMLInputElement).checked
diff --git a/src/styles.css b/src/styles.css
index 45254b8..7bfe6b0 100644
--- a/src/styles.css
+++ b/src/styles.css
@@ -301,16 +301,13 @@ button.secondary-button.play:hover {
}
.weight-paint-tools-heading {
- font-size: 0.8rem;
- font-weight: 600;
- letter-spacing: 0.04em;
- text-transform: uppercase;
+
color: var(--text-secondary);
}
.weight-paint-bone-name {
- font-weight: bold;
- overflow-wrap: anywhere;
+ flex: 1;
+ min-width: 0;
}
.weight-paint-slider-row {