[英]Three.js: attach object to camera but not make it rotate with it
I currently have a SphereGeometry attached to a Perspective Camera. 我目前将SphereGeometry附加到透视相机。 But when I rotate the camera, the Sphere rotates with the camera which is normal but in my case I do not want that. 但是,当我旋转相机时,Sphere随相机一起旋转,这是正常现象,但我不希望这样。
Here is what I have: 这是我所拥有的:
camera.add(Sphere);
Sphere.position.set (0, -100, 0);
What I want is to attach the sphere to the bottom of the camera but stay in that position. 我想要的是将球体连接到相机底部,但保持在该位置。 Currently, when I rotate the camera, the Sphere seems to rotate with it so I cannot see it. 目前,当我旋转相机时,Sphere似乎随其旋转,所以我看不到它。 How can I attach the child object in a way that does not rotate with the camera? 如何以不随相机旋转的方式附加子对象? Thanks. 谢谢。
One approach is to define an onBeforeRender()
method for your sphere mesh. 一种方法是为球体网格定义onBeforeRender()
方法。 For example: 例如:
scene.add( sphere ); // add it as a child of the scene, not the camera
sphere.onBeforeRender = function( renderer, scene, camera, geometry, material, group ) {
var pos = camera.position;
this.position.set( pos.x, pos.y - 100, pos.z );
};
three.js r.86 three.js r.86
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.