示例#1
0
    public static HightMap GenHightMap(MeshSettings meshSettings, HightMapSettings settings, Vector2 center)
    {
        AnimationCurve animationCurve_t = new AnimationCurve(settings.animationCurve.keys);

        float minV = float.MaxValue;
        float maxV = float.MinValue;

        float[,] falloffMap = null;

        if (settings.useFalloff)
        {
            if (falloffMap == null)
            {
                falloffMap = fallofGenerator.GenerateFalloff(meshSettings.numberVerticisPerLine + 2, settings.FalloffBlur, settings.FalloffSize);
            }
        }

        float[,] valuse = PerlinNoise.GeneratorNoise(meshSettings.numberVerticisPerLine + 2, meshSettings.numberVerticisPerLine + 2, settings.noiseSettings, center);

        //Erode
        valuse = HightMap.ConwertTabBack(Erosion.Erode(HightMap.ConwertTab(valuse, meshSettings.numberVerticisPerLine + 2), settings, meshSettings, settings.erosionShader, 1), meshSettings.numberVerticisPerLine + 2);



        for (int i = 0; i < meshSettings.numberVerticisPerLine + 2; i++)
        {
            for (int j = 0; j < meshSettings.numberVerticisPerLine + 2; j++)
            {
                if (settings.useFalloff)
                {
                    valuse[i, j] = Mathf.Clamp(valuse[i, j] - falloffMap[i, j], 0, 1) * animationCurve_t.Evaluate(valuse[i, j]) * settings.heightMultiplayer;
                }
                else
                {
                    valuse[i, j] *= animationCurve_t.Evaluate(valuse[i, j]) * settings.heightMultiplayer;
                }
                if (valuse[i, j] > maxV)
                {
                    maxV = valuse[i, j];
                }
                if (valuse[i, j] < minV)
                {
                    minV = valuse[i, j];
                }
            }
        }



        return(new HightMap(valuse, minV, maxV));
    }
    public IEnumerator GenerateEnvironment(HightMap heightMap, MechData meshData, MeshSettings meshSettings, HightMapSettings hightMapSettings, EnvironmentData environmentData, int mapChunkSize, float scale, float min, float max)
    {
        int seed;

        if (environmentData.usingHeightMapSeed)
        {
            seed = hightMapSettings.noiseSettings.seed;
        }
        else
        {
            seed = environmentData.seed;
        }

        System.Random prng = new System.Random(seed);


        bool useFlatSheadedB            = false;
        int  flatSheadedChunkSizeIndexB = 0;

        if (meshSettings.useFlatShader)
        {
            flatSheadedChunkSizeIndexB  = meshSettings.chunkSizeIndex;
            useFlatSheadedB             = true;
            meshSettings.chunkSizeIndex = meshSettings.flatSheadedChunkSizeIndex;
            meshSettings.useFlatShader  = false;
        }

        for (int i = 0; i < environmentData.types.Length; i++)
        {
            panelProcess.setNumer(i + 1 + "/" + environmentData.types.Length);
            panelProcess.setLabel("Environment ");

            EnvironmentData.Types now = environmentData.types[i];
            float[,] noise = PerlinNoise.GeneratorNoise(mapChunkSize + 2, mapChunkSize + 2, now.noiseData.noiseSettings, Vector2.zero);

            float[] noisMapEnd = HightMap.ConwertTab(noise, mapChunkSize + 2);
            int     msi        = (now.LOD == 0) ? 1 : now.LOD * 2;
            Vector3 lastPos    = Vector3.zero;
            int     len        = ((int)(mapChunkSize + 2) / msi) + 1;
            len = len * len;

            Vector3[] points          = mechDraw.GenerateMech(heightMap.value, meshSettings, now.LOD).vertices;
            Vector3[] orginalVerticis = meshData.vertices;

            for (int j = 0; j < len; j++)
            {
                Vector3 nowPos = Vector3.zero;
                if ((positioningMode == PositioningMode.Calculation) || (positioningMode == PositioningMode.BothMode))
                {
                    nowPos = orginalVerticis[CalculationPos(points, orginalVerticis, j, len)];
                }
                else
                {
                    nowPos = points[j];
                }


                panelProcess.setValue((float)j / len);

                float wynik = map(min, max, 0, 1, nowPos.y);


                //if (true)
                if (noisMapEnd[j] < now.curve.Evaluate(wynik))
                {
                    if (lastPos != nowPos)
                    {
                        Vector3 randPos = new Vector3(prng.Next(-now.LOD * environmentData.prngPrecision, now.LOD * environmentData.prngPrecision) / environmentData.prngPrecision, 0, prng.Next(-now.LOD * environmentData.prngPrecision, now.LOD * environmentData.prngPrecision) / environmentData.prngPrecision) * now.randPos;

                        float x = 0, y = 0, z = 0;
                        if (now.randRotX)
                        {
                            x = prng.Next(0, 359);
                        }
                        if (now.randRotY)
                        {
                            y = prng.Next(0, 359);
                        }
                        if (now.randRotZ)
                        {
                            z = prng.Next(0, 359);
                        }
                        if ((positioningMode == PositioningMode.Colision) || (positioningMode == PositioningMode.BothMode))
                        {
                            nowPos.y = ColidePos(nowPos.x + randPos.x, nowPos.z + randPos.z, heightMap.minV, heightMap.maxV) - randPos.y;
                        }
                        Vector3 randRot = new Vector3(x, y, z);
                        lastPos = nowPos;

                        GameObject o = Instantiate(now.Object, (nowPos + randPos) * scale, Quaternion.Euler(now.rotation + randRot));

                        Transform tObject = o.GetComponent <Transform>() as Transform;
                        tObject.SetParent(parent, true);
                        tObject.localScale = now.scale;

                        if (j % skip == 0)
                        {
                            yield return(null);
                        }
                    }
                }
            }
        }
        yield return(null);

        if (useFlatSheadedB)
        {
            meshSettings.chunkSizeIndex = flatSheadedChunkSizeIndexB;
            meshSettings.useFlatShader  = true;
        }
        panelProcess.setActive(false);
    }