Notifications
Clear all

[Closed] Mass deleting intersecting objects

Hi there,

I am working on a bottle where there are lots of water drops on the outer surface. I do create these drops with instancing a “Masterdrop” and painting it onto the bottle with the “Objectpainter”-Script (part of the soulburnscripts). This works fine so far. The only problem is, that there are some intersecting drops which don’t look good when it comes to rendering.

So my question is:

Is there a possibility to check all those drops against on another and then delete those that intersect with an other drop?
( I found this “intersects()”-function and thought this could do the trick. But then there has to be a routine to check all selected objects against one another and then delete those that return true for the intersection test )

Hope you understand what I want to do?!?

Thanks in advance

7 Replies

Try this…


objs = selection as array
 for i = 1 to objs.count where not isDeleted objs[i]  do
 (
	  for j = i+1 to objs.count where not isDeleted objs[j] do
		 (
			 if (intersects objs[i] objs[j]) then
				 delete objs[j]
		 ) 	
 )

THAT is EXACTLY what I was looking for!

A big big “THANK YOU”.
You made my Day :applause:

Hi Akram,

actually that exactly my situation – and im asking myself where are the differences
between this script and the other one you posted in my thread.

It seems that you dont even check the sphere diameter only if there is an intersection
betwen objects right?

Would it be possible to select which objects to delete?
When i got three smaller drops in one big drop and select the three smaller meshes
first and then the bigger one, than your script will delete the bigger drop
and vice versa.

regards

NAIK

@NAIK

The script i wrote for u checked Big with Small. It was specific objects while in this case it checks with each and every object with respect to each other. Since this is a intersect method it check with bounds and i a little inaccurate.

Would it be possible to select which objects to delete?

Yes u can select the object to be delete, just add

 clearselection() --- before the for loop and replace delete with selectmore

ahh okay, i forgot again the bounding box issue.

Thanks for the advise mate…

Keep up the good work!

NAIK

Naik, he did post a similar script in your thread. Again this only tests for intersecting bounding boxes. If you need high precission, it is not suitable.

I posted a similar script in Naiks thread…I edited it for your needs. I hope it works, since I didn’t test it.

Before you run it, you have to give all your drops a Shell Modifier, since the IntersectRay function that I use in the script doesn’t recognise backfaces (at least I don’t know how to do it…).

Also, it is quite probable that you run into memory issues…it is not exactly a friendly script, especially not with the shell modifiers…hence the ‘undo off’…safe before you try it…

undo off
(
	fn Test_Distance Op_A Op_B Dir --Test Function
	(
		Root = Op_A.pos
		Test_Ray = Ray Root Dir --shoot a Ray from the Root to the given Direction

		Dist_A = try(length ((intersectRay Op_A Test_Ray).pos - Root)) catch() --tries to hit itself and gives the lenght
		Dist_B = try(length ((intersectRay OP_B Test_Ray).pos - Root)) catch() --tries to hit the other drop and gives the length

		if Dist_A != undefined and Dist_B!= undefined do --tests if both distances are valid
		(
		if Dist_B < Dist_A do KillMesh = true --sets the Kill Variable True, if the distance to the other drop is smaller than the distance to its own surface
		)
	)

	objs = Selection as array

	for i in 1 to objs.count where not isDeleted i do --loop through the drops
	(
		KillMesh = false --sets the Kill Variable False
		
		for j in i+1 to objs.count where not isDeleted j do --second loop through the drops
		(
			for v in 1 to objs[i].mesh.numverts while KillMesh == false do --loop through the Vertices
			(
				Vert_Pos = getVert objs[i].mesh v --current Vertex' position
				Vert_Dir = normalize (Vert_Pos - objs[i].pos) --direction from the pivot to the vertex
				Test_Distance objs[i] objs[j] Vert_Dir --calls the Test Function and hands over the three operants
			)
			if KillMesh == True do delete objs[j] --deletes the drop if the Kill Variable is true
		)

	)
)

Mate, thanks again for all you effort.
Right now im not in my office.
But tomorrow i will test your script in my scene.

Yep i have recognized that Akrams scripts bottleneck is the bounding box.

Also the memory issue is quite an issue.
Although i got a dual quad with 16gig ram
i have noticed that this task takes very long to complete.

Also when i detach my (10000) drops it takes perhaps 30 min!!!
The detach task will only take one cpu , thats really a pity…

I will test your latest “draft” again tomorrow and get back to you!

best regards

NAIK