- Home /
Optimization problems
So i am having this really bad optimization problem and i was thinking people on the forums could help.
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.
Answer by DaveA · Sep 20, 2013 at 05:34 AM
You may want to look into the Marching Cubes algorithm (google that) which is used in many voxel (minecraft-like) programs. Also I think there's at least one plugin in the Asset Store that can optimize such meshes.
Your answer
Follow this Question
Related Questions
[Optimization] How can i optimize this voxel terrain more? 3 Answers
Make a simple tree 1 Answer
Freeze on destructible terrain. 0 Answers
Wind Zone Best Practices: Less is more? 0 Answers
Minecraft Biomes: How to Make? 2 Answers