Closed mmedinav18 closed 5 years ago
To answer your question simply, no, Plankton doesn't include a way to convert to a Unity mesh. It should however be straightforward to write your own conversion. I don't know Unity myself, but I took a quick look at their docs...
Vector3
. You can get the X
, Y
and Z
properties of a PlanktonVertex
and add a vertex to the Unity mesh.
...
int vcount = pmesh.Vertices.Count; // get number of vertices in plankton mesh
mesh.vertices = new Vector3[](vcount); // set up unity mesh vertex array
for (int i=0; i<vcount; i++)
{
PlanktonVertex v = pmesh.Vertices[i]; // get plankton mesh vertex
mesh.vertices[i] = new Vector3(v.X, v.Y, v.Z); // add vertex to unity mesh
}
...
int[]
containing vertex indices in sets of three. Having triangulated the plankton mesh (see below) you can use GetFaceVertices()
to get the vertex indices for each face and add them to the array.
...
int fcount = pmesh.Faces.Count; // get number of faces in plankton mesh
mesh.triangles = new int[](fcount*3); // set up unity mesh triangle array
for (int i=0; i<fcount; i++)
{
int[] vs = pmesh.Faces.GetFaceVertices(i); // get vertex indices for mesh
mesh.triangles[i*3] = vs[0]; // add first vertex index
mesh.triangles[i*3+1] = vs[1]; // add second ...
mesh.triangles[i*3+2] = vs[2]; // add third ...
}
...
This code is just to give you an idea. None of it has been tested!
One thing I noticed by reading the Unity docs for their Scripting API was that Unity meshes are triangulated. Plankton supports n-gon faces, so you might need to triangulate your mesh before converting it to Unity (one option is Stellate()
).
Good luck :)
That's what I though. I was looking more at visualizing just quads instead of quads that are triangulated, but this helps. Thanks @pearswj!
I created a fork with some changes and tools to integrate with Unity here: https://github.com/adamgryu/Plankton-Unity I just wanted to share this in case it's helpful!
Hi,
I started using the Plankton library for Unity as part of a bigger project that I started in unity. My question is if Plankton Meshes are able to convert to unity meshes for visualization? Is this possible? As of now, I am just simply creating a simple plane mesh from scratch. I am also new at c# and unity so my apologies if my question is a very obvious one to resolve.
Thanks in advance.