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; } }
/// <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; }
public void WriteHtml(string path) { LightmapExportType lightmapExportType = room.LightmapType; float uniformScale = room.UniformScale; XmlWriterSettings settings = new XmlWriterSettings(); settings.OmitXmlDeclaration = true; settings.Encoding = Encoding.UTF8; builder = new StringBuilder(); writer = (XmlTextWriter)XmlWriter.Create(builder, settings); writer.Formatting = Formatting.Indented; writer.WriteStartDocument(); writer.WriteStartElement("html"); writer.WriteStartElement("head"); writer.WriteStartElement("title"); writer.WriteString("Janus Unity Exporter v" + JanusGlobals.Version); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteStartElement("body"); FireBoxRoom fireBoxRoom = MakeRoom(); XmlSerializer fireBoxRoomSerializer = new XmlSerializer(typeof(FireBoxRoom)); fireBoxRoomSerializer.Serialize(writer, fireBoxRoom, fireBoxRoom.Namespaces); writer.WriteEndDocument(); writer.Close(); writer.Flush(); UnityUtil.WriteAllText(path, builder.ToString()); return; }
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); } } }
private void OnGUI() { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Export Path"); exportPath = EditorGUILayout.TextField(exportPath); if (GUILayout.Button("...")) { // search for a folder exportPath = EditorUtility.OpenFolderPanel("JanusVR Export Folder", exportPath, @"C:\"); } EditorGUILayout.EndHorizontal(); defaultMeshFormat = (ExportMeshFormat)EditorGUILayout.EnumPopup("Default Mesh Format", defaultMeshFormat); defaultTexFormat = (ImageFormatEnum)EditorGUILayout.EnumPopup("Default Textures Format", defaultTexFormat); filterMode = (TextureFilterMode)EditorGUILayout.EnumPopup("Texture Filter", filterMode); defaultQuality = EditorGUILayout.IntSlider("Default Textures Quality", defaultQuality, 0, 100); uniformScale = EditorGUILayout.FloatField("Uniform Scale", uniformScale); exportMaterials = EditorGUILayout.Toggle("Export Materials", exportMaterials); exportSkybox = EditorGUILayout.Toggle("Export Skybox (6-sided)", exportSkybox); lightmapExportType = (LightmapExportType)EditorGUILayout.EnumPopup("Lightmap Type", lightmapExportType); if (lightmapExportType != LightmapExportType.None) { maxLightMapResolution = Math.Max(32, EditorGUILayout.IntField("Max Lightmap Resolution", maxLightMapResolution)); } if (!string.IsNullOrEmpty(exportPath)) { if (GUILayout.Button("Start Export")) { PreExport(); } } scrollPosition = GUILayout.BeginScrollView(scrollPosition); if (exported != null) { perTextureOptions = EditorGUILayout.Foldout(perTextureOptions, "Per Texture Options"); Rect last = GUILayoutUtility.GetLastRect(); last.y = last.y + last.height; float size = Math.Min(Screen.width * 0.3f, Screen.height * 0.1f); float half = Screen.width * 0.5f; if (perTextureOptions) { for (int i = 0; i < texturesExportedData.Count; i++) { TextureExportData tex = texturesExportedData[i]; Rect r = GUILayoutUtility.GetRect(Screen.width, size * 1.05f); GUI.DrawTexture(new Rect(size * 0.1f, r.y, size, size), tex.Preview); GUI.Label(new Rect(size * 1.1f, r.y, half - size, size), tex.Texture.name); float x1 = half * 1.3f; float y = r.y; float wid = half * 0.6f; GUI.Label(new Rect(half, y, half * 0.3f, last.height), "Format"); tex.Format = (ImageFormatEnum)EditorGUI.EnumPopup(new Rect(x1, y, wid, last.height), tex.Format); y += last.height; GUI.Label(new Rect(half, y, half * 0.3f, last.height), "Resolution"); tex.Resolution = EditorGUI.IntSlider(new Rect(x1, y, wid, last.height), tex.Resolution, 32, tex.Texture.width); y += last.height; GUI.Label(new Rect(half, y, half * 0.3f, last.height), "Export Alpha"); tex.ExportAlpha = EditorGUI.Toggle(new Rect(x1, y, wid, last.height), tex.ExportAlpha); y += last.height; if (SupportsQuality(tex.Format)) { GUI.Label(new Rect(half, y, half * 0.3f, last.height), "Quality"); tex.Quality = EditorGUI.IntSlider(new Rect(x1, y, wid, last.height), tex.Quality, 0, 100); } } } //perModelOptions = EditorGUILayout.Foldout(perModelOptions, "Per Model Options"); //if (perModelOptions) //{ // for (int i = 0; i < meshesExportedData.Count; i++) // { // MeshExportData model = meshesExportedData[i]; // string name = meshesNames[model.Mesh]; // Rect r = GUILayoutUtility.GetRect(Screen.width, size * 1.05f); // //GUI.DrawTexture(new Rect(size * 0.1f, r.y, size, size), model.Preview); // GUI.Label(new Rect(size * 1.1f, r.y, half - size, size), name); // GUI.Label(new Rect(half, r.y, half * 0.3f, last.height), "Format"); // model.Format = (ExportMeshFormat)EditorGUI.EnumPopup(new Rect(half * 1.3f, r.y, half * 0.7f, last.height), model.Format); // } //} if (GUILayout.Button("Do Export")) { DoExport(); } } GUILayout.EndScrollView(); }
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(); }