From f2decb3873ca402a08b25fa4d3b7cd6b280b53e9 Mon Sep 17 00:00:00 2001 From: Revar Desmera Date: Mon, 30 Mar 2020 14:46:30 -0700 Subject: [PATCH] Bugfix for vec3 spin values. --- attachments.scad | 26 +++++++++++++++++++------- version.scad | 2 +- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/attachments.scad b/attachments.scad index 6f992ad..80235a4 100644 --- a/attachments.scad +++ b/attachments.scad @@ -307,7 +307,6 @@ function attach_geom_size(geom) = // p = If given as a VNF, path, or point, applies the affine3d transformation matrix to it and returns the result. function attach_transform(anchor=CENTER, spin=0, orient=UP, geom, p) = assert(is_string(anchor) || is_vector(anchor)) - assert(is_num(spin) || is_vector(spin,3)) assert(is_vector(orient)) let( two_d = attach_geom_2d(geom), @@ -316,36 +315,49 @@ function attach_transform(anchor=CENTER, spin=0, orient=UP, geom, p) = anch = find_anchor($attach_to, geom), pos = anch[1] ) two_d? ( + assert(two_d && is_num(spin)) let( ang = vector_angle(anch[2], BACK) ) affine3d_zrot(ang+spin) * affine3d_translate(point3d(-pos)) ) : ( + assert(is_num(spin) || is_vector(spin,3)) let( ang = vector_angle(anch[2], DOWN), axis = vector_axis(anch[2], DOWN), ang2 = (anch[2]==UP || anch[2]==DOWN)? 0 : 180-anch[3], axis2 = rot(p=axis,[0,0,ang2]) ) - affine3d_rot_by_axis(axis2,ang) * - affine3d_zrot(ang2+spin) * - affine3d_translate(point3d(-pos)) + affine3d_rot_by_axis(axis2,ang) * ( + is_num(spin)? affine3d_zrot(ang2+spin) : ( + affine3d_zrot(spin.z) * + affine3d_yrot(spin.y) * + affine3d_xrot(spin.x) * + affine3d_zrot(ang2) + ) + ) * affine3d_translate(point3d(-pos)) ) ) : ( let( pos = find_anchor(anchor, geom)[1] ) two_d? ( + assert(two_d && is_num(spin)) affine3d_zrot(spin) * affine3d_translate(point3d(-pos)) ) : ( + assert(is_num(spin) || is_vector(spin,3)) let( axis = vector_axis(UP,orient), ang = vector_angle(UP,orient) ) - affine3d_rot_by_axis(axis,ang) * - affine3d_zrot(spin) * - affine3d_translate(point3d(-pos)) + affine3d_rot_by_axis(axis,ang) * ( + is_num(spin)? affine3d_zrot(spin) : ( + affine3d_zrot(spin.z) * + affine3d_yrot(spin.y) * + affine3d_xrot(spin.x) + ) + ) * affine3d_translate(point3d(-pos)) ) ) ) is_undef(p)? m : diff --git a/version.scad b/version.scad index 3d106de..f5ae8e5 100644 --- a/version.scad +++ b/version.scad @@ -8,7 +8,7 @@ ////////////////////////////////////////////////////////////////////// -BOSL_VERSION = [2,0,242]; +BOSL_VERSION = [2,0,243]; // Section: BOSL Library Version Functions