| | 1 | | using System; |
| | 2 | | using UnityEditor; |
| | 3 | | using UnityEngine.SceneManagement; |
| | 4 | | using UnityGLTF; |
| | 5 | |
|
| | 6 | | public class GLTFExportMenu : EditorWindow |
| | 7 | | { |
| | 8 | | public static string RetrieveTexturePath(UnityEngine.Texture texture) |
| | 9 | | { |
| 0 | 10 | | return AssetDatabase.GetAssetPath(texture); |
| | 11 | | } |
| | 12 | |
|
| | 13 | | [MenuItem("GLTF/Settings")] |
| | 14 | | static void Init() |
| | 15 | | { |
| 0 | 16 | | GLTFExportMenu window = (GLTFExportMenu)EditorWindow.GetWindow(typeof(GLTFExportMenu), false, "GLTF Settings"); |
| 0 | 17 | | window.Show(); |
| 0 | 18 | | } |
| | 19 | |
|
| | 20 | | void OnGUI() |
| | 21 | | { |
| 0 | 22 | | EditorGUILayout.LabelField("Exporter", EditorStyles.boldLabel); |
| 0 | 23 | | GLTFSceneExporter.ExportFullPath = EditorGUILayout.Toggle("Export using original path", GLTFSceneExporter.Export |
| 0 | 24 | | GLTFSceneExporter.ExportNames = EditorGUILayout.Toggle("Export names of nodes", GLTFSceneExporter.ExportNames); |
| 0 | 25 | | GLTFSceneExporter.RequireExtensions = EditorGUILayout.Toggle("Require extensions", GLTFSceneExporter.RequireExte |
| 0 | 26 | | EditorGUILayout.Separator(); |
| 0 | 27 | | EditorGUILayout.LabelField("Importer", EditorStyles.boldLabel); |
| 0 | 28 | | EditorGUILayout.Separator(); |
| 0 | 29 | | EditorGUILayout.HelpBox("UnityGLTF version 0.1", MessageType.Info); |
| 0 | 30 | | EditorGUILayout.HelpBox("Supported extensions: KHR_material_pbrSpecularGlossiness, ExtTextureTransform", Message |
| 0 | 31 | | } |
| | 32 | |
|
| | 33 | | [MenuItem("GLTF/Export Selected")] |
| | 34 | | static void ExportSelected() |
| | 35 | | { |
| | 36 | | string name; |
| 0 | 37 | | if (Selection.transforms.Length > 1) |
| | 38 | | { |
| 0 | 39 | | name = SceneManager.GetActiveScene().name; |
| 0 | 40 | | } |
| 0 | 41 | | else if (Selection.transforms.Length == 1) |
| | 42 | | { |
| 0 | 43 | | name = Selection.activeGameObject.name; |
| 0 | 44 | | } |
| | 45 | | else |
| | 46 | | { |
| 0 | 47 | | throw new Exception("No objects selected, cannot export."); |
| | 48 | | } |
| | 49 | |
|
| 0 | 50 | | var exporter = new GLTFSceneExporter(Selection.transforms, RetrieveTexturePath); |
| | 51 | |
|
| 0 | 52 | | var path = EditorUtility.OpenFolderPanel("glTF Export Path", "", ""); |
| 0 | 53 | | if (!string.IsNullOrEmpty(path)) |
| | 54 | | { |
| 0 | 55 | | exporter.SaveGLTFandBin(path, name); |
| | 56 | | } |
| 0 | 57 | | } |
| | 58 | |
|
| | 59 | | [MenuItem("GLTF/ExportGLB Selected")] |
| | 60 | | static void ExportGLBSelected() |
| | 61 | | { |
| | 62 | | string name; |
| 0 | 63 | | if (Selection.transforms.Length > 1) |
| | 64 | | { |
| 0 | 65 | | name = SceneManager.GetActiveScene().name; |
| 0 | 66 | | } |
| 0 | 67 | | else if (Selection.transforms.Length == 1) |
| | 68 | | { |
| 0 | 69 | | name = Selection.activeGameObject.name; |
| 0 | 70 | | } |
| | 71 | | else |
| | 72 | | { |
| 0 | 73 | | throw new Exception("No objects selected, cannot export."); |
| | 74 | | } |
| | 75 | |
|
| 0 | 76 | | var exporter = new GLTFSceneExporter(Selection.transforms, RetrieveTexturePath); |
| | 77 | |
|
| 0 | 78 | | var path = EditorUtility.OpenFolderPanel("glTF Export Path", "", ""); |
| 0 | 79 | | if (!string.IsNullOrEmpty(path)) |
| | 80 | | { |
| 0 | 81 | | exporter.SaveGLB(path, name); |
| | 82 | | } |
| 0 | 83 | | } |
| | 84 | |
|
| | 85 | | [MenuItem("GLTF/Export Scene")] |
| | 86 | | static void ExportScene() |
| | 87 | | { |
| 0 | 88 | | var scene = SceneManager.GetActiveScene(); |
| 0 | 89 | | var gameObjects = scene.GetRootGameObjects(); |
| 0 | 90 | | var transforms = Array.ConvertAll(gameObjects, gameObject => gameObject.transform); |
| | 91 | |
|
| 0 | 92 | | var exporter = new GLTFSceneExporter(transforms, RetrieveTexturePath); |
| 0 | 93 | | var path = EditorUtility.OpenFolderPanel("glTF Export Path", "", ""); |
| 0 | 94 | | if (path != "") |
| | 95 | | { |
| 0 | 96 | | exporter.SaveGLTFandBin(path, scene.name); |
| | 97 | | } |
| 0 | 98 | | } |
| | 99 | | } |