Exemplo n.º 1
0
        public void RecursiveSearch(GameObject root)
        {
            if (room.IgnoreInactiveObjects &&
                !root.activeInHierarchy)
            {
                return;
            }

            // loop thorugh all the gameObjects components
            // to see what we can extract
            Component[] comps = root.GetComponents <Component>();
            if (!compExtractor.CanExport(comps))
            {
                compExtractor.Process(comps);
                return;
            }

            for (int i = 0; i < comps.Length; i++)
            {
                Component comp = comps[i];
                if (!comp)
                {
                    continue;
                }

                if (comp is MeshRenderer)
                {
                    MeshRenderer meshRen = (MeshRenderer)comp;
                    MeshFilter   filter  = comps.FirstOrDefault(c => c is MeshFilter) as MeshFilter;
                    if (filter == null || !meshRen.isVisible)
                    {
                        continue;
                    }

                    Mesh mesh = filter.sharedMesh;
                    if (mesh == null ||
                        !room.CanExportObj(comps))
                    {
                        continue;
                    }

                    Material mat = meshRen.sharedMaterial;
                    if (!mat)
                    {
                        continue;
                    }

                    if (!room.ExportDynamicGameObjects &&
                        !root.isStatic)
                    {
                        continue;
                    }

                    sceneBounds.Encapsulate(meshRen.bounds);

                    PerMaterialMeshExportData data;
                    if (!meshesToExport.TryGetValue(mat, out data))
                    {
                        data = new PerMaterialMeshExportData();
                        meshesToExport.Add(mat, data);

                        AssetObject asset = new AssetObject();
                        data.Asset = asset;

                        asset.id  = mat.name;
                        asset.src = mat.name + ".fbx";
                        room.AddAssetObject(asset);

                        RoomObject obj = new RoomObject();
                        data.Object = obj;
                        obj.id      = mat.name;
                        obj.SetNoUnityObj(room);

                        room.AddRoomObject(obj);
                        compExtractor.ProcessNewRoomObject(obj, comps);
                    }

                    materialScanner.PreProcessObject(meshRen, mesh, data.Asset, data.Object, false);

                    PerMaterialMeshExportDataObj dObj = new PerMaterialMeshExportDataObj();
                    dObj.Mesh      = mesh;
                    dObj.Transform = root.transform;
                    dObj.Renderer  = meshRen;
                    data.Meshes.Add(dObj);
                }
            }

            // loop through all this GameObject children
            foreach (Transform child in root.transform)
            {
                RecursiveSearch(child.gameObject);
            }
        }
Exemplo n.º 2
0
        public void RecursiveSearch(GameObject root)
        {
            if (room.IgnoreInactiveObjects &&
                !root.activeInHierarchy)
            {
                return;
            }

            // loop thorugh all the gameObjects components
            // to see what we can extract
            Component[] comps = root.GetComponents <Component>();
            if (!compExtractor.CanExport(comps))
            {
                compExtractor.Process(comps);
                return;
            }

            for (int i = 0; i < comps.Length; i++)
            {
                Component comp = comps[i];
                if (!comp)
                {
                    continue;
                }

                if (comp is MeshRenderer)
                {
                    MeshRenderer meshRen = (MeshRenderer)comp;
                    MeshFilter   filter  = comps.FirstOrDefault(c => c is MeshFilter) as MeshFilter;
                    if (filter == null)
                    {
                        continue;
                    }

                    Mesh mesh = filter.sharedMesh;
                    if (mesh == null ||
                        !room.CanExportObj(comps) ||
                        mesh.GetTopology(0) != MeshTopology.Triangles)
                    {
                        continue;
                    }

                    if (!room.ExportDynamicGameObjects &&
                        !root.isStatic)
                    {
                        continue;
                    }

                    sceneBounds.Encapsulate(meshRen.bounds);

                    // Only export the mesh if we never exported this one mesh
                    BruteForceMeshExportData exp;
                    if (!meshesToExport.TryGetValue(mesh, out exp))
                    {
                        exp      = new BruteForceMeshExportData();
                        exp.Mesh = mesh;
                        // generate name
                        string meshId = mesh.name;
                        if (string.IsNullOrEmpty(meshId) ||
                            meshNames.Contains(meshId))
                        {
                            meshId = "ExportedMesh" + meshNames.Count;
                        }
                        meshNames.Add(meshId);

                        // keep our version of the data
                        exp.MeshId = meshId;
                        meshesToExport.Add(mesh, exp);

                        // but also supply the data to the Janus Room so the Html can be built
                        AssetObject asset = new AssetObject();
                        exp.Asset = asset;

                        asset.id  = meshId;
                        asset.src = meshId + ".fbx";

                        room.AddAssetObject(asset);
                    }

                    // We are brute force, so all objects become Room Objects
                    RoomObject obj = new RoomObject();
                    obj.id = exp.Asset.id;
                    obj.SetUnityObj(root, room);
                    room.AddRoomObject(obj);
                    compExtractor.ProcessNewRoomObject(obj, comps);

                    // let the material scanner process this object
                    materialScanner.PreProcessObject(meshRen, mesh, exp.Asset, obj, true);
                }
            }

            // loop through all this GameObject children
            foreach (Transform child in root.transform)
            {
                RecursiveSearch(child.gameObject);
            }
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
                }
            }
        }
Exemplo n.º 6
0
 public void AddRoomObject(RoomObject roomObj)
 {
     RoomObjects.Add(roomObj);
     RoomElements.Add(roomObj);
 }
Exemplo n.º 7
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();
        }