public override void Generate() { vertices = new VectorArray3d((NoSharedVertices) ? (4 * 6) : 8); uv = new VectorArray2f(vertices.Count); normals = new VectorArray3f(vertices.Count); triangles = new IndexArray3i(2 * 6); if (NoSharedVertices == false) { for (int i = 0; i < 8; ++i) { vertices[i] = Box.Corner(i); normals[i] = (Vector3F)(vertices[i] - Box.Center[i]).Normalized; uv[i] = Vector2F.Zero; // what to do for UVs in this case ?!? } int ti = 0; for (int fi = 0; fi < 6; ++fi) { triangles.Set(ti++, gIndices.BoxFaces[fi, 0], gIndices.BoxFaces[fi, 1], gIndices.BoxFaces[fi, 2], Clockwise); triangles.Set(ti++, gIndices.BoxFaces[fi, 0], gIndices.BoxFaces[fi, 2], gIndices.BoxFaces[fi, 3], Clockwise); } } else { int ti = 0; int vi = 0; Vector2F[] square_uv = new Vector2F[4] { Vector2F.Zero, new Vector2F(1, 0), new Vector2F(1, 1), new Vector2F(0, 1) }; for (int fi = 0; fi < 6; ++fi) { int v0 = vi++; vi += 3; int ni = gIndices.BoxFaceNormals[fi]; Vector3F n = (Vector3F)(Math.Sign(ni) * Box.Axis(Math.Abs(ni) - 1)); for (int j = 0; j < 4; ++j) { vertices[v0 + j] = Box.Corner(gIndices.BoxFaces[fi, j]); normals[v0 + j] = n; uv[v0 + j] = square_uv[j]; } triangles.Set(ti++, v0, v0 + 1, v0 + 2, Clockwise); triangles.Set(ti++, v0, v0 + 2, v0 + 3, Clockwise); } } }
public void Generate() { Append_mesh(); AxisAlignedBox3i bounds = Voxels.GridBounds; bounds.Max -= Vector3i.One; int[] vertices = new int[4]; foreach (Vector3i nz in Voxels.NonZeros()) { Check_counts_or_append(6, 2); Box3d cube = Box3d.UnitZeroCentered; cube.Center = (Vector3D)nz; for (int fi = 0; fi < 6; ++fi) { // checks dependent on neighbours Index3i nbr = nz + gIndices.GridOffsets6[fi]; if (bounds.Contains(nbr)) { if (SkipInteriorFaces && Voxels.Get(nbr)) { continue; } } else if (CapAtBoundary == false) { continue; } int ni = gIndices.BoxFaceNormals[fi]; Vector3F n = (Vector3F)(Math.Sign(ni) * cube.Axis(Math.Abs(ni) - 1)); NewVertexInfo vi = new NewVertexInfo(Vector3D.Zero, n); if (ColorSourceF != null) { vi.c = ColorSourceF(nz); vi.bHaveC = true; } for (int j = 0; j < 4; ++j) { vi.v = cube.Corner(gIndices.BoxFaces[fi, j]); vertices[j] = cur_mesh.AppendVertex(vi); } Index3i t0 = new Index3i(vertices[0], vertices[1], vertices[2], Clockwise); Index3i t1 = new Index3i(vertices[0], vertices[2], vertices[3], Clockwise); cur_mesh.AppendTriangle(t0); cur_mesh.AppendTriangle(t1); } } }