Import a 3D Model and automatically assign and export animations
TypeScript
add support so model variations can expand/contract arms
Scott Petrovic12712269e576
diff --git a/src/lib/RigModelVariations.ts b/src/lib/RigModelVariations.tsindex 324b6d9..bc4e027 100644--- a/src/lib/RigModelVariations.ts+++ b/src/lib/RigModelVariations.ts@@ -3,6 +3,7 @@ interface VariationSpec {displayName: stringattribution?: stringlicense?: string+ expandArms?: number}export interface ModelVariation {@@ -11,7 +12,7 @@ export interface ModelVariation {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 dialoglicense: string // License string for this model variation, e.g. 'CC0', 'CC-SA 4.0'-+ expandArms: number // Explore page arm expansion value, default 0 for human rigs}function createVariation(type: string, spec: VariationSpec): ModelVariation {@@ -20,7 +21,8 @@ function createVariation(type: string, spec: VariationSpec): ModelVariation {display_name: spec.displayName,attribution: spec.attribution ?? '', // attribution only needed for CC-SA and CC-BYlicense: spec.license ?? 'CC0', // defaults to CC0 unless otherwise specified- preview_image: `models-variation/profiles/${spec.variant}.png` // all preview images are stored in the profiles folder+ preview_image: `models-variation/profiles/${spec.variant}.png`, // all preview images are stored in the profiles folder+ expandArms: spec.expandArms ?? 0 // default to 0 unless a human variation overrides it for the Explore page}}@@ -32,7 +34,7 @@ export const humanVariations: ModelVariation[] = [createVariation(HUMAN_TYPE, { variant: 'sophia', displayName: 'Sophia', attribution: 'Tysan Tan', license: 'CC-SA 4.0' }),createVariation(HUMAN_TYPE, { variant: 'jay', displayName: 'Jay', attribution: 'Blender Studio', license: 'CC-BY' }),createVariation(HUMAN_TYPE, { variant: 'sintel', displayName: 'Sintel', attribution: 'Blender Studio', license: 'CC-BY' }),- createVariation(HUMAN_TYPE, { variant: 'bunny', displayName: 'Bunny', attribution: 'Blender Studio', license: 'CC-BY' }),+ createVariation(HUMAN_TYPE, { variant: 'bunny', displayName: 'Bunny', attribution: 'Blender Studio', license: 'CC-BY', expandArms: -30 }),]const FOX_TYPE = 'fox'diff --git a/src/lib/Utilities.test.ts b/src/lib/Utilities.test.tsindex 8adbb62..cdff358 100644--- a/src/lib/Utilities.test.ts+++ b/src/lib/Utilities.test.ts@@ -1,5 +1,6 @@import { describe, it, expect } from 'vitest'import { Bone } from 'three'+import { ArmExtensionControl } from './processes/animations-listing/ArmExtensionControl'import { Utility } from './Utilities'/**@@ -38,3 +39,19 @@ describe('Utility.is_leaf_bone', () => {expect(Utility.is_leaf_bone(make_bone('upperarm_l'))).toBe(false)})})++describe('ArmExtensionControl.set_value', () => {+ it('stores the variation arm extension and notifies listeners', () => {+ const control = ArmExtensionControl.getInstance()+ let value = -1++ ;(control as any).on_change = (next_value: number) => {+ value = next_value+ }++ control.set_value(24)++ expect(control.value()).toBe(24)+ expect(value).toBe(24)+ })+})diff --git a/src/lib/processes/animations-listing/ArmExtensionControl.ts b/src/lib/processes/animations-listing/ArmExtensionControl.tsindex dd9ed27..8814d22 100644--- a/src/lib/processes/animations-listing/ArmExtensionControl.ts+++ b/src/lib/processes/animations-listing/ArmExtensionControl.ts@@ -53,6 +53,16 @@ export class ArmExtensionControl {return this.arm_extension_amount}+ /**+ * Set the arm extension value programmatically, including updating the UI and notifying listeners.+ * This is used when model variations on the Explore page specify a custom arm spread.+ */+ public set_value (new_value: number): void {+ this.arm_extension_amount = new_value+ this.update_input_elements(new_value)+ this.on_change?.(new_value)+ }+/*** Return the value and both inputs to zero without notifying the current listener.* Needed because the markup is static and survives leaving/re-entering a step.diff --git a/src/lib/processes/animations-listing/ModelVariationSwitcher.ts b/src/lib/processes/animations-listing/ModelVariationSwitcher.tsindex 33ed5a5..6259c26 100644--- a/src/lib/processes/animations-listing/ModelVariationSwitcher.ts+++ b/src/lib/processes/animations-listing/ModelVariationSwitcher.ts@@ -229,7 +229,7 @@ export class ModelVariationSwitcher extends EventTarget {})}- private load_variation_model (model_file: string): void {+ private load_variation_model (model_file: string, expand_arms: number = 0): void {this.show_loading_progress()this.loader.load(@@ -250,7 +250,7 @@ export class ModelVariationSwitcher extends EventTarget {this.normalize_skinned_meshes(skinned_meshes)this.dispatchEvent(new CustomEvent('variation-changed', {- detail: { model_file, skinned_meshes }+ detail: { model_file, skinned_meshes, expandArms: expand_arms }}))},(progress: ProgressEvent<EventTarget>) => {@@ -306,7 +306,7 @@ export class ModelVariationSwitcher extends EventTarget {this.confirmed_variation = this.pending_variationif (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)+ this.load_variation_model(this.confirmed_variation.model_file, this.confirmed_variation.expandArms)})// clicking on the overlay screen bg should also close/cancel the dialogdiff --git a/src/lib/processes/animations-listing/StepAnimationsListing.ts b/src/lib/processes/animations-listing/StepAnimationsListing.tsindex 6eac770..8710ed2 100644--- a/src/lib/processes/animations-listing/StepAnimationsListing.ts+++ b/src/lib/processes/animations-listing/StepAnimationsListing.ts@@ -192,6 +192,21 @@ export class StepAnimationsListing extends EventTarget {this.model_variation_switcher = switcher}+ /**+ * Applies the current arm-extension deformation for the active model variation+ * and immediately replays the current animation when the Explore page swaps models.+ */+ public apply_model_variation_arm_extension (value: number): void {+ this.arm_extension_control.set_value(value)++ if (this.animation_clips_loaded.length === 0) {+ return+ }++ this.rebuild_warped_animations()+ this.play_animation(this.current_playing_index)+ }+/*** Removes the current skinned meshes from the scene, adds the new ones,* and replays the current animation on them.diff --git a/src/marketing/MarketingBootstrap.ts b/src/marketing/MarketingBootstrap.tsindex 1f4d827..8b07d4c 100644--- a/src/marketing/MarketingBootstrap.ts+++ b/src/marketing/MarketingBootstrap.ts@@ -69,13 +69,16 @@ export class MarketingBootstrap {// when the user picks a different model variation, swap the skinned mesh in the scenethis.model_variation_switcher.addEventListener('variation-changed', ((event: CustomEvent) => {const skinned_meshes = event.detail.skinned_meshes as SkinnedMesh[]+ const expand_arms = Number(event.detail.expandArms ?? 0)+this.mesh2motion_engine.animations_listing_step.swap_skinned_meshes(this.mesh2motion_engine.scene, skinned_meshes)+ this.mesh2motion_engine.animations_listing_step.apply_model_variation_arm_extension(expand_arms)this.rebuild_skeleton_helper(skinned_meshes)this.apply_wireframe_to_skinned_meshes(skinned_meshes)-+}) as EventListener)// event after the DOM is fully loaded for HTML elements