opencax / GSoC

Google Summer of Code Projects
30 stars 14 forks source link

Direct Modeling tools in FreeCAD #17

Closed yorikvanhavre closed 1 year ago

yorikvanhavre commented 5 years ago

This idea now happens on the FreeCAD repo at https://github.com/FreeCAD/FreeCAD/issues/5764

Outline

FreeCAD is a feature-based parametric modeling system, hence different modeling steps depend on one or multiple previous steps. Each step is at the same time a tool/operation, and a geometrical object, resulting from that operation. This mix of operation and object is called a feature. Direct modeling, often presented as the opposite of parametric modeling, allows to graphically move vertices, push or pull faces and edges to modify the geometry of an object.

Watch an introduction to direct modeling on https://www.youtube.com/watch?v=RMrvjAPxyN0

The two concepts could however easily coexist in FreeCAD. Each operation performed via direct modeling could be stored into a new feature, that would successively modify the previous object by adding transformations, such as a displacement of a vertex, an edge, or a face, or extrusion of a certain face.

This GSoC project aims at throwing the bases of the necessary feature(s) to hold such transformations as parameters, and the 3D manipulators to allow the user to modify an existing 3D object by clicking and dragging on the screen.

Details

Expected Outcome

Future Possibilities

Since direct modeling is a huge area in constant evolution, the work done in this GSoC will only cover a small part of it. But if the bases are done right, extending them will be easy and could develop very far.

Project Properties

Skills

Difficulty

Hard

Additional Information

TheBeLieveRs commented 4 years ago

I am Prakhar Srivastava a student if IIT Roorkee ,India and I would like to work on this issue can u tell what ide u suggest for this, or maybe the ide u would have worked on

yorikvanhavre commented 3 years ago

Warning: This project idea had been formulated for GSO2020, and might be too big for the new format of GSOC2021. Nevertheless, this functionality is still required, and this can serve as a base to build your own project, or could be implemented partially.

yorikvanhavre commented 3 years ago

Other FreeCAD ideas for 2021 at https://www.forum.freecadweb.org/viewtopic.php?f=8&t=54913

luzpaz commented 3 years ago

FYI, there's work already going on for direct modeling in FreeCAD at https://github.com/MariwanJ/Design456
Maybe a student can join the effort ?

/cc @MariwanJ

MariwanJ commented 3 years ago

@Yorik: By parametric modeling : Do you mean that even Direct Modeling should have options, parameters that could be changed live to change the object you applied a command before? Like what you have now in Sketcher? In my understanding, direct modeling will not have any parametric, you apply a command and the object will follow that command .. that is it. You might have some undo-redo but not more. If you think to use parameter to change an object, that would create a huge problem for the project. It is like class-inheritance. if someone, or somehow the base-class changed .. the whole project might fail. Please forgive my lack of knowledge. In all commands I am implementing, I make a simple copy of what I done. So no way to go back a step. I didn't implement yet undo-redo .. but there will be .. More than that will not be possible.

Biggest problem in FreeCAD at the moment for me .. Many object-parameters are read only. So you cannot easily modify them. For example chaining location of a vertex will not be possible if you don't re-crate the object from new vertices . you need to recreate them to be able to change anything. That is what the API tell me .. I might be wrong. First thing to do in this project. Make tools (classes) to let developer use them. Tools that allow developer to modify shapes, vertices and objects. Documented in details. Second thing to mention: Should we stick to CPP or it is ok with python. I have a CPP background but started to use python since it was easier to start with FreeCAD API. Unfortunately, There are so many developers out there that make a different functionalities, but but it is totally fragmented .

yorikvanhavre commented 3 years ago

You approach seems good too, it's mostly a question of deciding how one wants to do things. There is basically no right or wrong here I think. Indeed tying strictly to parametric model has drawbacks too (slower approach, maybe ends up in a "half-baked direct modeling"), But the current API can be extended too. Having "movable vertices" is possible too, look at the Draft Wire/polyline for example. It's just a matter of how you design things.

MariwanJ commented 3 years ago

Yorik: You are an experience FreeCAD developer. Please answer my question regarding if I stick to CPP or Python? I have a feeling that it would be difficult to make all these bases/changes using python .. at least it will be slow somehow.

luzpaz commented 3 years ago

If you use cpp and want people to test, then we'll need to figure out how to compile FC test builds for people to use. Most won't know how or not want to because of the amount of time it takes to compile FC.

yorikvanhavre commented 3 years ago

Please answer my question regarding if I stick to CPP or Python?

Basicallyit does not make big difference... It it more a question of your own preference, what you are most comfortable with. Almost anything can be done in either language. If you are thinking of doing this in a separate addon/workbench, though, then working in python is an advantage, as your code can be distributed "as is", no compiling/packaging necessary.

yorikvanhavre commented 3 years ago

In my opinion there is no need to touch the TopoShapes themselves. You would be reinventing the wheel, which is already well enough done by OpenCasCade.

I think this is mostly an UX job, not a geometry job. What we need is to think a system of how a person can interact with a shape (ex: move a vertex, move an edge, move a face, scale an edge, scale a face, rotate an edge, rotate a face, extrude/intrude a face, extrude several faces, move several vertices/edges/faces, cut through/divide a face, the list can be endless), and define UI tools that provide a nice UX experience to the user to perform these things. That is, define the steps of what the user does, what they see, what they can do next, etc. and implement the needed coin workflow (manipulable widgets, etc) That's 99% of the work. Recreating the object itself is 1% of the work (OK maybe I'm exaggerating a bit ;) ), and IMHO it's no big deal to have the tool recreating the object, and it's overkill to re-imagine a whole geometry system just for that, when we have a fairly good one already.

But of course all this is just my vision, basically it is how I would myself approach it. Any research is always a benefit, so pursuing another way is absolutely no wasted effort, if you are interested in doing it that way.

yorikvanhavre commented 2 years ago

This is still valid for GSOC 2022. One should have a look at other attempts and maybe joint forces:

This issue on FreeCAD: https://github.com/FreeCAD/FreeCAD/issues/5764

KeithSloan commented 2 years ago

"What we need is to think a system of how a person can interact with a shape (ex: move a vertex, move an edge, move a face, scale an edge, scale a face, rotate an edge, rotate a face, extrude/intrude a face, extrude several faces, move several vertices/edges/faces, cut through/divide a face, the list can be endless)"

Given that this project is defined as Hard and the above long list of interactions, how about starting with a sub project namely interacting with Part2DObjects https://wiki.freecadweb.org/Part_Part2DObject

Once the foundations of interacting with 2D objects is established then things can then progress in the fullness of time onto the full gambit of Shapes and the multitude of possible interactions

i.e Initial phase add support in FreeCAD for

Then could update the Curves part of the Curves workbench to have editable curves, this could be done without the need to recompile FC.

A follow on step could be Surfaces following a similar approach.

I feel the above would make for a more containable project with a useful end point

MariwanJ commented 2 years ago

@KeithSloan This is not anything bad for what you wrote or against anything/one, but it is the reality of FreeCAD. This is MHO. It is easy to describe what we should do for making direct modeling achieved. But the reality is the OCC is not capable to do so. It is very slow, and full of bugs. I made several tools and those tools are suffering from the slowness of the OCC and FreeCAD. Several times I described how we can try to introduce other things to FreeCAD but the freecad community are not interested in direct modeling. Alone, I was trying to talk the forum for finding other way of thinking.. the result is nothing. So, it is not possible to make what you described simply because freecad cannot do direct change in objects due to the internal structure for both freecad and OCC.

If you read about 3D Wings you understand the principle used there to achieve the direct modeling they have.

For every little change you do in freecad, you have to redraw the whole thing. In normal Windows/X server GUI , often you have to limit the area you are redrawing/recalculating. That is not possible for OCC or FreeCAD. I have a test that I just collect some 3D models in a Fusion object. It becomes so slow after some 30 pcs that is not responsive any more as it should... only a Fusion nothing complicated. I have a video about that.

Without real change in the way FreeCAD made, real direct modeling is no just hard, it is impossible. Look at and use my tools and my videos, you will see the difficulties. It is almost a year I am trying to work on this project, still I am along .. no one wish to come to the project. hope I answered your comment. Google summer will results in nothing to be honest.

KeithSloan commented 2 years ago

@MariwanJ I have in the past had a brief look at your Design456 Workbench. I think it is brave attempt at Direct modelling but I am not sure your about your approach of trying to enable manipulation via OCC.

@yorikvanhavre Makes second item in details is "Get familiar with Coin, FreeCADs 3D display manager, and understand how to create manipulators and interact with the 3D scene" i.e Looking at implementing Coin facilities to enable manipulation.

Some time ago I added an issue to the Curves workbench seehttps://github.com/tomate44/CurvesWB/issues/59 asking for the ability to edit curves the response "Making the interactive feature is not an easy task with Pivy. @joelgraff made the pivy_trackers library that looks great. I did a couple of tests but was not able to use it properly, unfortunately."

I think Joels tracker is used in the Civil Engineering workbench Trails perhaps @joelgraff and @HakanSeven12 could comment.

@MariwanJ "It is almost a year I am trying to work on this project, still I am alone .. no one wish to come to the project. hope I answered your comment. Google summer will results in nothing to be honest."

Which re-enforces my view that this needs to be tackled as a small subset, my suggestion being just manipulation Part2DObjects.

SMALL STEPS and SMALL BEGINNINGS

joelgraff commented 2 years ago

pivy_trackers works, but it's a bit complicated. And I've just not had time to really work on it lately. That said, I have managed to make it work as a real-time curve adjustment tool for horizontal highway alignments in Trails. Python is just good enough as a scripting language to keep up with the demands, but I think I'm really pushing the limits, here - it really ought to be compiled.

My goal was to create a visualization framework to prototype engineering tools - a way to provide immediate visual feedback during engineering design processes, rather than adjusting parameters, applying changes, and watching to see how the geometry updates. If there's interest in implementing it in a specific context, I'm open to that, but I don't promise it'll be quick or easy.

MariwanJ commented 2 years ago

Regarding coin, I made many detailed steps how to use it and I have the widget system FR_WIDGET. But I don't like the idea to use coin. That makes my code too complex with a gain of nothing. You wouldn't be able to replace OCC as you need to redraw the shape each time you change the (face, vertex, edge) .. just not possible. For very basic shape, I managed to replace OCC with coin .. but that is far from being used properly .. and works only on planer shapes.

Newer 3d library is essential and a better way of representing objects in 3D world is also a MUST. I described my idea at the forum .. no one replied that post and for that reason .. there is no way to do that thing by a person. You have to take that idea.. you shouldn't redraw the whole screen because of a change that is made on one object. If you are careful in looking at other CAD program (for example DesignSpark Mechanical) you will notice that internally they keep the (cylinder, box, ..etc) as it is .. but they draw the results not the primitive objects. As soon as you click the object, they draw the basic shape behind that part or face. Any external library will fail since FreeCAD will "never" included and your project will not reach users. That is why I am kinda rejecting including other library without been added to FreeCAD core.

KeithSloan commented 2 years ago

Question - With a Sketch I can create a BSpline and I can edit it by pressing the Ctrl key and selecting a Control point which I can drag around and the curve changes in realtime. Okay this is 2D but how is the Sketcher workbench implementing this?

MariwanJ commented 2 years ago

Each time, it must recreate the whole thing. There is no other way to do so. Think if you have hundred of objects, and OCC is slow? it wouldn't work.

KeithSloan commented 2 years ago

Well it does not appear to redraw the other lines in the sketch, just the BSpline being manipulated.

luzpaz commented 2 years ago

An aside,@realthunder was talking about Coin3D in foss4g. I don't recall if it was for replacing or augmenting the coin3d library? Perhaps he can weigh-in?

realthunder commented 2 years ago

It is to augment Coin3D. I'd like to keep the node construction and iteration part of Coin3D, but replace its rendering backend with some third party library. The current design of Coin3D rendering backend is too tightly coupled with the rest. I managed to use its SoCallback interface to replace its render caching entirely and perform rendering with my own code. Although the rendering is done using only OpenGL 2 which is more or less the same as Coin3D, there is already big performance gain for large assembly.

The most critical part for improving the rendering performance is actually the rendering cache. In CAD particularly, where the assets are dynamically created and prone to changes. The cache must be able to reuse as much as possible but can still perform incremental update efficiently. Using third part library makes it easy to leverage on modern graphics API. Apart from giving us more eye candy, ultimately, for a CAD system, it is to help improve caching, like instance rendering, etc.

OCC boolean operation is no doubt slow in non trivial cases, but we can work around it by showing partial result. Like what I've done with PartDesign right now, for almost all features, you can preview only the tool shape while editing instead of the final shape. We can even explore possibility to run OCC and rendering in different CPU cores.

BTW, I am very much interested in direct modeling. But I think the rendering part is more important at the moment, which is what I'd like to work on first. Actually, there are two not quite related aspect of direct modeling, one is the push pull UI, and the other is the much more difficult feature-less/history-less direct shape manipulation like those in Fusion 360 and SolidEdge. I'm assuming we are talking about the first aspect right now, although I'm interested in both.

aothms commented 2 years ago

I'm not really involved in FreeCAD, but I feel the urge to comment as well:

Even if it turns out direct modelling on top of OCCT is slow for interactive use. There might be cases where it might still make sense in programmatic use. For example. I'd like to have the option to snap the second operand geometry onto the geometry of the first operand prior to performing a boolean operation (giving more local control, as an alternative to the global fuzziness). I can imagine that out of this project a good API originates that could be used for that purpose. Like ShapeBuild_ReShape but with a more geometric focus.

Yes, OCCT can be slow, but it might be that certain bottlenecks can be eliminated with caching or a more efficient higher level data model (Maybe Part already provides some of that, sorry I don't know). For example, for calls like OuterWire one might naively assume it's like a constant time operation that just reads a flag or something. Where in fact it does a full geometric check for containment of a point infinitely far away for every wire in the face. If the bottlenecks are known I think that with an intermediate data structure on top of TopoDS it may be possible to provide a more efficient and more user friendly API for this purpose. Same for ancestor and sibling lookup, they can probably be stored directly and with the assumption of a manifold valid data structure certain shortcuts can be made in terms of retrieval.

KeithSloan commented 2 years ago

I think @MariwanJ is in danger of throwing out the baby with the bath water. I see Wings3D in the same category as Rhino https://www.rhino3d.com and to a certain degree Blender. If the only way to achieve direct modeling is a root and branch redesign of FreeCAD then maybe people should be puting their efforts into enhancing Blender, Wings3D. I think @yorikvanhavre has developed a FreeCAD importer for Blender(?)

brlcad commented 1 year ago

FreeCAD is now participating as their own GSoC org, congrats!

MariwanJ commented 1 year ago

@KeithSloan COIN3D is a dead project, OCCT is kind a closed way (no fix is expected).. so no hopes there at least for now. I tried to find a way to inject OpenGL (modern) into COIN3D, but no .. it is not possible. The only thing remained for me is try to bring Wings3D to freecad. But the problem is Wings3D is written using a such horrible language that you cannot bring it so easy. And also is based on very old OpenGL. I tried to use FLTK, I faced also a lot of problems. Wasn't easy. It is a rabbit hole. I now try to make the conversion using ImGui. Nothing is easy. Design456 based on OCCT and COIN3D is almost dead because of all difficulties I faced for direct modeling. FreeCAD because of OCCT is veryyyyy sloooooow. And direct modeling is about quickly movements .. so that is not a good combination. in short, no direct modeling is possible without using MESH and using OpenGL (modern) or Vulkan.

tritao commented 6 months ago

Hey @MariwanJ, just came across this comment.

I tried to find a way to inject OpenGL (modern) into COIN3D, but no .. it is not possible.

I have a work in progress fork of Coin3D where I have updated the rendering to more modern OpenGL context with shaders. Do you think it could be useful for your work on direct modeling? Would be happy to discuss more about what you need.

MariwanJ commented 6 months ago

Hey @MariwanJ, just came across this comment. Hi, Thanks. I explained at different occasions what the problem is with FreeCAD for direct modeling. It is the engine. I am not sure if COIN3D is so fast that can be used in mesh manipulations. What I need is to have a working, multi-threaded mesh manipulator platform. That is what I am trying to achieve with Design456App. Not sure if Coin3D can do that. It is also complicated for no reason. Another thing that I am not sure how to achieve is targeting mesh structure. I mean finding edges, faces ..etc based on selection. Cut, join, ..etc of faces, mesh elements .. all that stuff. Basically, you need a good, multi-threading manipulator of mesh to achieve direct modeling on mesh not OCCT. Without working on mesh, direct modeling is not possible for FreeCAD. Not sure how you can modernize COIN3D. seems to be a lot of work. BR

yorikvanhavre commented 6 months ago

This issue is now happening on the FreeCAD repo at https://github.com/FreeCAD/FreeCAD/issues/5764 Please continue the discussion there instead!