private void FillMasksWithBackFront(ref ChunkStruct c, int currentSlice, ref byte[][] firstMask, ref byte[][] secondMask) { for (int x = 0; x < CHUNK_SIZE; x++) { for (int y = 0; y < CHUNK_SIZE; y++) { HashSet <Face> faceSet = CheckFaces(x, y, currentSlice, ref c); if (faceSet.Contains(Face.BACK)) { firstMask[x][y] = c[x, y, currentSlice]; } else { firstMask[x][y] = 0; } if (faceSet.Contains(Face.FRONT)) { secondMask[x][y] = c[x, y, currentSlice]; } else { secondMask[x][y] = 0; } } } }
private void CreateTopQuad(ref ChunkStruct c, int x, int z, int x2, int z2, int y) { Vector3 voxPosition1 = new Vector3((x) * VOX_SIZE, (y) * VOX_SIZE, (z) * VOX_SIZE); voxPosition1.x = voxPosition1.x + (c.Dx * CHUNK_SIZE * VOX_SIZE); voxPosition1.y = voxPosition1.y + (c.Dy * CHUNK_SIZE * VOX_SIZE); voxPosition1.z = voxPosition1.z + (c.Dz * CHUNK_SIZE * VOX_SIZE); Vector3 voxPosition2 = new Vector3((x2) * VOX_SIZE, (y) * VOX_SIZE, (z2) * VOX_SIZE); voxPosition2.x = voxPosition2.x + (c.Dx * CHUNK_SIZE * VOX_SIZE); voxPosition2.y = voxPosition2.y + (c.Dy * CHUNK_SIZE * VOX_SIZE); voxPosition2.z = voxPosition2.z + (c.Dz * CHUNK_SIZE * VOX_SIZE); SurfaceTool surfaceTool = c.surfaceTool; surfaceTool.AddNormal(new Vector3(0.0f, 1.0f, 0.0f)); surfaceTool.AddVertex(new Vector3(voxPosition1.x, voxPosition2.y, voxPosition1.z)); surfaceTool.AddVertex(new Vector3(voxPosition2.x, voxPosition2.y, voxPosition1.z)); surfaceTool.AddVertex(new Vector3(voxPosition1.x, voxPosition2.y, voxPosition2.z)); surfaceTool.AddVertex(new Vector3(voxPosition2.x, voxPosition2.y, voxPosition1.z)); surfaceTool.AddVertex(new Vector3(voxPosition2.x, voxPosition2.y, voxPosition2.z)); surfaceTool.AddVertex(new Vector3(voxPosition1.x, voxPosition2.y, voxPosition2.z)); // this.addQuad(ref c, // new Vector3(x, y, z2), // new Vector3(x2, y, z2), // new Vector3(x2, y, z), // new Vector3(x, y, z)); }
private void FillMasksWithBottomTop(ref ChunkStruct c, int currentSlice, ref byte[][] firstMask, ref byte[][] secondMask) { for (int x = 0; x < CHUNK_SIZE; x++) { for (int z = 0; z < CHUNK_SIZE; z++) { HashSet <Face> faceSet = CheckFaces(x, currentSlice, z, ref c); if (faceSet.Contains(Face.BOTTOM)) { firstMask[x][z] = c[x, currentSlice, z]; } else { firstMask[x][z] = 0; } if (faceSet.Contains(Face.TOP)) { secondMask[x][z] = c[x, currentSlice, z]; } else { secondMask[x][z] = 0; } } } }
private void FillMasksWithLeftRight(ref ChunkStruct c, int currentSlice, ref byte[][] firstMask, ref byte[][] secondMask) { for (int y = 0; y < CHUNK_SIZE; y++) { for (int z = 0; z < CHUNK_SIZE; z++) { HashSet <Face> faceSet = CheckFaces(currentSlice, y, z, ref c); if (faceSet.Contains(Face.LEFT)) { firstMask[z][y] = c[currentSlice, y, z]; } else { firstMask[z][y] = 0; } if (faceSet.Contains(Face.RIGHT)) { secondMask[z][y] = c[currentSlice, y, z]; } else { secondMask[z][y] = 0; } } } }
public override MeshInstance CreateChunkMesh(ref ChunkStruct c) { // c.chunkData = SnappyCodec.Uncompress(c.compChunkData); c.surfaceTool.Begin(Mesh.PrimitiveType.Triangles); c.surfaceTool.SetMaterial(mat); for (int i = 0; i < CHUNK_SIZE; i++) { for (int j = 0; j < CHUNK_SIZE; j++) { for (int k = 0; k < CHUNK_SIZE; k++) { if (c[i, j, k] == 0) { continue; } createFaces(i, j, k, c.Dx, c.Dy, c.Dz, ref c.surfaceTool, ref c); } } } c.surfaceTool.Index(); MeshInstance mesh = new MeshInstance(); mesh.SetMesh(c.surfaceTool.Commit()); c.surfaceTool.Clear(); // c.chunkData = new byte[1]; return(mesh); }
private void CreateFrontQuad(ref ChunkStruct c, int x, int y, int x2, int y2, int z) { //The Z-1 is more of a hack because the face previously was shown on the back side rather than the front Vector3 voxPosition1 = new Vector3((x) * VOX_SIZE, (y) * VOX_SIZE, (z - 1) * VOX_SIZE); voxPosition1.x = voxPosition1.x + (c.Dx * CHUNK_SIZE * VOX_SIZE); voxPosition1.y = voxPosition1.y + (c.Dy * CHUNK_SIZE * VOX_SIZE); voxPosition1.z = voxPosition1.z + (c.Dz * CHUNK_SIZE * VOX_SIZE); Vector3 voxPosition2 = new Vector3((x2) * VOX_SIZE, (y2) * VOX_SIZE, (z) * VOX_SIZE); voxPosition2.x = voxPosition2.x + (c.Dx * CHUNK_SIZE * VOX_SIZE); voxPosition2.y = voxPosition2.y + (c.Dy * CHUNK_SIZE * VOX_SIZE); voxPosition2.z = voxPosition2.z + (c.Dz * CHUNK_SIZE * VOX_SIZE); SurfaceTool surfaceTool = c.surfaceTool; surfaceTool.AddNormal(new Vector3(0.0f, 0.0f, -1.0f)); surfaceTool.AddVertex(new Vector3(voxPosition1.x, voxPosition1.y, voxPosition1.z)); surfaceTool.AddVertex(new Vector3(voxPosition2.x, voxPosition1.y, voxPosition1.z)); surfaceTool.AddVertex(new Vector3(voxPosition2.x, voxPosition2.y, voxPosition1.z)); surfaceTool.AddVertex(new Vector3(voxPosition2.x, voxPosition2.y, voxPosition1.z)); surfaceTool.AddVertex(new Vector3(voxPosition1.x, voxPosition2.y, voxPosition1.z)); surfaceTool.AddVertex(new Vector3(voxPosition1.x, voxPosition1.y, voxPosition1.z)); // addQuad(ref c, // new Vector3(x,y,z), // new Vector3(x2,y,z), // new Vector3(x2,y2,z), // new Vector3(x,y2,z)); }
public void createVoxel(int x, int y, int z, ref ChunkStruct chunk) { Random random = new Random(); float r = (float)random.NextDouble(); float g = (float)random.NextDouble(); float b = (float)random.NextDouble(); HashSet <Face> faceSet = CheckFaces(x, y, z, ref chunk); int size = faceSet.Count; if ((size == 1 && faceSet.Contains(Face.NO_SIDE)) || faceSet.Contains(Face.NONE)) { return; } Vector3 normal = Vector3.Zero; foreach (Face face in faceSet) { normal += face.offset; } normal /= faceSet.Count; if (normal == Vector3.Zero) { normal.y = 1; } chunk.surfaceTool.AddNormal(normal); chunk.surfaceTool.AddColor(new Color(r, g, b)); Vector3 voxPosition = new Vector3((x) * VOX_SIZE, (y) * VOX_SIZE, (z) * VOX_SIZE); voxPosition.x = voxPosition.x + (chunk.Dx * CHUNK_SIZE * VOX_SIZE); voxPosition.y = voxPosition.y + (chunk.Dy * CHUNK_SIZE * VOX_SIZE); voxPosition.z = voxPosition.z + (chunk.Dz * CHUNK_SIZE * VOX_SIZE); chunk.surfaceTool.AddVertex(voxPosition); }
private bool canCreateFace(int x, int y, int z, ref ChunkStruct c) { if (!isInData(x, y, z)) { if (volume[c.Dx * CHUNK_SIZE + x, c.Dy *CHUNK_SIZE + y, c.Dz *CHUNK_SIZE + z] != (byte)VoxelTypes.Air) { return(false); } return(true); } // else if (volume[x * CHUNK_SIZE, y * CHUNK_SIZE, z * CHUNK_SIZE] == VoxelTypes.Default) // { // Console.WriteLine(string.Format("{0} {1} {2} ",x,y,z)+volume[x * CHUNK_SIZE, y * CHUNK_SIZE, z * CHUNK_SIZE]); // return false; // } // Console.WriteLine(string.Format("{0} {1} {2}", x, y, z)); if (c[x, y, z] == (byte)VoxelTypes.Air) { return(true); } // if (volume[c.Dx * CHUNK_SIZE+x, c.Dy * CHUNK_SIZE+y, c.Dz * CHUNK_SIZE+z] == (byte)VoxelTypes.Air) // { // return true; // } return(false); }
public void getChunks(Stream pStream) { int offset = INITIAL_CHUNK_OFFSET; while (offset < pStream.Length) { ChunkStruct newChunk = new ChunkStruct(); UInt16 dataLength; // Chunk Size newChunk.chunkSize = new byte[CHUNK_SIZE_SIZE]; pStream.Seek(offset + CHUNK_SIZE_OFFSET, SeekOrigin.Begin); pStream.Read(newChunk.chunkSize, 0, CHUNK_SIZE_SIZE); // Chunk Id newChunk.chunkIdentifier = new byte[CHUNK_IDENTIFIER_SIZE]; pStream.Seek(offset + CHUNK_IDENTIFIER_OFFSET, SeekOrigin.Begin); pStream.Read(newChunk.chunkIdentifier, 0, CHUNK_IDENTIFIER_SIZE); // Chunk Data dataLength = BitConverter.ToUInt16(newChunk.chunkSize, 0); newChunk.chunkData = new byte[dataLength]; pStream.Seek(offset + CHUNK_DATA_OFFSET, SeekOrigin.Begin); pStream.Read(newChunk.chunkData, 0, dataLength); // Add Chunk to Array chunks.Add(newChunk); // Increment Offset offset += CHUNK_DATA_OFFSET + (int)dataLength; } }
protected override ChunkStruct GetVideoChunk(FileStream inStream, long currentOffset) { ChunkStruct videoChunkStruct = new ChunkStruct(); long chunkSize = (long)ParseFile.ReadUintLE(inStream, currentOffset + 4); byte[] videoChunk = ParseFile.ParseSimpleOffset(inStream, currentOffset + 8, (int)chunkSize); videoChunkStruct.Chunk = videoChunk; videoChunkStruct.ChunkId = MobiclipWiiStream.VideoChunkId; return(videoChunkStruct); }
protected override ChunkStruct[] GetAudioChunk(FileStream inStream, long currentOffset, long blockSize, long videoChunkSize) { ChunkStruct[] audioChunkStructs = new ChunkStruct[this.AudioStreamCount]; long absoluteOffset = currentOffset + 8 + videoChunkSize + 4; uint baseChunkId;// = ParseFile.ReadUintLE(inStream, absoluteOffset - 4); baseChunkId = 0; uint chunkSize = 0; for (uint i = 0; i < this.AudioStreamCount; i++) { audioChunkStructs[i] = new ChunkStruct(); // Untested for file with more than 2 streams if (this.AudioStreamCount > 1) { if (i == 0) { // read chunk size before first audio stream, should be the same for each. chunkSize = ParseFile.ReadUintLE(inStream, absoluteOffset); absoluteOffset += 4; } } else { chunkSize = (uint)((currentOffset + blockSize) - absoluteOffset); } if (chunkSize > 0) { audioChunkStructs[i].ChunkId = baseChunkId + i; audioChunkStructs[i].Chunk = ParseFile.ParseSimpleOffset(inStream, absoluteOffset, (int)chunkSize); } absoluteOffset += chunkSize; } //int chunkSize = (int)(blockSize - videoChunkSize - 8 - 4); //if (chunkSize > 0) //{ // audioChunk = ParseFile.ParseSimpleOffset(inStream, absoluteOffset, chunkSize); // audioChunkStruct.Chunk = audioChunk; // audioChunkStructs[0].ChunkId = ParseFile.ReadUintLE(inStream, absoluteOffset - 4); // audioChunkStruct.ChunkId = 0; //} return(audioChunkStructs); }
public override MeshInstance CreateChunkMesh(ref ChunkStruct c) { // Console.WriteLine("Curr Chunk {0},{1},{2}",c.Dx,c.Dy,c.Dz); String startTime = DateTime.Now.ToString("HH:mm:ss:ffff"); c.surfaceTool.Begin(Mesh.PrimitiveType.Points); c.surfaceTool.SetMaterial(mat); String initTime = DateTime.Now.ToString("HH:mm:ss:ffff"); // for (int i = 0; i < CHUNK_SIZE; i += 1) // { // for (int j = 0; j < CHUNK_SIZE; j += 1) // { // for (int k = 0; k < CHUNK_SIZE; k += 1) // { // if (c[i, j, k] == 0) // { // continue; // } // createVoxel(i, j, k, ref c); // } // } // } int maxChunk = CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE; for (int i = 0; i < maxChunk; i++) { int x = i / (CHUNK_SIZE * CHUNK_SIZE); int y = (i / CHUNK_SIZE) % CHUNK_SIZE; int z = i % CHUNK_SIZE; if (c[x, y, z] == 0) { continue; } createVoxel(x, y, z, ref c); } String pointCreationTime = DateTime.Now.ToString("HH:mm:ss:ffff"); c.surfaceTool.Index(); MeshInstance mesh = new MeshInstance(); mesh.SetMesh(c.surfaceTool.Commit()); c.surfaceTool.Clear(); String indexTime = DateTime.Now.ToString("HH:mm:ss:ffff"); // Console.WriteLine("Curr Chunk {0},{1},{2} Curr Thread: {3}, StartTime: {4}, Initialization Time: {5}, Greedy Time: {6}, Index Time {7}",c.Dx,c.Dy,c.Dz, // System.Threading.Thread.CurrentThread.ManagedThreadId,startTime // ,initTime,pointCreationTime,indexTime); return(mesh); }
// public override MeshInstance CreateChunkMesh(ref ChunkStruct c) // { // // c.chunkData = SnappyCodec.Uncompress(c.compChunkData); // c.surfaceTool.Begin(Mesh.PrimitiveType.Triangles); // c.surfaceTool.SetMaterial(mat); // for (int i = 0; i < CHUNK_SIZE; i++) // { // for (int j = 0; j < CHUNK_SIZE; j++) // { // for (int k = 0; k < CHUNK_SIZE; k++) // { // if (c[i, j, k] == 0) // { // continue; // } // createFaces(i, j, k, c.Dx, c.Dy, c.Dz, ref c.surfaceTool, ref c); // } // } // } // c.surfaceTool.Index(); // MeshInstance mesh = new MeshInstance(); // mesh.SetMesh(c.surfaceTool.Commit()); // c.surfaceTool.Clear(); // // c.chunkData = new byte[1]; // return mesh; // } public override MeshInstance CreateChunkMesh(ref ChunkStruct c) { String startTime = DateTime.Now.ToString("HH:mm:ss:ffff"); byte[][] firstMask; byte[][] secondMask; MeshInstance mesh = new MeshInstance(); c.surfaceTool.Begin(Mesh.PrimitiveType.Triangles); c.surfaceTool.SetMaterial(mat); firstMask = new byte[CHUNK_SIZE][]; secondMask = new byte[CHUNK_SIZE][]; initializeJaggedArr(ref firstMask); initializeJaggedArr(ref secondMask); String initTime = DateTime.Now.ToString("HH:mm:ss:ffff"); for (int x = 0; x < CHUNK_SIZE; x++) { this.FillMasksWithLeftRight(ref c, x, ref firstMask, ref secondMask); this.FillWithQuads(firstMask, x, ref c, CreateLeftQuad); this.FillWithQuads(secondMask, x + 1, ref c, CreateRightQuad); } for (int y = 0; y < CHUNK_SIZE; y++) { this.FillMasksWithBottomTop(ref c, y, ref firstMask, ref secondMask); this.FillWithQuads(firstMask, y, ref c, CreateBottomQuad); this.FillWithQuads(secondMask, y + 1, ref c, CreateTopQuad); } for (int z = 0; z < CHUNK_SIZE; z++) { this.FillMasksWithBackFront(ref c, z, ref firstMask, ref secondMask); this.FillWithQuads(firstMask, z, ref c, CreateBackQuad); this.FillWithQuads(secondMask, z + 1, ref c, CreateFrontQuad); } String greedyMeshingTime = DateTime.Now.ToString("HH:mm:ss:ffff"); c.surfaceTool.Index(); mesh.SetMesh(c.surfaceTool.Commit()); c.surfaceTool.Clear(); String indexTime = DateTime.Now.ToString("HH:mm:ss:ffff"); Console.WriteLine("Curr Thread: {0}, StartTime: {1}, Initialization Time: {2}, Greedy Time: {3}, Index Time {4}", System.Threading.Thread.CurrentThread.ManagedThreadId, startTime , initTime, greedyMeshingTime, indexTime); return(mesh); }
private bool canCreateFace(int x, int y, int z, ref ChunkStruct c) { if (!isInData(x, y, z)) { if (volume[c.Dx * CHUNK_SIZE + x, c.Dy *CHUNK_SIZE + y, c.Dz *CHUNK_SIZE + z] != (byte)VoxelTypes.Air) { return(false); } return(true); } if (c[x, y, z] == (byte)VoxelTypes.Air) { return(true); } return(false); }
private HashSet <Face> CheckFaces(int x, int y, int z, ref ChunkStruct c) { var faceSet = new HashSet <Face>(); if (c[x, y, z] == (byte)VoxelTypes.Air) { faceSet.Add(Face.NONE); return(faceSet); } faceSet.Add(canCreateFace(x, y - 1, z, ref c) == true ? Face.BOTTOM : Face.NO_SIDE); faceSet.Add(canCreateFace(x, y + 1, z, ref c) == true ? Face.TOP : Face.NO_SIDE); faceSet.Add(canCreateFace(x + 1, y, z, ref c) == true ? Face.RIGHT : Face.NO_SIDE); faceSet.Add(canCreateFace(x - 1, y, z, ref c) == true ? Face.LEFT : Face.NO_SIDE); faceSet.Add(canCreateFace(x, y, z + 1, ref c) == true ? Face.BACK : Face.NO_SIDE); faceSet.Add(canCreateFace(x, y, z - 1, ref c) == true ? Face.FRONT : Face.NO_SIDE); return(faceSet); }
protected override ChunkStruct GetVideoChunk(FileStream inStream, long currentOffset) { ChunkStruct videoChunkStruct = new ChunkStruct(); long blockSize = (long)(BitConverter.ToUInt16(ParseFile.ParseSimpleOffset(inStream, currentOffset + 2, 2), 0) * 4); blockSize += 4; long audioChunkSize = (long)(BitConverter.ToUInt16(ParseFile.ParseSimpleOffset(inStream, currentOffset, 2), 0) * 4); if (audioChunkSize > 0) { audioChunkSize += 8; } byte[] videoChunk = ParseFile.ParseSimpleOffset(inStream, currentOffset + 4 + audioChunkSize, (int)(blockSize - audioChunkSize)); videoChunkStruct.Chunk = videoChunk; videoChunkStruct.ChunkId = (uint)BitConverter.ToUInt16(ParseFile.ParseSimpleOffset(inStream, currentOffset, 2), 0); return(videoChunkStruct); }
protected override ChunkStruct[] GetAudioChunk(FileStream inStream, long currentOffset, long blockSize, long videoChunkSize) { // @TODO: Fix this for multi-audio streams ChunkStruct[] audioChunkStructs = new ChunkStruct[1]; long chunkSize = (long)BitConverter.ToUInt16(ParseFile.ParseSimpleOffset(inStream, currentOffset, 2), 0); chunkSize *= 4; if (chunkSize > 0) { chunkSize += 8; } byte[] audioChunk = ParseFile.ParseSimpleOffset(inStream, currentOffset + 4, (int)chunkSize); audioChunkStructs[0] = new ChunkStruct(); audioChunkStructs[0].Chunk = audioChunk; audioChunkStructs[0].ChunkId = (uint)BitConverter.ToUInt16(ParseFile.ParseSimpleOffset(inStream, currentOffset, 2), 0); return(audioChunkStructs); }
private void FillWithQuads(byte[][] mask, int currentSlice, ref ChunkStruct c, CreateFace createFace) { for (int x = 0; x < mask.Length; x++) { byte[] row = mask[x]; for (int y = 0; y < row.Length; y++) { if (row[y] != (byte)VoxelTypes.Air) { byte currentId = row[y]; int startX = x; int startY = y; int endY = findYEnd(row, currentId, startY); int endX = findXEnd(mask, currentId, startY, endY, x); y = endY - 1; //public delegate void CreateFace(ref ChunkStruct c, int x, int y, int z, int x2, int y2, int z2); createFace(ref c, startX, startY, endX, endY, currentSlice); } } } }
public virtual void DemultiplexStreams(MpegStream.DemuxOptionsStruct demuxOptions) { long currentOffset = 0; long fileSize; long blockSize; long videoChunkSize; Dictionary <uint, FileStream> streamOutputWriters = new Dictionary <uint, FileStream>(); ChunkStruct currentChunk = new ChunkStruct(); ChunkStruct[] audioChunks; try { using (FileStream fs = File.OpenRead(this.FilePath)) { this.ReadHeader(fs, currentOffset); fileSize = fs.Length; currentOffset = ParseFile.GetNextOffset(fs, currentOffset, DataStartBytes) + 4; while (currentOffset < fileSize) { if (currentOffset == 0x4C7DC) { } blockSize = this.GetBlockSize(fs, currentOffset); if (blockSize > 0) { // write video block to stream currentChunk = this.GetVideoChunk(fs, currentOffset); if (demuxOptions.ExtractVideo && (currentChunk.Chunk != null)) { this.writeChunkToStream(currentChunk.Chunk, currentChunk.ChunkId, streamOutputWriters, this.FileExtensionVideo); } // NDS -- currentBlockId = (uint)(BitConverter.ToUInt16(ParseFile.ParseSimpleOffset(fs, currentOffset, 2), 0) & 0x00FF); // write audio block to stream if (demuxOptions.ExtractAudio && (this.AudioStreamCount > 0)) { videoChunkSize = currentChunk.Chunk == null ? 0 : currentChunk.Chunk.Length; audioChunks = this.GetAudioChunk(fs, currentOffset, blockSize, videoChunkSize); for (uint i = 0; i < this.AudioStreamCount; i++) { if (audioChunks[i].Chunk != null) { this.writeChunkToStream(audioChunks[i].Chunk, audioChunks[i].ChunkId, streamOutputWriters, this.FileExtensionAudio); } } } // move offset currentOffset += blockSize; } else { break; } } } // using (FileStream fs = File.OpenRead(this.FilePath)) } catch (Exception ex) { throw new Exception(String.Format("Exception processing block at offset 0x{0}: {1}{2}", currentOffset.ToString("X"), ex.Message, Environment.NewLine)); } finally { // clean up this.DoFinalTasks(streamOutputWriters, demuxOptions); } }
private void createFaces(int x, int y, int z, int Dx, int Dy, int Dz, ref SurfaceTool surfaceTool, ref ChunkStruct c) { Vector3 voxPosition = new Vector3((x) * VOX_SIZE, (y) * VOX_SIZE, (z) * VOX_SIZE); voxPosition.x = voxPosition.x + (Dx * CHUNK_SIZE * VOX_SIZE); voxPosition.y = voxPosition.y + (Dy * CHUNK_SIZE * VOX_SIZE); voxPosition.z = voxPosition.z + (Dz * CHUNK_SIZE * VOX_SIZE); if (canCreateFace(x, y - 1, z, ref c)) { surfaceTool.AddNormal(new Vector3(0.0f, -1.0f, 0.0f)); surfaceTool.AddColor(new Color(1.0f, 1.0f, .7f, 1f)); surfaceTool.AddVertex(vertices[1] + voxPosition); surfaceTool.AddVertex(vertices[3] + voxPosition); surfaceTool.AddVertex(vertices[2] + voxPosition); surfaceTool.AddVertex(vertices[1] + voxPosition); surfaceTool.AddVertex(vertices[0] + voxPosition); surfaceTool.AddVertex(vertices[3] + voxPosition); } if (canCreateFace(x, y + 1, z, ref c)) { surfaceTool.AddNormal(new Vector3(0.0f, 1.0f, 0.0f)); surfaceTool.AddColor(new Color(0.7f, 0.0f, .7f, 1f)); surfaceTool.AddVertex(vertices[4] + voxPosition); surfaceTool.AddVertex(vertices[5] + voxPosition); surfaceTool.AddVertex(vertices[7] + voxPosition); surfaceTool.AddVertex(vertices[5] + voxPosition); surfaceTool.AddVertex(vertices[6] + voxPosition); surfaceTool.AddVertex(vertices[7] + voxPosition); } if (canCreateFace(x + 1, y, z, ref c)) { surfaceTool.AddNormal(new Vector3(1.0f, 0.0f, 0.0f)); surfaceTool.AddColor(new Color(1f, 1f, 1f, 1f)); surfaceTool.AddVertex(vertices[2] + voxPosition); surfaceTool.AddVertex(vertices[5] + voxPosition); surfaceTool.AddVertex(vertices[1] + voxPosition); surfaceTool.AddVertex(vertices[2] + voxPosition); surfaceTool.AddVertex(vertices[6] + voxPosition); surfaceTool.AddVertex(vertices[5] + voxPosition); } if (canCreateFace(x - 1, y, z, ref c)) { surfaceTool.AddNormal(new Vector3(-1.0f, 0.0f, 0.0f)); surfaceTool.AddColor(new Color(1f, 1f, 1f, 1f)); surfaceTool.AddVertex(vertices[0] + voxPosition); surfaceTool.AddVertex(vertices[7] + voxPosition); surfaceTool.AddVertex(vertices[3] + voxPosition); surfaceTool.AddVertex(vertices[0] + voxPosition); surfaceTool.AddVertex(vertices[4] + voxPosition); surfaceTool.AddVertex(vertices[7] + voxPosition); } if (canCreateFace(x, y, z + 1, ref c)) { surfaceTool.AddNormal(new Vector3(0.0f, 0.0f, 1.0f)); surfaceTool.AddColor(new Color(1f, 1f, 1f, 1f)); surfaceTool.AddVertex(vertices[3] + voxPosition); surfaceTool.AddVertex(vertices[6] + voxPosition); surfaceTool.AddVertex(vertices[2] + voxPosition); surfaceTool.AddVertex(vertices[3] + voxPosition); surfaceTool.AddVertex(vertices[7] + voxPosition); surfaceTool.AddVertex(vertices[6] + voxPosition); } if (canCreateFace(x, y, z - 1, ref c)) { surfaceTool.AddNormal(new Vector3(0.0f, 0.0f, -1.0f)); surfaceTool.AddColor(new Color(1f, 1f, 1f, 1f)); surfaceTool.AddVertex(vertices[0] + voxPosition); surfaceTool.AddVertex(vertices[1] + voxPosition); surfaceTool.AddVertex(vertices[5] + voxPosition); surfaceTool.AddVertex(vertices[5] + voxPosition); surfaceTool.AddVertex(vertices[4] + voxPosition); surfaceTool.AddVertex(vertices[0] + voxPosition); } }
public abstract MeshInstance CreateChunkMesh(ref ChunkStruct c);