public void Paint(Pinwheel.Griffin.GStylizedTerrain terrain, GTexturePainterArgs args) { if (terrain.TerrainData == null) { return; } if (args.MouseEventType == GPainterMouseEventType.Up) { return; } if (!args.Transform.IsChildOf(terrain.transform)) { return; } if (!(args.Collider is MeshCollider)) { return; } MeshCollider mc = args.Collider as MeshCollider; if (mc.sharedMesh == null) { return; } Mesh m = mc.sharedMesh; Vector2[] uvs = m.uv; int[] tris = m.triangles; int trisIndex = args.TriangleIndex; Vector2 v0 = uvs[tris[trisIndex * 3 + 0]]; Vector2 v1 = uvs[tris[trisIndex * 3 + 1]]; Vector2 v2 = uvs[tris[trisIndex * 3 + 2]]; int albedoMapResolution = terrain.TerrainData.Shading.AlbedoMapResolution; RenderTexture rt = new RenderTexture(albedoMapResolution, albedoMapResolution, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB); GCommon.CopyToRT(terrain.TerrainData.Shading.AlbedoMap, rt); Color c = args.Color; if (args.ActionType == GPainterActionType.Negative) { if (!ColorUtility.TryParseHtmlString(args.CustomArgs, out c)) { c = Color.white; } } GCommon.DrawTriangle(rt, v0, v1, v2, c); RenderTexture.active = rt; terrain.TerrainData.Shading.AlbedoMap.ReadPixels( new Rect(0, 0, albedoMapResolution, albedoMapResolution), 0, 0); terrain.TerrainData.Shading.AlbedoMap.Apply(); RenderTexture.active = null; rt.Release(); Object.DestroyImmediate(rt); terrain.TerrainData.SetDirty(GTerrainData.DirtyFlags.Shading); }