I am trying to develop an educational activity for my students wherein a group of objects needs to be replicated and positioned randomly in a scene. I have created a function for this purpose, but unfortunately, it only duplicates the same object instead of adding new ones. I have been attempting to clone additional objects without success. Additionally, I will need to delete these models individually at a later stage. If anyone could offer guidance on how to address these issues, I would greatly appreciate it.
Below is the code snippet:
this.addmodel = function() {
scene.add(model);
model.name = "model-" + scene.children.length;
model.position.x= -20 + Math.round((Math.random() * 40));
model.position.y= Math.round((Math.random() * 5));
model.position.z= -17.5 + Math.round((Math.random() * 35));
this.numOfObjects = scene.children.length;
}