Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Add wireframe toggle on the player to help figure out what is happening

Scott Petrovicedeb369cd6c0
diff --git a/src/lib/DOMUtilities.ts b/src/lib/DOMUtilities.ts
index ded9cfb..6f1143d 100644
--- a/src/lib/DOMUtilities.ts
+++ b/src/lib/DOMUtilities.ts
@@ -113,10 +113,17 @@ export class DOMUtilities {
<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">
+ <label for="show-skeleton-checkbox" data-tippy-content="Show skeleton" tabindex="0" style="border-radius: 0; padding: 0.4rem;">
<img src="../images/icons/bone-display.svg" class="action-icon" alt="Show skeleton" style="user-select: none" />
</label>
</div>
+
+ <div id="wireframe-toggle" class="styled-checkbox icon-toggle">
+ <input type="checkbox" id="wireframe-checkbox" name="wireframe" value="wireframe" style="display: none" />
+ <label for="wireframe-checkbox" data-tippy-content="Toggle wireframe" tabindex="0" style="border-radius: 0; padding: 0.4rem;">
+ <img src="../images/icons/wireframe.svg" class="action-icon" alt="Toggle wireframe" style="user-select: none" />
+ </label>
+ </div>
</div>
</div>
`
diff --git a/src/lib/EventListeners.ts b/src/lib/EventListeners.ts
index fbddc07..a6261c6 100644
--- a/src/lib/EventListeners.ts
+++ b/src/lib/EventListeners.ts
@@ -5,7 +5,7 @@ import { TransformSpace } from './enums/TransformSpace'
import { Utility } from './Utilities'
import { ModelCleanupUtility } from './processes/load-model/ModelCleanupUtility'
import { DownloadSuccessDialog } from './components/download-success/DownloadSuccessDialog'
-import { type Bone } from 'three'
+import { type Bone, type Material, type MeshBasicMaterial, type MeshPhongMaterial, type MeshStandardMaterial } from 'three'
export class EventListeners {
// Track the pointer that started canvas drag so touch/pencil moves stay consistent
@@ -236,6 +236,17 @@ export class EventListeners {
}
})
+ this.bootstrap.ui.dom_wireframe_checkbox?.addEventListener('change', (event: Event) => {
+ const is_wireframe = (event.target as HTMLInputElement).checked
+ const skinned_meshes = this.bootstrap.animations_listing_step.active_skinned_meshes()
+ skinned_meshes.forEach((mesh) => {
+ const materials = Array.isArray(mesh.material) ? mesh.material : [mesh.material]
+ materials.forEach((mat: Material) => {
+ (mat as MeshBasicMaterial | MeshPhongMaterial | MeshStandardMaterial).wireframe = is_wireframe
+ })
+ })
+ })
+
this.bootstrap.ui.dom_export_button?.addEventListener('click', () => {
const all_clips = this.bootstrap.animations_listing_step.animation_clips()
const animations_to_export: number[] = this.bootstrap.animations_listing_step.get_animation_indices_to_export()
diff --git a/src/lib/UI.ts b/src/lib/UI.ts
index 8610872..4ec689d 100644
--- a/src/lib/UI.ts
+++ b/src/lib/UI.ts
@@ -11,6 +11,10 @@ export class UI {
dom_show_skeleton_container: HTMLElement | null = null
dom_show_skeleton_checkbox: HTMLInputElement | null = null
+ // toggle for wireframe display of the mesh
+ dom_wireframe_toggle: HTMLElement | null = null
+ dom_wireframe_checkbox: HTMLInputElement | null = null
+
// load skeleton UI
dom_rotate_model_x_button: HTMLButtonElement | null = null
dom_rotate_model_y_button: HTMLButtonElement | null = null
@@ -128,6 +132,10 @@ export class UI {
this.dom_show_skeleton_container = document.querySelector('#skeleton-toggle')
this.dom_show_skeleton_checkbox = document.querySelector('#show-skeleton-checkbox')
+ // wireframe toggle on UI viewport
+ this.dom_wireframe_toggle = document.querySelector('#wireframe-toggle')
+ this.dom_wireframe_checkbox = document.querySelector('#wireframe-checkbox')
+
// UI controls for loading the model
this.dom_load_model_tools = document.querySelector('#load-model-tools')
this.dom_upload_model_button = document.querySelector('#model-upload')
diff --git a/src/marketing/MarketingBootstrap.ts b/src/marketing/MarketingBootstrap.ts
index 86f4f30..1f4d827 100644
--- a/src/marketing/MarketingBootstrap.ts
+++ b/src/marketing/MarketingBootstrap.ts
@@ -74,6 +74,7 @@ export class MarketingBootstrap {
)
this.rebuild_skeleton_helper(skinned_meshes)
+ this.apply_wireframe_to_skinned_meshes(skinned_meshes)
}) as EventListener)
@@ -86,6 +87,12 @@ export class MarketingBootstrap {
this.mesh2motion_engine.load_model_step.addEventListener('modelLoaded', () => {
this.mesh2motion_engine.shake_camera()
+ // reset wireframe toggle when a new model is loaded
+ const wireframe_checkbox = this.mesh2motion_engine.ui.dom_wireframe_checkbox
+ if (wireframe_checkbox !== null) {
+ wireframe_checkbox.checked = false
+ }
+
// resolve the rig file path from the central config
const rig_file = RigConfig.rig_file_for(this.skeleton_type)
this.mesh2motion_engine.process_step_changed(ProcessStep.LoadSkeleton)
@@ -116,6 +123,16 @@ export class MarketingBootstrap {
}
}
+ private apply_wireframe_to_skinned_meshes (skinned_meshes: SkinnedMesh[]): void {
+ const is_wireframe = this.mesh2motion_engine.ui.dom_wireframe_checkbox?.checked ?? false
+ skinned_meshes.forEach((mesh) => {
+ const materials = Array.isArray(mesh.material) ? mesh.material : [mesh.material]
+ materials.forEach((mat) => {
+ (mat as any).wireframe = is_wireframe
+ })
+ })
+ }
+
}
diff --git a/src/styles.css b/src/styles.css
index d86f7db..04360f8 100644
--- a/src/styles.css
+++ b/src/styles.css
@@ -137,7 +137,7 @@ div, p {
background: var(--button-alternate-bg);
}
-#skeleton-toggle {
+#skeleton-toggle, #wireframe-toggle {
padding: 0;
margin: 0;
}
diff --git a/static/images/icons/wireframe.svg b/static/images/icons/wireframe.svg
new file mode 100644
index 0000000..11443ce
--- /dev/null
+++ b/static/images/icons/wireframe.svg
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg width="100%" height="100%" viewBox="0 0 256 256" version="1.1" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;">
+ <rect x="0" y="0" width="256" height="256" style="fill:none;"/>
+ <!-- Wireframe cube-like shape: front face, back face, connecting edges -->
+ <!-- Front face (bottom-left rectangle) -->
+ <rect x="30" y="110" width="130" height="116" style="fill:none;stroke:rgb(216,216,216);stroke-width:14px;"/>
+ <!-- Back face (top-right rectangle, offset) -->
+ <rect x="96" y="30" width="130" height="116" style="fill:none;stroke:rgb(216,216,216);stroke-width:14px;"/>
+ <!-- Connecting edges (4 corners) -->
+ <line x1="30" y1="110" x2="96" y2="30" style="stroke:rgb(216,216,216);stroke-width:14px;"/>
+ <line x1="160" y1="110" x2="226" y2="30" style="stroke:rgb(216,216,216);stroke-width:14px;"/>
+ <line x1="160" y1="226" x2="226" y2="146" style="stroke:rgb(216,216,216);stroke-width:14px;"/>
+ <line x1="30" y1="226" x2="96" y2="146" style="stroke:rgb(216,216,216);stroke-width:14px;"/>
+</svg>