Align Object to Face + Get Face Dimensions

Hey,

I want to select a face in an editable poly and then have my script create a new Plane at the upper left vertex position of that face, and have the Plane be aligned to the face orientation. Like so:

So far I only managed to create a non-aligned Plane in the center of that face...

>>> How do I know which vert is in the upper left corner?

>>> How do I align an object to a face normal?

>>> Is there any way to get the width and length of a face ( "distance" comes to my mind, but again I do not know which verts to choose)

I want to create windows for buildings this way, any help really appreciated!

Cheers

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Swordslayer's picture

If it will be a box and a

If it will be a box and a plane, it's not that hard – this could get you started:

try destroyDialog placePlane catch()
rollout placePlane "Place a plane"
(
	local pickedBox, pickedPlane
 
	fn boxFilter obj = isKindOf obj Editable_Poly
 
	pickButton pbBox "Pick a Box" filter:boxFilter
	pickButton pbPlane "Pick a Plane"
	button btnAlign "ALIGN" height:25
 
	on pbBox picked obj do
		if obj != undefined do
			pbBox.text = (pickedBox = obj).name
 
	on pbPlane picked obj do
		if obj != undefined do
			pbPlane.text = (pickedPlane = obj).name
 
	on btnAlign pressed do undo "Align Plane" on
	(
		if isValidNode pickedBox AND
			(local faceSelected = polyOp.getFaceSelection pickedBox).numberSet == 1 AND
			isValidNode pickedPlane then
		(
			local faceNormal = polyOp.getFaceNormal pickedBox faceSelected.count
			local faceCenter = polyOp.getFaceCenter pickedBox faceSelected.count
			local faceMatrix = matrix3 (cross faceNormal [0,0,1]) [0,0,1] faceNormal faceCenter
 
			local faceVerts = polyOp.getVertsUsingFace pickedBox faceSelected
				faceVerts = for v in faceVerts collect (polyOp.getVert pickedBox v) * inverse faceMatrix
 
			local upperLeftVert = for v in faceVerts where v.x > 0 AND v.y > 0 do exit with v 
			local planeDims = (pickedPlane.max - pickedPlane.min)/2
 
			pickedPlane.transform *= faceMatrix
			pickedPlane.pos = [(upperLeftVert.x - planeDims.x),(upperLeftVert.y - planeDims.y),0] * faceMatrix
		)
		else messageBox "Pick something first"
	)
)
createDialog placePlane

As for the lenght/width part, in this case you can measure the distance between verts in different quadrants (viz upperLeftVert).

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.