gradientspace / geometry3sharp Goto Github PK
View Code? Open in Web Editor NEWC# library for 2D/3D geometric computation, mesh algorithms, and so on. Boost license.
Home Page: http://www.gradientspace.com
License: Boost Software License 1.0
C# library for 2D/3D geometric computation, mesh algorithms, and so on. Boost license.
Home Page: http://www.gradientspace.com
License: Boost Software License 1.0
In a lack of a real documentation, I think it's easier if I ask here;
Edit: found some hints of "BuildMesh_TolerantWeld" and "BuildMesh_IdenticalWeld" in STLReader.cs. From a quick glance, that would have the same issue of not keeping UVs / Normals.
I want to apply this project to make Mesh of 3D hands model in Unity, for VR .After I try to do it,it seems that those codes are not the whole project for Unity ,so I would like to know how to do with it.
one graduate from Shanghai University ,China
I'm working on a plane mesh. 128-cell square rectangle, with cell also squares. I build the mesh procedurally, using DMesh3. Upon built, I want to reduce the triangle count, by merging adjacent cells with same height (Y axis). Looking at thr reducer, it doesn't seem operable on such simple case. Just want to confirm am I correct?
Hi,
First I explain my problem.
I have a .png binary image.
I would like to create a mesh out of it where x and y is defined by the image and the depth is costant. What I have achieved is creating a mesh where every pixel is a little cube of constant depth.
This lead to a very huge ammount of cube, so I tried to use the reducer to diminish the number of triangles/vertex. Unfortunately the result is not what I expected since some cube are removed leaving some blank space betweeen the cube.
So my question is: there is a better approach to this problem?
I found some extrude function that could help me but I don't know how to pass the .png point to it.
Do you have some suggestion?
Thanks for your time
Andrea
:) Feel free to close this - just curious what your strategy is.
I think there's a bug in the tube generator capping because it caps in the following incorrect way:
Also, the incorrect (red) vertex color is typical, although it doesn't happen on the far end side.
var profile = ... a semicircle
var path = Polygon2d
.MakeCircle(innerRadius, steps)
.Vertices.Select(n => new Vector3d(n.x, 0, n.y))
.Take((int)(steps * 0.88f))
.ToArray();
var tubeGenerator = new TubeGenerator
{
Polygon = profile,
Vertices = pathVertices,
Capped = true
};
I am trying to integrate g3Sharp into Unity3d. I want to extract Boundary Edges of a Unity mesh. for now i am using Unity's cube primitive. I used the following method:
IEnumerable edges = startMesh.Edges ();
IEnumerator edgeEnum = edges.GetEnumerator ();
List boundaryEdgesList = new List();
List UniqueBoundaryEdgesList = new List ();
for (int i = 0; i < startMesh.EdgeCount; i++) {
// Debug.Log ("BEdge");
edgeEnum.MoveNext ();
if (startMesh.IsBoundaryEdge (i)) {
boundaryEdgesList.Add (startMesh.GetEdge (i));
// Debug.Log ("BEdge : " + i);
cnt++;
Debug.Log (edgeEnum.Current);
}
}
cnt = 0;
foreach (Index4i edg in boundaryEdgesList)
{
if (cnt == 0) {
UniqueBoundaryEdgesList.Add(edg);
}
else
{
bool matchd = false;
foreach(Index4i edgy in UniqueBoundaryEdgesList)
{
if (edgy.c == edg.c)
matchd = true;
}
if(!matchd)
UniqueBoundaryEdgesList.Add(edg);
}
cnt++;
}
//Debug.Log (edg);
line.positionCount = UniqueBoundaryEdgesList.Count;
cnt = 0;
foreach (Index4i edg1 in UniqueBoundaryEdgesList)
{
line.SetPosition (cnt, (Vector3)startMesh.GetVertex (edg1.a));
cnt++;
line.SetPosition (cnt, (Vector3)startMesh.GetVertex (edg1.b));
cnt++;
Debug.Log (edg1);
}
What i am trying is get the edge count first, then check for boundary edges, its a shared mesh, so repeated edges are coming, so i checked for the repeated edges and get the 12 edges only. But the result is with "Inner" edges also. I draw Lines using LineRenderer above the edges of the mesh. could you please give me a solution for this or correct me my mistake in this code.
Hi Ryan,
I would like to create a tool, in the future, for fixing meshes produced from aerial image reconstruction, e.g. Autodesk 123D, Pix4d or Bentley ContextCapture.
A major issue is to create simple windows on the facades and I have found the stamp tool in meshmixer to be very helpful: Create a rectangle stamp on the window area -> offset a little outward for the windowsill -> extrude the windowsill.
The first thing is the stamp operation, I still have no idea on how to do it. It seems the edge of the stamp is spilt into several segments and of course the intersections between stamp and mesh edges are also considered.
Would you give me some hints on this? And again thanks for this awesome library.
Han
Hi,
I tried your library and it works:) It is supernice.
I tried to convert your mesh to other type of mesh.
Basically what I am trying to do is to pass all vertices and mesh faces from one mesh type to another.
But I noticed that DMesh3 has vertices with strange indexing. For instance if there are 100 vertices their index id can be something like 2000, 0, 281 and etc, the mesh library I am working with vertex id would go from 0,1,2 to 100 sequentially. Therefore I always have to remap indices.
Is there a better way to do below conversion?
//Remeshed cylinder
g3.DMesh3 g3m = make_good_cylinder();
//Converting DMesh3 to Other mesh
Mesh mesh = new Mesh();
//Add all vertices
var vertices = g3m.Vertices();
foreach(g3.Vector3d vec in vertices)
mesh.Vertices.Add(vec.x, vec.y, vec.z);
//Add faces
int[] vID = g3m.VertexIndices().ToArray();
var faces = g3m.Triangles();
foreach(g3.Index3i f in faces)
mesh.Faces.AddFace(Array.IndexOf(vID, f.a), Array.IndexOf(vID, f.b), Array.IndexOf(vID, f.c));
Currently, the OBJWriter supports writing the material only to a file path. Some of us might need the material in memory however so it would be nice if we could write it to a string or something.
I'm currently hacking around this by writing to a temporary file and subsequently reading it into a string. This is of course very inefficient.
Hi!
I am using Unity and I would like to dynamic unwrap a mesh during the game. The problem is that UnityEditor namespace (that contains the only unwrap function) cannot be used in standalone version (.exe).
So I am searching an alternative way to do so.
Since this library works with mesh geometry I searched a function to UV unwrap custom mesh in an automatic way but I didn't found any. I was wondering if this feature is implemented or there is some future plan to do it.
Thanks anyway for the great work.
// [RMS] What to do here? We definitely do not want to add a duplicate triangle!!
// But is silently ignoring the right thing to do?
I'm still figuring my way through the library. But I'd appreciate the library showing my when I did a wrong. So that something doesn't bite me in the ass later .
I am developing cad system: http://notecad.xyz.
Can I use this library in this project (I mean license)?
Is there a source code that I can visually design as a mesh?
(especially C#)
Hi, thanks for sharing this lib.
I am trying to procedurally create some bevels on a cube with the MeshPlaneCut class:
// Unity code below:
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
var mesh = cube.GetComponent<MeshFilter>().sharedMesh;
var dMesh = mesh.ToDMesh3();
MonoBehaviour.DestroyImmediate(cube);
double dist = 0.45;
var cutDirs = new List<Vector3d> {
new Vector3d(dist, dist, 0),
new Vector3d(dist, -dist, 0),
new Vector3d(-dist, dist, 0),
new Vector3d(-dist, -dist, 0),
new Vector3d(0, dist, dist),
new Vector3d(0, dist, -dist),
new Vector3d(0, -dist, dist),
new Vector3d(0, -dist, -dist),
new Vector3d(dist, 0, dist),
new Vector3d(dist, 0, -dist),
new Vector3d(-dist, 0, dist),
new Vector3d(-dist, 0, -dist),
};
foreach (var cutDir in cutDirs) {
var cut = new MeshPlaneCut(dMesh, cutDir, cutDir.Normalized);
cut.Cut();
cut.FillHoles();
}
mesh = dMesh.ToUnityMesh();
var go = new GameObject("result");
var mf = go.AddComponent<MeshFilter>();
mf.sharedMesh = mesh;
var renderer = go.AddComponent<MeshRenderer>();
var material = new Material(Shader.Find("Standard"));
material.color = Color.red;
renderer.material = material;
The problem is that the holes are not filled and there the plane cutter reports that there are only CutSpans and no CutLoops.
Is this a bug or intended behaviour?
Thanks!
Oh, right here is the code for ToUnityMesh() and ToDMesh3():
public static DMesh3 ToDMesh3(this Mesh mesh) {
DMesh3 result = new DMesh3(bWantNormals: true, bWantUVs: true);
var verts = mesh.vertices;
var tris = mesh.triangles;
var normals = mesh.normals;
for (int i = 0; i < verts.Length; i++) {
result.AppendVertex((Vector3d) verts[i]);
result.SetVertexNormal(i, normals[i]);
}
for (int i = 0; i < tris.Length; i += 3) {
result.AppendTriangle(tris[i], tris[i+1], tris[i+2]);
}
return result;
}
public static Mesh ToUnityMesh(this DMesh3 dm) {
var result = new Mesh();
List<Vector3> vertices = new List<Vector3>();
List<int> triangles = new List<int>();
List<Vector3> normals = new List<Vector3>();
List<Vector2> uvs = new List<Vector2>();
int[] mapV = new int[dm.MaxVertexID];
int nAccumCountV = 0;
// write vertices for this mesh
foreach (int vertId in dm.VertexIndices()) {
mapV[vertId] = nAccumCountV++;
Vector3d vert = dm.GetVertex(vertId);
vertices.Add((Vector3) vert);
uvs.Add(dm.GetVertexUV(vertId));
normals.Add(dm.GetVertexNormal(vertId));
}
foreach (var triIndex in dm.TriangleIndices()) {
var tri = dm.GetTriangle(triIndex);
triangles.Add(mapV[tri.a]);
triangles.Add(mapV[tri.b]);
triangles.Add(mapV[tri.c]);
}
result.vertices = vertices.ToArray();
result.normals = normals.ToArray();
result.triangles = triangles.ToArray();
result.uv = uvs.ToArray();
return result;
}
i have obj file,i want Split an obj into four block? help me
i load my obj model , invoke r.ReduceToTriangleCount(800); error
my obj model Can you look at it? I have sent it to your mail ([email protected])
help me thank you
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 .
DMesh3[] componentMeshes = MeshConnectedComponents.Separate(builder.Meshes[i]);
System error {{System.OutOfMemoryException}}
Hi there,
I would very much like to use your library in a rather old code base. Would it be possible for you to provide a build for .Net 4.0?
I have downloaded the source and built it myself for .Net 4.0, but for maintainability reasons, it would be lovely to have a 4.0 build through Nuget.
To build it, I had to change line 475 of BufferUtil.cs from
DeflateStream zip = new DeflateStream(ms, (bFast) ? CompressionLevel.Fastest : CompressionLevel.Optimal, true);
to
DeflateStream zip = new DeflateStream(ms, CompressionMode.Compress, true);
I do realize that .Net 4.0 is ancient, so I understand if you would not like to support it, but I figured it was worth asking. Thanks!
Hi!
I have stl which crashes slicer. Issue in with
MeshIsoCurves class, this line:
`
int graph_eid = Graph.AppendEdge(e0, e1, (int)TriangleCase.OnEdge);
if (WantGraphEdgeInfo)
add_on_edge(graph_eid, tid, triEdges[z0], new Index2i(e0, e1));
`
when AppendEdge returns -1, that is DuplicateEdgeID, then next method crashes. Upgrading condition to
if (WantGraphEdgeInfo && graph_eid >= 0)
solves this issue but I'm not 100% positive if this is the right way hence no PR, only issue.
Such as the PCL: http://pointclouds.org/documentation/tutorials/#filtering-tutorial
I am working with large latitude,longitude,elevation point clouds and am trying to generate an encompassing mesh. Totally new area so struggling to get started.
I expect I will need to re project into Cartesian coordinates x,y,z for it to work where do I go from there?
How to group multiple mesh quadtree,help me
I heard boundary edges can be extracted for open meshes only. That means for Non-manifold meshes only? Is it true?
Please clear me.
Thanks.
Hi,
I would to ask if it is possible to get a remesher example?
I am totally new to this library. And would like to create a simple mesh geometry and remesh as a test.
Would you be kind to show how to do this?
Hi, first of all wanted to say thanks for the library, it is very broad and useful. Really enjoying using it. I did notice one minor issue while using Unity that I thought I'd mention. After I normalized a Vector3d it still returned false when calling IsNormalized.
This is not a priority for me as I changed the check of IsNormalized to compare against MathUtil.ZeroTolerancef rather than MathUtil.ZeroTolerance and it is working fine for me although I haven't checked thoroughly if this fixes all cases.
Here are one set of values that reproduced the case,
Vector3d with x, y, z values,
-.90034962
.37379742
-.22281371
gives (x * x + y * y + z * z) of
.9999998987967649
and Math.Abs( (x * x + y * y + z * z) - 1) of
0.0000001012032351
which is greater than 1e-08.
Cheers,
Brian :)
The ObjWriter.Write(...) uses the thread's default culture (and that affects the numbers format ) but i guess that the obj file format should be culture angnostic/invariant.
Hi
Is there a typo in the Vector2d and Vector2f Cross method?
They return (y * v2.y - y * v2.x). I would expect them to return (x * v2.y - y * v2.x)
I read original article and explored code in Reducer.cs, and found that while collecting initial "fundamental error quadric" you are multiply it by area of triangle
geometry3Sharp/mesh/Reducer.cs
Line 243 in 0c84997
summ_p(K_p)
without any respect to the area of defining triangle, can you please explain this? Does this change the optimal point for contraction?
I am new in your library, but it very interesting me for my current unity3d project, so now I am trying evaluated ability to use geometry3Sharp. How can I implement cutting, stretching and boolean operation with 3d meshes using geometry3Sharp? For example, I want to subtract one shape from another, is this possible? Maybe do you have examples or you can advise me class or method name which helps me. Thanks.
How can we visually create meshes?
Hi,
What is the simplest method to create geometry3Sharp mesh from array of floats that represent vertex coordinates and array of face id?
I tried this one below but this produces error:
//mesh variables is other type of mesh so I try convert one mesh to geometry3Sharp mesh
float[][] v = new float[mesh.Vertices.Count][];
for(int i = 0; i < mesh.Vertices.Count; i++)
v[i] = new []{mesh.Vertices[i].X,mesh.Vertices[i].Y,mesh.Vertices[i].Z};
int[][] t = new int[mesh.Faces.Count][];
for(int i = 0; i < mesh.Faces.Count; i++)
t[i] = new int[]{mesh.Faces[i].A,mesh.Faces[i].B,mesh.Faces[i].C};
DMesh3 Dmesh = geometry3Sharp.mesh.DMesh3Builder.Build(v, t,null,null);
Hello!
Can you create good documentation with full list of methods, classes and for what they needs?
Thanks in advance!
StandardMeshWriter writes using current thread culture, which results in data such as
v 461,939769107802 0 -191,341709296824
since I'm located in The Netherlands and my PC's culture uses a comma as a decimal separator.
Obviously, this should be:
v 461.939769107802 0 -191.341709296824
Therefore, I think the writer should use the invariant culture at all times.
Thank you for sharing the excellent library.I have a question about the class MeshLocalParam.When I use the function ComputeToMaxDistance,I don't know what the arguments seedFrame and seedNbrs mean.I chose a random triangle as a seed,for example, tid=1000,but the result is messy after using the material Checkerboard.Do I need to chose a suitable seed for different mesh?
i want one mesh separated into multiple mesh?thank
After some trial and error I figured out that for e.g. subtracting a sphere from a bunny one way is to
That means that whenever I want to move a piece inside of a more complex operation (say, I want to move the sphere around that gets subtracted), I'll have to regenerate the mesh and the SDFs for everything. Is there a way to combine different SDFs together to speed things up? What I'd want to do is this order:
And whenever something changes:
Am I just missing something? If not, consider this a feature request :)
In the following overload, prev
is never updated so the result of the method is incorrect:
geometry3Sharp/curve/CurveUtils.cs
Line 40 in 2502714
I was trying to follow the example you provided for Signed Distance Fields to create a BitMap3 of voxels corresponding to a mesh, but I'm not certain which method I could use. Can you suggest how I might do that? Would I be able to use a MeshSignedDistanceGrid?
Assets/Scripts/geometry3Sharp/core/BufferUtil.cs(475,65): error CS0103: The name `CompressionLevel' does not exist in the current context.
There is a using: System.IO.Compression in BufferUtil.cs, but it doesn't work.
Did anyone meet the problem before? Any suggestion? THX~~
It seems use some points and their data on borehole, and then in spatial interpolation construct the signed distance filed, and then create the mesh?
https://sketchfab.com/ctech/models?cursor=cD0yMDE2LTA5LTA4KzE2JTNBMzMlM0EwNC44NzE3MzYmcj0x
Is Arc2d supports 3 point arc drawing like in AutoCad?
Thanks.
I would to ask if it is possible to mesh simplfication example?
thank you
StandardMeshReader read obj file,uv is null ! why?
Can't seem to find it...
Basically reduce according to the difference in angle. (If more than, then remove)
Did anyone use DijkstraGraphDistance class?
I want to find all nodes' dijkstra distance from a single seed. But only a small part of nodes has the distance.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.