Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Don't pass in function for a constructor

Scott Petrovic0fce35847eab
diff --git a/src/retarget/TargetBoneTreeDialog.ts b/src/retarget/TargetBoneTreeDialog.ts
index 8342e50..bbf45e3 100644
--- a/src/retarget/TargetBoneTreeDialog.ts
+++ b/src/retarget/TargetBoneTreeDialog.ts
@@ -2,14 +2,10 @@ import { type Bone } from 'three'
import { ModalDialog } from '../lib/ModalDialog.ts'
export class TargetBoneTreeDialog {
- private readonly get_target_bones: () => Map<string, Bone>
+ private target_bones: Map<string, Bone> = new Map<string, Bone>()
private view_bone_tree_button: HTMLSpanElement | null = null
private has_added_event_listeners: boolean = false
- constructor (get_target_bones: () => Map<string, Bone>) {
- this.get_target_bones = get_target_bones
- }
-
public begin (): void {
this.view_bone_tree_button = document.getElementById('view-bone-tree-button') as HTMLSpanElement
@@ -22,8 +18,12 @@ export class TargetBoneTreeDialog {
}
}
+ public set_target_bones (target_bones: Map<string, Bone>): void {
+ this.target_bones = target_bones
+ }
+
public show (): void {
- const target_bones = this.get_target_bones()
+ const target_bones = this.target_bones
const root_target_bones = TargetBoneTreeDialog.get_root_bones(target_bones)
if (target_bones.size === 0) {
@@ -72,7 +72,7 @@ export class TargetBoneTreeDialog {
? `<ul>${child_bones.map((child_bone) => this.create_bone_tree_html(child_bone, target_bones)).join('')}</ul>`
: ''
- return `<li><span class="bone-tree-node-name">${this.escape_html(bone.name)}</span>${children_html}</li>`
+ return `<li>🦴<span class="bone-tree-node-name">${this.escape_html(bone.name)}</span>${children_html}</li>`
}
private static escape_html (value: string): string {
diff --git a/src/retarget/steps/StepLoadTargetModel.ts b/src/retarget/steps/StepLoadTargetModel.ts
index 0630de2..2c9eb6a 100644
--- a/src/retarget/steps/StepLoadTargetModel.ts
+++ b/src/retarget/steps/StepLoadTargetModel.ts
@@ -18,7 +18,7 @@ export class StepLoadTargetModel extends EventTarget {
constructor (mesh2motion_engine: Mesh2MotionEngine) {
super()
this.mesh2motion_engine = mesh2motion_engine
- this.target_bone_tree_dialog = new TargetBoneTreeDialog(() => this.get_unique_target_bones())
+ this.target_bone_tree_dialog = new TargetBoneTreeDialog()
}
public begin (): void {
@@ -48,6 +48,7 @@ export class StepLoadTargetModel extends EventTarget {
}
public show_target_bone_tree_dialog (): void {
+ this.target_bone_tree_dialog.set_target_bones(this.get_unique_target_bones())
this.target_bone_tree_dialog.show()
}
@@ -117,7 +118,7 @@ export class StepLoadTargetModel extends EventTarget {
this.mesh2motion_engine.get_scene().add(retargetable_meshes)
const largest_dimension: number = this.calculate_max_mesh_dimension(retargetable_meshes)
- // if the largest dimension is over 20, scale the entire scene down to be
+ // if the largest dimension is over 20, scale the entire scene down to be
const target_height: number = 1.5 // in meters
if (largest_dimension > 20) {
// calculate scale factor
@@ -136,6 +137,7 @@ export class StepLoadTargetModel extends EventTarget {
// Save the final retargetable meshes and dispatch event
this.retargetable_meshes = retargetable_meshes
+ this.target_bone_tree_dialog.set_target_bones(this.get_unique_target_bones())
this.dispatchEvent(new CustomEvent('target-model-loaded'))
}
}, { once: true })