Import a 3D Model and automatically assign and export animations
TypeScript
Start convert model variation selection into a dialog selection
Scott Petrovicb621a5e714e4
diff --git a/src/dialog.css b/src/dialog.cssindex 30f15f2..24820b7 100644--- a/src/dialog.css+++ b/src/dialog.css@@ -76,4 +76,62 @@width: 100%;aspect-ratio: 16 / 9;border: 0;+}++/* ── Model Variation Dialog ── */++.variation-dialog {+ max-width: 600px;+}++.variation-grid {+ display: grid;+ grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));+ gap: 1rem;+ padding: 1rem 0;+}++.variation-card {+ border: 2px solid var(--border-color);+ border-radius: 8px;+ padding: 0.75rem;+ cursor: pointer;+ text-align: center;+ transition: border-color 0.15s, box-shadow 0.15s;+ background: var(--bg-alternate);+}++.variation-card:hover {+ border-color: var(--text-primary);+}++.variation-card.selected {+ border-color: var(--accent-color, #4a9eff);+ box-shadow: 0 0 0 2px var(--accent-color, #4a9eff);+}++.variation-preview-image {+ width: 100%;+ aspect-ratio: 1;+ object-fit: contain;+ border-radius: 4px;+ background: var(--bg-primary);+ margin-bottom: 0.5rem;+}++.variation-name {+ font-weight: bold;+ margin-bottom: 0.25rem;+}++.variation-attribution {+ font-size: 0.85rem;+ opacity: 0.7;+}++.variation-dialog-buttons {+ display: flex;+ justify-content: flex-end;+ gap: 0.75rem;+ margin-top: 1rem;}\ No newline at end of filediff --git a/src/index.html b/src/index.htmlindex d2f95ee..0bada82 100644--- a/src/index.html+++ b/src/index.html@@ -128,10 +128,21 @@<!-- model variation switcher--><div id="model-variation-switcher">- <span>Model variation:</span>- <select id="model-variation-selection">- <!-- populated dynamically from RigConfig -->- </select>+ <button id="model-variation-button" class="secondary-button">Change Model</button>+ </div>++ <!-- model variation confirmation dialog (hidden by default) -->+ <div id="variation-dialog-overlay" class="modal-dialog-overlay" style="display: none">+ <div class="modal-dialog-content variation-dialog">+ <h2>Choose Model Variation</h2>+ <div id="variation-grid" class="variation-grid">+ <!-- cards populated dynamically from RigConfig -->+ </div>+ <div class="variation-dialog-buttons">+ <button id="variation-cancel-button" class="secondary-button">Cancel</button>+ <button id="variation-confirm-button" disabled>Confirm</button>+ </div>+ </div></div><span id="skinned-step-animation-export-options">diff --git a/src/lib/RigConfig.ts b/src/lib/RigConfig.tsindex e5ef753..8b0b055 100644--- a/src/lib/RigConfig.ts+++ b/src/lib/RigConfig.ts@@ -20,6 +20,7 @@ export interface ModelVariation {model_file: string // Model file path relative to the static root, e.g. 'models/model-human-a-pose.glb'display_name: string // Display name shown in the model dropdown, e.g. 'Human (A-Pose)'attribution: string // Free-form attribution text to be shown in the UI when this model variation is selected, e.g. 'Model by Artist Name'+ preview_image: string // Preview image path relative to the static root, shown in the variation selection dialog}/**@@ -45,17 +46,20 @@ export class RigConfig {{model_file: 'models-variation/human-base.glb',display_name: 'Mannequin',- attribution: 'Model by Quaternius, CC0-licensed'+ attribution: 'Model by Quaternius, CC0-licensed',+ preview_image: 'images/variations/human-mannequin.png'} satisfies ModelVariation,{model_file: 'models-variation/human-zombie.glb',display_name: 'Zombie',- attribution: 'Model by Kenney.nl, CC0-licensed'+ attribution: 'Model by Kenney.nl, CC0-licensed',+ preview_image: 'images/variations/human-zombie.png'} satisfies ModelVariation,{model_file: 'models-variation/human-sophia.glb',display_name: 'Sophia',- attribution: 'Art by Tysan Tan, CC-SA 4.0'+ attribution: 'Art by Tysan Tan, CC-SA 4.0',+ preview_image: 'images/variations/human-sophia.png'} satisfies ModelVariation]} satisfies RigConfigEntry,@@ -74,12 +78,14 @@ export class RigConfig {{model_file: 'models-variation/fox-base.glb',display_name: 'Fox',- attribution: 'None'+ attribution: 'None',+ preview_image: 'images/variations/fox-base.png'} satisfies ModelVariation,{model_file: 'models-variation/fox-horse.glb',display_name: 'Horse',- attribution: 'None'+ attribution: 'None',+ preview_image: 'images/variations/fox-horse.png'} satisfies ModelVariation]} satisfies RigConfigEntry,diff --git a/src/lib/processes/animations-listing/ModelVariationSwitcher.ts b/src/lib/processes/animations-listing/ModelVariationSwitcher.tsindex ef7f6e6..6a29d44 100644--- a/src/lib/processes/animations-listing/ModelVariationSwitcher.ts+++ b/src/lib/processes/animations-listing/ModelVariationSwitcher.ts@@ -1,23 +1,30 @@import { Skeleton, SkinnedMesh } from 'three'import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'-import { RigConfig, type RigConfigEntry } from '../../RigConfig'+import { RigConfig, type ModelVariation, type RigConfigEntry } from '../../RigConfig'import { type SkeletonType } from '../../enums/SkeletonType'/**- * Manages the model variation dropdown on the Explore page.+ * Manages the model variation selection on the Explore page.* When a rig type is selected that has model_variations in its RigConfig,- * the dropdown is populated and shown. Otherwise it is hidden.+ * a button is shown that opens a confirmation dialog with image previews+ * and attribution for each variation. Otherwise the button is hidden.*+ * The dialog HTML lives in index.html; this class populates and shows/hides it.* Loads the selected variation GLB and dispatches 'variation-changed'* with the extracted SkinnedMesh[] so consumers can swap the model directly.*/export class ModelVariationSwitcher extends EventTarget {private readonly dom_switcher: HTMLElement | null = document.querySelector('#model-variation-switcher')- private readonly dom_select: HTMLSelectElement | null = document.querySelector('#model-variation-selection')+ private readonly dom_button: HTMLButtonElement | null = document.querySelector('#model-variation-button')+ private readonly dom_dialog_overlay: HTMLElement | null = document.querySelector('#variation-dialog-overlay')+ private readonly dom_grid: HTMLElement | null = document.querySelector('#variation-grid')+ private readonly dom_confirm_button: HTMLButtonElement | null = document.querySelector('#variation-confirm-button')+ private readonly dom_cancel_button: HTMLButtonElement | null = document.querySelector('#variation-cancel-button')private readonly loader: GLTFLoader = new GLTFLoader()private current_rig: RigConfigEntry | undefinedprivate added_event_listeners = falseprivate _is_variation_active: boolean = false+ private selected_variation: ModelVariation | null = nullpublic get is_variation_active (): boolean {return this._is_variation_active@@ -29,18 +36,17 @@ export class ModelVariationSwitcher extends EventTarget {/*** Call this whenever the active rig type changes.- * Populates the variation dropdown if the rig has variations, otherwise hides it.+ * Shows the variation button if the rig has variations, otherwise hides it.*/public update_for_rig (skeleton_type: SkeletonType): void {this.current_rig = RigConfig.by_skeleton_type(skeleton_type)- this.populate_select()+ this.update_button_visibility()this.add_event_listeners()}- private populate_select (): void {+ private update_button_visibility (): void {const switcher = this.dom_switcher- const select = this.dom_select- if (switcher === null || select === null) return+ if (switcher === null) returnconst variations = this.current_rig?.model_variationsif (variations === undefined || variations.length === 0) {@@ -48,16 +54,66 @@ export class ModelVariationSwitcher extends EventTarget {return}- // clear any previous options and rebuild from RigConfig- select.innerHTML = ''+ switcher.style.display = '' // use default display style by removing inline style+ }++ private populate_grid (): void {+ const grid = this.dom_grid+ if (grid === null) return++ const variations = this.current_rig?.model_variations+ if (variations === undefined || variations.length === 0) return++ grid.innerHTML = ''+for (const variation of variations) {- const option = document.createElement('option')- option.value = variation.model_file- option.textContent = variation.display_name- select.appendChild(option)+ const card = document.createElement('div')+ card.className = 'variation-card'++ const img = document.createElement('img')+ img.src = '../' + variation.preview_image+ img.alt = variation.display_name+ img.className = 'variation-preview-image'+ card.appendChild(img)++ const name_el = document.createElement('div')+ name_el.className = 'variation-name'+ name_el.textContent = variation.display_name+ card.appendChild(name_el)++ if (variation.attribution !== 'None') {+ const attribution_el = document.createElement('div')+ attribution_el.className = 'variation-attribution'+ attribution_el.textContent = variation.attribution+ card.appendChild(attribution_el)+ }++ card.addEventListener('click', () => {+ grid.querySelectorAll('.variation-card').forEach(c => c.classList.remove('selected'))+ card.classList.add('selected')+ this.selected_variation = variation+ if (this.dom_confirm_button !== null) this.dom_confirm_button.disabled = false+ })++ grid.appendChild(card)}+ }- switcher.style.display = '' // use default display style by removing inline style+ private show_dialog (): void {+ if (this.dom_dialog_overlay === null) return++ this.selected_variation = null+ if (this.dom_confirm_button !== null) {+ this.dom_confirm_button.disabled = true+ }++ this.populate_grid()+ this.dom_dialog_overlay.style.display = '' // reset to default styling+ }++ private hide_dialog (): void {+ if (this.dom_dialog_overlay === null) return+ this.dom_dialog_overlay.style.display = 'none'}private load_variation_model (model_file: string): void {@@ -107,11 +163,24 @@ export class ModelVariationSwitcher extends EventTarget {if (this.added_event_listeners) returnthis.added_event_listeners = true- const select = this.dom_select- if (select === null) return+ this.dom_button?.addEventListener('click', () => {+ this.show_dialog()+ })++ this.dom_cancel_button?.addEventListener('click', () => {+ this.hide_dialog()+ })++ this.dom_confirm_button?.addEventListener('click', () => {+ if (this.selected_variation !== null) {+ this.hide_dialog()+ this.load_variation_model(this.selected_variation.model_file)+ }+ })- select.addEventListener('change', () => {- this.load_variation_model(select.value)+ // close on overlay click+ this.dom_dialog_overlay?.addEventListener('click', (e) => {+ if (e.target === this.dom_dialog_overlay) this.hide_dialog()})}}