private void DrawLivePreview(GStylizedTerrain t, Camera cam) { if (t.transform.rotation != Quaternion.identity || t.transform.lossyScale != Vector3.one) { return; } Mesh previewMesh = GGriffinSettings.Instance.GetLivePreviewMesh(t.TerrainData.Geometry.MeshResolution); RenderTexture rt = GetPreviewTexture(t); instance.Internal_Apply(t, rt, instance.SplineCreator.Editor_Vertices); Vector3 terrainSize = new Vector3( t.TerrainData.Geometry.Width, t.TerrainData.Geometry.Height, t.TerrainData.Geometry.Length); previewPropertyBlock.Clear(); previewPropertyBlock.SetTexture("_OldHeightMap", t.TerrainData.Geometry.HeightMap); previewPropertyBlock.SetTexture("_NewHeightMap", rt); previewPropertyBlock.SetTexture("_MainTex", rt); previewPropertyBlock.SetFloat("_Height", t.TerrainData.Geometry.Height); previewPropertyBlock.SetVector("_BoundMin", t.transform.position); previewPropertyBlock.SetVector("_BoundMax", t.transform.TransformPoint(terrainSize)); Material mat = GInternalMaterials.GeometryLivePreviewMaterial; List <Rect> uvRects = new List <Rect>(instance.SplineCreator.SweepDirtyRect(t)); for (int i = 0; i < uvRects.Count; ++i) { Rect r = uvRects[i]; Vector3 localPos = new Vector3( terrainSize.x * r.x, 0f, terrainSize.z * r.y); Vector3 worldPos = t.transform.TransformPoint(localPos); Quaternion rotation = Quaternion.identity; Vector3 scale = new Vector3(terrainSize.x * r.width, 1, terrainSize.z * r.height); Graphics.DrawMesh( previewMesh, Matrix4x4.TRS(worldPos, rotation, scale), mat, LayerMask.NameToLayer("Default"), cam, 0, previewPropertyBlock); } }
private void DrawLivePreview(GStylizedTerrain t, Camera cam) { if (t.transform.rotation != Quaternion.identity || t.transform.lossyScale != Vector3.one) { return; } Mesh previewMesh = GEditorSettings.Instance.livePreview.GetTriangleMesh(t.TerrainData.Geometry.MeshResolution); RenderTexture rt = GetPreviewTexture(t); instance.Internal_Apply(t, rt, instance.SplineCreator.Editor_Vertices); List <Rect> uvRects = new List <Rect>(instance.SplineCreator.SweepDirtyRect(t)); Rect r = GUtilities.MergeRects(uvRects); GLivePreviewDrawer.DrawGeometryLivePreview(t, cam, rt, r); }