Преглед на файлове

Improvements for MarlinMesh.scad

Scott Lahteine преди 4 години
родител
ревизия
f7d663c7db
променени са 1 файла, в които са добавени 102 реда и са изтрити 54 реда
  1. 102
    54
      buildroot/share/scripts/MarlinMesh.scad

+ 102
- 54
buildroot/share/scripts/MarlinMesh.scad Целия файл

10
  *                                      *
10
  *                                      *
11
  \**************************************/
11
  \**************************************/
12
 
12
 
13
-//$t = 0.15; // comment out during animation
13
+$t = 0.15; // comment out during animation!
14
+X = 0; Y = 1;
15
+L = 0; R = 1; F = 2; B = 3;
14
 
16
 
15
 //
17
 //
16
-// Mesh info and points
18
+// Sample Mesh - Replace with your own
17
 //
19
 //
18
-
19
-mesh_width    = 200;   // X Size in mm of the probed area
20
-mesh_height   = 200;   // Y Size...
21
-zprobe_offset = 0;     // Added to the points
22
-NAN           = 0;     // Z to use for un-measured points
23
-
24
 measured_z = [
20
 measured_z = [
25
   [ -1.20, -1.13, -1.09, -1.03, -1.19 ],
21
   [ -1.20, -1.13, -1.09, -1.03, -1.19 ],
26
   [ -1.16, -1.25, -1.27, -1.25, -1.08 ],
22
   [ -1.16, -1.25, -1.27, -1.25, -1.08 ],
30
 ];
26
 ];
31
 
27
 
32
 //
28
 //
29
+// An offset to add to all points in the mesh
30
+//
31
+zadjust     = 0;
32
+
33
+//
34
+// Mesh characteristics
35
+//
36
+bed_size = [ 200, 200 ];
37
+
38
+mesh_inset  = [ 10, 10, 10, 10 ]; // L, F, R, B
39
+
40
+mesh_bounds = [
41
+  [ mesh_inset[L], mesh_inset[F] ],
42
+  [ bed_size[X] - mesh_inset[R], bed_size[Y] - mesh_inset[B] ]
43
+];
44
+
45
+mesh_size = mesh_bounds[1] - mesh_bounds[0];
46
+
47
+                      // NOTE: Marlin meshes already subtract the probe offset
48
+NAN         = 0;      // Z to use for un-measured points
49
+
50
+//
33
 // Geometry
51
 // Geometry
34
 //
52
 //
35
 
53
 
45
 
63
 
46
 show_plane    = true;
64
 show_plane    = true;
47
 show_labels   = true;
65
 show_labels   = true;
66
+show_coords   = true;
48
 arrow_length  = 5;
67
 arrow_length  = 5;
49
 
68
 
50
 label_font_lg = "Arial";
69
 label_font_lg = "Arial";
62
 mesh_points_y = len(measured_z);
81
 mesh_points_y = len(measured_z);
63
 mesh_points_x = len(measured_z[0]);
82
 mesh_points_x = len(measured_z[0]);
64
 
83
 
65
-xspace = mesh_width / (mesh_points_x - 1);
66
-yspace = mesh_height / (mesh_points_y - 1);
84
+xspace = mesh_size[X] / (mesh_points_x - 1);
85
+yspace = mesh_size[Y] / (mesh_points_y - 1);
67
 
86
 
68
 // At $t=0 and $t=1 scale will be 100%
87
 // At $t=0 and $t=1 scale will be 100%
69
 z_scale_factor = min_z_scale + (($t > 0.5) ? 1.0 - $t : $t) * (max_z_scale - min_z_scale) * 2;
88
 z_scale_factor = min_z_scale + (($t > 0.5) ? 1.0 - $t : $t) * (max_z_scale - min_z_scale) * 2;
72
 // Min and max recursive functions for 1D and 2D arrays
91
 // Min and max recursive functions for 1D and 2D arrays
73
 // Return the smallest or largest value in the array
92
 // Return the smallest or largest value in the array
74
 //
93
 //
94
+function some_1D(b,i) = (i<len(b)-1) ? (b[i] && some_1D(b,i+1)) : b[i] != 0;
95
+function some_2D(a,j) = (j<len(a)-1) ? some_2D(a,j+1) : some_1D(a[j], 0);
75
 function min_1D(b,i) = (i<len(b)-1) ? min(b[i], min_1D(b,i+1)) : b[i];
96
 function min_1D(b,i) = (i<len(b)-1) ? min(b[i], min_1D(b,i+1)) : b[i];
76
 function min_2D(a,j) = (j<len(a)-1) ? min_2D(a,j+1) : min_1D(a[j], 0);
97
 function min_2D(a,j) = (j<len(a)-1) ? min_2D(a,j+1) : min_1D(a[j], 0);
77
 function max_1D(b,i) = (i<len(b)-1) ? max(b[i], max_1D(b,i+1)) : b[i];
98
 function max_1D(b,i) = (i<len(b)-1) ? max(b[i], max_1D(b,i+1)) : b[i];
98
 //
119
 //
99
 module point_markers(show_home=true) {
120
 module point_markers(show_home=true) {
100
   // Mark the home position 0,0
121
   // Mark the home position 0,0
101
-  color([0,0,0,0.25]) translate([1,1]) cylinder(r=1, h=z_scale_factor, center=true);
122
+  if (show_home)
123
+    translate([1,1]) color([0,0,0,0.25])
124
+      cylinder(r=1, h=z_scale_factor, center=true);
102
 
125
 
103
   for (x=[0:mesh_points_x-1], y=[0:mesh_points_y-1]) {
126
   for (x=[0:mesh_points_x-1], y=[0:mesh_points_y-1]) {
104
-    z = measured_z[y][x];
127
+    z = measured_z[y][x] - zadjust;
105
     down = z < mean_value;
128
     down = z < mean_value;
106
-    translate(pos(x, y, z)) {
129
+    xyz = pos(x, y, z);
130
+    translate([ xyz[0], xyz[1] ]) {
131
+
132
+      // Show the XY as well as the Z!
133
+      if (show_coords) {
134
+        color("black")
135
+        translate([0,0,0.5]) {
136
+          $fn=8;
137
+          rotate([0,0]) {
138
+            posx = floor(mesh_bounds[0][X] + x * xspace);
139
+            posy = floor(mesh_bounds[0][Y] + y * yspace);
140
+            text(str(posx, ",", posy), 2, label_font_sm, halign="center", valign="center");
141
+          }
142
+        }
143
+      }
107
 
144
 
108
-      // Label each point with the Z
109
-      if (show_labels) {
145
+      translate([ 0, 0, xyz[2] ]) {
146
+        // Label each point with the Z
110
         v = z - mean_value;
147
         v = z - mean_value;
148
+        if (show_labels) {
111
 
149
 
112
-        color(abs(v) < 0.1 ? [0,0.5,0] : [0.25,0,0])
113
-        translate([0,0,down?-10:10]) {
150
+          color(abs(v) < 0.1 ? [0,0.5,0] : [0.25,0,0])
151
+          translate([0,0,down?-10:10]) {
114
 
152
 
115
-          $fn=8;
116
-          rotate([90,0])
117
-            text(str(z), 6, label_font_lg, halign="center", valign="center");
153
+            $fn=8;
154
+            rotate([90,0])
155
+              text(str(z), 6, label_font_lg, halign="center", valign="center");
118
 
156
 
119
-          translate([0,0,down?-6:6]) rotate([90,0])
120
-            text(str(down ? "" : "+", v), 3, label_font_sm, halign="center", valign="center");
157
+            if (v)
158
+              translate([0,0,down?-6:6]) rotate([90,0])
159
+                text(str(down || !v ? "" : "+", v), 3, label_font_sm, halign="center", valign="center");
160
+          }
121
         }
161
         }
122
-      }
123
 
162
 
124
-      // Show an arrow pointing up or down
125
-      rotate([0, down ? 180 : 0]) translate([0,0,-1])
126
-        cylinder(
127
-          r1=0.5,
128
-          r2=0.1,
129
-          h=arrow_length, $fn=12, center=1
130
-        );
163
+        // Show an arrow pointing up or down
164
+        if (v) {
165
+          rotate([0, down ? 180 : 0]) translate([0,0,-1])
166
+            cylinder(
167
+              r1=0.5,
168
+              r2=0.1,
169
+              h=arrow_length, $fn=12, center=1
170
+            );
171
+        }
172
+        else
173
+          color([1,0,1,0.4]) sphere(r=1.0, $fn=20, center=1);
174
+      }
131
     }
175
     }
132
   }
176
   }
133
 }
177
 }
161
  * The simplest mesh display
205
  * The simplest mesh display
162
  */
206
  */
163
 module simple_mesh(show_plane=show_plane) {
207
 module simple_mesh(show_plane=show_plane) {
164
-  if (show_plane) color(plane_color) cube([mesh_width, mesh_height, thickness]);
208
+  if (show_plane) color(plane_color) cube([mesh_size[X], mesh_size[Y], thickness]);
165
   color(mesh_color)
209
   color(mesh_color)
166
     for (x=[0:mesh_points_x-2], y=[0:mesh_points_y-2])
210
     for (x=[0:mesh_points_x-2], y=[0:mesh_points_y-2])
167
       tesselated_square(grid_square(x, y));
211
       tesselated_square(grid_square(x, y));
171
  * Subdivide the mesh into smaller squares.
215
  * Subdivide the mesh into smaller squares.
172
  */
216
  */
173
 module bilinear_mesh(show_plane=show_plane,tesselation=tesselation) {
217
 module bilinear_mesh(show_plane=show_plane,tesselation=tesselation) {
174
-  if (show_plane) color(plane_color) translate([-5,-5]) cube([mesh_width+10, mesh_height+10, thickness]);
175
-  tesselation = tesselation % 4;
176
-  color(mesh_color)
177
-  for (x=[0:mesh_points_x-2], y=[0:mesh_points_y-2]) {
178
-    square = grid_square(x, y);
179
-    if (tesselation < 1) {
180
-      tesselated_square(square,(x%alternation)-(y%alternation));
181
-    }
182
-    else {
183
-      subdiv_4 = subdivided_square(square);
184
-      if (tesselation < 2) {
185
-        for (i=[0:3]) tesselated_square(subdiv_4[i],i%alternation);
218
+  if (show_plane) color(plane_color) translate([-5,-5]) cube([mesh_size[X]+10, mesh_size[Y]+10, thickness]);
219
+
220
+  if (some_2D(measured_z, 0)) {
221
+
222
+    tesselation = tesselation % 4;
223
+    color(mesh_color)
224
+    for (x=[0:mesh_points_x-2], y=[0:mesh_points_y-2]) {
225
+      square = grid_square(x, y);
226
+      if (tesselation < 1) {
227
+        tesselated_square(square,(x%alternation)-(y%alternation));
186
       }
228
       }
187
       else {
229
       else {
188
-        for (i=[0:3]) {
189
-          subdiv_16 = subdivided_square(subdiv_4[i]);
190
-          if (tesselation < 3) {
191
-            for (j=[0:3]) tesselated_square(subdiv_16[j],j%alternation);
192
-          }
193
-          else {
194
-            for (j=[0:3]) {
195
-              subdiv_64 = subdivided_square(subdiv_16[j]);
196
-              if (tesselation < 4) {
197
-                for (k=[0:3]) tesselated_square(subdiv_64[k]);
230
+        subdiv_4 = subdivided_square(square);
231
+        if (tesselation < 2) {
232
+          for (i=[0:3]) tesselated_square(subdiv_4[i],i%alternation);
233
+        }
234
+        else {
235
+          for (i=[0:3]) {
236
+            subdiv_16 = subdivided_square(subdiv_4[i]);
237
+            if (tesselation < 3) {
238
+              for (j=[0:3]) tesselated_square(subdiv_16[j],j%alternation);
239
+            }
240
+            else {
241
+              for (j=[0:3]) {
242
+                subdiv_64 = subdivided_square(subdiv_16[j]);
243
+                if (tesselation < 4) {
244
+                  for (k=[0:3]) tesselated_square(subdiv_64[k]);
245
+                }
198
               }
246
               }
199
             }
247
             }
200
           }
248
           }
249
 
297
 
250
 //================================================ Run the plan
298
 //================================================ Run the plan
251
 
299
 
252
-translate([-mesh_width / 2, -mesh_height / 2]) {
300
+translate([-mesh_size[X] / 2, -mesh_size[Y] / 2]) {
253
   $fn = 12;
301
   $fn = 12;
254
   point_markers();
302
   point_markers();
255
   bilinear_mesh();
303
   bilinear_mesh();

Loading…
Отказ
Запис