Import a 3D Model and automatically assign and export animations
TypeScript
remove the arm plane correction since we have weight painting now
Scott Petrovic3682a17118e7
diff --git a/src/Mesh2MotionEngine.ts b/src/Mesh2MotionEngine.tsindex c476f18..8806ccb 100644--- a/src/Mesh2MotionEngine.ts+++ b/src/Mesh2MotionEngine.ts@@ -878,12 +878,6 @@ export class Mesh2MotionEngine {this.edit_skeleton_step.get_preview_plane_height())- // Pass arm plane correction settings to the weight skin step- this.weight_skin_step.set_arm_plane_correction_settings(- this.edit_skeleton_step.use_arm_plane_correction(),- this.edit_skeleton_step.get_arm_plane_offset()- )-this.weight_skin_step.create_binding_skeleton()// add geometry data needed for skinning@@ -921,12 +915,6 @@ export class Mesh2MotionEngine {this.edit_skeleton_step.use_head_weight_correction(),this.edit_skeleton_step.get_preview_plane_height())-- // Pass arm plane correction settings to the weight skin step- this.weight_skin_step.set_arm_plane_correction_settings(- this.edit_skeleton_step.use_arm_plane_correction(),- this.edit_skeleton_step.get_arm_plane_offset()- )}public show_contributors_dialog (): void {diff --git a/src/create.html b/src/create.htmlindex ecf97f9..91a2543 100644--- a/src/create.html+++ b/src/create.html@@ -353,22 +353,6 @@</div>- <!-- Arm plane controls -->- <div id="use-arm-plane-container" style="display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem;">- <div class="styled-checkbox">- <input type="checkbox" id="arm-plane-checkbox" />- <label for="arm-plane-checkbox">Use Arm Plane Correction</label>-- <img data-tippy-content="If the arms are grabbing weights from the torso (common when arms point down in an A-pose), use a divider to define where the arm area starts." src="images/icons/help.svg" alt="Help" width="20" height="20" />-- </div>- <div id="arm-plane-setting-container" style="display: flex; align-items: center; gap: 0.5rem;">- <label for="arm-plane-offset-input">Distance:</label>- <input type="range" id="arm-plane-offset-input" min="-0.10" max="0.10" step="0.001" value="0.00" />- <span id="arm-plane-offset-label" style="width: 3.5rem;">0.0%</span>- </div>- </div>-<!-- back to load skeleton --><div class="display: flex; gap: 0.5rem;"><button class="no-style-button" id="action_back_to_load_skeleton">‹ Back</button>diff --git a/src/lib/UI.ts b/src/lib/UI.tsindex f74992a..11ac9fa 100644--- a/src/lib/UI.ts+++ b/src/lib/UI.ts@@ -63,13 +63,6 @@ export class UI {dom_model_pose_instructions: HTMLElement | null = null- // arm plane controls- dom_use_arm_plane_container: HTMLElement | null = null- dom_arm_plane_checkbox: HTMLInputElement | null = null- dom_arm_plane_offset_input: HTMLInputElement | null = null- dom_arm_plane_offset_label: HTMLElement | null = null- dom_arm_plane_setting_container: HTMLElement | null = null-dom_weight_paint_step_tools: HTMLElement | null = nulldom_enable_weight_paint_step: HTMLInputElement | null = nulldom_skinned_mesh_tools: HTMLElement | null = null@@ -204,13 +197,6 @@ export class UI {this.dom_model_pose_instructions = document.querySelector('#model-pose-instructions')- // arm plane controls- this.dom_use_arm_plane_container = document.querySelector('#use-arm-plane-container')- this.dom_arm_plane_checkbox = document.querySelector('#arm-plane-checkbox')- this.dom_arm_plane_offset_input = document.querySelector('#arm-plane-offset-input')- this.dom_arm_plane_offset_label = document.querySelector('#arm-plane-offset-label')- this.dom_arm_plane_setting_container = document.querySelector('#arm-plane-setting-container')-this.dom_bind_pose_button = document.querySelector('#action_bind_pose')// this.dom_scale_skeleton_input_box = document.querySelector('#scale-input')this.dom_move_to_origin_button = document.querySelector('#action_move_to_origin')diff --git a/src/lib/processes/edit-skeleton/ArmPlaneManager.ts b/src/lib/processes/edit-skeleton/ArmPlaneManager.tsdeleted file mode 100644index 6b258b9..0000000--- a/src/lib/processes/edit-skeleton/ArmPlaneManager.ts+++ /dev/null@@ -1,145 +0,0 @@-import { Group, Mesh, PlaneGeometry, MeshBasicMaterial, type Scene, DoubleSide } from 'three'--/**- * ArmPlaneManager - manages the pair of mirrored vertical planes that show where- * the arm weight correction cuts off during the edit skeleton step.- *- * Unlike PreviewPlaneManager (one horizontal plane, singleton) this owns two- * planes at +X and -X, so it is a plain class instantiated by the step that- * needs it.- */-export class ArmPlaneManager {- private readonly arm_plane_group_name: string = 'arm_plane_group'-- // State tracking- private scene_ref: Scene | null = null- private plane_group: Group | null = null- private left_plane_mesh: Mesh | null = null- private right_plane_mesh: Mesh | null = null- private current_plane_x: number = 0.0- private current_center_y: number = 0.0- private current_center_z: number = 0.0- private readonly plane_size: number = 2.0- private is_visible: boolean = false-- /**- * Initialize the manager with a scene reference- * @param scene The main scene- */- public initialize (scene: Scene): void {- this.scene_ref = scene- }-- /**- * Set the visibility of the arm planes. Creates them on demand and removes- * them when hidden, so nothing lingers in the scene between steps.- */- public set_visibility (visible: boolean): void {- if (visible && !this.is_visible) {- this.add_planes()- } else if (!visible && this.is_visible) {- this.remove_planes()- }- }-- /**- * Move the planes to a new distance from the center line. The planes are- * centered on the shoulder joint's height/depth so they sit over the torso.- *- * State is stored even when the planes are hidden, so callers can update the- * position before or after toggling visibility.- */- public update_position (plane_x: number, center_y: number, center_z: number): void {- this.current_plane_x = plane_x- this.current_center_y = center_y- this.current_center_z = center_z-- if (this.left_plane_mesh !== null && this.right_plane_mesh !== null) {- this.left_plane_mesh.position.set(-plane_x, center_y, center_z)- this.right_plane_mesh.position.set(plane_x, center_y, center_z)- }- }-- public is_plane_visible (): boolean {- return this.is_visible- }-- /**- * Remove both planes from the scene and dispose their resources- */- public remove_planes (): void {- if (this.plane_group !== null && this.scene_ref !== null) {- [this.left_plane_mesh, this.right_plane_mesh].forEach((plane_mesh) => {- if (plane_mesh === null) return- plane_mesh.geometry.dispose()- if (plane_mesh.material instanceof MeshBasicMaterial) {- plane_mesh.material.dispose()- }- })-- this.scene_ref.remove(this.plane_group)- }-- this.plane_group = null- this.left_plane_mesh = null- this.right_plane_mesh = null- this.is_visible = false- }-- /**- * Clean up all resources and reset state- */- public cleanup (): void {- this.remove_planes()- this.scene_ref = null- this.current_plane_x = 0.0- this.current_center_y = 0.0- this.current_center_z = 0.0- this.is_visible = false- }-- /**- * Build the two vertical planes at the currently stored position- */- private add_planes (): void {- if (this.scene_ref === null) {- throw new Error('ArmPlaneManager not initialized with scene reference')- }-- this.remove_planes()-- this.plane_group = new Group()- this.plane_group.name = this.arm_plane_group_name-- this.left_plane_mesh = this.create_plane_mesh('arm_plane_left')- this.right_plane_mesh = this.create_plane_mesh('arm_plane_right')-- this.plane_group.add(this.left_plane_mesh)- this.plane_group.add(this.right_plane_mesh)- this.scene_ref.add(this.plane_group)-- this.is_visible = true-- // apply the stored position to the freshly created meshes- this.update_position(this.current_plane_x, this.current_center_y, this.current_center_z)- }-- private create_plane_mesh (name: string): Mesh {- const geometry = new PlaneGeometry(this.plane_size, this.plane_size)- const material = new MeshBasicMaterial({- color: 0x3399ff, // blue, to distinguish from the green head weight correction plane- transparent: true,- opacity: 0.5,- side: DoubleSide,- wireframe: false- })-- const plane_mesh = new Mesh(geometry, material)- plane_mesh.name = name-- // rotate so the plane's normal points along X (a vertical wall facing sideways)- plane_mesh.rotation.y = Math.PI / 2-- return plane_mesh- }-}diff --git a/src/lib/processes/edit-skeleton/StepEditSkeleton.ts b/src/lib/processes/edit-skeleton/StepEditSkeleton.tsindex 80fb8f3..3d4086d 100644--- a/src/lib/processes/edit-skeleton/StepEditSkeleton.ts+++ b/src/lib/processes/edit-skeleton/StepEditSkeleton.ts@@ -5,8 +5,6 @@ import { Generators } from '../../Generators.ts'import { Utility } from '../../Utilities.ts'import { UndoRedoSystem } from './UndoRedoSystem.ts'import { PreviewPlaneManager } from './PreviewPlaneManager.ts'-import { ArmPlaneManager } from './ArmPlaneManager.ts'-import { ArmWeightCorrector } from '../../solvers/ArmWeightCorrector.ts'import { IndependentBoneMovement } from './IndependentBoneMovement.ts'import { ModalDialog } from '../../ModalDialog.ts'import {@@ -65,16 +63,10 @@ export class StepEditSkeleton extends EventTarget {private enable_head_weight_correction: boolean = falseprivate head_weight_correction_height: number = 1.4 // default- // Arm plane state. The offset is relative to the shoulder joint's X position,- // so it has to match the default in create.html's slider.- private enable_arm_plane_correction: boolean = false- private arm_plane_offset: number = 0.0-private readonly joint_texture = new TextureLoader().load('/images/skeleton-joint-point.png')private _added_event_listeners: boolean = falseprivate readonly preview_plane_manager: PreviewPlaneManager = PreviewPlaneManager.getInstance()- private readonly arm_plane_manager: ArmPlaneManager = new ArmPlaneManager()public readonly independent_bone_movement: IndependentBoneMovement = new IndependentBoneMovement()// UI elements specific for this area@@ -149,21 +141,10 @@ export class StepEditSkeleton extends EventTarget {this.ui.dom_model_pose_instructions.style.display = skeleton_type === SkeletonType.Human ? 'block' : 'none'}- // only human skeletons have the arm plane correction option- if (this.ui.dom_use_arm_plane_container != null) {- if (skeleton_type === SkeletonType.Human) {- this.ui.dom_use_arm_plane_container.style.display = 'block'- } else {- this.ui.dom_use_arm_plane_container.style.display = 'none'- this.enable_arm_plane_correction = false // force setting to false in case it was enabled before- }- }-this.update_skeleton_template_image(skeleton_type)// show/hide settings for the head correct depending on if it is checkedthis.show_preview_plane_options()- this.show_arm_plane_options()}private update_skeleton_template_image(skeleton_type: SkeletonType): void {@@ -240,56 +221,6 @@ export class StepEditSkeleton extends EventTarget {)this.initialize_preview_plane(main_scene)- this.initialize_arm_plane(main_scene)- }-- private initialize_arm_plane (main_scene: Scene): void {- this.arm_plane_manager.initialize(main_scene)-- // off by default, but can be enabled if we navigate back to the step- this.arm_plane_manager.set_visibility(this.enable_arm_plane_correction)- this.refresh_arm_plane_position()-- // set default value (and label) for arm plane offset on UI- if (this.ui.dom_arm_plane_offset_input !== null && this.ui.dom_arm_plane_offset_label !== null) {- this.ui.dom_arm_plane_offset_input.value = this.arm_plane_offset.toString()- this.ui.dom_arm_plane_offset_label.textContent = this.format_arm_plane_offset_label()- }-- // the checkbox is forced off for non-human rigs, so keep the DOM in sync- // with our state instead of leaving a checked box next to a hidden slider- if (this.ui.dom_arm_plane_checkbox !== null) {- this.ui.dom_arm_plane_checkbox.checked = this.enable_arm_plane_correction- }- }-- /**- * The offset is a decimal in scene units, but a percentage reads better on a- * range this small (-0.10 to 0.10 shows as -10.0% to 10.0%). One decimal- * place so the slider's 0.001 step is actually visible in the label.- */- private format_arm_plane_offset_label (): string {- return `${(this.arm_plane_offset * 100).toFixed(1)}%`- }-- /**- * Move the arm planes to wherever the shoulder joint currently is, plus the- * user's offset. The solver derives its plane the same way at skin time, so- * what the user sees here is what actually gets applied.- */- private refresh_arm_plane_position (): void {- const bones = this.threejs_skeleton.bones- if (bones.length === 0) { return }-- const anchor_x = ArmWeightCorrector.shoulder_anchor_x(bones)- if (anchor_x === null) { return } // no arm bones on this rig-- const shoulder_bone = ArmWeightCorrector.find_shoulder_bone(bones)- const shoulder_position = shoulder_bone === undefined- ? new Vector3()- : Utility.world_position_from_object(shoulder_bone)-- this.arm_plane_manager.update_position(anchor_x + this.arm_plane_offset, shoulder_position.y, shoulder_position.z)}private initialize_preview_plane (main_scene: Scene): void {@@ -442,32 +373,6 @@ export class StepEditSkeleton extends EventTarget {return this.head_weight_correction_height}- /**- * Toggle the arm plane correction and the planes that visualize it- */- public set_use_arm_plane_correction (is_enabled: boolean): void {- this.enable_arm_plane_correction = is_enabled- this.arm_plane_manager.set_visibility(is_enabled)- this.refresh_arm_plane_position()- }-- public use_arm_plane_correction (): boolean {- return this.enable_arm_plane_correction- }-- /**- * Set how far the arm plane sits from the shoulder joint- * @param offset Distance along X to add to the shoulder joint position- */- public set_arm_plane_offset (offset: number): void {- this.arm_plane_offset = offset- this.refresh_arm_plane_position()- }-- public get_arm_plane_offset (): number {- return this.arm_plane_offset- }-public manual_weight_overrides (): ManualWeightOverrides {return this.weight_paint_tools.overrides_for_skin()}@@ -606,30 +511,6 @@ export class StepEditSkeleton extends EventTarget {this.ui.dom_preview_plane_height_label.textContent = this.head_weight_correction_height.toFixed(2)}})-- // Add arm plane event listeners- this.ui.dom_arm_plane_checkbox?.addEventListener('change', (event) => {- const target = event.target as HTMLInputElement- this.set_use_arm_plane_correction(target.checked)-- this.show_arm_plane_options()- })-- this.ui.dom_arm_plane_offset_input?.addEventListener('input', (event) => {- const target = event.target as HTMLInputElement- const offset = parseFloat(target.value)- this.set_arm_plane_offset(isNaN(offset) ? 0.00 : offset)-- // Update the label to show current value- if (this.ui.dom_arm_plane_offset_label !== null) {- this.ui.dom_arm_plane_offset_label.textContent = this.format_arm_plane_offset_label()- }- })-- // keep the arm planes anchored to the shoulder joint when bones get moved- this.addEventListener('skeletonTransformed', () => {- this.refresh_arm_plane_position()- })}private show_preview_plane_options (): void {@@ -638,12 +519,6 @@ export class StepEditSkeleton extends EventTarget {}}- private show_arm_plane_options (): void {- if (this.ui.dom_arm_plane_setting_container !== null) {- this.ui.dom_arm_plane_setting_container.style.display = this.use_arm_plane_correction() ? 'flex' : 'none'- }- }-// returning back to edit skeleton step later will call this to reset undo statepublic clear_undo_history (): void {this.undo_redo_system.clear_history()@@ -694,15 +569,6 @@ export class StepEditSkeleton extends EventTarget {if (this.ui.dom_preview_plane_height_input !== null) {this.ui.dom_preview_plane_height_input.removeEventListener('input', () => {})}-- // Remove arm plane event listeners- if (this.ui.dom_arm_plane_checkbox !== null) {- this.ui.dom_arm_plane_checkbox.removeEventListener('change', () => {})- }-- if (this.ui.dom_arm_plane_offset_input !== null) {- this.ui.dom_arm_plane_offset_input.removeEventListener('input', () => {})- }}public cleanup_on_exit_step (): void {@@ -710,7 +576,6 @@ export class StepEditSkeleton extends EventTarget {this.remove_event_listeners()this.clear_hover_point_if_exists()this.remove_preview_plane()- this.arm_plane_manager.cleanup()}/**diff --git a/src/lib/processes/weight-skin/StepWeightSkin.ts b/src/lib/processes/weight-skin/StepWeightSkin.tsindex 4a339c9..9641635 100644--- a/src/lib/processes/weight-skin/StepWeightSkin.ts+++ b/src/lib/processes/weight-skin/StepWeightSkin.ts@@ -154,17 +154,6 @@ export class StepWeightSkin extends EventTarget {this.bone_skinning_formula.set_preview_plane_height(height)}- /**- * Configure arm plane correction settings for the solver- * @param enabled Whether arm plane correction is enabled- * @param offset Distance along X from the shoulder joint to place the plane- */- public set_arm_plane_correction_settings (enabled: boolean, offset: number): void {- if (this.bone_skinning_formula === undefined) return- this.bone_skinning_formula.set_arm_plane_correction_enabled(enabled)- this.bone_skinning_formula.set_arm_plane_offset(offset)- }-/*** Manual weights painted in the edit skeleton step. They override the* automatic solver result for the vertices that were painted.diff --git a/src/lib/solvers/ArmWeightCorrector.test.ts b/src/lib/solvers/ArmWeightCorrector.test.tsdeleted file mode 100644index f39a5f1..0000000--- a/src/lib/solvers/ArmWeightCorrector.test.ts+++ /dev/null@@ -1,208 +0,0 @@-import { describe, it, expect } from 'vitest'-import { Bone, BufferGeometry, Float32BufferAttribute, type Vector3 } from 'three'-import { Utility } from '../Utilities'-import { ArmWeightCorrector } from './ArmWeightCorrector'--/**- * Builds a minimal symmetric humanoid-ish rig with these WORLD positions:- *- * root (0, 0, 0)- * spine_01 (0, 1.0, 0) chest (0, 1.5, 0)- * clavicle (+/-0.1, 1.5, 0)- * upperarm (+/-1.0, 1.5, 0) lowerarm (+/-2.0, ...) hand (+/-3.0, ...)- *- * Which puts the midpoint-to-child reference points the solver measures against at:- * spine_01 (0, 1.25, 0) chest (+/-0.05, 1.5, 0) clavicle (+/-0.55, 1.5, 0)- */-function build_test_rig (): Bone[] {- const root = new Bone()- root.name = 'root'-- const spine = new Bone()- spine.name = 'spine_01'- spine.position.set(0, 1.0, 0)- root.add(spine)-- const chest = new Bone()- chest.name = 'chest'- chest.position.set(0, 0.5, 0)- spine.add(chest)-- const bones: Bone[] = [root, spine, chest]-- const build_arm = (side: string, direction: number): void => {- const clavicle = new Bone()- clavicle.name = `clavicle_${side}`- clavicle.position.set(direction * 0.1, 0, 0) // world x = direction * 0.1-- const upperarm = new Bone()- upperarm.name = `upperarm_${side}`- upperarm.position.set(direction * 0.9, 0, 0) // world x = direction * 1.0-- const lowerarm = new Bone()- lowerarm.name = `lowerarm_${side}`- lowerarm.position.set(direction * 1.0, 0, 0) // world x = direction * 2.0-- const hand = new Bone()- hand.name = `hand_${side}`- hand.position.set(direction * 1.0, 0, 0) // world x = direction * 3.0-- lowerarm.add(hand)- upperarm.add(lowerarm)- clavicle.add(upperarm)- chest.add(clavicle)-- bones.push(clavicle, upperarm, lowerarm, hand)- }-- build_arm('l', 1)- build_arm('r', -1)-- root.updateWorldMatrix(true, true)- return bones-}--function bone_index (bones: Bone[], name: string): number {- return bones.findIndex(bone => bone.name === name)-}--function geometry_from_points (points: Array<[number, number, number]>): BufferGeometry {- const geometry = new BufferGeometry()- geometry.setAttribute('position', new Float32BufferAttribute(points.flat(), 3))- return geometry-}--describe('ArmWeightCorrector.shoulder_anchor_x', () => {- it('returns the absolute world X of the upperarm bone', () => {- const bones = build_test_rig()- expect(ArmWeightCorrector.shoulder_anchor_x(bones)).toBeCloseTo(1.0)- })-- it('returns null when the rig has no arm bones', () => {- const snake_head = new Bone()- snake_head.name = 'head'- expect(ArmWeightCorrector.shoulder_anchor_x([snake_head])).toBeNull()- })-})--describe('ArmWeightCorrector.apply_arm_weight_correction', () => {- it('reassigns inboard vertices off arm bones onto the nearest non-arm bone', () => {- const bones = build_test_rig()- const upperarm_l = bone_index(bones, 'upperarm_l')-- // a chest-height vertex inboard of the shoulder plane (x = 1.0), closest to- // the clavicle's reference point at 0.55- const geometry = geometry_from_points([[0.35, 1.5, 0]])- const skin_indices = [upperarm_l, 0, 0, 0]- const skin_weights = [1.0, 0, 0, 0]-- new ArmWeightCorrector(geometry, bones, 0).apply_arm_weight_correction(skin_indices, skin_weights)-- expect(skin_indices[0]).not.toBe(upperarm_l)- expect(bones[skin_indices[0]].name).toBe('clavicle_l')- expect(skin_weights[0] + skin_weights[1] + skin_weights[2] + skin_weights[3]).toBeCloseTo(1.0)- })-- it('leaves vertices outboard of the plane alone', () => {- const bones = build_test_rig()- const upperarm_l = bone_index(bones, 'upperarm_l')-- const geometry = geometry_from_points([[1.5, 1.5, 0]])- const skin_indices = [upperarm_l, 0, 0, 0]- const skin_weights = [1.0, 0, 0, 0]-- new ArmWeightCorrector(geometry, bones, 0).apply_arm_weight_correction(skin_indices, skin_weights)-- expect(skin_indices[0]).toBe(upperarm_l)- expect(skin_weights[0]).toBe(1.0)- })-- it('applies symmetrically to the negative X side', () => {- const bones = build_test_rig()- const upperarm_r = bone_index(bones, 'upperarm_r')-- const geometry = geometry_from_points([[-0.35, 1.5, 0]])- const skin_indices = [upperarm_r, 0, 0, 0]- const skin_weights = [1.0, 0, 0, 0]-- new ArmWeightCorrector(geometry, bones, 0).apply_arm_weight_correction(skin_indices, skin_weights)-- expect(bones[skin_indices[0]].name).toBe('clavicle_r')- })-- it('never hands a vertex to the clavicle when the offset pushes the plane past it', () => {- // clavicle midpoint sits at x = 0.55, so a -0.5 offset puts the plane at 0.5- const bones = build_test_rig()- const upperarm_l = bone_index(bones, 'upperarm_l')-- const geometry = geometry_from_points([[0.45, 1.5, 0]])- const skin_indices = [upperarm_l, 0, 0, 0]- const skin_weights = [1.0, 0, 0, 0]-- new ArmWeightCorrector(geometry, bones, -0.5).apply_arm_weight_correction(skin_indices, skin_weights)-- // still corrected (0.45 < 0.5), and the replacement is never an arm bone- expect(bones[skin_indices[0]].name.includes('arm')).toBe(false)- })-- it('is a no-op when the rig has no arm bones', () => {- const snake_head = new Bone()- snake_head.name = 'head'- snake_head.updateWorldMatrix(true, true)-- const geometry = geometry_from_points([[0, 0, 0]])- const skin_indices = [0, 0, 0, 0]- const skin_weights = [1.0, 0, 0, 0]-- new ArmWeightCorrector(geometry, [snake_head], 0).apply_arm_weight_correction(skin_indices, skin_weights)-- expect(skin_indices).toEqual([0, 0, 0, 0])- expect(skin_weights).toEqual([1.0, 0, 0, 0])- })-- it('does not strip weights from the clavicle itself', () => {- const bones = build_test_rig()- const clavicle_l = bone_index(bones, 'clavicle_l')-- const geometry = geometry_from_points([[0.35, 1.5, 0]])- const skin_indices = [clavicle_l, 0, 0, 0]- const skin_weights = [1.0, 0, 0, 0]-- new ArmWeightCorrector(geometry, bones, 0).apply_arm_weight_correction(skin_indices, skin_weights)-- expect(skin_indices[0]).toBe(clavicle_l)- expect(skin_weights[0]).toBe(1.0)- })-- it('merges the stolen weight into an existing slot for the replacement bone', () => {- const bones = build_test_rig()- const upperarm_l = bone_index(bones, 'upperarm_l')- const clavicle_l = bone_index(bones, 'clavicle_l')-- const geometry = geometry_from_points([[0.35, 1.5, 0]])- const skin_indices = [upperarm_l, clavicle_l, 0, 0]- const skin_weights = [0.6, 0.4, 0, 0]-- new ArmWeightCorrector(geometry, bones, 0).apply_arm_weight_correction(skin_indices, skin_weights)-- // all of it collapses onto the single clavicle slot- expect(skin_indices[1]).toBe(clavicle_l)- expect(skin_weights[1]).toBeCloseTo(1.0)- expect(skin_weights[0]).toBe(0)- })-})--describe('Utility.bone_midpoint_to_child', () => {- it('returns the halfway point to the first child', () => {- const bones = build_test_rig()- const upperarm_l = bones[bone_index(bones, 'upperarm_l')]- const midpoint: Vector3 = Utility.bone_midpoint_to_child(upperarm_l)- expect(midpoint.x).toBeCloseTo(1.5)- })-- it('falls back to the bone position when childless', () => {- const bones = build_test_rig()- const hand_l = bones[bone_index(bones, 'hand_l')]- expect(Utility.bone_midpoint_to_child(hand_l).x).toBeCloseTo(3.0)- })-})diff --git a/src/lib/solvers/ArmWeightCorrector.ts b/src/lib/solvers/ArmWeightCorrector.tsdeleted file mode 100644index 6826bb1..0000000--- a/src/lib/solvers/ArmWeightCorrector.ts+++ /dev/null@@ -1,231 +0,0 @@-import {- Vector3,- Bone,- type BufferGeometry-} from 'three'--import { Utility } from '../Utilities.js'--/**- * Pulls torso vertices back off the arm bones.- *- * When a character's arms hang down (A-pose or lower) the upperarm/lowerarm- * bones run close to the ribcage and hips, so the closest-midpoint assignment- * hands chest vertices to an arm bone. Lifting the arm then drags part of the- * torso with it.- *- * This defines a vertical plane anchored at the shoulder joint's X position- * (nudged in or out by the user's offset) and mirrored to both sides. Any- * vertex *inboard* of that plane (|x| < plane_x) that was given to an arm bone- * has that weight taken away and handed to its nearest non-arm bone.- *- * The "arm" set is the upperarm bone and everything below it. The clavicle is- * deliberately excluded — it sits inboard of the shoulder joint and legitimately- * covers part of the chest.- */-export class ArmWeightCorrector {- private readonly geometry: BufferGeometry- private readonly bones: Bone[]- private readonly arm_plane_offset: number-- constructor (geometry: BufferGeometry, bones_master_data: Bone[], arm_plane_offset: number) {- this.geometry = geometry- this.bones = bones_master_data- this.arm_plane_offset = arm_plane_offset- }-- /**- * Distance from the model's center line to the shoulder joint, which is where- * the arm plane sits when the user's offset is zero.- *- * Shared with the edit-skeleton preview so the plane the user sees and the- * plane the solver uses are derived the same way. The solver runs against a- * clone of the edited armature, so both recompute this from bones rather than- * passing an absolute coordinate around.- *- * @returns the absolute world X of the shoulder joint, or null if no arm bone was found- */- public static shoulder_anchor_x (bones: Bone[]): number | null {- const shoulder_bone = ArmWeightCorrector.find_shoulder_bone(bones)- if (shoulder_bone === undefined) {- return null- }- return Math.abs(Utility.world_position_from_object(shoulder_bone).x)- }-- /**- * The bone the arm plane is anchored to. Human rigs name it `upperarm_l`;- * the fallbacks cover rigs that use other conventions.- */- public static find_shoulder_bone (bones: Bone[]): Bone | undefined {- const name_priority = ['upperarm', 'shoulder', 'arm']- for (const keyword of name_priority) {- const match = bones.find(bone => bone.name.toLowerCase().includes(keyword))- if (match !== undefined) {- return match- }- }- return undefined- }-- /**- * Reassign arm-bone weights on vertices inboard of the arm plane.- * Modifies skin_indices and skin_weights in place. Runs before smoothing so- * the smoother blends the new torso/arm boundary instead of leaving a seam.- */- public apply_arm_weight_correction (skin_indices: number[], skin_weights: number[]): void {- const anchor_x = ArmWeightCorrector.shoulder_anchor_x(this.bones)- if (anchor_x === null) { return } // no arm bones on this rig, nothing to correct-- const plane_x = anchor_x + this.arm_plane_offset- if (plane_x <= 0) { return } // plane pushed past the center line, would strip both arms entirely-- const arm_bone_indices = this.find_arm_bone_indices()- if (arm_bone_indices.size === 0) { return }-- const fallback_bones = this.build_fallback_bone_candidates(arm_bone_indices)- if (fallback_bones.length === 0) { return }-- this.correct_vertex_weights(skin_indices, skin_weights, plane_x, arm_bone_indices, fallback_bones)- }-- /**- * Every upperarm bone plus all of its descendants (lowerarm, hand, fingers),- * on both sides. Walking the hierarchy rather than matching a keyword list- * gives exactly "upperarm and below" without needing to enumerate every- * finger bone name, and it leaves the clavicle alone.- */- private find_arm_bone_indices (): Set<number> {- const bone_to_index = new Map<Bone, number>()- this.bones.forEach((bone, idx) => bone_to_index.set(bone, idx))-- const arm_bone_indices = new Set<number>()-- this.bones.forEach((bone) => {- if (!bone.name.toLowerCase().includes('upperarm')) { return }-- bone.traverse((descendant) => {- if (!(descendant instanceof Bone)) { return }- const index = bone_to_index.get(descendant)- if (index !== undefined) {- arm_bone_indices.add(index)- }- })- })-- return arm_bone_indices- }-- /**- * Bones a stripped vertex can be handed to: everything that isn't an arm bone,- * minus the root (global transform only) and leaf/orientation bones, which the- * solver never assigns vertices to.- */- private build_fallback_bone_candidates (arm_bone_indices: Set<number>): Array<{ index: number, midpoint: Vector3 }> {- const candidates: Array<{ index: number, midpoint: Vector3 }> = []-- this.bones.forEach((bone, idx) => {- if (arm_bone_indices.has(idx)) { return }- if (bone.name === 'root' || Utility.is_leaf_bone(bone)) { return }- candidates.push({ index: idx, midpoint: Utility.bone_midpoint_to_child(bone) })- })-- return candidates- }-- private correct_vertex_weights (- skin_indices: number[],- skin_weights: number[],- plane_x: number,- arm_bone_indices: Set<number>,- fallback_bones: Array<{ index: number, midpoint: Vector3 }>- ): void {- const vertex_count = this.geometry.attributes.position.array.length / 3-- for (let i = 0; i < vertex_count; i++) {- const vertex_position = new Vector3().fromBufferAttribute(this.geometry.attributes.position, i)-- // Math.abs is what makes this symmetric: one slider drives both arms,- // regardless of which side of the model is +X.- if (Math.abs(vertex_position.x) >= plane_x) { continue } // outboard of the plane, genuinely arm territory-- const offset = i * 4-- // Take the weight away from every arm bone influencing this vertex.- // Index 0 is the root bone, which never receives weights, so it doubles- // as the "empty slot" marker (same convention as HeadWeightCorrector).- let stolen_weight = 0- let first_freed_slot = -1- for (let j = 0; j < 4; j++) {- if (!arm_bone_indices.has(skin_indices[offset + j])) { continue }- if (skin_weights[offset + j] <= 0) { continue }-- stolen_weight += skin_weights[offset + j]- skin_weights[offset + j] = 0- skin_indices[offset + j] = 0- if (first_freed_slot === -1) {- first_freed_slot = j- }- }-- if (stolen_weight <= 0) { continue }-- const replacement_bone_index = this.find_closest_fallback_bone(vertex_position, fallback_bones)-- // Merge into the replacement bone's existing slot if it already influences- // this vertex, otherwise reuse one of the slots we just emptied.- let target_slot = -1- for (let j = 0; j < 4; j++) {- if (skin_indices[offset + j] === replacement_bone_index && skin_weights[offset + j] > 0) {- target_slot = j- break- }- }-- if (target_slot === -1) {- target_slot = first_freed_slot- skin_indices[offset + target_slot] = replacement_bone_index- }-- skin_weights[offset + target_slot] += stolen_weight-- this.normalize_vertex_weights(skin_weights, offset)- }- }-- private find_closest_fallback_bone (- vertex_position: Vector3,- fallback_bones: Array<{ index: number, midpoint: Vector3 }>- ): number {- let closest_distance = Infinity- let closest_index = fallback_bones[0].index-- for (const candidate of fallback_bones) {- const distance = candidate.midpoint.distanceTo(vertex_position)- if (distance < closest_distance) {- closest_distance = distance- closest_index = candidate.index- }- }-- return closest_index- }-- /**- * Normalize weights for a single vertex to ensure they sum to 1.0- */- private normalize_vertex_weights (skin_weights: number[], offset: number): void {- const total_weight =- skin_weights[offset] +- skin_weights[offset + 1] +- skin_weights[offset + 2] +- skin_weights[offset + 3]-- if (total_weight > 0) {- skin_weights[offset] /= total_weight- skin_weights[offset + 1] /= total_weight- skin_weights[offset + 2] /= total_weight- skin_weights[offset + 3] /= total_weight- }- }-}diff --git a/src/lib/solvers/SkinningAlgorithm.ts b/src/lib/solvers/SkinningAlgorithm.tsindex 31bfedd..a92bf48 100644--- a/src/lib/solvers/SkinningAlgorithm.ts+++ b/src/lib/solvers/SkinningAlgorithm.ts@@ -7,7 +7,6 @@ import {import { Utility } from '../Utilities.js'import { SkeletonType } from '../enums/SkeletonType.js'import { HeadWeightCorrector } from './HeadWeightCorrector.js'-import { ArmWeightCorrector } from './ArmWeightCorrector.js'import { WeightCalculator } from './WeightCalculator.js'import { ExtremityWeightCorrector } from './ExtremityWeightCorrector.js'import { WeightSmoother } from './WeightSmoother.js'@@ -31,11 +30,6 @@ export default class SkinningAlgorithm {private use_head_weight_correction: boolean = falseprivate preview_plane_height: number = 1.4- // Arm plane correction properties. The offset is relative to the shoulder- // joint's X, which the corrector reads off the bones itself.- private use_arm_plane_correction: boolean = false- private arm_plane_offset: number = 0.0-constructor (bone_hier: Object3D, skeleton_type: SkeletonType) {this.skeleton_type = skeleton_typethis.bones_master_data = Utility.bone_list_from_hierarchy(bone_hier)@@ -53,14 +47,6 @@ export default class SkinningAlgorithm {this.preview_plane_height = height}- public set_arm_plane_correction_enabled (enabled: boolean): void {- this.use_arm_plane_correction = enabled- }-- public set_arm_plane_offset (offset: number): void {- this.arm_plane_offset = offset- }-public calculate_indexes_and_weights (): number[][] {const skin_indices: number[] = []const skin_weights: number[] = []@@ -78,19 +64,6 @@ export default class SkinningAlgorithm {const extremity_corrector = new ExtremityWeightCorrector(this.geometry, this.bones_master_data)extremity_corrector.apply_extremity_weight_correction(skin_indices, skin_weights)- // Step 1c: Hand torso vertices back from the arm bones. Arms that hang down- // (A-pose or lower) run close to the ribcage, so the closest-bone pass gives- // them chest vertices. Runs before smoothing so the smoother blends the new- // torso/arm boundary instead of leaving a hard seam.- if (this.use_arm_plane_correction) {- const arm_weight_corrector = new ArmWeightCorrector(- this.geometry,- this.bones_master_data,- this.arm_plane_offset- )- arm_weight_corrector.apply_arm_weight_correction(skin_indices, skin_weights)- }-// Step 2: Smooth weight boundaries between adjacent bonesconst weight_smoother = new WeightSmoother(this.geometry, this.bones_master_data)weight_smoother.smooth_bone_weight_boundaries(skin_indices, skin_weights)