ScriptSpot

Forum topic · General Scripting

Align and size a plane on a face

By Kasimashi · 2013-01-22

Description
Comments (8)

Kasimashi · 2013-01-25

Up !

Reply

Kasimashi · 2013-01-22

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 !

Planes over faces

barigazy · 2013-01-22

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

Reply

Kasimashi · 2013-01-23

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

similar method using UP VECTOR

barigazy · 2013-01-22


(
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
)

Reply

Kasimashi · 2013-01-22

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 · 2013-01-22

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
)

barigazy · 2013-01-22

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