【问题标题】:Three.js: attach object to camera but not make it rotate with itThree.js:将对象附加到相机但不使其随之旋转
【发布时间】:2017-06-26 10:30:53
【问题描述】:

我目前有一个 SphereGeometry 附加到透视相机。但是当我旋转相机时,球体会随着相机旋转,这是正常的,但在我的情况下我不希望这样。

这是我所拥有的:

camera.add(Sphere);
Sphere.position.set (0, -100, 0);

我想要的是将球体连接到相机的底部,但保持在那个位置。目前,当我旋转相机时,球体似乎随之旋转,所以我看不到它。如何以不随相机旋转的方式附加子对象?谢谢。

【问题讨论】:

    标签: javascript three.js


    【解决方案1】:

    一种方法是为您的球体网格定义一个onBeforeRender() 方法。例如:

    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

    【讨论】:

      猜你喜欢
      • 2015-12-01
      • 2014-05-19
      • 2013-08-30
      • 2023-04-05
      • 1970-01-01
      • 2016-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多