Import a 3D Model and automatically assign and export animations
TypeScript
These DOM population stuff should not happen in the rig config file
Scott Petrovic8ff517ed78a5
diff --git a/src/lib/DOMUtilities.ts b/src/lib/DOMUtilities.tsnew file mode 100644index 0000000..1fed76a--- /dev/null+++ b/src/lib/DOMUtilities.ts@@ -0,0 +1,91 @@+import { RigConfig } from './RigConfig.ts'++export class DOMUtilities {+ /**+ * Populate a <select> with one <option> per rig using model display names.+ * Existing options are replaced.+ */+ static populate_model_select (select: HTMLSelectElement): void {+ select.innerHTML = ''++ // also import some custom models that are not the default models for a rig like an A-pose version of human+ const custom_models = [+ {+ model_file: 'test-files/bone-correction-tests/human-a-pose.glb',+ display_name: 'Human (A-Pose)'+ }+ ]++ // combine all the rigs with the custom models needed+ const model_options = [+ ...RigConfig.all.map((rig) => {+ return {+ model_file: rig.model_file,+ display_name: rig.rig_display_name+ }+ }),+ ...custom_models+ ]++ // build out HTML options+ for (const custom of model_options) {+ const option = document.createElement('option')+ option.value = custom.model_file+ option.textContent = custom.display_name+ select.appendChild(option)+ }+ }++ /**+ * Populate a <select> with one <option> per rig using skeleton display names.+ * Pass `include_placeholder = false` to omit the "Select a skeleton" entry.+ * Existing options are replaced.+ */+ static populate_skeleton_select (select: HTMLSelectElement, include_placeholder = true): void {+ select.innerHTML = ''+ if (include_placeholder) {+ const placeholder = document.createElement('option')+ placeholder.value = 'select-skeleton'+ placeholder.textContent = 'Select a skeleton'+ select.appendChild(placeholder)+ }+ for (const rig of RigConfig.all) {+ const option = document.createElement('option')+ option.value = rig.skeleton_type+ option.textContent = rig.rig_display_name+ select.appendChild(option)+ }+ }++ /** Video Preview HTML generation for Rig selection+ * Populate a <select> with one <option> per animation file across all rigs.+ * A placeholder option is always inserted first.+ */+ static populate_animation_file_select (select: HTMLSelectElement): void {+ // configure the select+ select.innerHTML = ''+ const placeholder = document.createElement('option')+ placeholder.value = ''++ // create first default option as placeholder/instructions+ placeholder.textContent = 'Pick a 3d animation to generate previews'+ select.appendChild(placeholder)++ // create all available animation options from GLB files in rig config+ for (const rig of RigConfig.all) {+ for (const file of rig.animation_files) {+ const option = document.createElement('option')+ option.value = file+ // derive a readable label from the filename, e.g. 'human-base-animations.glb' -> 'Human Base Animations'+ const label = file+ .replace(/\.\.\/animations\//i, '')+ .replace(/\.glb$/i, '')+ .split('-')+ .map(w => w.charAt(0).toUpperCase() + w.slice(1))+ .join(' ')+ option.textContent = label+ select.appendChild(option)+ }+ }+ }+}diff --git a/src/lib/RigConfig.ts b/src/lib/RigConfig.tsindex 823bd54..551bad5 100644--- a/src/lib/RigConfig.ts+++ b/src/lib/RigConfig.ts@@ -137,91 +137,4 @@ export class RigConfig {return config.animation_files}- /**- * Populate a <select> with one <option> per rig using model display names.- * Existing options are replaced.- */- static populate_model_select (select: HTMLSelectElement): void {- select.innerHTML = ''-- // also import some custom models that are not the default models for a rig like an A-pose version of human- const custom_models = [- {- model_file: 'test-files/bone-correction-tests/human-a-pose.glb',- display_name: 'Human (A-Pose)'- }- ]-- // combine all the rigs with the custom models needed- const model_options = [- ...this.all.map((rig) => {- return {- model_file: rig.model_file,- display_name: rig.rig_display_name- }- }),- ...custom_models- ]-- // build out HTML options- for (const custom of model_options) {- const option = document.createElement('option')- option.value = custom.model_file- option.textContent = custom.display_name- select.appendChild(option)- }- }-- /**- * Populate a <select> with one <option> per rig using skeleton display names.- * Pass `include_placeholder = false` to omit the "Select a skeleton" entry.- * Existing options are replaced.- */- static populate_skeleton_select (select: HTMLSelectElement, include_placeholder = true): void {- select.innerHTML = ''- if (include_placeholder) {- const placeholder = document.createElement('option')- placeholder.value = 'select-skeleton'- placeholder.textContent = 'Select a skeleton'- select.appendChild(placeholder)- }- for (const rig of this.all) {- const option = document.createElement('option')- option.value = rig.skeleton_type- option.textContent = rig.rig_display_name- select.appendChild(option)- }- }-- /** Video Preview HTML generation for Rig selection- * Populate a <select> with one <option> per animation file across all rigs.- * A placeholder option is always inserted first.- */- static populate_animation_file_select (select: HTMLSelectElement): void {- // configure the select- select.innerHTML = ''- const placeholder = document.createElement('option')- placeholder.value = ''-- // create first default option as placeholder/instructions- placeholder.textContent = 'Pick a 3d animation to generate previews'- select.appendChild(placeholder)-- // create all available animation options from GLB files in rig config- for (const rig of this.all) {- for (const file of rig.animation_files) {- const option = document.createElement('option')- option.value = file- // derive a readable label from the filename, e.g. 'human-base-animations.glb' -> 'Human Base Animations'- const label = file- .replace(/\.\.\/animations\//i, '')- .replace(/\.glb$/i, '')- .split('-')- .map(w => w.charAt(0).toUpperCase() + w.slice(1))- .join(' ')- option.textContent = label- select.appendChild(option)- }- }- }}diff --git a/src/lib/processes/load-model/StepLoadModel.ts b/src/lib/processes/load-model/StepLoadModel.tsindex c6dd110..765df3f 100644--- a/src/lib/processes/load-model/StepLoadModel.ts+++ b/src/lib/processes/load-model/StepLoadModel.ts@@ -2,7 +2,7 @@ import { UI } from '../../UI.ts'import { ModelZipLoader } from './ModelZipLoader.ts'import { CustomFBXLoader, type FBXResults } from './CustomFBXLoader.ts'import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'-import { RigConfig } from '../../RigConfig.ts'+import { DOMUtilities } from '../../DOMUtilities.ts'import { Scene } from 'three/src/scenes/Scene.js'import { Mesh } from 'three/src/objects/Mesh.js'@@ -160,7 +160,7 @@ export class StepLoadModel extends EventTarget {// Populate the model reference dropdown from the central rig configconst model_select = document.querySelector<HTMLSelectElement>('#model-selection')if (model_select !== null) {- RigConfig.populate_model_select(model_select)+ DOMUtilities.populate_model_select(model_select)}if (this.ui.dom_upload_model_button !== null) {diff --git a/src/lib/processes/load-skeleton/StepLoadSkeleton.ts b/src/lib/processes/load-skeleton/StepLoadSkeleton.tsindex fed2aa2..a426354 100644--- a/src/lib/processes/load-skeleton/StepLoadSkeleton.ts+++ b/src/lib/processes/load-skeleton/StepLoadSkeleton.ts@@ -3,6 +3,7 @@ import { Object3D, type Scene, type Object3DEventMap } from 'three'import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'import { SkeletonType, type HandSkeletonType } from '../../enums/SkeletonType.js'import { RigConfig } from '../../RigConfig.ts'+import { DOMUtilities } from '../../DOMUtilities.ts'import type GLTFResult from './interfaces/GLTFResult.ts'import { add_origin_markers, remove_origin_markers } from './OriginMarkerManager'import { add_preview_skeleton, remove_preview_skeleton } from './PreviewSkeletonManager.ts'@@ -122,7 +123,7 @@ export class StepLoadSkeleton extends EventTarget {private add_event_listeners (): void {// Populate the skeleton template dropdown from the central rig configif (this.ui.dom_skeleton_drop_type !== null) {- RigConfig.populate_skeleton_select(this.ui.dom_skeleton_drop_type)+ DOMUtilities.populate_skeleton_select(this.ui.dom_skeleton_drop_type)}// Add event listener for skeleton type changes to show/hide hand optionsdiff --git a/src/preview-generator/preview-generator.ts b/src/preview-generator/preview-generator.tsindex fc5427a..e31b023 100644--- a/src/preview-generator/preview-generator.ts+++ b/src/preview-generator/preview-generator.ts@@ -9,7 +9,7 @@ import JSZip from 'jszip'import { Generators } from '../lib/Generators.ts'import { ThemeManager } from '../lib/ThemeManager.ts'import { AnimationUtility } from '../lib/processes/animations-listing/AnimationUtility.ts'-import { RigConfig } from '../lib/RigConfig.ts'+import { DOMUtilities } from '../lib/DOMUtilities.ts'import { SkeletonType } from '../lib/enums/SkeletonType.ts'class PreviewGenerator {@@ -231,7 +231,7 @@ const app = new PreviewGenerator()// Populate animation file dropdown from central rig configconst animation_file_dropdown = document.getElementById('animation-file-dropdown') as HTMLSelectElement | nullif (animation_file_dropdown !== null) {- RigConfig.populate_animation_file_select(animation_file_dropdown)+ DOMUtilities.populate_animation_file_select(animation_file_dropdown)}// look out for select changediff --git a/src/retarget/steps/StepLoadSourceSkeleton.ts b/src/retarget/steps/StepLoadSourceSkeleton.tsindex 8d6af81..4364c88 100644--- a/src/retarget/steps/StepLoadSourceSkeleton.ts+++ b/src/retarget/steps/StepLoadSourceSkeleton.ts@@ -2,6 +2,7 @@ import { Group, Object3D, Scene, SkeletonHelper } from 'three'import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'import { SkeletonType } from '../../lib/enums/SkeletonType.ts'import { RigConfig } from '../../lib/RigConfig.ts'+import { DOMUtilities } from '../../lib/DOMUtilities.ts'import type GLTFResult from '../../lib/processes/load-skeleton/interfaces/GLTFResult.ts'import { ModalDialog } from '../../lib/ModalDialog.ts'@@ -28,7 +29,7 @@ export class StepLoadSourceSkeleton extends EventTarget {// Populate the skeleton dropdown from the central rig config (no placeholder needed)if (this.skeleton_type_select !== null) {- RigConfig.populate_skeleton_select(this.skeleton_type_select, false)+ DOMUtilities.populate_skeleton_select(this.skeleton_type_select, false)}if (!this._added_event_listeners) {