Generative Design with FreeCAD

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!
User avatar
j8sr0230
Posts: 140
Joined: Thu Apr 07, 2022 8:59 am
Location: Chemnitz
Contact:

Generative Design with FreeCAD

Post by j8sr0230 »

Hello Community,
after my post in the "Users Showcase" (https://forum.freecadweb.org/viewtopic. ... &start=230) the member Kunda1 encouraged me to open this thread. Among other things, I model curved façade elements, which I then produce from wood using a CNC router. For such projects I usually use node-based modellers like Rhino's Grasshopper, Blender's Geometry Nodes or Sverchok. For some time now, I've been kicking around the idea of converting my workflow to FreeCAD, implementing generative algorithms as scripted objects, and in this way gradually expanding the scope of FreeCAD for generative designs and modelling. For the development I use realthunder's latest FreeCAD version:

Code: Select all

OS: Windows 10 (10.0)
Word size of FreeCAD: 64-bit
Version: 2022.430.26244 +4758 (Git)
Build type: Release
Branch: LinkDaily
Hash: b024b876480a533018fdc702145e9e38f8c54ba6
Python version: 3.9.12
Qt version: 5.12.9
Coin version: 4.0.1
OCC version: 7.5.3
Locale: German/Germany (de_DE)
I implemented my first two scripted objects with the classes DistributeOnFaceLink and DualMesh. As a container for my classes I use the Python module GenerativeDesign.py (see appendix).

DistributeOnFaceLink uses FreeCAD's Link Array Technology to randomly distribute object instances on target surfaces (cf. Blender's particle system). The instantiated object and the target surface remain fully parametric after creation. In addition, particle distribution (beta-distribution), particle density and seed can be manipulated parametrically (see figures below).
DistributeFace: Cone on torus
DistributeFace: Cone on torus
2022-05-25_DistributeFace1.png (102.68 KiB) Viewed 7517 times
DistributeFace: Increased number of instances
DistributeFace: Increased number of instances
2022-05-25_DistributeFace2.png (136.12 KiB) Viewed 7517 times
DistributeFace: Manipulated particle distribution
DistributeFace: Manipulated particle distribution
2022-05-25_DistributeFace3.png (142.76 KiB) Viewed 7517 times
DistributeFace: Parametric manipulation of instances
DistributeFace: Parametric manipulation of instances
2022-05-25_DistributeFace4.png (671.76 KiB) Viewed 7517 times
Last edited by j8sr0230 on Wed May 25, 2022 8:11 pm, edited 1 time in total.
Codelink on GitHub: https://github.com/j8sr0230/codelink
Codelink on PiPy: https://pypi.org/project/codelink/
FreeCAD Nodes Workbench on GitHub: https://github.com/j8sr0230/Nodes
User avatar
j8sr0230
Posts: 140
Joined: Thu Apr 07, 2022 8:59 am
Location: Chemnitz
Contact:

Re: Generative Design with FreeCAD

Post by j8sr0230 »

DualMesh converts a triangular mesh from Mesh Workbench into it’s dual, i.e. faces are turned into vertices and vertices are turned into faces. It produces clean solid elements. Extrusion thickness, scaling and shape (polygon or bspline) can be manipulated parametrically (see figures).
DualMesh with polygon contour
DualMesh with polygon contour
2022-05-25_DualMesh1.png (227.32 KiB) Viewed 7498 times
DualMesh with bspline contour
DualMesh with bspline contour
2022-05-25_DualMesh2.png (251.3 KiB) Viewed 7498 times
DualMesh with big extrusion thickness
DualMesh with big extrusion thickness
2022-05-25_DualMesh3.png (400.88 KiB) Viewed 7498 times
If you are interested, simply download the module GenerativeDesign.py, move it to your macro directory, create a new FreeCAD document and execute the following code from your FreeCAD terminal:

Code: Select all

import GenerativeDesign as gd
gd.makeDistributeOnFaceLink()
gd.makeDualMesh()
These function calls generate examples that you can use to take a closer look at the objects. Together with the documented code in the Python module, you should be able to understand how my scripted objects work. I hope for a good exchange and a lively discussion. If you have any questions, please do not hesitate to contact me.
Attachments
GenerativeDesign.py
GenerativeDesign Python Module
(7.72 KiB) Downloaded 140 times
Codelink on GitHub: https://github.com/j8sr0230/codelink
Codelink on PiPy: https://pypi.org/project/codelink/
FreeCAD Nodes Workbench on GitHub: https://github.com/j8sr0230/Nodes
bleber
Posts: 259
Joined: Thu Jun 30, 2016 5:12 pm

Re: Generative Design with FreeCAD

Post by bleber »

Hi, i like your work. Are you planing some type of node programing or other visual method to create generative objects?.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Generative Design with FreeCAD

Post by Kunda1 »

Lets add this to FreeCAD-macros ?

CC 'Sverchok to FreeCAD' folk: @Rastart @MisterMaker @drmacro
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
M4x
Veteran
Posts: 1472
Joined: Sat Mar 11, 2017 9:23 am
Location: Germany

Re: Generative Design with FreeCAD

Post by M4x »

Very interesting, I'm going to have a closer look!
User avatar
hammax
Veteran
Posts: 1985
Joined: Thu Jan 19, 2017 5:03 pm
Location: Ammersee DE

Re: Generative Design with FreeCAD

Post by hammax »

... is there a way, to change the support from torus to sphere inside the property window.
FC.20 28886 Win 10

Link_on_Face.PNG
Link_on_Face.PNG (77.83 KiB) Viewed 7192 times
Attachments
Dist_on_Face.FCStd
FC.20 28886
(29.88 KiB) Downloaded 52 times
User avatar
j8sr0230
Posts: 140
Joined: Thu Apr 07, 2022 8:59 am
Location: Chemnitz
Contact:

Re: Generative Design with FreeCAD

Post by j8sr0230 »

hammax wrote: Thu May 26, 2022 10:44 am ... is there a way, to change the support from torus to sphere inside the property window.
FC.20 28886 Win 10

Link_on_Face.PNG
Yes, that is possible. The target area is just a link that you can change parametrically. The link array object has the property Face in the property group "Particles". You can simply change this via the three points in the menu (see figure below). Attention: DistributeOnFaceLink does not work with solids but with faces (subelements). Therefore, Face1 must be entered manually in the dialogue behind Kugel. The basic use of DualMesh and DistributeOnFaceLink can be seen in the maker functions in GenerativeDesign.py.
Changing the target face
Changing the target face
Change of target face.png (770.75 KiB) Viewed 7165 times
Codelink on GitHub: https://github.com/j8sr0230/codelink
Codelink on PiPy: https://pypi.org/project/codelink/
FreeCAD Nodes Workbench on GitHub: https://github.com/j8sr0230/Nodes
User avatar
j8sr0230
Posts: 140
Joined: Thu Apr 07, 2022 8:59 am
Location: Chemnitz
Contact:

Re: Generative Design with FreeCAD

Post by j8sr0230 »

bleber wrote: Wed May 25, 2022 8:51 pm Hi, i like your work. Are you planing some type of node programing or other visual method to create generative objects?.
Kunda1 wrote: Wed May 25, 2022 9:00 pm Lets add this to FreeCAD-macros ?

CC 'Sverchok to FreeCAD' folk: @Rastart @MisterMaker @drmacro
There is a great follow along tutorial on programming a node editor in Python using PyQT5 on BlenderFreak https://blenderfreak.com/tutorials/node ... al-series/. I am thinking of doing the tutorial and programming everything into a FreeCAD QtGui.QDockWidget instead of a stand-alone QMainWindow. You can see a draft design in the image below.
FreeCAD Node Editor
FreeCAD Node Editor
FreeCAD Node Editor.png (927.03 KiB) Viewed 7119 times
That should be a manageable task. After that, the community could work with me to transfer the necessary OCCT functions of the part module into nodes. In contrast to microelly2's PyFlow approach, this would not be an extra program but a FreeCAD native node editor as a dock widget. This in turn would be a suitable platform for making generative algorithms available to the community as nodes, possibly better than independent macros. What is your opinion on this and why was the solid PyFlow approach not pursued further?
Codelink on GitHub: https://github.com/j8sr0230/codelink
Codelink on PiPy: https://pypi.org/project/codelink/
FreeCAD Nodes Workbench on GitHub: https://github.com/j8sr0230/Nodes
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Generative Design with FreeCAD

Post by Kunda1 »

@j8sr0230 Have you seen https://github.com/QuentinTournier40/AnimationFreeCAD ? It uses PyFlow with microelly2's modifications along with mods made by the student devs creating AnimationFreeCAD.
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
hammax
Veteran
Posts: 1985
Joined: Thu Jan 19, 2017 5:03 pm
Location: Ammersee DE

Re: Generative Design with FreeCAD

Post by hammax »

... it's really a "generative design".
My first trial to use a "face" ended here => really astonishing !!!
Beg your pardon for being OT.
I'll try it again.
Attachments
Dist_on_Face_2.FCStd
FC.20
(15.85 KiB) Downloaded 53 times
Link_on_Face_4.PNG
Link_on_Face_4.PNG (116.84 KiB) Viewed 7036 times
Post Reply