Import a 3D Model and automatically assign and export animations
TypeScript
Added some data structures to make the data passed around more clear
Scott Petrovic7f19606c2ca7
diff --git a/src/lib/Utilities.ts b/src/lib/Utilities.tsindex 1f2e877..b8484ac 100644--- a/src/lib/Utilities.ts+++ b/src/lib/Utilities.ts@@ -1,9 +1,10 @@import {Vector3, Vector2, type Object3D, Mesh, Group, Bone, type Skeleton, Euler, Raycaster,- type PerspectiveCamera, type Scene, type Object3DEventMap, type BufferAttribute, BufferGeometry+ type PerspectiveCamera, type Scene, type Object3DEventMap, type BufferAttribute, BufferGeometry, InterleavedBufferAttribute} from 'three'import BoneTransformState from './models/BoneTransformState'import BoneCalculationData from './models/BoneCalculationData'+import IntersectionPointData from './models/IntersectionPointData'// eslint-disable-next-line @typescript-eslint/no-extraneous-classexport class Utility {@@ -38,14 +39,15 @@ export class Utility {}static is_point_in_box (point: Vector3, box_mesh: Mesh): boolean {+ // Transform the point from world space into the objects space+ box_mesh.updateMatrixWorld()+ const local_point: Vector3 = box_mesh.worldToLocal(point.clone())+if (box_mesh.geometry.boundingBox === null) {- console.warn('is_point_in_box() - box_mesh does not have a bounding box')+ console.warn('is_point_in_box() - box_mesh does not have a bounding box', box_mesh)return false}- // Transform the point from world space into the objects space- box_mesh.updateMatrixWorld()- const local_point: Vector3 = box_mesh.worldToLocal(point.clone())return box_mesh.geometry.boundingBox.containsPoint(local_point)}@@ -110,7 +112,8 @@ export class Utility {return bone_list}- static intersection_points_between_positions_and_mesh (positions: BufferAttribute, envelope_mesh: Mesh) {+ static intersection_points_between_positions_and_mesh (positions: BufferAttribute | InterleavedBufferAttribute,+ envelope_mesh: Mesh): IntersectionPointData {const vertex_positions_inside_bone_envelope: Vector3[] = []const vertex_indexes_inside_bone_evelope: number[] = []const vertex_count: number = positions.array.length / 3@@ -125,7 +128,7 @@ export class Utility {}}- return { vertex_positions_inside_bone_envelope, vertex_indexes_inside_bone_evelope }+ return new IntersectionPointData(vertex_positions_inside_bone_envelope, vertex_indexes_inside_bone_evelope)}/**@@ -159,8 +162,6 @@ export class Utility {this.remove_object_array(existing_debugging_container)existing_debugging_container.clear()scene.remove(existing_debugging_container)- } else {- console.warn('regenerate_debugging_scene() error - debugging container does not exist')}// add a reusable container for debuggingdiff --git a/src/lib/interfaces/IAutoSkinSolver.ts b/src/lib/interfaces/IAutoSkinSolver.tsindex 84818e1..64cd641 100644--- a/src/lib/interfaces/IAutoSkinSolver.ts+++ b/src/lib/interfaces/IAutoSkinSolver.ts@@ -1,4 +1,5 @@import { type Object3D, type BufferGeometry } from 'three'+import type BoneTesterData from '../models/BoneTesterData'export interface IAutoSkinSolver {set_geometry: (geom: BufferGeometry) => void@@ -6,4 +7,5 @@ export interface IAutoSkinSolver {set_show_debug: (debug_value: boolean) => voidset_bone_index_to_test: (bone_idx: number) => voidcalculate_indexes_and_weights: () => number[][]+ test_bones_outside_in_mesh: () => BoneTesterData}diff --git a/src/lib/models/BoneTesterData.ts b/src/lib/models/BoneTesterData.tsnew file mode 100644index 0000000..cc607a8--- /dev/null+++ b/src/lib/models/BoneTesterData.ts@@ -0,0 +1,12 @@+import { type Vector3 } from 'three'++// returns back if we are having issues with bones inside of mesh+export default class BoneTesterData {+ public bones_names_with_errors: string[] = []+ public bones_vertices_with_errors: Vector3[] = []++ constructor (bones_names_with_errors: string[], bones_vertices_with_errors: Vector3[]) {+ this.bones_names_with_errors = bones_names_with_errors+ this.bones_vertices_with_errors = bones_vertices_with_errors+ }+}diff --git a/src/lib/models/BoneTransformState.ts b/src/lib/models/BoneTransformState.tsindex b09ab86..393e24c 100644--- a/src/lib/models/BoneTransformState.ts+++ b/src/lib/models/BoneTransformState.ts@@ -1,14 +1,12 @@import { type Vector3 } from 'three'-export default class BoneTransformState-{+export default class BoneTransformState {public name: stringpublic position: Vector3public rotation: Vector3 // Not sure if this is rightpublic scale: Vector3- constructor (name = '', position: Vector3, rotation: Vector3, scale: Vector3)- {+ constructor (name = '', position: Vector3, rotation: Vector3, scale: Vector3) {this.name = namethis.position = positionthis.rotation = rotationdiff --git a/src/lib/models/IntersectionGeometryData.ts b/src/lib/models/IntersectionGeometryData.tsnew file mode 100644index 0000000..91b61c3--- /dev/null+++ b/src/lib/models/IntersectionGeometryData.ts@@ -0,0 +1,11 @@+import { type Vector3 } from 'three'++export default class IntersectionGeometryData {+ public vertices: Vector3[] = []+ public distances: number[] = []++ constructor (vertices: Vector3[], distances: number[]) {+ this.vertices = vertices+ this.distances = distances+ }+}diff --git a/src/lib/models/IntersectionPointData.ts b/src/lib/models/IntersectionPointData.tsnew file mode 100644index 0000000..3cad1cd--- /dev/null+++ b/src/lib/models/IntersectionPointData.ts@@ -0,0 +1,11 @@+import { type Vector3 } from 'three'++export default class IntersectionPointData {+ public vertex_positions: Vector3[] = []+ public vertex_indices: number[] = []++ constructor (vertex_positions: Vector3[], vertex_indices: number[]) {+ this.vertex_positions = vertex_positions+ this.vertex_indices = vertex_indices+ }+}diff --git a/src/lib/processes/StepWeightSkin.ts b/src/lib/processes/StepWeightSkin.tsindex 9d6fe39..de22b57 100644--- a/src/lib/processes/StepWeightSkin.ts+++ b/src/lib/processes/StepWeightSkin.ts@@ -9,19 +9,20 @@ import { SkinningFormula } from '../enums/SkinningFormula.ts'import { Generators } from '../Generators.ts'import { type BufferGeometry, type Material, type Object3D, type Skeleton, SkinnedMesh, type Scene } from 'three'+import { IAutoSkinSolver } from '../interfaces/IAutoSkinSolver.ts'+import BoneTesterData from '../models/BoneTesterData.ts'// Note: EventTarget is a built-ininterface and do not need to import itexport class StepWeightSkin extends EventTarget {private readonly ui: UI = new UI()private skinning_armature: Object3D | undefined- private bone_skinning_formula = null+ private bone_skinning_formula: IAutoSkinSolver | undefinedprivate binding_skeleton: Skeleton | undefinedprivate skinned_meshes: SkinnedMesh[] = []// debug options for bone skinning formula- private enable_debugging: boolean = falseprivate show_debug: boolean = false- private debug_scene_object: Scene | undefined+ private debug_scene_object: Object3D | undefinedprivate bone_index_to_test: number = -1public begin (): void {@@ -70,10 +71,20 @@ export class StepWeightSkin extends EventTarget {}public set_mesh_geometry (geometry: BufferGeometry): void {+ if (this.bone_skinning_formula === undefined) {+ console.warn('Tried to set_mesh_geometry() in weight skinning step, but bone_skinning_formula is undefined!')+ return+ }+this.bone_skinning_formula.set_geometry(geometry)}- public test_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)@@ -132,10 +143,10 @@ export class StepWeightSkin extends EventTarget {this.bone_index_to_test = index}- public calculate_weights () {- if (this.bone_skinning_formula === null) {- console.warn('Tried to calculate_weights() but bone_skinning_formula is null!')- return+ public calculate_weights (): number[][] {+ if (this.bone_skinning_formula === undefined) {+ console.warn('Tried to calculate_weights() but bone_skinning_formula is null for some reason!')+ return [[], []]}return this.bone_skinning_formula.calculate_indexes_and_weights()diff --git a/src/lib/solvers/BoneWeightsByDistance.ts b/src/lib/solvers/BoneWeightsByDistance.tsindex c67dfe0..23e08c1 100644--- a/src/lib/solvers/BoneWeightsByDistance.ts+++ b/src/lib/solvers/BoneWeightsByDistance.ts@@ -2,6 +2,7 @@ import { type Bone, BufferGeometry, Object3D, Vector3 } from 'three'import { Utility } from '../Utilities.js'import BoneCalculationData from '../models/BoneCalculationData.js'import { type IAutoSkinSolver } from '../interfaces/IAutoSkinSolver.js'+import BoneTesterData from '../models/BoneTesterData.js'export default class BoneWeightsByDistance implements IAutoSkinSolver {private readonly bones_master_data: BoneCalculationData[] = []@@ -66,10 +67,9 @@ export default class BoneWeightsByDistance implements IAutoSkinSolver {return [skin_indices, skin_weights]}- public test_bones_outside_in_mesh (): never[][] {+ public test_bones_outside_in_mesh (): BoneTesterData {// don't do test for now and just return success- const return_data = [[], []]- return return_data+ return new BoneTesterData([], [])}private init_bone_weights_data_structure (bone_hier: Object3D): void {diff --git a/src/lib/solvers/BoneWeightsByEnvelope.ts b/src/lib/solvers/BoneWeightsByEnvelope.tsindex 55f526b..216d399 100644--- a/src/lib/solvers/BoneWeightsByEnvelope.ts+++ b/src/lib/solvers/BoneWeightsByEnvelope.ts@@ -5,6 +5,9 @@ import { Utility } from '../Utilities.ts'import BoneCalculationData from '../models/BoneCalculationData.ts'import { BufferGeometry, type Bone, Object3D, Mesh, Vector3, Raycaster, type Intersection } from 'three'import { type IAutoSkinSolver } from '../interfaces/IAutoSkinSolver.ts'+import type IntersectionPointData from '../models/IntersectionPointData.ts'+import IntersectionGeometryData from '../models/IntersectionGeometryData.ts'+import BoneTesterData from '../models/BoneTesterData.ts'export class BoneWeightsByEnvelope implements IAutoSkinSolver {private bones_master_data: BoneCalculationData[] = []@@ -18,8 +21,7 @@ export class BoneWeightsByEnvelope implements IAutoSkinSolver {private readonly debug_sphere_color_failure = 0xff0000 // vertices that will have to use closest bone// two variables used for testing to see if we have an ok bone envelope to bind- private readonly bone_names_with_errors: string[] = []- private readonly bone_vertices_with_errors: Vector3[] = []+ private readonly bone_testing_data: BoneTesterData = new BoneTesterData([], [])constructor (bone_hier: Object3D) {this.init_bone_weights_data_structure(bone_hier)@@ -29,26 +31,20 @@ export class BoneWeightsByEnvelope implements IAutoSkinSolver {this.geometry = geom}- public test_bones_outside_in_mesh (): [string[], Vector3[]] {+ public test_bones_outside_in_mesh (): BoneTesterData {this.bones_master_data.forEach((bone: BoneCalculationData, bone_index: number) => {if (bone.supports_envelope_calculation) {const rays_to_cast: number = 4const bone_start: Bone = bone.bone_objectconst bone_end: Bone = bone.bone_object.children[0] as Boneconst intersection_plane_mesh = Generators.create_bone_plane_mesh(bone_start, bone_end, rays_to_cast)- const [intersection_distances] = this.intersections_for_geometry(rays_to_cast, intersection_plane_mesh)+ const geometry_data: IntersectionGeometryData = this.intersections_for_geometry(rays_to_cast, intersection_plane_mesh)const envelope_mesh = this.create_envelope_mesh_for_bone(bone)- this.expand_envelope_mesh_to_fit_bone(envelope_mesh, intersection_distances, bone)+ this.expand_envelope_mesh_to_fit_bone(envelope_mesh, geometry_data.distances, bone)}})- // there are some errors in bone positions being outside of the mesh.- // avoid future calculations and eventually exit out- if (this.bone_names_with_errors.length > 0) {- return [this.bone_names_with_errors, this.bone_vertices_with_errors]- }-- return [[], []]+ return this.bone_testing_data}public calculate_indexes_and_weights (): number[][] {@@ -63,18 +59,18 @@ export class BoneWeightsByEnvelope implements IAutoSkinSolver {const bone_start: Bone = bone.bone_objectconst bone_end: Bone = bone.bone_object.children[0] as Boneconst intersection_plane_mesh = Generators.create_bone_plane_mesh(bone_start, bone_end, rays_to_cast)- const [intersection_distances] = this.intersections_for_geometry(rays_to_cast, intersection_plane_mesh)+ const intersection_geometry_data: IntersectionGeometryData = this.intersections_for_geometry(rays_to_cast, intersection_plane_mesh)const envelope_mesh = this.create_envelope_mesh_for_bone(bone)- this.expand_envelope_mesh_to_fit_bone(envelope_mesh, intersection_distances, bone)+ this.expand_envelope_mesh_to_fit_bone(envelope_mesh, intersection_geometry_data.distances, bone)- const { vertex_positions_inside_bone_envelope, vertex_indexes_inside_bone_evelope } =- Utility.intersection_points_between_positions_and_mesh(this.geometry.attributes.position, envelope_mesh)+ const intersection_data: IntersectionPointData =+ Utility.intersection_points_between_positions_and_mesh(this.geometry.attributes.position, envelope_mesh)- bone.assigned_vertices.push(...vertex_indexes_inside_bone_evelope)+ bone.assigned_vertices.push(...intersection_data.vertex_indices)// show all of these visually when we are done with checks- vertex_points_that_passed.push(...vertex_positions_inside_bone_envelope)+ vertex_points_that_passed.push(...intersection_data.vertex_positions)envelope_shapes_to_show.push(envelope_mesh)}})@@ -93,8 +89,9 @@ export class BoneWeightsByEnvelope implements IAutoSkinSolver {// There could be some bones that aren't inside the mesh from the last calculation. This will mess up the bone envelope calculations// and need to be fixed. We need to abort the calculations- if (this.bone_names_with_errors.length > 0) {- throw new Error(`ERROR: Some bones are outside the mesh. Need to fix this. Bones: ${this.bone_names_with_errors}`)+ if (this.bone_testing_data.bones_names_with_errors.length > 0) {+ throw new Error(`ERROR: Some bones are outside the mesh.+ Need to fix this. Bones: ${this.bone_testing_data.bones_names_with_errors.toString()}`)}if (this.show_debug) {@@ -177,13 +174,11 @@ export class BoneWeightsByEnvelope implements IAutoSkinSolver {// 4 leg creature has entire word "right", while human has appreviation "R"let use_minimum_expand_distance: boolean = false- if (bone.name === 'Right_Front_Leg_Upper' ||- bone.name === 'Left_Front_Leg_Upper' ||- bone.name === 'Right_Back_Leg_Upper' ||- bone.name === 'L_Toe' ||- bone.name === 'R_Toe' ||- bone.name.includes('UpLeg') ||- bone.name === 'Left_Back_Leg_Upper') {+ if (bone.name.includes('Front_Leg_Upper') ||+ bone.name.includes('Back_Leg_Upper') ||+ bone.name.includes('_Toe') ||+ bone.name.includes('Shoulder') ||+ bone.name.includes('UpLeg')) {use_minimum_expand_distance = true}@@ -197,6 +192,7 @@ export class BoneWeightsByEnvelope implements IAutoSkinSolver {const envelope_color = 0xaaaaffconst envelope_geometry: BoneEnvelopeGeometry = new BoneEnvelopeGeometry()+const envelope_mesh = new Mesh(envelope_geometry as BufferGeometry, Generators.create_material(true, envelope_color))envelope_mesh.name = `Envelope Box Mesh: ${bone.name}`const padding_multiplier: number = 1.2 // scale the box to help with overlap and points just outside box@@ -212,23 +208,23 @@ export class BoneWeightsByEnvelope implements IAutoSkinSolver {const bone_direction = Utility.direction_between_points(Utility.world_position_from_object(bone_start), Utility.world_position_from_object(bone_end))const facing_direction = Utility.world_position_from_object(bone_end)envelope_mesh.position.copy(Utility.world_position_from_object(bone_start))- envelope_mesh.translateOnAxis(bone_direction, height*0.5)+ envelope_mesh.translateOnAxis(bone_direction, height * 0.5)envelope_mesh.lookAt(facing_direction)- envelope_mesh.rotateOnAxis(new Vector3(1,0,0), Math.PI * 0.5)+ envelope_mesh.rotateOnAxis(new Vector3(1, 0, 0), Math.PI * 0.5)return envelope_mesh}- private expand_envelope_mesh_to_fit_bone (envelope_mesh: Mesh, intersections, bone: BoneCalculationData): void {+ private expand_envelope_mesh_to_fit_bone (envelope_mesh: Mesh, intersection_distances: number[], bone: BoneCalculationData): void {const bone_start = bone.bone_objectconst bone_end = bone_start.children[0]// Grow bone envelope to fix spaceconst height = Utility.distance_between_objects(bone_start, bone_end)- const left_ray_distance: number = intersections[0]- const back_ray_distance: number = intersections[1]- const right_ray_distance: number = intersections[2]- const forward_ray_distance: number = intersections[3]+ const left_ray_distance: number = intersection_distances[0]+ const back_ray_distance: number = intersection_distances[1]+ const right_ray_distance: number = intersection_distances[2]+ const forward_ray_distance: number = intersection_distances[3]if (bone.use_minimum_envelope_expand) {const min_x_side = Math.min(right_ray_distance, left_ray_distance)@@ -238,21 +234,21 @@ export class BoneWeightsByEnvelope implements IAutoSkinSolver {BoneEnvelopeGeometryUtils.expand_x_negative_face(envelope_mesh.geometry, min_x_side)BoneEnvelopeGeometryUtils.expand_z_positive_face(envelope_mesh.geometry, min_z_side)BoneEnvelopeGeometryUtils.expand_z_negative_face(envelope_mesh.geometry, min_z_side)- BoneEnvelopeGeometryUtils.expand_y_positive_face(envelope_mesh.geometry, height*0.5)- BoneEnvelopeGeometryUtils.expand_y_negative_face(envelope_mesh.geometry, height*0.5)+ BoneEnvelopeGeometryUtils.expand_y_positive_face(envelope_mesh.geometry, height * 0.5)+ BoneEnvelopeGeometryUtils.expand_y_negative_face(envelope_mesh.geometry, height * 0.5)} else {BoneEnvelopeGeometryUtils.expand_x_positive_face(envelope_mesh.geometry, right_ray_distance)BoneEnvelopeGeometryUtils.expand_x_negative_face(envelope_mesh.geometry, left_ray_distance)BoneEnvelopeGeometryUtils.expand_z_positive_face(envelope_mesh.geometry, forward_ray_distance)BoneEnvelopeGeometryUtils.expand_z_negative_face(envelope_mesh.geometry, back_ray_distance)- BoneEnvelopeGeometryUtils.expand_y_positive_face(envelope_mesh.geometry, height*0.5)- BoneEnvelopeGeometryUtils.expand_y_negative_face(envelope_mesh.geometry, height*0.5)+ BoneEnvelopeGeometryUtils.expand_y_positive_face(envelope_mesh.geometry, height * 0.5)+ BoneEnvelopeGeometryUtils.expand_y_negative_face(envelope_mesh.geometry, height * 0.5)}// if a bone goes outside a mesh, the intersection will be undefined. keep track of what bones do this andif (left_ray_distance === undefined || right_ray_distance === undefined || back_ray_distance === undefined || forward_ray_distance === undefined) {- this.bone_names_with_errors.push(bone.name)- this.bone_vertices_with_errors.push(Utility.world_position_from_object(bone_start))+ this.bone_testing_data.bones_names_with_errors.push(bone.name)+ this.bone_testing_data.bones_vertices_with_errors.push(Utility.world_position_from_object(bone_start))return}@@ -260,11 +256,12 @@ export class BoneWeightsByEnvelope implements IAutoSkinSolver {envelope_mesh.geometry.computeBoundingBox() // need to recompute for collision next}- private intersections_for_geometry (rays_to_cast: number, debug_bone_plane_mesh: Mesh): Array<number[] | Vector3[]> {+ private intersections_for_geometry (rays_to_cast: number, debug_bone_plane_mesh: Mesh): IntersectionGeometryData {const intersection_distances: number[] = [] // ray cast around the object and find how far out the mesh goesconst intersection_vertexes: Vector3[] = [] // output for potentially showing in debuggerconst normal_mesh: Mesh = new Mesh(this.geometry, Generators.create_material(true))normal_mesh.name = 'Normal mesh used for intersection'+for (let j = 0; j < rays_to_cast; j++) {const point_2: Vector3 = Utility.world_position_from_object(debug_bone_plane_mesh.children[j])const ray_origin: Vector3 = Utility.world_position_from_object(debug_bone_plane_mesh)@@ -275,12 +272,20 @@ export class BoneWeightsByEnvelope implements IAutoSkinSolver {// this.debugging_scene_object.add(ray_helper)// calculate where closest intersection happensconst intersects: Intersection[] = raycaster.intersectObject(normal_mesh)++ // if there is no intersection, that means the bone is outside the mesh+ // and we need to abort calculations+ if (intersects.length === 0) {+ // this.bone_testing_data.bones_names_with_errors.push(debug_bone_plane_mesh.name)+ // this.bone_testing_data.bones_vertices_with_errors.push(Utility.world_position_from_object(debug_bone_plane_mesh))+ return new IntersectionGeometryData([], [])+ }+intersection_distances.push(intersects[0].distance)intersection_vertexes.push(intersects[0].point)} // end for loop through rays- const return_value = [intersection_distances, intersection_vertexes]- return return_value+ return new IntersectionGeometryData(intersection_vertexes, intersection_distances)}/**@@ -361,7 +366,6 @@ export class BoneWeightsByEnvelope implements IAutoSkinSolver {if (bone.name.includes('Fingers') ||bone.name.includes('HandBase') ||- bone.name.includes('Shoulder') ||bone.name === 'SpineUp') {return false}diff --git a/src/lib/solvers/BoneWeightsByMedianDistance.ts b/src/lib/solvers/BoneWeightsByMedianDistance.tsindex fc9a8cc..23b5921 100644--- a/src/lib/solvers/BoneWeightsByMedianDistance.ts+++ b/src/lib/solvers/BoneWeightsByMedianDistance.ts@@ -1,20 +1,22 @@import { Utility } from '../Utilities.js'-import { type Bone, BufferGeometry, type Object3D, type Scene, Vector3 } from 'three'+import { type Bone, BufferGeometry, Object3D, type Scene, Vector3 } from 'three'import BoneCalculationData from '../models/BoneCalculationData.js'+import { type IAutoSkinSolver } from '../interfaces/IAutoSkinSolver.js'+import BoneTesterData from '../models/BoneTesterData.js'/*** This calculation is similar to the normal bone weights by distance, but uses the* location half way between the bone and the child's bone. This gives better results with the joints* If there is no child bone, it just uses the bone's position for the distance calculation*/-export default class BoneWeightsByMedianDistance {+export default class BoneWeightsByMedianDistance implements IAutoSkinSolver {private geometry: BufferGeometry = new BufferGeometry()private readonly skin_indices: number[] = []private readonly skin_weights: number[] = []private show_debug: boolean = falseprivate bone_idx_test: number = -1private readonly bones_master_data: BoneCalculationData[] = []- private debugging_scene_object: Scene+ private debugging_scene_object: Object3D = new Object3D()constructor (bone_hier: Object3D) {this.init_bone_weights_data_structure(bone_hier)@@ -36,7 +38,7 @@ export default class BoneWeightsByMedianDistance {this.bone_idx_test = bone_idx}- public set_debugging_scene_object (scene_object: Scene): void {+ public set_debugging_scene_object (scene_object: Object3D): void {this.debugging_scene_object = scene_object}@@ -74,9 +76,8 @@ export default class BoneWeightsByMedianDistance {return output}- public test_bones_outside_in_mesh (): never[][] {+ public test_bones_outside_in_mesh (): BoneTesterData {// don't do test for now and just return success- const output = [[], []]- return output+ return new BoneTesterData([], [])}} // end classdiff --git a/src/script.ts b/src/script.tsindex dcc8d70..e19b864 100644--- a/src/script.ts+++ b/src/script.ts@@ -17,13 +17,14 @@ import { StepWeightSkin } from './lib/processes/StepWeightSkin.ts'import { ProcessStep } from './lib/enums/ProcessStep.ts'import { type Bone, Group, Scene, type Skeleton, type Vector3, type SkeletonHelper, type Points } from 'three'+import BoneTesterData from './lib/models/BoneTesterData.ts'export class Bootstrap {private readonly camera = Generators.create_camera()private readonly renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true })private controls: OrbitControls | undefined = undefined- private transform_controls: TransformControls | undefined = undefined+ private readonly transform_controls: TransformControls = new TransformControls(this.camera, this.renderer.domElement)private is_transform_controls_dragging: boolean = false// has UI elements on the HTML page that we will reference/use@@ -43,7 +44,7 @@ export class Bootstrap {private readonly clock = new THREE.Clock()- private environment_container: Group = new Group()+ private readonly environment_container: Group = new Group()public initialize (): void {this.setup_environment()@@ -70,9 +71,6 @@ export class Bootstrap {this.controls.target.set(0, 0.9, 0)this.controls.update()- // setup transform controls to eventually test out differnt bone rotations- this.transform_controls = new TransformControls(this.camera, this.renderer.domElement)-this.scene.add(this.transform_controls)// basic things in another group, to better isolate what we are working on@@ -105,11 +103,9 @@ export class Bootstrap {}}- private show_skin_failure_message (bones_with_errors: string[]): void {- console.log(bones_with_errors, 'BONE WITH ERRORS')-+ private show_skin_failure_message (bone_names_with_errors: string[], error_point_positions: Vector3[]): void {// add the bone vertices as sphere to debugging object- const sphere_failures: Points = Generators.create_spheres_for_points(bones_with_errors, 0.02, 0xff0000)+ const sphere_failures: Points = Generators.create_spheres_for_points(error_point_positions, 0.08, 0xff0000)this.debugging_visual_object.add(sphere_failures)// add information to the info panel@@ -123,8 +119,8 @@ export class Bootstrap {// display the bones names in an HTML listlet bones_error_list = '<ol id="bone-list">'- bones_with_errors.forEach((bone) => {- bones_error_list += `<li>${Utility.clean_bone_name_for_messaging(bone)}</li>`+ bone_names_with_errors.forEach((bone_name: string) => {+ bones_error_list += `<li>${Utility.clean_bone_name_for_messaging(bone_name)}</li>`})bones_error_list += '</ol>'@@ -338,7 +334,7 @@ export class Bootstrap {this.load_model_step.models_geometry_list().forEach((mesh_geometry, index) => {// we passed the bone test, so we can do the skinning processthis.weight_skin_step.set_mesh_geometry(mesh_geometry)- const [final_skin_indices, final_skin_weights] = this.weight_skin_step.calculate_weights()+ const [final_skin_indices, final_skin_weights]: number[][] = this.weight_skin_step.calculate_weights();mesh_geometry.setAttribute('skinIndex', new THREE.Uint16BufferAttribute(final_skin_indices, 4))mesh_geometry.setAttribute('skinWeight', new THREE.Float32BufferAttribute(final_skin_weights, 4))@@ -389,11 +385,12 @@ export class Bootstrap {let testing_geometry_success = truethis.load_model_step.models_geometry_list().forEach((mesh_geometry, index) => {this.weight_skin_step.set_mesh_geometry(mesh_geometry)- const [bone_names_failing_skin_test] = this.weight_skin_step.test_geometry()+ const tester_data: BoneTesterData = this.weight_skin_step.test_geometry()- if (bone_names_failing_skin_test.length > 0) {- const names_with_object_index: string[] = bone_names_failing_skin_test.map((bone_name: string) => bone_name + ` (${mesh_geometry.name})`)- this.show_skin_failure_message(names_with_object_index)+ if (tester_data.bones_names_with_errors.length > 0) {+ const names_with_object_index: string[] =+ tester_data.bones_names_with_errors.map((bone_name: string) => bone_name + ` ${mesh_geometry.name}`)+ this.show_skin_failure_message(names_with_object_index, tester_data.bones_vertices_with_errors)testing_geometry_success = false}})