private Schematic ProcessShaderPatina(Schematic schematic)
        {
            using (ProgressBar progressBar = new ProgressBar())
            {
                int          index        = 0;
                List <Voxel> allVoxels    = schematic.GetAllVoxels();
                int          colorChanged = 0;
                foreach (Voxel voxel in allVoxels)
                {
                    if (Grows(schematic, voxel))
                    {
                        uint newColor = GetCrowColor(schematic, voxel);
                        if (voxel.Color != newColor)
                        {
                            schematic.ReplaceVoxel(voxel, newColor);
                            colorChanged++;
                        }
                    }

                    progressBar.Report(index++ / (float)(allVoxels.Count));
                }
                Console.WriteLine("COLOR CHANGED: " + colorChanged);

                if (colorChanged == 0)
                {
                    mShouldBreak = true;
                    Console.WriteLine("[INFO] NO COLORS CHANGED, BREAK");
                }
            }

            return(schematic);
        }
Exemple #2
0
        public async Task <Schematic> CreateSchematicAsync(Schematic schematic, string forkedFrom, CancellationToken cancellationToken)
        {
            var definition = _StringSerializer.Serialize(schematic);

            var results = await DefineCommand(
                "INSERT INTO Schematics (SchematicName, ForkedFrom, InitialState, Schematic) " +
                "VALUES (@SchematicName, @ForkedFrom, @InitialState, @Schematic);" +
                "\r\n\r\n" +
                "SELECT * FROM Schematics WHERE SchematicName = @SchematicName")
                          .SendNullValues()
                          .WithResultsAs <SchematicRecord>()
                          .Compile()
                          .ExecuteAsync(DatabaseManagerPool.DatabaseManager, new
            {
                schematic.SchematicName,
                ForkedFrom = forkedFrom,
                schematic.InitialState,
                Schematic = definition
            }, cancellationToken).ConfigureAwait(false);

            var schematicRecord = results.Single();

            var schematicResult = _StringSerializer.Deserialize <Schematic>(schematicRecord.Schematic);

            return(schematicResult);
        }
        private uint GetCrowColor(Schematic schematic, Voxel voxel)
        {
            float distance = MinDistanceToWall(schematic, voxel, mShaderPatina.Thickness);
            float index    = mShaderPatina.TargetColorIndex + mShaderPatina.AdditionalColorRange * (distance / MathF.Sqrt(MathF.Pow(mShaderPatina.Thickness, 2) * 3));

            return(schematic.GetColorAtPaletteIndex((int)index));
        }
        protected HashSet <Voxel> FillHoles(uint[,,] blocks, Schematic schematic)
        {
            Console.WriteLine("[LOG] Started to fill holes...");
            int max   = schematic.Width * schematic.Height * schematic.Length * 2;
            int index = 0;

            using (ProgressBar progressBar = new ProgressBar())
            {
                for (int i = 0; i < 2; i++)
                {
                    for (ushort y = 0; y < schematic.Height; y++)
                    {
                        for (ushort z = 0; z < schematic.Length; z++)
                        {
                            for (ushort x = 0; x < schematic.Width; x++)
                            {
                                if (blocks[x, y, z] == 0 && x > 0 && x <= schematic.Width && y > 0 && y <= schematic.Height && z > 0 && z <= schematic.Length)
                                {
                                    blocks = Check1X1X1Hole(blocks, x, y, z);
                                    blocks = Check1X2X1Hole(blocks, x, y, z);
                                    blocks = Check2X1X1Hole(blocks, x, y, z);
                                    blocks = Check1X1X2Hole(blocks, x, y, z);
                                }

                                progressBar.Report(index / (float)max);
                                index++;
                            }
                        }
                    }
                }
            }

            Console.WriteLine("[LOG] Done.");
            return(blocks.ToHashSetFrom3DArray());
        }
Exemple #5
0
        public Schematic WriteSchematic()
        {
            Schematic finalSchematic = new Schematic();

            if (mSchematic != null)
            {
                finalSchematic = new Schematic(mSchematic.GetAllVoxels());
            }

            Console.WriteLine("[INFO] Count steps: " + mHeightmapData.Steps.Length);
            for (int index = 0; index < mHeightmapData.Steps.Length; index++)
            {
                Console.WriteLine("[INFO] Start parse heightmap for step : " + index);
                HeightmapStep step = mHeightmapData.Steps[index];
                step.ValidateSettings();
                step.DisplayInfo();

                Bitmap bitmap      = new Bitmap(new FileInfo(step.TexturePath).FullName);
                Bitmap bitmapColor = null;
                if (!string.IsNullOrEmpty(step.ColorTexturePath))
                {
                    bitmapColor = new Bitmap(new FileInfo(step.ColorTexturePath).FullName);
                }


                Schematic schematicStep = ImageUtils.WriteSchematicFromImage(bitmap, bitmapColor, step);
                finalSchematic = SchematicMerger.Merge(finalSchematic, schematicStep, step);
            }

            return(finalSchematic);
        }
        //For now we're assuming (probably ignorantly) that schematics don't have the same block count issues as structures.
        //If this gives weird counts, then we need to refactor the nbt reading to take the things in those straight brackets as properties
        //and turn them into structure style blocks. Then we need to use the structure version of determine block count.
        private Dictionary <int, int> SetBlockCounts(Schematic schematic, Dictionary <int, int> itemDictionary)
        {
            foreach (int block in schematic.BlockData)
            {
                var blockPalette = schematic.Palette.FirstOrDefault(x => x.SchemBlockId == block);

                string blockMinecraftId = null;
                if (blockPalette != null)
                {
                    blockMinecraftId = blockPalette.MinecraftId;
                }

                if (blockMinecraftId == null)
                {
                    continue;
                }

                var blockId = blockMinecraftId.GetItemId();
                var palette = schematic.Palette.First(x => x.SchemBlockId == block);

                if (blockMinecraftId.Contains("slab") && !palette.Properties.Values.Contains("top"))
                {
                    var truth = "Her I am";
                }

                itemDictionary = ParsePropertyBasedCounts(itemDictionary, palette, blockId);
            }

            return(itemDictionary);
        }
        protected HashSet <Voxel> FixLonelyVoxels(uint[,,] blocks, Schematic schematic)
        {
            Console.WriteLine("[LOG] Started to delete lonely voxels...");
            int max   = schematic.Width * schematic.Height * schematic.Length * 2;
            int index = 0;

            using (ProgressBar progressBar = new ProgressBar())
            {
                for (ushort y = 0; y < schematic.Height; y++)
                {
                    for (ushort z = 0; z < schematic.Length; z++)
                    {
                        for (ushort x = 0; x < schematic.Width; x++)
                        {
                            if (blocks[x, y, z] != 0 && x > 0 && x < schematic.Width && y > 0 && y < schematic.Height && z > 0 && z < schematic.Length)
                            {
                                if (blocks[x - 1, y, z] == 0 && blocks[x + 1, y, z] == 0 && blocks[x, y - 1, z] == 0 && blocks[x, y + 1, z] == 0 && blocks[x, y, z - 1] == 0 && blocks[x, y, z + 1] == 0)
                                {
                                    blocks[x, y, z] = 0;
                                }
                            }

                            progressBar.Report(index / (float)max);
                            index++;
                        }
                    }
                }
            }
            Console.WriteLine("[LOG] Done.");
            return(blocks.ToHashSetFrom3DArray());
        }
Exemple #8
0
        private static bool SchematicToVox(AbstractToSchematic converter)
        {
            Schematic schematic = converter.WriteSchematic();

            Console.WriteLine($"[INFO] Vox Width: {schematic.Width}");
            Console.WriteLine($"[INFO] Vox Length: {schematic.Length}");
            Console.WriteLine($"[INFO] Vox Height: {schematic.Height}");

            if (schematic.Width > Schematic.MAX_WORLD_WIDTH || schematic.Length > Schematic.MAX_WORLD_LENGTH || schematic.Height > Schematic.MAX_WORLD_HEIGHT)
            {
                Console.WriteLine("[ERROR] Model is too big ! MagicaVoxel can't support model bigger than 2000x2000x1000");
                return(false);
            }

            VoxWriter writer = new VoxWriter();

            if (INPUT_PALETTE_FILE != null)
            {
                PaletteSchematicConverter converterPalette = new PaletteSchematicConverter(INPUT_PALETTE_FILE);
                schematic = converterPalette.ConvertSchematic(schematic);
                return(writer.WriteModel(FormatOutputDestination(OUTPUT_PATH), converterPalette.GetPalette(), schematic));
            }

            if (INPUT_SHADER_FILE != null)
            {
                JsonToSchematic jsonParser = new JsonToSchematic(INPUT_SHADER_FILE, schematic);
                schematic = jsonParser.WriteSchematic();
            }

            return(writer.WriteModel(FormatOutputDestination(OUTPUT_PATH), null, schematic));
        }
Exemple #9
0
        private void viewDXF(string source)
        {
            DXFFile fileRep = new DXFFile(source);

            drawing = new Schematic(fileRep, this, mainCanvas);
            drawing.draw(mainCanvas);
        }
        public override Schematic WriteSchematic()
        {
            List <Voxel> list      = Quantization.ApplyQuantization(mSchematic.GetAllVoxels(), ColorLimit);
            Schematic    schematic = new Schematic(list);

            return(schematic);
        }
 protected void AddMultipleBlocks(ref Schematic schematic, int minZ, int maxZ, int x, int y, Color color)
 {
     for (int z = minZ; z < maxZ; z++)
     {
         AddBlock(ref schematic, new Voxel((ushort)x, (ushort)z, (ushort)y, color.ColorToUInt()));
     }
 }
Exemple #12
0
        private Schematic Convert(List <VoxelDTO> voxels)
        {
            int minX = voxels.Min(x => x.X);
            int minY = voxels.Min(x => x.Y);
            int minZ = voxels.Min(x => x.Z);

            Schematic schematic = new Schematic();

            Console.WriteLine("[INFO] Started to write schematic from qb...");
            Console.WriteLine("[INFO] Qb Width: " + schematic.Width);
            Console.WriteLine("[INFO] Qb Length: " + schematic.Length);
            Console.WriteLine("[INFO] Qb Height: " + schematic.Height);
            using (ProgressBar progressbar = new ProgressBar())
            {
                for (var index = 0; index < voxels.Count; index++)
                {
                    VoxelDTO voxel = voxels[index];
                    voxel.X -= minX;
                    voxel.Y -= minY;
                    voxel.Z -= minZ;
                    ushort x = (ushort)voxel.X;
                    ushort y = (ushort)voxel.Y;
                    ushort z = (ushort)voxel.Z;

                    schematic.AddVoxel(x, y, z, FctExtensions.ByteArrayToUInt(voxel.R, voxel.G, voxel.B, 1));
                    progressbar.Report((index / (float)voxels.Count));
                }
            }
            Console.WriteLine("[INFO] Done.");

            return(schematic);
        }
Exemple #13
0
        public SchematicIterator(ConstructionArea area, string schematicName, Schematic.Rotation rotation)
        {
            this.area = area;

            positionMin = area.Minimum;
            positionMax = area.Maximum;

            iterationChunkLocation = positionMin;
            cursor = positionMin;

            SchematicName = schematicName;

            if (SchematicReader.TryGetSchematic(SchematicName, area.Owner.ColonyID, iterationChunkLocation, out var schematic))
            {
                BuilderSchematic = schematic;

                if (rotation >= Schematic.Rotation.Right)
                {
                    BuilderSchematic.Rotate();
                }

                if (rotation >= Schematic.Rotation.Back)
                {
                    BuilderSchematic.Rotate();
                }

                if (rotation >= Schematic.Rotation.Left)
                {
                    BuilderSchematic.Rotate();
                }
            }
        }
        public override Schematic WriteSchematic()
        {
            float minX = _blocks.MinBy(t => t.X).X;
            float minY = _blocks.MinBy(t => t.Y).Y;
            float minZ = _blocks.MinBy(t => t.Z).Z;

            float maxX = _blocks.MaxBy(t => t.X).X;
            float maxY = _blocks.MaxBy(t => t.Y).Y;
            float maxZ = _blocks.MaxBy(t => t.Z).Z;

            Schematic schematic = new Schematic()
            {
                Length = (ushort)(Math.Abs(maxZ - minZ)),
                Width  = (ushort)(Math.Abs(maxX - minX)),
                Heigth = (ushort)(Math.Abs(maxY - minY)),
                Blocks = new HashSet <Block>()
            };

            LoadedSchematic.LengthSchematic = schematic.Length;
            LoadedSchematic.WidthSchematic  = schematic.Width;
            LoadedSchematic.HeightSchematic = schematic.Heigth;
            List <Block> list = Quantization.ApplyQuantization(_blocks);

            list.ApplyOffset(new Vector3(minX, minY, minZ));
            HashSet <Block> hashSet = list.ToHashSet();

            //RemoveHoles(ref hashSet, schematic);
            schematic.Blocks = hashSet;

            return(schematic);
        }
        /// <summary>
        /// BitmapをSchematicに変換
        /// </summary>
        /// <param name="bitmap"></param>
        /// <returns></returns>
        public TagCompound ToSchematic(Bitmap bitmap)
        {
            var schematic = new Schematic(bitmap.Width, 1, bitmap.Height);
            var result    = Convert(bitmap);

            for (var y = 0; y < bitmap.Height; y++)
            {
                for (var x = 0; x < bitmap.Width; x++)
                {
                    var blockColor = result[x, y];

                    try
                    {
                        var block = AnvilImprovedDataProvider.Instance.GetBlock("minecraft:" + blockColor.BlockName);
                        schematic.SetBlock(x, 0, y, block.DefaultBlockSet);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show(blockColor.BlockName);
                    }
                }
                convertFile.Complete++;
            }

            return(schematic.BuildTag());
        }
Exemple #16
0
        public async Task BulkCreateMachineFromSchematicAsync()
        {
            // Arrange
            var schematic = new Schematic <string, string>
            {
                SchematicName = "schematic name",
                InitialState  = "initial state",
                States        = new[] { new State <string, string> {
                                            Value = "initial state"
                                        } }
            };
            var schematicBytes     = MessagePackSerializer.Serialize(schematic, ContractlessStandardResolver.Instance);
            var metadataEnumerable = new List <Dictionary <string, string> >();
            var firstKey           = "first key";
            var firstValue         = "first value";
            var firstMetadataEntry = new Dictionary <string, string> {
                { firstKey, firstValue }
            };
            var secondKey           = "second key";
            var secondValue         = "second value";
            var secondMetadataEntry = new Dictionary <string, string> {
                { secondKey, secondValue }
            };

            metadataEnumerable.Add(firstMetadataEntry);
            metadataEnumerable.Add(secondMetadataEntry);

            _localAdapterMock
            .Setup(_ => _.BulkCreateMachineFromSchematicAsync <string, string>(
                       It.Is <Schematic <string, string> >(it => it.SchematicName == schematic.SchematicName),
                       It.IsAny <IEnumerable <IDictionary <string, string> > >(),
                       It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(
                         new BulkCreateMachineResponse
            {
                MachineIds = new[] { "a", "b" }
            }));

            // Act
            var response = await _stateMachineServiceMock.Object
                           .BulkCreateMachineFromSchematicAsync(new BulkCreateMachineFromSchematicRequest
            {
                SchematicBytes = schematicBytes,
                Metadata       = metadataEnumerable
            });

            // Assert
            // Note: first parameter has to be checked for It.Is, other parameters CANNOT or the verify will fail
            _localAdapterMock.Verify(
                expression: _ => _.BulkCreateMachineFromSchematicAsync(
                    It.Is <Schematic <string, string> >(it => it.SchematicName == schematic.SchematicName),
                    metadataEnumerable,
                    CancellationToken.None),
                times: Times.Once());

            Assert.NotNull(response);
            Assert.NotNull(response.MachineIds);
            Assert.Collection(response.MachineIds, Assert.NotNull, Assert.NotNull);
            Assert.Collection(response.MachineIds, machineId => Assert.Equal("a", machineId), machineId => Assert.Equal("b", machineId));
        }
Exemple #17
0
        public Schematic ApplyShader(Schematic schematic, ShaderStep shaderStep)
        {
            List <Voxel> allVoxels = schematic.GetAllVoxels();

            int index = 0;

            using (ProgressBar progressBar = new ProgressBar())
            {
                foreach (Voxel voxel in allVoxels)
                {
                    int x = voxel.X;
                    int y = voxel.Y;
                    int z = voxel.Z;

                    if (x == 0 || y == 0 || z == 0)
                    {
                        continue;
                    }

                    if (schematic.GetColorAtVoxelIndex(x - 1, y, z) == 0 &&
                        schematic.GetColorAtVoxelIndex(x + 1, y, z) == 0 &&
                        schematic.GetColorAtVoxelIndex(x, y - 1, z) == 0 &&
                        schematic.GetColorAtVoxelIndex(x, y + 1, z) == 0 &&
                        schematic.GetColorAtVoxelIndex(x, y, z - 1) == 0 &&
                        schematic.GetColorAtVoxelIndex(x, y, z + 1) == 0)
                    {
                        schematic.RemoveVoxel(x, y, z);
                    }

                    progressBar.Report(index++ / (float)allVoxels.Count);
                }
            }
            Console.WriteLine("[INFO] Done.");
            return(schematic);
        }
Exemple #18
0
        public async Task GetSchematicAsync()
        {
            // Arrange
            var schematicName = "schematic name";
            var schematic     = new Schematic <string, string> {
                SchematicName = "schematic name"
            };
            var schematicBytes = MessagePackSerializer.Serialize(schematic, ContractlessStandardResolver.Instance);

            _localAdapterMock
            .Setup(_ => _.GetSchematicAsync <string, string>(
                       It.Is <string>(it => it == schematicName),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(new GetSchematicResponse
            {
                SchematicBytes = schematicBytes
            });

            // Act
            var response = await _stateMachineServiceMock.Object
                           .GetSchematicAsync(new GetSchematicRequest
            {
                SchematicName = schematicName
            });

            // Assert
            Assert.NotNull(response);
            Assert.Equal(schematicBytes, response.SchematicBytes);
        }
        public Schematic ConvertSchematic(Schematic schematic)
        {
            Console.WriteLine("[INFO] Started to convert all colors of blocks to match the palette");
            Schematic              newSchematic      = new Schematic(GetPaletteUint());
            List <uint>            colors            = schematic.UsedColors;
            Dictionary <uint, int> paletteDictionary = new Dictionary <uint, int>();

            foreach (uint color in colors)
            {
                int index = ColorComparison.CompareColorRGB(_colors, color.UIntToColor());
                paletteDictionary[color] = index;
            }

            using (ProgressBar progressbar = new ProgressBar())
            {
                int          i         = 0;
                List <Voxel> allVoxels = schematic.GetAllVoxels();
                foreach (Voxel block in allVoxels)
                {
                    newSchematic.AddVoxel(block.X, block.Y, block.Z,
                                          _colors[paletteDictionary[block.Color]].ColorToUInt());
                    progressbar.Report(i++ / (float)allVoxels.Count);
                }
            }

            Console.WriteLine("[INFO] Done.");
            return(newSchematic);
        }
Exemple #20
0
 private void AddMultipleBlocks(ref Schematic schematic, int minZ, int maxZ, int x, int y, Color color)
 {
     for (int z = minZ; z < maxZ; z++)
     {
         AddBlock(ref schematic, new Block((short)x, (short)z, (short)y, color.ColorToUInt()));
     }
 }
        public override Schematic WriteSchematic()
        {
            float minX = _blocks.MinBy(t => t.X).X;
            float minY = _blocks.MinBy(t => t.Y).Y;
            float minZ = _blocks.MinBy(t => t.Z).Z;

            Schematic schematic = new Schematic();

            List <Voxel> list = Quantization.ApplyQuantization(_blocks, _colorLimit);

            list.ApplyOffset(new Vector3(minX, minY, minZ));
            HashSet <Voxel> hashSet = list.ToHashSet();

            if (_holes)
            {
                hashSet = FillHoles(hashSet.To3DArray(schematic), schematic);
            }
            if (_flood)
            {
                hashSet = FillInvisiblesVoxels(hashSet.To3DArray(schematic), schematic);
            }
            if (_lonely)
            {
                hashSet = FixLonelyVoxels(hashSet.To3DArray(schematic), schematic);
            }
            schematic.Blocks = hashSet;

            return(schematic);
        }
Exemple #22
0
        private static void SchematicToVox(AbstractToSchematic converter, string outputPath)
        {
            Schematic schematic = converter.WriteSchematic();

            Console.WriteLine($"[INFO] Vox Width: {schematic.Width}");
            Console.WriteLine($"[INFO] Vox Length: {schematic.Length}");
            Console.WriteLine($"[INFO] Vox Height: {schematic.Height}");

            if (schematic.Width > MAX_WORLD_WIDTH || schematic.Length > MAX_WORLD_LENGTH || schematic.Height > MAX_WORLD_HEIGHT)
            {
                Console.WriteLine("[ERROR] Voxel model is too big ! MagicaVoxel can't support model bigger than 2000^3");
                return;
            }

            VoxWriter writer = new VoxWriter();

            if (_inputPaletteFile != null)
            {
                PaletteSchematicConverter converterPalette = new PaletteSchematicConverter(_inputPaletteFile, _colorLimit);
                schematic = converterPalette.ConvertSchematic(schematic);
                writer.WriteModel(_chunkSize, outputPath + ".vox", converterPalette.GetPalette(), schematic);
            }
            else
            {
                writer.WriteModel(_chunkSize, outputPath + ".vox", null, schematic);
            }
        }
        private Schematic GetSchematic()
        {
            int width           = Math.Min(Math.Max(TerrainEnvironment.Instance.WorldTerrainData.Width, TerrainEnvironment.Instance.WorldTerrainData.Length), 2000);
            int chunkXZDistance = width / 2;
            int chunkYDistance  = 1000 / 2;

            int visibleXMin = -chunkXZDistance;
            int visibleXMax = chunkXZDistance - 1;

            int visibleZMin = -chunkXZDistance;
            int visibleZMax = chunkXZDistance - 1;

            int visibleYMin = -chunkYDistance;
            int visibleYMax = chunkYDistance - 1;

            uint[,,] voxels = TerrainEnvironment.Instance.GetVoxels(new Vector3(visibleXMin, visibleYMin, visibleZMin), new Vector3(visibleXMax, visibleYMax, visibleZMax));
            Schematic schematic = new Schematic();

            for (int y = 0; y < voxels.GetLength(0); y++)
            {
                for (int z = 0; z < voxels.GetLength(1); z++)
                {
                    for (int x = 0; x < voxels.GetLength(2); x++)
                    {
                        if (voxels[y, z, x] != 0)
                        {
                            schematic.Blocks.Add(new Voxel((ushort)x, (ushort)y, (ushort)z, voxels[y, z, x]));
                        }
                    }
                }
            }

            return(schematic);
        }
Exemple #24
0
        public string PreviewDiagram(Schematic schematic)
        {
            var machine = _stateMachineFactory
                          .ConstructFromConfiguration(_apiKey, null, schematic);

            return(machine.ToString());
        }
        private float DistanceAverage(Schematic schematic, Voxel currentVoxel, List <Voxel> voxels)
        {
            float sum = voxels.Where(v => v != null).Aggregate <Voxel, float>(0, (current, voxel) => current + Distance(schematic.GetPaletteIndex(currentVoxel.Color), schematic.GetPaletteIndex(voxel.Color)));

            sum /= voxels.Count(v => v != null);
            return(sum);
        }
Exemple #26
0
        public Schematic ApplyShader(Schematic schematic, ShaderStep shaderStep)
        {
            ShaderFill shaderFill = shaderStep as ShaderFill;

            if (shaderFill.TargetColorIndex == -1)
            {
                schematic = ProcessSchematicInDeleteMode(schematic, shaderFill);
            }
            else
            {
                switch (shaderFill.RotationMode)
                {
                case RotationMode.X:
                    schematic = ProcessSchematicInXAxis(schematic, shaderFill);
                    break;

                case RotationMode.Y:
                    schematic = ProcessSchematicInYAxis(schematic, shaderFill);
                    break;

                case RotationMode.Z:
                    schematic = ProcessSchematicInZAxis(schematic, shaderFill);
                    break;
                }
            }

            return(schematic);
        }
Exemple #27
0
        private float MinDistanceToWall(Schematic schematic, Voxel voxel, int distance)
        {
            float minDistance = distance + 1;

            for (int x = -distance; x <= distance; x++)
            {
                for (int y = -distance; y <= distance; y++)
                {
                    for (int z = -distance; z <= distance; z++)
                    {
                        if (schematic.GetVoxel(voxel.X + x, voxel.Y + y, voxel.Z + z, out Voxel foundVoxel))
                        {
                            if (!IsGrowColor(schematic, foundVoxel))
                            {
                                float d = MathF.Sqrt(MathF.Pow(x, 2) + MathF.Pow(y, 2) + MathF.Pow(z, 2));
                                if (minDistance > d)
                                {
                                    minDistance = d;
                                }
                            }
                        }
                    }
                }
            }

            return(minDistance);
        }
Exemple #28
0
        private Schematic ProcessSchematicInXAxis(Schematic schematic, ShaderFill shaderFill)
        {
            int  min   = shaderFill.Limit;
            uint color = schematic.GetColorAtPaletteIndex(shaderFill.TargetColorIndex);

            for (int y = 0; y < schematic.Height; y++)
            {
                for (int z = 0; z < schematic.Length; z++)
                {
                    if (shaderFill.FillDirection == FillDirection.PLUS)
                    {
                        for (int x = min; x < schematic.Width; x++)
                        {
                            schematic.AddVoxel(x, y, z, color, shaderFill.Replace);
                        }
                    }
                    else
                    {
                        for (int x = min; x >= 0; x--)
                        {
                            schematic.AddVoxel(x, y, z, color, shaderFill.Replace);
                        }
                    }
                }
            }

            return(schematic);
        }
Exemple #29
0
        private bool GrowsDown(Schematic schematic, Voxel voxel)
        {
            if (schematic.GetVoxel(voxel.X, voxel.Y + 1, voxel.Z, out Voxel foundVoxel) && IsGrowColor(schematic, foundVoxel))
            {
                return(true);
            }

            if (schematic.GetVoxel(voxel.X + 1, voxel.Y, voxel.Z, out foundVoxel) && IsGrowColor(schematic, foundVoxel))
            {
                return(true);
            }

            if (schematic.GetVoxel(voxel.X - 1, voxel.Y, voxel.Z, out foundVoxel) && IsGrowColor(schematic, foundVoxel))
            {
                return(true);
            }

            if (schematic.GetVoxel(voxel.X, voxel.Y, voxel.Z - 1, out foundVoxel) && IsGrowColor(schematic, foundVoxel))
            {
                return(true);
            }

            if (schematic.GetVoxel(voxel.X, voxel.Y, voxel.Z + 1, out foundVoxel) && IsGrowColor(schematic, foundVoxel))
            {
                return(true);
            }

            return(false);
        }
        private Schematic WriteSchematicFromBinvox()
        {
            using (LineReader lineReader = new LineReader(File.Open(_path, FileMode.Open), Encoding.UTF8))
            {
                ReadHeader(lineReader);
                ReadVoxels(lineReader);
                Schematic schematic = new Schematic();

                int xmult = (int)(mDimensions.Z * mDimensions.Y);
                int zmult = (int)(mDimensions.Z);

                for (int Y = 0; Y < mDimensions.Y; Y++)
                {
                    for (int Z = 0; Z < mDimensions.Z; Z++)
                    {
                        for (int X = 0; X < mDimensions.X; X++)
                        {
                            int index = X * xmult + Z * zmult + Y;
                            if (mVoxels[index] == 1)
                            {
                                schematic.Blocks.Add(new Voxel((ushort)X, (ushort)Y, (ushort)Z, Color.Wheat.ColorToUInt()));
                            }
                        }
                    }
                }

                return(schematic);
            }
        }
Exemple #31
0
    //builds from schema
    public Transform createActor(Schematic schema)
    {
        if (schema == null)
            return null;

        if (schema.parts.Count < 1)
            return null;

        Transform core = createPart (schema.getPart (0));

        if (core == null)
            return null;

        assembleActor (core, schema, 0);
        return core;
    }
Exemple #32
0
    public void assembleActor(Transform parentPart, Schematic schema, int index)
    {
        //reads node data to create child parts
        Part thisPart = schema.getPart (index);
        if (thisPart == null)
            return;
        else {
            for(int i=0; i<thisPart.nodes.Length; i+=1) {

                Node thisNode = thisPart.getNode(i);
                if(thisNode == null) continue;

                if(thisNode.equipped) {
                    Debug.Log("node:yes");
                    PartTag attachedTag = thisNode.getPartTag ();

                    if (attachedTag == null)
                        continue; //nothing attached

                    Part attachedPart = schema.getPart (attachedTag.index);

                    //now that we pulled the data we need..
                    Transform partObject = createPart(attachedPart);
                    if(partObject) {
                        partObject.SetParent(parentPart);
                        partObject.localPosition.Set (thisNode.localPosition.x,thisNode.localPosition.y,thisNode.localPosition.z);
                        partObject.localRotation = Quaternion.Euler(thisNode.localRotation.x,thisNode.localRotation.y,thisNode.localRotation.z);
                        assembleActor(partObject, schema, attachedTag.index);
                    }
                    else Debug.Log("Gag! no part!");
                }

            }

        }
    }
 private void GenerateLayoutCode(Eagle.eagle eagle, Schematic.TestBench TestBench_obj)
 {
     // write layout file
     string layoutFile = Path.Combine(this.mainParameters.OutputDirectory, "layout-input.json");
     new Layout.LayoutGenerator(eagle.drawing.Item as Eagle.schematic, TestBench_obj, Logger).Generate(layoutFile);
 }
Exemple #34
0
        public MainForm()
        {
            this.schematic = new Schematic();

            InitializeComponent();
        }
Exemple #35
0
 public OutputForm()
 {
     this.schematic = new Schematic();
     InitializeComponent();
 }
Exemple #36
0
        public void BuildSchematic(string schmaticpath)
        {
            int maxl = 0;
            int maxlw = 0;
            foreach (var i in Methods)
            {
                if (i.Value.Count > maxl)
                {
                    maxl = i.Value.Count;
                }
                foreach (var iyy in i.Value)
                {
                    var iz = iyy;
                    if (iz.StartsWith("|"))
                    {
                        iz = iz.TrimStart('|');
                        maxlw += int.Parse(iz + 2); // 2 exstra repeaters to give script time

                    }
                }
            }

            Schematic s = new Schematic();
            s.Height = 1;
            s.Width = (short)((Methods.Count * 2) + maxlw + 5) ;
            s.Length = (short)(maxl * 2 + 2 + 5);
            s.Fill();
            int x = 0;
            foreach (var ii in Methods)
            {
                int z = 1;
                s.SetBlock(x, 0, 0, new Block() { ID = 93, Metta = 2 });
                foreach (var iyy in ii.Value)
                {
                    var i = iyy;

                    if (i.StartsWith("|"))
                    {
                        i = i.TrimStart('|');
                        for (int iu = 0; iu < int.Parse(i); iu++)
                        {
                            s.SetBlock(x, 0, z, new Block() { ID = 93, Metta = 14 }); // full tic repeater
                            z++;
                        }

                    }
                    else
                    {
                        int b = 2;
                        if (!i.StartsWith("/"))
                        {
                            b = 6;
                        }
                        if (i.StartsWith("#"))
                        {
                            i = i.TrimStart('#');
                            s.SetBlock(x, 0, z + 1, new Block() { ID = 149, Metta = 2 });
                        }
                        else
                        {
                            s.SetBlock(x, 0, z + 1, new Block() { ID = 93, Metta = b });
                        }
                        s.SetBlock(x, 0, z, new Block() { ID = 137, Metta = 0, Command = i });
                        z += 2;
                    }
                }
                s.SetBlock(x, 0, z, new Block() { ID = 137, Metta = 0, Command = "/setblock ~ ~ ~-" + (z + 1) + " minecraft:air" });
                x += 2;
            }
            s.Save(schmaticpath);
        }