private void Apply(GStylizedTerrain t)
        {
            if (t.TerrainData == null)
            {
                return;
            }
            if (PrototypeIndices.Count == 0)
            {
                return;
            }
            if (Prototypes.Count == 0)
            {
                return;
            }
            RenderTexture  rt       = new RenderTexture(MaskResolution, MaskResolution, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
            List <Vector4> vertices = SplineCreator.GenerateVerticesWithFalloff();

            Internal_Apply(t, rt, vertices);
            Texture2D mask = GCommon.CreateTexture(MaskResolution, Color.clear);

            GCommon.CopyFromRT(mask, rt);
            mask.wrapMode = TextureWrapMode.Clamp;

            Color[] maskColors = mask.GetPixels();
            RemoveObjectFromTerrain(t, maskColors);

            rt.Release();
            GUtilities.DestroyObject(rt);
            GUtilities.DestroyObject(mask);
        }
Exemple #2
0
        private void Apply(GStylizedTerrain t)
        {
            if (t.TerrainData == null)
            {
                return;
            }
            RenderTexture  rt       = new RenderTexture(MaskResolution, MaskResolution, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
            List <Vector4> vertices = SplineCreator.GenerateVerticesWithFalloff();

            Internal_Apply(t, rt, vertices);
            Texture2D mask = GCommon.CreateTexture(MaskResolution, Color.clear);

            GCommon.CopyFromRT(mask, rt);
            mask.wrapMode = TextureWrapMode.Clamp;

            Color[] maskColors = mask.GetPixels();
            if (RemoveTrees)
            {
                RemoveTreeOnTerrain(t, maskColors);
            }
            if (RemoveGrasses)
            {
                RemoveGrassOnTerrain(t, maskColors);
                t.UpdateGrassPatches();
            }

            t.TerrainData.Foliage.ClearGrassDirtyRegions();
            t.TerrainData.SetDirty(GTerrainData.DirtyFlags.Foliage);

            rt.Release();
            GUtilities.DestroyObject(rt);
            GUtilities.DestroyObject(mask);
        }
Exemple #3
0
        private void Apply(GStylizedTerrain t)
        {
            if (t.TerrainData == null)
            {
                return;
            }
            List <Vector4> worldPoints = SplineCreator.GenerateVerticesWithFalloff();

            if (Channel == PaintChannel.AlbedoAndMetallic)
            {
                ApplyAlbedoAndMetallic(t, worldPoints);
            }
            else if (Channel == PaintChannel.Splat)
            {
                ApplySplat(t, worldPoints);
            }
            t.TerrainData.SetDirty(GTerrainData.DirtyFlags.Shading);
        }
        private void Apply(GStylizedTerrain t)
        {
            if (t.TerrainData == null)
            {
                return;
            }
            int            heightMapResolution = t.TerrainData.Geometry.HeightMapResolution;
            RenderTexture  rt       = new RenderTexture(heightMapResolution, heightMapResolution, 0, GGeometry.HeightMapRTFormat, RenderTextureReadWrite.Linear);
            List <Vector4> vertices = SplineCreator.GenerateVerticesWithFalloff();

            Internal_Apply(t, rt, vertices);

            Color[] oldHeightMapColors = t.TerrainData.Geometry.HeightMap.GetPixels();
            RenderTexture.active = rt;
            t.TerrainData.Geometry.HeightMap.ReadPixels(new Rect(0, 0, heightMapResolution, heightMapResolution), 0, 0);
            t.TerrainData.Geometry.HeightMap.Apply();
            RenderTexture.active = null;
            Color[] newHeightMapColors = t.TerrainData.Geometry.HeightMap.GetPixels();

            rt.Release();
            Object.DestroyImmediate(rt);

            List <Rect> dirtyRects = new List <Rect>(GCommon.CompareHeightMap(t.TerrainData.Geometry.ChunkGridSize, oldHeightMapColors, newHeightMapColors));

            for (int i = 0; i < dirtyRects.Count; ++i)
            {
                t.TerrainData.Geometry.SetRegionDirty(dirtyRects[i]);
            }
            t.TerrainData.SetDirty(GTerrainData.DirtyFlags.Geometry);

            for (int i = 0; i < dirtyRects.Count; ++i)
            {
                t.TerrainData.Foliage.SetTreeRegionDirty(dirtyRects[i]);
                t.TerrainData.Foliage.SetGrassRegionDirty(dirtyRects[i]);
            }
            t.UpdateTreesPosition();
            t.UpdateGrassPatches();
            t.TerrainData.Foliage.ClearTreeDirtyRegions();
            t.TerrainData.Foliage.ClearGrassDirtyRegions();
            t.TerrainData.SetDirty(GTerrainData.DirtyFlags.Foliage);
        }