コード例 #1
0
    public void generateSkin(Color c1, Color c2)
    {
        this.c1 = c1;
        this.c2 = c2;
        var noise   = new PerlinNoise2D(10, 10, 5);
        var texture = new Texture2D(100, 100, TextureFormat.RGBA32, false);

        for (var x = 0; x < 100; x++)
        {
            for (var y = 0; y < 100; y++)
            {
                var c     = noise.at(x / 10f, y / 10f) / 2 + .5f;
                var color = Color.Lerp(c1, c2, c);
                texture.SetPixel(x, y, color);
            }
        }

        texture.Apply();

        var renderer     = GetComponent <Renderer>();
        var tempMaterial = new Material(renderer.sharedMaterial);

        tempMaterial.mainTexture = texture;
        tempMaterial.SetTexture(EmissionMap, texture);
        tempMaterial.SetColor(EmissionColor, Color.white);

        renderer.sharedMaterial = tempMaterial;
    }
コード例 #2
0
ファイル: WoodenTexture.cs プロジェクト: fniyaz/PCGG
    // todo probably don't need
    public static Texture2D getCracks(int width, int height)
    {
        var xyPeriod  = 8.0f;  //number of rings
        var turbPower = 0.2f;  //makes twists
        var turbSize  = 32.0f; //initial size of the turbulence

        var noise = new PerlinNoise2D(width / 10, height / 100, 1);

        var texWid  = width;
        var texHei  = height;
        var texture = new Texture2D(texWid, texHei, TextureFormat.ARGB32, false);

        for (int x = 0; x < texWid; x++)
        {
            for (int y = 0; y < texHei; y++)
            {
                var noiseVal = noise.at((float)x / 10, (float)y / 100) / (.5f * Mathf.Sqrt(2)) + .5f;
                noiseVal = noiseVal > 0.9 ? (noiseVal - 0.9f) / (1 - 0.9f) : 0;


                var noiseColor = new Color(noiseVal, noiseVal, noiseVal);
                var treeColor  = noiseColor;

                texture.SetPixel(x, y, Color.Lerp(treeColor, noiseColor, 0f));
            }
        }

        texture.Apply();

        return(texture);
    }
コード例 #3
0
ファイル: Planet.cs プロジェクト: fniyaz/PCGG
    public void generateSkin(GameObject sun, Color c1, Color c2, float speed, float aS)
    {
        this.aS    = aS;
        this.sun   = sun;
        this.speed = speed;
        var noise   = new PerlinNoise2D(7, 7, 5);
        var texture = new Texture2D(70, 70, TextureFormat.RGBA32, false);

        for (var x = 0; x < 70; x++)
        {
            for (var y = 0; y < 70; y++)
            {
                var c     = noise.at(x / 10f, y / 10f) / 2 + .5f;
                var color = Color.Lerp(c1, c2, c);
                texture.SetPixel(x, y, color);
            }
        }
        texture.Apply();

        var renderer     = GetComponent <Renderer>();
        var tempMaterial = new Material(renderer.sharedMaterial);

        tempMaterial.mainTexture = texture;

        renderer.sharedMaterial = tempMaterial;
    }
コード例 #4
0
        BiomeData Generate2DBiomeData()
        {
            BiomeData        biomeData     = new BiomeData();
            BiomeSwitchGraph switchGraph   = new BiomeSwitchGraph();
            Sampler2D        terrainHeight = new Sampler2D(size, step);
            PerlinNoise2D    perlin        = new PerlinNoise2D(seed);

            perlin.UpdateParams(seed, step, octaves, persistance, lacunarity);

            perlin.ComputeSampler2D(terrainHeight);

            terrainHeight = NoiseFunctions.Map(terrainHeight, 0, maxTerrainHeight);

            biomeData.waterLevel  = waterLevel;
            biomeData.isWaterless = isWaterless;
            biomeData.UpdateSamplerValue(BiomeSamplerName.terrainHeight, terrainHeight);
            if (!isWaterless)
            {
                biomeData.UpdateSamplerValue(BiomeSamplerName.waterHeight, GenerateWaterHeight(terrainHeight));
            }

            switchGraph.BuildTestGraph(0);

            biomeData.biomeMap         = Generate2DBiomeMap(0);
            biomeData.biomeSwitchGraph = switchGraph;
            return(biomeData);
        }
コード例 #5
0
ファイル: AsteroidMeshGenerator.cs プロジェクト: fniyaz/PCGG
    public static Mesh generateAsteroid(float radius, float distortion)
    {
        var mesh = new Mesh();

        mesh.name = "Asteroid";

        var horizontalLines = 40;
        var verticalLines   = 40;

        var vertices = new Vector3[horizontalLines * verticalLines];
        var posMap   = new Dictionary <(int, int), int>();

        List <Vector2> newUVs       = new List <Vector2>();
        List <int>     newTriangles = new List <int>();
        List <Vector3> normals      = new List <Vector3>();


        var noise = new PerlinNoise2D(5, 5, 5);

        int index  = 0;
        var origin = new Vector3(0, 0, 0);

        for (int m = 0; m < horizontalLines; m++)
        {
            for (int n = 0; n < verticalLines - 1; n++)
            {
                var sample = noise.at(m / 8f, n / 8f) * distortion;
                sample *= Mathf.Sin(Mathf.PI * m / (horizontalLines - 1));

                var pos = at(n, m, verticalLines, horizontalLines, radius + sample);
                vertices[index] = pos;
                posMap[(n, m)]  = index;
コード例 #6
0
    private void Start()
    {
        mesh = new Mesh();
        GetComponent <MeshFilter>().mesh = mesh;

        perlinNoise2D = new PerlinNoise2D();

        CreateMeshShape();
        UpdateMesh();
    }
コード例 #7
0
        /// <summary>
        /// コンストラクタ <see cref="MapGenerator" /> class.
        /// </summary>
        /// <param name="amplitude">波の大きさ</param>
        /// <param name="wavePeriod">波の周期</param>
        /// <param name="amplitudeDecreasingRate">波の大きさの1オクターブ毎の変化率</param>
        /// <param name="wavePeriodDecreasingRate">波の周期の1オクターブ毎の変化率</param>
        /// <param name="octaves">ノイズを何回重ねるか</param>
        /// <param name="seed">シード値</param>
        public MapGenerator(float amplitude, float wavePeriod, float amplitudeDecreasingRate, float wavePeriodDecreasingRate, int octaves, int seed)
        {
            this.amplitude  = amplitude;
            this.wavePeriod = wavePeriod;
            this.amplitudeDecreasingRate  = amplitudeDecreasingRate;
            this.wavePeriodDecreasingRate = wavePeriodDecreasingRate;
            this.octaves        = octaves;
            this.noiseGenerator = new PerlinNoise2D(seed);

            Assert.IsTrue(this.amplitude > 0, $"波の大きさは0以下にできません");
            Assert.IsTrue(this.wavePeriod > 0, $"波の周期は0以下にできません");
            Assert.IsTrue((0 < this.amplitudeDecreasingRate) && (this.amplitudeDecreasingRate <= 1f), $"波の大きさの変化率は(0, 1]でなければなりません");
            Assert.IsTrue((0 < this.wavePeriodDecreasingRate) && (this.wavePeriodDecreasingRate <= 1f), $"波の周期の変化率は(0, 1]でなければなりません");
            Assert.IsTrue(this.octaves > 0, $"ノイズを重ねる回数は0以下にできません");
        }
コード例 #8
0
    private void calculateTerrainNoise(ref float[,] heights)
    {
        var scale  = 1 << noiseRandomScale;
        var fscale = (float)scale;
        var wid    = heights.GetLength(0);
        var hei    = heights.GetLength(1);
        var noise  = new PerlinNoise2D(wid / scale, hei / scale);

        for (var x = 0; x < wid; x++)
        {
            for (var y = 0; y < hei; y++)
            {
                heights[x, y] = (noise.at(x / fscale, y / fscale) / 0.5f + 1) / 2;
            }
        }
    }
コード例 #9
0
    public PerlinNoise2D(int wid, int hei, int octaves)
    {
        if (octaves < 1)
        {
            throw new ArgumentException("Can't be negative", "octaves");
        }

        if (octaves == 1)
        {
            setUpGrads(wid, hei);
            p = null;
        }
        else
        {
            setUpGrads(wid, hei);
            p = new PerlinNoise2D(wid * 2, hei * 2, octaves - 1);
        }
    }
コード例 #10
0
		public override void OnNodeProcess()
		{
			if (chunkSizeHasChanged)
				output.Resize(chunkSize);

			//recalcul perlin noise values with new seed / position.
			if (needUpdate)
			{
				float scale = 40f;
				output.Foreach((x, y) => {
					float nx = (float)x * step + chunkPosition.x;
					float ny = (float)y * step + chunkPosition.z;
					float val = PerlinNoise2D.GenerateNoise(nx / scale, ny / scale, 2, 2, 1, 1, seed);
					for (int i = 0; i < octaves; i++)
						val *= 1.2f;
					return val;
				});
			}
		}
コード例 #11
0
        // PerlinNoise2D produces values from -1 to 1. This forces that noise into the range 0.0 to 1.0
        private double[,] GetPositiveNoise( )
        {
            double[,] noise = new double[mapParams.size.X, mapParams.size.Y];

            PerlinNoise2D.GenPerlinNoise(noise,
                                         mapParams.zoomOut,
                                         mapParams.frequencyMulti,
                                         mapParams.persistence,
                                         mapParams.octaves,
                                         mapParams.seed);

            for (int x = 0; x < mapParams.size.X; x++)
            {
                for (int y = 0; y < mapParams.size.Y; y++)
                {
                    noise[x, y] += 1;
                    noise[x, y] /= 2;
                }
            }

            return(noise);
        }
コード例 #12
0
    static List <Vector2> GenerateRoomVertices(Vector2 p, ROOM_TYPE type)
    {
        List <Vector2> verts      = new List <Vector2>();
        float          roomScale  = 1;
        float          noiseScale = 0.05f;
        int            nVertices  = 40;
        float          degPadd    = (360f / nVertices);
        float          deg        = 125;

        float rx = Random.Range(1f, 1.5f);
        float ry = Random.Range(1f, 1.5f);

        for (int i = 0; i < nVertices; i++, deg += degPadd)
        {
            float x = Mathf.Cos(deg * Mathf.Deg2Rad);
            float y = Mathf.Sin(deg * Mathf.Deg2Rad);

            Vector2 roomPoint     = new Vector2(x * rx, y * ry);
            float   noiseModifier = PerlinNoise2D.GenerateNoise(x + p.x, y + p.y, .05f, 2);
            noiseModifier = (noiseModifier - .5f) * 2 * noiseScale;
            verts.Add(p + roomPoint * roomScale + (roomPoint * noiseModifier));
        }
        return(verts);
    }
コード例 #13
0
ファイル: WoodenTexture.cs プロジェクト: fniyaz/PCGG
    // static Color dark = new Color(139 / 255f, 69 / 255f, 19 / 255f);
    // static Color light = new Color(200 / 255f, 199 / 255f, 137 / 255f);

    public static Texture2D getLines(
        bool vertical,
        int width,
        int height,
        int num,
        Color dark,
        Color light,
        float highGrain = 1,
        float lowGrain  = 1 / 5f,
        float _2dNoise  = 1 / 5f
        )
    {
        var noise          = new PerlinNoise2D(width, height, 5);
        var widthNoise     = new PerlinNoise2D(width, 1, 5);
        var highGrainNoise = new PerlinNoise2D(width, 1, 1);
        var texture        = new Texture2D(width * num, height * num, TextureFormat.RGBA32, false);
        var offset         = Random.Range(0, Mathf.PI * 2);

        if (vertical)
        {
            (width, height) = (height, width);
        }

        for (int y = 0; y < height * num; y++)
        {
            var fy           = (float)y / num;
            var widthDisturb = widthNoise.at(fy, 0.5f) * highGrain;
            widthDisturb += highGrainNoise.at(fy, 0.5f) * lowGrain;

            for (int x = 0; x < width * num; x++)
            {
                var fx       = (float)x / num;
                var noiseVal = noise.at(fx, fy);

                var pos = new Vector2(fx, fy);
                pos = shift(pos, noiseVal * _2dNoise);

                var linePattern = getLinePattern(pos, widthDisturb, offset);

                var col = Color.Lerp(
                    light,
                    dark,
                    Mathf.Pow(linePattern, 1f / 8)
                    );

                if (linePattern > 0.95f)
                {
                    col = Color.Lerp(Color.black, dark, 0.5f + 1 / 0.1f * (1 - linePattern));
                    // col = Color.Lerp(Color.black, dark, 0.5f);
                }

                var disCol = new Color(col.r, col.g, col.b);

                if (vertical)
                {
                    texture.SetPixel(y, x, disCol);
                }
                else
                {
                    texture.SetPixel(x, y, disCol);
                }
            }
        }

        texture.Apply();

        return(texture);
    }
コード例 #14
0
ファイル: TerrainToolkit.cs プロジェクト: Antrum/Unity
 private float[,] generatePerlin(float[,] heightMap, Vector2 arraySize, GeneratorProgressDelegate generatorProgressDelegate)
 {
     int Tw = (int) arraySize.x;
     int Th = (int) arraySize.y;
     // Zero...
     for (int My = 0; My < Th; My++) {
         for (int Mx = 0; Mx < Tw; Mx++) {
             heightMap[Mx, My] = 0.0f;
         }
     }
     PerlinNoise2D[] noiseFunctions = new PerlinNoise2D[perlinOctaves];
     int freq = perlinFrequency;
     float amp = 1.0f;
     int i;
     for (i = 0; i < perlinOctaves; i++) {
         noiseFunctions[i] = new PerlinNoise2D(freq, amp);
         freq *= 2;
         amp /= 2;
     }
     for (i = 0; i < perlinOctaves; i++) {
         double xStep = (float) Tw / (float) noiseFunctions[i].Frequency;
         double yStep = (float) Th / (float) noiseFunctions[i].Frequency;
         for (int Px = 0; Px < Tw; Px++) {
             for (int Py = 0; Py < Th; Py++) {
                 int Pa = (int) (Px / xStep);
                 int Pb = Pa + 1;
                 int Pc = (int) (Py / yStep);
                 int Pd = Pc + 1;
                 double interpValue = noiseFunctions[i].getInterpolatedPoint(Pa, Pb, Pc, Pd, (Px / xStep) - Pa, (Py / yStep) - Pc);
                 heightMap[Px, Py] += (float) (interpValue * noiseFunctions[i].Amplitude);
             }
         }
         // Show progress...
         float percentComplete = (i + 1) / perlinOctaves;
         generatorProgressDelegate("Perlin Generator", "Generating height map. Please wait.", percentComplete);
     }
     GeneratorProgressDelegate normaliseProgressDelegate = new GeneratorProgressDelegate(dummyGeneratorProgress);
     float oldNormaliseMin = normaliseMin;
     float oldNormaliseMax = normaliseMax;
     float oldNormaliseBlend = normaliseBlend;
     normaliseMin = 0.0f;
     normaliseMax = 1.0f;
     normaliseBlend = 1.0f;
     heightMap = normalise(heightMap, arraySize, normaliseProgressDelegate);
     normaliseMin = oldNormaliseMin;
     normaliseMax = oldNormaliseMax;
     normaliseBlend = oldNormaliseBlend;
     for (int Px = 0; Px < Tw; Px++) {
         for (int Py = 0; Py < Th; Py++) {
             heightMap[Px, Py] = heightMap[Px, Py] * perlinAmplitude;
         }
     }
     for (i = 0; i < perlinOctaves; i++) {
         noiseFunctions[i] = null;
     }
     noiseFunctions = null;
     return heightMap;
 }
コード例 #15
0
        // Helpers/Value
        private static float GetValue(float x, float y)
        {
            const float scale = 1f / 6;

            return(PerlinNoise2D.GetNoise01(x * scale, y * scale, 1));
        }
コード例 #16
0
    /**
     * Apply Template To Map
     * Method responsible for modifying the nodes to reflect the template.
     */
    public void ApplyTemplateToMap(MapTemplate mapTemplate)
    {
        Debug.Log("ApplyTemplateToMap");
        // Initialize perlin noise generator to make terrain
        m_envPerlinNoise = new PerlinNoise2D(GetMapRowCount(), GetMapColCount());


        m_nodeList = new SortedDictionary <int, SortedDictionary <int, NodeV2> >();

        Vector3 envPos;
        int     col = 0;
        int     row = 0;


        int N           = -m_tileSize / 2;
        int S           = m_tileSize / 2;
        int E           = m_tileSize / 2;
        int W           = -m_tileSize / 2;
        int westWallCol = GetMapColCount() - 1;

        int northWallRow = GetMapRowCount() - 1;
        //isPlayablePerimeter

        Vector3 westWallOffset  = new Vector3(0, 0, -m_tileSize / 2);
        Vector3 eastWallOffset  = new Vector3(0, 0, m_tileSize / 2);
        Vector3 southWallOffset = new Vector3(m_tileSize / 2, 0, 0);
        Vector3 northWallOffset = new Vector3(-m_tileSize / 2, 0, 0);

        int northRow = 0;
        int eastCol  = GetMapRowCount() - 1;
        int westCol  = 0;
        int southRow = GetMapColCount() - 1;

        Vector2Int cornerNE = new Vector2Int(northRow, eastCol);
        Vector2Int cornerSE = new Vector2Int(southRow, eastCol);
        Vector2Int cornerSW = new Vector2Int(southRow, westCol);
        Vector2Int cornerNW = new Vector2Int(northRow, westCol);

        //==================================================

        //              UPDATE CAMERA LIMITATION

        //==================================================
        // Super sketch but effective
        if (m_sketchCameraBounds)
        {
            float axisVal;
            float posOffsetVal;

            axisVal      = (m_tileSize * GetMapColCount() - 1) / 2F;
            posOffsetVal = transform.position.x;
            Vector2 rangeX = new Vector2(posOffsetVal, posOffsetVal) + new Vector2(-axisVal, axisVal - m_tileSize);

            axisVal      = (m_tileSize * GetMapRowCount() - 1) / 2F;
            posOffsetVal = transform.position.z;
            Vector2 rangeZ = new Vector2(posOffsetVal, posOffsetVal) + new Vector2(-axisVal, axisVal - m_tileSize);


            axisVal      = 100;
            posOffsetVal = transform.position.y + 5;
            Vector2 rangeY = new Vector2(posOffsetVal, posOffsetVal + axisVal);


            UpdateCameraLimitations(rangeX, rangeY, rangeZ);
        }

        //==================================================

        //                GENERATE BASE TILES

        //==================================================
        // Generate Tiles
        float mapWidth  = m_tileSize * GetMapColCount();
        float mapHeight = m_tileSize * GetMapRowCount();

        NodeTemplate nodeTemplate;

        for (row = 0; row < GetMapRowCount(); ++row)
        {
            m_nodeList.Add(row, new SortedDictionary <int, NodeV2>());

            for (col = 0; col < GetMapColCount(); ++col)
            {
                //----------------------------------------------

                // Create Tile at position

                float tileRowPosX = m_tileSize * col - mapWidth / 2;
                float tileRowPosZ = m_tileSize * row - mapHeight / 2;

                Vector3 tilePos = transform.position + new Vector3(tileRowPosX, 0, tileRowPosZ);


                // Decide which prefab
                nodeTemplate = mapTemplate.GetNode(row, col);
                GameObject prefab = nodeTemplate.type == "path" ||
                                    nodeTemplate.type == "start" ||
                                    nodeTemplate.type == "end"
                                    ? m_pathTile : m_grassTile;


                GameObject spawnNode     = Instantiate(prefab, tilePos, Quaternion.identity, this.gameObject.transform);
                NodeV2     spawnInstance = spawnNode.GetComponent <NodeV2>();
                m_nodeList[row].Add(col, spawnInstance);



                //----------------------------------------------

                // Add vegitation to terrain

                if (nodeTemplate.type == "terrain" && nodeTemplate.isEnvPlacable)
                {
                    OddsTable subCategoryTable;

                    // Choose which table to role on
                    if (nodeTemplate.isPlayablePerimeter)
                    {
                        subCategoryTable = m_shrubOddsTable;
                    }
                    else
                    {
                        string rolledKey;
                        if (Random.Range(0F, 10f) / 10F > 0.2F)
                        {
                            rolledKey = m_environmentOddsTable.GetForNormalizedRoll(m_envPerlinNoise.GetValue(row, col));
                        }
                        else
                        {
                            rolledKey = m_environmentOddsTable.Roll();
                        }

                        subCategoryTable = (OddsTable)m_environmentOddsTable.GetPayload(rolledKey);
                    }


                    // Table exists
                    if (subCategoryTable != null)
                    {
                        // Decide prefab at Random
                        string rolledKey;

                        if (Random.Range(0, 1) > 0.5)
                        {
                            rolledKey = subCategoryTable.GetForNormalizedRoll(Mathf.Clamp(Random.Range(-0.2F, 0.2F) + m_envPerlinNoise.GetValue(row, col), 0, 1));
                        }
                        else
                        {
                            rolledKey = subCategoryTable.Roll();
                        }
                        GameObject envPrefab = (GameObject)subCategoryTable.GetPayload(rolledKey);
                        if (envPrefab != null)
                        {
                            SpawnNodeEnv(spawnInstance, envPrefab);
                        }
                    }
                }
                //________________________________________________
            }
        }



        //==================================================

        //                APPLY TILE DATA

        //==================================================
        // Read directly from the map
        NodeTemplate template;

        for (row = 0; row < GetMapRowCount(); ++row)
        {
            for (col = 0; col < GetMapColCount(); ++col)
            {
                if (GetNode(row, col))
                {
                    NodeV2 node = GetNode(row, col);
                    template = mapTemplate.GetNode(row, col);
                    node.SetNodeType(template.type);
                    node.SetIsPlayablePerimeter(template.isPlayablePerimeter);
                    node.SetIsTowerPlacable(template.isTowerPlacable);
                    node.SetIsEnvPlacable(template.isEnvPlacable);
                    node.SetCoordinate(new Vector2Int(col, row));
                }
            }
        }



        //==================================================

        //                DECORATE PATHS

        //==================================================

        m_pathSegments = mapTemplate.GetPathSegments();
        int        globalPathTileCount  = 0;
        int        segmentLargestIndex  = m_pathSegments.Count - 1;
        int        previousSegmentIndex = -1;
        Vector2Int currentPos           = new Vector2Int(0, 0);
        Vector2Int previousPos          = new Vector2Int(0, 0);

        for (int s = 0; s <= segmentLargestIndex; ++s)
        {
            bool isLastSegment = s == segmentLargestIndex;

            PathSegment segment = m_pathSegments[s];

            int deltaX = segment.end.x - segment.start.x;
            int deltaY = segment.end.y - segment.start.y;

            int directionX = deltaX == 0 ? 0 : deltaX / Mathf.Abs(deltaX);
            int directionY = deltaY == 0 ? 0 : deltaY / Mathf.Abs(deltaY);



            //isLastTile, isFirstTile

            // Set up 2D iteration
            int  dy = 0;
            int  dx = 0;
            bool isLastIteration = false;
            bool isDone          = false;
            while (!isDone)
            {
                // Set loop ending flag
                if (isLastIteration)
                {
                    isDone = true;
                }
                //----------------------
                // Execute for-loop contents with dx and dy

                // Get tile location
                row = segment.start.y + dy;
                col = segment.start.x + dx;

                // Select colour
                bool isFirstTile       = globalPathTileCount == 0;
                bool isLastTile        = isLastSegment && isLastIteration;
                bool isDirectionChange = s != previousSegmentIndex;


                currentPos = new Vector2Int(col, row);
                if (isFirstTile)
                {
                    previousPos = currentPos;
                }


                //====================================================================
                // If the segment is not overlapping form the last segment
                if (previousPos != currentPos || isFirstTile)
                {
                    NodeV2 currentTile = GetNode(row, col);

                    Transform parentTransform = currentTile.gameObject.transform;
                    envPos = currentTile.gameObject.transform.position + currentTile.GetEnvOffset();


                    Vector3    wallPos;
                    Quaternion wallRotation;
                    nodeTemplate = mapTemplate.GetNode(row, col);



                    // -------------------------------------------------------------------

                    //                          ADD PATH WALLS

                    // -------------------------------------------------------------------
                    if (currentTile.GetNodeType() != "end" && m_pathWall != null)
                    {
                        if (nodeTemplate.hasWall[(int)NodeTemplate.Wall.N])
                        {
                            wallPos      = envPos + new Vector3(N, 0, 0);
                            wallRotation = Quaternion.AngleAxis(90, Vector3.up);
                            Instantiate(m_pathWall, wallPos, wallRotation, parentTransform);
                        }
                        if (nodeTemplate.hasWall[(int)NodeTemplate.Wall.S])
                        {
                            wallPos      = envPos + new Vector3(S, 0, 0);
                            wallRotation = Quaternion.AngleAxis(-90, Vector3.up);
                            Instantiate(m_pathWall, wallPos, wallRotation, parentTransform);
                        }
                        if (nodeTemplate.hasWall[(int)NodeTemplate.Wall.E])
                        {
                            wallPos      = envPos + new Vector3(0, 0, E);
                            wallRotation = Quaternion.AngleAxis(180, Vector3.up);
                            Instantiate(m_pathWall, wallPos, wallRotation, parentTransform);
                        }
                        if (nodeTemplate.hasWall[(int)NodeTemplate.Wall.W])
                        {
                            wallPos      = envPos + new Vector3(0, 0, W);
                            wallRotation = Quaternion.AngleAxis(0, Vector3.up);
                            Instantiate(m_pathWall, wallPos, wallRotation, parentTransform);
                        }
                    }



                    // -------------------------------------------------------------------

                    //                          ADD PATH PILLARS

                    // -------------------------------------------------------------------
                    Quaternion pillarRotation = Quaternion.identity;
                    if (m_pathPiller != null)
                    {
                        if (nodeTemplate.hasPillar[(int)NodeTemplate.Pillar.NE])
                        {
                            Vector3 pillarPos = envPos + new Vector3(N, 0, E);
                            Instantiate(m_pathPiller, pillarPos, pillarRotation, parentTransform);
                        }
                        if (nodeTemplate.hasPillar[(int)NodeTemplate.Pillar.NW])
                        {
                            Vector3 pillarPos = envPos + new Vector3(N, 0, W);
                            Instantiate(m_pathPiller, pillarPos, pillarRotation, parentTransform);
                        }
                        if (nodeTemplate.hasPillar[(int)NodeTemplate.Pillar.SE])
                        {
                            Vector3 pillarPos = envPos + new Vector3(S, 0, E);
                            Instantiate(m_pathPiller, pillarPos, pillarRotation, parentTransform);
                        }
                        if (nodeTemplate.hasPillar[(int)NodeTemplate.Pillar.SW])
                        {
                            Vector3 pillarPos = envPos + new Vector3(S, 0, W);
                            Instantiate(m_pathPiller, pillarPos, pillarRotation, parentTransform);
                        }
                    }


                    if (currentTile.GetIsPath() && currentTile.GetPlayablePerimeter() && currentTile.GetNodeType() != "end")
                    {
                        Quaternion pillarRot = Quaternion.identity;
                        if (m_leftEntrancePillar != null)
                        {
                            Instantiate(m_leftEntrancePillar, envPos + westWallOffset + northWallOffset, pillarRot, this.gameObject.transform);
                        }
                        if (m_rightEntrancePillar != null)
                        {
                            Instantiate(m_rightEntrancePillar, envPos + westWallOffset + southWallOffset, pillarRot, this.gameObject.transform);
                        }
                    }

                    /*
                     * if (currentTile.GetNodeType() == "end")
                     * {
                     *  Quaternion pillarRot = Quaternion.AngleAxis(180, Vector3.up);
                     *  Instantiate(m_pathPiller, envPos + eastWallOffset + southWallOffset, pillarRot, this.gameObject.transform);
                     *  Instantiate(m_pathPiller, envPos + eastWallOffset + northWallOffset, pillarRot, this.gameObject.transform);
                     * }
                     */


                    if (currentTile.GetNodeType() == "end" && m_finalScene != null)
                    {
                        currentTile.m_height = 11F;
                        Vector3    endPos = currentTile.gameObject.transform.position;
                        Quaternion endRot = Quaternion.AngleAxis(0, Vector3.up);
                        Instantiate(m_finalScene, endPos, endRot, this.gameObject.transform);
                    }



                    if (currentTile.GetNodeType() == "start" && m_startScene != null)
                    {
                        Vector3    startPos = currentTile.gameObject.transform.position + new Vector3(0, 0, -m_tileSize);//HERE
                        Quaternion startRot = Quaternion.AngleAxis(0, Vector3.up);
                        Instantiate(m_startScene, startPos, startRot, this.gameObject.transform);
                    }



                    // -------------------------------------------------------------------

                    //                          ADD Tiles

                    // -------------------------------------------------------------------

                    Quaternion tileRotation = Quaternion.identity;
                    Vector3    tilePos;
                    GameObject tilePrefrab = null;
                    float      tileOffset  = 0;

                    tilePos     = envPos + new Vector3(N / 2, tileOffset, E / 2);
                    tilePrefrab = (GameObject)m_tileOddsTable.GetPayload(m_tileOddsTable.Roll());
                    if (tilePrefrab != null)
                    {
                        Instantiate(tilePrefrab, tilePos, tileRotation, parentTransform);
                    }

                    tilePos     = envPos + new Vector3(S / 2, tileOffset, E / 2);
                    tilePrefrab = (GameObject)m_tileOddsTable.GetPayload(m_tileOddsTable.Roll());
                    if (tilePrefrab != null)
                    {
                        Instantiate(tilePrefrab, tilePos, tileRotation, parentTransform);
                    }

                    tilePos     = envPos + new Vector3(S / 2, tileOffset, W / 2);
                    tilePrefrab = (GameObject)m_tileOddsTable.GetPayload(m_tileOddsTable.Roll());
                    if (tilePrefrab != null)
                    {
                        Instantiate(tilePrefrab, tilePos, tileRotation, parentTransform);
                    }

                    tilePos     = envPos + new Vector3(N / 2, tileOffset, W / 2);
                    tilePrefrab = (GameObject)m_tileOddsTable.GetPayload(m_tileOddsTable.Roll());
                    if (tilePrefrab != null)
                    {
                        Instantiate(tilePrefrab, tilePos, tileRotation, parentTransform);
                    }



                    // -------------------------------------------------------------------

                    //                          ADD LAMPS

                    // -------------------------------------------------------------------
                    if (currentTile.GetNodeType() != "end" && m_pathLamp != null)
                    {
                        float      lampOffset   = 3;
                        Quaternion lampRotation = Quaternion.identity;
                        if (nodeTemplate.hasLamp[(int)NodeTemplate.Pillar.NE])
                        {
                            Vector3 pillarPos = envPos + new Vector3(N, lampOffset, E);
                            lampRotation = Quaternion.AngleAxis(-90, Vector3.up);
                            Instantiate(m_pathLamp, pillarPos, lampRotation, parentTransform);
                        }
                        if (nodeTemplate.hasLamp[(int)NodeTemplate.Pillar.SE])
                        {
                            Vector3 pillarPos = envPos + new Vector3(S, lampOffset, E);
                            lampRotation = Quaternion.AngleAxis(0, Vector3.up);
                            Instantiate(m_pathLamp, pillarPos, lampRotation, parentTransform);
                        }
                        if (nodeTemplate.hasLamp[(int)NodeTemplate.Pillar.SW])
                        {
                            Vector3 pillarPos = envPos + new Vector3(S, lampOffset, W);
                            lampRotation = Quaternion.AngleAxis(90, Vector3.up);
                            Instantiate(m_pathLamp, pillarPos, lampRotation, parentTransform);
                        }
                        if (nodeTemplate.hasLamp[(int)NodeTemplate.Pillar.NW])
                        {
                            Vector3 pillarPos = envPos + new Vector3(N, lampOffset, W);
                            lampRotation = Quaternion.AngleAxis(180, Vector3.up);
                            Instantiate(m_pathLamp, pillarPos, lampRotation, parentTransform);
                        }
                    }
                } // End segment does not overlatp
                  //====================================================================



                // Increment tile could to tell first tile
                ++globalPathTileCount;
                //----------------------
                // Increment loop
                if (dx != deltaX)
                {
                    dx += directionX;
                }
                else if (dy != deltaY)
                {
                    dy += directionY;
                }
                // Detect going on last iteration
                isLastIteration = (dx == deltaX && dy == deltaY);

                previousPos          = currentPos;
                previousSegmentIndex = s;
            }
        }



        //==================================================

        //                ADD OUTTER WALLS

        //==================================================
        if (m_outterWall != null)
        {
            // NORTH WALL
            for (int i = 0; i < GetMapRowCount(); ++i)
            {
                Vector2Int coord    = new Vector2Int(northRow, i);
                NodeV2     nodeInst = GetNode(coord);
                Vector3    nodePos  = nodeInst.gameObject.transform.position;


                if (!nodeInst.GetIsPath())
                {
                    Quaternion outterWallRot = Quaternion.AngleAxis(90, Vector3.up);
                    Instantiate(m_outterWall, nodePos + nodeInst.GetEnvOffset() + northWallOffset, outterWallRot, this.gameObject.transform);
                }
            }
            // SOUTH WALL
            for (int i = 0; i < GetMapRowCount(); ++i)
            {
                Vector2Int coord    = new Vector2Int(southRow, i);
                NodeV2     nodeInst = GetNode(coord);
                Vector3    nodePos  = nodeInst.gameObject.transform.position;
                if (!nodeInst.GetIsPath())
                {
                    Quaternion outterWallRot = Quaternion.AngleAxis(-90, Vector3.up);
                    Instantiate(m_outterWall, nodePos + nodeInst.GetEnvOffset() + southWallOffset, outterWallRot, this.gameObject.transform);
                }
            }



            // EAST WALL
            for (int i = 0; i < GetMapColCount(); ++i)
            {
                Vector2Int coord    = new Vector2Int(i, eastCol);
                NodeV2     nodeInst = GetNode(coord);
                Vector3    nodePos  = nodeInst.gameObject.transform.position;
                if (!nodeInst.GetIsPath())
                {
                    Quaternion outterWallRot = Quaternion.AngleAxis(180, Vector3.up);
                    Instantiate(m_outterWall, nodePos + nodeInst.GetEnvOffset() + eastWallOffset, outterWallRot, this.gameObject.transform);
                }
            }

            // WEST WALL
            for (int i = 0; i < GetMapColCount(); ++i)
            {
                Vector2Int coord    = new Vector2Int(i, westCol);
                NodeV2     nodeInst = GetNode(coord);
                Vector3    nodePos  = nodeInst.gameObject.transform.position;
                if (!nodeInst.GetIsPath())
                {
                    Quaternion outterWallRot = Quaternion.AngleAxis(0, Vector3.up);
                    Instantiate(m_outterWall, nodePos + nodeInst.GetEnvOffset() + westWallOffset, outterWallRot, this.gameObject.transform);
                }
            }
        }



        //==================================================

        //                ADD OUTTER PILLARS

        //==================================================
        if (m_outterPillar != null)
        {
            // NE PILLAR
            if (true)
            {
                NodeV2  nodeInst  = GetNode(cornerNE);
                Vector3 posOffset = northWallOffset + eastWallOffset;
                Vector3 nodePos   = nodeInst.gameObject.transform.position;
                Instantiate(m_outterPillar, nodePos + nodeInst.GetEnvOffset() + posOffset, Quaternion.identity, this.gameObject.transform);
            }


            // NW PILLAR
            if (true)
            {
                NodeV2  nodeInst  = GetNode(cornerNW);
                Vector3 posOffset = northWallOffset + westWallOffset;
                Vector3 nodePos   = nodeInst.gameObject.transform.position;
                Instantiate(m_outterPillar, nodePos + nodeInst.GetEnvOffset() + posOffset, Quaternion.identity, this.gameObject.transform);
            }

            // SW PILLAR
            if (true)
            {
                NodeV2  nodeInst  = GetNode(cornerSW);
                Vector3 posOffset = southWallOffset + westWallOffset;
                Vector3 nodePos   = nodeInst.gameObject.transform.position;
                Instantiate(m_outterPillar, nodePos + nodeInst.GetEnvOffset() + posOffset, Quaternion.identity, this.gameObject.transform);
            }


            // SE PILLAR
            if (true)
            {
                NodeV2  nodeInst  = GetNode(cornerSE);
                Vector3 posOffset = southWallOffset + eastWallOffset;
                Vector3 nodePos   = nodeInst.gameObject.transform.position;
                Instantiate(m_outterPillar, nodePos + nodeInst.GetEnvOffset() + posOffset, Quaternion.identity, this.gameObject.transform);
            }
        }
    }
コード例 #17
0
ファイル: PerlinNoise2D.cs プロジェクト: orf53975/worldcraft
 public NoiseArray2D(float scale)
 {
     noise = new PerlinNoise2D(scale);
 }
コード例 #18
0
 public override void OnNodeEnable()
 {
     output   = new Sampler2D(chunkSize, step);
     perlin2D = new PerlinNoise2D(seed);
 }
コード例 #19
0
 public override void OnNodeEnable()
 {
     output   = new Sampler2D(chunkSize, step);
     perlin2D = new PerlinNoise2D();
     delayedChanges.BindCallback(noiseSettingsChangedKey, (unused) => NotifyReload());
 }