[Closed] Align object to face normal problem
Hi, i try to align object by it face normal, but seems aligns not perfect.
$.pivot = $.center
f = polyop.getFaceSelection $ as Array
fNor = polyop.getFaceNormal $ f[1]
fCen = polyop.getFaceCenter $ f[1]
m = MatrixFromNormal fNor
m.row4 = fCen
$.transform = $.transform * (Inverse m)
– same with helper
/*
p = point()
p.transform = m
$.parent = p
p.rotation.x_rotation
p.rotation.x_rotation =0
p.rotation.y_rotation
p.rotation.y_rotation =0
delete p
*/
if scale the face after aligning by z few times, distortion between face vertices more visible , so aligns not perfect to XY plane.
Any tip?
http://creativescratchpad.blogspot.com/2017/05/undocumented-maxscript-features.html
you can try inverseHighPrecision <matrix>, if you’re really sure that polygon is 100% flat in the first place.
thanks, result preaty the same.
I think thats max ‘s problem, because after reseting Xform, object has no 0 rotation at axis, values like 2.7e-6 deg. for rotation – calculation error(0,001%)
First, a poly face can be not exactly planar (polyop.getFaceNormal)
Second, you can get a degeneracy when base axis of matrix parallel to face normal (matrixFromNormal).
Try calculating the true matrix for the triangle first to check if your math is correct.
delete objects
t = converttomesh (geosphere radius:10 segs:1 name:#target smooth:off wirecolor:green isselected:on)
pp = for f=1 to t.numfaces collect
(
p = point name:#point size:4 axistripod:on cross:on wirecolor:orange
s = p.controller = transform_script()
s.addnode #target t
s.addconstant #faceID f
ss = @"
vv = getface target faceID
a = getpointpos target vv[1]
b = getpointpos target vv[2]
c = getpointpos target vv[3]
front = normalize (b - a)
up = normalize (cross front (c - a))
side = cross up front
pos = (a + b + c)/3
matrix3 front side up pos
"
s.setexpression ss
p
)