I’m attempting to create a voxel system that uses a variety of custom block shapes.
Each chunk has lists for vertices, UVs, triangles and suchlike that are easily populated through code when creating cubes, as the components for each face are very short, simple and logical. However, when implementing more complex meshes for each face, although it’s still possible, it soon becomes prohibitively complex.
Therefore, is there a way I can import mesh data from a 3D modelling application and add those data to my vertex/uv/triangle lists directly through code. I know I could instantiate a lot of prefabs and then combine their meshes, but this seems very inefficient.
// Mesh prefabs
public Mesh testMesh;
public Mesh testCollisionMesh;
// Lists to hold mesh data, including for collision mesh
public List<Vector3> vertexList = new List<Vector3>();
public List<int> triangleList = new List<int>();
public List<Vector2> uvList = new List<Vector2>();
public List<Vector3> collisionVertexList = new List<Vector3>();
public List<int> collisionTriangleList = new List<int>();
The lists here are where I’m storing the data for creating my procedural meshes. The Mesh variables at the top have the mesh component of an imported model dragged onto them in the inspector.
How can I add data to my lists from the arrays in the mesh variables? I swear this can’t be too difficult, but nothing I try seems to work. Going from lists to arrays isn’t so hard, so I’ve no idea why I can’t find a way to do the reverse without the console lighting up like a christmas tree.