[Closed] Orient shape to helper
I’m trying to orient a shape to a helper, but having trouble getting the normal to the box helper. This would be easy if it was a poly, but as it is a helper, is there an easy way to get the normal vector to the box helper so I can have the shape aligned to it? Thnx in advance guys.
Thank you but it Doesn’t really help. Once I do shape.transform =helper.transform, and shape.dir = helper.dir,
it just orients to the pivot in a default manner every time…I want to be able to orient the dummy box the way I want and then have the shape align itself correspondingly …
So, do you want to create something like pathConstraint? If yes, check this
fn splineAlign mySpline splineIndex segmentIndex percent = (
pos = interpBezier3D mySpline splineIndex segmentIndex percent
dir = tangentBezier3D mySpline splineIndex segmentIndex percent
myMatrix = matrixFromNormal dir
myMatrix.pos = pos
myMatrix
)
$Point001.transform = splineAlign $Line001 1 1 .5
yeah, ” orient a shape to a helper” may not be communicating what you mean clearly.
do you mean just matching the rotation?
you can do that without messing with normals or transforms directly.
obj=$mesh_object
target= $Dummy001
obj.rotation=target.rotation
if you need to animate, then an orient constraint is probably what you want.
Or do you mean something more like a lookAt constraint?
See image below
Thank your for your replies…what I need is pretty simple – The helper on the left is oriented in a certain way, but there is no real geometry there, which I suppose is the problem, but I want the n- gon object on the right to snap to the side of the helper ‘cube’ with it’s normal aligned to the cube face normal, as I have done manually on the right. Thnx again
So, something like this?
fn alignToObj fromObj toObj axis offset:10 = (
case axis of (
"x": (
fromObj.pos = toObj.pos
fromObj.dir = toObj.transform.row1
in coordSys toObj move fromObj [offset, 0, 0]
)
"-x": (
fromObj.pos = toObj.pos
fromObj.dir = -toObj.transform.row1
in coordSys toObj move fromObj [-offset, 0, 0]
)
"y": (
fromObj.pos = toObj.pos
fromObj.dir = toObj.transform.row2
in coordSys toObj move fromObj [0, offset, 0]
)
"-y": (
fromObj.pos = toObj.pos
fromObj.dir = -toObj.transform.row2
in coordSys toObj move fromObj [0, -offset, 0]
)
"-z": (
fromObj.pos = toObj.pos
fromObj.dir = -toObj.transform.row3
in coordSys toObj move fromObj [0, 0, -offset]
)
default: (
fromObj.pos = toObj.pos
fromObj.dir = toObj.transform.row3
in coordSys toObj move fromObj [0, 0, offset]
)
)
)
alignToObj $Circle001 $Point001 "x" offset:10
Cool,
btw, if you want a more compact version with a bit more math, you can use this one too.
fn alignToObj fromObj toObj axis offset:10 = (
dir = if axis == "x" then toObj.transform.row1
else if axis == "-x" then -toObj.transform.row1
else if axis == "y" then toObj.transform.row2
else if axis == "-y" then -toObj.transform.row2
else if axis == "-z" then -toObj.transform.row3
else toObj.transform.row3
fromObj.pos = toObj.pos + dir*offset
fromObj.dir = dir
)
alignToObj $Circle001 $Point001 "-x" offset:10
this one fixes the “random” rotation on the other axis
fn alignToObj fromObj toObj axis offset:0 = (
--Store toObj transforms
toTm = toObj.transform
--Compute tm
tm = if axis == "x" then matrix3 toTm.row3 toTm.row2 toTm.row1 (toTm.row4+toTm.row1*offset)
else if axis == "-x" then matrix3 toTm.row3 toTm.row2 -toTm.row1 (toTm.row4-toTm.row1*offset)
else if axis == "y" then matrix3 toTm.row1 toTm.row3 toTm.row2 (toTm.row4+toTm.row2*offset)
else if axis == "-y" then matrix3 toTm.row1 toTm.row3 -toTm.row2 (toTm.row4-toTm.row2*offset)
else if axis == "-z" then matrix3 toTm.row1 toTm.row2 -toTm.row3 (toTm.row4-toTm.row3*offset)
else if axis == "z" then matrix3 toTm.row1 toTm.row2 toTm.row3 (toTm.row4+toTm.row3*offset)
--Apply tm
fromObj.transform = tm
)
alignToObj $Circle001 $Point001 "y" offset:10