最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Three.js Child of camera isn't visible - Stack Overflow

programmeradmin4浏览0评论

I'm trying to attach an object to the camera so that it can be used more more or less as a GUI element.

My camera is defined as follows:

camera = new THREE.PerspectiveCamera( 45, windowWidth / windowHeight, 1, 2000 );
camera.position.z = 100;

In my init(), I define the object to be added:

    obj = new THREE.Mesh(new THREE.CubeGeometry(5, 5, 5, 1, 1, 1),
new THREE.MeshBasicMaterial({ color: 0xFFFFFF } ));
    obj.position.set( 0, 0, -50);
    camera.add(obj);

But, the block does not show up. I have tried adding this object to scene, and it is visible. I added a loop to animate() that will slide the object's z position between (-50, 50), but I can't see it.

I tried using camera.lookAt(obj) and logging the world position of obj (obj position + camera position), and they behave as expected. World position seems to be what I'd expect, and camera.lookAt flips the camera when the z position crosses 0.

I apologize for not providing more clear example code, but I will do my best to cooperate with anyone trying to help me. Thanks!

I'm trying to attach an object to the camera so that it can be used more more or less as a GUI element.

My camera is defined as follows:

camera = new THREE.PerspectiveCamera( 45, windowWidth / windowHeight, 1, 2000 );
camera.position.z = 100;

In my init(), I define the object to be added:

    obj = new THREE.Mesh(new THREE.CubeGeometry(5, 5, 5, 1, 1, 1),
new THREE.MeshBasicMaterial({ color: 0xFFFFFF } ));
    obj.position.set( 0, 0, -50);
    camera.add(obj);

But, the block does not show up. I have tried adding this object to scene, and it is visible. I added a loop to animate() that will slide the object's z position between (-50, 50), but I can't see it.

I tried using camera.lookAt(obj) and logging the world position of obj (obj position + camera position), and they behave as expected. World position seems to be what I'd expect, and camera.lookAt flips the camera when the z position crosses 0.

I apologize for not providing more clear example code, but I will do my best to cooperate with anyone trying to help me. Thanks!

Share Improve this question asked Feb 13, 2013 at 22:02 maaachinemaaachine 8211 gold badge7 silver badges12 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 19

Did you add the camera to the scene?

scene.add( camera );

The camera does not usually have to be added to the scene, but in this case, the object is a child of the camera, so you must.

three.js r.58

发布评论

评论列表(0)

  1. 暂无评论