/// <summary> /// Generates a thumbnail for the planet /// </summary> public static Texture2D GetPlanetThumbnail(CelestialBody body) { // Config RuntimePreviewGenerator.TransparentBackground = true; RuntimePreviewGenerator.BackgroundColor = Color.clear; RuntimePreviewGenerator.PreviewDirection = Vector3.forward; RuntimePreviewGenerator.Padding = -0.15f; if (runningKopernicus && KopernicusOnDemand.BodyHasComponent(body)) { Log.Info("Found Kopernicus and OnDemand Component"); if (!KopernicusOnDemand.TextureIsLoaded) { KopernicusOnDemand.LoadTexturesOnDemand(); } } GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); sphere.GetComponentInChildren <MeshFilter>().sharedMesh = body.scaledBody.GetComponent <MeshFilter>().sharedMesh; sphere.GetComponentInChildren <MeshRenderer>().sharedMaterial = body.scaledBody.GetComponent <MeshRenderer>().sharedMaterial; Texture2D finalTexture = RuntimePreviewGenerator.GenerateModelPreview(sphere.transform, 512, 512); UnityEngine.Object.DestroyImmediate(sphere); if (runningKopernicus && KopernicusOnDemand.ManuellyLoaded) { KopernicusOnDemand.UnloadTexturesOnDemand(); } return(finalTexture); }
/// <summary> /// Generates a thumbnail for the planet /// </summary> public static Texture2D GetPlanetThumbnail(CelestialBody body) { // Config RuntimePreviewGenerator.TransparentBackground = true; RuntimePreviewGenerator.BackgroundColor = Color.clear; RuntimePreviewGenerator.PreviewDirection = Vector3.forward; RuntimePreviewGenerator.Padding = -0.15f; #if false ScaledSpaceOnDemand od = body.scaledBody.GetComponent <ScaledSpaceOnDemand>(); Boolean isLoaded = true; if (od != null) { isLoaded = od.isLoaded; if (!isLoaded) { od.LoadTextures(); } } #endif GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); sphere.GetComponentInChildren <MeshFilter>().sharedMesh = body.scaledBody.GetComponent <MeshFilter>().sharedMesh; sphere.GetComponentInChildren <MeshRenderer>().sharedMaterial = body.scaledBody.GetComponent <MeshRenderer>().sharedMaterial; Texture2D finalTexture = RuntimePreviewGenerator.GenerateModelPreview(sphere.transform, 512, 512); UnityEngine.Object.DestroyImmediate(sphere); #if false if (!isLoaded) { od.UnloadTextures(); } #endif return(finalTexture); }