コード例 #1
0
        public IEnumerator SavedTwice()
        {
            var childA = GameObject.CreatePrimitive(PrimitiveType.Cube);

            childA.name = "child A";

            var logger = new CollectingLogger();
            var export = new GameObjectExport(logger: logger);

            export.AddScene(new [] { childA });
            var path = Path.Combine(Application.persistentDataPath, "SavedTwice1.gltf");
            var task = export.SaveToFileAndDispose(path);

            yield return(Utils.WaitForTask(task));

            var success = task.Result;

            Assert.IsTrue(success);
            AssertLogger(logger);
#if GLTF_VALIDATOR && UNITY_EDITOR
            ValidateGltf(path, MessageCode.UNUSED_OBJECT);
#endif
            Assert.Throws <InvalidOperationException>(delegate()
            {
                export.AddScene(new [] { childA });
            });
            path = Path.Combine(Application.persistentDataPath, "SavedTwice2.gltf");
            AssertThrowsAsync <InvalidOperationException>(async() => await export.SaveToFileAndDispose(path));
        }
コード例 #2
0
        public IEnumerator SimpleTree()
        {
            var root   = new GameObject("root");
            var childA = GameObject.CreatePrimitive(PrimitiveType.Cube);

            childA.name = "child A";
            var childB = GameObject.CreatePrimitive(PrimitiveType.Sphere);

            childB.name                    = "child B";
            childA.transform.parent        = root.transform;
            childB.transform.parent        = root.transform;
            childB.transform.localPosition = new Vector3(1, 0, 0);

            var logger = new CollectingLogger();
            var export = new GameObjectExport(logger: logger);

            export.AddScene(new [] { root }, "UnityScene");
            var path = Path.Combine(Application.persistentDataPath, "root.gltf");
            var task = export.SaveToFileAndDispose(path);

            yield return(Utils.WaitForTask(task));

            var success = task.Result;

            Assert.IsTrue(success);
            AssertLogger(logger);
#if GLTF_VALIDATOR && UNITY_EDITOR
            ValidateGltf(path, MessageCode.UNUSED_OBJECT);
#endif
        }
コード例 #3
0
        async Task ExportSceneAll(bool binary, bool toStream = false)
        {
            var sceneName = GetExportSceneName();

            SceneManager.LoadScene(sceneName, LoadSceneMode.Single);

            var scene = SceneManager.GetActiveScene();

            var rootObjects = scene.GetRootGameObjects();

            var logger = new CollectingLogger();
            var export = new GameObjectExport(
                new ExportSettings {
                format = binary ? GltfFormat.Binary : GltfFormat.Json,
                fileConflictResolution = FileConflictResolution.Overwrite,
            },
                logger: logger
                );

            export.AddScene(rootObjects, sceneName);
            var extension = binary ? GltfGlobals.glbExt : GltfGlobals.gltfExt;
            var path      = Path.Combine(Application.persistentDataPath, $"ExportScene{extension}");

            bool success;

            if (toStream)
            {
                var glbStream = new MemoryStream();
                success = await export.SaveToStreamAndDispose(glbStream);

                Assert.Greater(glbStream.Length, 20);
                glbStream.Close();
            }
            else
            {
                success = await export.SaveToFileAndDispose(path);
            }
            Assert.IsTrue(success);
            AssertLogger(logger);
#if GLTF_VALIDATOR && UNITY_EDITOR
            ValidateGltf(path, new [] {
                MessageCode.ACCESSOR_ELEMENT_OUT_OF_MAX_BOUND,
                MessageCode.ACCESSOR_MAX_MISMATCH,
                MessageCode.ACCESSOR_MIN_MISMATCH,
                MessageCode.NODE_EMPTY,
                MessageCode.UNUSED_OBJECT,
            });
#endif
        }
コード例 #4
0
        public IEnumerator Empty()
        {
            var logger = new CollectingLogger();
            var export = new GameObjectExport(logger: logger);
            var path   = Path.Combine(Application.persistentDataPath, "Empty.gltf");
            var task   = export.SaveToFileAndDispose(path);

            yield return(Utils.WaitForTask(task));

            var success = task.Result;

            Assert.IsTrue(success);
            AssertLogger(logger);
#if GLTF_VALIDATOR && UNITY_EDITOR
            ValidateGltf(path, MessageCode.UNUSED_OBJECT);
#endif
        }
コード例 #5
0
        public IEnumerator TwoScenes()
        {
            var childA = GameObject.CreatePrimitive(PrimitiveType.Cube);

            childA.name = "child A";

            var logger = new CollectingLogger();
            var export = new GameObjectExport(logger: logger);

            export.AddScene(new [] { childA }, "scene A");
            export.AddScene(new [] { childA }, "scene B");
            var path = Path.Combine(Application.persistentDataPath, "TwoScenes.gltf");
            var task = export.SaveToFileAndDispose(path);

            yield return(Utils.WaitForTask(task));

            var success = task.Result;

            Assert.IsTrue(success);
            AssertLogger(logger);
#if GLTF_VALIDATOR && UNITY_EDITOR
            ValidateGltf(path, MessageCode.UNUSED_OBJECT);
#endif
        }