zalo / CascadeStudio

A Full Live-Scripted CAD Kernel in the Browser
https://zalo.github.io/CascadeStudio/
MIT License
1.01k stars 126 forks source link

CascadeStudio models randomly corrupted #36

Open udif opened 3 years ago

udif commented 3 years ago

I started playing with CascadeStudio every since the hackaday article 1-2 months ago, and I really like it.

However, as I try building more complex models I run into geometrical corruption issues, where changing a small parameter controlling the size of an objects can cause total model corruption. sometimes changing the model, evaluating it, and reverting the change fixes the corruption. For my previous model I had to rewrite it for a different platform (www.jscad.xyz), just because CascadeStudio wasn't stable enough.

Today it happened again, so I wanted to share the model to get to the bottom of it. Here is a minimum example from a larger model:


let space_diag = 0.2
let height = 60
let rad_ext = 2.5
let width = 30 - 2 * rad_ext
let line_spacing = 16.5
let axis_d = 0.5 // distance from axis to start of base
let line1_w = 1.6
let line2_w = 2
let grid_angle = (90 - 47.5)
let axis_o = -15.21 

//let holder = Translate([10,10,0], hold_s)
let line_2 = Rotate([1, 0, 0], 180 + grid_angle, Box(2, line2_w + space_diag, 3*width))
let line_1 = Rotate([1, 0, 0], -grid_angle, Box(2, line1_w + space_diag, 3*width))

let line = Translate([rad_ext, 0, height], Union([line_2, line_1]))
let line_grid = Union([
    Translate([0, axis_o, line_spacing * 2], line),
    Translate([0, axis_o, line_spacing], line),
    Translate([0, axis_o, 0], line),
    Translate([0, axis_o, -line_spacing], line),
    Translate([0, axis_o, -line_spacing * 2], line),
    Translate([0, axis_o, -line_spacing * 3], line),
    Translate([0, axis_o, -line_spacing * 4], line),
    Translate([0, axis_o, -line_spacing * 5], line),
    Translate([0, axis_o, -line_spacing * 6], line)
])
let b2 = Translate([rad_ext, 0, 0], Box(2, width, height, false))
let plane1 = Difference(b2, [line_grid])

When I render this (clean, InPrivate (same as incognito in chrome) on Microsoft Edge), I get: bad_grid

After commenting out the last line (Difference(...)) , evaluating the script and removing the comment again, I now get: good_grid

I think my problems in previous models were also related to Difference().

zalo commented 3 years ago

For what it's worth, random model corruption is probably related to the Cache? checkbox.

The cache is a hack I'm using to store the intermediate states of the model evaluation to dramatically speed up generation. But unfortunately, sometimes the Cache gets corrupted and causes issues :-(