public static void ExportTexture(Cubemap input, Stream output, ExportTextureFormat imageFormat, object data) { Texture2D cache = new Texture2D(input.width * 6, input.height); for (int i = 0; i < 6; i++) { Color[] pixels = input.GetPixels((CubemapFace)i); cache.SetPixels(i * input.width, 0, input.width, input.height, pixels); } cache.Apply(); byte[] exported; switch (imageFormat) { case ExportTextureFormat.JPG: { exported = cache.EncodeToJPG((int)data); } break; default: case ExportTextureFormat.PNG: exported = cache.EncodeToPNG(); break; } if (exported == null) { // log texture name Debug.LogError("Texture failed exporting: " + input.name); } output.Write(exported, 0, exported.Length); }
private void UpdateTextureFormat(ExportTextureFormat format, AssetImage asset, string extension) { if (string.IsNullOrEmpty(extension)) { asset.src = asset.src + JanusUtil.GetImageExtension(format); } else { asset.src = asset.src + extension; } }
public static bool SupportsAlpha(ExportTextureFormat format) { switch (format) { case ExportTextureFormat.PNG: return(true); case ExportTextureFormat.JPG: default: return(false); } }
public static string GetImageExtension(ExportTextureFormat format) { switch (format) { case ExportTextureFormat.JPG: return(".jpg"); case ExportTextureFormat.PNG: default: return(".png"); } }
public static bool SupportsQuality(ExportTextureFormat format) { switch (format) { case ExportTextureFormat.JPG: return(true); case ExportTextureFormat.PNG: // PNG is lossless default: return(false); } }
public void ProcessTextures() { LightmapExportType lightmapExportType = room.LightmapType; LightmapTextureFormat lightmapTextureFormat = room.LightmapTextureFormat; ExportTextureFormat format = room.TextureFormat; // export everything that has already been loaded List <AssetImage> assetImages = room.AssetImages; for (int i = 0; i < assetImages.Count; i++) { AssetImage image = assetImages[i]; if (image.Texture || (room.ExportOnlyHtml && image.Created)) { if (image.Texture) { EditorUtility.DisplayProgressBar("Exporting main textures...", image.Texture.name, i / (float)assetImages.Count); } ExportTexture(image.Texture, format, image, true); } } switch (lightmapExportType) { case LightmapExportType.BakedMaterial: ProcessLightmapsBaked(); break; case LightmapExportType.Packed: { switch (lightmapTextureFormat) { case LightmapTextureFormat.EXR: ProcessLightmapsPackedSourceEXR(); break; default: ProcessLightmapsPacked(); break; } } break; case LightmapExportType.Unpacked: ProcessLightmapsUnpacked(); break; } }
private void ExportTexture(Texture2D texture, ExportTextureFormat format, AssetImage asset, bool canCopy) { // force PNG if alpha?? string sourcePath = AssetDatabase.GetAssetPath(asset.Texture); string sourceExtension = Path.GetExtension(sourcePath); bool forceConversion = room.TextureForceReExport && !JanusUtil.IgnoreReExport(sourcePath); string rootDir = room.RootFolder; if (!forceConversion && canCopy && JanusUtil.SupportsImageFormat(sourceExtension)) { asset.src = asset.src + sourceExtension; if (room.ExportOnlyHtml) { return; } string texPath = Path.Combine(rootDir, asset.src); File.Copy(sourcePath, texPath, true); } else { try { asset.src = asset.src + JanusUtil.GetImageExtension(format); if (room.ExportOnlyHtml) { return; } string texPath = Path.Combine(rootDir, asset.src); using (Stream output = File.OpenWrite(texPath)) { TempTextureData data = TextureUtil.LockTexture(texture, sourcePath); TextureUtil.ExportTexture(texture, output, format, room.TextureData, false); TextureUtil.UnlockTexture(data); } } catch { Debug.LogError("Failure exporting texture " + asset.id); } } }
/// <summary> /// Resets all possible parameters to their default values /// </summary> private void ResetParameters() { string proj = JanusUtil.GetDefaultExportPath(); exportPath = proj; searchType = AssetObjectSearchType.EachMesh; uniformScale = 1; exportedTexturesFormat = ExportTextureFormat.JPG; defaultQuality = 70; exportTextures = true; exportMaterials = true; exportSkyboxResolution = 1024; exportInactiveObjects = false; exportDynamicGameObjects = true; textureForceReExport = false; lightmapExportType = LightmapExportType.Packed; lightmapTextureFormat = LightmapTextureFormat.EXR; lightmapTextureQuality = 70; lightmapExposureVisible = true; builtLightmapExposure = false; lightmapRelFStops = 0; useEulerRotations = true; scrollPos = Vector2.zero; maxLightMapResolution = 2048; environmentProbeExport = true; environmentProbeRadResolution = 128; environmentProbeIrradResolution = 32; environmentProbeOverride = null; exportMaterials = true; exportTextures = true; scrollPos = Vector2.zero; meshScrollPos = Vector2.zero; }
private void ProcessLightmapsBaked() { ExportTextureFormat format = room.TextureFormat; if (room.ExportOnlyHtml) { foreach (var lightPair in lightmapped) { int id = lightPair.Key; List <RoomObject> toRender = lightPair.Value; for (int i = 0; i < toRender.Count; i++) { RoomObject rObj = toRender[i]; string imgId = rObj.id + "_Baked"; UpdateTextureFormat(format, room.GetTexture(imgId), ""); } } return; } string lightMapsFolder = UnityUtil.GetLightmapsFolder(); // only load shader now, so if the user is not exporting lightmaps // he doesn't need to have it on his project folder Shader lightMapShader = Shader.Find("Hidden/LMapBaked"); JanusUtil.AssertShader(lightMapShader); Material lightMap = new Material(lightMapShader); lightMap.SetPass(0); lightMap.SetFloat("_RelFStops", room.LightmapRelFStops); lightMap.SetFloat("_IsLinear", PlayerSettings.colorSpace == ColorSpace.Linear ? 1 : 0); // export lightmaps int lmap = 0; foreach (var lightPair in lightmapped) { int id = lightPair.Key; List <RoomObject> toRender = lightPair.Value; // get the path to the lightmap file string lightMapFile = Path.Combine(lightMapsFolder, "Lightmap-" + id + "_comp_light.exr"); Texture2D texture = AssetDatabase.LoadAssetAtPath <Texture2D>(lightMapFile); if (texture == null) { continue; } lightMap.SetTexture("_LightMapTex", texture); for (int i = 0; i < toRender.Count; i++) { RoomObject rObj = toRender[i]; GameObject obj = rObj.UnityObj; MeshRenderer renderer = obj.GetComponent <MeshRenderer>(); MeshFilter filter = obj.GetComponent <MeshFilter>(); Mesh mesh = filter.sharedMesh; Transform trans = obj.transform; Matrix4x4 world = Matrix4x4.TRS(trans.position, trans.rotation, trans.lossyScale); Vector4 scaleOffset = renderer.lightmapScaleOffset; float width = (1 - scaleOffset.z) * scaleOffset.x; float height = (1 - scaleOffset.w) * scaleOffset.y; float size = Math.Max(width, height); // guarantee were not scaling stuff up int maxLmapRes = Math.Min(room.LightmapMaxResolution, texture.width); int lightMapSize = (int)(maxLmapRes * size); lightMapSize = (int)Math.Pow(2, Math.Ceiling(Math.Log(lightMapSize) / Math.Log(2))); lightMapSize = Math.Min(maxLmapRes, Math.Max(lightMapSize, 16)); RenderTexture renderTexture = RenderTexture.GetTemporary(lightMapSize, lightMapSize, 0, RenderTextureFormat.ARGB32); Graphics.SetRenderTarget(renderTexture); GL.Clear(true, true, new Color(0, 0, 0, 0)); // clear to transparent Material[] mats = renderer.sharedMaterials; for (int j = 0; j < mats.Length; j++) { Material mat = mats[j]; // clear to default lightMap.SetTexture("_MainTex", EditorGUIUtility.whiteTexture); lightMap.SetColor("_Color", Color.white); // uvs lightMap.SetVector("_LightMapUV", renderer.lightmapScaleOffset); Shader shader = mat.shader; int props = ShaderUtil.GetPropertyCount(shader); for (int k = 0; k < props; k++) { string name = ShaderUtil.GetPropertyName(shader, k); ShaderUtil.ShaderPropertyType propType = ShaderUtil.GetPropertyType(shader, k); if (propType == ShaderUtil.ShaderPropertyType.TexEnv) { if (JanusGlobals.SemanticsMainTex.Contains(name.ToLower())) { // main texture texture Texture matTex = mat.GetTexture(name); if (matTex) { lightMap.SetTexture("_MainTex", matTex); } } } else if (propType == ShaderUtil.ShaderPropertyType.Color) { if (JanusGlobals.SemanticsColor.Contains(name.ToLower())) { lightMap.SetColor("_Color", mat.GetColor(name)); } } } lightMap.SetPass(0); Graphics.DrawMeshNow(mesh, world, j); } // This is the only way to access data from a RenderTexture Texture2D tex = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.ARGB32, false, false); tex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0); string imgId = rObj.id + "_Baked"; tex.name = imgId; Graphics.SetRenderTarget(null); RenderTexture.ReleaseTemporary(renderTexture); lmap++; // save the texture file ExportTexture(tex, format, room.GetTexture(rObj.image_id), false); UObject.DestroyImmediate(tex); } } UObject.DestroyImmediate(lightMap); }
private void ProcessLightmapsUnpacked() { ExportTextureFormat format = room.TextureFormat; if (room.ExportOnlyHtml) { foreach (var lightPair in lightmapped) { int id = lightPair.Key; List <RoomObject> toRender = lightPair.Value; for (int i = 0; i < toRender.Count; i++) { RoomObject rObj = toRender[i]; string imgId = rObj.id + "_Baked"; UpdateTextureFormat(format, room.GetTexture(imgId), ""); } } return; } string lightMapsFolder = UnityUtil.GetLightmapsFolder(); Shader lightMapShader = Shader.Find("Hidden/LMapUnpacked"); JanusUtil.AssertShader(lightMapShader); Material lightMap = new Material(lightMapShader); lightMap.SetPass(0); lightMap.SetFloat("_RelFStops", room.LightmapRelFStops); lightMap.SetFloat("_IsLinear", PlayerSettings.colorSpace == ColorSpace.Linear ? 1 : 0); // export lightmaps int lmap = 0; foreach (var lightPair in lightmapped) { int id = lightPair.Key; List <RoomObject> toRender = lightPair.Value; // get the path to the lightmap file string lightMapFile = Path.Combine(lightMapsFolder, "Lightmap-" + id + "_comp_light.exr"); Texture2D texture = AssetDatabase.LoadAssetAtPath <Texture2D>(lightMapFile); if (texture == null) { continue; } lightMap.SetTexture("_LightMapTex", texture); for (int i = 0; i < toRender.Count; i++) { RoomObject rObj = toRender[i]; GameObject obj = rObj.UnityObj; MeshRenderer renderer = obj.GetComponent <MeshRenderer>(); MeshFilter filter = obj.GetComponent <MeshFilter>(); Mesh mesh = filter.sharedMesh; Transform trans = obj.transform; Matrix4x4 world = Matrix4x4.TRS(trans.position, trans.rotation, trans.lossyScale); Vector4 scaleOffset = renderer.lightmapScaleOffset; float width = (1 - scaleOffset.z) * scaleOffset.x; float height = (1 - scaleOffset.w) * scaleOffset.y; float size = Math.Max(width, height); int lightMapSize = (int)(room.LightmapMaxResolution * size); lightMapSize = (int)Math.Pow(2, Math.Ceiling(Math.Log(lightMapSize) / Math.Log(2))); lightMapSize = Math.Min(room.LightmapMaxResolution, Math.Max(lightMapSize, 16)); RenderTexture renderTexture = RenderTexture.GetTemporary(lightMapSize, lightMapSize, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB); Graphics.SetRenderTarget(renderTexture); GL.Clear(true, true, new Color(0, 0, 0, 0)); // clear to transparent Material[] mats = renderer.sharedMaterials; lightMap.SetVector("_LightMapUV", renderer.lightmapScaleOffset); for (int j = 0; j < mats.Length; j++) { //Material mat = mats[j]; lightMap.SetPass(0); Graphics.DrawMeshNow(mesh, world, j); } // This is the only way to access data from a RenderTexture Texture2D tex = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.ARGB32, false, false); tex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0); string imgId = rObj.id + "_Baked"; tex.name = imgId; tex.Apply(); // send the data back to the GPU so we can draw it on the preview area Graphics.SetRenderTarget(null); RenderTexture.ReleaseTemporary(renderTexture); lmap++; // save the texture file ExportTexture(tex, format, room.GetTexture(rObj.image_id), false); UObject.DestroyImmediate(tex); } } UObject.DestroyImmediate(lightMap); }
private void ProcessLightmapsPacked() { ExportTextureFormat format = room.TextureFormat; if (room.ExportOnlyHtml) { foreach (var lightPair in lightmapped) { int id = lightPair.Key; string imgId = "Lightmap" + id; UpdateTextureFormat(format, room.GetTexture(imgId), ""); } return; } string lightMapsFolder = UnityUtil.GetLightmapsFolder(); Shader exposureShader = Shader.Find("Hidden/ExposureShader"); JanusUtil.AssertShader(exposureShader); Material exposureMat = new Material(exposureShader); exposureMat.SetPass(0); exposureMat.SetFloat("_RelFStops", room.LightmapRelFStops); exposureMat.SetFloat("_IsLinear", PlayerSettings.colorSpace == ColorSpace.Linear ? 1 : 0); foreach (var lightPair in lightmapped) { int id = lightPair.Key; AssetImage lmapImage = room.TryGetTexture("Lightmap" + id); if (lmapImage == null) { continue; } // get the path to the lightmap file string lightMapFile = Path.Combine(lightMapsFolder, "Lightmap-" + id + "_comp_light.exr"); Texture2D texture = AssetDatabase.LoadAssetAtPath <Texture2D>(lightMapFile); if (texture == null) { continue; } exposureMat.SetTexture("_InputTex", texture); // We need to access unity_Lightmap_HDR to decode the lightmap, // but we can't, so we have to render everything to a custom RenderTexture! Texture2D decTex = new Texture2D(texture.width, texture.height); decTex.name = "Lightmap" + id; //texturesExported.Add(decTex); RenderTexture renderTexture = RenderTexture.GetTemporary(texture.width, texture.height); Graphics.SetRenderTarget(renderTexture); GL.Clear(true, true, new Color(0, 0, 0, 0)); // clear to transparent exposureMat.SetPass(0); Graphics.DrawMeshNow(JanusResources.PlaneMesh, Matrix4x4.identity); decTex.ReadPixels(new Rect(0, 0, decTex.width, decTex.height), 0, 0); Graphics.SetRenderTarget(null); RenderTexture.ReleaseTemporary(renderTexture); // save the lightmap file ExportTexture(decTex, format, lmapImage, false); UObject.DestroyImmediate(decTex); } UObject.DestroyImmediate(exposureMat); }
public void PreProcessObject(MeshRenderer renderer, Mesh mesh, AssetObject obj, RoomObject rObj, bool assignLightmapScale) { LightmapExportType lightmapExportType = room.LightmapType; ExportTextureFormat format = room.TextureFormat; if (lightmapExportType != LightmapExportType.None) { int lightMap = renderer.lightmapIndex; if (lightMap != -1) { // Register mesh for lightmap render List <RoomObject> toRender; if (!lightmapped.TryGetValue(lightMap, out toRender)) { toRender = new List <RoomObject>(); lightmapped.Add(lightMap, toRender); } toRender.Add(rObj); if (assignLightmapScale) { if (lightmapExportType == LightmapExportType.Packed) { Vector4 lmap = renderer.lightmapScaleOffset; lmap.x = Mathf.Clamp(lmap.x, -2, 2); lmap.y = Mathf.Clamp(lmap.y, -2, 2); lmap.z = Mathf.Clamp(lmap.z, -2, 2); lmap.w = Mathf.Clamp(lmap.w, -2, 2); rObj.SetLightmap(lmap); } } if (lightmapExportType != LightmapExportType.BakedMaterial) { // check if we already have the texture string lmapId = "Lightmap" + lightMap; AssetImage lmapImage = room.TryGetTexture(lmapId); if (lmapImage == null) { lmapImage = new AssetImage(); lmapImage.id = lmapId; lmapImage.src = lmapId; room.AddAssetImage(lmapImage); } rObj.lmap_id = lmapImage.id; } } } switch (lightmapExportType) { case LightmapExportType.BakedMaterial: case LightmapExportType.Unpacked: { AssetImage image = new AssetImage(); string imgId = obj.id + "_Baked"; image.id = imgId; image.src = imgId; rObj.image_id = image.id; room.AddAssetImage(image); } break; } if (lightmapExportType != LightmapExportType.BakedMaterial && room.ExportMaterials) { // search for textures/color on object Texture2D texture = null; Color objColor = Color.white; Material[] mats = renderer.sharedMaterials; for (int j = 0; j < mats.Length; j++) { Material mat = mats[j]; Vector2 sca = mat.mainTextureScale; Vector2 off = mat.mainTextureOffset; if (sca != Vector2.one || off != Vector2.zero) { rObj.tiling = JanusUtil.FormatVector4(new Vector4(sca.x, sca.y, off.x, off.y)); } Shader shader = mat.shader; int props = ShaderUtil.GetPropertyCount(shader); for (int k = 0; k < props; k++) { string name = ShaderUtil.GetPropertyName(shader, k); ShaderUtil.ShaderPropertyType propType = ShaderUtil.GetPropertyType(shader, k); if (propType == ShaderUtil.ShaderPropertyType.TexEnv) { if (JanusGlobals.SemanticsMainTex.Contains(name.ToLower())) { // main texture texture Texture matTex = mat.GetTexture(name); if (matTex is Texture2D) { texture = (Texture2D)matTex; } } } else if (propType == ShaderUtil.ShaderPropertyType.Color) { if (JanusGlobals.SemanticsColor.Contains(name.ToLower())) { objColor = mat.GetColor(name); } } } } rObj.col = JanusUtil.FormatColor(objColor); if (room.ExportTextures && texture != null) { if (textureNames.Contains(texture.name)) { AssetImage img = room.AssetImages.FirstOrDefault(c => c.Texture == texture); if (img != null) { rObj.image_id = img.id; } return; } textureNames.Add(texture.name); AssetImage image = new AssetImage(); image.Texture = texture; image.id = texture.name; image.src = texture.name; rObj.image_id = image.id; room.AddAssetImage(image); } } }
public static void ExportTexture(Texture2D input, Stream output, ExportTextureFormat imageFormat, object data, bool zeroAlpha) { #if SYSTEM_DRAWING ImageFormat format = GetImageFormat(imageFormat); Color32[] colors = input.GetPixels32(); byte[] bdata = new byte[colors.Length * 4]; // this is slower than linear, but easier to fix the texture mirrored for (int x = 0; x < input.width; x++) { for (int y = 0; y < input.height; y++) { int index = x + (y * input.width); Color32 col = colors[index]; index = (x + ((input.height - y - 1) * input.width)) * 4; //index *= 4; bdata[index] = col.b; bdata[index + 1] = col.g; bdata[index + 2] = col.r; bdata[index + 3] = col.a; } } Bitmap bitmap = new Bitmap(input.width, input.height); BitmapData locked = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); Marshal.Copy(bdata, 0, locked.Scan0, bdata.Length); bitmap.UnlockBits(locked); bitmap.Save(output, format); bitmap.Dispose(); #else Texture2D inp; if (zeroAlpha) { inp = ZeroAlpha(input); } else { inp = input; } byte[] exported; switch (imageFormat) { case ExportTextureFormat.JPG: { exported = inp.EncodeToJPG((int)data); } break; default: case ExportTextureFormat.PNG: exported = inp.EncodeToPNG(); break; } if (exported == null) { // log texture name Debug.LogError("Texture failed exporting: " + input.name); } output.Write(exported, 0, exported.Length); if (zeroAlpha) { // destroy the texture UnityEngine.Object.DestroyImmediate(inp); } #endif }
private void OnGUI() { Rect rect = this.position; Rect showArea = new Rect(border.x, border.y, rect.width - border.width, rect.height - border.height); GUILayout.BeginArea(showArea); scrollPos = GUILayout.BeginScrollView(scrollPos); GUILayout.BeginHorizontal(); GUILayout.Label("Janus Exporter " + (JanusGlobals.Version).ToString("F2"), EditorStyles.boldLabel); GUILayout.EndHorizontal(); // Asset Objects (Models) GUILayout.Label("Asset Objects", EditorStyles.boldLabel); searchType = (AssetObjectSearchType)EditorGUILayout.EnumPopup("Search Type", searchType); //meshFormat = (ExportMeshFormat)EditorGUILayout.EnumPopup("Mesh Format", meshFormat); //meshPreviewShow = EditorGUILayout.Foldout(meshPreviewShow, "Asset Objects Extracted"); meshPreviewShow = false; if (meshPreviewShow) { Color defaultColor = GUI.color; int previewHeight = 200; Rect area = GUILayoutUtility.GetRect(rect.width - border.width, previewHeight); Rect meshPreviewFullArea = area; meshPreviewFullArea.width = meshPreviewWidth; meshPreviewFullArea.height -= 20; meshScrollPos = GUI.BeginScrollView(area, meshScrollPos, meshPreviewFullArea); GUI.color = new Color(0.2f, 0.2f, 0.2f, 1f); GUI.DrawTexture(new Rect(area.x + meshScrollPos.x, area.y, area.width, area.height), EditorGUIUtility.whiteTexture); GUI.color = new Color(0, 0, 0, 1f); GUI.DrawTexture(new Rect(area.x + meshScrollPos.x, area.y, area.width, 1), EditorGUIUtility.whiteTexture); GUI.DrawTexture(new Rect(area.x + meshScrollPos.x, area.y + area.height - 1, area.width, 1), EditorGUIUtility.whiteTexture); GUI.DrawTexture(new Rect(area.x + meshScrollPos.x, area.y, 1, area.height), EditorGUIUtility.whiteTexture); GUI.DrawTexture(new Rect(area.x + area.width - 1 + meshScrollPos.x, area.y, 1, area.height), EditorGUIUtility.whiteTexture); GUI.color = defaultColor; if (room != null) { List <RoomObject> objects = room.RoomObjects; int objUiSize = 80; int objUiBorder = 5; int columns = previewHeight / objUiSize; meshPreviewWidth = objects.Count * (objUiSize + objUiBorder); int rowSize = meshPreviewWidth / columns; meshPreviewWidth = rowSize + objUiSize; for (int i = 0; i < objects.Count; i++) { RoomObject obj = objects[i]; if (obj.Preview == null) { obj.Preview = AssetPreview.GetMiniThumbnail(obj.UnityObj); objects[i] = obj; } float x = area.x + (i * (objUiSize + objUiBorder)); int lineIndex = (int)(x / rowSize); float y = area.y + objUiBorder + (lineIndex * objUiSize); x -= lineIndex * rowSize; Rect display = new Rect(x, y, objUiSize, objUiSize); GUI.DrawTexture(display, obj.Preview); } } GUI.EndScrollView(); } float scale = EditorGUILayout.FloatField("Uniform Scale", uniformScale); if (uniformScale != scale) { uniformScale = scale; // update the scale on all possible Janus objects on screen JanusGlobals.UpdateScale(uniformScale); } // Main Parameters GUILayout.Label("Main", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Export Path"); //exportPath = EditorGUILayout.TextField(exportPath); EditorGUILayout.LabelField(exportPath); if (GUILayout.Button("...")) { // search for a folder string newExportPath = EditorUtility.SaveFolderPanel("JanusVR Export Folder", "", ""); if (!string.IsNullOrEmpty(newExportPath)) { exportPath = newExportPath; } } EditorGUILayout.EndHorizontal(); useEulerRotations = EditorGUILayout.Toggle("Use Euler Rotations (Janus 59+ only)", useEulerRotations); // Texture GUILayout.Label("Texture", EditorStyles.boldLabel); textureForceReExport = EditorGUILayout.Toggle("Force ReExport", textureForceReExport); exportedTexturesFormat = (ExportTextureFormat)EditorGUILayout.EnumPopup("Exported Textures Format", exportedTexturesFormat); if (JanusUtil.SupportsQuality(exportedTexturesFormat)) { defaultQuality = EditorGUILayout.IntSlider("Exported Textures Quality", defaultQuality, 0, 100); } // Scene GUILayout.Label("Scene", EditorStyles.boldLabel); exportInactiveObjects = EditorGUILayout.Toggle("Export Inactive Objects", exportInactiveObjects); exportDynamicGameObjects = EditorGUILayout.Toggle("Export Dynamic Objects", exportDynamicGameObjects); exportTextures = EditorGUILayout.Toggle("Export Textures", exportTextures); exportMaterials = EditorGUILayout.Toggle("Export Materials", exportMaterials); EditorGUILayout.LabelField(" Useful for testing lighting results in Janus"); exportSkybox = EditorGUILayout.Toggle("Export Skybox", exportSkybox); if (exportSkybox && UnityUtil.IsProceduralSkybox()) { exportSkyboxResolution = Math.Max(4, EditorGUILayout.IntField("Skybox Render Resolution", exportSkyboxResolution)); } EditorGUILayout.LabelField(" Will render the Skybox into 6 textures with the specified resolution"); // Probes GUILayout.Label("Probes", EditorStyles.boldLabel); environmentProbeExport = EditorGUILayout.Toggle("Export Environment Probes", environmentProbeExport); if (environmentProbeExport) { environmentProbeOverride = EditorGUILayout.ObjectField("Override Probe (Optional)", environmentProbeOverride, typeof(ReflectionProbe), true) as ReflectionProbe; environmentProbeRadResolution = Math.Max(4, EditorGUILayout.IntField("Probe Radiance Resolution", environmentProbeRadResolution)); environmentProbeIrradResolution = Math.Max(4, EditorGUILayout.IntField("Probe Irradiance Resolution", environmentProbeIrradResolution)); } // Lightmap GUILayout.Label("Lightmaps", EditorStyles.boldLabel); lightmapExportType = (LightmapExportType)EditorGUILayout.EnumPopup("Lightmap Type", lightmapExportType); switch (lightmapExportType) { case LightmapExportType.None: EditorGUILayout.LabelField(" No lightmaps are going to be exported"); break; case LightmapExportType.Packed: EditorGUILayout.LabelField(" Uses the source lightmap files from Unity without any atlas changes"); break; case LightmapExportType.BakedMaterial: EditorGUILayout.LabelField(" Bakes the lightmap into the material"); break; case LightmapExportType.Unpacked: EditorGUILayout.LabelField(" Converts the source EXR files to Low-Dynamic Range and unpacks"); EditorGUILayout.LabelField(" into individual textures (for testing purposes)"); break; } if (lightmapExportType != LightmapExportType.None) { lightmapTextureFormat = (LightmapTextureFormat)EditorGUILayout.EnumPopup("Lightmap Format", lightmapTextureFormat); if (lightmapTextureFormat != LightmapTextureFormat.EXR && JanusUtil.SupportsQuality(lightmapTextureFormat)) { lightmapTextureQuality = EditorGUILayout.IntSlider("Lightmap Textures Quality", lightmapTextureQuality, 0, 100); } } // cant scale if theres no lightmap and if its EXR (for now) if (lightmapExportType != LightmapExportType.None && lightmapTextureFormat != LightmapTextureFormat.EXR) { maxLightMapResolution = Math.Max(4, EditorGUILayout.IntField("Max Lightmap Resolution", maxLightMapResolution)); } if (NeedsLDRConversion(lightmapTextureFormat)) { float newFStop = EditorGUILayout.Slider("Lightmap Relative F-Stops", lightmapRelFStops, -5, 5); bool update = false; if (Math.Abs(newFStop - lightmapRelFStops) > 0.0001f) { lightmapRelFStops = newFStop; update = true; } lightmapExposureVisible = EditorGUILayout.Foldout(lightmapExposureVisible, "Preview Exposure"); if (lightmapExposureVisible) { if (update || !builtLightmapExposure) { builtLightmapExposure = MaterialScanner.ProcessExposure(0, lightmapRelFStops); } if (builtLightmapExposure) { Texture2D preview = JanusResources.TempRenderTexture; int texSize = (int)(showArea.width * 0.4); Rect tex = GUILayoutUtility.GetRect(texSize, texSize + 30); GUI.Label(new Rect(tex.x + 20, tex.y + 5, texSize, texSize), "Lightmap Preview"); GUI.DrawTexture(new Rect(tex.x + 20, tex.y + 30, texSize, texSize), preview); //if (previewWindow) //{ // previewWindow.Tex = preview; // previewWindow.Repaint(); //} //if (GUI.Button(new Rect(tex.x + texSize - 60, tex.y, 80, 20), "Preview")) //{ // previewWindow = EditorWindow.GetWindow<LightmapPreviewWindow>(); // previewWindow.Show(); //} } else { GUILayout.Label("No Lightmap Preview"); } } } GUILayout.FlexibleSpace(); // if (exported != null) // { // // Exported // GUILayout.Label("Exported", EditorStyles.boldLabel); // GUILayout.Label("Scene size " + sceneSize.size); // if (farPlaneDistance < 500) // { // GUILayout.Label("Far Plane " + farPlaneDistance.ToString("F2") + " (Exported as 500)"); // } // else // { // GUILayout.Label("Far Plane " + farPlaneDistance.ToString("F2")); // } // Cubemap cubemap = exported.environmentCubemap; // if (cubemap == null) // { //#if UNITY_5_0 // GUILayout.Label("Environment Probe: Not supported on Unity 5.0", errorStyle); //#elif UNITY_5_3 // GUILayout.Label("Environment Probe: On Unity 5.3 can only be exported if set as cubemap on the Lighting window", errorStyle); //#else // GUILayout.Label("Environment Probe: None (need baked lightmaps)", errorStyle); //#endif // } // else // { // GUILayout.Label("Environment Probe: " + cubemap.width); // } // } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Export HTML only")) { try { Export(true); } catch (Exception ex) { Debug.Log("Error exporting: " + ex.Message); } finally { EditorUtility.ClearProgressBar(); } } if (GUILayout.Button("Reset Parameters")) { ResetParameters(); } if (!string.IsNullOrEmpty(exportPath) && Directory.Exists(exportPath) && GUILayout.Button("Show In Explorer")) { UnityUtil.StartProcess(exportPath); } EditorGUILayout.EndHorizontal(); if (!string.IsNullOrEmpty(exportPath)) { if (GUILayout.Button("Full Export", GUILayout.Height(30))) { if (lightmapExportType == LightmapExportType.Unpacked) { Debug.LogError("Unpacked is unsupported right now."); return; } //try { Export(false); } //catch (Exception ex) { //Debug.Log("Error exporting: " + ex.Message); } //finally { // delete room room = null; } EditorUtility.ClearProgressBar(); } } GUILayout.EndScrollView(); GUILayout.EndArea(); }