Parametric file format

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
xryl669
Posts: 32
Joined: Fri Jul 31, 2020 1:19 pm

Parametric file format

Post by xryl669 »

Hi,

I know that there is no standard parametric CAD file format that's open and interoperable (maybe STEP 242 is close, but I don't know if it's correctly supported for parametric information import/export in OCCT, I haven't found any software generating parametric STEP 242 format).

I'm trying to write a tool that's analyzing a basic mesh and tries to reproduce it as a solid by identifying and extracting its features so it re-becomes parametric, unlike the "Convert to solid" function in FreeCAD.

While doing this, I'm looking for a way to save the deduced information from the mesh into a file format that can be imported in parametric CAD software, and stay parametric.

I've thought about OpenSCAD format, but it's not really parametric (unless the user starts to tinker with the internal value) and it's not user friendly to use.
Also, sketches in OpenSCAD are too simple to be of any use.
I've tried next to use FreeCAD FCstd format, but the documentation is hard to find to explain what is useful and what isn't in the XML document, and also how the BREP OCCT's format is made. What is the minimum XML document that can be opened by FreeCAD without breaking, with a sketch and some functions (Pad/Pocket/etc) ?
I've ruled out all proprietary format (f3d, sldprt etc...) since there is no documentation about them and they can't be opened by other software.

So instead of re-inventing the wheel here, maybe you know about a parametric file format for CAD that I could have missed that can be used for this ?
If you don't, can someone points me to a clear document about the fcstd file format (not the wiki ;-) ?
Is there any community effort to make one ? (I know about OpenCAD but it seems dead).
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Parametric file format

Post by Kunda1 »

Cool idea. Yes, there is a need for this! + We really need to have a clear standard documentation for FCStd format. Maybe this is something that can be done in parallel with your effort here 'xryl669' ?
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
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: Parametric file format

Post by adrianinsaval »

xryl669 wrote: Fri Aug 06, 2021 3:58 pm I've tried next to use FreeCAD FCstd format, but the documentation is hard to find to explain what is useful and what isn't in the XML document, and also how the BREP OCCT's format is made. What is the minimum XML document that can be opened by FreeCAD without breaking, with a sketch and some functions (Pad/Pocket/etc) ?
I think the .brep files are not strictly necessary, they can be generated on file open, that would mean the files are not immediately usable but will require recomputation though. My understanding is that those files are created by calls to opencascade functions, I guess he most sensible thing would be to generate only the xml via script then open in FreeCAD and trigger a recompute to generate those files.
chrisb
Veteran
Posts: 53920
Joined: Tue Mar 17, 2015 9:14 am

Re: Parametric file format

Post by chrisb »

I'm not sure if it is a good idea to create the file contents directly. Wouldn't it be better to create appropriate geometric structures and let the existing mechanism do the work to store it in the file?
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Parametric file format

Post by keithsloan52 »

xryl669 wrote: Fri Aug 06, 2021 3:58 pm I'm trying to write a tool that's analyzing a basic mesh and tries to reproduce it as a solid by identifying and extracting its features so it re-becomes parametric, unlike the "Convert to solid" function in FreeCAD.
If you are looking at Meshes then there are extensions to the Obj file format for curves and surfaces.
Quote from http://www.martinreddy.net/gfx/3d/OBJ.spec
The curve and surface extensions to the .obj file format were developed in conjunction with mental images GmbH&Co.KG, Berlin, Germany, as part of a joint development project to incorporate free-form surfaces into Wavefront's Advanced Visualizer.
As to going from mesh to parametric curve/surfaces, then if there are any solutions in the open source world its likely to be in Blender
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Parametric file format

Post by keithsloan52 »

keithsloan52 wrote: Fri Aug 06, 2021 5:58 pm As to going from mesh to parametric curve/surfaces, then if there are any solutions in the open source world its likely to be in Blender
Not open source but there is an extension to Rhino which goes from mesh to surface http://www.resurf3d.com/products.htm
Neither Rhino or resurf3d are open source.

I made a start on a workbench to import 3dm files from Rhino https://github.com/KeithSloan/ImportNURBS but whilst it creates valid BezierSplines and surfaces, none of the curve workbenches allow one to edit them see Clearly curves and surfaces are parametric, but it is a question of exposure of them. If we had an object layer on top of Part::BezierSpline etc the same way we have for others Parts then I think we might make some progress but there seems to be resistance to this.
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Parametric file format

Post by keithsloan52 »

xryl669 wrote: Fri Aug 06, 2021 3:58 pm Hi,
I know that there is no standard parametric CAD file format that's open and interoperable (maybe STEP 242 is close, but I don't know if it's correctly supported for parametric information import/export in OCCT, I haven't found any software generating parametric STEP 242 format).
The 3DM file format is parametric and there is open source software to read & write see https://www.rhino3d.com/opennurbs/
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: Parametric file format

Post by adrianinsaval »

is it really parametric? I thought it was more like an stp file, not a mesh but not parametric either
xryl669
Posts: 32
Joined: Fri Jul 31, 2020 1:19 pm

Re: Parametric file format

Post by xryl669 »

Thanks for all the links!

When I was writing parametric CAD, I was more thinking about the way Solidwork and FreeCAD interprets parametric, not the way Rhino does, that is sketch with constraints based on some dynamic value, then applying functions on it (like pad /pocket / revolve / loft etc) and then getting solid that can be combined (boolean) to make a part. If I understand correctly, 3dm is more about specifying parametric curves (that is, the surface of a solid), but it does not deal with the solid part itself (no boolean operations, no constraint).

Basically, my goal is to be able to load a STL for a simple part in the software, the software then detects all the vertices and faces on the same plane and builds back a N-gon (at first) or a BSpline. Then it uses an algorithm to figure out if the same curve exists on a parallel plane (thus this is an extrusion). It'll then group the vertices for the N-Gon on a sketch and create an extrude operation.
For circles, a simple algorithm is used to detect when a set of vertices is likely representing a circle and instead of storing a N-Gon here, it's using a circle primitive.

It's also using basic heuristic to find out symmetry planes, so it can also detect basic revolution's operation.
As for boolean operations, right now I don't have a obvious solution, unless the boolean operation is simple (union), but for example, difference, there is no heuristic I can find to figure what was the part that was removed from the original solid.

Finally, I'm also planning to detect chamfer and fillet (similar to the circle detection above) and remove them before the analysis above is done.

The algorithm for circle detection is based on counting the number of sides for a cyclic N-Gon, and checking the angles between edges (it must be within a tolerance around 360°/sides and the edge length should be almost equal). It should also support partial circles (a.k.a arc).
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Parametric file format

Post by keithsloan52 »

xryl669 wrote: Sat Aug 07, 2021 7:16 am When I was writing parametric CAD, I was more thinking about the way Solidwork and FreeCAD interprets parametric, not the way Rhino does, that is sketch with constraints based on some dynamic value, then applying functions on it (like pad /pocket / revolve / loft etc) and then getting solid that can be combined (boolean) to make a part. If I understand correctly, 3dm is more about specifying parametric curves (that is, the surface of a solid), but it does not deal with the solid part itself (no boolean operations, no constraint).
3dm is NOT just about curves and surfaces it also supports regular shapes. Interchange of of sketch etc would be great but will have very limited usefulness unless you can get people like Solidworks to support it, plus a common interpretation of a sketch and constraints implementation is going to be very challenging
Basically, my goal is to be able to load a STL for a simple part in the software, the software then detects all the vertices and faces on the same plane and builds back a N-gon (at first) or a BSpline. Then it uses an algorithm to figure out if the same curve exists on a parallel plane (thus this is an extrusion). It'll then group the vertices for the N-Gon on a sketch and create an extrude operation.
For circles, a simple algorithm is used to detect when a set of vertices is likely representing a circle and instead of storing a N-Gon here, it's using a circle primitive.

It's also using basic heuristic to find out symmetry planes, so it can also detect basic revolution's operation.
As for boolean operations, right now I don't have a obvious solution, unless the boolean operation is simple (union), but for example, difference, there is no heuristic I can find to figure what was the part that was removed from the original solid.

Finally, I'm also planning to detect chamfer and fillet (similar to the circle detection above) and remove them before the analysis above is done.

The algorithm for circle detection is based on counting the number of sides for a cyclic N-Gon, and checking the angles between edges (it must be within a tolerance around 360°/sides and the edge length should be almost equal). It should also support partial circles (a.k.a arc).
Good luck with all of this
Post Reply