gradientspace / geometry3Sharp

C# library for 2D/3D geometric computation, mesh algorithms, and so on. Boost license.
http://www.gradientspace.com
Boost Software License 1.0
1.68k stars 379 forks source link

Create one of several mesh #16

Closed KisliPlug closed 6 years ago

KisliPlug commented 6 years ago

temp_write.zip Hi, thanks for the library. Everything works fine but on some complex objects I have to break objects into flat mesh making up complex geometry to further translate them into the format of your library, but after such manipulations the simplification does not work whether it is possible to make one of several meshes in 1 or perhaps there are nuances for flat mesh .

flatten.zip

rms80 commented 6 years ago

sorry, I don't 100% understand what you are asking. I'm not sure what you mean by "flat mesh" - do you mean this was originally a curved patch, and you have to convert to triangles?

KisliPlug commented 6 years ago

I've attached an example of a fragment that can not be simplified and an entire geometry, you can see it in here https://3dviewer.net /. I mean the geometry of a facet of an object.

rms80 commented 6 years ago

yes i looked at the attachment. I don't understand what your question/problem is.

KisliPlug commented 6 years ago

I can not simplify with the help of Reducer, such parts, whole meshes are normally simplified, and such fragments not , I wanted to clarify whether it is possible to merge such fragments into a one mesh, or to find out the reason why this method does not work. I'm using the following code for simplify : var red = mn.Select(x => new Reducer(x)); foreach ( var r in red ) { r.SetExternalConstraints(new MeshConstraints()); MeshConstraintUtil.FixAllBoundaryEdges(r.Constraints, r.Mesh); DMeshAABBTree3 tree = new DMeshAABBTree3(new DMesh3(r.Mesh)); tree.Build(); MeshProjectionTarget target = new MeshProjectionTarget(tree.Mesh, tree); r.SetProjectionTarget(target); r.ProjectionMode = Reducer.TargetProjectionMode.Inline;

r.ReduceToTriangleCount(200);

} mn = mn.Select(x => new DMesh3(x, true)).ToList();

rms80 commented 6 years ago

So you are trying to reduce the attached fragment with this code? It won't do anything, there are only 112 triangles (you are trying to reduce to 200).

If you want to connect up the borders of a bunch of fragments, it depends on whether the boundaries match. If they do not, this is a very hard problem, I would suggest trying Make Solid in Autodesk Meshmixer, with repair turned off. If they do line up, DMesh3.MergeEdges() will let you join pairs of edges, but you will have to match them. Alternately you can construct a unique vertex map and then rebuild the mesh w/ the vertices shared. A quick-and-dirty way to do this is just to write it out as an STL and read it back in, the STL reader does this internally.

KisliPlug commented 6 years ago

This fragment is for example, and in this case (200) nothing will happen, but if you make 50, it will still not happen and the number of triangles will be the same. Thank you, I will try to follow your advice.

rms80 commented 6 years ago

none of the triangles are connected (blue edges are border edges): image

So when you do MeshConstraintUtil.FixAllBoundaryEdges(), it tells the reducer it cannot modify any of the edges.

use the write/read STL thing I mentioned and it will work, at least for an individual patch.

KisliPlug commented 6 years ago

Thank you, I will use your advice!

KisliPlug commented 6 years ago

And to unite these faces without re-export is possible? The point is that when I load such fragments, I get an error, maybe I can recreate a grid from a set of meshes and triangles?

rms80 commented 6 years ago

If you look at STLReader.BuildMesh_IdenticalWeld, you will see that the way it is done is quite simple to reproduce directly on a DMesh3. Just build a hash table of vertices, assign each a unique ID, and use that to remap the triangle IDs

KisliPlug commented 6 years ago

Thank you