// this function will count the number of quads for our terrain int Primitive_Count(CVolumeBuffer volume) { int count = 0; int size = volume.Size; for (int z = 0; z < size; ++z) { for (int y = 0; y < size; ++y) { for (int x = 0; x < size; ++x) { int value = volume.GetData(new Vector3(x, y, z)); // if we are in the blank space check and see if there is any valid terrain around us if (value == 0) { if (volume.GetData_BoundarySafe(new Vector3(x + 1, y, z)) > 0) { count++; } if (volume.GetData_BoundarySafe(new Vector3(x - 1, y, z)) > 0) { count++; } if (volume.GetData_BoundarySafe(new Vector3(x, y + 1, z)) > 0) { count++; } if (volume.GetData_BoundarySafe(new Vector3(x, y - 1, z)) > 0) { count++; } if (volume.GetData_BoundarySafe(new Vector3(x, y, z + 1)) > 0) { count++; } if (volume.GetData_BoundarySafe(new Vector3(x, y, z - 1)) > 0) { count++; } } } } } return(count); }
public void Generate(CVolumeBuffer volume) { int quad_count = Primitive_Count(volume); int tri_count = quad_count * 2; int vert_count = tri_count * 3; // calculate total vertices we need List <FatVertex> verts = new List <FatVertex>(vert_count); int size = volume.Size; for (int z = 0; z < size; ++z) { for (int y = 0; y < size; ++y) { for (int x = 0; x < size; ++x) { int value = volume.GetData(new Vector3(x, y, z)); if (value == 0) { if (volume.GetData_BoundarySafe(new Vector3(x + 1, y, z)) > 0) { CQuad newQuad = m_LookupMesh[1].Clone(); newQuad.Translate(new Vector3(x + 1, y, z)); verts.AddRange(newQuad.verts); } if (volume.GetData_BoundarySafe(new Vector3(x - 1, y, z)) > 0) { CQuad newQuad = m_LookupMesh[0].Clone(); newQuad.Translate(new Vector3(x - 1, y, z)); verts.AddRange(newQuad.verts); } if (volume.GetData_BoundarySafe(new Vector3(x, y + 1, z)) > 0) { CQuad newQuad = m_LookupMesh[3].Clone(); newQuad.Translate(new Vector3(x, y + 1, z)); verts.AddRange(newQuad.verts); } if (volume.GetData_BoundarySafe(new Vector3(x, y - 1, z)) > 0) { CQuad newQuad = m_LookupMesh[2].Clone(); newQuad.Translate(new Vector3(x, y - 1, z)); verts.AddRange(newQuad.verts); } if (volume.GetData_BoundarySafe(new Vector3(x, y, z + 1)) > 0) { CQuad newQuad = m_LookupMesh[5].Clone(); newQuad.Translate(new Vector3(x, y, z + 1)); verts.AddRange(newQuad.verts); } if (volume.GetData_BoundarySafe(new Vector3(x, y, z - 1)) > 0) { CQuad newQuad = m_LookupMesh[4].Clone(); newQuad.Translate(new Vector3(x, y, z - 1)); verts.AddRange(newQuad.verts); } } } } } var vb = Engine.Global.Device3d.CreateBuffer(new Device3dD3d11.SCreateBufferCmd() { Name = "VolumeDataVB", SizeInBytes = (int)vert_count * m_VertDesc.SizeInBytes, BufferBindFlags = BindFlags.VertexBuffer }); m_MeshDesc.VBBinding = new VertexBufferBinding(vb, m_VertDesc.SizeInBytes, 0); // update data buffer Engine.Global.Device3d.UpdateBufferData("VolumeDataVB", new DataStream(verts.ToArray(), false, false)); m_MeshDesc.VertexCount = vert_count; }
public void Generate(CVolumeBuffer volume) { int quad_count = Primitive_Count(volume); int tri_count = quad_count * 2; int vert_count = tri_count * 3; // calculate total vertices we need List<FatVertex> verts = new List<FatVertex>(vert_count); int size = volume.Size; for (int z = 0; z < size; ++z) { for (int y = 0; y < size; ++y) { for (int x = 0; x < size; ++x) { int value = volume.GetData(new Vector3(x, y, z)); if (value == 0) { if (volume.GetData_BoundarySafe(new Vector3(x + 1, y, z)) > 0) { CQuad newQuad = m_LookupMesh[1].Clone(); newQuad.Translate(new Vector3(x + 1, y, z)); verts.AddRange(newQuad.verts); } if (volume.GetData_BoundarySafe(new Vector3(x - 1, y, z)) > 0) { CQuad newQuad = m_LookupMesh[0].Clone(); newQuad.Translate(new Vector3(x - 1, y, z)); verts.AddRange(newQuad.verts); } if (volume.GetData_BoundarySafe(new Vector3(x, y + 1, z)) > 0) { CQuad newQuad = m_LookupMesh[3].Clone(); newQuad.Translate(new Vector3(x, y + 1, z)); verts.AddRange(newQuad.verts); } if (volume.GetData_BoundarySafe(new Vector3(x, y - 1, z)) > 0) { CQuad newQuad = m_LookupMesh[2].Clone(); newQuad.Translate(new Vector3(x, y - 1, z)); verts.AddRange(newQuad.verts); } if (volume.GetData_BoundarySafe(new Vector3(x, y, z + 1)) > 0) { CQuad newQuad = m_LookupMesh[5].Clone(); newQuad.Translate(new Vector3(x, y, z + 1)); verts.AddRange(newQuad.verts); } if (volume.GetData_BoundarySafe(new Vector3(x, y, z - 1)) > 0) { CQuad newQuad = m_LookupMesh[4].Clone(); newQuad.Translate(new Vector3(x, y, z - 1)); verts.AddRange(newQuad.verts); } } } } } var vb = Engine.Global.Device3d.CreateBuffer(new Device3dD3d11.SCreateBufferCmd() { Name = "VolumeDataVB", SizeInBytes = (int)vert_count * m_VertDesc.SizeInBytes, BufferBindFlags = BindFlags.VertexBuffer }); m_MeshDesc.VBBinding = new VertexBufferBinding(vb, m_VertDesc.SizeInBytes, 0); // update data buffer Engine.Global.Device3d.UpdateBufferData("VolumeDataVB", new DataStream(verts.ToArray(), false, false)); m_MeshDesc.VertexCount = vert_count; }
// this function will count the number of quads for our terrain int Primitive_Count(CVolumeBuffer volume) { int count = 0; int size = volume.Size; for (int z = 0; z < size; ++z) { for (int y = 0; y < size; ++y) { for (int x = 0; x < size; ++x) { int value = volume.GetData(new Vector3(x, y, z)); // if we are in the blank space check and see if there is any valid terrain around us if (value == 0) { if (volume.GetData_BoundarySafe(new Vector3(x + 1, y, z)) > 0) count++; if (volume.GetData_BoundarySafe(new Vector3(x - 1, y, z)) > 0) count++; if (volume.GetData_BoundarySafe(new Vector3(x, y + 1, z)) > 0) count++; if (volume.GetData_BoundarySafe(new Vector3(x, y - 1, z)) > 0) count++; if (volume.GetData_BoundarySafe(new Vector3(x, y, z + 1)) > 0) count++; if (volume.GetData_BoundarySafe(new Vector3(x, y, z - 1)) > 0) count++; } } } } return count; }