I need to change the position of some cylinders in the scene by removing them and adding new ones.
Here is a snippet of code to show how I currently place the cylinders:
for (i = 0; i < cylinderCount; i++) {
var geometry = new THREE.CylinderGeometry( (cylinderDiameter * scale), (cylinderDiameter * scale) , cylinderLength * scale , 20 );
var material = new THREE.MeshBasicMaterial( {color: 0xffe26f} );
var cylinder = new THREE.Mesh( geometry, material );
scene.add( cylinder );
cylinder.position.set( 0 , 0 ,bottomEdgeGrid);
bottomEdgeGrid -= (cylinderSpacing * scale);
cylinder.rotation.z = Math.PI / 2;
}
To remove the cylinders, I utilize this function:
function ClearMesh(){
scene.remove(scene.getObjectByName(cylinder));
scene.remove(scene.getObjectByName(secondCylinder));
}
This button triggers the removal of the cylinders:
<button onclick="ClearMesh();">Clear mesh</button>