Detach faces based on normals

Detach faces based on normals

Anonymous
Not applicable
1,184 Views
1 Reply
Message 1 of 2

Detach faces based on normals

Anonymous
Not applicable

Hi all,

 

To improve my workflow I'm looking for a script (or quick workflow) to detach all faces of an object to separate objects based on the normal direction, if possible with a threshold.

I have looked through a lot of detach scripts, but I haven't been able to find what I've been looking for.

 

Does anyone know if such a script exists?

 

Ive included an image for clarity; but the objects wouldn't need to be exploded though

0 Likes
1,185 Views
1 Reply
Reply (1)
Message 2 of 2

leeminardi
Mentor
Mentor

The following script will detach the polygons of a selected Editable Poly given a vector direction.

A dot product value of greater than 0.95 is used to determine if the poly normals are within the tolerance of the test vector.  Modify this value if you find the tolerance too loose or tight.  I've included some output statements to help with the debugging.

(
-- detaches poly with normal vector close to vector specified
-- LRM 12/15/2018	
on isEnabled return 
selection.count == 1 and classof selection[1].baseobject == Editable_Poly
x = getKBValue prompt:"\nEnter normal vector x component: " as float	
y = getKBValue prompt:"\nEnter normal vector y component: "	 as float	
z = getKBValue prompt:"\nEnter normal vector z component: "	 as float	
on execute do
	(
	 n = 0 as integer
		obj = selection[1]
	for p = polyop.getNumFaces obj to 1 by -1 do
		(
		local testVector = [x,y,z]
		local poGFN = polyop.getFaceNormal; poGFC = polyop.getFaceCenter
		faceNormal  = (poGFN obj p)
			(if 
			( (dot (normalize faceNormal) (normalize testVector)) >= 0.95 ) then 
				(n = n + 1
				--	obj.material = meditMaterials[1] -- used in debugging
				format "\nFace normal: % Test Vector: %" faceNormal (normalize testVector)
				polyOp.detachFaces obj #{p} asNode:true
									)
			)
		) -- end for
	format "\n% poly objects detached.\n" n
	) -- end do
)
lee.minardi
0 Likes