mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-08-08 10:56:36 +02:00
Massive reworking of documentation production.
This commit is contained in:
124
debug.scad
124
debug.scad
@@ -1,5 +1,11 @@
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Helpers to make debugging OpenScad code easier.
|
||||
// LibFile: debug.scad
|
||||
// Helpers to make debugging OpenScad code easier.
|
||||
// To use, add the following lines to the beginning of your file:
|
||||
// ```
|
||||
// include <BOSL/constants.scad>
|
||||
// use <BOSL/debug.scad>
|
||||
// ```
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
@@ -36,76 +42,21 @@ include <paths.scad>
|
||||
include <beziers.scad>
|
||||
|
||||
|
||||
// Renders lines between each point of a polyline path.
|
||||
// Can also optionally show the individual vertex points.
|
||||
// pline = the array of points in the polyline.
|
||||
// showpts = If true, draw vertices and control points.
|
||||
// N = Mark the first and every Nth vertex after in a different color and shape.
|
||||
// size = diameter of the lines drawn.
|
||||
// color = Color to draw the lines (but not vertices) in.
|
||||
// Example:
|
||||
// bez = [
|
||||
// [-10, 0, 0], [-15, -5, 9], [0, -3, 5], [5, -10, 0],
|
||||
// [15, 0, -5], [5, 12, -8], [0, 10, -5]
|
||||
// ];
|
||||
// trace_polyline(bez, N=3, showpts=true, size=0.5, color="lightgreen");
|
||||
module trace_polyline(pline, N=1, showpts=false, size=1, color="yellow") {
|
||||
if (showpts) {
|
||||
for (i = [0:len(pline)-1]) {
|
||||
translate(pline[i]) {
|
||||
if (i%N == 0) {
|
||||
color("blue") sphere(d=size*2.5, $fn=8);
|
||||
} else {
|
||||
color("red") {
|
||||
cylinder(d=size/2, h=size*3, center=true, $fn=8);
|
||||
xrot(90) cylinder(d=size/2, h=size*3, center=true, $fn=8);
|
||||
yrot(90) cylinder(d=size/2, h=size*3, center=true, $fn=8);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = [0:len(pline)-2]) {
|
||||
if (N!=3 || (i%N) != 1) {
|
||||
color(color) extrude_from_to(pline[i], pline[i+1]) circle(d=size/2);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Section: Debugging Polyhedrons
|
||||
|
||||
|
||||
// Renders lines between each point of a polyline path.
|
||||
// Can also optionally show the individual vertex points.
|
||||
// bez = the array of points in the bezier.
|
||||
// N = Mark the first and every Nth vertex after in a different color and shape.
|
||||
// size = diameter of the lines drawn.
|
||||
// Example:
|
||||
// bez = [
|
||||
// [-10, 0], [-15, -5],
|
||||
// [ -5, -10], [ 0, -10], [ 5, -10],
|
||||
// [ 14, -5], [ 15, 0], [16, 5],
|
||||
// [ 5, 10], [ 0, 10]
|
||||
// ];
|
||||
// trace_bezier(bez, N=3, size=0.5);
|
||||
module trace_bezier(bez, N=3, size=1) {
|
||||
trace_polyline(bez, N=N, showpts=true, size=size/2, color="green");
|
||||
trace_polyline(bezier_polyline(bez, N=N), size=size);
|
||||
}
|
||||
|
||||
|
||||
// Draws all the vertices in an array, at their 3D position, numbered by their
|
||||
// position in the vertex array. Also draws any children of this module with
|
||||
// transparency.
|
||||
// Module: debug_vertices()
|
||||
// Description:
|
||||
// Draws all the vertices in an array, at their 3D position, numbered by their
|
||||
// position in the vertex array. Also draws any children of this module with
|
||||
// transparency.
|
||||
// Arguments:
|
||||
// vertices = Array of point vertices.
|
||||
// size = The size of the text used to label the vertices.
|
||||
// disabled = If true, don't draw numbers, and draw children without transparency. Default = false.
|
||||
// Example:
|
||||
// verts = [
|
||||
// [-10, 0, -10], [10, 0, -10],
|
||||
// [0, -10, 10], [0, 10, 10]
|
||||
// ];
|
||||
// faces = [
|
||||
// [0,2,1], [1,2,3], [0,3,2], [1,3,0]
|
||||
// ];
|
||||
// verts = [for (z=[-10,10], y=[-10,10], x=[-10,10]) [x,y,z]];
|
||||
// faces = [[0,1,2], [1,3,2], [0,4,5], [0,5,1], [1,5,7], [1,7,3], [3,7,6], [3,6,2], [2,6,4], [2,4,0], [4,6,7], [4,7,5]];
|
||||
// debug_vertices(vertices=verts, size=2) {
|
||||
// polyhedron(points=verts, faces=faces);
|
||||
// }
|
||||
@@ -128,7 +79,7 @@ module debug_vertices(vertices, size=1, disabled=false) {
|
||||
}
|
||||
if ($children > 0) {
|
||||
if (!disabled) {
|
||||
color([0.5, 0.5, 0, 0.25]) children();
|
||||
color([0.2, 1.0, 0, 0.5]) children();
|
||||
} else {
|
||||
children();
|
||||
}
|
||||
@@ -137,22 +88,20 @@ module debug_vertices(vertices, size=1, disabled=false) {
|
||||
|
||||
|
||||
|
||||
// Draws all the vertices at their 3D position, numbered in blue by their
|
||||
// position in the vertex array. Each face will have their face number drawn
|
||||
// in red, aligned with the center of face. All children of this module are drawn
|
||||
// with transparency.
|
||||
// Module: debug_faces()
|
||||
// Description:
|
||||
// Draws all the vertices at their 3D position, numbered in blue by their
|
||||
// position in the vertex array. Each face will have their face number drawn
|
||||
// in red, aligned with the center of face. All children of this module are drawn
|
||||
// with transparency.
|
||||
// Arguments:
|
||||
// vertices = Array of point vertices.
|
||||
// faces = Array of faces by vertex numbers.
|
||||
// size = The size of the text used to label the faces and vertices.
|
||||
// disabled = If true, don't draw numbers, and draw children without transparency. Default = false.
|
||||
// Example:
|
||||
// verts = [
|
||||
// [-10, 0, -10], [10, 0, -10],
|
||||
// [0, -10, 10], [0, 10, 10]
|
||||
// ];
|
||||
// faces = [
|
||||
// [0,2,1], [1,2,3], [0,3,2], [1,3,0]
|
||||
// ];
|
||||
// verts = [for (z=[-10,10], y=[-10,10], x=[-10,10]) [x,y,z]];
|
||||
// faces = [[0,1,2], [1,3,2], [0,4,5], [0,5,1], [1,5,7], [1,7,3], [3,7,6], [3,6,2], [2,6,4], [2,4,0], [4,6,7], [4,7,5]];
|
||||
// debug_faces(vertices=verts, faces=faces, size=2) {
|
||||
// polyhedron(points=verts, faces=faces);
|
||||
// }
|
||||
@@ -201,20 +150,23 @@ module debug_faces(vertices, faces, size=1, disabled=false) {
|
||||
|
||||
|
||||
|
||||
// A drop-in module to replace `polyhedron()` and help debug vertices and faces.
|
||||
// Draws all the vertices at their 3D position, numbered in blue by their
|
||||
// position in the vertex array. Each face will have their face number drawn
|
||||
// in red, aligned with the center of face. All given faces are drawn with
|
||||
// transparency. All children of this module are drawn with transparency.
|
||||
// Works best with Thrown-Together preview mode, to see reversed faces.
|
||||
// Module: debug_polyhedron()
|
||||
// Description:
|
||||
// A drop-in module to replace `polyhedron()` and help debug vertices and faces.
|
||||
// Draws all the vertices at their 3D position, numbered in blue by their
|
||||
// position in the vertex array. Each face will have their face number drawn
|
||||
// in red, aligned with the center of face. All given faces are drawn with
|
||||
// transparency. All children of this module are drawn with transparency.
|
||||
// Works best with Thrown-Together preview mode, to see reversed faces.
|
||||
// Arguments:
|
||||
// vertices = Array of point vertices.
|
||||
// faces = Array of faces by vertex numbers.
|
||||
// txtsize = The size of the text used to label the faces and vertices.
|
||||
// disabled = If true, act exactly like `polyhedron()`. Default = false.
|
||||
// Example:
|
||||
// pts = [[-5,0,-5], [5,0,-5], [0,-5,5], [0,5,5]];
|
||||
// fcs = [[0,2,1], [1,2,3], [1,3,0], [0,2,3]]; // Last face reversed
|
||||
// debug_polyhedron(points=pts, faces=fcs, txtsize=1);
|
||||
// verts = [for (z=[-10,10], a=[0:120:359.9]) [10*cos(a),10*sin(a),z]];
|
||||
// faces = [[0,1,2], [5,4,3], [0,3,4], [0,4,1], [1,4,5], [1,5,2], [2,5,3], [2,3,0]];
|
||||
// debug_polyhedron(points=verts, faces=faces, txtsize=1);
|
||||
module debug_polyhedron(points, faces, convexity=10, txtsize=1, disabled=false) {
|
||||
debug_faces(vertices=points, faces=faces, size=txtsize, disabled=disabled) {
|
||||
polyhedron(points=points, faces=faces, convexity=convexity);
|
||||
|
Reference in New Issue
Block a user