Dynamic list of meshes that is being added to the scene

hey guys,
what I want to achieve is to create an empty list of object and add it to the group, and then add the meshes that are being dynamically generated to this list.
after a set of meshes are added to this list, I want to do some geometric operations on these set of meshes.

Issue I am facing is , whenever any manipulation is done, It creates a new updated mesh, and adds it to the group, so there is a set of old meshes, that were generated initially, and its adding new updated mesh on top of it.

To help you we need to know more:

  • What are the manipulations you are doing on the meshes?
  • How are you performing them?

Without knowing that, I would suggest:

var objectsList = [];
var group = new THREE.Group();
scene.add( group );

function onCreateMesh( oldMesh ) {

    var newMesh;
    var i = objectsList.indexOf( oldMesh );
    if ( i >= 0 ) {
        newMesh = manipulateMesh( params, oldMesh );
        group.remove( mesh );
        objectsList.splice( i, 1 );
    }
    else {
        newMesh = generateMesh( params );
    }
    group.add( newMesh );
    objectsList.push( newMesh );

}
2 Likes

I am just calculating intersecting area between two polygons and creating a new mesh according to it. Whenever any of the two polygon moves/ resized, new intersection is calculated and new mesh is generated. Intersection between two polygons may result in more than one intersecting region thats why I need an array of meshes.
Is it possible to add an array having data type of mesh, and then I can add or remove from that array later on?

Yes, that is what the code snippet I made is for. You maintain the array, and add or remove objects from the group or the scene.

Edit: or do you mean editing the mesh? If so, please read this

I found a better way . to use shape geometry to have multiple shapes in a single mesh. This worked for me pretty well. Thanks for your help mate!
Cheers!