1
0
mirror of https://github.com/nophead/NopSCADlib.git synced 2025-08-09 17:06:34 +02:00

Workarounds for bugs in the OpenSCAD snapshots.

This commit is contained in:
Chris Palmer
2021-09-12 18:02:43 +01:00
parent 588a1edf62
commit f0c25d37b0
20 changed files with 8632 additions and 8628 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -24,13 +24,10 @@
// bom defaults to 0 // bom defaults to 0
// Setting $bom on the command line or in the main file before including lib.scad overrides it everywhere. // Setting $bom on the command line or in the main file before including lib.scad overrides it everywhere.
// Setting $bom after including lib overrides bom in the libs but not in the local file. // Setting $bom after including lib overrides bom in the libs but not in the local file.
// Setting $_bom in the local file overrides it in the local file but not in the libs.
// //
rr_green = [0, 146/255, 0]; // RepRap logo colour rr_green = [0, 146/255, 0]; // RepRap logo colour
crimson = [220/255, 20/255, 60/255]; crimson = [220/255, 20/255, 60/255];
$_bom = is_undef($bom) ? 0 : $bom; // 0 no bom, 1 assemblies and stls, 2 vitamins as well
$exploded = is_undef($explode) ? 0 : $explode; // 1 for exploded view
layer_height = is_undef($layer_height) ? 0.25 : $layer_height; // layer height when printing layer_height = is_undef($layer_height) ? 0.25 : $layer_height; // layer height when printing
extrusion_width = is_undef($extrusion_width) ? 0.5 : $extrusion_width; // filament width when printing extrusion_width = is_undef($extrusion_width) ? 0.5 : $extrusion_width; // filament width when printing
nozzle = is_undef($nozzle) ? 0.45 : $nozzle; // 3D printer nozzle nozzle = is_undef($nozzle) ? 0.45 : $nozzle; // 3D printer nozzle

View File

@@ -139,6 +139,7 @@ def make_parts(target, part_type, parts = None):
# #
part_maker_name = tmp_dir + '/' + part_type + ".scad" part_maker_name = tmp_dir + '/' + part_type + ".scad"
with open(part_maker_name, "w") as f: with open(part_maker_name, "w") as f:
f.write("include <NopSCADlib/global_defs.scad>\n")
f.write("use <%s/%s>\n" % (reltmp(dir, target), filename)) f.write("use <%s/%s>\n" % (reltmp(dir, target), filename))
f.write("%s();\n" % module); f.write("%s();\n" % module);
t = time.time() t = time.time()

View File

@@ -94,11 +94,13 @@ def render(target, type):
cam = "--camera=0,0,0,70,0,315,500" if type == 'stl' else "--camera=0,0,0,0,0,0,500" cam = "--camera=0,0,0,70,0,315,500" if type == 'stl' else "--camera=0,0,0,0,0,0,500"
render = "--preview" if type == 'stl' or colour != pp1 else "--render" render = "--preview" if type == 'stl' or colour != pp1 else "--render"
tmp_name = tmp_dir + '/' + part[:-4] + '.png' tmp_name = tmp_dir + '/' + part[:-4] + '.png'
openscad.run("-o", tmp_name, png_maker_name, colour_scheme, "--projection=p", "--imgsize=4096,4096", cam, render, "--autocenter", "--viewall"); dummy_deps_name = tmp_dir + '/tmp.deps' # work around for OpenSCAD issue #3879
openscad.run("-o", tmp_name, png_maker_name, colour_scheme, "--projection=p", "--imgsize=4096,4096", cam, render, "--autocenter", "--viewall", "-d", dummy_deps_name)
do_cmd(("magick "+ tmp_name + " -trim -resize 280x280 -background %s -gravity Center -extent 280x280 -bordercolor %s -border 10 %s" do_cmd(("magick "+ tmp_name + " -trim -resize 280x280 -background %s -gravity Center -extent 280x280 -bordercolor %s -border 10 %s"
% (background, background, tmp_name)).split()) % (background, background, tmp_name)).split())
update_image(tmp_name, png_name) update_image(tmp_name, png_name)
os.remove(png_maker_name) os.remove(png_maker_name)
os.remove(dummy_deps_name)
# #
# Remove tmp dir # Remove tmp dir
# #

View File

@@ -72,6 +72,8 @@ def update_image(tmp_name, png_name):
if pixels < 0 or pixels > threshold: if pixels < 0 or pixels > threshold:
shutil.copyfile(tmp_name, png_name) shutil.copyfile(tmp_name, png_name)
print(Fore.YELLOW + png_name + " updated" + Fore.WHITE, pixels if pixels > 0 else '') print(Fore.YELLOW + png_name + " updated" + Fore.WHITE, pixels if pixels > 0 else '')
if png_name.endswith('_tn.png'):
os.remove(diff_name)
else: else:
os.utime(png_name, None) os.utime(png_name, None)
os.remove(diff_name) os.remove(diff_name)

View File

@@ -25,6 +25,7 @@ import time
def mktmpdir(top_dir): def mktmpdir(top_dir):
tmp_dir = top_dir + 'tmp' tmp_dir = top_dir + 'tmp'
if not os.path.isdir(tmp_dir): if not os.path.isdir(tmp_dir):
time.sleep(0.1)
os.makedirs(tmp_dir) os.makedirs(tmp_dir)
else: else:
for file in os.listdir(tmp_dir): for file in os.listdir(tmp_dir):

View File

@@ -216,6 +216,7 @@ def views(target, do_assemblies = None):
# #
png_maker_name = tmp_dir + '/png.scad' png_maker_name = tmp_dir + '/png.scad'
with open(png_maker_name, "w") as f: with open(png_maker_name, "w") as f:
f.write("include <NopSCADlib/global_defs.scad>\n")
f.write("use <%s/%s>\n" % (reltmp(dir, target), filename)) f.write("use <%s/%s>\n" % (reltmp(dir, target), filename))
f.write("%s();\n" % module); f.write("%s();\n" % module);
t = time.time() t = time.time()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 162 KiB

After

Width:  |  Height:  |  Size: 162 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 84 KiB

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 103 KiB

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 72 KiB

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 95 KiB

After

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 180 KiB

After

Width:  |  Height:  |  Size: 180 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 KiB

After

Width:  |  Height:  |  Size: 88 KiB

View File

@@ -42,24 +42,24 @@
//! * To get the parameter values make the GUI window square, pose the view with the mouse and then copy the viewport parameters from the Edit menu and paste them into the pose invocation. //! * To get the parameter values make the GUI window square, pose the view with the mouse and then copy the viewport parameters from the Edit menu and paste them into the pose invocation.
//! * Two `pose()` modules can be chained to allow different poses for exploded and assembled views. //! * Two `pose()` modules can be chained to allow different poses for exploded and assembled views.
// //
function bom_mode(n = 1) = $_bom >= n && (is_undef($on_bom) || $on_bom); //! Current BOM mode, 0 = none, 1 = printed and routed parts and assemblies, 2 includes vitamins as well function bom_mode(n = 1) = (is_undef($bom) ? 0 : $bom) >= n && (is_undef($on_bom) || $on_bom); //! Current BOM mode, 0 = none, 1 = printed and routed parts and assemblies, 2 includes vitamins as well
function exploded() = is_undef($exploded_parent) ? $exploded : 0; //! Returns the value of `$exploded` if it is defined, else `0` function exploded() = is_undef($exploded_parent) ? is_undef($explode) ? 0 : $explode : 0; //! Returns the value of `$exploded` if it is defined, else `0`
function show_supports() = !$preview || exploded(); //! True if printed support material should be shown function show_supports() = !$preview || exploded(); //! True if printed support material should be shown
module no_explode() let($exploded_parent = true) children(); //! Prevent children being exploded module no_explode() let($exploded_parent = true) children(); //! Prevent children being exploded
module explode(d, explode_children = false, offset = [0,0,0]) { //! Explode children by specified Z distance or vector `d`, option to explode grand children module explode(d, explode_children = false, offset = [0,0,0]) { //! Explode children by specified Z distance or vector `d`, option to explode grand children
v = is_list(d) ? d : [0, 0, d]; v = is_list(d) ? d : [0, 0, d];
o = is_list(offset) ? offset : [0, 0, offset]; o = is_list(offset) ? offset : [0, 0, offset];
if($exploded && is_undef($exploded_parent) && norm(v)) { if(exploded() && norm(v)) {
translate(o) // Draw the line first in case the child is transparent translate(o) // Draw the line first in case the child is transparent
color("yellow") hull() { color("yellow") hull() {
sphere(0.2); sphere(0.2);
translate(v * $exploded) translate(v * exploded())
sphere(0.2); sphere(0.2);
} }
translate(v * $exploded) translate(v * exploded())
let($exploded_parent = explode_children ? undef : true) let($exploded_parent = explode_children ? undef : true)
children(); children();
} }

View File

@@ -116,7 +116,7 @@ module wingnut(type) { //! Draw a wingnut
polygon([ polygon([
[hole_rad, 0], [hole_rad, 0],
[bottom_rad, 0], [bottom_rad, 0],
[top_rad,, thickness], [top_rad, thickness],
[hole_rad, thickness] [hole_rad, thickness]
]); ]);
for(rot = [0, 180]) for(rot = [0, 180])