Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

fix(retarget): bind arm extension controls when UI singleton is created before shared markup (#168)

叁suger017169ae6f75
diff --git a/src/Mesh2MotionEngine.ts b/src/Mesh2MotionEngine.ts
index 8806ccb..f9ebb32 100644
--- a/src/Mesh2MotionEngine.ts
+++ b/src/Mesh2MotionEngine.ts
@@ -961,6 +961,11 @@ export class Mesh2MotionEngine {
if (settings_dropdown_mount instanceof HTMLElement) {
DOMUtilities.populate_settings_dropdown(settings_dropdown_mount)
}
+
+ // the UI singleton may already exist at this point (the retarget module builds its
+ // PropsManager as a field initializer, before this engine), so it cached null refs for
+ // every element injected above. Re-query the DOM so those controls work.
+ UI.getInstance().initialize_dom_elements()
}
} // end Mesh2Motion Engine
diff --git a/src/lib/UI.ts b/src/lib/UI.ts
index 11ac9fa..a5922a4 100644
--- a/src/lib/UI.ts
+++ b/src/lib/UI.ts
@@ -137,7 +137,16 @@ export class UI {
return UI.instance
}
- private initialize_dom_elements (): void {
+ /**
+ * (Re)binds every DOM element reference on the singleton.
+ *
+ * Public and idempotent so callers can refresh after injecting shared HTML fragments.
+ * A module can create the UI instance before the shared markup exists (for example a
+ * field initializer such as `props_manager = new PropsManager()` runs before
+ * Mesh2MotionEngine populates the shared mounts), which leaves references such as the
+ * arm-extension inputs pointing at null. Those controls then silently bind no listeners.
+ */
+ public initialize_dom_elements (): void {
// grab all UI Elements from page that we need to interact with
this.dom_current_step_element = document.querySelector('#current-step-label')