private void CreateVegetation(VoxelChunk chunk, int voxelIndex, Color vd) { if (chunk != null) { // Updates current chunk if (chunk.Voxels[voxelIndex].Color == 0) { chunk.Voxels[voxelIndex].Color = vd.ColorToUInt(); //ChunkRequestRefresh(chunk, false, true); } } }
private static Bitmap CreateBitmapFromColors(List <Voxel> blocks) { int width = blocks.Count; Bitmap bitmap = new Bitmap(width, 1); for (int i = 0; i < blocks.Count; i++) { Voxel voxel = blocks[i]; Color color = voxel.Color.UIntToColor(); int x = i % width; int y = i / width; bitmap.SetPixel(x, y, color.ToSystemDrawingColor()); } return(bitmap); }
public override Schematic WriteSchematic() { Schematic schematic = new Schematic(); FileToVoxCore.Drawing.Color[] colorsPalette = mVoxModel.Palette; using (ProgressBar progressbar = new ProgressBar()) { int minX = (int)mVoxModel.TransformNodeChunks.MinBy(t => t.TranslationAt().X).TranslationAt().X; int minY = (int)mVoxModel.TransformNodeChunks.MinBy(t => t.TranslationAt().Y).TranslationAt().Y; int minZ = (int)mVoxModel.TransformNodeChunks.MinBy(t => t.TranslationAt().Z).TranslationAt().Z; for (int i = 0; i < mVoxModel.VoxelFrames.Count; i++) { VoxelData data = mVoxModel.VoxelFrames[i]; Vector3 worldPositionFrame = mVoxModel.TransformNodeChunks[i + 1].TranslationAt(); if (worldPositionFrame == Vector3.zero) { continue; } for (int y = 0; y < data.VoxelsTall; y++) { for (int z = 0; z < data.VoxelsDeep; z++) { for (int x = 0; x < data.VoxelsWide; x++) { int indexColor = data.Get(x, y, z); FileToVoxCore.Drawing.Color color = colorsPalette[indexColor]; if (color != FileToVoxCore.Drawing.Color.Empty) { schematic.AddVoxel((int)(z + worldPositionFrame.X - minX), (int)(y + (worldPositionFrame.Z - minZ)), (int)(x + worldPositionFrame.Y - minY), color.ColorToUInt()); } } } } progressbar.Report(i / (float)mVoxModel.VoxelFrames.Count); } } return(schematic); }
public void RequestVegetationCreation(VoxelChunk chunk, int voxelIndex, Color vd) { if (chunk == null) { return; } mVegetationRequestLast++; if (mVegetationRequestLast >= mVegetationRequests.Length) { mVegetationRequestLast = 0; } if (mVegetationRequestLast != mVegetationRequestFirst) { mVegetationRequests[mVegetationRequestLast].Chunk = chunk; mVegetationRequests[mVegetationRequestLast].ChunkOriginalPosition = chunk.Position; mVegetationRequests[mVegetationRequestLast].VoxelIndex = voxelIndex; mVegetationRequests[mVegetationRequestLast].vd = vd; } }
public static Color ToUnityColor(this FileToVoxCore.Drawing.Color color) { Color result = new Color(color.R / (float)255, color.G / (float)255, color.B / (float)255, color.A / (float)255); return(result); }
private List <VoxelDTO> LoadVoxels() { List <VoxelDTO> voxels = new List <VoxelDTO>(); using (FileStream fs = File.OpenRead(PathFile)) { BinaryReader reader = new BinaryReader(fs); uint version = reader.ReadUInt32(); uint colorFormat = reader.ReadUInt32(); uint zAxisOrientation = reader.ReadUInt32(); uint compressed = reader.ReadUInt32(); uint visibilityMaskEncoded = reader.ReadUInt32(); uint numMatrices = reader.ReadUInt32(); for (int i = 0; i < numMatrices; i++) { //Read matrix name byte nameLength = reader.ReadByte(); string name = Encoding.UTF8.GetString(reader.ReadBytes(nameLength)); //Read matrix size uint sizeX = reader.ReadUInt32(); uint sizeY = reader.ReadUInt32(); uint sizeZ = reader.ReadUInt32(); //Read matrix position int posX = reader.ReadInt32(); int posY = reader.ReadInt32(); int posZ = reader.ReadInt32(); //uint[] matrix = new uint[sizeX * sizeY * sizeZ]; //matrixList.Add(matrix); if (compressed == 0) { for (uint z = 0; z < sizeZ; z++) { for (uint y = 0; y < sizeY; y++) { for (uint x = 0; x < sizeX; x++) { FileToVoxCore.Drawing.Color data = reader.ReadUInt32().UIntToColor(); if (data.A != 0) { voxels.Add(new VoxelDTO( (int)(zAxisOrientation == 1 ? (z + posZ) : (x + posX)), (int)y + posY, (int)(zAxisOrientation == 1 ? (x + posX) : (z + posZ)), colorFormat == 0 ? data.B : data.R, data.G, colorFormat == 0 ? data.R : data.B, data.A)); } } } } } else { int z = 0; while (z < sizeZ) { int index = -1; while (true) { uint data = reader.ReadUInt32(); if (data == NEXT_SLICE_FLAG) { break; } else if (data == CODE_FLAG) { uint count = reader.ReadUInt32(); data = reader.ReadUInt32(); for (int j = 0; j < count; j++) { long x = ((index + 1) % sizeX); long y = ~~((index + 1) / sizeX); index++; Color color = data.UIntToColor(); if (color.A != 0) { voxels.Add(new VoxelDTO( (int)(zAxisOrientation == 1 ? (z + posZ) : (x + posX)), (int)y, (int)(zAxisOrientation == 1 ? (x + posX) : (z + posZ)), colorFormat == 0 ? color.B : color.R, color.G, colorFormat == 0 ? color.R : color.B, color.A)); } } } else { long x = ((index + 1) % sizeX); long y = ~~((index + 1) / sizeX); index++; Color color = data.UIntToColor(); if (color.A != 0) { voxels.Add(new VoxelDTO( (int)(zAxisOrientation == 1 ? (z + posZ) : (x + posX)), (int)y, (int)(zAxisOrientation == 1 ? (x + posX) : (z + posZ)), colorFormat == 0 ? color.B : color.R, color.G, colorFormat == 0 ? color.R : color.B, color.A)); } } } z++; } } } return(voxels); } }