public MaterialScanner(JanusRoom room) { this.room = room; textureNames = new List <string>(); lightmapped = new Dictionary <int, List <RoomObject> >(); }
public static Vector2[][] GetMeshUVs(JanusRoom room, Mesh mesh, int fakeUvSize = 0) { int uvLayers = LightmapNeedsUV1(room) ? 2 : 1; bool needUvOverride = LightmapNeedsUVOverride(room); Vector2[][] uvs = new Vector2[uvLayers][]; for (int i = 0; i < uvLayers; i++) { Vector2[] array = null; #if !UNITY_5_3_OR_NEWER List <Vector2> tverts = new List <Vector2>(); if (needUvOverride) { mesh.GetUVs(1, tverts); } else { mesh.GetUVs(i, tverts); } array = tverts.ToArray(); #else switch (i) { case 0: if (needUvOverride) { array = mesh.uv2; } else { array = mesh.uv; } break; case 1: array = mesh.uv2; break; } #endif if (fakeUvSize > 0 && (array == null || array.Length == 0)) { array = new Vector2[fakeUvSize]; } if (i == 1 && array == null || array.Length == 0 && room.LightmapType != LightmapExportType.None) { Debug.LogWarning("Lightmapping is enabled but mesh has no UV1 channel - " + mesh.name + " - Tick the Generate Lightmap UVs", mesh); } uvs[i] = array; } return(uvs); }
private void Export(bool onlyHtml) { room = new JanusRoom(); room.ExportOnlyHtml = onlyHtml; CopyParametersToRoom(); room.Initialize(searchType); room.PreExport(exportPath); room.ExportAssetImages(); room.ExportAssetObjects(); room.WriteHtml("index.html"); room.Cleanup(); }
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; }
public static ObjectScanner GetObjectScanner(AssetObjectSearchType type, JanusRoom room) { switch (type) { case AssetObjectSearchType.EachMesh: return(new BruteForceObjectScanner()); case AssetObjectSearchType.PerMaterial: return(new PerMaterialObjectScanner()); case AssetObjectSearchType.PerLightmapId: return(new PerLightmapIDScanner()); default: return(null); } }
public override void Initialize(JanusRoom room, GameObject[] rootObjects) { this.room = room; materialScanner = new MaterialScanner(room); compExtractor = new JanusComponentExtractor(room); EditorUtility.DisplayProgressBar("Janus VR Exporter", "Brute force scanning for AssetObjects...", 0.0f); materialScanner.Initialize(); for (int i = 0; i < rootObjects.Length; i++) { GameObject root = rootObjects[i]; RecursiveSearch(root); } room.FarPlaneDistance = (int)Math.Max(500, sceneBounds.size.magnitude * 1.3f); }
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; } }
public static MeshData GetMeshData(JanusRoom room, Mesh mesh) { MeshData data = new MeshData(); Vector3[] vertices = mesh.vertices; Vector3[] normals = mesh.normals; int[] triangles = mesh.triangles; data.Vertices = vertices; data.Normals = normals; data.Triangles = triangles; data.Name = mesh.name; if (vertices == null || vertices.Length == 0) { Debug.LogWarning("Mesh is empty " + mesh.name, mesh); return(null); } // check if we have all the data int maximum = triangles.Max(); if (normals.Length < maximum) { Debug.LogWarning("Mesh has not enough normals - " + mesh.name, mesh); return(null); } string meshPath = AssetDatabase.GetAssetPath(mesh); if (!string.IsNullOrEmpty(meshPath)) { ModelImporter importer = (ModelImporter)ModelImporter.GetAtPath(meshPath); if (importer != null) { data.Scale = importer.globalScale; } } data.UV = GetMeshUVs(room, mesh); return(data); }
public override void Initialize(JanusRoom room, GameObject[] rootObjects) { this.room = room; lightmapIdScanner = new LightmapIDScanner(room); compExtractor = new JanusComponentExtractor(room); meshesToExport = new Dictionary <int, PerMaterialMeshExportData>(); EditorUtility.DisplayProgressBar("Janus VR Exporter", "Per lightmap id scanning for AssetObjects...", 0.0f); lightmapIdScanner.Initialize(); for (int i = 0; i < rootObjects.Length; i++) { GameObject root = rootObjects[i]; RecursiveSearch(root); } room.FarPlaneDistance = (int)Math.Max(500, sceneBounds.size.magnitude * 1.3f); }
public static bool LightmapNeedsUVOverride(JanusRoom room) { return(room.LightmapType == LightmapExportType.BakedMaterial); }
public static bool LightmapNeedsUV1(JanusRoom room) { return(room.LightmapType == LightmapExportType.Packed || room.LightmapType == LightmapExportType.Unpacked); }
public JanusRoomWriterXml(JanusRoom room) { this.room = room; }
public abstract void Initialize(JanusRoom room);
public JanusComponentExtractor(JanusRoom room) { this.room = room; }
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(); }
public override void Initialize(JanusRoom room) { this.room = room; }
public abstract void Initialize(JanusRoom room, GameObject[] rootObjects);