1

I am creating a Cube with standard new THREE.CubeGeometry. I am also changing the position of the mesh (x,y,z) and I add it to the scene. Later when user clicks on the option, I would like to draw a cube in all 6 corners of the cube. How can I get the position of each vertice in the coordinate system?

gman
  • 100,619
  • 31
  • 269
  • 393
user1736479
  • 235
  • 1
  • 4
  • 17

2 Answers2

0

You can do simply :

var geometry = new THREE.CubeGeometry(...);
var verices = geometry.vertices;
Troopers
  • 5,127
  • 1
  • 37
  • 64
  • Yes I know about that, but the problem is, that vertices doesn't give me the coordinates where are they currently, after I moved the whole Mesh. – user1736479 Jan 24 '14 at 13:18
  • 1
    Are you looking for this? http://stackoverflow.com/questions/11495089/how-to-get-the-absolute-position-of-a-vertex-in-three-js btw. a cube has 8 corners ;) – GuyGood Jan 24 '14 at 13:44
0

if u looking for 8 vertices/corners... http://jsfiddle.net/ebeit303/54uQ9/

function addShapes() {
width = 100;
height = 100
depth = 100;
var geometry = new THREE.CubeGeometry( width, height, depth );
var material = new THREE.MeshBasicMaterial({color:0xffccff, side:2, overdraw:true} );

mesh = new THREE.Mesh( geometry, material );
group.add( mesh );
mesh.position.set(10,20,20);
var x = mesh.position.x;
var y = mesh.position.y;
var z = mesh.position.z;
console.log(geometry.vertices);
var len = geometry.vertices.length;
for(var i = 0; i < len; i++){
    var vx = geometry.vertices[i].x;
    var vy = geometry.vertices[i].y;
    var vz = geometry.vertices[i].z;
        var material1 = new THREE.MeshBasicMaterial({color:Math.random()*0xffffff, side:2, overdraw:true, opacity:0.6, transparent:true} );
    var mesh1 = new THREE.Mesh( geometry, material1 );
    group.add(mesh1);
    mesh1.position.set( (vx*2)+x,(vy*2)+y,(vz*2)+z);
}
}

here the cube consist of 8 vertices/corners, now new cubes were drawn and position on each vertices of the middle cube, its a simple logic... cubegeometry - geometry.vertices and mesh position is used for simple calculation.... just go through the jsfiddle link... it might give you some fair idea...

Iam Coder
  • 993
  • 9
  • 22