Import a 3D Model and automatically assign and export animations
TypeScript
Add loading progress bar for slower connections when changing models
Scott Petrovicdc69fdbca0e4
diff --git a/src/dialog.css b/src/dialog.cssindex 4f68314..008b4b5 100644--- a/src/dialog.css+++ b/src/dialog.css@@ -151,6 +151,8 @@.variation-license-chip {padding: 0.5rem 1.0rem;background: color-mix(in srgb, var(--text-alternate) 22%, var(--bg-primary));+ font-size: 90%;+ margin: 0;}.variation-license-chip:hover {background: color-mix(in srgb, var(--text-alternate) 32%, var(--bg-primary));@@ -160,6 +162,42 @@opacity: 0.7;}+.variation-loading-container {+ display: flex;+ flex-direction: column;+ gap: 0;+ margin: 0;+}++.variation-loading-track {+ width: 100%;+ background: var(--bg-alternate);+ border-radius: 4px;+ overflow: hidden;+ border: 1px solid var(--border-color);+ display: flex;+ flex-direction: row;+ gap: 1rem;+ align-items: center; /* vertical align */+}++.variation-loading-bar {+ flex: 1;+ height: 100%;+ background-color: var(--button-primary-bg);+ border-radius: 4px;+ transform: scaleX(0);+ transform-origin: left center;+ transition: transform 0.2s ease;+ display: block;+}++.variation-loading-text {+ color: var(--text-alternate);+ white-space: nowrap;+ flex-shrink: 0;+}+.variation-dialog-buttons {display: flex;justify-content: flex-end;diff --git a/src/index.html b/src/index.htmlindex 9b78b76..c1c3479 100644--- a/src/index.html+++ b/src/index.html@@ -239,8 +239,6 @@<!-- build version information--><span id="build-version"></span>--<!-- 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">@@ -248,6 +246,13 @@<div id="variation-grid" class="variation-grid"><!-- cards populated dynamically from RigConfig --></div>+ <div id="variation-loading-container" class="variation-loading-container" style="display: none">+ <div class="variation-loading-track">+ <span id="variation-loading-text" class="variation-loading-text">Loading model…</span>+ <div id="variation-loading-bar" class="variation-loading-bar"></div>+ </div>++ </div><div class="variation-dialog-buttons"><button id="variation-cancel-button" class="secondary-button">Cancel</button><button id="variation-confirm-button" disabled>Replace Model</button>diff --git a/src/lib/processes/animations-listing/ModelVariationSwitcher.ts b/src/lib/processes/animations-listing/ModelVariationSwitcher.tsindex 898f32c..f8d47a5 100644--- a/src/lib/processes/animations-listing/ModelVariationSwitcher.ts+++ b/src/lib/processes/animations-listing/ModelVariationSwitcher.ts@@ -31,6 +31,12 @@ export class ModelVariationSwitcher extends EventTarget {private pending_variation: ModelVariation | null = null // active selection (will be reset if user cancels out of dialog)+ // Loading progress bar elements within the dialog once confirmation happens. A few models are around 5MB which could take+ // a moment to load.+ private readonly dom_loading_container: HTMLElement | null = document.querySelector('#variation-loading-container')+ private readonly dom_loading_bar: HTMLElement | null = document.querySelector('#variation-loading-bar')+ private readonly dom_loading_text: HTMLElement | null = document.querySelector('#variation-loading-text')+// 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')@@ -197,10 +203,35 @@ export class ModelVariationSwitcher extends EventTarget {this.dom_dialog_overlay.style.display = 'none'}+ private show_loading_progress (): void {+ if (this.dom_loading_container !== null) this.dom_loading_container.style.display = ''+ if (this.dom_loading_bar !== null) this.dom_loading_bar.style.transform = 'scaleX(0)'+ if (this.dom_loading_text !== null) this.dom_loading_text.textContent = 'Loading model…'+ }++ private hide_loading_progress (): void {+ if (this.dom_loading_container !== null) this.dom_loading_container.style.display = 'none'+ if (this.dom_loading_bar !== null) this.dom_loading_bar.style.transform = 'scaleX(0)'+ }++ private update_loading_progress (percent: number): void {+ // the progress callback from the GLTF loader can fire frequently and the DOM never 'repaints' with the new values+ // this forces the DOM to update the new progress bar values immediately.+ requestAnimationFrame(() => {+ if (this.dom_loading_bar !== null) this.dom_loading_bar.style.transform = `scaleX(${percent / 100})`+ if (this.dom_loading_text !== null) this.dom_loading_text.textContent = `Loading model… ${Math.round(percent)}%`+ })+ }+private load_variation_model (model_file: string): void {+ this.show_loading_progress()+this.loader.load('../' + model_file,(gltf) => {+ this.hide_loading_progress()+ this.hide_dialog()+const skinned_meshes: SkinnedMesh[] = []gltf.scene.traverse((child) => {if (child instanceof SkinnedMesh) {@@ -216,9 +247,17 @@ export class ModelVariationSwitcher extends EventTarget {detail: { model_file, skinned_meshes }}))},- undefined,- (error) => {+ (progress: ProgressEvent<EventTarget>) => {+ if (progress.lengthComputable) {+ const percent = (progress.loaded / progress.total) * 100+ this.update_loading_progress(percent)+ }+ },+ (error: unknown) => {+ // this should never happen since we are only using application filesconsole.error('Failed to load model variation:', model_file, error)+ this.hide_loading_progress()+ if (this.dom_dialog_confirm_button !== null) this.dom_dialog_confirm_button.disabled = false})}@@ -259,7 +298,7 @@ export class ModelVariationSwitcher extends EventTarget {if (this.pending_variation === null) return // this shouldn't happen, but leave for a safe guardthis.confirmed_variation = this.pending_variation- this.hide_dialog()+ if (this.dom_dialog_confirm_button !== null) this.dom_dialog_confirm_button.disabled = truethis.update_active_model_info()this.load_variation_model(this.confirmed_variation.model_file)})diff --git a/src/marketing/marketing.css b/src/marketing/marketing.cssindex 687a655..4d9e3b3 100644--- a/src/marketing/marketing.css+++ b/src/marketing/marketing.css@@ -93,6 +93,5 @@ button.active-button {}#model-variation-info-attribution {- font-size: 0.75rem;opacity: 0.7;}\ No newline at end of file