Hi all I cant seem to get the new mesh data api stuff to work I followed the meshApi examples on github but that only has taking existing data , so I had to wing it a bit when making this script
The script generates an error saying its referencing out of bounds in verts,
also another wierd thing is I cant use color I have to use color32 which messes with the way i do my setting up .
I allocate my arrays in another thread so all that works and is report correct values ,
I only assign the meshdata to meshes which have > 0 vertices.
Its marching cubes BTW.
Heres what I have so far
public Mesh.MeshDataArray outputMesh;
public List<Vector3> verts = new List<Vector3>();
public List<Color> colorsM = new List<Color>();
public List<Vector2> Uvs = new List<Vector2>();
public List<int> tris = new List<int>();
public List<Vector3> normals = new List<Vector3>();
public void Initialize()
{
outputMesh = Mesh.AllocateWritableMeshData(1);
}
void Execute(int o){
//size = verts.Count
outputMesh[0].SetVertexBufferParams(size, new VertexAttributeDescriptor(VertexAttribute.Position), new VertexAttributeDescriptor(VertexAttribute.Normal, stream: 1), new VertexAttributeDescriptor(VertexAttribute.TexCoord0), new VertexAttributeDescriptor(VertexAttribute.Color));
NativeArray<Vector3> NVerts = new NativeArray<Vector3>(size, Allocator.TempJob);
NVerts = outputMesh[0].GetVertexData<Vector3>();
NativeArray<Vector3> NNormals = new NativeArray<Vector3>(size, Allocator.TempJob); ;
NNormals = outputMesh[0].GetVertexData<Vector3>(stream: 1);
NativeArray<Vector2> NUVs = new NativeArray<Vector2>(size, Allocator.TempJob); ;
NUVs = outputMesh[0].GetVertexData<Vector2>();
NativeArray<Color32> NColors = new NativeArray<Color32>(size, Allocator.TempJob); ;
NColors = outputMesh[0].GetVertexData<Color32>();
var data = outputMesh[0];
int Tr = tris.Count;
outputMesh[0].SetIndexBufferParams(Tr, IndexFormat.UInt16);
NativeArray<int> NTris = new NativeArray<int>(Tr, Allocator.TempJob);
NTris = outputMesh[0].GetIndexData<int>();
//tried setting VCount to SIze
int vCount = data.vertexCount;
for (int i = 0; i < vCount; i++)
{
NVerts[i] = verts[i];//this always says out of bounds
NUVs[i] = tUvs[i];
NColors[i] = color[i];
}
data.subMeshCount = 1;
outputMesh[0].SetSubMesh(0, new SubMeshDescriptor(0, Tr));
int T = data.GetSubMesh(0).indexCount;
for (int i = 0; i < T; i++)
{
NTris[i] = tris[i];
}
}
Thanks for your help