News for hackers. Stuff that matters.
Re:Fornjot – The world needs another CAD program by injidup on Monday March 28, 2022 @04:03AM (#30828260)
The problem CAD as code doesn't easily solve is how to refer to parts of the generated model for further processing. Consider adding in fillets to parts of your model. You have generated something complex through a series of sketches and extrusions in different orientations. Now you wish to round off some of the sharp edges in the resulting model but not all of them. Using CAD as code you have the problem of trying to select which edges you want.

Some have tried to generate things like CSS selectors for 3D geometry. It's clever but hard to use. In a GUI CAD system you just click on the edge. In a good GUI CAD system the selections are robust against slight changes in the feature tree.

Re:Fornjot – The world needs another CAD program by ur-whale on Monday March 28, 2022 @05:22AM (#30828739)
> The problem CAD as code doesn't easily solve is how to refer to parts of the generated model for further processing.

Yes, I very much agree, but that is simply something that needs to be added to 'code as CAD' tools.

Software engineering has solved this a long time ago with self introspection.

OpenSCAD, to name a specific 'code as CAD' tool sorely lacks a way to "query" an existing assembly and use the result in subsequent modeling. If they added that, it'd be a quantum leap in modeling power for the platform. It's all the more frustrating that the underlying engine (CGAL) fully supports it with the ray-model intersection routine.

Re:Fornjot – The world needs another CAD program by injidup on Monday March 28, 2022 @05:42AM (#30828838)
Tell me. How has software engineering solved a long time ago how to select the single segment shown here? The one marked yellow is selected. https://i.imgur.com/rbGDsvF.png I just picked this with my mouse within OnShape and it took me one only second to robustly pick it.

If you look under the hood as see how OnShape generates robust picking selectors it is not something you really want to try coding by hand. You can do it but it is non trivial.

Read

https://www.onshape.com/en/resource-center/tech-tips/tech-ti...

and

https://cad.onshape.com/FsDoc/library.html#module-query.fs

if you want to learn more how it is done. It is super awesome but not trivial to use.

Featurescript is designed to be used in within a GUI environment where you pick something specific and then a new custom feature is added to the feature tree. It is a hybrid code / no-code solution. The end user still performs the typical pick and configure workflow.

Re:Fornjot – The world needs another CAD program by duped on Monday March 28, 2022 @08:52AM (#30830007)
Typically we'd call this feature "goto definition"
Re:Fornjot – The world needs another CAD program by phkahler on Monday March 28, 2022 @10:52AM (#30831083)
The definition isn't explicit. That curve - and several other - is the result of a single CSG operation. It might be possible to describe it in terms of the things that generated it, but that's way harder to do than selecting it with a mouse.
Re:Fornjot – The world needs another CAD program by duped on Monday March 28, 2022 @11:25AM (#30831506)
You wouldn't replace clicking stuff with a mouse?
Re:Fornjot – The world needs another CAD program by injidup on Monday March 28, 2022 @09:32AM (#30830352)
And how would you implement "Goto definition?" For a line segment that you didn't directly create and is an incidental artifact of a sequence of CSG operations.

The line segment is not "defined" like a variable. There is no line in the code that gives you a declaration. It is a build artifact.

Re:Fornjot – The world needs another CAD program by duped on Monday March 28, 2022 @10:30AM (#30830861)
With a table that stores the source locator of the operation that generated the visualization and a program to query this table.

A rendering is not a build artifact except in the purest sense, it's just a different view into the source code. If you want to transition back to code you store the information required for it, it's not terribly difficult.

Another analogous feature is setting a breakpoint. They're not exactly equivalent, but depending on how the visualization is treated by the programming environment it covers what you're talking about.

Re:Fornjot – The world needs another CAD program by injidup on Monday March 28, 2022 @11:25AM (#30831507)
Oh. You mean with a vtable. Like with OO languages and virtual functions. And it would be just like that except perhaps with borrow checking. ,#rust
Re:Fornjot – The world needs another CAD program by duped on Monday March 28, 2022 @12:23PM (#30832207)
Not really, vtables are a way to implement dynamic dispatch. A "table" is just a key/value store (in a vtable, the key is a function/method identifier and the value is the function itself).

In this case the key is the geometry and the value is the code that created it. But the real trick is to make sure the opposite is true, so you can go from code -> visualization and visualization -> code without a ton of difficulty.

Re:Fornjot – The world needs another CAD program by injidup on Monday March 28, 2022 @10:25PM (#30838047)
Vtables are the digital analogue of signed distance fields. That is the trick. Rust gets this right. It is why most rust developers use text editors instead of UML diagrams. We can do the same with CAD. Instead of using a transformer network put the whole geometric inversion in level 1 cache and dispatch through the vtable. The borrow checker does the rest for you. No need to use the mouse anymore. The geometry inversions are now just a keyboard press away.
Re:Fornjot – The world needs another CAD program by duped on Monday March 28, 2022 @10:48PM (#30838182)
Rust doesn't use vtables by and large - like I said it's a technique for implementing dynamic dispatch (call a function with a different implementation based on the type of one argument, aka single dispatch). Notably, Rust does not rely on it for most cases (Rust uses type classes aka traits which are monomorphized - unless you explicitly use the `dyn` keyword to use a vtable implementation that incurs a slight performance penalty).

Not sure what they have to do with signed distance fields. It's just an implementation detail for single dispatch. What's the analog?

Re:Fornjot – The world needs another CAD program by injidup on Tuesday March 29, 2022 @03:09AM (#30839691)
Signed distance fields are like vtables. You can invert the cross product and you can introspect information that is otherwise not observable. That is you call a method in user space and it is dispatched to the origin. It is a monad or more specifically an applicative over the geometric inversion. Instead of selecting the segment with the mouse you perform a bind over the generative original data. Thus the projection in the limit provides the functor towards the flat space in which exists the segment that requires selection. You are right. Vtables are not enough but with the borrow checking rust provides you no longer need to track the ownership of the space vectors of the transitive solution. It's pretty complex stuff as a library writer to formulate but once encoded it is not much harder to use than a CSS selector. If you spend a few minutes thinking about it anybody could code it up I'm sure.
Re:Fornjot – The world needs another CAD program by benhurmarcel on Tuesday March 29, 2022 @10:37AM (#30843092)
I completely agree, and just to point out that the author answered about this below: https://news.ycombinator.com/item?id=30841614

In particular this is interesting, although as a mechanical engineer I don't see that as very practical: https://cadquery.readthedocs.io/en/latest/selectors.html

Re:Fornjot – The world needs another CAD program by regularfry on Monday March 28, 2022 @04:55AM (#30828599)
Signed distance fields are one approach to this, but it's a very different way of thinking.
Re:Fornjot – The world needs another CAD program by injidup on Monday March 28, 2022 @06:47AM (#30829127)
How does a signed distance field robustly allow you to select one edge out of many considering that these edges are an artefact the previous CSG operations you may have performed? These edges may or may not exist, their adjacent faces may or may not exist. They may be an in a non obvious orientation or be near or far from other edges or faces. Any query language or filter would need to be able to robustly handle such a system. OnShape has this but it is not for end users. It is for library developers. End users still get to point and click because it's the most obvious and simple thing to do.
Re:Fornjot – The world needs another CAD program by regularfry on Monday March 28, 2022 @09:45AM (#30830417)
I mean that part of the problem isn't unique to CAD as code. You've just described the Topological Naming Problem, and handling it is a complete mess.

SDFs let you say the reverse: by default fillet everything, and focus on finding ways to parameterise the fillet radius in ways that work for the part.

Re:Fornjot – The world needs another CAD program by injidup on Monday March 28, 2022 @11:29AM (#30831552)
Sorry but no. Well maybe you managed to put a new/old name to the problem but SDFs don't solve selecting an edge or a face or a point out of 5000.
Re:Fornjot – The world needs another CAD program by regularfry on Tuesday March 29, 2022 @03:38AM (#30839858)
Nothing does. That's what I'm getting at. SDFs give you a different way of thinking about the problem to avoid having to make the selection explicitly which, when you can get away with it, solves for an interesting subset of the problem space, but there is no general solution to the problem you're describing, visual CAD or CAD-as-code. What we do have are mountains of hacks that more or less work to hide that fact.

Any CAD package, code or visual, has only two ways to identify topological entities. Either you identify them from their underlying topology ("this edge is the 5th created by the intersection of objects A and B"), or you define some sort of query function over the final shape as it ends up in space, divorced from how it was created ("give me the edge that includes an arc in the XY plane radius r about point B"). Freecad does the former, from what I can see Onshape does something like the latter, but in both cases it's possible to generate a pathological feature tree which breaks under a change you want to make. How easy it is to make that breakage happen (or, conversely, how likely you are to accidentally trip over it in your day-to-day work) is controlled by how high the mountain of hacks is.

It's reasonable to say that no current CAD-as-code package solves the problem today but it's not true to say that it couldn't be done. The most obvious approach you could see is where the user clicks to select an element in a rendered preview and some selector string or other gets copied to to the clipboard that they then paste into the code to use directly, just like you can get a usable selector for a DOM element in the same format as you'd write by hand out of Chrome's Dev tools. That would work with either approach, and the fact that you're using a selector string in the same format as you'd write by hand means you can edit it as code when you need to.

Re:Fornjot – The world needs another CAD program by injidup on Tuesday March 29, 2022 @06:25AM (#30840817)
This is exactly what OnShape does. When. You click they generate two things, an id for that which is selected based on a feature path as well as the region that was clicked along with the type of object. The first works as long as the feature tree remains stable. This is only possible with a GUI selection mechanism which you acknowledge. As OnShape provides a powerful scripting system called feature script the future you imagine is already here. I wrote my own feature components for surfboard design using it.
Re:Fornjot – The world needs another CAD program by regularfry on Tuesday March 29, 2022 @07:53AM (#30841359)
It's not only possible with a GUI selection mechanism, that's just one way to get at them. If you've got a human-readable selector, it should be human-writable as well, and there will be cases where you would want to do that.

The property of only working "as long as the feature tree remains stable" is a big part of the Topological Naming Problem, and it applies to both GUI and non-GUI environments.

Re:Fornjot – The world needs another CAD program by injidup on Tuesday March 29, 2022 @08:55PM (#30850317)
I think we both agree that stability is an issue. I'm only taking issue with the 'code only' crowd who are claiming that it's just as easy to SELECT an object via code as with a mouse. It is not.

In fact depending on the contextual information the GUI is able to obtain when the user clicks it is probably possible in many cases to ensure better stability than code only.

Again look at how OnShape records user selection via mouse click. It not only tries to record path information but also the 3D location of the click. Thus if the path lookup fails there is a fallback. The actual recorded data is quite unwieldy but as it is computer generated this is fine.

As you point out the "topological naming problem" is not guaranteed to be solvable under feature tree changes. However it can be often solved with heuristics that can be collected by an agent from analysing what the user clicked on and trying to figure out what makes that click unique. It's not 100% reliable but it is hard to do better or faster if you are hand coding a more than trivial part.

Again I recommend you look an actual production system.

https://www.onshape.com/en/resource-center/tech-tips/tech-ti...

Re:Fornjot – The world needs another CAD program by regularfry on Wednesday March 30, 2022 @11:14AM (#30856289)
> I'm only taking issue with the 'code only' crowd who are claiming that it's just as easy to SELECT an object via code as with a mouse.

Where are these people? I see people saying it's possible, not saying it's just as easy. If you've got two different interaction modes, then some things are going to be easier in one than in the other, and vice versa. Otherwise there would be One True Interface, Autodesk would have patented the hell out of it, and nothing else would be worth building.

> ...heuristics...

Yes. I know. That's the mountain of hacks I was talking about upthread. And there's not a lot in there that you couldn't represent textually.

> Again I recommend you look an actual production system.

Already seen it, thanks.

Re:Fornjot – The world needs another CAD program by injidup on Tuesday March 29, 2022 @08:53PM (#30850309)
I think we both agree that stability is an issue. I'm only taking issue with the 'code only' crowd who are claiming that it's just as easy to SELECT an object via code as with a mouse. It is not.

In fact depending on the contextual information the GUI is able to obtain when the user clicks it is probably possible in many cases to ensure better stability than code only.

Again look at how OnShape records user selection via mouse click. It not only tries to record path information but also the 3D location of the click. Thus if the path lookup fails there is a fallback. The actual recorded data is quite unwieldy but as it is computer generated this is fine.

As you point out the "topological naming problem" is not guaranteed to be solvable under feature tree changes. However it can be often solved with heuristics that can be collected by an agent from analysing what the user clicked on and trying to figure out what makes that click unique. It's not 100% reliable but it is hard to do better or faster if you are hand coding a more than trivial part.