Exemplo n.º 1
0
        private void ReloadTerrain()
        {
            this.ters = Terrain.activeTerrains;
            int num = this.ters.Length;

            for (int i = 0; i < num; i++)
            {
                GrassManager component = this.ters[i].GetComponent <GrassManager>();
                if (component != null)
                {
                    this.GrassManagers.Add(component);
                    this.ActiveGrassManagers++;
                }
            }
        }
Exemplo n.º 2
0
        public float InitCellContent(int cellIndex)
        {
            GrassCell grassCell        = this.Cells[cellIndex];
            int       cellContentCount = grassCell.CellContentCount;

            for (int i = 0; i < cellContentCount; i++)
            {
                int num = grassCell.CellContentIndexes[i];
                GrassCellContent grassCellContent = this.CellContent[num];
                int num2 = grassCellContent.Layer;
                int num3 = 0;
                this.samplePosition.x   = grassCellContent.Pivot.x;
                this.samplePosition.y   = grassCellContent.Pivot.z;
                this.tempSamplePosition = this.samplePosition;
                int   num4 = (int)this.InstanceRotation[num2];
                bool  flag = this.WriteNormalBuffer[num2];
                float num5 = this.Noise[num2];
                float num6 = this.MinSize[num2];
                float num7 = this.MaxSize[num2] - num6;
                int   num8 = 1;
                if (grassCellContent.SoftlyMergedLayers != null)
                {
                    num8 += grassCellContent.SoftlyMergedLayers.Length;
                }
                for (int j = 0; j < num8; j++)
                {
                    this.tempSamplePosition = this.samplePosition;
                    if (j > 0)
                    {
                        num2 = grassCellContent.SoftlyMergedLayers[j - 1];
                        num5 = this.Noise[num2];
                        num6 = this.MinSize[num2];
                        num7 = this.MaxSize[num2] - num6;
                    }
                    for (int k = 0; k < this.NumberOfBucketsPerCell; k++)
                    {
                        for (int l = 0; l < this.NumberOfBucketsPerCell; l++)
                        {
                            int num9 = cellIndex + num2 + j * 55;
                            GrassManager.ATGSeed = (uint)((float)(num9 - (k * this.NumberOfBucketsPerCell + l)) * 0.0001f * 2.14748365E+09f);
                            Vector2 vector;
                            vector.x = this.tempSamplePosition.x;
                            vector.y = this.tempSamplePosition.y;
                            int num10 = (int)this.mapByte[num2][grassCellContent.PatchOffsetX + grassCellContent.PatchOffsetZ + k * (int)this.TerrainDetailSize.y + l];
                            num10 = (int)Math.Ceiling((double)((float)num10 * this.CurrentDetailDensity));
                            float num11 = (vector.x >= this.TerrainSizeOverHeightmap) ? this.OneOverHeightmapWidth : 0f;
                            float num12 = (vector.x < this.OneOverHeightmapWidthRight) ? this.OneOverHeightmapWidth : 0f;
                            float num13 = (vector.y >= this.TerrainSizeOverHeightmap) ? this.OneOverHeightmapHeight : 0f;
                            float num14 = (vector.y < this.OneOverHeightmapHeightUp) ? this.OneOverHeightmapHeight : 0f;
                            for (int m = 0; m < num10; m++)
                            {
                                float atgrandomNext = GrassManager.GetATGRandomNext();
                                float num15         = atgrandomNext * this.BucketSize;
                                atgrandomNext = GrassManager.GetATGRandomNext();
                                float   num16 = atgrandomNext * this.BucketSize;
                                Vector2 vector2;
                                vector2.x = (vector.x + num15) * this.OneOverTerrainSize.x;
                                vector2.y = (vector.y + num16) * this.OneOverTerrainSize.z;
                                float num17 = vector2.x * (float)(this.TerrainHeightmapWidth - 1);
                                float num18 = vector2.y * (float)(this.TerrainHeightmapHeight - 1);
                                int   num19 = (int)num17;
                                int   num20 = (int)num18;
                                int   num21 = (int)(num17 + 1f);
                                int   num22 = (int)(num18 + 1f);
                                float num23 = num17 - (float)num19;
                                float num24 = (float)num21 - num17;
                                float num25 = num18 - (float)num20;
                                float num26 = (float)num22 - num18;
                                num19 *= this.TerrainHeightmapHeight;
                                num21 *= this.TerrainHeightmapHeight;
                                float num27 = this.TerrainHeights[num19 + num20] * num24;
                                num27 += this.TerrainHeights[num21 + num20] * num23;
                                float num28 = this.TerrainHeights[num19 + num22] * num24;
                                num28 += this.TerrainHeights[num21 + num22] * num23;
                                this.tempPosition.y = num27 * num26 + num28 * num25;
                                float   num29 = this.GetfilteredHeight((vector2.x - num11) * (float)(this.TerrainHeightmapWidth - 1), vector2.y * (float)(this.TerrainHeightmapHeight - 1));
                                float   num30 = this.GetfilteredHeight((vector2.x + num12) * (float)(this.TerrainHeightmapWidth - 1), vector2.y * (float)(this.TerrainHeightmapHeight - 1));
                                float   num31 = this.GetfilteredHeight(vector2.x * (float)(this.TerrainHeightmapWidth - 1), (vector2.y + num14) * (float)(this.TerrainHeightmapHeight - 1));
                                float   num32 = this.GetfilteredHeight(vector2.x * (float)(this.TerrainHeightmapWidth - 1), (vector2.y - num13) * (float)(this.TerrainHeightmapHeight - 1));
                                Vector3 vector3;
                                vector3.x = -2f * (num30 - num29);
                                if (num4 != 2 && num4 != 4)
                                {
                                    vector3.y = 6.283184f * this.TerrainSizeOverHeightmap;
                                }
                                else
                                {
                                    vector3.y = 4f * this.TerrainSizeOverHeightmap;
                                }
                                vector3.z = (num31 - num32) * -2f;
                                float num33 = vector3.x * vector3.x + vector3.y * vector3.y + vector3.z * vector3.z;
                                float num34 = (float)Math.Sqrt((double)num33);
                                float num35 = 1f / num34;
                                vector3.x          *= num35;
                                vector3.y          *= num35;
                                vector3.z          *= num35;
                                this.tempPosition.x = this.tempSamplePosition.x + num15 + this.TerrainPosition.x;
                                this.tempPosition.z = this.tempSamplePosition.y + num16 + this.TerrainPosition.z;
                                float num36 = num6 + Mathf.PerlinNoise(this.tempPosition.x * num5, this.tempPosition.z * num5) * num7;
                                this.tempScale.x = num36;
                                this.tempScale.y = num36;
                                this.tempScale.z = num36;
                                Quaternion zeroQuat = this.ZeroQuat;
                                if (num4 != 2)
                                {
                                    zeroQuat.x = vector3.z;
                                    zeroQuat.y = 0f;
                                    zeroQuat.z = -vector3.x;
                                    zeroQuat.w = (float)Math.Sqrt((double)(1f + vector3.y));
                                    float num37 = (float)(1.0 / Math.Sqrt((double)(zeroQuat.w * zeroQuat.w + zeroQuat.x * zeroQuat.x + zeroQuat.y * zeroQuat.y + zeroQuat.z * zeroQuat.z)));
                                    zeroQuat.w *= num37;
                                    zeroQuat.x *= num37;
                                    zeroQuat.y *= num37;
                                    zeroQuat.z *= num37;
                                }
                                float      num38      = GrassManager.GetATGRandomNext() * 180f;
                                float      num39      = (float)Math.Cos((double)num38);
                                float      num40      = (float)Math.Sin((double)num38);
                                Quaternion quaternion = zeroQuat;
                                zeroQuat.x = quaternion.x * num39 - quaternion.z * num40;
                                zeroQuat.y = quaternion.w * num40 + quaternion.y * num39;
                                zeroQuat.z = quaternion.z * num39 + quaternion.x * num40;
                                zeroQuat.w = quaternion.w * num39 - quaternion.y * num40;
                                if (num4 == 1)
                                {
                                    num38 = GrassManager.GetATGRandomNext() * 180f;
                                    float num41 = (float)Math.Sin((double)num38);
                                    float num42 = (float)Math.Cos((double)num38);
                                    quaternion = zeroQuat;
                                    zeroQuat.x = quaternion.w * num41 + quaternion.x * num42;
                                    zeroQuat.y = quaternion.y * num42 + quaternion.z * num41;
                                    zeroQuat.z = quaternion.z * num42 - quaternion.y * num41;
                                    zeroQuat.w = quaternion.w * num42 - quaternion.x * num41;
                                }
                                this.tempMatrix.m03 = this.tempPosition.x;
                                this.tempMatrix.m13 = this.tempPosition.y + this.TerrainPosition.y;
                                this.tempMatrix.m23 = this.tempPosition.z;
                                float num43 = 2f * zeroQuat.x * zeroQuat.x;
                                float num44 = 2f * zeroQuat.y * zeroQuat.y;
                                float num45 = 2f * zeroQuat.z * zeroQuat.z;
                                this.tempMatrix.m00 = 1f - num44 - num45;
                                this.tempMatrix.m01 = 2f * zeroQuat.x * zeroQuat.y - 2f * zeroQuat.z * zeroQuat.w;
                                this.tempMatrix.m02 = 2f * zeroQuat.x * zeroQuat.z + 2f * zeroQuat.y * zeroQuat.w;
                                this.tempMatrix.m10 = 2f * zeroQuat.x * zeroQuat.y + 2f * zeroQuat.z * zeroQuat.w;
                                this.tempMatrix.m11 = 1f - num43 - num45;
                                this.tempMatrix.m12 = 2f * zeroQuat.y * zeroQuat.z - 2f * zeroQuat.x * zeroQuat.w;
                                this.tempMatrix.m20 = 2f * zeroQuat.x * zeroQuat.z - 2f * zeroQuat.y * zeroQuat.w;
                                this.tempMatrix.m21 = 2f * zeroQuat.y * zeroQuat.z + 2f * zeroQuat.x * zeroQuat.w;
                                this.tempMatrix.m22 = 1f - num43 - num44;
                                this.tempMatrix.m00 = this.tempMatrix.m00 * this.tempScale.x;
                                this.tempMatrix.m01 = this.tempMatrix.m01 * this.tempScale.y;
                                this.tempMatrix.m02 = this.tempMatrix.m02 * this.tempScale.z;
                                this.tempMatrix.m10 = this.tempMatrix.m10 * this.tempScale.x;
                                this.tempMatrix.m11 = this.tempMatrix.m11 * this.tempScale.y;
                                this.tempMatrix.m12 = this.tempMatrix.m12 * this.tempScale.z;
                                this.tempMatrix.m20 = this.tempMatrix.m20 * this.tempScale.x;
                                this.tempMatrix.m21 = this.tempMatrix.m21 * this.tempScale.y;
                                this.tempMatrix.m22 = this.tempMatrix.m22 * this.tempScale.z;
                                if (num4 == 2 && flag)
                                {
                                    Vector3 vector4 = vector3;
                                    float   num46   = -num38;
                                    num39 = (float)Math.Cos((double)num46);
                                    num40 = (float)Math.Sin((double)num46);
                                    float num47 = num40 * 2f;
                                    float num48 = num40 * num47;
                                    float num49 = num39 * num47;
                                    vector4.x           = (1f - num48) * vector3.x + num49 * vector3.z;
                                    vector4.z           = -num49 * vector3.x + (1f - num48) * vector3.z;
                                    this.tempMatrix.m30 = vector4.x;
                                    this.tempMatrix.m31 = vector4.y;
                                    this.tempMatrix.m32 = vector4.z;
                                }
                                else
                                {
                                    this.tempMatrix.m30 = 0f;
                                    this.tempMatrix.m31 = 0f;
                                    this.tempMatrix.m32 = 0f;
                                }
                                this.tempMatrix.m33        = (float)j + this.tempScale.x * 0.01f;
                                this.tempMatrixArray[num3] = this.tempMatrix;
                                num3++;
                            }
                            this.tempSamplePosition.y = this.tempSamplePosition.y + this.BucketSize;
                        }
                        this.tempSamplePosition.y = this.samplePosition.y;
                        this.tempSamplePosition.x = this.tempSamplePosition.x + this.BucketSize;
                    }
                }
                grassCellContent.v_matrices = new Matrix4x4[num3];
                Array.Copy(this.tempMatrixArray, grassCellContent.v_matrices, num3);
            }
            grassCell.state = 2;
            return(1f);
        }