Irev-Dev / curated-code-cad

A list of the various code-cad projects out there.
https://kurthutten.com/blog/curated-code-cad
MIT License
243 stars 9 forks source link

Add FreeCAD work in progress #8

Closed Irev-Dev closed 3 years ago

Irev-Dev commented 3 years ago

experiments with making the birdhouse in a code-centric manner.

image

Ultimately I didn't finish the bird-house, but my goal was never to complete the birdhouse at all costs with code (because I could just copy everything from the python console for that).

Instead, the goal was to become familiar with methods/classes at play in freecad and see if I could come up with a generalised approach to make Cading in freeCAD in a code only fashion sustainable and enjoyable. So I would say I failed at doing so for the amount of the effort I'm willing to put in right now, I feel like I hit some obstacles that would be pretty hard to overcome, but that's also why I'm consulting the FreeCAD community to see if they have any killer ideas. I'm not sure to what extent code-only-cading in freecad has been explored previously. Maybe I've gone about it completely wrong?

Background

Most of the code-cad packages use CSG paradigm, that is boolean operations with 3d primitives. I think this a very limited mode that the community is stuck in (my opinion). Since FreeCad uses a constraint-based-model, with a BREP kernal, and support for a lot of customization there feels like there's an opportunity here.

One of OpenSCAD's (the OG code-cad package) greatest strengths is that its very declarative in nature. OpenSCAD code describes what the shape should look like and it's not exactly procedural. In this regard, a power extension to the code-cad paradigm would be a declarative syntax/API that incorporates constraints, and this can be done in any language just by having a data structure convention.

So in the code I had an attempt at doing so with some very basic sketches, where the sketch is made of a series of vertices that form a complete loop, and these vertices are then referenced to add constraints to the sketch. It worked for this very simple example. Look at my inline comments for further details.

These attempts at constant based code modelling is what I failed at. If I was trying to do boolean operations with 3d primitives in FreeCAD, I'm sure that would be reasonably straight forward.

Where did it fall apart?

While I had already started to introduce some hacky things in the simple example. When I tried to add arc/radii into the mix things really feel apart. When adding curves the "tangent" constraint is very important and this is where I found FreeCAD to be less than deterministic. Mainly because whenever an arc is made to be tangential with a line there are two directions it can do so in, an obtuse (where the line flows smoothly into the arc) or acute (where it comes to a sharp point). Normally with use in the GUI this isn't a problem because FreeCAD snaps to the one it matches closes to and it has a user to guide it, but when trying to describe to tangent with code I feel like it's important to differentiate between the two. Some of the code from this experiment can be found here

Now, much of what I've been talking about might simply be the case that there are functions and methods that do all this that I'm simply not aware of. Otherwise, I also found that I would often have to draw lines arbitrarily in 2d space just so they existed before I constrained them, that's completely fine for proof of concept like this, but it did add to the general feel that I was very much trying to fit a square peg into a hole.

Oh and BTW I've been using v0.19

Irev-Dev commented 3 years ago

As much as this isn't a complete example I think there's still something to be learned from this. I'll make a ready me for all these examples and given context I think it still makes sense to merge this.