在将网格添加到three.js中的场景之前,如何设置网格的位置 [英] How can I set the position of a mesh before I add it to the scene in three.js

查看:581
本文介绍了在将网格添加到three.js中的场景之前,如何设置网格的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在three.js中,我想在场景中的位置添加网格物体

In three.js, I want to add a mesh to a position in the scene

我尝试过:

// 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()

但它不会影响任何事情。

BUT it didn't affect anything.

我该怎么办?

推荐答案

我建议你查看这里的文件:
http://threejs.org/docs/#Reference/Objects/Mesh
正如您在文档页面顶部所见,Mesh继承自 Object3D 。这意味着您可以使用Object3D提供的所有方法或属性。因此,单击docu-page上的 Object3D 链接并检查属性列表。你会发现属性 .position 。单击 .position 以查看它是什么数据类型。 Paha..its Vector3

i would recommend you to check the documenation over here: http://threejs.org/docs/#Reference/Objects/Mesh As you can see on the top of the docu-page, Mesh inherits from "Object3D". That means that you can use all methods or properties that are provided by Object3D. So click on the "Object3D" link on the docu-page and check the properties list. You will find propertie ".position". Click on ".position" to see what data-type it is. Paha..its Vector3.

因此,请尝试执行以下操作:

So try to do the following:

//scene is a THREE.Scene
scene.add(mesh);
mesh.position.set(100, 100, 100);

这篇关于在将网格添加到three.js中的场景之前,如何设置网格的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆