三台摄像头三。
在三分js中,我如何从一个相机切换到另一台相机,理想情况下,通过平滑的过渡/补间?
假设我们的场景有两个物体,一个岩石和一棵树。对于每个对象,都有一个专用的相机来查看它。我希望能够在这两个摄像机之间顺利过渡。
PS:避免任何混乱,我的设置有两个相机,但一个视口。
例子:
// Rock camera
const rockCamera = new THREE.PerspectiveCamera(75, sizes.width/sizes.height, 0.1, 1000);
rockCamera.rotation.x = THREE.MathUtils.degToRad(-50);
rockCamera.position.set(2, 13, 8,);
scene.add(rockCamera);
// Tree camera
const treeCamera = new THREE.PerspectiveCamera(75, sizes.width/sizes.height, 0.1, 1000);
treeCamera.rotation.x = THREE.MathUtils.degToRad(25);
treeCamera.position.set(7, 5, 12,);
scene.add(treeCamera);
In Three.js, how can I switch from one camera to another, ideally with a smooth transition/tween?
Let's assume our scene has two objects, a rock and a tree. For each object, there is a dedicated camera set up to look at it. I want to be able to transition smoothly between those two cameras.
PS: To avoid any confusion, my setup has two cameras, but one viewport.
Example:
// Rock camera
const rockCamera = new THREE.PerspectiveCamera(75, sizes.width/sizes.height, 0.1, 1000);
rockCamera.rotation.x = THREE.MathUtils.degToRad(-50);
rockCamera.position.set(2, 13, 8,);
scene.add(rockCamera);
// Tree camera
const treeCamera = new THREE.PerspectiveCamera(75, sizes.width/sizes.height, 0.1, 1000);
treeCamera.rotation.x = THREE.MathUtils.degToRad(25);
treeCamera.position.set(7, 5, 12,);
scene.add(treeCamera);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(3)
使用一台相机,然后在开始位置/旋转和位置/旋转之间插值。例如:
W
是范围[0.0,1.0]中的浮点值。随着时间的流逝更改值,并在每个帧中更改相机:Use one camera and interpolate between the start position/rotation and position/rotation over time. e.g.:
w
is a floating point value that in range [0.0, 1.0]. Change the value over time and change the camera in every frame:您需要更改您对相机的看法。
相机是您在画布上渲染的内容,因此无法通过在2个具有不同位置的摄像机之间切换来平稳过渡。
而不是具有
rockcamera
和treecamera
。您可以将其更改为空对象,
rockObject
和treebject
。并将其用作位置枢轴以插入主摄像头。
可以帮助您进行摄像机插值的一件事是使用Tween引擎,例如Tween.js。
这是一个示例 https://sbcode.net/threejs/thee/theen/
You need to change you're perspective about the camera a bit.
The camera is what you render on the canvas so there is no way to smoothly transition by switching between 2 cameras with a different positions.
Instead of having
rockCamera
andtreeCamera
.You could change it into empty objects,
rockObject
andtreeObject
.And use it as position pivots to interpolate your main camera.
One thing that could help you with camera interpolation is using the tween engine like Tween.js.
Here is an example https://sbcode.net/threejs/tween/
如果您想创建一个过渡,在某个时候(a)在某个时候渲染了树相机; (b)在以后的某个时候,摇滚摄像头被渲染; (c)在两者之间的某个时候,两个相机的位都呈现,然后您需要使用后处理。 three.js提供示例该示例使用两个不同的场景,但是将其修改以将一个场景与两个摄像机一起使用是微不足道的。
If you're looking to create a transition where (a) at some time, the tree camera is rendered; (b) at some later time, the rock camera is rendered; and (c) at some time in between, bits of both cameras are rendered, then you'll want to use post-processing. Three.js provides an example of this kind of transition; that example uses two different scenes, but modifying it to use one scene with two cameras is trivial.