Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Have shared area that renders common DOM elements between pages

Scott Petrovic6c3fc1202ad4
diff --git a/src/Mesh2MotionEngine.ts b/src/Mesh2MotionEngine.ts
index 1b7037b..010364e 100644
--- a/src/Mesh2MotionEngine.ts
+++ b/src/Mesh2MotionEngine.ts
@@ -82,10 +82,7 @@ export class Mesh2MotionEngine {
private readonly camera_shake: CameraShake
constructor () {
- const settings_dropdown_mount = document.querySelector('#settings-dropdown-mount')
- if (settings_dropdown_mount instanceof HTMLElement) {
- DOMUtilities.populate_settings_dropdown(settings_dropdown_mount)
- }
+ this.initialize_shared_dom_mounts()
this.eventListeners = new EventListeners(this)
// helps resolve requestAnimationFrame calling animate() with wrong context
@@ -665,4 +662,33 @@ export class Mesh2MotionEngine {
public show_learning_resources_dialog (): void {
new ModalDialog('Learning Resources', Generators.get_learning_resources_html()).show()
}
+
+
+ /**
+ * Populate shared HTML fragments that are reused across app pages.
+ * This runs before UI/Theme initialization so expected DOM IDs exist
+ * when singleton classes bind their element references and listeners.
+ */
+ private initialize_shared_dom_mounts (): void {
+ const top_nav_links_mount = document.querySelector('#top-nav-links-mount')
+ if (top_nav_links_mount instanceof HTMLElement) {
+ DOMUtilities.populate_top_nav_links(top_nav_links_mount)
+ }
+
+ const header_ui_mount = document.querySelector('#header-ui-mount')
+ if (header_ui_mount instanceof HTMLElement) {
+ DOMUtilities.populate_header_controls(header_ui_mount)
+ }
+
+ const animation_player_mount = document.querySelector('#animation-player-mount')
+ if (animation_player_mount instanceof HTMLElement) {
+ DOMUtilities.populate_animation_player(animation_player_mount)
+ }
+
+ const settings_dropdown_mount = document.querySelector('#settings-dropdown-mount')
+ if (settings_dropdown_mount instanceof HTMLElement) {
+ DOMUtilities.populate_settings_dropdown(settings_dropdown_mount)
+ }
+ }
+
} // end Mesh2Motion Engine
diff --git a/src/create.html b/src/create.html
index 8488537..6ea7907 100644
--- a/src/create.html
+++ b/src/create.html
@@ -39,47 +39,11 @@
</div>
<div style="display: inline-flex; align-items: center;">
- <a href="#" id="learn-link">Learn</a>
- <a href="#" id="attribution-link">Contributors</a>
- <a href="https://support.mesh2motion.org" target="_blank">πŸ’—</a>
- <a href="https://github.com/scottpetrovic/mesh2motion-app" target="_blank">
- <img src="../images/github-white-icon.png" width="24" height="24" alt="GitHub" />
- </a>
-
-
- <div id="settings-dropdown-mount"></div>
-
+ <div id="top-nav-links-mount"></div>
</div>
</nav>
- <!-- Top toolbar with mouse controls -->
- <div id="header-ui">
- <div>
- <img
- class="nav-icon"
- src="/images/mouse-left.svg"
- style="vertical-align: middle"
- />
- Rotate
- </div>
-
- <div>
- <img
- class="nav-icon"
- src="/images/mouse-right.svg"
- style="vertical-align: middle"
- />
- Pan
- </div>
- <div>
- <img
- class="nav-icon"
- src="/images/mouse-middle.svg"
- style="vertical-align: middle"
- />
- Zoom
- </div>
- </div>
+ <div id="header-ui-mount"></div>
<div id="tool-panel">
<!-- create a radio button group. There are two options. Move Skeleton, Rotate Mesh -->
@@ -523,57 +487,7 @@
</div>
<!-- end tool-panel-->
- <!-- Free-floating Animation Player -->
- <div id="animation-player">
- <div id="current-animation-container">
- <span id="current-animation-name">No animation selected</span>
- </div>
- <div id="play-controls">
- <button
- id="play-pause-button"
- class="animation-control-button"
- disabled
- >
- <span class="material-symbols-outlined">play_arrow</span>
- </button>
- <span>
- <span id="current-time">0f</span> /
- <span id="total-time">0f</span>
- </span>
- <input
- type="range"
- id="animation-scrubber"
- min="0"
- max="100"
- value="0"
- disabled
- />
-
- <!-- checkbox option to show skeleton -->
- <div id="skeleton-toggle" class="styled-checkbox icon-toggle">
- <input
- type="checkbox"
- id="show-skeleton-checkbox"
- name="show-skeleton"
- value="show"
- style="display: none"
- />
- <label
- for="show-skeleton-checkbox"
- data-tippy-content="Show skeleton"
- tabindex="0"
- style="border-radius: 0"
- >
- <img
- src="../images/icons/bone-display.svg"
- class="action-icon"
- alt="Show skeleton"
- style="user-select: none"
- />
- </label>
- </div>
- </div>
- </div>
+ <div id="animation-player-mount"></div>
<!-- 3d view controls shown on bottom right. This helps with click events -->
<div id="view-control-hitbox"></div>
diff --git a/src/index.html b/src/index.html
index a16fb0c..dec21a0 100644
--- a/src/index.html
+++ b/src/index.html
@@ -30,33 +30,11 @@
</div>
<div style="display: inline-flex; align-items: center;">
- <a href="#" id="learn-link">Learn</a>
- <a href="#" id="attribution-link">Contributors</a>
- <a href="https://support.mesh2motion.org" target="_blank">πŸ’—</a>
- <a href="https://github.com/scottpetrovic/mesh2motion-app" target="_blank">
- <img src="../images/github-white-icon.png" width="24" height="24" alt="GitHub" />
- </a>
-
- <div id="settings-dropdown-mount"></div>
+ <div id="top-nav-links-mount"></div>
</div>
</nav>
- <!-- Top toolbar with mouse controls -->
- <div id="header-ui">
-
-
-
- <div>
- <img src="/images/mouse-left.svg" class="nav-icon" style="vertical-align: middle;"/> Rotate
- </div>
-
- <div>
- <img src="/images/mouse-right.svg" class="nav-icon" style="vertical-align: middle;"/> Pan
- </div>
- <div>
- <img src="/images/mouse-middle.svg" class="nav-icon" style="vertical-align: middle;"/> Zoom
- </div>
- </div>
+ <div id="header-ui-mount"></div>
<div class="model-selection-section">
<!-- populated dynamically from RigConfig -->
@@ -217,34 +195,7 @@
</div> <!-- end tool-panel-->
- <!-- Free-floating Animation Player -->
- <div id="animation-player">
- <div id="current-animation-container">
- <span id="current-animation-name">No animation selected</span>
- </div>
- <div id="play-controls">
- <button id="play-pause-button" class="animation-control-button" disabled>
- <span class="material-symbols-outlined">play_arrow</span>
- </button>
- <span>
- <span id="current-time">0f</span> /
- <span id="total-time">0f</span>
- </span>
- <input type="range" id="animation-scrubber" min="0" max="100" value="0" step="any" disabled>
-
-
- <!-- checkbox option to show skeleton -->
- <div id="skeleton-toggle" class="styled-checkbox icon-toggle" >
- <input type="checkbox" id="show-skeleton-checkbox" name="show-skeleton" value="show" style="display:none;">
- <label for="show-skeleton-checkbox" data-tippy-content="Show skeleton" tabindex="0" style="border-radius: 0">
- <img src="../images/icons/bone-display.svg" class="action-icon" alt="Show skeleton" style="user-select: none;" />
- </label>
- </div>
- </div>
-
-
-
- </div>
+ <div id="animation-player-mount"></div>
<!-- 3d view control hit box. It is just a container to help with 3d view controls. -->
diff --git a/src/lib/DOMUtilities.ts b/src/lib/DOMUtilities.ts
index 327d6ab..fc026bc 100644
--- a/src/lib/DOMUtilities.ts
+++ b/src/lib/DOMUtilities.ts
@@ -14,7 +14,19 @@ interface SettingsDefaultsConfig {
solid_background_enabled: boolean
}
+interface TopNavLinksConfig {
+ support_href: string
+ github_href: string
+ github_icon_src: string
+}
+
export class DOMUtilities {
+ static readonly top_nav_links: TopNavLinksConfig = {
+ support_href: 'https://support.mesh2motion.org',
+ github_href: 'https://github.com/scottpetrovic/mesh2motion-app',
+ github_icon_src: '../images/github-white-icon.png'
+ }
+
static readonly settings_defaults: SettingsDefaultsConfig = {
light_intensity: {
min: '0.1',
@@ -32,12 +44,94 @@ export class DOMUtilities {
solid_background_enabled: false
}
+ /**
+ * Render shared top-right navigation links into the provided mount element.
+ */
+ static populate_top_nav_links (mount: HTMLElement): void {
+ const nav_links = DOMUtilities.top_nav_links
+
+ // Keep mount behavior consistent with original inline nav structure.
+ mount.style.display = 'inline-flex'
+ mount.style.alignItems = 'center'
+
+ mount.innerHTML = `
+ <a href="#" id="learn-link">Learn</a>
+ <a href="#" id="attribution-link">Contributors</a>
+ <a href="${nav_links.support_href}" target="_blank">πŸ’—</a>
+ <a href="${nav_links.github_href}" target="_blank">
+ <img src="${nav_links.github_icon_src}" width="24" height="24" alt="GitHub" />
+ </a>
+ <span id="settings-dropdown-mount"></span>
+ `
+ }
+
+ /**
+ * Render shared viewport mouse control hints into the provided mount element.
+ */
+ static populate_header_controls (mount: HTMLElement): void {
+ mount.innerHTML = `
+ <div id="header-ui">
+ <div>
+ <img class="nav-icon" src="/images/mouse-left.svg" style="vertical-align: middle" />
+ Rotate
+ </div>
+
+ <div>
+ <img class="nav-icon" src="/images/mouse-right.svg" style="vertical-align: middle" />
+ Pan
+ </div>
+
+ <div>
+ <img class="nav-icon" src="/images/mouse-middle.svg" style="vertical-align: middle" />
+ Zoom
+ </div>
+ </div>
+ `
+ }
+
+ /**
+ * Render shared animation player controls into the provided mount element.
+ */
+ static populate_animation_player (mount: HTMLElement): void {
+ mount.innerHTML = `
+ <div id="animation-player">
+ <div id="current-animation-container">
+ <span id="current-animation-name">No animation selected</span>
+ </div>
+
+ <div id="play-controls">
+ <button id="play-pause-button" class="animation-control-button" disabled>
+ <span class="material-symbols-outlined">play_arrow</span>
+ </button>
+
+ <span>
+ <span id="current-time">0f</span> /
+ <span id="total-time">0f</span>
+ </span>
+
+ <input type="range" id="animation-scrubber" min="0" max="100" value="0" disabled />
+
+ <div id="skeleton-toggle" class="styled-checkbox icon-toggle">
+ <input type="checkbox" id="show-skeleton-checkbox" name="show-skeleton" value="show" style="display: none" />
+ <label for="show-skeleton-checkbox" data-tippy-content="Show skeleton" tabindex="0" style="border-radius: 0">
+ <img src="../images/icons/bone-display.svg" class="action-icon" alt="Show skeleton" style="user-select: none" />
+ </label>
+ </div>
+ </div>
+ </div>
+ `
+ }
+
/**
* Render shared nav settings dropdown markup into the provided mount element.
*/
static populate_settings_dropdown (mount: HTMLElement): void {
const defaults = DOMUtilities.settings_defaults
+ // Nested settings mount should not introduce block-flow wrapping.
+ mount.style.display = 'inline-flex'
+ mount.style.alignItems = 'center'
+
mount.innerHTML = `
<div id="settings-dropdown-container" class="nav-dropdown">
<button id="settings-toggle" class="nav-icon-button" aria-expanded="false" aria-controls="settings-dropdown-content" aria-haspopup="true" aria-label="Open settings">
diff --git a/src/retarget/index.html b/src/retarget/index.html
index d8ed055..36af4df 100644
--- a/src/retarget/index.html
+++ b/src/retarget/index.html
@@ -28,14 +28,7 @@
</div>
<div style="display: inline-flex; align-items: center;">
- <a href="#" id="learn-link">Learn</a>
- <a href="#" id="attribution-link">Contributors</a>
- <a href="https://support.mesh2motion.org" target="_blank">πŸ’—</a>
- <a href="https://github.com/scottpetrovic/mesh2motion-app" target="_blank">
- <img src="../images/github-white-icon.png" width="24" height="24" alt="GitHub" />
- </a>
-
- <div id="settings-dropdown-mount"></div>
+ <div id="top-nav-links-mount"></div>
</div>
</nav>
@@ -195,47 +188,10 @@
</div>
- <!-- Free-floating Animation Player -->
- <div id="animation-player">
- <div id="current-animation-container">
- <span id="current-animation-name">No animation selected</span>
- </div>
- <div id="play-controls">
- <button id="play-pause-button" class="animation-control-button" disabled>
- <span class="material-symbols-outlined">play_arrow</span>
- </button>
- <span>
- <span id="current-time">0f</span> /
- <span id="total-time">0f</span>
- </span>
- <input type="range" id="animation-scrubber" min="0" max="100" value="0" disabled>
-
- <!-- checkbox option to show skeleton -->
- <div id="skeleton-toggle" class="styled-checkbox icon-toggle" >
- <input type="checkbox" id="show-skeleton-checkbox" name="show-skeleton" value="show" style="display:none;">
- <label for="show-skeleton-checkbox" data-tippy-content="Show skeleton" tabindex="0" style="border-radius: 0">
- <img src="../images/icons/bone-display.svg" class="action-icon" alt="Show skeleton" style="user-select: none;" />
- </label>
- </div>
-
- </div>
-
- </div>
+ <div id="animation-player-mount"></div>
- <!-- Top toolbar with mouse controls -->
- <div id="header-ui">
- <div>
- <img class="nav-icon" src="/images/mouse-left.svg" style="vertical-align: middle;"/> Rotate
- </div>
-
- <div>
- <img class="nav-icon" src="/images/mouse-right.svg" style="vertical-align: middle;"/> Pan
- </div>
- <div>
- <img class="nav-icon" src="/images/mouse-middle.svg" style="vertical-align: middle;"/> Zoom
- </div>
- </div>
+ <div id="header-ui-mount"></div>
<!-- 3d view controls shown on bottom right. This helps with click events -->
diff --git a/src/retarget/retarget.ts b/src/retarget/retarget.ts
index 3fbb1a6..a550be8 100644
--- a/src/retarget/retarget.ts
+++ b/src/retarget/retarget.ts
@@ -8,7 +8,6 @@ import { RetargetAnimationListing } from './RetargetAnimationListing.ts'
import { AnimationRetargetService } from './AnimationRetargetService'
import { type SkeletonType } from '../lib/enums/SkeletonType.ts'
import { RetargetUtils } from './RetargetUtils.ts'
-import { UI } from '../lib/UI.ts'
class RetargetModule {
private readonly mesh2motion_engine: Mesh2MotionEngine
@@ -20,7 +19,6 @@ class RetargetModule {
private back_to_bone_map_button: HTMLButtonElement | null = null
private continue_to_listing_button: HTMLButtonElement | null = null
- private readonly ui: UI = UI.getInstance()
constructor () {
// Set up camera position similar to marketing bootstrap