Exemple #1
0
        async void LoadModelAsync(string path)
        {
            if (!File.Exists(path))
            {
                return;
            }

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

            switch (ext)
            {
            case ".vrm":
            {
                var data = new GlbFileParser(path).Parse();

                using (var context = new VRMImporterContext(data))
                {
                    await m_texts.UpdateMetaAsync(context);

                    var loaded = await context.LoadAsync();

                    loaded.EnableUpdateWhenOffscreen();
                    loaded.ShowMeshes();
                    SetModel(loaded.gameObject);
                }
                break;
            }

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

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

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

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

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

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

            default:
                Debug.LogWarningFormat("unknown file type: {0}", path);
                break;
            }
        }
Exemple #2
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;
            }
        }