Skip to content

Commit 290e39c

Browse files
Merge pull request #1641 from adrianVmariano/master
vnf_vertex_array examples & tex_scaling
2 parents abb9748 + dfc1037 commit 290e39c

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

skin.scad

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4788,7 +4788,7 @@ module _textured_revolution(
47884788
}
47894789

47904790

4791-
function _textured_point_array(points, texture, tex_reps, tex_size, tex_samples, tex_inset=false, tex_rot=0, triangulate=false,
4791+
function _textured_point_array(points, texture, tex_reps, tex_size, tex_samples, tex_inset=false, tex_rot=0, triangulate=false, tex_scaling="default",
47924792
col_wrap=false, tex_depth=1, row_wrap=false, caps, cap1, cap2, reverse=false, style="min_edge", tex_extra, tex_skip, sidecaps,sidecap1,sidecap2,normals) =
47934793
assert(tex_reps==undef || is_int(tex_reps) || (all_integer(tex_reps) && len(tex_reps)==2), "tex_reps must be an integer or list of two integers")
47944794
assert(tex_size==undef || is_num(tex_size) || is_vector(tex_size,2), "tex_size must be a scalar or 2-vector")
@@ -4814,7 +4814,9 @@ function _textured_point_array(points, texture, tex_reps, tex_size, tex_samples,
48144814
)
48154815
[max(1,round(xsize/tex_size.x)), max(1,round(ysize/tex_size.y))],
48164816
normals = default(normals,surface_normals(points, col_wrap=col_wrap, row_wrap=row_wrap)),
4817-
getscale = function(x,y) (x+y)/2
4817+
getscale = tex_scaling=="default" ? function(x,y) (x+y)/2
4818+
: tex_scaling=="const" ? function(x,y) 1
4819+
: assert(false, "Unknown tex_scaling value. Must be either \"default\" or \"const\"")
48184820
)
48194821
!is_vnf(texture) ? // heightmap case
48204822
let(

vnf.scad

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ EMPTY_VNF = [[],[]]; // The standard empty VNF with no vertices or faces.
5757
// the meaning of `tex_size` and it also affects the vertical texture scale. The size of the texture tiles is proportional to the point
5858
// spacing of the location where they are placed, so if the points are closer together, you get small texture elements. The specified `tex_depth`
5959
// is correct at the `points[0][0]` but would be different at places in the point array where the scale is different. This
60-
// differs from {{rotate_sweep()}}, which uses a uniform resampling of the curve you specify.
60+
// differs from {{rotate_sweep()}}, which uses a uniform resampling of the curve you specify.
61+
// .
62+
// The vertical scale of texture elements adjusts based on the size of the grid square where it is placed. By default, the height is scaled by the average
63+
// of the width and height of the texture element. You can disable this scaling by setting `tex_scaling="const"`, which results
64+
// in a constant height that does not vary with the grid spacing.
6165
// .
6266
// The point data for `vnf_vertex_array()` is resampled using bilinear interpolation to match the required point density of the tile count, but the
6367
// sampling is based on the grid, not on the distance between points. If you want to
@@ -93,6 +97,7 @@ EMPTY_VNF = [[],[]]; // The standard empty VNF with no vertices or faces.
9397
// sidecaps = if `col_wrap==false` this controls whether to cap any floating ends of a VNF tile on the texture. Does not affect the main texture surface. Ignored it doesn't apply. Default: false
9498
// sidecap1 = set sidecap only for the `points[][0]` edge of the output
9599
// sidecap2 = set sidecap only for the `points[][max]` edge of the output
100+
// tex_scaling = set to "const" to disable grid size vertical scaling of the texture. Default: "default"
96101
// normals = array of normal vectors to each point in the point array for more accurate texture height calculation
97102
// cp = (module) Centerpoint for determining intersection anchors or centering the shape. Determines the base of the anchor vector. Can be "centroid", "mean", "box" or a 3D point. Default: "centroid"
98103
// anchor = (module) Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `"origin"`
@@ -278,6 +283,20 @@ EMPTY_VNF = [[],[]]; // The standard empty VNF with no vertices or faces.
278283
// ];
279284
// vnf_polyhedron(vnf_vertex_array(polystack, col_wrap=true, caps=true,
280285
// texture="dots", tex_samples=1));
286+
// Example(3D,Med,NoAxes,VPR=[0,0,0],VPD=126.00,VPT=[-0.35,-0.54,4.09]): This point array defines a square region but with a non-uniform grid.
287+
// pts = [for(x=[-1:.1:1])
288+
// [for(y=[-1:.1:1])
289+
// zrot(45*min([abs(x-1),abs(x+1),abs(y-1),abs(y+1)]),
290+
// 20*[x,y,0])]];
291+
// vnf=vnf_vertex_array(pts);
292+
// color("blue") vnf_wireframe(vnf,width=.2);
293+
// Example(3D,Med,NoAxes,VPR=[0,0,0],VPD=126.00,VPT=[-0.35,-0.54,4.09]): The non-uniform grid gives rise to a non-uniform texturing.
294+
// pts = [for(x=[-1:.1:1])
295+
// [for(y=[-1:.1:1])
296+
// zrot(45*min([abs(x-1),abs(x+1),abs(y-1),abs(y+1)]),
297+
// 20*[x,y,0])]];
298+
// vnf_vertex_array(pts,texture="dots",tex_reps=15);
299+
281300

282301
module vnf_vertex_array(
283302
points,
@@ -288,11 +307,11 @@ module vnf_vertex_array(
288307
style="default",
289308
triangulate = false,
290309
texture, tex_reps, tex_size, tex_samples, tex_inset=false, tex_rot=0,
291-
tex_depth=1, tex_extra, tex_skip, sidecaps,sidecap1,sidecap2,
310+
tex_depth=1, tex_extra, tex_skip, sidecaps,sidecap1,sidecap2, tex_scaling="default",
292311
convexity=2, cp="centroid", anchor="origin", spin=0, orient=UP, atype="hull")
293312
{
294313
vnf = vnf_vertex_array(points=points, caps=caps, cap1=cap2, cap2=cap2,
295-
col_wrap=col_wrap, row_wrap=row_wrap, reverse=reverse, style=style,triangulate=triangulate,
314+
col_wrap=col_wrap, row_wrap=row_wrap, reverse=reverse, style=style,triangulate=triangulate, tex_scaling=tex_scaling,
296315
texture=texture, tex_reps=tex_reps, tex_size=tex_size, tex_samples=tex_samples, tex_inset=tex_inset, tex_rot=tex_rot,
297316
tex_depth=tex_depth, tex_extra=tex_extra, tex_skip=tex_skip, sidecaps=sidecaps,sidecap1=sidecap1,sidecap2=sidecap2
298317
);
@@ -308,7 +327,7 @@ function vnf_vertex_array(
308327
reverse=false,
309328
style="default",
310329
triangulate = false,
311-
texture, tex_reps, tex_size, tex_samples, tex_inset=false, tex_rot=0,
330+
texture, tex_reps, tex_size, tex_samples, tex_inset=false, tex_rot=0, tex_scaling="default",
312331
tex_depth=1, tex_extra, tex_skip, sidecaps,sidecap1,sidecap2, normals
313332
) =
314333
assert(in_list(style,["default","alt","quincunx", "convex","concave", "min_edge","min_area","flip1","flip2"]))
@@ -317,7 +336,7 @@ function vnf_vertex_array(
317336
assert(is_bool(triangulate))
318337
is_def(texture) ?
319338
_textured_point_array(points=points, texture=texture, tex_reps=tex_reps, tex_size=tex_size,
320-
tex_inset=tex_inset, tex_samples=tex_samples, tex_rot=tex_rot,
339+
tex_inset=tex_inset, tex_samples=tex_samples, tex_rot=tex_rot, tex_scaling=tex_scaling,
321340
col_wrap=col_wrap, row_wrap=row_wrap, tex_depth=tex_depth, caps=caps, cap1=cap1, cap2=cap2, reverse=reverse,
322341
style=style, tex_extra=tex_extra, tex_skip=tex_skip, sidecaps=sidecaps, sidecap1=sidecap1, sidecap2=sidecap2,normals=normals,triangulate=triangulate)
323342
:

0 commit comments

Comments
 (0)