Import a 3D Model and automatically assign and export animations
TypeScript
Don't allow root bone to be selectable for now
Scott Petrovicc01a422db6ac
diff --git a/src/lib/Utilities.ts b/src/lib/Utilities.tsindex 9fa4c00..249c79a 100644--- a/src/lib/Utilities.ts+++ b/src/lib/Utilities.ts@@ -220,7 +220,7 @@ export class Utility {.replace(/(Right|Right_|R_|_Right|_R|Left|Left_|_Left|L_|_R|_L)/g, '')}- static raycast_closest_bone_test (camera: PerspectiveCamera, mouse_event: MouseEvent, skeleton: Skeleton): Array<number | null> {+ static raycast_closest_bone_test (camera: PerspectiveCamera, mouse_event: MouseEvent, skeleton: Skeleton): [Bone | null, number, number] {// Find the closest bone for raycaster. Select thatconst raycaster: Raycaster = new Raycaster()raycaster.setFromCamera(Utility.normalized_mouse_position(mouse_event), camera)@@ -228,7 +228,7 @@ export class Utility {let closest_bone_index = 0let closest_distance = Infinity- skeleton.bones.forEach((bone, bone_index) => {+ skeleton.bones.forEach((bone: Bone, bone_index: number) => {const world_position = Utility.world_position_from_object(bone)const target = new Vector3()const point = raycaster.ray.closestPointToPoint(world_position, target)@@ -241,7 +241,7 @@ export class Utility {}})- const output = [closest_bone, closest_bone_index, closest_distance]+ const output: [Bone | null, number, number] = [closest_bone, closest_bone_index, closest_distance]return output}diff --git a/src/script.ts b/src/script.tsindex 20d4fb8..60c300b 100644--- a/src/script.ts+++ b/src/script.ts@@ -287,8 +287,15 @@ export class Bootstrap {return}+ // this returns 3 values, so we can destructure them. do not remove any of these+ // even if one of them is not used, otherwise there will be weird issuesconst [closest_bone, closest_bone_index, closest_distance] = Utility.raycast_closest_bone_test(this.camera, mouse_event, skeleton_to_test)+ // don't allow to select root bone for now+ if (closest_bone?.name === 'root') {+ return+ }+// only do selection if we are close// the orbit controls also have panning with alt-click, so we don't want to interfere with thatif (closest_distance === null || closest_distance > this.transform_controls_hover_distance) {@@ -298,7 +305,6 @@ export class Bootstrap {if (closest_bone !== null) {this.transform_controls.attach(closest_bone)this.edit_skeleton_step.set_currently_selected_bone(closest_bone)- // this.weight_skin_step.set_bone_index_to_test(closest_bone_index)} else {this.edit_skeleton_step.set_currently_selected_bone(null)}