Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem rendering roof difference #4449

Open
ali1234 opened this issue Dec 16, 2022 · 2 comments
Open

Problem rendering roof difference #4449

ali1234 opened this issue Dec 16, 2022 · 2 comments

Comments

@ali1234
Copy link

ali1234 commented Dec 16, 2022

Version 2022.12.07 (Nightly snap)

I'm trying to take an arbitrary 2D shape and subtract the roof() from the linear_extrude() and in this specific example it fails to render. The result is just the linear extrude - nothing is subtracted. No errors are produced in the console, but I do see "WARNING: Warning: mesh is not closed!". The preview displays correctly. Changing $fa or adding a small offset() to one of the objects prevents this from happening and the render result is as expected.

Code (I wasn't able to reduce this any further and still reproduce):

$fa = 5;


module mirrorkeep(axis) {
    children();
    mirror(axis) children();
}


module roof_for_height(h) {
    intersection() {
        roof(convexity=10) children();
        linear_extrude(height=h, convexity=4) children();
    }
}


module inner_roof(radius = 3) {
    difference() {
        linear_extrude(height = radius) children();
        #translate([0, 0, -0.01]) roof_for_height(radius+0.02) children();
    }
}

module shoe_outline() {
    offset(10) offset(-10) offset(-3) offset(3)  {
        hull() {
            intersection() {
                circle(r=43);
                translate([0, -30]) square([60, 60], center=true);
            }
            mirrorkeep([1, 0, 0]) {
                translate([25.5, 32]) circle(r=10);
                translate([15.5, -16.5]) circle(r=20);
            }
        }
        translate([0, 15.5]) square([74.5, 35], center=true);
    }
}


inner_roof(radius = 1.4) offset(- 2.9) shoe_outline();

Preview (correct):

image

Render (incorrect):

image

When highlighting the roof object, it doesn't seem to be the expected shape. For example here it is z-fighting with the outside of the extrude object. Those polygons simply shouldn't exist in the roof object.

image

Other observations: changing $fa makes the problem go away, as does adding a small negative offset before applying roof.

@ali1234
Copy link
Author

ali1234 commented Dec 16, 2022

Here is another example. This creates a round roof by stacking multiple scaled roof objects to create a curve. The problem seems to be in roof_for_height() which is used in both examples. This one produces CGAL assertion errors when rendering. Again, the preview is correct and the roof objects seem to be absent from the render result.

$fs = 1;
$fa = 1;
    
module roof_for_height(h) {
    intersection() {
        roof(convexity=10) children();
        linear_extrude(height=h, convexity=4) children();
    }
}

module round_roof(step = 15, radius = 3) {
    for (angle = [0 : step : 90]) {
        x1 = radius * sin(angle);
        y1 = radius * (1 - cos(angle));
        x2 = radius * sin(angle + step);
        y2 = radius * (1 - cos(angle + step));
        dy = y2 - y1;
        dx = x2 - x1;
        translate([0, 0, x1]) scale([1, 1, dx/dy]) roof_for_height(dy) offset(-y1) children();
    }
}

round_roof(radius=5, step=10) circle(d=30);

@ali1234
Copy link
Author

ali1234 commented Dec 16, 2022

I reduced the last example down even further to this:

$fs = 1;
$fa = 1;
    
module roof_for_height(h) {
    intersection() {
        roof() children();
        linear_extrude(height=h) children();
    }
}

roof_for_height(1) offset(-0.03) circle(d=30);

Preview (correct):
image

Render result:
image

In the render, the intersection has not been applied, and several polygons are missing from the surface. Each time I do "flush caches" and re-render, the missing polygons change. Sometimes it produces assertions on the console, but not always. Here is an example of the assertions:

Parsing design (AST generation)...
Compiling design (CSG Tree generation)...
Rendering Polygon Mesh using CGAL...
WARNING: Warning: mesh is not closed!
[fast-csg] Performing safer but slower nef operation instead of corefinement because operands share some vertices. (can override with fast-csg-trust-corefinement)
ERROR: CGAL error in CGALUtils::applyOperator3DHybrid intersection: CGAL ERROR: assertion violation!
Expr: e->incident_sface() != SFace_const_handle()
File: /build/openscad-nightly/stage/usr/include/CGAL/Nef_S2/SM_const_decorator.h
Line: 329
Geometries in cache: 8
Geometry cache size in bytes: 138464
CGAL Polyhedrons in cache: 2
CGAL cache size in bytes: 10656
Total rendering time: 0:00:00.069
Top level object is a 3D object:
   Facets:        184
Rendering finished.
 
Parsing design (AST generation)...
Compiling design (CSG Tree generation)...
Compiling design (CSG Products generation)...
Geometries in cache: 8
Geometry cache size in bytes: 138464
CGAL Polyhedrons in cache: 2
CGAL cache size in bytes: 10656
Compiling design (CSG Products normalization)...
Normalized tree has 2 elements!
Compile and preview finished.
Total rendering time: 0:00:00.040

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants