Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

add preview images for props

Scott Petrovic9467a43af4d9
diff --git a/src/lib/processes/animations-listing/props/PropCatalog.ts b/src/lib/processes/animations-listing/props/PropCatalog.ts
index 7bf9507..77a3b77 100644
--- a/src/lib/processes/animations-listing/props/PropCatalog.ts
+++ b/src/lib/processes/animations-listing/props/PropCatalog.ts
@@ -20,6 +20,7 @@ export interface PropDefinition {
display_name: string
category: PropCategory
asset_path: string
+ preview_path: string
model_offset_y: number
default_mount_offsets: Record<PropSide, PropMountOffset>
rig_mount_offsets: Partial<Record<SkeletonType, Record<PropSide, PropMountOffset>>>
@@ -37,6 +38,7 @@ function create_definition (
display_name,
category,
asset_path: `props/${filename}`,
+ preview_path: `props/preview/${filename.replace(/\.glb$/, '.png')}`,
model_offset_y,
default_mount_offsets: {
[PropSide.Left]: { along_hand: 0.09, below_palm: 0.035, rotation: new Euler() },
diff --git a/src/lib/processes/animations-listing/props/PropsPanel.ts b/src/lib/processes/animations-listing/props/PropsPanel.ts
index 216c674..f5d982b 100644
--- a/src/lib/processes/animations-listing/props/PropsPanel.ts
+++ b/src/lib/processes/animations-listing/props/PropsPanel.ts
@@ -7,6 +7,7 @@ import { type PropSelection } from './PropSelection.ts'
export class PropsPanel extends EventTarget {
private readonly ui: UI = UI.getInstance()
private readonly selects = new Map<PropSide, HTMLSelectElement>()
+ private readonly previews = new Map<PropSide, HTMLImageElement>()
private dom_panel: HTMLElement | null = null
private added_event_listeners: boolean = false
@@ -37,7 +38,15 @@ export class PropsPanel extends EventTarget {
}
this.selects.set(side, select)
- select.addEventListener('change', () => { this.dispatch_selection_changed() })
+ const preview = mount.querySelector<HTMLImageElement>(`#props-${side}-hand-preview`)
+ if (preview !== null) {
+ this.previews.set(side, preview)
+ }
+
+ select.addEventListener('change', () => {
+ this.update_preview(side)
+ this.dispatch_selection_changed()
+ })
})
this.ui.dom_props_toggle_button?.addEventListener('click', () => {
@@ -82,6 +91,28 @@ export class PropsPanel extends EventTarget {
if (left_select !== undefined) { left_select.value = selection.left }
if (right_select !== undefined) { right_select.value = selection.right }
+
+ this.update_preview(PropSide.Left)
+ this.update_preview(PropSide.Right)
+ }
+
+ private update_preview (side: PropSide): void {
+ const preview = this.previews.get(side)
+ if (preview === undefined) {
+ return
+ }
+
+ const definition = PropCatalog.find(this.selected_prop(side))
+ if (definition === undefined) {
+ preview.removeAttribute('src')
+ preview.alt = ''
+ preview.hidden = true
+ return
+ }
+
+ preview.src = definition.preview_path
+ preview.alt = definition.display_name
+ preview.hidden = false
}
private set_expanded (is_expanded: boolean): void {
@@ -113,7 +144,12 @@ export class PropsPanel extends EventTarget {
return `
<label class="props-panel-row" for="props-${side}-hand-select">
<span>${label}</span>
- <select id="props-${side}-hand-select">${options_html}</select>
+ <span class="props-panel-control">
+ <span class="props-panel-preview">
+ <img id="props-${side}-hand-preview" alt="" hidden>
+ </span>
+ <select id="props-${side}-hand-select">${options_html}</select>
+ </span>
</label>
`
}
diff --git a/src/lib/processes/animations-listing/props/props.css b/src/lib/processes/animations-listing/props/props.css
index 66b92b6..ca6ffc6 100644
--- a/src/lib/processes/animations-listing/props/props.css
+++ b/src/lib/processes/animations-listing/props/props.css
@@ -51,6 +51,34 @@
color: var(--text-alternate);
}
+.props-panel-control {
+ display: flex;
+ align-items: center;
+ gap: 0.5rem;
+}
+
+.props-panel-preview {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ flex-shrink: 0;
+ width: 2.5rem;
+ height: 2.5rem;
+ border: 1px solid var(--bg-tertiary);
+ border-radius: 4px;
+ background: var(--bg-alternate);
+}
+
+.props-panel-preview img {
+ width: 100%;
+ height: 100%;
+ object-fit: contain;
+}
+
+.props-panel-preview img[hidden] {
+ display: none;
+}
+
.props-panel-row select {
min-width: 8rem;
}
diff --git a/static/props/preview/arrow_A.png b/static/props/preview/arrow_A.png
new file mode 100644
index 0000000..9d6cbae
Binary files /dev/null and b/static/props/preview/arrow_A.png differ
diff --git a/static/props/preview/arrow_B.png b/static/props/preview/arrow_B.png
new file mode 100644
index 0000000..0fceb09
Binary files /dev/null and b/static/props/preview/arrow_B.png differ
diff --git a/static/props/preview/axe_A.png b/static/props/preview/axe_A.png
new file mode 100644
index 0000000..b4934dc
Binary files /dev/null and b/static/props/preview/axe_A.png differ
diff --git a/static/props/preview/axe_B.png b/static/props/preview/axe_B.png
new file mode 100644
index 0000000..99ebeea
Binary files /dev/null and b/static/props/preview/axe_B.png differ
diff --git a/static/props/preview/axe_C.png b/static/props/preview/axe_C.png
new file mode 100644
index 0000000..e050fb7
Binary files /dev/null and b/static/props/preview/axe_C.png differ
diff --git a/static/props/preview/bow_A.png b/static/props/preview/bow_A.png
new file mode 100644
index 0000000..c7722b1
Binary files /dev/null and b/static/props/preview/bow_A.png differ
diff --git a/static/props/preview/bow_A_withString.png b/static/props/preview/bow_A_withString.png
new file mode 100644
index 0000000..b2701eb
Binary files /dev/null and b/static/props/preview/bow_A_withString.png differ
diff --git a/static/props/preview/bow_B.png b/static/props/preview/bow_B.png
new file mode 100644
index 0000000..830ce8e
Binary files /dev/null and b/static/props/preview/bow_B.png differ
diff --git a/static/props/preview/bow_B_withString.png b/static/props/preview/bow_B_withString.png
new file mode 100644
index 0000000..5f40a26
Binary files /dev/null and b/static/props/preview/bow_B_withString.png differ
diff --git a/static/props/preview/dagger_A.png b/static/props/preview/dagger_A.png
new file mode 100644
index 0000000..be46ddc
Binary files /dev/null and b/static/props/preview/dagger_A.png differ
diff --git a/static/props/preview/dagger_B.png b/static/props/preview/dagger_B.png
new file mode 100644
index 0000000..6362db8
Binary files /dev/null and b/static/props/preview/dagger_B.png differ
diff --git a/static/props/preview/fistweapon_A.png b/static/props/preview/fistweapon_A.png
new file mode 100644
index 0000000..cf6443d
Binary files /dev/null and b/static/props/preview/fistweapon_A.png differ
diff --git a/static/props/preview/fistweapon_A_stacked.png b/static/props/preview/fistweapon_A_stacked.png
new file mode 100644
index 0000000..0c5439b
Binary files /dev/null and b/static/props/preview/fistweapon_A_stacked.png differ
diff --git a/static/props/preview/fistweapon_B.png b/static/props/preview/fistweapon_B.png
new file mode 100644
index 0000000..06a7e4e
Binary files /dev/null and b/static/props/preview/fistweapon_B.png differ
diff --git a/static/props/preview/fistweapon_B_stacked.png b/static/props/preview/fistweapon_B_stacked.png
new file mode 100644
index 0000000..f574ca3
Binary files /dev/null and b/static/props/preview/fistweapon_B_stacked.png differ
diff --git a/static/props/preview/halberd.png b/static/props/preview/halberd.png
new file mode 100644
index 0000000..b3729d4
Binary files /dev/null and b/static/props/preview/halberd.png differ
diff --git a/static/props/preview/hammer_A.png b/static/props/preview/hammer_A.png
new file mode 100644
index 0000000..ff83a02
Binary files /dev/null and b/static/props/preview/hammer_A.png differ
diff --git a/static/props/preview/hammer_B.png b/static/props/preview/hammer_B.png
new file mode 100644
index 0000000..6bee10e
Binary files /dev/null and b/static/props/preview/hammer_B.png differ
diff --git a/static/props/preview/hammer_C.png b/static/props/preview/hammer_C.png
new file mode 100644
index 0000000..5ea8587
Binary files /dev/null and b/static/props/preview/hammer_C.png differ
diff --git a/static/props/preview/shield_A.png b/static/props/preview/shield_A.png
new file mode 100644
index 0000000..4bffdc6
Binary files /dev/null and b/static/props/preview/shield_A.png differ
diff --git a/static/props/preview/shield_B.png b/static/props/preview/shield_B.png
new file mode 100644
index 0000000..1163032
Binary files /dev/null and b/static/props/preview/shield_B.png differ
diff --git a/static/props/preview/shield_C.png b/static/props/preview/shield_C.png
new file mode 100644
index 0000000..d930338
Binary files /dev/null and b/static/props/preview/shield_C.png differ
diff --git a/static/props/preview/spear_A.png b/static/props/preview/spear_A.png
new file mode 100644
index 0000000..0f3e6ff
Binary files /dev/null and b/static/props/preview/spear_A.png differ
diff --git a/static/props/preview/staff_A.png b/static/props/preview/staff_A.png
new file mode 100644
index 0000000..6acd403
Binary files /dev/null and b/static/props/preview/staff_A.png differ
diff --git a/static/props/preview/staff_B.png b/static/props/preview/staff_B.png
new file mode 100644
index 0000000..1372d8c
Binary files /dev/null and b/static/props/preview/staff_B.png differ
diff --git a/static/props/preview/sword_A.png b/static/props/preview/sword_A.png
new file mode 100644
index 0000000..adf41b8
Binary files /dev/null and b/static/props/preview/sword_A.png differ
diff --git a/static/props/preview/sword_B.png b/static/props/preview/sword_B.png
new file mode 100644
index 0000000..909a393
Binary files /dev/null and b/static/props/preview/sword_B.png differ
diff --git a/static/props/preview/sword_C.png b/static/props/preview/sword_C.png
new file mode 100644
index 0000000..13234cc
Binary files /dev/null and b/static/props/preview/sword_C.png differ
diff --git a/static/props/preview/sword_D.png b/static/props/preview/sword_D.png
new file mode 100644
index 0000000..52f8db9
Binary files /dev/null and b/static/props/preview/sword_D.png differ
diff --git a/static/props/preview/sword_E.png b/static/props/preview/sword_E.png
new file mode 100644
index 0000000..c450135
Binary files /dev/null and b/static/props/preview/sword_E.png differ
diff --git a/static/props/preview/wand_A.png b/static/props/preview/wand_A.png
new file mode 100644
index 0000000..312b2fa
Binary files /dev/null and b/static/props/preview/wand_A.png differ