discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Re-Surface interpolation and BREP-style design

KS
Keith Sloan
Wed, Mar 1, 2023 9:27 AM

Hi Martin

My interest in the original post, is that I developed the original
FreeCAD OpenSCAD importer which Sebastian Hoogen used as part of
The OpenSCAD workbench. The importer parses a CSG file and created the
equivalent Brep Objects. (Apart from some odd situation
which OCC cannot handle, see
https://github.com/FreeCAD/FreeCAD/issues/6270 and
https://github.com/FreeCAD/FreeCAD/issues/6271)
it can directly create Brep objects apart from Hull and Minkowski.

The OpenSCAD Alternate importer which is installable using the FreeCAD
Addon_Manager
tries to deal with specific Hull and Minkowski requests. and details are at
https://github.com/KeithSloan/OpenSCAD_Alt_Import.

Now I was under the impression that a common use of minkowski was to
create fillets.  The BSOL and BSOL2 documentation
https://github.com/revarbat/BOSL and https://github.com/revarbat/BOSL2
shows an example for shapes.scad of

cuboid([20,20,30], rounding=5);

producing

minkowski() {cube([10,10,20], center=true); sphere(r=5, $fn=32);}

Which using the alternate import gives

i.e. A Brep shape with fully rounded edges.

Similarly group() {
    minkowski(convexity = 0) {
        cube(size = [10, 10, 1], center = false);
        cylinder($fn = 50, $fa = 12, $fs = 2, h = 1, r1 = 2, r2 = 2,
center = false);
    }
}

Produces

Which has fully editable fillets in FreeCAD

Now it seems that the BSOL and BSOL2 libraries now produce the following CSG

group() {
    group() {
        multmatrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0,
1]]) {
            group() {
                group() {
                    group() {
                        group() {
polyhedron(points = [...], faces = [...], convexity = 2);
                        }
                    }
                }
            }
            group() {
                group();
            }
        }
    }
}

And my testing

group() {
group() {
group() {
group() {
group();
}
}
multmatrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
group() {
group() {
group() {
minkowski(convexity = 0) {
cube(size = [10, 10, 20], center = true);
group() {
rotate_extrude(angle = 360, convexity = 2, $fn = 16, $fa = 12, $fs = 2) {
polygon(points = [[0, -5.09796], [1.9509, -4.7099], [3.6048, -3.6048], [4.7099, -1.9509], [5.09796, 0], [4.7099, 1.9509], [3.6048, 3.6048], [1.9509, 4.7099], [0, 5.09796]], paths = undef, convexity = 1);
}
}
}
}
}
}
}
}

So NOT at all easy to determine the desired radius of fillets :-)

Would it be possible to add a function to the library that set a flag, something along the lines of setBrepCSG(True) and
setBrep(False)?, such that if the user codes setBrepCSG(True) then made any use of things like cuboid with rounding would create
a CSG file (Old style) that was importable into Brep objects rather than Meshes in FreeCAD?

This would facilitate better creation of STEP files, ability to perform FEM analysis, Create photo realistic versions of models etc etc of models created with OpenSCAD

Keith

--
========== Art & Ceramics ===========
https://www.instagram.com/ksloan1952/

Hi Martin My interest in the original post, is that I developed the original FreeCAD OpenSCAD importer which Sebastian Hoogen used as part of The OpenSCAD workbench. The importer parses a CSG file and created the equivalent Brep Objects. (Apart from some odd situation which OCC cannot handle, see https://github.com/FreeCAD/FreeCAD/issues/6270 and https://github.com/FreeCAD/FreeCAD/issues/6271) it can directly create Brep objects apart from Hull and Minkowski. The OpenSCAD Alternate importer which is installable using the FreeCAD Addon_Manager tries to deal with specific Hull and Minkowski requests. and details are at https://github.com/KeithSloan/OpenSCAD_Alt_Import. Now I was under the impression that a common use of minkowski was to create fillets.  The BSOL and BSOL2 documentation https://github.com/revarbat/BOSL and https://github.com/revarbat/BOSL2 shows an example for shapes.scad of cuboid([20,20,30], rounding=5); producing minkowski() {cube([10,10,20], center=true); sphere(r=5, $fn=32);} Which using the alternate import gives i.e. A Brep shape with fully rounded edges. Similarly group() {     minkowski(convexity = 0) {         cube(size = [10, 10, 1], center = false);         cylinder($fn = 50, $fa = 12, $fs = 2, h = 1, r1 = 2, r2 = 2, center = false);     } } Produces Which has fully editable fillets in FreeCAD Now it seems that the BSOL and BSOL2 libraries now produce the following CSG group() {     group() {         multmatrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {             group() {                 group() {                     group() {                         group() { polyhedron(points = [...], faces = [...], convexity = 2);                         }                     }                 }             }             group() {                 group();             }         }     } } And my testing group() { group() { group() { group() { group(); } } multmatrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { group() { group() { group() { minkowski(convexity = 0) { cube(size = [10, 10, 20], center = true); group() { rotate_extrude(angle = 360, convexity = 2, $fn = 16, $fa = 12, $fs = 2) { polygon(points = [[0, -5.09796], [1.9509, -4.7099], [3.6048, -3.6048], [4.7099, -1.9509], [5.09796, 0], [4.7099, 1.9509], [3.6048, 3.6048], [1.9509, 4.7099], [0, 5.09796]], paths = undef, convexity = 1); } } } } } } } } So NOT at all easy to determine the desired radius of fillets :-) Would it be possible to add a function to the library that set a flag, something along the lines of setBrepCSG(True) and setBrep(False)?, such that if the user codes setBrepCSG(True) then made any use of things like cuboid with rounding would create a CSG file (Old style) that was importable into Brep objects rather than Meshes in FreeCAD? This would facilitate better creation of STEP files, ability to perform FEM analysis, Create photo realistic versions of models etc etc of models created with OpenSCAD Keith -- ========== Art & Ceramics =========== https://www.instagram.com/ksloan1952/
MH
Martin Herdieckerhoff
Wed, Mar 1, 2023 4:12 PM

Am 01.03.2023 um 10:27 schrieb Keith Sloan:

The OpenSCAD Alternate importer [...]
tries to deal with specific Hull and Minkowski requests.

cuboid([20,20,30], rounding=5);

producing

[...]
A Brep shape with fully rounded edges [in FreeCAD].

Such an importer in FreeCAD, with perfect support for spherical and
cylindric roundings, seems like a very useful thing to have. It looks
like a great achievement and an ambitious goal at the same time. The
problem is that you depend on specific high level input (hull,
minkowsky, sphere, cylinder; no multmatrix on those and no arbitrary
other shapes allowed) but you seem to get a low level triangle soup.

My impression is that it should be possible for BOSL2 to pick a sphere
from those many variants supported by BOSL2 which satisfies your needs
as well as those expressed by Revar Desmera ("better looking
triangulation"). But I might not understand all implications of CSG
export. I would expect the current method of BOSL2 to be a lot faster
than use of the Minkowski operator and had thought that this might be
the reason for BOSL2 to avoid that operator for rounding. Your issue has
to be clarified with BOSL2. My library would not help. It does not use
Minkowski at all. My construction of the cuboid does not even involve
"cylinder" or "sphere".

I would like to see polyhedra with normals at vertices to come up as an
exchange format. Or is there a format which does already use that? Then
OpenSCAD would pass polyhedra with normals to FreeCAD and both sides
would use their methods (code or GUI, triangulated or smoothed down to
the pixel) to change or to display those.

However, a good exchange format would need to support sharp features.
You can get sharp features with my method of interpolation. That case
goes beyond a single normal per vertex. It requires a normal and/or a
tangent to be stored with each half-edge. This puts a capable half-edge
data structure into the center of all further considerations regarding
smooth interpolation and good high level exchange formats for
programmable shapes. I lack experience with NURBS based tools but as far
as I can see, NURBS requires GUI control and is not well suited for
program-oriented tools like OpenSCAD. What do the experts here think
about this?

I attach an image with sharp features. The input is a cube with most
normals into obvious directions. Only at the upper right corner,
normals, or rather the resulting directions of half edges, have been
tweaked as indicated by the bars. At the upper left corner, the sharp
feature merges gracefully into a precise sphere.

Am 01.03.2023 um 10:27 schrieb Keith Sloan: > > The OpenSCAD Alternate importer [...] > tries to deal with specific Hull and Minkowski requests. > > cuboid([20,20,30], rounding=5); > > producing > > [...] > A Brep shape with fully rounded edges [in FreeCAD]. Such an importer in FreeCAD, with perfect support for spherical and cylindric roundings, seems like a very useful thing to have. It looks like a great achievement and an ambitious goal at the same time. The problem is that you depend on specific high level input (hull, minkowsky, sphere, cylinder; no multmatrix on those and no arbitrary other shapes allowed) but you seem to get a low level triangle soup. My impression is that it should be possible for BOSL2 to pick a sphere from those many variants supported by BOSL2 which satisfies your needs as well as those expressed by Revar Desmera ("better looking triangulation"). But I might not understand all implications of CSG export. I would expect the current method of BOSL2 to be a lot faster than use of the Minkowski operator and had thought that this might be the reason for BOSL2 to avoid that operator for rounding. Your issue has to be clarified with BOSL2. My library would not help. It does not use Minkowski at all. My construction of the cuboid does not even involve "cylinder" or "sphere". I would like to see polyhedra with normals at vertices to come up as an exchange format. Or is there a format which does already use that? Then OpenSCAD would pass polyhedra with normals to FreeCAD and both sides would use their methods (code or GUI, triangulated or smoothed down to the pixel) to change or to display those. However, a good exchange format would need to support sharp features. You can get sharp features with my method of interpolation. That case goes beyond a single normal per vertex. It requires a normal and/or a tangent to be stored with each half-edge. This puts a capable half-edge data structure into the center of all further considerations regarding smooth interpolation and good high level exchange formats for programmable shapes. I lack experience with NURBS based tools but as far as I can see, NURBS requires GUI control and is not well suited for program-oriented tools like OpenSCAD. What do the experts here think about this? I attach an image with sharp features. The input is a cube with most normals into obvious directions. Only at the upper right corner, normals, or rather the resulting directions of half edges, have been tweaked as indicated by the bars. At the upper left corner, the sharp feature merges gracefully into a precise sphere.