Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Get initial loading done for marketing page

Scott Petrovicc73149ddd2dc
diff --git a/src/lib/processes/animations-listing/StepAnimationsListing.ts b/src/lib/processes/animations-listing/StepAnimationsListing.ts
index 089bbff..5bdded3 100644
--- a/src/lib/processes/animations-listing/StepAnimationsListing.ts
+++ b/src/lib/processes/animations-listing/StepAnimationsListing.ts
@@ -29,6 +29,8 @@ export class StepAnimationsListing extends EventTarget {
private current_playing_index: number = 0
private skeleton_type: SkeletonType = SkeletonType.Human
+ private animations_file_path: string = 'animations/'
+
// retrieved from load skeleton step
// we will use this to scale all position animation keyframes (uniform scale)
private skeleton_scale: number = 1.0
@@ -38,6 +40,10 @@ export class StepAnimationsListing extends EventTarget {
// Animation search functionality
public animation_search: AnimationSearch | null = null
+ public set_animations_file_path (path: string): void {
+ this.animations_file_path = path
+ }
+
/**
* The amount to raise the arms.
*/
@@ -118,21 +124,26 @@ export class StepAnimationsListing extends EventTarget {
let animations_to_load_filepaths: string[] = []
switch (this.skeleton_type) {
case SkeletonType.Human:
- animations_to_load_filepaths = ['animations/human-base-animations.glb', 'animations/human-addon-animations.glb']
+ animations_to_load_filepaths = [this.animations_file_path + 'human-base-animations.glb',
+ this.animations_file_path + 'human-addon-animations.glb']
break
case SkeletonType.Quadraped:
- animations_to_load_filepaths = ['animations/quad-creature-animations.glb']
+ animations_to_load_filepaths = [this.animations_file_path + 'quad-creature-animations.glb']
break
case SkeletonType.Bird:
- animations_to_load_filepaths = ['animations/bird-animations.glb']
+ animations_to_load_filepaths = [this.animations_file_path + 'bird-animations.glb']
break
case SkeletonType.Dragon:
- animations_to_load_filepaths = ['animations/dragon-animations.glb']
+ animations_to_load_filepaths = [this.animations_file_path + 'dragon-animations.glb']
break
default:
console.error('Unknown skeleton type for loading animations. Add GLB file to animation listing process')
}
+ // if we call this load animations externally (like marketing page)
+ // we might need to modify the location paths for these to reference the correct part
+
+
this.gltf_animation_loader = new GLTFLoader()
// The GLTF loader doesn't return a promise, so we need some way
diff --git a/src/lib/processes/load-skeleton/StepLoadSkeleton.ts b/src/lib/processes/load-skeleton/StepLoadSkeleton.ts
index 5d08804..994fd8d 100644
--- a/src/lib/processes/load-skeleton/StepLoadSkeleton.ts
+++ b/src/lib/processes/load-skeleton/StepLoadSkeleton.ts
@@ -21,10 +21,23 @@ export class StepLoadSkeleton extends EventTarget {
// to prevent large offsets
private skeleton_scale_percentage: number = 1.0
+ // this was invented since this value is stored on a DOM element
+ // this helps the marketing page set the type and doesn't rely on a DOM value
+ // probably could refactor this a bit to be cleaner later.
+ private manual_set_skeleton_type: SkeletonType = SkeletonType.None
+
public skeleton_type (): SkeletonType {
+ if (this.skeleton_file_path() === SkeletonType.None) {
+ return this.manual_set_skeleton_type
+ }
+
return this.skeleton_file_path() // this is actually the type/filepath combo
}
+ public set_skeleton_type (type: SkeletonType): void {
+ this.manual_set_skeleton_type = type
+ }
+
// The edit skeleton step will use this to scale the skeleton when loading editable skeleton
// animations listing will use this to scale all position keyframes
public skeleton_scale (): number {
@@ -155,46 +168,8 @@ export class StepLoadSkeleton extends EventTarget {
return
}
- // load skeleton from GLB file
- this.loader.load(this.skeleton_file_path(), (gltf: GLTFResult) => {
- // traverse scene and find first bone object
- // we will go to the parent and mark that as the original armature
- let armature_found = false
- let original_armature: Object3D = new Object3D()
-
- gltf.scene.traverse((child: Object3D) => {
- // Note: three.js removes punctuation characters from names object names like `-` and `.` for sanitization
- // Our 3D source files will need to account fo this if we are relying on that later for parsing
- // https://discourse.threejs.org/t/avoid-dots-and-colons-being-deleted-from-models-name/15304/2
- if (child.type === 'Bone' && !armature_found) {
- armature_found = true
-
- if (child.parent != null) {
- original_armature = child.parent
- } else {
- console.warn('could not find armature parent while loading skeleton')
- }
- }
- })
-
- this.loaded_armature = original_armature.clone()
- this.loaded_armature.name = 'Loaded Armature'
-
- // Apply hand skeleton modifications for human skeletons
- if (this.skeleton_file_path() === SkeletonType.Human) {
- const helper = new HandHelper()
- helper.modify_hand_skeleton(this.loaded_armature, this.hand_skeleton_type())
- }
-
- // reset the armature to 0,0,0 in case it is off for some reason
- this.loaded_armature.position.set(0, 0, 0)
- this.loaded_armature.updateWorldMatrix(true, true)
-
- // scale the armature to what we picked using the scale slider/preview
- this.loaded_armature.scale.set(this.skeleton_scale(), this.skeleton_scale(), this.skeleton_scale())
-
- this.dispatchEvent(new CustomEvent('skeletonLoaded', { detail: this.loaded_armature }))
- })
+ // add back loading information here
+ this.load_skeleton_file(this.skeleton_file_path())
})
}// end if statement
@@ -222,6 +197,49 @@ export class StepLoadSkeleton extends EventTarget {
})
}
+ public load_skeleton_file (file_path: string): void {
+ // load skeleton from GLB file
+ this.loader.load(file_path, (gltf: GLTFResult) => {
+ // traverse scene and find first bone object
+ // we will go to the parent and mark that as the original armature
+ let armature_found = false
+ let original_armature: Object3D = new Object3D()
+
+ gltf.scene.traverse((child: Object3D) => {
+ // Note: three.js removes punctuation characters from names object names like `-` and `.` for sanitization
+ // Our 3D source files will need to account fo this if we are relying on that later for parsing
+ // https://discourse.threejs.org/t/avoid-dots-and-colons-being-deleted-from-models-name/15304/2
+ if (child.type === 'Bone' && !armature_found) {
+ armature_found = true
+
+ if (child.parent != null) {
+ original_armature = child.parent
+ } else {
+ console.warn('could not find armature parent while loading skeleton')
+ }
+ }
+ })
+
+ this.loaded_armature = original_armature.clone()
+ this.loaded_armature.name = 'Loaded Armature'
+
+ // Apply hand skeleton modifications for human skeletons
+ if (this.skeleton_file_path() === SkeletonType.Human) {
+ const helper = new HandHelper()
+ helper.modify_hand_skeleton(this.loaded_armature, this.hand_skeleton_type())
+ }
+
+ // reset the armature to 0,0,0 in case it is off for some reason
+ this.loaded_armature.position.set(0, 0, 0)
+ this.loaded_armature.updateWorldMatrix(true, true)
+
+ // scale the armature to what we picked using the scale slider/preview
+ this.loaded_armature.scale.set(this.skeleton_scale(), this.skeleton_scale(), this.skeleton_scale())
+
+ this.dispatchEvent(new CustomEvent('skeletonLoaded', { detail: this.loaded_armature }))
+ })
+ }
+
private has_select_skeleton_ui_option (): boolean {
return this.ui.dom_skeleton_drop_type?.options[0].value === 'select-skeleton'
}
diff --git a/src/marketing/MarketingBootstrap.ts b/src/marketing/MarketingBootstrap.ts
index fac60c1..08fb9f4 100644
--- a/src/marketing/MarketingBootstrap.ts
+++ b/src/marketing/MarketingBootstrap.ts
@@ -1,3 +1,4 @@
+import { ProcessStep } from '../lib/enums/ProcessStep'
import { SkeletonType } from '../lib/enums/SkeletonType'
import { Mesh2MotionEngine } from '../Mesh2MotionEngine'
@@ -44,12 +45,15 @@ export class MarketingBootstrap {
this.setup_model_buttons()
this.mesh2motion_engine.load_model_step.addEventListener('modelLoaded', () => {
- console.log('model has been loaded')
-
- // load associated skeleton
- // ths (this.skeleton_type) value contains the filename for the skeleton rig
- // this.mesh2motion_engine.load_skeleton_step.load
-
+ // this (this.skeleton_type) value contains the filename for the skeleton rig
+ this.mesh2motion_engine.load_skeleton_step.load_skeleton_file('../' + this.skeleton_type)
+ this.mesh2motion_engine.load_skeleton_step.set_skeleton_type(this.skeleton_type)
+
+ this.mesh2motion_engine.load_skeleton_step.addEventListener('skeletonLoaded', () => {
+ // need to automatically finish the edit skeleton step and move onto the next step
+ this.mesh2motion_engine.animations_listing_step.set_animations_file_path('../animations/')
+ this.mesh2motion_engine.process_step_changed(ProcessStep.BindPose)
+ })
})
})
}