Open DmitriyIudokhin opened 8 months ago
Thanks for using camera-controls. I think it's because setOrbitPoint calls setFocalOffset internally, and focalOffset causes many problems, like
TBH, I would like to remove focalOffset
and related features such as setOrbitPoint
, but still available for backward compat😢
The best solution is, to avoid using setFocalOffset...
But in your examples setOrbitPoint with dollyToCursor is working well. Maybe it is because of using Perspective camera(your examples) instead of Orthographic(in my app)?
setOrbitPoint with dollyToCursor
Come to think of it, that's right. Would you mind providing a simplified working demo using codesanbox or so to just reproduce your problem?
setFocalOffset
will break dollyToCursor = true
anyway...
I had the same problem with my project. I solved it by recalculating the target for the controller with every mouse-up event (after every rotation with changing the orbitPoint). I scale the look vector of the camera with the radius of the spherical in the control and then move the new target with moveTo. Similar to the fitToSphere
const spherical = new THREE.Spherical(0, 0, 0);
const vTempA = new THREE.Vector3();
const vTempB = new THREE.Vector3();
container.addEventListener('mouseup', (evt) => {
if(event.which === 3 ){
if (controls._camera.isOrthographicCamera) {
controls.getSpherical(spherical); //Get sperical who is used to calculate the camera position in the update loop
vTempA.set(controls._camera.position.x, controls._camera.position.y, controls._camera.position.z); //Get camera position
vTempB.set(0, 0, -1).applyQuaternion(controls._camera.quaternion); //Get the look vector from the camera
vTempB.multiplyScalar(spherical.radius); //scale the look vector
vTempB.add(vTempA); // add the camera position to get the new target position
controls.setFocalOffset(0, 0, 0, false).then();
controls.moveTo(vTempB.x, vTempB.y, vTempB.z, false).then(); //Move the new target to the position
controls.update(0.0001);
} else {
controls.setOrbitPoint(0, 0, 0, false);
}
}
});
I haven't checked the other functions of the controller to see if they still work, as that was the most important thing for me that time.
Getting focalOffset working so we could use set orbitpoint without side effects would be very nice. Atm user in my app need to use ALT+ mouse click to set orbit point. (I then use controller.setTarget(x, y, z, true), so it centers it) But I notice som users coming fram navisworks really do not like it.
Been a while since I tested, but doing reset on some actions might work.. think it was mainly when using AWSD keys I got some weird jumping, maybe dolly to cursor too.
Think I will give it a new try this week 😄
Describe the bug
Hi. thanks for this library. It helps a lot but i cant solve one problem. I have OrthographicCamera and dollyToCursor working well but when i setOrbitPoint manually ( i want rotation around my part on scene) or make a movement with offset => after that when zooming with dollyToCursor it jumps by some delta. Video attached.
To Reproduce
Steps to reproduce the behavior:
Code
Live example
No response
Expected behavior
dolly to cursor dollies exactly to mouse location
Screenshots or Video
https://github.com/yomotsu/camera-controls/assets/112622889/a48ae260-3191-406c-89d9-94aa8eee81b6
Device
Desktop
OS
Windows
Browser
Chrome