@kenc wrote:
@denisT.MaxDoctor max file attached as 2019. Deleted all but doors and cabinets. The pivots are pointing in the direction after I ran your last code.
My vector code doesn't work
As I can see from the example scene, there is no simple rule for automatically finding the correct panel pivot direction.
The best I can suggest is to use a "preselected" face for each panel, specifying the pivot direction. If you specify a front face, the rotation will face forward, if you specify a back face, the rotation will face backward (as you want).
If the face selection method is used, the specified face no longer has to be "maximum size", which also solves the previous limitation.
fn setPivotRotation obj tm =
(
worldAlignPivot obj
local rot = inverse tm.rotationpart
animate off in coordsys local obj.rotation *= rot
obj.objectoffsetrot *= rot
obj.objectoffsetpos *= rot
obj.objecttransform
)
mapped fn alignPivotToFace obj face:#max zUp:on = if iskindof obj Editable_Mesh do
(
fn getMaxFace obj =
(
fmax = meshop.getfacearea obj 1
i = 1
for k = 2 to obj.numfaces where (area = meshop.getfacearea obj k) > fmax do
(
fmax = area
i = k
)
i
)
fn matrixZUp tm =
(
side = normalize (cross z_axis tm[3])
front = cross z_axis side
matrix3 side front z_axis tm.pos
)
if face == #max then face = getMaxFace obj
else if face == #sel then
(
face = ((obj.selectedfaces as bitarray) as array)[1]
)
else face = int face
if face != undefined and face > 0 and face < obj.numfaces do
(
norm = getfacenormal obj face
tm = matrixfromnormal norm
if zUp do
(
tm = matrixZUp tm
)
centerPivot obj
setPivotRotation obj tm
)
)
alignPivotToFace selection face:#sel