Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Show current model selection on UI

Scott Petrovic462001242b75
diff --git a/src/index.html b/src/index.html
index 9af4c63..9b78b76 100644
--- a/src/index.html
+++ b/src/index.html
@@ -128,7 +128,17 @@
<!-- model variation switcher-->
<div id="model-variation-switcher">
- <button id="model-variation-button" class="secondary-button">Change Model</button>
+ <div id="model-variation-info">
+ <img id="model-variation-info-image" src="" alt="" />
+ <div id="model-variation-info-details">
+ <span style="display: flex; flex-direction: row; gap: 0.5rem;">
+ <span id="model-variation-info-name"></span>
+ <span id="model-variation-info-license" class="variation-license-chip"></span>
+ </span>
+ <span id="model-variation-info-attribution"></span>
+ </div>
+ </div>
+ <button id="model-variation-button" class="secondary-button">Change</button>
</div>
diff --git a/src/lib/RigConfig.ts b/src/lib/RigConfig.ts
index 5c45622..a6ceaea 100644
--- a/src/lib/RigConfig.ts
+++ b/src/lib/RigConfig.ts
@@ -57,7 +57,7 @@ export class RigConfig {
display_name: 'Female Mannequin',
attribution: 'Quaternius',
license: 'CC0',
- preview_image: 'models-variation/profiles/mannequin.png'
+ preview_image: 'models-variation/profiles/mannequin-female.png'
} satisfies ModelVariation,
{
model_file: 'models-variation/human-zombie.glb',
diff --git a/src/lib/processes/animations-listing/ModelVariationSwitcher.ts b/src/lib/processes/animations-listing/ModelVariationSwitcher.ts
index eae9676..898f32c 100644
--- a/src/lib/processes/animations-listing/ModelVariationSwitcher.ts
+++ b/src/lib/processes/animations-listing/ModelVariationSwitcher.ts
@@ -6,7 +6,7 @@ import { type SkeletonType } from '../../enums/SkeletonType'
import { VariationLicenseCatalog } from '../../VariationLicenseInfo'
/**
- * Manages the model variation selection 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,
* a button is shown that opens a confirmation dialog with image previews
* and attribution for each variation. Otherwise the button is hidden.
@@ -16,12 +16,13 @@ import { VariationLicenseCatalog } from '../../VariationLicenseInfo'
* 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_change_model_button: HTMLButtonElement | null = document.querySelector('#model-variation-button')
+
+ // Dialog related DOM elements for switching the model with a popup dialog
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_dialog_confirm_button: HTMLButtonElement | null = document.querySelector('#variation-confirm-button')
private readonly dom_dialog_cancel_button: HTMLButtonElement | null = document.querySelector('#variation-cancel-button')
+
private readonly loader: GLTFLoader = new GLTFLoader()
private current_rig: RigConfigEntry | undefined
private added_event_listeners = false
@@ -29,6 +30,15 @@ export class ModelVariationSwitcher extends EventTarget {
private confirmed_variation: ModelVariation | null = null // model we currently have loaded
private pending_variation: ModelVariation | null = null // active selection (will be reset if user cancels out of dialog)
+
+ // UI elements on the explore page that show the currently selected variation's info. Used to populate current value.
+ private readonly dom_switcher: HTMLElement | null = document.querySelector('#model-variation-switcher')
+ private readonly dom_change_model_button: HTMLButtonElement | null = document.querySelector('#model-variation-button')
+ private readonly dom_info_image: HTMLImageElement | null = document.querySelector('#model-variation-info-image')
+ private readonly dom_info_name: HTMLElement | null = document.querySelector('#model-variation-info-name')
+ private readonly dom_info_license: HTMLElement | null = document.querySelector('#model-variation-info-license')
+ private readonly dom_info_attribution: HTMLElement | null = document.querySelector('#model-variation-info-attribution')
+
public get is_variation_active (): boolean {
return this._is_variation_active
}
@@ -50,6 +60,50 @@ export class ModelVariationSwitcher extends EventTarget {
const variations = this.current_rig?.model_variations
this.confirmed_variation = (variations !== undefined && variations.length > 0) ? variations[0] : null
this.pending_variation = this.confirmed_variation
+ this.update_active_model_info()
+ }
+
+ /**
+ * Updates the info section on the explore page to reflect the currently active variation.
+ * If no variation is active, hides the info section.
+ */
+ private update_active_model_info (): void {
+
+ // nothing selected for rig, or user cancelled out of dialog -> hide info section
+ if (this.confirmed_variation === null) {
+ if (this.dom_info_image !== null) this.dom_info_image.style.display = 'none'
+ if (this.dom_info_name !== null) this.dom_info_name.textContent = ''
+ if (this.dom_info_license !== null) this.dom_info_license.textContent = ''
+ return
+ }
+
+ // update image properties
+ if (this.dom_info_image !== null) {
+ this.dom_info_image.src = '../' + this.confirmed_variation.preview_image
+ this.dom_info_image.alt = this.confirmed_variation.display_name
+ this.dom_info_image.style.display = ''
+ }
+
+ // Update rig name
+ if (this.dom_info_name !== null) {
+ this.dom_info_name.textContent = this.confirmed_variation.display_name
+ }
+
+ // update license info
+ if (this.dom_info_license !== null) {
+ this.dom_info_license.textContent = this.confirmed_variation.license
+ }
+
+ // update attribution
+ if (this.dom_info_attribution !== null) {
+ if (this.confirmed_variation.attribution !== 'None') {
+ this.dom_info_attribution.textContent = this.confirmed_variation.attribution
+ this.dom_info_attribution.style.display = ''
+ } else {
+ this.dom_info_attribution.textContent = ''
+ this.dom_info_attribution.style.display = 'none'
+ }
+ }
}
private update_button_visibility (): void {
@@ -192,7 +246,7 @@ export class ModelVariationSwitcher extends EventTarget {
if (this.added_event_listeners) return
this.added_event_listeners = true
- this.dom_change_model_button?.addEventListener('click', () => {
+ this.dom_switcher?.addEventListener('click', () => {
this.show_dialog()
})
@@ -206,6 +260,7 @@ export class ModelVariationSwitcher extends EventTarget {
this.confirmed_variation = this.pending_variation
this.hide_dialog()
+ this.update_active_model_info()
this.load_variation_model(this.confirmed_variation.model_file)
})
diff --git a/src/marketing/marketing.css b/src/marketing/marketing.css
index c921d97..687a655 100644
--- a/src/marketing/marketing.css
+++ b/src/marketing/marketing.css
@@ -40,5 +40,59 @@ button.active-button {
}
#animation-listing-count {
- top: 1.87rem;
+ top: 5.8rem;
+ right: 2.5rem;
+}
+
+
+/* model switcher styles on the explore page */
+#model-variation-switcher {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ cursor: pointer;
+ border-radius: 8px;
+ box-sizing: border-box;
+ transition: background 0.15s;
+}
+
+#model-variation-switcher:hover {
+ background: color-mix(in srgb, var(--text-alternate) 12%, var(--bg-primary));
+}
+
+#model-variation-info {
+ display: flex;
+ align-items: center;
+ gap: 0.5rem;
+}
+
+#model-variation-info-image {
+ width: 40px;
+ height: 40px;
+ border-radius: 6px;
+ object-fit: cover;
+ background: var(--bg-primary);
+ filter: none !important;
+}
+
+#model-variation-info-details {
+ display: flex;
+ flex-direction: column;
+ gap: 0.15rem;
+}
+
+#model-variation-info-name {
+ font-weight: bold;
+ font-size: 0.9rem;
+}
+
+#model-variation-info-license {
+ font-size: 0.75rem;
+ padding: 0.1rem 0.4rem;
+ width: fit-content;
+}
+
+#model-variation-info-attribution {
+ font-size: 0.75rem;
+ opacity: 0.7;
}
\ No newline at end of file