Exemplo n.º 1
0
        private (GameObject, IReadOnlyList <VRMShaders.MaterialFactory.MaterialLoadInfo>) ToUnity(byte[] bytes)
        {
            // Vrm => Model
            if (!Vrm10Parser.TryParseOrMigrate("tpm.vrm", bytes, true, out Vrm10Parser.Result result))
            {
                throw new Exception();
            }

            return(ToUnity(result.Data, result.Vrm));
        }
Exemplo n.º 2
0
        static GameObject Import(byte[] bytes, FileInfo path)
        {
            if (!Vrm10Parser.TryParseOrMigrate(path.FullName, bytes, doMigrate: true, out Vrm10Parser.Result result))
            {
                return(null);
            }

            using (var loader = new Vrm10Importer(result.Data, result.Vrm))
            {
                var loaded = loader.Load();
                loaded.ShowMeshes();
                return(loaded.gameObject);
            }
        }
Exemplo n.º 3
0
        public void Sample()
        {
            var path = "Tests/Models/Alicia_vrm-0.51/AliciaSolid_vrm-0.51.vrm";

            Debug.Log($"load: {path}");

            Assert.IsTrue(Vrm10Parser.TryParseOrMigrate(path, true, out Vrm10Parser.Result result));

            var go = BuildGameObject(result.Data, result.Vrm, true);

            Debug.Log(go);

            // export
            var vrmBytes = Vrm10Exporter.Export(go, new EditorTextureSerializer());

            Debug.Log($"export {vrmBytes.Length} bytes");
        }
Exemplo n.º 4
0
        void LoadModel(string path)
        {
            if (!File.Exists(path))
            {
                return;
            }

            Debug.LogFormat("{0}", path);
            var ext = Path.GetExtension(path).ToLower();

            switch (ext)
            {
            case ".vrm":
            {
                if (!Vrm10Parser.TryParseOrMigrate(path, doMigrate: true, out Vrm10Parser.Result result))
                {
                    Debug.LogError(result.Message);
                    return;
                }
                using (var loader = new Vrm10Importer(result.Data, result.Vrm))
                {
                    var loaded = loader.Load();
                    loaded.ShowMeshes();
                    loaded.EnableUpdateWhenOffscreen();
                    SetModel(loaded.gameObject);
                }
                break;
            }

            case ".glb":
            {
                var data = new GlbFileParser(path).Parse();

                using (var loader = new UniGLTF.ImporterContext(data))
                {
                    var loaded = loader.Load();
                    loaded.ShowMeshes();
                    loaded.EnableUpdateWhenOffscreen();
                    SetModel(loaded.gameObject);
                }
                break;
            }

            case ".gltf":
            {
                var data = new GltfFileWithResourceFilesParser(path).Parse();

                using (var loader = new UniGLTF.ImporterContext(data))
                {
                    var loaded = loader.Load();
                    loaded.ShowMeshes();
                    loaded.EnableUpdateWhenOffscreen();
                    SetModel(loaded.gameObject);
                }
                break;
            }

            case ".zip":
            {
                var data = new ZipArchivedGltfFileParser(path).Parse();

                using (var loader = new UniGLTF.ImporterContext(data))
                {
                    var loaded = loader.Load();
                    loaded.ShowMeshes();
                    loaded.EnableUpdateWhenOffscreen();
                    SetModel(loaded.gameObject);
                }
                break;
            }

            default:
                Debug.LogWarningFormat("unknown file type: {0}", path);
                break;
            }
        }