1

I made this function that for each vertices of geometry create a sphere and place it in the same position of vertice.For example if I have a cube,the function place a sphere for each cube vertice.

function makeSphereVertices(){
console.log("makesphere");

spheres = [];

for(var j=0 ; j<geometryContainer.length ; j++) {               
for (var i=0 ; i<geometryContainer[j].geometry.vertices.length ; i++){
var sphereGeometry = new THREE.SphereGeometry(0.04,10,10);//relative to dimension object : ToDo
var sphereMaterial = new THREE.MeshBasicMaterial({transparent: false,color: 0x000000 /*opacity: 0.01*/});
spheres = new THREE.Mesh(sphereGeometry,sphereMaterial);
spheres.position.set(geometryContainer[j].geometry.vertices[i].x,
                  geometryContainer[j].geometry.vertices[i].y,
                  geometryContainer[j].geometry.vertices[i].z);
                  console.log(geometryContainer[j].id);
    spheres.name = "sphere";            
scene.add(spheres);
verticesSphere.push(spheres);

 }
    }


  }

After this,I have created function to move my cube like this Draggable shape. Now the problem is: I can't find a way to move together cube and all spheres. For example if I drag cube all the spheres remains in the old position. Is there a way to chain the spheres to my cube?Thank you.

stefano
  • 123
  • 1
  • 14

1 Answers1

2

By placing them all in a new object.

group = new THREE.Object3D();//create an empty container
group.add( mesh );//add a mesh with geometry to it
scene.add( group );//when done, add the group to the scene

three.js - mesh group example? (THREE.Object3D() advanced)

So make sure you place the cube and all the spheres in your newly created group object.

Community
  • 1
  • 1
hobs
  • 55
  • 2
  • 8
  • I have done and render well, but raycaster.intersectObjects( group); give me no intersection with group. @hobs – stefano Nov 08 '14 at 12:38
  • I think the answer to that problem is the same as I asked for yesterday. What you need to do is pass the recursive flag. raycaster.intersectObjects( group , true); http://stackoverflow.com/questions/26800922/threejs-raycast-click-detection-not-working-on-loaded-3dobject This way it checks for children of "group" too. – hobs Nov 09 '14 at 01:11