Skip to content

Commit

Permalink
Cleanup textures after exporting
Browse files Browse the repository at this point in the history
StollD committed Jul 28, 2018
1 parent 0689df0 commit a54f22f
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions src/Kopernicus/UI/PlanetTextureExporter.cs
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Remoting.Channels;
using System.Threading;
using Kopernicus.OnDemand;
using UnityEngine;
@@ -221,13 +222,27 @@ public static IEnumerator UpdateTextures(CelestialBody celestialBody, TextureOpt
if (options.ApplyToScaled)
{
colorMap.Apply();
celestialBody.scaledBody.GetComponent<MeshRenderer>().sharedMaterial.SetTexture("_MainTex", colorMap);
ScaledSpaceOnDemand od = celestialBody.scaledBody.GetComponent<ScaledSpaceOnDemand>();
if (od != null)
{
od.normals = colorMap.name;
od.texture = colorMap.name;
UnityEngine.Object.DestroyImmediate(colorMap);

if (od.isLoaded)
{
od.UnloadTextures();
od.LoadTextures();
}
}
else
{
celestialBody.scaledBody.GetComponent<MeshRenderer>().sharedMaterial.SetTexture("_MainTex", colorMap);
}
}
else
{
UnityEngine.Object.DestroyImmediate(colorMap);
}
}

if (options.ExportHeight)
@@ -260,15 +275,31 @@ public static IEnumerator UpdateTextures(CelestialBody celestialBody, TextureOpt
if (options.ApplyToScaled)
{
normalMap.Apply();
celestialBody.scaledBody.GetComponent<MeshRenderer>().sharedMaterial
.SetTexture("_BumpMap", normalMap);
ScaledSpaceOnDemand od = celestialBody.scaledBody.GetComponent<ScaledSpaceOnDemand>();
if (od != null)
{
od.normals = normalMap.name;
UnityEngine.Object.DestroyImmediate(normalMap);

if (od.isLoaded)
{
od.UnloadTextures();
od.LoadTextures();
}
}
else
{
celestialBody.scaledBody.GetComponent<MeshRenderer>().sharedMaterial
.SetTexture("_BumpMap", normalMap);
}
}
else
{
UnityEngine.Object.DestroyImmediate(normalMap);
}
}

UnityEngine.Object.DestroyImmediate(heightMap);
}

// Close the Renderer

0 comments on commit a54f22f

Please sign in to comment.