Hey everyone, is it Possible to rotate the Pivot Z-axis to the Largest Face of an object, like in the example in the picture?
It should find the largest face by his own, no manual selection.
Thx
Forum topic · General Scripting
By Dragan_ilic · 2019-11-28
Hey everyone, is it Possible to rotate the Pivot Z-axis to the Largest Face of an object, like in the example in the picture?
It should find the largest face by his own, no manual selection.
Thx
.
miauu · 2019-12-02
Try this:
(
local poGetNumFaces = polyop.getNumFaces
local poGetFaceArea = polyop.getFaceArea
local poGetFaceCenter = polyop.getFaceCenter
local poGetFaceNormal = polyop.getFaceNormal
function AlignPivotToFace obj face =
(
c = poGetFaceCenter obj face
n = poGetFaceNormal obj face
ftm = translate (matrixfromnormal n) c
itm = ftm*(inverse obj.transform)
obj.transform = ftm
obj.objectOffsetPos *= inverse itm
obj.objectOffsetRot *= inverse itm.rotation
obj.transform
)
selObjsArr = selection as array
if selObjsArr.count != 0 do
(
for o in selObjsArr where classOf o == Editable_Poly do
(
numFaces = poGetNumFaces o
maxArea = -1
largestFaceIdx = 0
for f = 1 to numFaces do
(
fArea = poGetFaceArea o f
if fArea > maxArea do
(
largestFaceIdx = f
maxArea = fArea
)
)
if largestFaceIdx != 0 do
(
AlignPivotToFace o largestFaceIdx
)
)
)
)
Works only with Editable Poly object and if you have two more more faces with the same area the script will align the pivot to last larger face it finds.