Exemple #1
0
        private static MeshDraft Platform(float radius, float baseOffset, int segments, float heignt)
        {
            float segmentAngle = 360f / segments;
            float currentAngle = 0;

            var lowerRing = new List <Vector3>(segments);
            var upperRing = new List <Vector3>(segments);

            for (var i = 0; i < segments; i++)
            {
                var lowerPoint = PTUtils.PointOnCircle3XZ(radius + baseOffset, currentAngle);
                lowerRing.Add(lowerPoint + Vector3.down * heignt);

                var upperPoint = PTUtils.PointOnCircle3XZ(radius, currentAngle);
                upperRing.Add(upperPoint);
                currentAngle -= segmentAngle;
            }

            var platform = new MeshDraft {
                name = "Platform"
            };
            var bottom = MeshDraft.TriangleFan(lowerRing);

            bottom.Add(MeshDraft.Band(lowerRing, upperRing));
            bottom.Paint(new Color(0.5f, 0.5f, 0.5f, 1));
            platform.Add(bottom);

            upperRing.Reverse();
            var top = MeshDraft.TriangleFan(upperRing);

            top.Paint(new Color(0.8f, 0.8f, 0.8f, 1));
            platform.Add(top);

            return(platform);
        }
Exemple #2
0
        private void Awake()
        {
            pixels        = new Color[width * height];
            texture       = PTUtils.CreateTexture(width, height, Color.clear);
            image.texture = texture;

            header = InstantiateControl <TextControl>(leftPanel);
            header.transform.SetAsFirstSibling();
            header.Initialize("Noise type:");

            InstantiateToggle(FastNoise.NoiseType.Perlin);
            InstantiateToggle(FastNoise.NoiseType.PerlinFractal);
            InstantiateToggle(FastNoise.NoiseType.Simplex);
            InstantiateToggle(FastNoise.NoiseType.SimplexFractal);
            InstantiateToggle(FastNoise.NoiseType.Cubic);
            InstantiateToggle(FastNoise.NoiseType.CubicFractal);
            InstantiateToggle(FastNoise.NoiseType.Value);
            InstantiateToggle(FastNoise.NoiseType.ValueFractal);
            InstantiateToggle(FastNoise.NoiseType.Cellular);
            InstantiateToggle(FastNoise.NoiseType.WhiteNoise);

            noise = new FastNoise();
            Generate();
            SetupSkyboxAndPalette();
        }
Exemple #3
0
        public void Simulate()
        {
            PTUtils.Swap(ref cells, ref copy);
            for (int x = 0; x < config.width; x++)
            {
                for (int y = 0; y < config.height; y++)
                {
                    int aliveCells = CountAliveNeighbourCells(x, y);

                    if (copy[x, y] == CellState.Dead)
                    {
                        if (config.ruleset.CanSpawn(aliveCells))
                        {
                            cells[x, y] = CellState.Alive;
                        }
                        else
                        {
                            cells[x, y] = CellState.Dead;
                        }
                    }
                    else
                    {
                        if (!config.ruleset.CanSurvive(aliveCells))
                        {
                            cells[x, y] = CellState.Dead;
                        }
                        else
                        {
                            cells[x, y] = CellState.Alive;
                        }
                    }
                }
            }
        }
Exemple #4
0
        private void Awake()
        {
            texture       = PTUtils.CreateTexture(textureSize, textureSize, Color.clear);
            pixels        = texture.GetPixels();
            image.texture = texture;

            var slider = InstantiateControl <SliderControl>(leftPanel.transform);

            slider.Initialize("Threshold", 0, 1, threshold, value =>
            {
                threshold = value;
                Generate();
            });

            var toggle = InstantiateControl <ToggleControl>(leftPanel.transform);

            toggle.Initialize("Animate", animate, isOn => animate = isOn);

            noise = new FastNoise();
            noise.SetNoiseType(FastNoise.NoiseType.SimplexFractal);

            UpdateTexture();
            Generate();
            GeneratePalette();
            SetupSkyboxAndPalette();
        }
Exemple #5
0
        private void Awake()
        {
            config.drawEdge = DrawEdge;

            int textureWidth  = MazeGenerator.GetMapWidth(config.width, wallSize, roomSize);
            int textureHeight = MazeGenerator.GetMapHeight(config.height, wallSize, roomSize);

            texture           = PTUtils.CreateTexture(textureWidth, textureHeight, Color.black);
            mazeImage.texture = texture;

            var header = InstantiateControl <TextControl>(algorithmsGroup.transform.parent);

            header.Initialize("Generator algorithm");
            header.transform.SetAsFirstSibling();

            InstantiateToggle(MazeGenerator.Algorithm.RandomTraversal, "Random traversal");
            InstantiateToggle(MazeGenerator.Algorithm.RandomDepthFirstTraversal, "Random depth-first traversal");

            InstantiateControl <ToggleControl>(leftPanel).Initialize("Use gradient", useGradient, value =>
            {
                useGradient = value;
                Generate();
            });

            InstantiateControl <ButtonControl>(leftPanel).Initialize("Generate new maze", Generate);

            Generate();
            SetupSkyboxAndPalette();
        }
Exemple #6
0
        private List <PanelSize> DivideFacade(float facadeWidth, bool leftIsConvex, bool rightIsConvex, out float remainder)
        {
            float availableWidth = facadeWidth;

            if (!leftIsConvex)
            {
                availableWidth -= bufferWidth;
            }
            if (!rightIsConvex)
            {
                availableWidth -= bufferWidth;
            }

            Dictionary <PanelSize, int> knapsack = PTUtils.Knapsack(sizeValues, availableWidth);
            var sizes = new List <PanelSize>();

            remainder = facadeWidth;
            foreach (var pair in knapsack)
            {
                for (var i = 0; i < pair.Value; i++)
                {
                    sizes.Add(pair.Key);
                    remainder -= sizeValues[pair.Key];
                }
            }
            sizes.Shuffle();
            return(sizes);
        }
Exemple #7
0
        public static MeshDraft Platform(float radius, float heignt, int segments = 128)
        {
            float segmentAngle = 360f / segments;
            float currentAngle = 0;

            var lowerRing = new List <Vector3>(segments);
            var upperRing = new List <Vector3>(segments);

            for (var i = 0; i < segments; i++)
            {
                var lowerPoint = PTUtils.PointOnCircle3XZ(radius + heignt, currentAngle);
                lowerRing.Add(lowerPoint + Vector3.down * heignt);

                var upperPoint = PTUtils.PointOnCircle3XZ(radius, currentAngle);
                upperRing.Add(upperPoint);
                currentAngle -= segmentAngle;
            }

            var platform = new MeshDraft {
                name = "Platform"
            };

            platform.Add(new MeshDraft()
                         .AddTriangleFan(lowerRing)
                         .Add(MeshDraft.Band(lowerRing, upperRing))
                         .Paint(new Color(0.5f, 0.5f, 0.5f, 1)));

            upperRing.Reverse();
            platform.Add(new MeshDraft()
                         .AddTriangleFan(upperRing)
                         .Paint(new Color(0.8f, 0.8f, 0.8f, 1)));

            return(platform);
        }
Exemple #8
0
        private List <BrickSize> BrickSizes(float width)
        {
            // https://en.wikipedia.org/wiki/Knapsack_problem
            // We are using knapsack problem solver to fill fixed width with bricks of random width
            Dictionary <BrickSize, int> knapsack;
            float knapsackWidth;

            do
            {
                // Prefill knapsack to get nicer distribution of widths
                knapsack = GetRandomKnapsack(width);
                // Calculate sum of brick widths in knapsack
                knapsackWidth = KnapsackWidth(knapsack);
            } while (knapsackWidth > width);

            width   -= knapsackWidth;
            knapsack = PTUtils.Knapsack(sizeValues, width, knapsack);
            var brickSizes = new List <BrickSize>();

            foreach (var pair in knapsack)
            {
                for (var i = 0; i < pair.Value; i++)
                {
                    brickSizes.Add(pair.Key);
                }
            }
            brickSizes.Shuffle();
            return(brickSizes);
        }
Exemple #9
0
        private static Vector2 GetBisector(Vector2 previous, Vector2 current, Vector2 next, out float angle)
        {
            Vector2 toPrevious = (previous - current).normalized;
            Vector2 toNext     = (next - current).normalized;

            angle = PTUtils.Angle360(toPrevious, toNext);
            Assert.IsFalse(float.IsNaN(angle));
            return(toPrevious.RotateCW(angle / 2));
        }
Exemple #10
0
        private static List <PanelSize> DivideFacade(Dictionary <PanelSize, float> sizeValues, float facadeWidth)
        {
            Dictionary <PanelSize, int> knapsack = PTUtils.Knapsack(sizeValues, facadeWidth);
            var sizes = new List <PanelSize>();

            foreach (var pair in knapsack)
            {
                for (var i = 0; i < pair.Value; i++)
                {
                    sizes.Add(pair.Key);
                }
            }
            sizes.Shuffle();
            return(sizes);
        }
        private List <PanelSize> PanelSizes(float wallLength)
        {
            var knapsack   = PTUtils.Knapsack(sizeValues, wallLength);
            var panelSizes = new List <PanelSize>();

            foreach (var pair in knapsack)
            {
                for (var i = 0; i < pair.Value; i++)
                {
                    panelSizes.Add(pair.Key);
                }
            }
            panelSizes.Shuffle();
            return(panelSizes);
        }
        private static List <PanelSize> SplitWallIntoPanels(float wallLength)
        {
            Dictionary <PanelSize, int> knapsack = PTUtils.Knapsack(sizeValues, wallLength);
            var panelSizes = new List <PanelSize>();

            foreach (var pair in knapsack)
            {
                for (var i = 0; i < pair.Value; i++)
                {
                    panelSizes.Add(pair.Key);
                }
            }
            panelSizes.Shuffle();
            return(panelSizes);
        }
    public ThumbExportElement ToExport()
    {
        //构造prefabinfo
        var prefabInfo = new PPPrefabInfo()
        {
            Name          = name,
            Model         = model,
            Material      = material,
            MaterialInfos = matinfos,
            Texs          = texs
        };

        if (prefabInfo.IsSticker)
        {
            prefabInfo.Texture = skins[0].skin_name;
        }

        //构造PPBlockInfo
        var nodeInfo = new PPBlockInfo()
        {
            Prefab = name,
        };
        var thumb = nodeInfo.Prefab;

        nodeInfo.Textures = new PPTextureInfo[texs.Count];
        for (var i = 0; i < texs.Count; i++)
        {
            var t = texs[i];
            nodeInfo.Textures[i] = new PPTextureInfo()
            {
                Prefab      = t.Name,
                EditorAngle = t.editor_angle,
                EditorPos   = t.editor_pos
            };
            thumb += "-" + t.Name;
        }
        nodeInfo.Thumb = nodeInfo.IsStamp ? nodeInfo.Prefab + "_" + PTUtils.Md5Sum(thumb) : nodeInfo.Prefab;

        return(new ThumbExportElement()
        {
            eulerAngle = angle,
            PrefabInfo = prefabInfo,
            BlockInfo = nodeInfo
        });
    }
        private void Awake()
        {
            pixels        = new Color[config.width * config.height];
            texture       = PTUtils.CreateTexture(config.width, config.height, Color.clear);
            image.texture = texture;

            cells = new Cells(config);

            #region Controls

            header = InstantiateControl <TextControl>(leftPanel);
            header.transform.SetAsFirstSibling();

            var currentRulesetName = RulesetName.Life;
            SelectRuleset(currentRulesetName);

            InstantiateToggle(RulesetName.Life, currentRulesetName);
            InstantiateToggle(RulesetName.Mazectric, currentRulesetName);
            InstantiateToggle(RulesetName.Coral, currentRulesetName);
            InstantiateToggle(RulesetName.WalledCities, currentRulesetName);
            InstantiateToggle(RulesetName.Coagulations, currentRulesetName);
            InstantiateToggle(RulesetName.Anneal, currentRulesetName);
            InstantiateToggle(RulesetName.Majority, currentRulesetName);

            InstantiateControl <SliderControl>(leftPanel).Initialize("Start noise", 0, 1, config.startNoise, value =>
            {
                config.startNoise = value;
                Generate();
            });

            InstantiateControl <ToggleControl>(leftPanel).Initialize("Alive borders", config.aliveBorders, value =>
            {
                config.aliveBorders = value;
                Generate();
            });

            InstantiateControl <ButtonControl>(leftPanel).Initialize("Generate", Generate);

            #endregion Controls

            Generate();
            SetupSkyboxAndPalette();
        }
        private void Awake()
        {
            int textureWidth  = MazeUtility.GetTextureWidth(config.width);
            int textureHeight = MazeUtility.GetTextureHeight(config.height);

            texture           = PTUtils.CreateTexture(textureWidth, textureHeight, Color.black);
            mazeImage.texture = texture;

            var header = InstantiateControl <TextControl>(algorithmsGroup.transform.parent);

            header.Initialize("Generator algorithm");
            header.transform.SetAsFirstSibling();

            InstantiateToggle(MazeJob.Algorithm.RandomTraversal, "Random traversal");
            InstantiateToggle(MazeJob.Algorithm.RandomDepthFirstTraversal, "Random depth-first traversal");

            InstantiateControl <ButtonControl>(leftPanel).Initialize("Generate new maze", Generate);

            Generate();
            SetupSkyboxAndPalette();
        }
Exemple #16
0
        private List <BrickSize> BrickSizes(float width)
        {
            var knapsack = GetRandomKnapsack(width);

            while (KnapsackWidth(knapsack) > width)
            {
                knapsack = GetRandomKnapsack(width);
            }

            width   -= KnapsackWidth(knapsack);
            knapsack = PTUtils.Knapsack(sizeValues, width, knapsack);
            var brickSizes = new List <BrickSize>();

            foreach (var pair in knapsack)
            {
                for (var i = 0; i < pair.Value; i++)
                {
                    brickSizes.Add(pair.Key);
                }
            }
            brickSizes.Shuffle();
            return(brickSizes);
        }