So i am having this really bad optimization problem and i was thinking people on the forums could help.[15618-screenshot+(2).png|15618]
Note: the inside the mesh its empty its just the out side. it would be nice to reduce the verts by like 5000. This is the script i use to generate a face for a chunk.
public void DrawBrick(int x, int y, int z, byte block) {
Vector3 start = new Vector3(x, y, z);
Vector3 offset1, offset2;
if (IsTransparent(x, y - 1, z))
{
offset1 = Vector3.left;
offset2 = Vector3.back;
DrawFace(start + Vector3.right, offset1, offset2, block);
}
if (IsTransparent(x, y + 1, z))
{
offset1 = Vector3.right;
offset2 = Vector3.back;
DrawFace(start + Vector3.up, offset1, offset2, block);
}
if (IsTransparent(x - 1, y, z))
{
offset1 = Vector3.back;
offset2 = Vector3.down;
DrawFace(start + Vector3.up, offset1, offset2, block);
}
if (IsTransparent(x + 1, y, z))
{
offset1 = Vector3.forward;
offset2 = Vector3.down;
DrawFace(start + Vector3.right + Vector3.up + Vector3.back, offset1, offset2, block);
}
if (IsTransparent(x, y, z - 1))
{
offset1 = Vector3.right;
offset2 = Vector3.down;
DrawFace(start + Vector3.back + Vector3.up, offset1, offset2, block);
}
if (IsTransparent(x, y, z + 1))
{
offset1 = Vector3.left;
offset2 = Vector3.down;
DrawFace(start + Vector3.up + Vector3.right, offset1, offset2, block);
}
}
public void DrawFace(Vector3 start, Vector3 offset1, Vector3 offset2, byte block)
{
int index = verts.Count;
verts.Add (start);
verts.Add (start + offset1);
verts.Add (start + offset2);
verts.Add (start + offset1 + offset2);
BlockType blockType = Terrain.blocks.GetBlock(block);
float zoom = 0.125F;
Vector2 uvBase = blockType.uv;
if(blockType.sideTexture == true)
{
if ((offset2 == Vector3.down))
{
uvBase = blockType.side;
}
}
if(blockType.bottomTexture == true)
{
if (!(offset2 == Vector3.down) && !(offset1 == Vector3.right))
{
uvBase = blockType.bottom;
}
}
uv.Add(uvBase);
uv.Add(uvBase + new Vector2(-zoom , 0F));
uv.Add(uvBase + new Vector2(0F , zoom));
uv.Add(uvBase + new Vector2(-zoom , zoom));
tris.Add (index + 0);
tris.Add (index + 1);
tris.Add (index + 2);
tris.Add (index + 3);
tris.Add (index + 2);
tris.Add (index + 1);
}
Thank you.