forked from alvani/Unity-glTF-Exporter
-
Notifications
You must be signed in to change notification settings - Fork 14
/
GlTF_ExporterWindow.cs
99 lines (90 loc) · 2.84 KB
/
GlTF_ExporterWindow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Xml;
public class GlTFExporterWindow : EditorWindow
{
const string KEY_PATH = "GlTFPath";
const string KEY_FILE = "GlTFFile";
static public string path = "?";
static string savedPath;
static string savedFile;
static XmlDocument xdoc;
static Preset preset = new Preset();
static UnityEngine.TextAsset presetAsset;
GameObject exporterGo;
SceneToGlTFWiz exporter;
bool buildZip = false;
bool convertImages = false;
bool exportAnimation = true;
//EditorPrefs.SetString(KEY_PATH, savedPath);
//EditorPrefs.SetString(KEY_FILE, savedFile);
//[MenuItem("Tools/Export to glTF")]
static void CreateWizard()
{
savedPath = EditorPrefs.GetString(KEY_PATH, "/");
savedFile = EditorPrefs.GetString(KEY_FILE, "test.gltf");
path = savedPath + "/" + savedFile;
// ScriptableWizard.DisplayWizard("Export Selected Stuff to glTF", typeof(SceneToGlTFWiz), "Export");
GlTFExporterWindow window = (GlTFExporterWindow)EditorWindow.GetWindow(typeof(GlTFExporterWindow));
window.Show();
}
void OnWizardUpdate()
{
// Texture[] txs = Selection.GetFiltered(Texture, SelectionMode.Assets);
// Debug.Log("found "+txs.Length);
}
void OnGUI()
{
GUILayout.Label("Export Options");
GlTF_Writer.binary = GUILayout.Toggle(GlTF_Writer.binary, "Binary GlTF");
buildZip = GUILayout.Toggle(buildZip, "Export Zip");
// Force animation baking for now
GlTF_Writer.bakeAnimation = GUILayout.Toggle(true, "Bake animations (forced for now)");
exportAnimation = GUILayout.Toggle(exportAnimation, "Export animations");
convertImages = GUILayout.Toggle(convertImages, "Convert images");
presetAsset = EditorGUILayout.ObjectField("Preset file", presetAsset, typeof(UnityEngine.TextAsset), false) as UnityEngine.TextAsset;
if (!exporterGo)
{
exporterGo = new GameObject("exporter");
}
if(!exporter)
{
exporter = exporterGo.AddComponent<SceneToGlTFWiz>();
}
GUI.enabled = (Selection.GetTransforms(SelectionMode.Deep).Length > 0);
if (GUILayout.Button("Export to glTF"))
{
ExportFile();
}
GUI.enabled = true;
}
void OnDestroy()
{
GameObject.DestroyImmediate(exporterGo);
exporter = null;
}
void ExportFile() // Create (Export) button has been hit (NOT wizard has been created!)
{
var ext = GlTF_Writer.binary ? "glb" : "gltf";
path = EditorUtility.SaveFilePanel("Save glTF file as", savedPath, savedFile, ext);
if (path.Length != 0)
{
if (presetAsset != null)
{
string psPath = AssetDatabase.GetAssetPath(presetAsset);
if (psPath != null)
{
psPath = psPath.Remove(0, "Assets".Length);
psPath = Application.dataPath + psPath;
preset.Load(psPath);
}
}
exporter.ExportCoroutine(path, preset, buildZip, true, exportAnimation, convertImages);
}
}
}
#endif