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!
TheMarkster
Posts: 1055
Joined: Thu Apr 05, 2018 1:53 am

Mesh Remodel workbench

Postby TheMarkster » Tue Aug 20, 2019 12:27 am

Can be installed via the AddonManager in Tools menu -> AddonManager if you have a very recent build. In the AddonManger click Configure, then add https://github.com/mwganson/MeshRemodel to the list of custom repositories. After restarting the AddonManager you should find MeshRemodel in the list of workbenches you can install.

Full documentation is at that url.

This workbench is for helping in remodeling a mesh object into a native FreeCAD object. The general workflow is to select the mesh object in the tree, then click the create points tool to create a points object, then use these points as references for creating elements, such as lines, polygons, circles, arcs, and bsplines. These elements can be created directly in the 3d view using the points as references. For example, select 2 points, then click the create line tool to make a line between those 2 points. Select 3 points, then select the create circle tool to create a circle or an arc. Once you have enough elements created to form a continuous wire, you can select the elements then use the create wire tool (which uses Draft.upgrade) to connect them into a single wire object. Once you have all the wires created for a sketch, select them in the 3d view, and click the Create sketch tool to make a sketch (uses Draft.makeSketch()). For convenience there is also a merge sketches icon, which uses the Sketcher merge sketches tool.

There is a tool to filter the points into only those that lie on a single plane. To do this select 3 points, the click the create coplanar points object tool to create a new points object containing only those points that are coplanar with the 3 selected points. This object is a compound of Part Points, which is automatically exploded. Press Undo (Ctrl+Z) if you would prefer it to not be exploded. The advantage of the exploded form is you can use block selection (Shift+B, draw rectangle) to select multiple points simultaneously. For example, use block select to select points in a circle, then click the make circle tool to make the circle. Tools that support block selection at this time: bspline, circle, polygon.

The polygon is actually a compound made up of lines. This is done as a separate document transaction, meaning if you click Undo (Ctrl+Z) after making a polygon you will get the individual lines as separate objects. This can be useful where you would like to delete some of the lines individually.

This workbench is still under construction, but I think it's at the point where it's usable. Here is a video demonstrating the remodeling of a very simple imported mesh.

phpBB [video]


The element creation tools are compatible with any selected points. For example, you could select points from a sketch (not in edit mode), from a cube, etc. and use those selected points as references for making lines, polygons, circles, arcs, and bsplines. So, it can potentially be of use even outside the context of remodeling a mesh.

If you prefer to model inside the sketcher you could use the points objects as links to external geometry. One advantage of working outside the sketcher as I did in the video is I can now delete all of the points objects and elements because there are no dependencies like you would have using links to external geometry, as seen in this screenshot of the dependency graph:
Snip macro screenshot-51ab4e.png
Snip macro screenshot-51ab4e.png (40.95 KiB) Viewed 859 times
The only dependencies the extrude objects have is to the sketches, which have no outside dependencies.

Using keyboard shortcuts, the work can go quite fast for these circles. Shift+B to go into block selection mode, draw rectangle to get at least 3 of the points selected, then Alt+R,Alt+C to make the circle.

Here is another video demonstrating how to connect arcs and lines into a profile.

phpBB [video]


The polygon (inner square) had some missing coincident contraints in the sketch. This wasn't an issue when I was making the polygons as single entities, but I switch to making them out of individual lines, then compounding them into a single compound. The reason for the switch is to be able to press Undo (Ctrl+Z) to get at the individual lines for deleting them individually. Edit: polygons missing coincidences is now solved in version 1.21.

It is also possible to create the outer profile as a bspline by selecting all the points, but I would prefer to have arcs in this case for easier editing in the sketcher. The bsplines can be useful where you have an ellipse in the mesh. I haven't worked out the math for getting an ellipse out of 5 selected points yet, and probably won't bother continuing since the bspline seems to work quite well. In such a use case you would want to use block select mode because there are likely to be quite a few points to select, which would be tedious to do one at the time. The problem with block select is the ordering of the points becomes crisscrossed, so if you just make the bspline (or polygon) you get crossed lines. Therefore I have a sorting algorithm built in to sort the lines. Alt+Click to use this sorting on bsplines and polygons.
pablogil
Posts: 747
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

Re: Mesh Remodel workbench

Postby pablogil » Thu Aug 22, 2019 10:05 am

It seems very interesting for inverse engineering, thanks!

Are you improving somehow in order to add new functionalities, improvements or automation?
Dark and Light stylesheets v2.0 to theme your FreeCAD UI, more information here
TheMarkster
Posts: 1055
Joined: Thu Apr 05, 2018 1:53 am

Re: Mesh Remodel workbench

Postby TheMarkster » Thu Aug 22, 2019 5:58 pm

I would like to add some automatic features, but I have some other issues that I'm trying to resolve. Sometimes the objects, for example 4+ point polygons, are not coplanar. I think the problem is even though the points from the mesh look coplanar they're really off by some tiny amount above or below the plane. This inaccuracy can be seen with radii of circles that are evidently supposed to be the same. For example with 4 identical holes, all presumably 1.5 mm radius, one might actually be 1.497895, another 1.4989, etc. It's easily worked around by rounding to the nearest 0.1mm, but with points on some arbitrary plane it's not just a matter of rounding the coordinates. If the mesh was constructed on or parallel to the major planes, then it's usually going to work, but if the mesh is rotated or if you have faces that are angles, 45 degrees or whatever, that's when the problem comes in. Floating point numbers are inherently inaccurate due to the way they are stored in computer memory, and when you start rotating, I think it adds to that. The process of converting to and from mesh probably adds to the inaccuracy.

I have my own coplanar test that involves creating a tetrahedron with 4 points and measuring its volume. If all 4 points are coplanar the volume of the tetrahedron will be zero or very close to it. I can set the tolerance for this test to a very small number, such as 1e-7 mm^3, but this usually results in no coplanar points found to create the coplanar points object. Only by increasing the tolerance to 1e-3 do I get all the points I can see in the 3d view that look like they should be coplanar. Viewing them edge on in the 3d view, they certainly appear coplanar, but often creating a polygon from 4 of the points results in failure in later operations, for example in creating a sketch out of the polygon. I can make a wire out of it, but then extrude fails because the wire is not coplanar. The Draft makesketch() function uses isPlanar() from DraftGeomUtils to test for coplanar shapes, which is much stricter than my internal one if I set the tolerance to where I get usable quantities of points. So in my latest version (not yet pushed to the repo) I have defaulted to using the Draft version for the coplanar test and offering the internal one via modifier keys, e.g. Alt+Click.

Currently, the workaround is to use the points inside the sketcher as links to external geometry and remodel from within the sketcher. This works fine even with coplanar points objects that are not truly coplanar (useful because they filter out points from other planes) because creating links to external geometry automatically ensures the points constrained to those external links are going to be coplanar with the rest of the points in the sketch.

My idea to resolve this is to move the points very slightly in order to ensure they are all truly coplanar. This I would do when creating the coplanar points objects. I have some ideas on how to do this, but need to work out the details and do some experiments. Basically, I need a function that takes 4 arguments, vectors A, B, C and D and returns a new vector for D, one that makes D now coplanar with the plane defined by A, B, and C. But not just coplanar it needs to be the shortest path to the plane. I would then run through all the points in the initial coplanar points list that was created with a permissive tolerance, e.g. 1e-3. I need to look through the source code and try to find some helpful functions for this.

Another idea is to do this by creating a sketch in python and using links to external geometry to the points. Then use coincidence constraints on points added to the sketch in a draft point array of points. I have already a fairly clear idea on how to do this.
User avatar
DeepSOIC
Posts: 6844
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: Mesh Remodel workbench

Postby DeepSOIC » Thu Aug 22, 2019 6:16 pm

Convert the points of a mesh to use them in sketcher? So simple, so nice, so useful. Thanks, that will come in handy I'm sure!
User avatar
DeepSOIC
Posts: 6844
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: Mesh Remodel workbench

Postby DeepSOIC » Thu Aug 22, 2019 6:18 pm

IMO it should be directly added as an option in "create shape from mesh" tool of Part workbench.
kisolre
Posts: 1243
Joined: Wed Nov 21, 2018 1:13 pm

Re: Mesh Remodel workbench

Postby kisolre » Thu Aug 22, 2019 6:30 pm

Do you really need to keep the original points? Some days ago I recreated a STEP file. I used the STEP surfaces/arcs/edges as external geometry through shapebinder but afret recreating the sketches added reference dimensions to, removed the external geometry and turned reference dimensions to real ones. So in the end nothing of the original STEP geometry is used in the final model.
My point is just project the points/arcs/circles/... on the desired plane and use those.
TheMarkster
Posts: 1055
Joined: Thu Apr 05, 2018 1:53 am

Re: Mesh Remodel workbench

Postby TheMarkster » Thu Aug 22, 2019 11:16 pm

I tried a number of ways to resolve the coplanar issues I was having with some polygons, but failed. I tried putting the points into a sketch filled with links to external geometry, and the making an array of Part Points with draft points array. This I did manually in the GUI as a test. The polygon created remained non-coplanar. I tried moving the points slightly in python to force them into alignment using projectToPlane() function, but that also failed. I believe the points were lined up properly. I did verify in the debugger that the points were getting moved very slightly.

In the end I opted to just recommend using the sketcher with the points as links to external geometry. The create coplanar object tool now creates an empty sketch and fills it with external geometry links to all the points in the plane defined by the 3 initially selected points. Now at least the tedious step of adding links to external geometry is avoided, albeit at the expense of perhaps having more than you wanted or needed.
pablogil
Posts: 747
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

Re: Mesh Remodel workbench

Postby pablogil » Fri Aug 23, 2019 8:19 am

DeepSOIC wrote:
Thu Aug 22, 2019 6:18 pm
IMO it should be directly added as an option in "create shape from mesh" tool of Part workbench.
+1
Dark and Light stylesheets v2.0 to theme your FreeCAD UI, more information here
TheMarkster
Posts: 1055
Joined: Thu Apr 05, 2018 1:53 am

Re: Mesh Remodel workbench

Postby TheMarkster » Sat Aug 24, 2019 4:07 am

https://github.com/FreeCAD/FreeCAD/pull/2450

I added it as a separate command from create shape from mesh. Should they be part of a submenu instead? The icon has the points of the cube, but the points don't really show up too well. I'm not good with icons. Inkscape and I just don't get along.


phpBB [video]
User avatar
easyw-fc
Posts: 2613
Joined: Thu Jul 09, 2015 9:34 am

Re: Mesh Remodel workbench

Postby easyw-fc » Sat Aug 24, 2019 6:08 am

Kunda1 wrote: ping
Would be possible to add this WB to the FC Addons list?