vnf_vertex_array bugfix for flip styles & doc improvement

This commit is contained in:
Adrian Mariano
2025-06-25 20:51:56 -04:00
parent 179eb72657
commit 1b5555060a

View File

@@ -40,15 +40,18 @@ EMPTY_VNF = [[],[]]; // The standard empty VNF with no vertices or faces.
// and creating the faces defined by those edges. You can optionally create the edges and faces to wrap the last column // and creating the faces defined by those edges. You can optionally create the edges and faces to wrap the last column
// back to the first column, or wrap the last row to the first. Endcaps can be added to either // back to the first column, or wrap the last row to the first. Endcaps can be added to either
// the first and/or last rows. The style parameter determines how the quadrilaterals are divided into // the first and/or last rows. The style parameter determines how the quadrilaterals are divided into
// triangles. The default style is an arbitrary, systematic subdivision in the same direction. The "alt" style // triangles. The styles are:
// is the uniform subdivision in the other (alternate) direction. The "flip1" style is an arbitrary division that alternates the // * "default" — arbitrary, systematic subdivision in the same direction
// direction for any adjacent pair of quadrilaterals. The "flip2" style is the alternating division that is the opposite of "flip1". // * "alt" — uniform subdivision in the other (alternate) direction
// The "min_edge" style picks the shorter edge to // * "flip1" — arbitrary division that alternates the direction adjacent pairs of quadrilaterals.
// subdivide for each quadrilateral, so the division may not be uniform across the shape. The "quincunx" style // * "flip2" — the alternating division that is the opposite of "flip1".
// adds a vertex in the center of each quadrilateral and creates four triangles, and the "convex" and "concave" styles // * "min_edge" — subdivide each quadrilateral on its shorter edge, so the division may not be uniform across the shape
// choose the locally convex/concave subdivision. The "min_area" option creates the triangulation with the minimal area. // * "min_area" — creates the triangulation with the minimal area.
// The "quad" style makes quadrilateral edges, which may not be coplanar, relying on OpensCAD to decide how to handle them. Degenerate faces // * "quincunx" — adds a vertex in the center of each quadrilateral and creates four triangles
// are not included in the output, but if this results in unused vertices, those unused vertices do still appear in the output. // * "convex" — choose the locally convex division
// * "concave" — choose the locally concave division
// * "quad" — makes quadrilateral edges, which may not be coplanar, relying on OpensCAD to decide how to handle them.
// Degenerate faces are not included in the output, but if this results in unused vertices, those unused vertices do still appear in the output.
// . // .
// You can apply a texture to the vertex array VNF using the usual texture parameters. // You can apply a texture to the vertex array VNF using the usual texture parameters.
// See [Texturing](skin.scad#section-texturing) for more details on how textures work. // See [Texturing](skin.scad#section-texturing) for more details on how textures work.
@@ -388,9 +391,6 @@ function vnf_vertex_array(
style=="quincunx"? style=="quincunx"?
let(i5 = pcnt + r*colcnt + c) let(i5 = pcnt + r*colcnt + c)
[[i1,i5,i2],[i2,i5,i3],[i3,i5,i4],[i4,i5,i1]] [[i1,i5,i2],[i2,i5,i3],[i3,i5,i4],[i4,i5,i1]]
: style=="alt" || (style=="flip1" && ((r+c)%2==0)) || (style=="flip2" && ((r+c)%2==1)) || (style=="random" && rands(0,1,1)[0]<.5)?
[[i1,i4,i2],[i2,i4,i3]]
: style=="default" ? [[i1,i3,i2],[i1,i4,i3]]
: style=="min_area"? : style=="min_area"?
let( let(
area42 = norm(cross(pts[i2]-pts[i1], pts[i4]-pts[i1]))+norm(cross(pts[i4]-pts[i3], pts[i2]-pts[i3])), area42 = norm(cross(pts[i2]-pts[i1], pts[i4]-pts[i1]))+norm(cross(pts[i4]-pts[i3], pts[i2]-pts[i3])),
@@ -429,7 +429,10 @@ function vnf_vertex_array(
: [[i1,i3,i2],[i1,i4,i3]] : [[i1,i3,i2],[i1,i4,i3]]
) )
concavefaces concavefaces
: [[i1,i2,i3,i4]], : style=="quad" ? [[i1,i2,i3,i4]]
: style=="alt" || (style=="flip1" && ((r+c)%2==0)) || (style=="flip2" && ((r+c)%2==1)) || (style=="random" && rands(0,1,1)[0]<.5)?
[[i1,i4,i2],[i2,i4,i3]]
: [[i1,i3,i2],[i1,i4,i3]],
// remove degenerate faces // remove degenerate faces
culled_faces= [for(face=faces) culled_faces= [for(face=faces)
if (norm(cross(verts[face[1]]-verts[face[0]], if (norm(cross(verts[face[1]]-verts[face[0]],