Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
4.3 KiB

  1. /************************************************************************************
  2. Filename : ONSPPropagationGeometryEditor.cs
  3. Content : Geometry editor class
  4. Attach to geometry to define material properties
  5. Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
  6. Licensed under the Oculus SDK Version 3.5 (the "License");
  7. you may not use the Oculus SDK except in compliance with the License,
  8. which is provided at the time of installation or download, or which
  9. otherwise accompanies this software in either electronic or hard copy form.
  10. You may obtain a copy of the License at
  11. https://developer.oculus.com/licenses/sdk-3.5/
  12. Unless required by applicable law or agreed to in writing, the Oculus SDK
  13. distributed under the License is distributed on an "AS IS" BASIS,
  14. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. See the License for the specific language governing permissions and
  16. limitations under the License.
  17. ************************************************************************************/
  18. //#define ENABLE_DEBUG_EXPORT_OBJ
  19. using UnityEngine;
  20. using UnityEditor;
  21. [CustomEditor(typeof(ONSPPropagationGeometry))]
  22. public class ONSPPropagationGeometryEditor : Editor
  23. {
  24. public override void OnInspectorGUI()
  25. {
  26. ONSPPropagationGeometry mesh = (ONSPPropagationGeometry)target;
  27. EditorGUI.BeginChangeCheck();
  28. bool newIncludeChildMeshes = EditorGUILayout.Toggle( new GUIContent("Include Child Meshes","Include all child meshes into single geometry instance"), mesh.includeChildMeshes );
  29. Separator();
  30. #if UNITY_EDITOR
  31. string newFilePath = mesh.filePath;
  32. bool editedPath = false;
  33. bool writeMesh = false;
  34. EditorGUI.BeginDisabledGroup( Application.isPlaying );
  35. bool newFileEnabled = EditorGUILayout.Toggle( new GUIContent("File Enabled","If set, the serialized mesh file is used as the mesh data source"), mesh.fileEnabled );
  36. EditorGUILayout.LabelField( new GUIContent("File Path:","The path to the serialized mesh file, relative to the StreamingAssets directory" ),
  37. new GUIContent(mesh.filePathRelative != null ? mesh.filePathRelative : ""));
  38. EditorGUILayout.BeginHorizontal();
  39. EditorGUILayout.PrefixLabel( " " );
  40. if ( GUILayout.Button("Set Path") )
  41. {
  42. if (!System.IO.Directory.Exists(Application.streamingAssetsPath))
  43. {
  44. System.IO.Directory.CreateDirectory(Application.streamingAssetsPath);
  45. }
  46. string directory = Application.streamingAssetsPath;
  47. string fileName = mesh.gameObject.name + "." + ONSPPropagationGeometry.GEOMETRY_FILE_EXTENSION;
  48. if (newFilePath != "")
  49. {
  50. directory = System.IO.Path.GetDirectoryName(newFilePath);
  51. fileName = System.IO.Path.GetFileName(newFilePath);
  52. }
  53. newFilePath = EditorUtility.SaveFilePanel(
  54. "Save baked mesh to file", directory, fileName,
  55. ONSPPropagationGeometry.GEOMETRY_FILE_EXTENSION);
  56. // If the user canceled, use the old path.
  57. if ( newFilePath == null || newFilePath.Length == 0 )
  58. newFilePath = mesh.filePath;
  59. else
  60. editedPath = true;
  61. }
  62. if ( GUILayout.Button("Bake Mesh to File") )
  63. writeMesh = true;
  64. EditorGUILayout.EndHorizontal();
  65. #if ENABLE_DEBUG_EXPORT_OBJ
  66. // this allows you to export the geometry to a .obj for viewing
  67. // in an external model viewer for debugging/validation
  68. if ( GUILayout.Button("Write to .obj (debug)") )
  69. mesh.WriteToObj();
  70. #endif
  71. EditorGUI.EndDisabledGroup();
  72. #endif
  73. if ( EditorGUI.EndChangeCheck() )
  74. {
  75. Undo.RecordObject( mesh, "Edited OVRAudioMesh" );
  76. mesh.includeChildMeshes = newIncludeChildMeshes;
  77. mesh.fileEnabled = newFileEnabled;
  78. newFilePath = newFilePath.Replace(Application.streamingAssetsPath + "/", "");
  79. if ( editedPath )
  80. mesh.filePathRelative = newFilePath;
  81. if ( editedPath || writeMesh )
  82. mesh.WriteFile();
  83. }
  84. if ( Application.isPlaying && GUILayout.Button("Upload Mesh") )
  85. mesh.UploadGeometry();
  86. }
  87. void Separator()
  88. {
  89. GUI.color = new Color(1, 1, 1, 0.25f);
  90. GUILayout.Box("", "HorizontalSlider", GUILayout.Height(16));
  91. GUI.color = Color.white;
  92. }
  93. }