mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-06 04:09:47 +00:00
commit
91dfeb7d29
1 changed files with 26 additions and 19 deletions
43
vnf.scad
43
vnf.scad
|
@ -1461,14 +1461,10 @@ module debug_vnf(vnf, faces=true, vertices=true, opacity=0.5, size=1, convexity=
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Function&Module: vnf_validate()
|
// Module: vnf_validate()
|
||||||
// Usage: As Function
|
// Usage:
|
||||||
// fails = vnf_validate(vnf);
|
|
||||||
// Usage: As Module
|
|
||||||
// vnf_validate(vnf, [size], [show_warns=], [check_isects=], [opacity=], [adjacent=], [label_verts=], [label_faces=], [wireframe=]);
|
// vnf_validate(vnf, [size], [show_warns=], [check_isects=], [opacity=], [adjacent=], [label_verts=], [label_faces=], [wireframe=]);
|
||||||
// Description:
|
// Description:
|
||||||
// When called as a function, returns a list of non-manifold errors with the given VNF.
|
|
||||||
// Each error has the format `[ERR_OR_WARN,CODE,MESG,POINTS,COLOR]`.
|
|
||||||
// When called as a module, echoes the non-manifold errors to the console, and color hilites the
|
// When called as a module, echoes the non-manifold errors to the console, and color hilites the
|
||||||
// bad edges and vertices, overlaid on a transparent gray polyhedron of the VNF.
|
// bad edges and vertices, overlaid on a transparent gray polyhedron of the VNF.
|
||||||
// .
|
// .
|
||||||
|
@ -1477,13 +1473,13 @@ module debug_vnf(vnf, faces=true, vertices=true, opacity=0.5, size=1, convexity=
|
||||||
// Type | Color | Code | Message
|
// Type | Color | Code | Message
|
||||||
// ------- | -------- | ------------ | ---------------------------------
|
// ------- | -------- | ------------ | ---------------------------------
|
||||||
// WARNING | Yellow | BIG_FACE | Face has more than 3 vertices, and may confuse CGAL.
|
// WARNING | Yellow | BIG_FACE | Face has more than 3 vertices, and may confuse CGAL.
|
||||||
// WARNING | Brown | NULL_FACE | Face has zero area.
|
// WARNING | Blue | NULL_FACE | Face has zero area.
|
||||||
// ERROR | Cyan | NONPLANAR | Face vertices are not coplanar.
|
// ERROR | Cyan | NONPLANAR | Face vertices are not coplanar.
|
||||||
// ERROR | Brown | DUP_FACE | Multiple instances of the same face.
|
// ERROR | Brown | DUP_FACE | Multiple instances of the same face.
|
||||||
// ERROR | Orange | MULTCONN | Multiply Connected Geometry. Too many faces attached at Edge.
|
// ERROR | Orange | MULTCONN | Multiply Connected Geometry. Too many faces attached at Edge.
|
||||||
// ERROR | Violet | REVERSAL | Faces reverse across edge.
|
// ERROR | Violet | REVERSAL | Faces reverse across edge.
|
||||||
// ERROR | Red | T_JUNCTION | Vertex is mid-edge on another Face.
|
// ERROR | Red | T_JUNCTION | Vertex is mid-edge on another Face.
|
||||||
// ERROR | Blue | FACE_ISECT | Faces intersect.
|
// ERROR | Brown | FACE_ISECT | Faces intersect.
|
||||||
// ERROR | Magenta | HOLE_EDGE | Edge bounds Hole.
|
// ERROR | Magenta | HOLE_EDGE | Edge bounds Hole.
|
||||||
// .
|
// .
|
||||||
// Still to implement:
|
// Still to implement:
|
||||||
|
@ -1494,11 +1490,11 @@ module debug_vnf(vnf, faces=true, vertices=true, opacity=0.5, size=1, convexity=
|
||||||
// ---
|
// ---
|
||||||
// show_warns = If true show warnings for non-triangular faces. Default: true
|
// show_warns = If true show warnings for non-triangular faces. Default: true
|
||||||
// check_isects = If true, performs slow checks for intersecting faces. Default: false
|
// check_isects = If true, performs slow checks for intersecting faces. Default: false
|
||||||
// opacity = The opacity level to show the polyhedron itself with. (Module only) Default: 0.67
|
// opacity = The opacity level to show the polyhedron itself with. Default: 0.67
|
||||||
// label_verts = If true, shows labels at each vertex that show the vertex number. (Module only) Default: false
|
// label_verts = If true, shows labels at each vertex that show the vertex number. Default: false
|
||||||
// label_faces = If true, shows labels at the center of each face that show the face number. (Module only) Default: false
|
// label_faces = If true, shows labels at the center of each face that show the face number. Default: false
|
||||||
// wireframe = If true, shows edges more clearly so you can see them in Thrown Together mode. (Module only) Default: false
|
// wireframe = If true, shows edges more clearly so you can see them in Thrown Together mode. Default: false
|
||||||
// adjacent = If true, only display faces adjacent to a vertex listed in the errors. (Module only) Default: false
|
// adjacent = If true, only display faces adjacent to a vertex listed in the errors. Default: false
|
||||||
// Example(3D,Edges): BIG_FACE Warnings; Faces with More Than 3 Vertices. CGAL often will fail to accept that a face is planar after a rotation, if it has more than 3 vertices.
|
// Example(3D,Edges): BIG_FACE Warnings; Faces with More Than 3 Vertices. CGAL often will fail to accept that a face is planar after a rotation, if it has more than 3 vertices.
|
||||||
// vnf = skin([
|
// vnf = skin([
|
||||||
// path3d(regular_ngon(n=3, d=100),0),
|
// path3d(regular_ngon(n=3, d=100),0),
|
||||||
|
@ -1555,10 +1551,13 @@ module debug_vnf(vnf, faces=true, vertices=true, opacity=0.5, size=1, convexity=
|
||||||
// path3d(regular_ngon(n=5, d=100),100)
|
// path3d(regular_ngon(n=5, d=100),100)
|
||||||
// ], slices=0, caps=false);
|
// ], slices=0, caps=false);
|
||||||
// vnf_validate(vnf,size=2);
|
// vnf_validate(vnf,size=2);
|
||||||
function vnf_validate(vnf, show_warns=true, check_isects=false) =
|
|
||||||
|
|
||||||
|
// Returns a list of non-manifold errors with the given VNF.
|
||||||
|
// Each error has the format `[ERR_OR_WARN,CODE,MESG,POINTS,COLOR]`.
|
||||||
|
function _vnf_validate(vnf, show_warns=true, check_isects=false) =
|
||||||
assert(is_vnf(vnf), "Invalid VNF")
|
assert(is_vnf(vnf), "Invalid VNF")
|
||||||
let(
|
let(
|
||||||
vnf = vnf_merge_points(vnf),
|
|
||||||
varr = vnf[0],
|
varr = vnf[0],
|
||||||
faces = vnf[1],
|
faces = vnf[1],
|
||||||
lvarr = len(varr),
|
lvarr = len(varr),
|
||||||
|
@ -1767,21 +1766,29 @@ function _edge_not_reported(edge, varr, reports) =
|
||||||
|
|
||||||
module vnf_validate(vnf, size=1, show_warns=true, check_isects=false, opacity=0.67, adjacent=false, label_verts=false, label_faces=false, wireframe=false) {
|
module vnf_validate(vnf, size=1, show_warns=true, check_isects=false, opacity=0.67, adjacent=false, label_verts=false, label_faces=false, wireframe=false) {
|
||||||
no_children($children);
|
no_children($children);
|
||||||
verts = vnf[0];
|
vcount = len(vnf[0]);
|
||||||
faults = vnf_validate(
|
fcount = len(vnf[1]);
|
||||||
|
vnf = vnf_merge_points(vnf);
|
||||||
|
faults = _vnf_validate(
|
||||||
vnf, show_warns=show_warns,
|
vnf, show_warns=show_warns,
|
||||||
check_isects=check_isects
|
check_isects=check_isects
|
||||||
);
|
);
|
||||||
|
verts = vnf[0];
|
||||||
|
vnf_changed = len(verts)!=vcount || len(vnf[1])!=fcount;
|
||||||
if (!faults) {
|
if (!faults) {
|
||||||
echo("VNF appears valid.");
|
echo("VNF appears valid.");
|
||||||
}
|
}
|
||||||
|
if (vnf_changed) echo("VNF changed when merging points; unable to display indices");
|
||||||
for (fault = faults) {
|
for (fault = faults) {
|
||||||
err = fault[0];
|
err = fault[0];
|
||||||
typ = fault[1];
|
typ = fault[1];
|
||||||
clr = fault[2];
|
clr = fault[2];
|
||||||
msg = fault[3];
|
msg = fault[3];
|
||||||
idxs = fault[4];
|
idxs = fault[4];
|
||||||
pts = [for (i=idxs) if(is_finite(i) && i>=0 && i<len(verts)) verts[i]];
|
pts = err=="FACE_ISECT" ? idxs : [for (i=idxs) if(is_finite(i) && i>=0 && i<len(verts)) verts[i]];
|
||||||
|
if (vnf_changed || err=="FACE_ISECT")
|
||||||
|
echo(str(typ, " ", err, " (", clr ,"): ", msg, " at ", pts));
|
||||||
|
else
|
||||||
echo(str(typ, " ", err, " (", clr ,"): ", msg, " at ", pts, " indices: ", idxs));
|
echo(str(typ, " ", err, " (", clr ,"): ", msg, " at ", pts, " indices: ", idxs));
|
||||||
color(clr) {
|
color(clr) {
|
||||||
if (is_vector(pts[0])) {
|
if (is_vector(pts[0])) {
|
||||||
|
|
Loading…
Reference in a new issue