Import a 3D Model and automatically assign and export animations
TypeScript
add a checkbox to show wireframe for weight painting
Scott Petrovic8b84e82360ca
diff --git a/src/create.html b/src/create.htmlindex a50d791..7f6ec4e 100644--- a/src/create.html+++ b/src/create.html@@ -451,6 +451,11 @@<input type="checkbox" id="weight-paint-step-mirror" checked /><label for="weight-paint-step-mirror">Mirror L/R</label></div>++ <div class="styled-checkbox">+ <input type="checkbox" id="weight-paint-step-wireframe" checked />+ <label for="weight-paint-step-wireframe">Show wireframe</label>+ </div></span><span id="weight-paint-test-tools" style="display: none; flex-direction: column; gap: 0.75rem;">diff --git a/src/lib/processes/weight-painting/StepWeightPainting.ts b/src/lib/processes/weight-painting/StepWeightPainting.tsindex e4624b1..2095ad3 100644--- a/src/lib/processes/weight-painting/StepWeightPainting.ts+++ b/src/lib/processes/weight-painting/StepWeightPainting.ts@@ -63,9 +63,17 @@ export class StepWeightPainting extends EventTarget {private bone_picking_enabled = falseprivate weight_paint_clear_marker = 0private readonly weight_paint_overlays = new Map<SkinnedMesh, SkinnedMesh>()+ private readonly weight_paint_wireframes: SkinnedMesh[] = []+ private show_wireframe = trueprivate readonly geometry_center_cache = new WeakMap<BufferGeometry, number>()private readonly original_materials = new Map<SkinnedMesh, SkinnedMesh['material']>()- private readonly black_material = new MeshBasicMaterial({ color: 0x000000 })+ // Pushed back in depth so the wireframe lines, which polygon offset can't move, win the depth test.+ private readonly black_material = new MeshBasicMaterial({+ color: 0x000000,+ polygonOffset: true,+ polygonOffsetFactor: 1,+ polygonOffsetUnits: 1+ })private rest_bone_transforms: Array<{bone: Boneposition: Vector3@@ -786,13 +794,47 @@ export class StepWeightPainting extends EventTarget {;(source.parent ?? source).add(overlay)this.weight_paint_overlays.set(source, overlay)+ this.weight_paint_wireframes.push(this.create_weight_paint_wireframe(overlay))}this.update_weight_paint_overlay_colors(this.weight_paint_bone_name)this.sync_weight_paint_overlay_visibility()}+ /**+ * Shows the mesh topology over the black material. Shares the overlay's+ * geometry, so it deforms with the pose and is disposed with the overlay.+ */+ private create_weight_paint_wireframe (overlay: SkinnedMesh): SkinnedMesh {+ const material = new MeshBasicMaterial({+ color: 0x8a8a8a,+ wireframe: true,+ transparent: true,+ opacity: 0.35,+ depthWrite: false+ })+ material.toneMapped = false++ const wireframe = new SkinnedMesh(overlay.geometry, material)+ wireframe.name = 'Weight Paint Wireframe'+ wireframe.frustumCulled = false+ wireframe.renderOrder = overlay.renderOrder + 1+ wireframe.position.copy(overlay.position)+ wireframe.quaternion.copy(overlay.quaternion)+ wireframe.scale.copy(overlay.scale)+ wireframe.bindMode = overlay.bindMode+ wireframe.bind(overlay.skeleton, overlay.bindMatrix)+ overlay.parent?.add(wireframe)+ return wireframe+ }+private dispose_weight_paint_overlays (): void {+ for (const wireframe of this.weight_paint_wireframes) {+ wireframe.removeFromParent()+ ;(wireframe.material as MeshBasicMaterial).dispose()+ }+ this.weight_paint_wireframes.length = 0+for (const overlay of this.weight_paint_overlays.values()) {overlay.removeFromParent()const geometry = overlay.geometry@@ -814,6 +856,9 @@ export class StepWeightPainting extends EventTarget {for (const overlay of this.weight_paint_overlays.values()) {overlay.visible = true}+ for (const wireframe of this.weight_paint_wireframes) {+ wireframe.visible = this.show_wireframe+ }}private update_weight_paint_overlay_colors (bone_name: string | null): void {@@ -892,6 +937,10 @@ export class StepWeightPainting extends EventTarget {this.weight_paint_brush.mirror_enabled = (event.target as HTMLInputElement).checkedthis.update_weight_paint_overlay_colors(this.weight_paint_bone_name)})+ document.getElementById('weight-paint-step-wireframe')?.addEventListener('change', (event) => {+ this.show_wireframe = (event.target as HTMLInputElement).checked+ this.sync_weight_paint_overlay_visibility()+ })document.getElementById('weight-paint-step-radius')?.addEventListener('input', (event) => {if (this.weight_paint_brush === null) { return }this.weight_paint_brush.radius_px = Number((event.target as HTMLInputElement).value)