-
Hello, First, I have a lot of fun trying things with this library, thanks for you all to have made this possible. I really like playing with 3D in a declarative way! :) ProblemSo, what I try to do is to display a scene from a top-down perspective with a PerspectiveCamera, but on some conditions add over the already painted scene a new draw of a piece of the scene, allowing us to zoom on it. const { gl, scene, camera, size, viewport } = useThree()
const virtualCam = useRef<OrthographicCameraImpl>()
useFrame(() => {
gl.autoClear = true
gl.render(scene, camera)
gl.autoClear = false
gl.clearDepth()
if (virtualCam.current) {
gl.render(scene, virtualCam.current)
}
}, 1)
return (
<OrthographicCamera
ref={virtualCam}
makeDefault={false}
near={1}
far={10}
left={0}
right={20}
top={30}
bottom={10}
position={modelRef.current?.position.clone().add(new Vector3(-3, 0, 5))}
/>
) The issue is that the object already exists on the scene, so I can't really move the object so it fit the screen layout? For reference, $gsimone showed me those examples too:
Now I'm thinking that maybe i should recreate a new scene for this specific object. It seems scene are not too costly to create and destroy. But I've only a reference of the object, not a component ready to be created. Can it be done with a reference too? And is it safe to do so without really knowing what model will be put on the top right of the screen (can we scale the model so it fit inside the given screen space)? Many thanks :) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Hello, Just thinking it would be better with a codesandbox to show the current state: |
Beta Was this translation helpful? Give feedback.
-
Still slowly incrementing on this and still thinking I'm going the wrong way (but that's the only way I see for now). I've added Leva so you can see the effects of Zoom, screen space and screen position. I need now to adjust the zoom related to the screen position? I need to think about it, I don't even know how to manage this. Don't hesitate to give me some feedback on the subject, I would appreciate it! :) |
Beta Was this translation helpful? Give feedback.
-
Hello, So I'm gonna close this discussion because I've finally understood through this exercise that I was doing things wrong. I got a working version without doing all these manipulations. For those interested you can go there check it out: Code could still be cleaned a bit and simplified but the main principles are here and I'm satisfied to be able to crop, decorate, zoom and move around my target on the screen. |
Beta Was this translation helpful? Give feedback.
Hello,
So I'm gonna close this discussion because I've finally understood through this exercise that I was doing things wrong. I got a working version without doing all these manipulations. For those interested you can go there check it out:
https://codesandbox.io/s/1wxbv
https://1wxbv.csb.app/
Code could still be cleaned a bit and simplified but the main principles are here and I'm satisfied to be able to crop, decorate, zoom and move around my target on the screen.