Notifications
Clear all

[Closed] Delete random elements from object

Hi,

I am struggling to delete random elements from an object.
An element need to have material ID 1 assigned before it can be deleted.
All other elements need to stay intact.

It is very slow:

for i=1 to 100 do
(
Face=random 1 $.numfaces
if (getFaceMatID $ Face)==1 then for ElementFace in (meshop.getElementsUsingFace $ Face) do deleteFace $ ElementFace
)

Is there any easier way to radomly delete a number of elements with material ID 1?

Thanks,
Davy

4 Replies
1 Reply
(@denist)
Joined: 1 year ago

Posts: 0

first of all your code is wrong. it can’t work right.
when you delete face (deleteFace $ ElementFace) your are changing topology of the mesh and next face for deletion in your loop might be from absolutely different element. So, you have to collect set of faces first and delete whole set…

  1. Collect all faces with mat ID 1:
    list = #{}
    for f=1 to obj.numfaces where (getFaceMatID obj f) == 1 do join list f

  2. Collect all element which are having any face from the list:

elements = #()
while (f = (list as array)[1]) != undefined do
(
ff = meshop.getElementsUsingFace obj f
append elements ff
list -= ff
)

  1. pick a random element from the element list
    ff = elements[random 1 elements.count]

  2. delete it
    meshop.deletefaces obj ff


unfortunately 3ds max is out my reach now and i can’t double-check my code…

I would probably collect all faces with Material ID, then do the random element selection. That way you know the random face/element will have the specific ID. Another option would be select all faces with Material ID, collect all the element faces into a nested array/bitarray, then pick a random random array element and use that to select the needed faces/elements. Another problem I see with your approach is that elements can have different material IDs, so unless you are sure that all elements have unique ids you could delete something with a different material ID. In that case you would need to collect all faces with Material ID, get an element, compare the element face list with material ID face list, and remove any faces that aren’t in both lists, then delete it.

-Eric

…yes, thats how I do it, making a selection and delete that selection.

All goes fine but when I add the meshop part to define what faces belong to an element, it gets very slow…that’s the bottleneck

Last, isn’t it possible to delete the selected faces from an edit_mesh modifier instead of the baseobject?

Thanks a lot,
Davy

…yes, I already have my code like that, the first example was just a quick note to demonstrate the meshop bottleneck…but I guess nothing to do about that especially if you have many faces in your object

I wish it was that simple to do a minus on an array but I don’t belief that’s possible

Is it possible to delete faces from an edit_mesh modifier instead of base object?

Thanks,
Davy