コード例 #1
0
        private FireBoxRoom MakeRoom()
        {
            FireBoxRoom fireBoxRoom  = new FireBoxRoom();
            float       uniformScale = room.UniformScale;

            // copy data
            fireBoxRoom.Assets.Assets    = room.AllAssets.ToArray();
            fireBoxRoom.Room.Elements    = room.RoomElements.ToArray();
            fireBoxRoom.Room.FarDistance = room.FarPlaneDistance;

            if (room.PortalPos != null)
            {
                fireBoxRoom.Room.pos  = JanusUtil.FormatVector3(room.PortalPos.Value);
                fireBoxRoom.Room.xdir = JanusUtil.FormatVector3(room.PortalXDir.Value);
                fireBoxRoom.Room.ydir = JanusUtil.FormatVector3(room.PortalYDir.Value);
                fireBoxRoom.Room.zdir = JanusUtil.FormatVector3(room.PortalZDir.Value);
            }

            // implicit operators
            fireBoxRoom.Room.skybox_back_id  = room.SkyboxBack;
            fireBoxRoom.Room.skybox_front_id = room.SkyboxFront;
            fireBoxRoom.Room.skybox_left_id  = room.SkyboxLeft;
            fireBoxRoom.Room.skybox_right_id = room.SkyboxRight;
            fireBoxRoom.Room.skybox_up_id    = room.SkyboxUp;
            fireBoxRoom.Room.skybox_down_id  = room.SkyboxDown;

            fireBoxRoom.Room.cubemap_irradiance_id = room.CubemapIrradiance;
            fireBoxRoom.Room.cubemap_radiance_id   = room.CubemapRadiance;

            return(fireBoxRoom);
        }
コード例 #2
0
        public void Process(Component[] comps)
        {
            float uniformScale = room.UniformScale;

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

                if (comp is JanusVREntryPortal)
                {
                    JanusVREntryPortal portal          = (JanusVREntryPortal)comp;
                    Transform          portalTransform = portal.transform;

                    Vector3 portalPos = JanusUtil.ConvertPosition(portal.GetJanusPosition(), uniformScale);
                    Vector3 xDir, yDir, zDir;

                    Quaternion rot = portalTransform.rotation;
                    //rot.eulerAngles += new Vector3(0, 180, 0);
                    JanusUtil.GetJanusVectors(rot, out xDir, out yDir, out zDir);

                    room.PortalPos  = portalPos;
                    room.PortalXDir = xDir;
                    room.PortalYDir = yDir;
                    room.PortalZDir = zDir;
                }
                else if (comp is JanusVRLink)
                {
                    JanusVRLink link = (JanusVRLink)comp;

                    Transform trans = link.transform;
                    Vector3   pos = JanusUtil.ConvertPosition(link.GetJanusPosition(), uniformScale);
                    Vector3   sca = trans.localScale;
                    Vector3   xDir, yDir, zDir;
                    JanusUtil.GetJanusVectors(trans.rotation, out xDir, out yDir, out zDir);

                    LinkObject linkObj = new LinkObject();
                    linkObj.pos   = pos;
                    linkObj.xDir  = xDir;
                    linkObj.yDir  = yDir;
                    linkObj.zDir  = zDir;
                    linkObj.col   = link.Color;
                    linkObj.scale = sca;
                    linkObj.url   = link.url;
                    linkObj.title = link.title;
                    //linkObj.image_id = link.url;

                    Material mat = link.meshRenderer.sharedMaterial;
                    Texture  tex = mat.mainTexture;
                    if (tex != null)
                    {
                    }

                    room.AddLinkObject(linkObj);
                }
            }
        }
コード例 #3
0
 public static void GetJanusVectors(Quaternion rot,
                                    out Vector3 xDir, out Vector3 yDir, out Vector3 zDir)
 {
     xDir = JanusUtil.ConvertDirection(rot * Vector3.right);
     yDir = JanusUtil.ConvertDirection(rot * Vector3.up);
     zDir = JanusUtil.ConvertDirection(rot * Vector3.forward);
 }
コード例 #4
0
 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;
     }
 }
コード例 #5
0
        public void SetNoUnityObj(JanusRoom room)
        {
            //Vector3 xDir = Vector3.right;
            //Vector3 yDir = Vector3.up;
            //Vector3 zDir = Vector3.forward;
            //xDir.x *= -1;
            //yDir.x *= -1;
            //zDir.x *= -1;

            //xdir = JanusUtil.FormatVector3(xDir, JanusGlobals.DecimalCasesForTransforms);
            //ydir = JanusUtil.FormatVector3(yDir, JanusGlobals.DecimalCasesForTransforms);
            //zdir = JanusUtil.FormatVector3(zDir, JanusGlobals.DecimalCasesForTransforms);
            pos      = JanusUtil.FormatVector3(Vector3.zero, JanusGlobals.DecimalCasesForTransforms);
            scale    = JanusUtil.FormatVector3(Vector3.one * room.UniformScale, JanusGlobals.DecimalCasesForTransforms);
            lighting = room.LightmapType == LightmapExportType.None;
        }
コード例 #6
0
        public void SetUnityObj(GameObject obj, JanusRoom room)
        {
            unityObj = obj;

            Transform trans    = obj.transform;
            Vector3   position = trans.position;

            Quaternion rot = trans.rotation;

            if (room.UseEulerRotations)
            {
                Vector3 euler = JanusUtil.ConvertEulerRotation(rot.eulerAngles);
                rotation = JanusUtil.FormatVector3(euler, JanusGlobals.DecimalCasesForTransforms);
            }
            else
            {
                Vector3 xDir = JanusUtil.ConvertDirection(rot * Vector3.right);
                Vector3 yDir = JanusUtil.ConvertDirection(rot * Vector3.up);
                Vector3 zDir = JanusUtil.ConvertDirection(rot * Vector3.forward);

                xdir = JanusUtil.FormatVector3(xDir, JanusGlobals.DecimalCasesForTransforms);
                ydir = JanusUtil.FormatVector3(yDir, JanusGlobals.DecimalCasesForTransforms);
                zdir = JanusUtil.FormatVector3(zDir, JanusGlobals.DecimalCasesForTransforms);
            }
            pos = JanusUtil.FormatVector3(JanusUtil.ConvertPosition(position, room.UniformScale), JanusGlobals.DecimalCasesForTransforms);

            Vector3 sca = trans.lossyScale;

            if (sca.x < 0 || sca.y < 0 || sca.z < 0)
            {
                cull_face = "front";
            }
            scale = JanusUtil.FormatVector3(trans.lossyScale * room.UniformScale, JanusGlobals.DecimalCasesForTransforms);

            if (obj.isStatic &&
                room.LightmapType != LightmapExportType.None)
            {
                lighting = false;
            }
            else
            {
                lighting = true;
            }
        }
コード例 #7
0
        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);
                }
            }
        }
コード例 #8
0
        /// <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;
        }
コード例 #9
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);
        }
コード例 #10
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);
        }
コード例 #11
0
        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);
        }
コード例 #12
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);
                }
            }
        }
コード例 #13
0
 public void SetLightmap(Vector4 lightmap)
 {
     lmap_sca = JanusUtil.FormatVector4(lightmap, JanusGlobals.DecimalCasesForLightmaps);
 }
コード例 #14
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();
        }