How to read triangles from a generated chunk?

Modified on Tue, 22 Jan 2019 at 10:10 AM

When using Geometry Shaders option, the generated mesh for the chunks' MeshFilter component has a POINT topology. This means that you cannot get the triangles from the MeshFilter mesh property as they are generated in the shader itself.


However you can get the triangles from the collider.sharedMesh as Voxel Play does generate a normal mesh for collider purposes

Sample code:


if (env.RayCast (ray, out hit, 500f, 15)) {
    Voxel voxel = env.GetVoxel (hit.voxelCenter);
    Debug.Log ("There's a voxel at " + hit.point.ToString("F6") + " of type " + voxel.type.name);
    Debug.Log ("Chunk triangles: " + hit.chunk.mc.sharedMesh.triangles.Length);
}

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article