I've developed a function that generates spheres for each vertex of a geometry and positions them accordingly. For instance, if there's a cube, the function will create a sphere for each vertex of the cube.
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);
}
}
}
Following this, I have also implemented a function to enable dragging of my cube similar to the example shown here. However, I am facing an issue where moving the cube does not move the associated spheres with it. Is there a way to link the spheres to the cube so they move together? Any assistance on this matter would be greatly appreciated. Thank you.