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

javascript - ThreeJS get element (Mesh) by id - Stack Overflow

programmeradmin0浏览0评论

I have a Mesh object in Three.JS.
How can i get that Mesh object with id, and change its position, like $(#"sample") in jQuery.
Or any better idea to change the position of an objects, in the middle of the code.

var voxel = new THREE.Mesh(new THREE.CubeGeometry(x, y, z), new THREE.MeshBasicMaterial(...))
voxel.id = "sample";
scene.add(voxel);

I have a Mesh object in Three.JS.
How can i get that Mesh object with id, and change its position, like $(#"sample") in jQuery.
Or any better idea to change the position of an objects, in the middle of the code.

var voxel = new THREE.Mesh(new THREE.CubeGeometry(x, y, z), new THREE.MeshBasicMaterial(...))
voxel.id = "sample";
scene.add(voxel);
Share Improve this question asked Jul 27, 2013 at 12:28 MeTe-30MeTe-30 2,5422 gold badges23 silver badges31 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

Just to be safe, don't overwrite the existing Object3D.id.

var objects = {};

mesh1.id2 = "mesh1";
objects[ mesh1.id2 ] = mesh1;

mesh2.id2 = "mesh2";
objects[ mesh2.id2 ] = mesh2;

objects[ "mesh2" ].position.set( 1, 1, 1 );

EDIT: Object3D has a property userData now. So you could use this pattern:

mesh1.userData.id = "mesh1";
objects[ mesh1.userData.id ] = mesh1;

three.js r.73

发布评论

评论列表(0)

  1. 暂无评论