jscad / OpenJSCAD.org

JSCAD is an open source set of modular, browser and command line tools for creating parametric 2D and 3D designs with JavaScript code. It provides a quick, precise and reproducible method for generating 3D models, and is especially useful for 3D printing applications.
https://openjscad.xyz/
MIT License
2.65k stars 513 forks source link

Browser use most of system ressources when rendering a script with rotate() method and an array of angles #357

Closed scls19fr closed 4 years ago

scls19fr commented 6 years ago

Expected Behavior

Render correctly without crashing

Actual Behavior

Browser uses most of system ressources and seems to crash

Steps to Reproduce the Problem

I'm new to programmatic CAD (OpenSCAD, OpenJSCAD, ImplicitCAD...). I was trying to convert manually OpenSCAD code from https://www.thingiverse.com/thing:155001 to OpenJSCAD and I put following code on https://openjscad.org

function main() {
    enclosure_inner_length = 60;
    enclosure_inner_width = 40;
    enclosure_inner_depth = 30;

    enclosure_thickness = 2;

    cover_thickness = 3;

    p = lid2(enclosure_inner_length,enclosure_inner_width,enclosure_inner_depth,enclosure_thickness,enclosure_thickness/2+0.10,cover_thickness);

    return p;
}

function lid2(in_x, in_y, in_z, shell, top_lip, top_thickness) {
    sx = in_x/2 - 4;
    sy = in_y/2 - 4;
    sh = shell + in_z - 12;
    nh = shell + in_z - 4;

    p1 = union(
        cylinder(r=1.5, h = 15, $fn=32).translate([sx , sy, sh]),
        cylinder(r=1.5, h = 15, $fn=32).translate([sx , -sy, sh ]),
        cylinder(r=1.5, h = 15, $fn=32).translate([-sx , sy, sh ]),
        cylinder(r=1.5, h = 15, $fn=32).translate([-sx , -sy, sh ])
    );

    /* 
    // Work
    p2 = cube ([5.75, 10, 2.8])
        .translate([-5.75/2, -5.6/2, -0.7]);
    */

    // Doesn't work
    p2 = cube ([5.75, 10, 2.8])
        .translate([-5.75/2, -5.6/2, -0.7])
        .rotate([0,0,-45]);

    return union(p1, p2);

}

Specifications

z3dev commented 6 years ago

@scls19fr Thanks for the information.

The issue is caused by the obj.rotate([0,0,-45] That version of the rotate() function does not accept an array of angles. Please use obj.rotateZ(-45)

FYI, we are working a new version of the API which resolves the differences in the function names, parameters, etc. But that probably won't be available for a few more releases.

z3dev commented 4 years ago

No reply. Closing.