Comments (7)
I am away from home for a few days so can’t really help at the moment. The 3d triangulation will include all of the points. If you just need the surface it might be better to use the hull.
Might be easier if you explain what your trying to accomplish.
from hull-delaunay-voronoi.
The meshes this project makes are just index based which are difficult to edit after creation. You might want to look into converting them into a DCEL style data structure to process further.
from hull-delaunay-voronoi.
Hello, thank you for answering!
My aim is to visualise my point cloud data (which consists of 3D points to represent a forest scene with trees and floor) in a way similar to the picture below as a gameobject with a rendered mesh and mesh collider in Unity.
Since you suggested, I tried to use ConvexHull3 with these points and I used:
mesh.SetIndices(meshIndices, MeshTopology.Points, 0);
. It is very fast and efficient.
This is the result is here which is almost what I need, just with bigger point size and with mesh collider:
As it seems, the point size is small, I searched a bit and I think I can resize the point size using shaders in Unity. Nevertheless, it does not allow me to add mesh colliders in MeshTopology.Points configuration.
On the other hand, when I tried MeshTopology.Triangles and MeshTopology.Quads you can see the result below:
I would be glad if you could suggest any idea for this aim.
Cheers,
Beril
from hull-delaunay-voronoi.
The meshIndices and the meshVertexs are just the random points I created to make the hull from. If you are using them then you are not using the results from the convex hull.
The points mesh is just created to show the random points. They are not triangles or quads which why that didnt work.
The triangles create are in the hull object called the simplexs. You can use the function to convert the hull into a unity mesh.
private GameObject HullToGameobject(ConvexHull3 hull, Material material)
{
var verts = new List<Vector3>();
var indices = new List<int>();
for (int i = 0; i < hull.Simplexs.Count; i++)
{
//The simplices are the triangles.
var v0 = hull.Simplexs[i].Vertices[0];
var v1 = hull.Simplexs[i].Vertices[1];
var v2 = hull.Simplexs[i].Vertices[2];
//Add 3 the triangles verts.
verts.Add(new Vector3(v0.X, v0.Y, v0.Z));
verts.Add(new Vector3(v1.X, v1.Y, v1.Z));
verts.Add(new Vector3(v2.X, v2.Y, v2.Z));
//add the indices for three new verts.
//Cheak if the triangle is flipped.
if (hull.Simplexs[i].IsNormalFlipped)
{
indices.Add(i * 3 + 2);
indices.Add(i * 3 + 1);
indices.Add(i * 3 + 0);
}
else
{
indices.Add(i * 3 + 0);
indices.Add(i * 3 + 1);
indices.Add(i * 3 + 2);
}
}
//Create the unity mesh.
var mesh = new Mesh();
mesh.SetVertices(verts);
mesh.SetTriangles(indices, 0);
mesh.RecalculateNormals();
mesh.RecalculateTangents();
mesh.RecalculateBounds();
var go = new GameObject();
go.AddComponent<MeshFilter>().sharedMesh = mesh;
go.AddComponent<MeshRenderer>().sharedMaterial = material;
return go;
}
The simplex vertices also have a id which is there index in the original point array.
from hull-delaunay-voronoi.
And you can do the same for a triangulation but this time the simplices are tetrahedrons.
private GameObject TriangulationToGameobject(DelaunayTriangulation3 tri, Material material)
{
var verts = new List<Vector3>();
var indices = new List<int>();
for (int i = 0; i < tri.Cells.Count; i++)
{
//For a triangulation the simplex is a tetrahedron.
var simplex = tri.Cells[i].Simplex;
//The tetrahedron has 4 vertes.
var v0 = simplex.Vertices[0];
var v1 = simplex.Vertices[1];
var v2 = simplex.Vertices[2];
var v3 = simplex.Vertices[3];
var V0 = new Vector3(v0.X, v0.Y, v0.Z);
var V1 = new Vector3(v1.X, v1.Y, v1.Z);
var V2 = new Vector3(v2.X, v2.Y, v2.Z);
var V3 = new Vector3(v3.X, v3.Y, v3.Z);
//Add the 4 triangles that make up the tetrahedron.
if(simplex.IsNormalFlipped)
{
verts.Add(V2);
verts.Add(V1);
verts.Add(V0);
verts.Add(V3);
verts.Add(V2);
verts.Add(V0);
verts.Add(V0);
verts.Add(V1);
verts.Add(V3);
verts.Add(V3);
verts.Add(V1);
verts.Add(V2);
}
else
{
verts.Add(V0);
verts.Add(V1);
verts.Add(V2);
verts.Add(V0);
verts.Add(V2);
verts.Add(V3);
verts.Add(V3);
verts.Add(V1);
verts.Add(V0);
verts.Add(V2);
verts.Add(V1);
verts.Add(V3);
}
//Add 12 triangle indices.
indices.Add(i * 12 + 0);
indices.Add(i * 12 + 1);
indices.Add(i * 12 + 2);
indices.Add(i * 12 + 3);
indices.Add(i * 12 + 4);
indices.Add(i * 12 + 5);
indices.Add(i * 12 + 6);
indices.Add(i * 12 + 7);
indices.Add(i * 12 + 8);
indices.Add(i * 12 + 9);
indices.Add(i * 12 + 10);
indices.Add(i * 12 + 11);
//you can only draw the surface triangles by checking which has
//a null adjacency but cant quite remember how atm
/*
for (int j = 0; j < 4; j++)
{
if (simplex.Adjacent[j].HasAdjacency())
{
}
}
*/
}
//Create the unity mesh.
var mesh = new Mesh();
mesh.SetVertices(verts);
mesh.SetTriangles(indices, 0);
mesh.RecalculateNormals();
mesh.RecalculateTangents();
mesh.RecalculateBounds();
var go = new GameObject();
go.AddComponent<MeshFilter>().sharedMesh = mesh;
go.AddComponent<MeshRenderer>().sharedMaterial = material;
return go;
}
from hull-delaunay-voronoi.
Hello! Thank you for the functions. I immediately tried your suggestions, both HullToGameobject and TriangulationToGameobject functions as in the code block where 'vertices' contains my 3d points.
hull = new ConvexHull3();
hull.Generate(vertices);
HullToGameobject(hull, material);
The result is as in the picture:
delaunay = new DelaunayTriangulation3();
delaunay.Generate(vertices);
TriangulationToGameobject(delaunay, material);
The result is as in the picture:
Even though it is promising, I need something closer to the point cloud where the floor (bottom point) and trees (top point) have their own boundaries and do not connect.
I wonder if it is possible or if I am not on the right track. Any suggestion is welcome.
Cheers,
Beril
from hull-delaunay-voronoi.
I don’t think this project does what you want. It’s about hulls not point clouds.
from hull-delaunay-voronoi.
Related Issues (13)
- Tagging/identifying vertices used during Voronoi mesh generation HOT 1
- Incremental Delaunay HOT 3
- Generating irregular (non-convex) meshes HOT 1
- Question: is there a way to get adjacent voronoi cells?
- UpdateAdjacency method under Simplex.cs HOT 1
- Support for using UnityEngine.Vector3[] instead of Vertex3[] in ConvexHull3.Generate()
- DelaunayTriangulation3 and the 4th Dimension HOT 1
- mesh.recalculateBounds
- Some lost cells of 3d Delaunay HOT 4
- Some lost cells of 3d Delaunay (reopened) HOT 3
- Generate 3D Voronoi Diagram from Sites?
- How to add constraints?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hull-delaunay-voronoi.