-
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
several orbitcontrols: one per canvas in several views? #31
Comments
I think (1) should be solved in 1.0.10 — can you check it? —. I still have to look at (2). |
Hi Tiago, Regarding the second topic, I uploaded this animation, which is a recording from my android phone. (android 12 and expo on dev server) chair_leaves_canvas.mp4 |
@MainzerKaiser I couldn't reproduce this (but still didn't test in an Android though). Maybe you can share the whole code, or try to reduce the code where the bug happens? Also, does this bug happen on web too? |
@TiagoCavalcante, the bug does not happen on web, it only appears on anroid. I could not test ios, though. https://github.com/MainzerKaiser/testing_r3f_orbit_in_reactnative.git |
The bug isn't happening on iOS, I'll test it on Android soon. |
How would you go about resetting the camera settings on button click? |
If you are using an "external" camera like in the second example from README.md, you can set its If you are using the default Canvas camera you can obtain the camera object with If you are using function ComponentWhichMustBeInsideTheCanvas() {
const invalidate = useThree((state) => state.invalidate)
useEffect(() => {
// Click stuff
invalidate()
}, [dependencies])
return null as unknown as JSX.Element // This must be a JSX element
} |
Unfortunately I could not make it work. I cannot use the external camera as it screws up the rest of my code (placement of all objects). How would i go about resetting each of my canvas cameras, if they are introduced by the mapping of controlsAndEvents.
|
@MainzerKaiser can you check if the error is still happening with 1.0.12? |
Hi Tiago,
This is my package.json with comparable packages as in your package.json. Do you see what the problem is?
and the tsconfig.json:
|
Hi Tiago, But i could test the android version with your new 1.0.12.. And my original second issue:
still persists, unfortunately. Best regards, |
I encountered the same issue as you and have resolved it. Hopefully, the same approach works for you. I calculate the Euclidean distance between two positions using a formula. If the distance is greater than 2, I assume the position update is incorrect. const cameraRef = useRef<Camera>();
const lastCameraPositionRef = useRef<Vector3>();
const handleOrbitPositionUpdate = (position?: Vector3) => {
if (!position) return;
const lastCameraPosition = lastCameraPositionRef.current;
if (lastCameraPosition) {
const { x, y, z } = position;
const [x0, y0, z0] = lastCameraPosition;
const camera = cameraRef.current;
if (camera) {
// if the distance exceeds 2, assume the new position is incorrect.
const distance = Math.sqrt((x0 - x) ** 2 + (y0 - y) ** 2 + (z0 - z) ** 2);
if (distance >= 2) {
camera.position.set(x0, y0, z0);
invalidate();
return;
}
}
if(lastCameraPositionRef.current) {
lastCameraPositionRef.current = position;
}
}
};
<OrbitControls
onChange={event =>
handleOrbitPositionUpdate(event.target.camera?.position)
}
/> |
Thanks for that idea. I adopted it to my problem and in principle it works fine. What does your invalidate() function do?
Setting the event.target.camera.position.set(x0,y0,z0); to the lastCameraPosition in case the distance>2 is visibile as a small stutter. I'd rather have an option to invalidate every touch event outside of the canvas. WhatsApp.Video.2024-07-14.um.12.07.27_96d1e932.mp4 |
I use the invalidate function to quickly update the corrected position on the canvas. This is especially useful when your canvas frameLoop is set to demand (On-demand rendering). |
Hey @MainzerKaiser and @markhuang19994 Can you confirm if #47 fixes the problem you were facing, If this your only requirement then this could fix #33 as well. |
Thx ahkalor! |
Hey @MainzerKaiser All you have to do is git clone my forked repo and change it to the map controls branch inside your project directory. |
Ok, ill give it a try when I have time again. I read your code changes a bit and saw warnings about the camera being used. Does it work with my appraoch from above, where i only use the camera of the canvas or do i have to explicetly set a perpective camera like in the example code by Tiago?
|
Hey @MainzerKaiser That's only if you're using multiple canvases. There is no configuration change. Try and use it just like before and see if you're facing any issues. |
I want to render several models and each shall have its own canvas and orbitcontrols. I made that work by the following code, but I make two observation:
The text was updated successfully, but these errors were encountered: