Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

don't show joints when loading skeleton templates

Scott Petrovic029e46c7cd12
diff --git a/src/lib/CustomSkeletonHelper.ts b/src/lib/CustomSkeletonHelper.ts
index 997dd1a..ffceca8 100644
--- a/src/lib/CustomSkeletonHelper.ts
+++ b/src/lib/CustomSkeletonHelper.ts
@@ -30,6 +30,9 @@ interface CustomSkeletonHelperOptions {
jointColor?: ColorRepresentation
thickness_ratio?: number
opacity?: number
+ // joints are only meaningful where the skeleton can be edited, so displays
+ // that are read only (the load skeleton preview) turn them off up front
+ showJoints?: boolean
}
const bone_category_colors: Record<BoneCategory, number> = {
@@ -186,6 +189,7 @@ class CustomSkeletonHelper extends InstancedMesh {
this.joint_points = new Points(pointsGeometry, pointsMaterial)
this.joint_points.frustumCulled = false
+ this.joint_points.visible = options.showJoints ?? true
this.add(this.joint_points)
// the bone shapes have to be sorted by camera distance, and onBeforeRender
diff --git a/src/lib/processes/load-skeleton/PreviewSkeletonManager.ts b/src/lib/processes/load-skeleton/PreviewSkeletonManager.ts
index a756d9d..b0c47d6 100644
--- a/src/lib/processes/load-skeleton/PreviewSkeletonManager.ts
+++ b/src/lib/processes/load-skeleton/PreviewSkeletonManager.ts
@@ -15,7 +15,8 @@ export async function add_preview_skeleton (
root: Scene,
skeleton_type: SkeletonType,
hand_skeleton_type: HandSkeletonType,
- skeleton_scale: number = 1.0
+ skeleton_scale: number = 1.0,
+ show_joints: boolean = true
): Promise<Object3D<Object3DEventMap>> {
let preview_skeleton_group = root.getObjectByName(skeleton_group_name) as Group | undefined
@@ -27,6 +28,15 @@ export async function add_preview_skeleton (
if (previous_file_path === skeleton_type && previous_hand_type === hand_skeleton_type) {
// Only update scale
preview_skeleton_group.scale.set(skeleton_scale, skeleton_scale, skeleton_scale)
+
+ // this path reuses a helper built by an earlier call, so the joint setting
+ // has to be reapplied here. Leaving it to the constructor alone meant a
+ // helper created while joints were on kept showing them
+ const existing_helper = preview_skeleton_group.getObjectByName('preview_skeleton')
+ if (existing_helper instanceof CustomSkeletonHelper) {
+ existing_helper.setJointsVisible(show_joints)
+ }
+
// Return the first child (should be loaded_scene)
return preview_skeleton_group.children[0]
} else {
@@ -57,7 +67,7 @@ export async function add_preview_skeleton (
}
// same custom helper used everywhere else, so the preview matches the
// edit skeleton display instead of three's default line skeleton
- const skeleton_helper = new CustomSkeletonHelper(loaded_scene)
+ const skeleton_helper = new CustomSkeletonHelper(loaded_scene, { showJoints: show_joints })
skeleton_helper.name = 'preview_skeleton'
preview_skeleton_group.add(skeleton_helper)
preview_skeleton_group.scale.set(skeleton_scale, skeleton_scale, skeleton_scale)
diff --git a/src/lib/processes/load-skeleton/StepLoadSkeleton.ts b/src/lib/processes/load-skeleton/StepLoadSkeleton.ts
index a426354..89a5ca2 100644
--- a/src/lib/processes/load-skeleton/StepLoadSkeleton.ts
+++ b/src/lib/processes/load-skeleton/StepLoadSkeleton.ts
@@ -69,8 +69,7 @@ export class StepLoadSkeleton extends EventTarget {
// when we come back to this step, there is a good chance we already selected a skeleton
// so just use that and load the preview right when we enter this step
if (!this.has_select_skeleton_ui_option()) {
- add_preview_skeleton(this._main_scene, this.skeleton_file_path(),
- this.hand_skeleton_type(), this.skeleton_scale_percentage).catch((err) => {
+ this.refresh_preview_skeleton().catch((err) => {
console.error('error loading preview skeleton: ', err)
})
@@ -148,7 +147,7 @@ export class StepLoadSkeleton extends EventTarget {
// load the preview skeleton
// need to get the file name for the correct skeleton
// we pass the skeleton scale in the case where we set a skeleton, change scale, then change the skeleton
- add_preview_skeleton(this._main_scene, this.skeleton_file_path(), this.hand_skeleton_type(), this.skeleton_scale()).then(() => {
+ this.refresh_preview_skeleton().then(() => {
// enable the ability to progress to next step
this.allow_proceeding_to_next_step(true)
}).catch((err) => {
@@ -176,7 +175,7 @@ export class StepLoadSkeleton extends EventTarget {
this.ui.dom_hand_skeleton_selection?.addEventListener('change', () => {
// rebuild the preview skeleton with the new hand skeleton type
// make sure we keep existing scale if we made a change to that
- add_preview_skeleton(this._main_scene, this.skeleton_file_path(), this.hand_skeleton_type(), this.skeleton_scale()).catch((err) => {
+ this.refresh_preview_skeleton().catch((err) => {
console.error('error loading preview skeleton: ', err)
})
})
@@ -202,12 +201,19 @@ export class StepLoadSkeleton extends EventTarget {
if (this.ui.dom_scale_skeleton_percentage_display !== null) {
this.ui.dom_scale_skeleton_percentage_display.textContent = display_value
}
- add_preview_skeleton(this._main_scene, this.skeleton_file_path(), this.hand_skeleton_type(), this.skeleton_scale_percentage)
+ this.refresh_preview_skeleton()
.catch((err) => {
console.error('error loading preview skeleton: ', err)
})
}
+ // the preview here is display only. The skeleton cannot be edited until the
+ // edit skeleton step, so the joint points are turned off for every rebuild
+ private async refresh_preview_skeleton (): Promise<Object3D<Object3DEventMap>> {
+ return await add_preview_skeleton(this._main_scene, this.skeleton_file_path(),
+ this.hand_skeleton_type(), this.skeleton_scale(), false)
+ }
+
public load_skeleton_file (file_path: string): void {
// load skeleton from GLB file
this.loader.load(file_path, (gltf: GLTFResult) => {