Generative Design with FreeCAD
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Be nice to others! Read the FreeCAD code of conduct!
Re: Generative Design with FreeCAD
This looks very interesting !
Maybe should cross-post in the Arch / BIM forum for more exposure
Maybe should cross-post in the Arch / BIM forum for more exposure
Re: Generative Design with FreeCAD
Trying to understand how it works, can you elaborate slightly on the usage of the attributes ?
And reading and hopefully could understand the codes
And reading and hopefully could understand the codes
Re: Generative Design with FreeCAD
I'm going to drop this here, in case there are clever people reading. Just in case there is some overlap in these ideas! I'm not sure though, as I'm not one of the clever ones
https://www.youtube.com/watch?v=gcRDdYrgOhg
Description: "This course is a comprehensive introduction to intrinsic triangulations, a powerful recent technique for surface mesh algorithms. These triangulations can be used to make existing algorithms robust to low-quality data, as well as enabling entirely new geometric routines. They offer a computational connection to the rich mathematical theory of intrinsic geometry."
https://www.youtube.com/watch?v=gcRDdYrgOhg
Description: "This course is a comprehensive introduction to intrinsic triangulations, a powerful recent technique for surface mesh algorithms. These triangulations can be used to make existing algorithms robust to low-quality data, as well as enabling entirely new geometric routines. They offer a computational connection to the rich mathematical theory of intrinsic geometry."
Re: Generative Design with FreeCAD
Noted App::LinkPython is used in your implementation. With limited python knowledge, I use the stock App:Link in Voxelisation - 2nd Prototype. Another FeaturePython object is responsible to calculate the placement and element count required. The 'output' of the latter FeaturePython are used to feed to the stock App:Link and can be used for other usecases.j8sr0230 wrote: ↑Wed May 25, 2022 7:49 pm 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.
Any comments on either approaches? Thanks
Example model file -
Links to codes in github -
https://github.com/paullee0/FreeCAD_Ske ... t.py#L1051
https://github.com/paullee0/FreeCAD_Ske ... ct.py#L558
https://github.com/paullee0/FreeCAD_Ske ... ct.py#L439
Re: Generative Design with FreeCAD
It would be a great addition for FreeCAD. I think it would allow to many artists to take interest in the software (currently there are almost only engineers as users). Also there are some addons that need a nodes platform to operate on the software like Topologic or Ladybug. You could help to fill the gap of these new tools and FreeCAD.j8sr0230 wrote: ↑Thu May 26, 2022 12:20 pm
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.
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?
::bitacovir::
==================
One must be absolutely modern.
Arthur Rimbaud (A Season in Hell -1873)
Canal Youtube Grupo Telegram de FreeCAD Español
My personal web site
My GitHub repository
Mini Airflow Tunnel Project
==================
One must be absolutely modern.
Arthur Rimbaud (A Season in Hell -1873)
Canal Youtube Grupo Telegram de FreeCAD Español
My personal web site
My GitHub repository
Mini Airflow Tunnel Project
Re: Generative Design with FreeCAD
Could this be used to generate a Voronoi pattern?
Source: https://openclipart.org/image/2400px/sv ... offset.png
Source: https://openclipart.org/image/2400px/sv ... offset.png
Regards / Viele Grüße
Max
Max
Re: Generative Design with FreeCAD
... don't forget saso's
https://forum.freecadweb.org/viewtopic.php?f=8&t=47493
https://forum.freecadweb.org/viewtopic.php?f=8&t=47493
Re: Generative Design with FreeCAD
Of course, let me start with the DistributeOnFaceLink class.
Code: Select all
def __init__(self, obj, instance_link, face_link):
Code: Select all
obj.addProperty("App::PropertyLinkSub", "Face", "Particles", "Target face", 0).Face = face_link
obj.addProperty("App::PropertyInteger", "Seed", "Particles", "Seed of random distribution", 0).Seed = 0
obj.addProperty("App::PropertyFloat", "Density", "Particles", "Instance density on target surface", 0).Density = 1
obj.addProperty("App::PropertyBool", "Align", "Particles", "Aligned to target surface (true) or default alignment (false)", 0).Align = True
obj.addProperty("App::PropertyFloat", "UAlpha", "Particles", "First distribution shape parameters in u direction", 0).UAlpha = 1
obj.addProperty("App::PropertyFloat", "UBeta", "Particles", "Second distribution shape parameters in u direction", 0).UBeta = 1
obj.addProperty("App::PropertyFloat", "VAlpha", "Particles", "First distribution shape parameters in v direction", 0).VAlpha = 1
obj.addProperty("App::PropertyFloat", "VBeta", "Particles", "Second distribution shape parameters in v direction", 0).VBeta = 1
obj.LinkedObject = instance_link # Instance to distribute
obj.ShowElement = False # Default setup
Since my scripted FreeCAD object is of type App::LinkPython, it already has the properties LinkedObject and ShowElement. In the penultimate constructor line, I pass the instance_link to the LinkedObject property, as it is precisely this instance that is to be duplicated. Lastly, I initiate ShowElement with False to avoid displaying all instances of instance_link in the FreeCAD tree.
The calculation of the positions of the object instances is done in the following function, which is called automatically by FreeCAD, e.g. after manipulation of the properties:
Code: Select all
def execute(self, obj):
Code: Select all
# Get uv range of target face
target_face = obj.Face[0].getSubObject(obj.Face[1])[0]
uRange = np.array(target_face.ParameterRange)[:2]
vRange = np.array(target_face.ParameterRange)[2:]
# Genrate random uv list with beta distribution
number = int((target_face.Area/1000) * obj.Density)
Code: Select all
random_gen = np.random.default_rng(seed=obj.Seed)
u_list = np.interp(random_gen.beta(obj.UAlpha, obj.UBeta, number), [0, 1], uRange)
v_list = np.interp(random_gen.beta(obj.VAlpha, obj.VBeta, number), [0, 1], vRange)
uv_list = np.column_stack((u_list, v_list))
Code: Select all
# Calculate vectors and normals on target face
vectors =[target_face.valueAt(uv[0], uv[1]) for uv in uv_list] # Random positions on uv
normals = [target_face.normalAt(uv[0], uv[1]) for uv in uv_list] # Random normals on uv
mask = np.array([target_face.isInside(vector, 0.1, True) for vector in vectors]) # True, if vector is inside face
vectors = np.array(vectors)[mask] # Random positions inside face
normals = np.array(normals)[mask] # Random normals inside face
rotations = [App.Rotation(App.Vector(0, 0, 1), App.Vector(normal)) for normal in normals] # Random rotations inside face
Code: Select all
# Generate placement list
placement_list = []
for idx, vector in enumerate(vectors):
placement = App.Placement()
placement.Base = vector
if obj.Align:
placement.Rotation = rotations[idx]
placement_list.append(placement)
obj.ElementCount = len(placement_list)
obj.PlacementList = placement_list
Before I forget, thanks for creating the cross-post. Are all my replies now automatically mirrored in this cross post, or does this just serve as a reference to this thread?
Last edited by j8sr0230 on Sun May 29, 2022 11:02 am, 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
Codelink on PiPy: https://pypi.org/project/codelink/
FreeCAD Nodes Workbench on GitHub: https://github.com/j8sr0230/Nodes
Re: Generative Design with FreeCAD
I like your implementation and to be honest I initially took exactly the same approach with two classes to position link array objects in space. However, I wanted my LinkArray to behave and look like a LinkArray from the Draft WB. The App::LinkPython object gives you the oportunity to create your very own AppLink with all the logic you need, implemented in the execute function (in just one class). By the way, it even has an appLinkExecute function, that is evaluated for every item in the LinkArray and can be used to get an even better access to all your linked elements in the array.paullee wrote: ↑Sat May 28, 2022 10:35 amNoted App::LinkPython is used in your implementation. With limited python knowledge, I use the stock App:Link in Voxelisation - 2nd Prototype. Another FeaturePython object is responsible to calculate the placement and element count required. The 'output' of the latter FeaturePython are used to feed to the stock App:Link and can be used for other usecases.j8sr0230 wrote: ↑Wed May 25, 2022 7:49 pm 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.
Any comments on either approaches? Thanks
Example model file -
Test_ Voxel_ 7_ Link w ElementCount_ Test_Class Voxel_ r.FCStd
Links to codes in github -
https://github.com/paullee0/FreeCAD_Ske ... t.py#L1051
https://github.com/paullee0/FreeCAD_Ske ... ct.py#L558
https://github.com/paullee0/FreeCAD_Ske ... ct.py#L439
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
Codelink on PiPy: https://pypi.org/project/codelink/
FreeCAD Nodes Workbench on GitHub: https://github.com/j8sr0230/Nodes