admin管理员组

文章数量:1023782

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

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

本文标签: javascriptThreeJS get element (Mesh) by idStack Overflow