use*_*292 27 javascript three.js
在three.js中,我想将一个网格添加到场景中的一个位置
我试过了:
// mesh is a THREE.Mesh
scene is a THREE.Scene
scene.add(mesh)
scene.updateMatrixWorld(true)
mesh.matrixWorld.setPosition(new THREE.Vector3(100, 100, 100))
scene.updateMatrix()
Run Code Online (Sandbox Code Playgroud)
但它没有影响任何事情.
我该怎么办 ?
chs*_*ann 74
我建议你查看这里的文档:http://threejs.org/docs/#Reference/Objects/Mesh 正如你在文档页面顶部看到的,Mesh继承自" Object3D ".这意味着您可以使用Object3D提供的所有方法或属性.因此,单击docu -page 上的" Object3D "链接并检查属性列表.你会发现属性" .position ".单击" .position "以查看它是什么数据类型.Paha .. Vector3.
因此,请尝试执行以下操作:
//scene is a THREE.Scene
scene.add(mesh);
mesh.position.set(100, 100, 100);
Run Code Online (Sandbox Code Playgroud)
bh_*_*th0 28
我之前在github上看过它.(three.js r71)
mesh.position.set(100, 100, 100);
Run Code Online (Sandbox Code Playgroud)
并且可以为个人完成
mesh.position.setX(200);
mesh.position.setZ(200);
Run Code Online (Sandbox Code Playgroud)
参考:https://threejs.org/docs/#api/math/Vector3
详细说明如下:
因为mesh.position是"Vector3".Vector3()有setX()setY()和setZ()方法.我们可以像这样使用它.
mesh.position = new THREE.Vector3() ; //see position is Vector3()
vector1 = new THREE.Vector3();
mesh.position.setX(100); //or this
vector1.setX(100) // because all of them is Vector3()
camera1.position.setZ(100); // or this
light1.position.setY(100) // applicable to any object.position
Run Code Online (Sandbox Code Playgroud)
我更喜欢使用Vector3来设置位置。
let group = new THREE.Group();
// position of box
let vector = new THREE.Vector3(10, 10, 10);
// add wooden Box
let woodenBox = new THREE.Mesh(boxGeometry, woodMaterial);
//update postion
woodenBox.position.copy(vector);
// add to scene
group.add(woodenBox)
this.scene.add(group);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
57891 次 |
| 最近记录: |