예제 #1
0
        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();
        }