Import a 3D Model and automatically assign and export animations
TypeScript
Loading preview skeleton kind of works now
Scott Petrovicfdfa22732b81
diff --git a/src/index.html b/src/index.htmlindex 7144e14..c6284fb 100644--- a/src/index.html+++ b/src/index.html@@ -146,7 +146,7 @@<div style="display: flex; gap: 0.5rem;"><button class="secondary-button" id="action_back_to_load_model" >‹ Back</button>- <button id="load-skeleton-button">Load Skeleton ›</button>+ <button id="load-skeleton-button">Edit Skeleton ›</button></div>diff --git a/src/lib/enums/SkeletonType.ts b/src/lib/enums/SkeletonType.tsindex 0fc8fd7..4a271a7 100644--- a/src/lib/enums/SkeletonType.ts+++ b/src/lib/enums/SkeletonType.ts@@ -5,7 +5,7 @@ export enum SkeletonType {Human = 'skeletons/human-skeleton.glb',Bird = 'skeletons/skeleton-bird.glb',Error = 'ERROR',- None = 'None'+ None = 'NONE'}// Hand skeleton variation types for human skeletondiff --git a/src/lib/processes/load-skeleton/PreviewSkeletonManager.ts b/src/lib/processes/load-skeleton/PreviewSkeletonManager.tsindex 21a8e49..e67bb2f 100644--- a/src/lib/processes/load-skeleton/PreviewSkeletonManager.ts+++ b/src/lib/processes/load-skeleton/PreviewSkeletonManager.ts@@ -1,14 +1,14 @@-import { Group, Object3D, Object3DEventMap, SkeletonHelper, type Scene } from 'three'-import { GLTF, GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader'+import { Group, type Object3D, type Object3DEventMap, SkeletonHelper, type Scene } from 'three'+import { type GLTF, GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader'import type GLTFResult from './interfaces/GLTFResult'-import { type SkeletonType } from '../../enums/SkeletonType'+import { type HandSkeletonType, type SkeletonType } from '../../enums/SkeletonType'const skeleton_group_name: string = 'preview_skeleton_group'// need a function that will add a preview skeleton to the scene// this will remove any existing preview skeleton first// and then add the new one based on the selected type-export async function add_preview_skeleton (root: Scene, skeleton_file_path: SkeletonType): Promise<Object3D<Object3DEventMap>> {+export async function add_preview_skeleton (root: Scene, skeleton_file_path: SkeletonType, hand_skeleton_type: HandSkeletonType): Promise<Object3D<Object3DEventMap>> {remove_preview_skeleton(root)// create new group for the preview skeleton@@ -22,10 +22,14 @@ export async function add_preview_skeleton (root: Scene, skeleton_file_path: Ske// need some logic to load the actual skeleton based on the type// we can only see the skeleton helper, so jwe will add that to the groupconst loaded_scene: Object3D<Object3DEventMap> = await load_skeleton(skeleton_file_path)- loaded_scene.name = 'preview_skeleton'- preview_skeleton_group.add(loaded_scene)++ console.log('loaded skeleton file path: ', loaded_scene, hand_skeleton_type)++ // need to convert the loaded scene into a custom skeleton helper+ const skeleton_helper = new SkeletonHelper(loaded_scene.children[0])+ skeleton_helper.name = 'preview_skeleton'+ preview_skeleton_group.add(skeleton_helper)root.add(preview_skeleton_group)- console.log('loaded skeleton: ', loaded_scene)return loaded_scene}diff --git a/src/lib/processes/load-skeleton/StepLoadSkeleton.ts b/src/lib/processes/load-skeleton/StepLoadSkeleton.tsindex b71a005..658bb50 100644--- a/src/lib/processes/load-skeleton/StepLoadSkeleton.ts+++ b/src/lib/processes/load-skeleton/StepLoadSkeleton.ts@@ -4,7 +4,7 @@ import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'import { SkeletonType, HandSkeletonType } from '../../enums/SkeletonType.js'import type GLTFResult from './interfaces/GLTFResult.ts'import { add_origin_markers, remove_origin_markers } from './OriginMarkerManager'-import { add_preview_skeleton } from './PreviewSkeletonManager.ts'+import { add_preview_skeleton, remove_preview_skeleton } from './PreviewSkeletonManager.ts'// Note: EventTarget is a built-ininterface and do not need to import itexport class StepLoadSkeleton extends EventTarget {@@ -46,7 +46,7 @@ export class StepLoadSkeleton extends EventTarget {}// Initialize hand skeleton hand options visibility- this.toggle_hand_skeleton_options()+ this.toggle_ui_hand_skeleton_options()// add origin markers for debugging model loading issuesadd_origin_markers(this._main_scene)@@ -66,6 +66,7 @@ export class StepLoadSkeleton extends EventTarget {public dispose (): void {remove_origin_markers(this._main_scene)+ remove_preview_skeleton(this._main_scene)}private skeleton_file_path (): SkeletonType {@@ -82,21 +83,29 @@ export class StepLoadSkeleton extends EventTarget {return SkeletonType.Humancase 'bird':return SkeletonType.Bird+ case 'select-skeleton':+ return SkeletonType.Nonedefault:console.error('unknown skeleton type selected: ', skeleton_file)return SkeletonType.Error}}+ private hand_skeleton_type (): HandSkeletonType {+ const hand_selection = this.ui.dom_hand_skeleton_selection?.options+ return hand_selection[hand_selection.selectedIndex].value as HandSkeletonType+ }+private add_event_listeners (): void {// Add event listener for skeleton type changes to show/hide hand optionsif (this.ui.dom_skeleton_drop_type !== null) {this.ui.dom_skeleton_drop_type.addEventListener('change', () => {// get selected value from skeleton optionsconst skeleton_selection = this.ui.dom_skeleton_drop_type.options- this.skeleton_t = skeleton_selection[skeleton_selection.selectedIndex].value+ this.skeleton_t = skeleton_selection[skeleton_selection.selectedIndex].value as SkeletonType- this.toggle_hand_skeleton_options()+ // hand options only apply to human skeletons, so we need to show/hide when skeleton type changes+ this.toggle_ui_hand_skeleton_options()// remove the "select a skeleton" option if we picked something elseif (this.has_select_skeleton_ui_option()) {@@ -121,15 +130,8 @@ export class StepLoadSkeleton extends EventTarget {return}- // Get hand skeleton selection for human skeletons- if (this.skeleton_file_path() === SkeletonType.Human) {- const hand_selection = this.ui.dom_hand_skeleton_selection?.options- this.hand_skeleton_t = hand_selection[hand_selection.selectedIndex].value as HandSkeletonType- }-// load skeleton from GLB file- console.log('trying to load skeleton', this.skeleton_t)- this.loader.load(this.skeleton_t, (gltf: GLTFResult) => {+ 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 armaturelet armature_found = false@@ -155,7 +157,7 @@ export class StepLoadSkeleton extends EventTarget {// Apply hand skeleton modifications for human skeletonsif (this.skeleton_t === SkeletonType.Human) {- this.modify_hand_skeleton(this.loaded_armature, this.hand_skeleton_t)+ this.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@@ -166,6 +168,14 @@ export class StepLoadSkeleton extends EventTarget {})})}// end if statement++ // when hand skeleton type changes. update the preview skeleton+ this.ui.dom_hand_skeleton_selection?.addEventListener('change', () => {+ // rebuild the preview skeleton with the new hand skeleton type+ add_preview_skeleton(this._main_scene, this.skeleton_file_path(), this.hand_skeleton_type()).catch((err) => {+ console.error('error loading preview skeleton: ', err)+ })+ })}private has_select_skeleton_ui_option (): boolean {@@ -182,7 +192,7 @@ export class StepLoadSkeleton extends EventTarget {return this.loaded_armature}- private toggle_hand_skeleton_options (): void {+ private toggle_ui_hand_skeleton_options (): void {if (this.ui.dom_skeleton_drop_type === null || this.ui.dom_hand_skeleton_options === null) {return}