Mesh Remodel workbench

Info about new community or project announcements, implemented features, classes, modules or APIs. Might get technical!
PLEASE DO NOT POST HELP REQUESTS OR OTHER DISCUSSIONS HERE!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
madcello
Posts: 48
Joined: Fri Apr 22, 2022 7:00 pm
Location: Portugal, Arraiolos

Re: Mesh Remodel workbench

Post by madcello »

Thank you for this tools. Very handy!

P.S. there's a Blender add-on called MESHmachine that seems to identify flat faces and, more important, "curved" faces (several faces that represent a curve of some kind) by selecting them.

If would me amazing to have this kind of tools to identify flat areas (turning several planar touching faces into a single freecad Toposhape), or several "curved" faces into a curved freecad Toposhape.

Is this possible?
Learning is a passion.
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Mesh Remodel (v1.9.7)

Post by TheMarkster »

New update:

I've been working on this workbench, adding some new features, in particular features for working on mesh objects to try to repair them.

New features:

* Move a point (moves a point in a mesh object, the facets change with the moved point).
* Remove a point (removes the point and all facets attached to it).
* Add or remove facet(s)
* MeshExpander

The MeshExpander tool creates a new Mesh::FeaturePython object that claims as a child in the tree the original mesh object. You use the expander tool in conjunction with a plane to define where to begin the expansion. Here is a screenshot:
mesh_expander_scr1.png
mesh_expander_scr1.png (181.91 KiB) Viewed 1342 times
In this simple example a mesh object has been expanded. The datum plane defines the plane for the expansion. The original mesh was created with Netgen. Notice how the facets are much different at the expansion. The MeshExpander object is parametric, meaning you can alter the expansion later and it will recompute itself. It is also parametrically bound to the original, so changes to that object would also propagate to the MeshExpander. But it's not parametric to the location of the plane. Edit the Base and Normal properties of the MeshExpander object directly to change the plane location and normal. You can expand in both directions, normal to the plane and the opposite direction from that, but you can't collapse the mesh or else you will get self-intersections.

Adding and removing facets works great for repairing defective mesh objects, but it can become tedious if there are many facets to replace. The add/remove facet tool can add multiple facets in one go. Select first the anchor point, which will be part of all of the facets created in this operation. For example, if you select p1, p2, p3, p4, and p5, and then run the command, p1 becomes the anchor point and you get these new facets (p1, p2, p3); (p1, p3, p4); (p1, p4; p5).
Snip macro screenshot-78fac6.png
Snip macro screenshot-78fac6.png (161.25 KiB) Viewed 1342 times
In this screenshot below the facets were created to close the end of this cylinder in this manner. It could be better to add a new center point and use that for the anchor in many cases, to avoid any self-intersections. Like in the screenshot below:
Snip macro screenshot-7979a4.png
Snip macro screenshot-7979a4.png (140.93 KiB) Viewed 1342 times
Usage: select the mesh object, create a new points object (or alternatively a wireframe object). This gives you selectable points to work with since FreeCAD can't select subobjects in a mesh. The points object serves as a proxy for the points on the mesh object. Then select the points that define the facet to add or remove. Some modifier keys are supported:

Click = add the facet
Ctrl+Click = undo the last command (if it was add a facet) and add the facet again, this time with the normal flipped
Alt+Click = remove the facet (you can only remove one facet at a time, but you can add multiple facets at a time)

When you are adding facets, the normal direction of the facet depends on the order of selection of the points. Sometimes the facet has its normal flipped the wrong direction, so when that happens, and with everything still selected Ctrl+Click again on the toolbar icon to flip the facet's normal.

Tip: when adding facets you can use Ctrl+Select to deselect an already-selected point and Ctrl+Select to select a new one. This can save you a few clicks while adding new facets. Then Click the toolbar to add the face, and Ctrl+Click again immediately if you need to reverse it. (But don't Ctrl+Click the first time when adding the facet unless you know for sure this will put it in the correct direction because Ctrl+Click again will just redo the same flipped normal and clicking without Ctrl again would add a new facet on top of the reversed one, which is a no no.)

Edit: above was removed because it was too complicated. New process is:
Click = add the facet
Alt+Click = remove the facet (or use Undo if it's a previously added facet with a flipped face)
Ctrl+Click = add the facet with the normal flipped the other way

Moving a point is easy. There is a dialog that allows to input the normal distance, for moving the point along its normal vector, in addition to the usual x, y, z coordinates.

Usage: select the point to move and the mesh object, click the move icon. Up comes the dialog.
move_point_scr1.png
move_point_scr1.png (38.76 KiB) Viewed 1342 times
Notice in this screenshot there is a red dot. This is a "Ghost" object that will be deleted when the dialog is closed. It shows a preview of where the point will be. Be careful in moving points because it often introduces self-intersections or folds on surface issues. You can use Undo to undo any of these tools.
Last edited by TheMarkster on Sat Dec 23, 2023 5:45 am, edited 1 time in total.
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Mesh Remodel workbench

Post by TheMarkster »

When moving a point you can also do it by selecting a 2nd point, which will be the new location for the first point, skipping the dialog. This can be useful where two points are too close together or where the facets are not quite meeting at that point.

Deleting a point also removes all the facets that were connected to it, but moving it to another point will merge those facets.
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Mesh Remodel workbench

Post by TheMarkster »

New version 1.9.8

Changes: add support for clicking edges to add or remove facets. Instead of creating the points object you can create a WireFrame object and use edge selection for this purpose. Edges are much easier to select and you only need 2 edges to define a facet whereas you need 3 vertices.

Note: only 1 facet may be removed at a time. You can add multiple facets, but only 1 can be removed (unless you use Undo to remove multiple facets recently added in the previous undo document transaction).

Other change: simplify removing flipped normal facets by removing the Ctrl+Click to undo and add back flipped in the same step. That was too complicated. Now the process is Alt+Click to remove the facet, Ctrl+Click to add it flipped.
HoWil
Veteran
Posts: 1279
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: Mesh Remodel (v1.9.7)

Post by HoWil »

TheMarkster wrote: Fri Dec 22, 2023 11:34 pm New update:
...
* MeshExpander
Nice... Until now I did exactly such an expansion of a complicated mesh with blender (the mesh was a part of printable headphones https://www.print.plus/download). In FC the mesh import and afterwards Part-wb->"Create shape from mesh" did not work out.
The import works but the created shape is hard to work with. I remember that FC crashed after I tried to cut the shape in Part-wb.

In Blender you basically have to learn how to select e.g. half of the nodes and how to move them. It is not difficult if you know to do it :lol: :roll: .

MeshExpander did work out! Thanks :!:
Minor note.... I takes several seconds to create the expanded shape. Why is that? Is the transfer from mesh to shape done every time in the background? Is there still some room for improvement?
Screenshot from 2023-12-29 17-32-53.png
Screenshot from 2023-12-29 17-32-53.png (209.56 KiB) Viewed 1151 times
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Mesh Remodel workbench

Post by TheMarkster »

It is possible some further optimization could be done to speed things up. I had included a progress bar, but this was crashing FreeCAD when running it inside the execute() function of the feature python object due to some recursion limit getting exceeded, so I had to do away with it. It might work to do the expansion algorithm outside of the execute() function, but I didn't try that yet. Progress bars will actually slow things down because processing the progress bar is itself another computation that must be done inside the loop, but at least with a progress bar the user is reassured that the process is still ongoing and progress is being made. And there is usually an option to abort.
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Mesh Remodel workbench

Post by TheMarkster »

Latest version: 1.9.21

Latest feature: Go back selection

Reverts back to the previous selection state. For example, suppose you have selected 38 out of 39 points or edges or faces for some operation, and then a misclick causes the selection to clear. You can press the toolbar icon to get back to the previous state where the 38 subobjects are selected again.

You can use keyboard modifiers: Ctrl, Alt, and Shift to increase the number of selection blocks to skip. Each modifier adds 1 to the amount to skip. For example:

Select a bunch of edges, then click in empty 3d space to clear the selection.
Select a bunch of faces, and then click again in empty 3d space to clear the selection.
Click on the icon = go back 1 selection state to the faces being selected.
Ctrl+Click on the icon = go back 2 selection states to the edges selected.

Which modifier you use doesn't matter, and they can be combined in any order, so Ctrl+Alt+Shift+Click = go back 4 selection states.

Note: clicking multiple times does not go back multiple states. You must use the modifier keys for that.

Details. This is implemented by simply parsing the selection history maintained in the python console as comments whenever the selection changes. Clearing the console would erase the history. The command itself alters the history because the selection change it makes gets also added to the console, so this is cleared as a QTimer.singleShot() event 0.25 seconds after you click the icon. It's a bit of a hack. Don't multiple click rapidly or else it could mess things up if the next click comes before the previous console selection comments can be cleaned up.
Post Reply