Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

cleanup unused skinning formula stuff. minor refactoring

Scott Petrovic4ace93e7177e
diff --git a/src/lib/enums/SkinningFormula.ts b/src/lib/enums/SkinningFormula.ts
deleted file mode 100644
index 9768acd..0000000
--- a/src/lib/enums/SkinningFormula.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-// we have simplified skinning formulas to just one option for now
-export enum SkinningFormula {
- DistanceChildTargeting = 'distance-child-targeting'
-}
diff --git a/src/lib/processes/edit-skeleton/StepEditSkeleton.ts b/src/lib/processes/edit-skeleton/StepEditSkeleton.ts
index d881a93..4db8539 100644
--- a/src/lib/processes/edit-skeleton/StepEditSkeleton.ts
+++ b/src/lib/processes/edit-skeleton/StepEditSkeleton.ts
@@ -17,7 +17,6 @@ import {
TextureLoader,
type Camera
} from 'three'
-import { SkinningFormula } from '../../enums/SkinningFormula.ts'
import { SkeletonType } from '../../enums/SkeletonType.ts'
/*
diff --git a/src/lib/processes/weight-skin/StepWeightSkin.ts b/src/lib/processes/weight-skin/StepWeightSkin.ts
index 575b558..f367001 100644
--- a/src/lib/processes/weight-skin/StepWeightSkin.ts
+++ b/src/lib/processes/weight-skin/StepWeightSkin.ts
@@ -1,8 +1,6 @@
import { UI } from '../../UI.ts'
import SolverDistanceChildTargeting from '../../solvers/SolverDistanceChildTargeting.ts'
-import { SkinningFormula } from '../../enums/SkinningFormula.ts'
-
import { Generators } from '../../Generators.ts'
import { type BufferGeometry, type Material, type Object3D, type Skeleton, SkinnedMesh, type Scene, Group, Uint16BufferAttribute, Float32BufferAttribute } from 'three'
@@ -80,20 +78,6 @@ export class StepWeightSkin extends EventTarget {
this.bone_skinning_formula.set_geometry(geometry)
}
- public test_geometry (): BoneTesterData {
- if (this.bone_skinning_formula === undefined) {
- console.warn('Tried to test_geometry() in weight skinning step, but bone_skinning_formula is undefined!')
- return new BoneTesterData([], [])
- }
-
- if (this.show_debug) {
- this.bone_skinning_formula.set_show_debug(this.show_debug)
- this.bone_skinning_formula.set_debugging_scene_object(this.debug_scene_object)
- this.bone_skinning_formula.set_bone_index_to_test(this.bone_index_to_test)
- }
-
- return this.bone_skinning_formula.test_bones_outside_in_mesh()
- }
public create_binding_skeleton (): void {
if (this.skinning_armature === undefined) {
diff --git a/src/lib/solvers/AbstractAutoSkinSolver.ts b/src/lib/solvers/AbstractAutoSkinSolver.ts
index 6622afc..c8b39aa 100644
--- a/src/lib/solvers/AbstractAutoSkinSolver.ts
+++ b/src/lib/solvers/AbstractAutoSkinSolver.ts
@@ -47,10 +47,6 @@ export abstract class AbstractAutoSkinSolver {
return this.bones_master_data
}
- public test_bones_outside_in_mesh (): BoneTesterData {
- return new BoneTesterData([], [])
- }
-
protected geometry_vertex_count (): number {
if (this.geometry === null) {
console.error('Geometry is null. cannot get vertex count')
diff --git a/src/lib/solvers/BoneWeightsByMedianDistance.ts b/src/lib/solvers/BoneWeightsByMedianDistance.ts
index f11aa9b..a5e741f 100644
--- a/src/lib/solvers/BoneWeightsByMedianDistance.ts
+++ b/src/lib/solvers/BoneWeightsByMedianDistance.ts
@@ -82,9 +82,4 @@ export default class BoneWeightsByMedianDistance implements IAutoSkinSolver {
const output = [this.skin_indices, this.skin_weights]
return output
}
-
- public test_bones_outside_in_mesh (): BoneTesterData {
- // don't do test for now and just return success
- return new BoneTesterData([], [])
- }
} // end class
diff --git a/src/lib/solvers/SolverDistanceChildTargeting.ts b/src/lib/solvers/SolverDistanceChildTargeting.ts
index 07536ab..29966fc 100644
--- a/src/lib/solvers/SolverDistanceChildTargeting.ts
+++ b/src/lib/solvers/SolverDistanceChildTargeting.ts
@@ -20,6 +20,50 @@ export default class SolverDistanceChildTargeting extends AbstractAutoSkinSolver
private use_head_weight_correction: boolean = false
private preview_plane_height: number = 1.4
+ public calculate_indexes_and_weights (): number[][] {
+ // There can be multiple objects that need skinning, so
+ // this will make sure we have a clean slate by putting it in function
+ const skin_indices: number[] = []
+ const skin_weights: number[] = []
+
+ // create cached items for all the vertex calculations later
+ // this.cached_bone_positions = this.get_bone_master_data().map(b => Utility.world_position_from_object(b))
+ this.cached_median_child_bone_positions = this.get_bone_master_data().map(b => this.midpoint_to_child(b))
+
+ this.get_bone_master_data().forEach((b, idx) => this.bone_object_to_index.set(b, idx))
+ this.distance_to_bottom_of_hip = this.calculate_distance_to_bottom_of_hip()
+
+ console.time('calculate_closest_bone_weights')
+ this.calculate_median_bone_weights(skin_indices, skin_weights)
+ this.smooth_bone_weight_boundaries(skin_indices, skin_weights)
+ console.timeEnd('calculate_closest_bone_weights')
+
+ if (this.show_debug) {
+ this.debugging_scene_object.add(this.objects_to_show_for_debugging(skin_indices))
+ this.points_to_show_for_debugging.length = 0 // Clear the points after adding to the scene
+ }
+
+ // find out if any weights aren't adding up to 1.0
+ // go through each incorrect weight influence. Fill in the 0.00 weight with the remaining weght so
+ // all the weights add up to 1.0
+ this.normalize_weights_with_incorrect_vertices(skin_weights)
+
+ // Apply head weight correction if enabled
+ if (this.use_head_weight_correction) {
+ const head_weight_corrector = new HeadWeightCorrector(
+ this.geometry,
+ this.get_bone_master_data(),
+ this.preview_plane_height
+ )
+ console.log('applying the head weight correction...')
+ head_weight_corrector.apply_head_weight_correction(skin_indices, skin_weights)
+ }
+
+ console.log('do we have any leftover incorrect weights ', this.find_vertices_with_incorrect_weight_sum(skin_weights))
+
+ return [skin_indices, skin_weights]
+ }
+
/**
* Enable or disable head weight correction
*/
@@ -37,7 +81,7 @@ export default class SolverDistanceChildTargeting extends AbstractAutoSkinSolver
/**
* Returns an array of vertex indices whose weights do not sum to 1.0 (within a small epsilon).
*/
- public find_vertices_with_incorrect_weight_sum (skin_weights: number[]): number[] {
+ private find_vertices_with_incorrect_weight_sum (skin_weights: number[]): number[] {
const epsilon: number = 1e-4 // very small number to signify close enough to 0
const incorrect_vertices: number[] = []
const vertex_count = this.geometry_vertex_count()
@@ -165,50 +209,6 @@ export default class SolverDistanceChildTargeting extends AbstractAutoSkinSolver
}
}
- public calculate_indexes_and_weights (): number[][] {
- // There can be multiple objects that need skinning, so
- // this will make sure we have a clean slate by putting it in function
- const skin_indices: number[] = []
- const skin_weights: number[] = []
-
- // create cached items for all the vertex calculations later
- // this.cached_bone_positions = this.get_bone_master_data().map(b => Utility.world_position_from_object(b))
- this.cached_median_child_bone_positions = this.get_bone_master_data().map(b => this.midpoint_to_child(b))
-
- this.get_bone_master_data().forEach((b, idx) => this.bone_object_to_index.set(b, idx))
- this.distance_to_bottom_of_hip = this.calculate_distance_to_bottom_of_hip()
-
- console.time('calculate_closest_bone_weights')
- this.calculate_median_bone_weights(skin_indices, skin_weights)
- this.smooth_bone_weight_boundaries(skin_indices, skin_weights)
- console.timeEnd('calculate_closest_bone_weights')
-
- if (this.show_debug) {
- this.debugging_scene_object.add(this.objects_to_show_for_debugging(skin_indices))
- this.points_to_show_for_debugging.length = 0 // Clear the points after adding to the scene
- }
-
- // find out if any weights aren't adding up to 1.0
- // go through each incorrect weight influence. Fill in the 0.00 weight with the remaining weght so
- // all the weights add up to 1.0
- this.normalize_weights_with_incorrect_vertices(skin_weights)
-
- // Apply head weight correction if enabled
- if (this.use_head_weight_correction) {
- const head_weight_corrector = new HeadWeightCorrector(
- this.geometry,
- this.get_bone_master_data(),
- this.preview_plane_height
- )
- console.log('applying the head weight correction...')
- head_weight_corrector.apply_head_weight_correction(skin_indices, skin_weights)
- }
-
- console.log('do we have any leftover incorrect weights ', this.find_vertices_with_incorrect_weight_sum(skin_weights))
-
- return [skin_indices, skin_weights]
- }
-
private normalize_weights_with_incorrect_vertices (all_skin_weights: number[]): void {
const vertices_that_do_not_have_influences_adding_to_one: number[] = this.find_vertices_with_incorrect_weight_sum(all_skin_weights)
for (const vertex_index of vertices_that_do_not_have_influences_adding_to_one) {