FreeCAD Sverchok & Subd To Nurbs

NODES FOR FREECAD - SVERCHOK “BRIDGE”

FCStd read - import parts from single or multiple freecad project files

FCStd read Sketches - import Sketches from single or multiple freecad project files

FCStd write - write solid or mesh parts in a single freecad project file

FCStd Spreadsheet - read/write parameter from a freecad spreadsheet

Approximate Subd to Nurbs - convert an obj (with subd modifier min 2level) to NURBS

SPERIMENTAL NODES UNDER EXCHANGE CATEGORY

If someone is interested to collaborate in this development, my goal would be to write a node set for sverchok to manage freecad project inside blender (read/write).

READ

WRITE

READ SKETCH

A SIMPLE JAR DESIGN…

how it all started

26 Likes

This is so awesome, I don’t understand why it doesn’t get more attention. I am excited overall about the subd to nurbs conversion. Hope you keep on developing this and keep us updated. Congrats for your great job.

4 Likes

Interesting. Would be nice with a video that show the workflow.

Very good start, I just tested and I am very interested in the rest

Yes, besides having freecad inside blender, subd to nurbs would be a great task to accomplish but less difficult than I thought.
I made a simple script to get it work and I now can obtain a watertight part of a subd from blender to use in cad project development, but the curvature conversion is not good enough at the moment and we have to brainstorm some math to get it work properly.
The script now take the four border marked by the seam, convert them in splines and then use the boundary curves ordered to generate a surface, it would be better to generate a nurbs grid with control points and then map this points accordingly. The curvature is obtained pinning the verts of the mesh before subdivide it and use the generated verts to guide curvature… or something like…

2 Likes

Interesting initiative. Blender lacks FreeCAD’s BIM features, and FreeCAD lacks Blender’s navigation and usability.
Have you contacted Yorik on this topic? If i recall right, he once also noted the possibility of such integration.

4 Likes

Yes the combo freeCAD “tesselate” to blender “mesh_from_pydata” seems to be already designed for this “live” connection.
But before contact Yorik about this maybe I would have something more structured on blender side.
I need some help on development mainly about these topic:

1 “node_tree” programming.
2 “math” to improve subd-nurbs conversion

3 Likes

Perhaps a more descriptive introduction to what exactly are you aiming and what you have accomplished already? It is not very clear from your first post. ‘Tesselate’, ‘subd’ and ‘mesh from py data’ terms don’t mean a lot to most people here, maybe some more low-level description?
Also - are there some images in larger resolution? I can’t seem to find a way to enlarge the ones you posted, to see some details.
Otherwise a nice idea, the information that this could be possible has been around for a couple of years now.

1 Like

I wrote a better script for “node_lite” to import all freecad parts from a file into sverchok viewer,
to update just save the project in freecad and update sverchok network

"""
in dummy v
out verts v
out faces s
out objs o
"""
import bpy,sys
#INSERT YOUR FREECAD PROJECT PATH
FREECADPATH = 'C:\\....\\bin'
sys.path.append(FREECADPATH)
import FreeCAD as F

try:
    #INSERT YOUR FREECAD PROJECT FILE PATH
    F.open("C:\\....\\WRITE_TEST.FCStd")
except:
    pass

F.setActiveDocument("WRITE_TEST")
verts=[]
faces=[]

for obj in F.ActiveDocument.Objects:
    if obj.Module in ('Part','PartDesign'):    
        mesh_data=obj.Shape.tessellate(0.01)
        verts.append( mesh_data[0] )
        faces.append( mesh_data[1] )
        F.ActiveDocument.recompute()

F.closeDocument("WRITE_TEST")

5 Likes

Hi.
Yorik said me some years ago, he will be glad to manage FreeCAD API from some node system.
Maybe interaction can be provided with sverchok even.
By the way, there are Sverchok extra tools that got nurbs/splines/vectorfields basics nodes:


Please, use it if needed. Install separately and extend with addon menu (installing dependency libraries with one click).

https://github.com/portnov/sverchok-extra/issues/1 - examples here


4 Likes

I put a years of research to design a workflow to produce complex NURBS-compatible organic mesh models.
Almost all results we has got trying to convert mesh to NURBS failed.
Here are results of our tests.
https://www.turbosquid.com/3d-models/quads-t-b-model-1225310

Can you try to convert it with your method, please?
SWAN_NB_TEST_blend.zip (1.1 MB)

1 Like

I converted a piece because the entire mesh was going to bottleneck both blender and freecad, i closed the surface to convert it in a solid. How you can see the method is quite raw in fact there is no perfect continuity between the patches, maybe It has to be fixed with some operation on curve degree.
I need some help to improve the code, it’s not a easy task.

At the moment this workflow state of art is in Fusion with T-spline, I used also the power translator in modo… I think we need to have something like in Blender, because the mesh are great but in production CAD object are best suited to obtain information and generate tech drawings, also having a bridge from Blender to FreeCAD could be the door for the “production” side, at moment I use blender in 50% of my work and other I use commercial software for CAD stuff… With a boost freecad could be a real option in CAD environment

here the step from freecad:
step_test.zip (3.7 MB)

3 Likes

I don’t know if you guys are aware of this initiative, i only found out about it recently. It is a group of enthusiasts trying to bring BIM (IFC) features to Blender, perhaps some coordination could come in handy:

Also, a Blender - BIM addon, currently in development:

https://blenderbim.org/

3 Likes

Hey here the swan converted to solid nurbs the first is an IGES and the other a step file made with Moi3D the conversion was made in two different ways the IGES with my tips and tricks here https://blenderartists.org/t/from-blender-subdivision-to-n-u-r-b-s-iges-for-free

IGES only 7mb https://mega.nz/file/B8l1hBjJ#m2XmC_hYQjA_npe5lygtHZRaCN51tZOjZM9T0JzJq3w
Step Solid but huge over 170mb
https://mega.nz/file/kw8lGZ7C#8ijriNJA6CzoCK27cygcSjXumQps2L68DrbDVMXK7Mw
here the file for FreeCAD https://mega.nz/file/N0khTZRY#hcTaXVHa8bZ1a70wut03N0V4Fz9UQ_J-S7flUpZzt-8

3 Likes

For sure, NURBS have pretty much strong mathematical engine, and scripting abstraction layer have a bottleneck by definition, but it is awesome, that method is working!
I can’t imagine how you achieved such resuls with scripting, didn’t thought that it is possible, amazing work!

I heard about initiative by Zomparelli (Blender for Computational Design and Architectural design), but not sure that it is the same. Nice to see they are using OpenIFCShell, I supported it a bit.

Well, that was completely unexpected!
A very interesting method, never heard about such programs (we also never got easyweight STEP files)
Thank you for this beautiful discovery)

1 Like

I’ve got a question - is it possible to convert objects not to subdivided NURBS, but to not subdivided solid with your approach?
It could expand freeform Architectural design in FreeCAD by using Blender.

BLENDER MESH TO FREECAD SOLID
Maybe I misunderstand the question, could be something like that?
In freecad you can import a stl file and convert it in a solid, here a sverchok/freecad way to do it in live mode… the output seems a correct solid ( I tried a boolean to test it)

Sverchok setup:

SCRIPT NODE CODE TO LOAD A BLENDER MESH INTO A FREECAD PROJECT

"""
in verts v
in faces s
"""
#out verts v
#out faces s
#out objs o

import bpy,sys
##################INSERT YOUR FREECAD PROJECT PATH
FREECADPATH = 'C:\\...\\bin'
sys.path.append(FREECADPATH)
import FreeCAD as F

try:
    ################################INSERT YOUR FREECAD PROJECT FILE PATH
    F.open("C:\\...\\WRITE_TEST.FCStd")
except:
    pass

import Mesh

F.setActiveDocument("WRITE_TEST")

fc_root = F.getDocument("WRITE_TEST")
obj_names = set( [ i.Name for i in fc_root.Objects])

if not "Mesh" in obj_names:

    mesh = Mesh.Mesh()

    meshdata=[]

    faces=faces[0]
    verts=verts[0]

    for f in faces:
        v1,v2,v3 = f[0],f[1],f[2]
        meshdata.append(verts[v1])
        meshdata.append(verts[v2])
        meshdata.append(verts[v3])
        
    MeshObject = Mesh.Mesh(meshdata)
    Mesh.show(MeshObject)

    import Part
    F.getDocument("WRITE_TEST").addObject("Part::Feature","Mesh001")
    __shape__=Part.Shape()
    __shape__.makeShapeFromMesh(F.getDocument("WRITE_TEST").getObject("Mesh").Mesh.Topology,0.100000)
    F.getDocument("WRITE_TEST").getObject("Mesh001").Shape=__shape__
    F.getDocument("WRITE_TEST").getObject("Mesh001").purgeTouched()
    del __shape__
    __s__=F.ActiveDocument.Mesh001.Shape
    __s__=Part.Solid(__s__)
    __o__=F.ActiveDocument.addObject("Part::Feature","Mesh001_solid")
    __o__.Label="Mesh001 (Solid)"
    __o__.Shape=__s__
    del __s__, __o__

    F.ActiveDocument.recompute()
    F.getDocument("WRITE_TEST").save()

F.closeDocument("WRITE_TEST")


3 Likes

Yes!
Wow, so that works as an awesome bridge now, that could be useful so in architectural modeling.
Thank you for demonstration)

3 Likes

Fantastic initiative! I really look forward to seeing this progress.

I am one of the developers of the BlenderBIM Add-on, and I have contributed a bit to the BIM features on FreeCAD, we are now collaborating on more features and organising how to share code. It is indeed the same one that Zomparelli mentioned.

1 Like

MAGIC!
I tried geomdl in sverchok extra, QUADS TO NURBS!
I see there is also a NURBS to JSON, this could be useful to convert it in freecad part…

5 Likes