attach_transform cleanup

This commit is contained in:
Adrian Mariano 2024-11-28 13:17:37 -05:00
parent b56ab4755e
commit cbe55c8514

View file

@ -3729,7 +3729,7 @@ function _attach_transform(anchor, spin, orient, geom, p) =
spin=default(spin,0), spin=default(spin,0),
orient=default(orient,UP), orient=default(orient,UP),
two_d = _attach_geom_2d(geom), two_d = _attach_geom_2d(geom),
m = ($attach_to != undef) ? // $attach_to is the attachment point on this object m = is_def($attach_to) ? // $attach_to is the attachment point on this object
( // which will attach to the parent ( // which will attach to the parent
let( let(
anch = _find_anchor($attach_to, geom), anch = _find_anchor($attach_to, geom),
@ -3739,7 +3739,6 @@ function _attach_transform(anchor, spin, orient, geom, p) =
: _find_anchor(_make_anchor_legal($anchor_override,geom),geom)[1] : _find_anchor(_make_anchor_legal($anchor_override,geom),geom)[1]
) )
two_d? two_d?
assert(is_num(spin))
affine3d_zrot(spin) affine3d_zrot(spin)
* rot(to=FWD, from=point3d(anch[2])) * rot(to=FWD, from=point3d(anch[2]))
* affine3d_translate(point3d(-pos)) * affine3d_translate(point3d(-pos))
@ -3756,17 +3755,14 @@ function _attach_transform(anchor, spin, orient, geom, p) =
: _make_anchor_legal(rot(spin, from=UP,to=orient,reverse=true,p=$attach_alignment),geom), : _make_anchor_legal(rot(spin, from=UP,to=orient,reverse=true,p=$attach_alignment),geom),
pos = _find_anchor(anchor, geom)[1] pos = _find_anchor(anchor, geom)[1]
) )
two_d? two_d? affine3d_zrot(spin) * affine3d_translate(point3d(-pos))
assert(is_num(spin))
affine3d_zrot(spin) * affine3d_translate(point3d(-pos))
: :
let( let(
axis = vector_axis(UP,orient), // Returns BACK if orient is UP axis = vector_axis(UP,orient), // Returns BACK if orient is UP
ang = vector_angle(UP,orient) ang = vector_angle(UP,orient)
) )
affine3d_rot_by_axis(axis,ang) affine3d_rot_by_axis(axis,ang)
* ( is_num(spin)? affine3d_zrot(spin) * affine3d_zrot(spin)
: affine3d_zrot(spin.z) * affine3d_yrot(spin.y) * affine3d_xrot(spin.x))
* affine3d_translate(point3d(-pos)) * affine3d_translate(point3d(-pos))
) )
is_undef(p)? m is_undef(p)? m