PDA

View Full Version : Delete random elements from object


Davy
10-07-2009, 04:28 PM
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

PiXeL_MoNKeY
10-07-2009, 04:57 PM
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

Davy
10-07-2009, 06:59 PM
...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

denisT
10-07-2009, 07:37 PM
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


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
)

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

4. delete it
meshop.deletefaces obj ff

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

Davy
10-08-2009, 11:46 AM
...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

CGTalk Moderation
10-08-2009, 11:46 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.