Compare commits

...
Author SHA1 Message Date
Tanish Manku e80a823521 Make the FK spheres scale-independent 2025-04-09 15:31:01 -07:00
Tanish Manku 24820fb6b0 Ignore dispatched click after gizmo is dragged 2025-04-09 15:30:20 -07:00
2 changed files with 23 additions and 3 deletions
@@ -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)),