Preventing Rotation Gizmo Value Reset After Full Cycle

Hi everyone,

I’m facing a challenge with the Rotation Gizmo where after completing a full rotation cycle, the rotation value resets between -3.14 and 3.14. I’m looking for a way to continuously increase or decrease the rotation value based on drag movements without this reset happening.

Essentially, I want the rotation numbers to keep going up or down, regardless of how many cycles have been completed. Any guidance on how to achieve this would be greatly appreciated.

Also this did not help;

initialRotation = mesh.rotation.clone();
gizmos.rotationGizmo.onDragObservable.add(() => {
    let rotationChange = mesh.rotation.y - initialRotation.y;
    mesh.rotation.y += rotationChange;
    initialRotation.y = mesh.rotation.y;
});

I think I found the solution;

let lastRotationY = box.rotation.y; // Track the last rotation
let accumulatedRotationY = 0; // Accumulate rotation changes
let currentRotationY;
let initialRotationY = box.rotation.y;

gizmo.onDragObservable.add(() => {
    currentRotationY = box.rotation.y;
    let rotationChange = currentRotationY - lastRotationY;

    // Adjust for rotation wrapping
    if (rotationChange > Math.PI) {
        rotationChange -= 2 * Math.PI;
    } else if (rotationChange < -Math.PI) {
        rotationChange += 2 * Math.PI;
    }

    accumulatedRotationY += rotationChange;
    lastRotationY = currentRotationY;

    // For debugging: Log the current and accumulated rotation in degrees
    console.log(`Current Rotation Y: ${BABYLON.Tools.ToDegrees(currentRotationY)} degrees`);
    console.log(`Accumulated Rotation Y: ${BABYLON.Tools.ToDegrees(accumulatedRotationY)} degrees`);
});

gizmo.onDragEndObservable.add(() => {
    console.log(accumulatedRotationY);
    box.rotation.y = initialRotationY + accumulatedRotationY;

    accumulatedRotationY = 0;
    initialRotationY = box.rotation.y;
});
1 Like