Discussion - Possible way ahead for OpenSCAD hull and Minkowski requests?

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
IPowIPi
Posts: 90
Joined: Sun Jul 25, 2021 9:37 am

Re: Discussion - Possible way ahead for OpenSCAD hull and Minkowski requests?

Post by IPowIPi »

keithsloan52 wrote: Sat Jul 31, 2021 8:50 pm A Rotation or Translation will result in a multmatrix statement in the CSG file.
which explains your test cases that worked and failed.

Going to have to think about this one.
Thank you!
If there would also be a way to extend the special case in the alternative OpenSCAD importer that can already cope with two spheres to N (in my case N=8) then I could export my full OpenSCAD model without triangulation. That trick to just place spheres at the corners of a shape and putting a hull over them covers a whole bunch of fillet scenarios and would be super useful! :oops:

Edit: Is there a reason that would speak against making your alternative importer the default one? As far as I understood it covers a number of useful corner cases where it can generate surfaces instead of triangles and otherwise just calls the default importer anyways? So wouldn't this always be better? (And in the case somebody really wants their hulls triangulated, they could still just save as STL in OpenSCAD and import that)
keithsloan52
Veteran
Posts: 2755
Joined: Mon Feb 27, 2012 5:31 pm

Re: Discussion - Possible way ahead for OpenSCAD hull and Minkowski requests?

Post by keithsloan52 »

IPowIPi wrote: Sat Jul 31, 2021 10:08 pm
Thank you!
If there would also be a way to extend the special case in the alternative OpenSCAD importer that can already cope with two spheres to N (in my case N=8) then I could export my full OpenSCAD model without triangulation. That trick to just place spheres at the corners of a shape and putting a hull over them covers a whole bunch of fillet scenarios and would be super useful! :oops:
Don't know if it would work, but for me would be an interesting experiment for you to try, would be to create your test case of cube with rounded edges as 12 pairs of hull'ed ( two spheres) all finally union'ed together, with one union. For each edge of the cube you make it a hull of two sphere's. Might have to add in a single cube.

Sounds complex but with OpenSCAD functions/modules not so bad
Edit: Is there a reason that would speak against making your alternative importer the default one? As far as I understood it covers a number of useful corner cases where it can generate surfaces instead of triangles and otherwise just calls the default importer anyways? So wouldn't this always be better? (And in the case somebody really wants their hulls triangulated, they could still just save as STL in OpenSCAD and import that)
Too experimental at the moment. Very long term plan would be to replace but at present I feel it is much better to have the option of using the original. Also easier for me to update as an external workbench as don't have the merge with FreeCAD main git
keithsloan52
Veteran
Posts: 2755
Joined: Mon Feb 27, 2012 5:31 pm

Re: Discussion - Possible way ahead for OpenSCAD hull and Minkowski requests?

Post by keithsloan52 »

Not tested for quite a while but I was under the impression OpenSCAD users use minkowski operations to create fillets.
The Alternate Importer ( used to or should ) rather than try and perform any minkowski request, just makes the objects to
be operated on in "red". The idea being that you create/develop your model with OpenSCAD and when you want to convert to FreeCAD for what ever reason, STEP file etc, you import into FreeCAD and all the objects you need to fillet are in Red and you can then use FreeCAD to do the fillets.
Last edited by keithsloan52 on Sun Aug 01, 2021 9:42 pm, edited 1 time in total.
IPowIPi
Posts: 90
Joined: Sun Jul 25, 2021 9:37 am

Re: Discussion - Possible way ahead for OpenSCAD hull and Minkowski requests?

Post by IPowIPi »

keithsloan52 wrote: Sun Aug 01, 2021 8:44 am Don't know if it would work, but for me would be an interesting experiment for you to try, would be to create your test case of cube with rounded edges as 12 pairs of hull'ed ( two spheres) all finally union'ed together, with one union. For each edge of the cube you make it a hull of two sphere's. Might have to add in a single cube.

Sounds complex but with OpenSCAD functions/modules not so bad
Good idea, gave this a try, have attached the result below (hull_to_step_experiment.scad). I get this: <class 'Part.OCCError'>: Creation of solid failed: No shells or compsolids found in shape

Should technically be a solid, but perhaps it still has holes e.g. because of rounding issues?

Edit: When removing the polyhedron that creates the faces (so only the hulls with the sphere pairs remains) then I get this:
17:02:03 Traceback (most recent call last):
File "C:\Users\strix\AppData\Roaming\FreeCAD\Mod\OpenSCAD_Alt_Import\OpenSCADHull.py", line 34, in execute
obj.Shape = createHull(obj.Group)
File "C:\Users\strix\AppData\Roaming\FreeCAD\Mod\OpenSCAD_Alt_Import\OpenSCADHull.py", line 468, in createHull
return hullTwoSpheres(obj0,obj1)
File "C:\Users\strix\AppData\Roaming\FreeCAD\Mod\OpenSCAD_Alt_Import\OpenSCADHull.py", line 331, in hullTwoSpheres
p1, p2 = c4.intersect(c3)
<class 'ValueError'>: too many values to unpack (expected 2)
keithsloan52 wrote: Sun Aug 01, 2021 8:56 am Not tested for quite a while but I was under the impression OpenSCAD users use minkowski operations to create fillets.
The Alternate Importer ( used to or should ) rather than try and perform any minkowski request, just makes the objects to
be operated in "red". The idea being that you create/develop your model with OpenSCAD and when you want to convert to FreeCAD for what ever reason, STEP file etc, you import into FreeCAD and all the objects you need to fillet are in Red and you can then use FreeCAD to do the fillets.
Hm I could probably have achieved this with minkowskiying a sphere over a polyhedron. In my case that works with hulls (or minkowskis) subtracted from hulls/minkowskis it could be challenging to mark stuff red (see attached screenshot).

It would probably be faster to get me a carving knive and learn how to carve this out of a block of wood instead of "just" trying to come up with a sound formal specification so a machine can do the carving for me. But hey, the way is (also part of) the goal :P
Attachments
pipes_lower_part.PNG
pipes_lower_part.PNG (25.41 KiB) Viewed 1267 times
hull_to_step_experiment.scad
(5.87 KiB) Downloaded 22 times
keithsloan52
Veteran
Posts: 2755
Joined: Mon Feb 27, 2012 5:31 pm

Re: Discussion - Possible way ahead for OpenSCAD hull and Minkowski requests?

Post by keithsloan52 »

IPowIPi wrote: Sun Aug 01, 2021 2:55 pm
Good idea, gave this a try, have attached the result below (hull_to_step_experiment.scad). I get this: <class 'Part.OCCError'>: Creation of solid failed: No shells or compsolids found in shape
There is at least one bug in handling just two spheres :-(

Reduced your test file to just one hull
hull_to_step_experiment-2.csg
(280 Bytes) Downloaded 47 times
And it fails

Code: Select all

6:07:56  hullTwoSpheres
16:07:56  5.0 mm
16:07:56  Traceback (most recent call last):
  File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/OpenSCAD_Alt_Import/OpenSCADHull.py", line 31, in execute
    obj.Shape = createHull(obj.Group)
  File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/OpenSCAD_Alt_Import/OpenSCADHull.py", line 474, in createHull
    return hullTwoSpheres(obj0,obj1)
  File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/OpenSCAD_Alt_Import/OpenSCADHull.py", line 337, in hullTwoSpheres
    p1, p2 = c4.intersect(c3)
<class 'ValueError'>: too many values to unpack (expected 2)
16:07:56  Recompute failed! Please check report view.
16:07:56  Group
16:07:56  End Parser
16:07:56  [<Part::PartFeature>]
16:07:56  End processing CSG file
And obviously when the union is attempted it fails to make a single solid.
keithsloan52
Veteran
Posts: 2755
Joined: Mon Feb 27, 2012 5:31 pm

Re: Discussion - Possible way ahead for OpenSCAD hull and Minkowski requests?

Post by keithsloan52 »

IPowIPi wrote: Sun Aug 01, 2021 2:55 pm It would probably be faster to get me a carving knive and learn how to carve this out of a block of wood instead of "just" trying to come up with a sound formal specification so a machine can do the carving for me. But hey, the way is (also part of) the goal :P
So is your objective to use a CNC machine to produce your shapes?

Found this post https://forum.freecadweb.org/viewtopic.php?t=36037 which raises the following questions in my mind
  • Are you using the Path workbench?
  • Will the Path workbench not handle meshes (Triangulated solids)?
  • Are you after a better result than can be achieved with CNC and meshes?
keithsloan52
Veteran
Posts: 2755
Joined: Mon Feb 27, 2012 5:31 pm

Re: Discussion - Possible way ahead for OpenSCAD hull and Minkowski requests?

Post by keithsloan52 »

IPowIPi wrote: Sun Aug 01, 2021 2:55 pm It would probably be faster to get me a carving knive and learn how to carve this out of a block of wood instead of "just" trying to come up with a sound formal specification so a machine can do the carving for me. But hey, the way is (also part of) the goal :P
Another possible experiment would be to take the shapes with Tessellations and try to wrap a NURBS surface with Blender.
Blender

Question : How to convert a mesh model to a curve/surface?

Answer : In Blender 2.79 you may consider 'shrink wrapping' a NURBs surface to your mesh.

Add a NURBS Surface into your scene above or beside a meshed object of interest (your ship hull) when in object mode. Select the NURB surface and go into Edit Mode, then subdivide as needed to get a suitable resolution for your needs, and perhaps scaling so that the NURBs surface would fully cover your mesh when shrink wrapped. Return to object mode and apply an object modifier in the deform category called Shrinkwrap. Choose the project option with a suitable direction until you get the NURBs surface to fully project on your mesh.

You could apply the result if needed so that the NURB surface retains the ship hull shape for export by pressing the Apply button in the object modifier interface. You could safely delete the ship mesh and the NURB would retain the hull shape.
IPowIPi
Posts: 90
Joined: Sun Jul 25, 2021 9:37 am

Re: Discussion - Possible way ahead for OpenSCAD hull and Minkowski requests?

Post by IPowIPi »

Thanks for the hints! Yes, CNC is one of the options in mind - once maker spaces become an option again...
Not much experience in that direction yet, still learning what to consider. Initially I was told that having a STEP file would give the most options to get this into a CAM program, but perhaps a high res STL is good enough, too.
Yepp, NURBS/SubD would also be an option. Currently I'm still on the parametric train (because I will need to iterate on a number of fundamental parameters via trial and error to see how this would actually function). But e.g. using MoI or Blender for building one best-bet iteration, trying to manufacture this and then creating a new iteration (in the worst case from scratch) might actually be faster than building the most super-parametric model imaginable. And if I have to change something I didn't foresee yet then changing this model might easily be more work than creating another up from scratch variation perhaps.
On the other hand trying to get this done via OpenSCAD is also kind of fun - a little like a puzzle game :) So will probably continue a little. Until it's done. Or until I maneuver myself into a corner I can't get out anymore. Then I can still restart from scratch with MoI or Blender :)
keithsloan52
Veteran
Posts: 2755
Joined: Mon Feb 27, 2012 5:31 pm

Re: Discussion - Possible way ahead for OpenSCAD hull and Minkowski requests?

Post by keithsloan52 »

IPowIPi wrote: Sun Aug 01, 2021 11:41 pm Thanks for the hints! Yes, CNC is one of the options in mind - once maker spaces become an option again...
Not much experience in that direction yet, still learning what to consider. Initially I was told that having a STEP file would give the most options to get this into a CAM program, but perhaps a high res STL is good enough, too.
Yepp, NURBS/SubD would also be an option. Currently I'm still on the parametric train (because I will need to iterate on a number of fundamental parameters via trial and error to see how this would actually function). But e.g. using MoI or Blender for building one best-bet iteration, trying to manufacture this and then creating a new iteration (in the worst case from scratch) might actually be faster than building the most super-parametric model imaginable. And if I have to change something I didn't foresee yet then changing this model might easily be more work than creating another up from scratch variation perhaps.
On the other hand trying to get this done via OpenSCAD is also kind of fun - a little like a puzzle game :) So will probably continue a little. Until it's done. Or until I maneuver myself into a corner I can't get out anymore. Then I can still restart from scratch with MoI or Blender :)
Asked in the FEM topic https://forum.freecadweb.org/viewtopic.php?f=15&t=60758

Would be interesting to get some feedback from somebody who was into OpenSCAD and CNC, who could try things out.
IPowIPi
Posts: 90
Joined: Sun Jul 25, 2021 9:37 am

Re: Discussion - Possible way ahead for OpenSCAD hull and Minkowski requests?

Post by IPowIPi »

keithsloan52 wrote: Mon Aug 02, 2021 7:44 am Would be interesting to get some feedback from somebody who was into OpenSCAD and CNC, who could try things out.
Thank you, will be interesting!
Have also opened a thread in the CFD forum regarding wind instrument breath simulation: https://forum.freecadweb.org/viewtopic.php?f=37&t=60768
Might be a little ambitious (and computationally expensive) - but if this could indeed be simulated then I could possibly skip a number of manufacturing trial-and-error iterations. And then a highly parametric model would of course make a lot of sense.
Post Reply