3D Editor: Persist gizmo is FK mode (#493)

This commit is contained in:
Tanish Manku authored and GitHub committed 2025-04-10 01:18:57 -07:00
1 parent e55bc020df
commit 2b453660da
2 files changed
+23 -3

No files matched your search

@@ -55,12 +55,20 @@ export class FKHelper {
}
// For each target bone, display a sphere to show the FK target and raycast intersect
const geometry = new THREE.SphereGeometry(1, 16, 16);
const geometry = new THREE.SphereGeometry(0.015, 16, 16);
const material = new THREE.MeshBasicMaterial({ color: 0xff0000, depthTest: false, transparent: true });
const sphere = new THREE.Mesh(geometry, material);
// FIX: Set the sphere scale to counter parent's world scale to remain constant in size
// TODO: Make a scale clamp
const parentScale = new THREE.Vector3();
child.getWorldScale(parentScale);
const sphereScale = new THREE.Vector3(1, 1, 1);
sphereScale.divide(parentScale);
sphere.scale.copy(sphereScale);
sphere.name = FKHelperSphereName;
const uniformScale = 1.5;
sphere.scale.set(uniformScale, uniformScale, uniformScale);
child.add(sphere);
this.targetBoneSpheres.push(sphere);
});
@@ -57,6 +57,7 @@ export class MouseControls {
private kinMode: KinMode = KinMode.NONE;
private fkHelper: FKHelper;
private isBoneDragged: boolean = false;
private ignoreNextClick: boolean = false;
constructor(
camera: THREE.PerspectiveCamera,
@@ -122,6 +123,10 @@ export class MouseControls {
onFKControlsDragging(dragging: boolean) {
this.isBoneDragged = dragging;
// FIX: Window dispatches a click event after FK dragging is complete
// This flag can be used to ignore that when FK is adjusted
this.ignoreNextClick = true;
}
clearFKVisuals() {
@@ -350,6 +355,13 @@ export class MouseControls {
if (this.camera == undefined) {
return;
}
// Ignore window clicks if FK is active and bone is being transformed
if (this.ignoreNextClick) {
this.ignoreNextClick = false;
return;
}
const camera_pos = new THREE.Vector3(
parseFloat(this.camera.position.x.toFixed(2)),
parseFloat(this.camera.position.y.toFixed(2)),