コード例 #1
0
        private static void ExportFromMenu()
        {
            var go   = Selection.activeObject as GameObject;
            var path = EditorUtility.SaveFilePanel("Save glb", "", go.name + ".glb", "glb");

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            var gltf = new GLTFRoot();

            using (var exporter = new GLTFExporter(gltf))
            {
                exporter.Prepare(go);
                exporter.Export();
            }
            var bytes = gltf.ToGlbBytes();

            File.WriteAllBytes(path, bytes);

            if (path.StartsWithUnityAssetPath())
            {
                AssetDatabase.ImportAsset(path.ToUnityRelativePath());
                AssetDatabase.Refresh();
            }
        }
コード例 #2
0
        private static void ExportGLTFFromMenu()
        {
            var go   = Selection.activeObject as GameObject;
            var path = EditorUtility.SaveFolderPanel("Save GLTF", "", go.name);

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            Debug.Log("export ... " + path);
            if (!path.EndsWith(go.name))
            {
                path += Path.AltDirectorySeparatorChar + go.name;
            }
            Debug.Log(path + "exist = " + Directory.Exists(path));
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            var gltf     = new GLTFRoot();
            var exporter = new GLTFExporter(gltf);

            exporter.Prepare(go);
            exporter.Export();
            Debug.Log("exported");
            var res = SaveFiles(path, go.name, exporter);
            // return;
            // var bytes = gltf.ToGlbBytes();
            // File.WriteAllBytes(path, bytes);

            // if (path.StartsWithUnityAssetPath())
            // {
            //     AssetDatabase.ImportAsset(path.ToUnityRelativePath());
            //     AssetDatabase.Refresh();
            // }
        }
コード例 #3
0
        public void UniGLTFSimpleSceneTest()
        {
            var go      = CreateSimpelScene();
            var context = new GLTFImporter();

            try
            {
                // export
                var gltf = new GLTFRoot();

                string json = null;
                using (var exporter = new GLTFExporter(gltf))
                {
                    exporter.Prepare(go);
                    exporter.Export();

                    // remove empty buffer
                    gltf.buffers.Clear();

                    json = gltf.ToJson();
                }

                // import
                context.ParseJson(json, new SimpleStorage(new ArraySegment <byte>()));
                //Debug.LogFormat("{0}", context.Json);
                //context.Load();

                AssertAreEqual(go.transform, context.root.transform);
            }
            finally
            {
                //Debug.LogFormat("Destory, {0}", go.name);
                GameObject.DestroyImmediate(go);
                context.EditorDestroyRootAndAssets();
            }
        }