Align and size a plane on a face

Hey ! I need help for script writting , I'm bad at scripting and I need a simple script.

This script say :

On click , on the face, place a plane on this face with same dimension.

example on screen :

http://img.funky-emu.net/uploads/2209102.jpg
http://img.funky-emu.net/uploads/2209103.jpg

Thx for you help and sorry for my bad english

Regards

Comments

Comment viewing options

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

Up !

Up !

Kasimashi's picture

Reply

Yeah !!!! It work perfect but I can't select all face and apply on each face , I have to do it one by one face. :)

Thanks you very much for your help !

barigazy's picture

Planes over faces

This is not perfect solution but works for this case

fn planesOverFaces obj = 
(	
	local planeArr = #()
	local ev = polyop.getEdgeVerts
	local gv = polyop.getvert
	local gfe = polyop.getFaceEdges
	local gfsc = polyop.getSafeFaceCenter
	local gfn = polyop.getFaceNormal
	local allFaces = (obj.Faces as bitarray) as array
	for f in allFaces do
	(
		getEdges = gfe obj f
		local sizeArr = #()
		for i in getEdges do
		(
			append sizeArr (distance (gv obj (ev obj i)[2]) (gv obj (ev obj i)[1]))
		)
		l = amin sizeArr ; w = amax sizeArr
		fc = gfsc obj f
		nf = gfn obj f
		xv = normalize (cross nf [0,0,1])
		yv = normalize (cross nf xv)
		thePlane = plane length:l width:w lengthsegs:1 widthsegs:1 name:(uniquename "FacePlane")\
		isSelected:on wirecolor:(random black white) transform:(matrix3 xv yv nf fc)
		append planeArr thePlane
	)
	select planeArr
	--thePlane.transform = prerotateZ (thePlane.transform) -90
)
delete $Plane*
clearlistener()
boxObj = convertToPoly (Box length:40 width:80 height:20)
planesOverFaces boxObj

bga

Kasimashi's picture

Reply

Yeah good joob ! it work perfectly, a last thing =)
For a simple object like a box it's perfectly but for a complex model we need many many many plane exemple for my bridge.

http://img.funky-emu.net/uploads/231840Picture.jpg

In fact When a player get in touch with a plane the plane say : stop can't go here.
A exemple of one of my creation with this plane (3hours for do the plane collider)

http://img.funky-emu.net/uploads/232536Picture2.png

or other exemple of collider workable

http://img.funky-emu.net/uploads/234124PICTURE4.png

Can we make less plane for the same thing?

last thing look this picture : I know the are a rotation problem :

http://img.funky-emu.net/uploads/234124PICTURE4.png

Regards

Thanks you very very very much for you help barigazy

barigazy's picture

similar method using UP VECTOR

(	
	delete $Plane*
	local obj = $Box001
	local sf = (polyop.getFaceSelection obj) as array
	local getEdges = polyop.getFaceEdges obj sf[1]
	local sizeArr = #()
	local ev = polyop.getEdgeVerts
	local gv = polyop.getvert
	for i in getEdges do
	(
		append sizeArr (distance (gv obj (ev obj i)[2]) (gv obj (ev obj i)[1]))
	)
	local  l = amin sizeArr, w = amax sizeArr
	local fc = polyop.getSafeFaceCenter obj sf[1]
	local nf = polyop.getFaceNormal obj sf[1]
	local xv = normalize (cross nf [0,0,1])
	local yv = normalize (cross nf xv)
local thePlane = plane length:l width:w lengthsegs:1 widthsegs:1 \
isSelected:on transform:(matrix3 xv yv nf fc)
	--thePlane.transform = prerotateZ (thePlane.transform) -90
)

bga

Kasimashi's picture

Reply

Thanks barigazy. but I need a plane because it must be a standart primitive, because I use this plane as collider for a game.

barigazy's picture

i start new code but you need

i start new code but you need to adjust a bit by yourselp.
a little homework it does not hurt

;)

(	
	delete $Plane*
	local obj = $Box001
	local sf = (polyop.getFaceSelection obj) as array
	local getEdges = polyop.getFaceEdges obj sf[1]
	local sizeArr = #()
	local ev = polyop.getEdgeVerts
	local gv = polyop.getvert
	for i in getEdges do
	(
		append sizeArr (distance (gv obj (ev obj i)[2]) (gv obj (ev obj i)[1]))
	)
	local  w = amin sizeArr, l = amax sizeArr
	local fc = polyop.getSafeFaceCenter obj sf[1]
	local nf = polyop.getFaceNormal obj sf[1]
	local thePlane = plane pos:fc dir:nf length:l width:w lengthsegs:1 widthsegs:1 isSelected:on
	thePlane.transform = prerotateZ (thePlane.transform) -90
)

bga

barigazy's picture

Why you need a plain.Why

Why you need a plain.Why don't you just detach selected face as clone

	fn extractPolys obj del: = 
	(
		local sf = (obj.selectedfaces as bitarray) as array
		if sf.count != 0 do
		(
			if getCommandPanelTaskMode() != #create do setCommandPanelTaskMode mode:#create
			with redraw off
			(
				local cloArr = #()
				for p = sf.count to 1 by -1 do 
				(
					polyOp.detachFaces obj #{sf[p]} delete:del asNode:on name:"poly001"
					clo = objects[objects.count]
					clo.wirecolor = yellow
					clo.pivot = clo.center
					append cloArr clo
				)
				select cloArr ; free sf ; free cloArr
			)
		)
	)
extractPolys selection[1] del:true --detach face and deleteoriginal face
--unmark next line if you want to preserve original face
--extractPolys selection[1] del:true

bga

Comment viewing options

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