mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-01 09:49:45 +00:00
commit
1060559aa6
3 changed files with 45 additions and 24 deletions
|
@ -22,10 +22,19 @@
|
|||
// .
|
||||
// Two gotchas may lead to models that don't behave as expected. While `if` statements work to control modules, you cannot
|
||||
// use them to make variable assignments in your child object. If you write a statement like
|
||||
// `if (condition) { c="red";}` then the `c` variable is set only in the scope of the `if` statement and is not available later on.
|
||||
// Instead you must use the ternary operator. The second complication is
|
||||
// that in OpenSCAD version 2021.01 and earlier, assignments in children were executed before their
|
||||
// parent. This means that `$` variables like `$idx` are not available in assignments, so if you use them you will get a warning about an unknown variable.
|
||||
// ```
|
||||
// if (condition) { c="red";}
|
||||
// else {c="green";}
|
||||
// ```
|
||||
// then the `c` variable is set only in the scope of the `if` and `else` clauses and is not available later on when you actually
|
||||
// try to use it. Instead you must use the ternary operator and write:
|
||||
// ```
|
||||
/// c = condition ? "red" : "green";
|
||||
// ```
|
||||
// The second complication is
|
||||
// that in OpenSCAD version 2021.01 and earlier, assignments in children were executed before their parent. This means
|
||||
// that `$` variables like `$idx` are not available in assignments because the parent hasn't run to set them, so if you use them
|
||||
// you will get a warning about an unknown variable.
|
||||
// Two workarounds exist, neither of which are needed in newer versions of OpenSCAD. The workarounds solve the problem because
|
||||
// **modules** execute after their parent, so the `$` variables **are** available in modules. You can put your assignments
|
||||
// in a `let()` module, or you can wrap your child in a `union()`. Both methods appear below.
|
||||
|
@ -63,9 +72,9 @@
|
|||
// xcopies(n=5,spacing=10)
|
||||
// union()
|
||||
// {
|
||||
// shiftback = $idx%2==0 ? back(5) : IDENT;
|
||||
// shiftback = $idx%2==0 ? back(10) : IDENT;
|
||||
// spin = zrot(180*$idx/4);
|
||||
// multmatrix(shiftback*spin) stroke([[-4,0],[4,0]],endcap2="arrow2",width=1/2);
|
||||
// multmatrix(shiftback*spin) stroke([[-4,0],[4,0]],endcap2="arrow2",width=3/4, color="red");
|
||||
// }
|
||||
// Continues:
|
||||
// ```
|
||||
|
|
|
@ -23,7 +23,7 @@ include <screws.scad>
|
|||
// The offset is the distance from a vertical mounting point to the center of the hinge pin. The hinge barrel is held by an angled support and
|
||||
// vertical support. The length of the angled support is determined by its angle and the offset. You specify the length of the vertical support with the
|
||||
// arm_height parameter.
|
||||
// Figure(2D,NoScales): The basic hinge form appears on the left. If fill is set to true the gap between the mount surface and hinge arm is filled as shown on the right.
|
||||
// Figure(2D,Med,NoScales): The basic hinge form appears on the left. If fill is set to true the gap between the mount surface and hinge arm is filled as shown on the right.
|
||||
// _hinge_profile(4, 5, $fn=32, fill=false);
|
||||
// right(13)_hinge_profile(4, 5, $fn=32, fill=true);
|
||||
// fwd(9)stroke([[0,0],[4,4],[4,9]], width=.3,color="black");
|
||||
|
@ -36,13 +36,13 @@ include <screws.scad>
|
|||
// Continues:
|
||||
// As shown in the above figure, the fill option fills the gap between the hinge arm and the mount surface to make a stronger connection. When the
|
||||
// arm height is set to zero, only a single segment connects the hinge barrel to the mount surface.
|
||||
// Figure(2D,NoScales): Zero arm height with 45 deg arm
|
||||
// Figure(2D,Med,NoScales): Zero arm height with 45 deg arm
|
||||
// right(10) _hinge_profile(4, 0, $fn=32);
|
||||
// _hinge_profile(4, 0, $fn=32,fill=false);
|
||||
// right(11)fwd(-3)color("blue")text("fill=true",size=1);
|
||||
// right(.5)fwd(-3)color("blue")text("fill=false",size=1);
|
||||
// Continues:
|
||||
// Figure(2D,NoScales): Zero arm height with 90 deg arm. The clear_top parameter removes the hinge support material that is above the x axis
|
||||
// Figure(2D,Med,NoScales): Zero arm height with 90 deg arm. The clear_top parameter removes the hinge support material that is above the x axis
|
||||
// _hinge_profile(4, 0, 90, $fn=32);
|
||||
// right(10) _hinge_profile(4, 0, 90, $fn=32,clear_top=true);
|
||||
// right(9.5)fwd(-3)color("blue")text("clear_top=true",size=.76);
|
||||
|
|
42
skin.scad
42
skin.scad
|
@ -2666,22 +2666,22 @@ function associate_vertices(polygons, split, curpoly=0) =
|
|||
// direction will be the vertical and tangential directions on the cylindrical surface. All horizontal dimensions for VNF textures are relative to the unit square
|
||||
// on which the textures are defined, so a value of 0.25 for a gap or inset will refer to 1/4 of the texture's full length and width.
|
||||
// Texture Values:
|
||||
// "bricks" = Heightfield = A brick-wall pattern. Giving `n=` sets the number of heightfield samples to `n x n`. Default: 24. Giving `roughness=` adds a level of height randomization to add roughness to the texture. Use `style="convex"`.
|
||||
// "bricks_vnf" = VNF Tile = VNF version of "bricks". Giving `gap=` sets the mortar gap between bricks at the bottom, default 0.05. Giving `inset=` specifies that the top face of the brick is smaller than the bottom of the brick by `inset` on each of the four sides. If `gap` is zero then `inset` close to 0.5 will cause bricks to come to a sharp pointed edge, with just a tiny flat top surface. Note that `gap+inset` must be strictly smaller than 0.5. Default is `inset=0.05`.
|
||||
// "bricks" = Heightfield = A brick-wall pattern. Giving `n=` sets the number of heightfield samples to `n x n`. Default: 24. Giving `roughness=` adds a level of height randomization to add roughness to the texture. Default: 0.05. Use `style="convex"`.
|
||||
// "bricks_vnf" = VNF Tile = VNF version of "bricks". Giving `gap=` sets the "mortar" gap between adjacent bricks, default 0.05. Giving `inset=` specifies that the top face of the brick is smaller than the bottom of the brick by `inset` on each of the four sides. If `gap` is zero then an `inset` value close to 0.5 will cause bricks to come to a sharp pointed edge, with just a tiny flat top surface. Note that `gap+inset` must be strictly smaller than 0.5. Default is `inset=0.05`.
|
||||
// "checkers" = VNF Tile = A pattern of alternating checkerboard squares. Giving `inset=` specifies that the top face of the checker surface is smaller than the bottom by `inset` on each of the four sides. As `inset` approaches 0.5 the tops come to sharp corners. You must set `inset` strictly between 0 and 0.5. Default: 0.05.
|
||||
// "cones" = VNF Tile = Raised conical spikes. Giving `n=` sets `$fn` for the cone (will be rounded to a multiple of 4). Default: 16. Giving `inset=` specifies the horizontal inset of the base of the cone, relative to the tile edges. The `inset` value must be nonnegative and smaller than 0.5. Default: 0.
|
||||
// "cubes" = VNF Tile = Cornercubes texture.
|
||||
// "diamonds" = Heightfield = Four-sided pyramid with the corners of the base aligned aligned with the axes. Compare to "pyramids". Useful for knurling. Giving `n=` sets the number of heightfield samples to `n x n`. Default: 2. Use `style="concave"` for pointed bumps, or `style="default"` or `style="alt"` for a diagonal ribs.
|
||||
// "diamonds_vnf" = VNF Tile = VNF version of "diamonds".
|
||||
// "dimples" = VNF Tile = Round divots. Giving `n=` sets `$fn` for the curve (will be rounded to a multiple of 4). Default: 16. Giving `inset=` specifies the horizontal distance of the flat region around the dimple relative to the edge of the tile. Default: 0.05.
|
||||
// "dimples" = VNF Tile = Round divots. Giving `n=` sets `$fn` for the curve (will be rounded to a multiple of 4). Default: 16. Giving `inset=` specifies the horizontal distance of the flat region around the dimple relative to the edge of the tile. Must be nonnegative and strictly less than 0.5. Default: 0.05.
|
||||
// "dots" = VNF Tile = Raised round bumps. Giving `n=` sets `$fn` for the curve (will be rounded to a multiple of 4). Default: 16. Giving `inset=` specifies the horizontal inset of the dots, relative to the edge of the tile. Must be nonnegative and strictly less than 0.5. Default: 0.05.
|
||||
// "hex_grid" = VNF Tile = A hexagonal grid defined by V-grove borders. Giving `inset=` specifies the X-direction horizontal inset of the hexagonal tops, relative to their bottoms. This means the V-groove top width for grooves running parallel to the Y axis will be double the inset value. If the texture is scaled in the Y direction by sqrt(3) then the groove will be uniform on all six sides of the hexagon. Inset must be strictly between 0 and 0.5, default: 0.1.
|
||||
// "hex_grid" = VNF Tile = A hexagonal grid defined by V-grove borders. Giving `inset=` specifies the horizontal inset of the left and right edges of the hexagonal tops, relative to their bottoms. This means the V-groove top width for grooves running parallel to the Y axis will be double the inset value. If the texture is scaled in the Y direction by sqrt(3) then the groove will be uniform on all six sides of the hexagon. Inset must be strictly between 0 and 0.5, default: 0.1.
|
||||
// "hills" = Heightfield = Wavy sine-wave hills and valleys, Giving `n=` sets the number of heightfield samples to `n` x `n`. Default: 12. Set `style="quincunx"`.
|
||||
// "pyramids" = Heightfield = Four-sided pyramid with the edges of the base aligned with the axess. Compare to "diamonds". Useful for knurling. Giving `n=` sets the number of heightfield samples to `n` by `n`. Default: 2. Set style to "convex". Note that style="concave" or style="min_edge" produce mini-diamonds with flat squares in between.
|
||||
// "pyramids_vnf" = VNF Tile = VNF version of "pyramids".
|
||||
// "ribs" = Heightfield = Vertically aligned triangular ribs. Giving `n=` sets the number of heightfield samples to `n` by 1. Default: 2. The choice of style does not matter.
|
||||
// "rough" = Heightfield = A pseudo-randomized rough texture. Giving `n=` sets the number of heightfield samples to `n` by `n`. Default: 32. The `roughness=` parameter specifies the height of the random texture. Default: 0.2.
|
||||
// "tri_grid" = VNF Tile = A triangular grid defined by V-groove borders Giving `inset=` specifies the horizontal inset of the triangular tops, relative to their bottoms, along the horizontal edges of the triangles. This means the V-groove top width of the horizontal grooves will be double the inset value. If the tile is scaled in the Y direction by sqrt(3) then the groove will be uniform on the three sides of the triangle. The inset must be strictly between 0 and 1/6, default: 0.05.
|
||||
// "tri_grid" = VNF Tile = A triangular grid defined by V-groove borders Giving `inset=` specifies the horizontal inset of the triangular tops, relative to their bottoms, along the horizontal edges (parallel to the X axis) of the triangles. This means the V-groove top width of the grooves parallel to the X axis will be double the inset value. If the tile is scaled in the Y direction by sqrt(3) then the groove will be uniform on the three sides of the triangle. The inset must be strictly between 0 and 1/6, default: 0.05.
|
||||
// "trunc_diamonds" = VNF Tile = Truncated diamonds, four-sided pyramids with the base corners aligned with the axes and the top cut off. Or you can interpret it as V-groove lines at 45º angles. Giving `inset=` specifies the horizontal inset of the square top face compared to the bottom face along all four edges. This means the V-groove top width will be double the inset value. The inset must be strictly between 0 and sqrt(2)/4, which is about 0.35. Default: 0.1.
|
||||
// "trunc_pyramids" = Heightfield = Truncated pyramids, four sided pyramids with the base edges aligned to the axes and the top cut off. Giving `n=` sets the number of heightfield samples to `n` by `n`. Default: 6. Set `style="convex"`.
|
||||
// "trunc_pyramids_vnf" = VNF Tile = Truncated pyramids, four sided pyramids with the base edges aligned to the axes and the top cut off. You can also regard this as a grid of V-grooves. Giving `inset=` specifies the horizontal inset of the flat square tops on all four sides relative to their bottoms. This means the V-groove top width will be double the inset value. The inset must be strictly between 0 and 0.5. Default: 0.1.
|
||||
|
@ -2718,8 +2718,8 @@ function associate_vertices(polygons, split, curpoly=0) =
|
|||
// Example(3D): "wave_ribs" texture.
|
||||
// tex = texture("wave_ribs");
|
||||
// linear_sweep(
|
||||
// rect(50), h=40, texture=tex,
|
||||
// tex_size=[10,10], style="concave"
|
||||
// rect(50), h=40, texture=tex,
|
||||
// tex_size=[10,10], tex_scale=3, style="concave"
|
||||
// );
|
||||
// Example(3D): "diamonds" texture.
|
||||
// tex = texture("diamonds");
|
||||
|
@ -2835,17 +2835,17 @@ function associate_vertices(polygons, split, curpoly=0) =
|
|||
// rect(50), texture=tex, h=40,
|
||||
// tex_size=[10,10]
|
||||
// );
|
||||
// Example(3D): "tri_grid" texture.
|
||||
// Example(3D): "tri_grid" texture. With uniform tex_size the triangles are squished and grooves uneven.
|
||||
// tex = texture("tri_grid");
|
||||
// linear_sweep(
|
||||
// rect(50), texture=tex, h=40,
|
||||
// tex_size=[12.5,20]
|
||||
// tex_size=[10,10]
|
||||
// );
|
||||
// Example(3D): "tri_grid" texture with large inset. (Max inset for tri_grid is 1/6.)
|
||||
// tex = texture("tri_grid",inset=.12);
|
||||
// linear_sweep(
|
||||
// rect(50), texture=tex, h=40,
|
||||
// tex_size=[12.5,20]
|
||||
// tex_size=[10,10]
|
||||
// );
|
||||
// Example(3D): "tri_grid" texture scaled by sqrt(3) so triangles are equilateral and grooves are all the same width. Note we have to ensure the height evenly fits the scaled texture tiles.
|
||||
// tex = texture("tri_grid",inset=.04);
|
||||
|
@ -2853,31 +2853,43 @@ function associate_vertices(polygons, split, curpoly=0) =
|
|||
// rect(50), texture=tex, h=quantup(40,10*sqrt(3)),
|
||||
// tex_size=[10,10*sqrt(3)], tex_scale=3
|
||||
// );
|
||||
// Example(3D): "tri_grid" texture. Here scale is approximately sqrt(3) taller so triangles are close to equilateral.
|
||||
// tex = texture("tri_grid");
|
||||
// linear_sweep(
|
||||
// rect(50), texture=tex, h=40,
|
||||
// tex_size=[12.5,20]
|
||||
// );
|
||||
// Example(3D): "hex_grid" texture.
|
||||
// tex = texture("hex_grid");
|
||||
// linear_sweep(
|
||||
// rect(50), texture=tex, h=40,
|
||||
// tex_size=[12.5,20]
|
||||
// tex_size=[10,10]
|
||||
// );
|
||||
// Example(3D): "hex_grid" texture with large inset
|
||||
// tex = texture("hex_grid", inset=0.4);
|
||||
// linear_sweep(
|
||||
// rect(50), texture=tex, h=40,
|
||||
// tex_size=[12.5,20]
|
||||
// tex_size=[10,10]
|
||||
// );
|
||||
// Example(3D): "hex_grid" scaled vertically by sqrt(3) so hexagons are regular and grooves are all the same width. Note height of cylinder is also scaled so tile fits without being automatically adjusted to fit, ruining our choice of scale.
|
||||
// tex = texture("hex_grid",inset=.04);
|
||||
// tex = texture("hex_grid",inset=.07);
|
||||
// linear_sweep(
|
||||
// rect(50), texture=tex, h=quantup(40,10*sqrt(3)),
|
||||
// tex_size=[10,10*sqrt(3)], tex_scale=3
|
||||
// );
|
||||
// Example(3D): "hex_grid" texture, with approximate scaling because 20 is close to sqrt(3) times 12.5.
|
||||
// tex = texture("hex_grid");
|
||||
// linear_sweep(
|
||||
// rect(50), texture=tex, h=40,
|
||||
// tex_size=[12.5,20]
|
||||
// );
|
||||
// Example(3D): "checkers" texture.
|
||||
// tex = texture("checkers");
|
||||
// linear_sweep(
|
||||
// rect(50), texture=tex, h=40,
|
||||
// tex_size=[10,10]
|
||||
// );
|
||||
// Example(3D): "checkers" texture.
|
||||
// Example(3D): "checkers" texture with large inset.
|
||||
// tex = texture("checkers",inset=0.25);
|
||||
// linear_sweep(
|
||||
// rect(50), texture=tex, h=40,
|
||||
|
@ -3184,7 +3196,7 @@ function texture(tex, n, inset, gap, roughness) =
|
|||
tex=="tri_grid"?
|
||||
assert(num_defined([gap, n, roughness])==0, str(tex," texture does not accept gap, n or roughness"))
|
||||
let(
|
||||
inset = default(inset,0.1)*sqrt(3)
|
||||
inset = default(inset,0.05)*sqrt(3)
|
||||
)
|
||||
assert(inset>0 && inset<sqrt(3)/6, "tri_grid texture requires inset in (0,1/6)")
|
||||
let(
|
||||
|
|
Loading…
Reference in a new issue