Пример #1
0
        private void LoadModel(string path)
        {
            if (!File.Exists(path))
            {
                return;
            }

            if (Path.GetExtension(path).ToLower() != ".vrm")
            {
                LogOutput.Instance.Write($"unknown file type: {path}");
                return;
            }

            try
            {
                var context = new VRMImporterContext();
                var file    = File.ReadAllBytes(path);
                context.ParseGlb(file);
                var meta = context.ReadMeta(false);

                context.Load();
                context.EnableUpdateWhenOffscreen();
                context.ShowMeshes();
                _sender.SendCommand(MessageFactory.Instance.ModelNameConfirmedOnLoad("VRM File: " + meta.Title));
                SetModel(context.Root);
            }
            catch (Exception ex)
            {
                HandleLoadError(ex);
            }
        }
Пример #2
0
    public async void Play()
    {
        record.RecordIncr();

        var path    = Application.streamingAssetsPath + "/" + "host.vrm";
        var bytes   = await new FileRead().ReadAllBytesAsync(path);
        var context = new VRMImporterContext();

        context.ParseGlb(bytes);
        var meta = context.ReadMeta(false);

        Debug.LogFormat("meta: title:{0}", meta.Title);
        await context.LoadAsyncTask();

        var go = context.Root;

        go.transform.SetParent(transform, false);
        go.transform.position = new Vector3(0, 0, 0);
        context.ShowMeshes();
        var pos = SetupVRIK(go);

        int progress = 0;
        int index    = record.RecordIndex;

        Observable.Interval(TimeSpan.FromSeconds(1 / 60)).Subscribe(_ => { if (progress >= 0)
                                                                           {
                                                                               progress = run(pos, progress, index);
                                                                           }
                                                                    });
    }
Пример #3
0
        private void LoadModelForPreview(string path)
        {
            if (!File.Exists(path))
            {
                return;
            }

            try
            {
                if (Path.GetExtension(path).ToLower() == ".vrm")
                {
                    using (var context = new VRMImporterContext())
                    {
                        context.ParseGlb(File.ReadAllBytes(path));
                        _previewCanvas.Show(context);
                    }
                }
                else
                {
                    LogOutput.Instance.Write("unknown file type: " + path);
                }
            }
            catch (Exception ex)
            {
                HandleLoadError(ex);
            }
        }
Пример #4
0
    public async Task ImportVrmAsync(string fullPath, Transform parent)
    {
        var bytes   = System.IO.File.ReadAllBytes(fullPath);
        var context = new VRMImporterContext();

        context.ParseGlb(bytes);
        await context.LoadAsyncTask();

        var root = context.Root;

        root.transform.SetParent(parent, false);
        root.transform.localPosition = new Vector3(0, 1f, 0);

        // 先にRigidbodyつける
        var rb = root.AddComponent <Rigidbody>();

        rb.freezeRotation = true;

        // コライダつける
        var capsuleCollider = root.AddComponent <CapsuleCollider>();

        capsuleCollider.center = new Vector3(0, 0.7f, 0);
        capsuleCollider.radius = 0.2f;
        capsuleCollider.height = 1.5f;

        //  アニメーションできるように、Animatorつける
        var rootAnimator = root.GetComponent <Animator>();

        rootAnimator.runtimeAnimatorController = loadedAnimatorController;

        // Playerとして扱うならタグつける
        root.tag = TagName.Player;

        context.ShowMeshes();
    }
    public void LoadVRMFromBytes(Byte[] bytes)
    {
        var context = new VRMImporterContext();

        try
        {
            context.ParseGlb(bytes);
            var meta = context.ReadMeta(true);
            context.Load();

            var model = context.Root;
            model.gameObject.name = meta.Title;
            context.ShowMeshes();

            LoadVrmObject = context.Root;
            LoadVrmObject.transform.parent        = ShadowObject.transform;
            LoadVrmObject.transform.localPosition = Vector3.zero;
            LoadVrmObject.transform.localRotation = Quaternion.identity;
            Animator ShadowObjectAnimator = ShadowObject.GetComponent <Animator>();
            Animator VrmObjectAnimator    = LoadVrmObject.GetComponent <Animator>();
            ShadowObjectAnimator.avatar = VrmObjectAnimator.avatar;
            IsVrmLoaded = true;
        }
        catch (Exception e)
        {
            Debug.LogError(e);
        }
    }
Пример #6
0
        IEnumerator Loading(Camera mainCamera, int defaultCullingMask, VrmMeta vrmMeta)
        {
            //Loading表示に切り替えるために1フレーム待つ
            yield return(null);

            var bytes = File.ReadAllBytes(GlobalPath.VrmHomePath + "/" + vrmMeta.VrmFileName);
            var vrmImporterContext = new VRMImporterContext();

            vrmImporterContext.ParseGlb(bytes);
            vrmImporterContext.Load();
            vrmImporterContext.Root.transform.SetParent(vrmRoot, false);
            var vrmAnimationController = vrmImporterContext.Root.AddComponent <VrmAnimationController>();

            vrmAnimationController.Play(defaultAnimation);

            //BlendShapeProxyの初期化を待つ。
            yield return(null);

            var vrmBlendShapeProxy = vrmImporterContext.Root.GetComponent <VRMBlendShapeProxy>();

            vrmBlendShapeProxy.ImmediatelySetValue(defaultBlendShapePreset, defaultBlendShapeValue);
            vrmImporterContext.EnableUpdateWhenOffscreen();
            vrmImporterContext.ShowMeshes();
            poolingVrmImporterContexts.Add(new KeyValuePair <string, VRMImporterContext>(vrmMeta.VrmFileName, vrmImporterContext));
            mainCamera.cullingMask = defaultCullingMask;
        }
Пример #7
0
        /// <summary>
        /// load VRM from byte array
        /// </summary>
        /// <param name="file"></param>
        /// <returns>generated model GameObject</returns>
        public async Task <GameObject> LoadVRM(byte[] file)
        {
            // Parse Json to GLB
            var context = new VRMImporterContext();

            context.ParseGlb(file);

            // Get VRM Meta data
            var meta = context.ReadMeta(true);

            Debug.Log("meta: title: " + meta.Title);

            //load
            await context.LoadAsyncTask();

            //put model
            var root = context.Root;

            root.transform.rotation = new Quaternion(0, 180, 0, 0);
            root.tag = "Player";
            await Task.Delay(500);

            root.AddComponent <ObjectMover>();
            context.ShowMeshes();
            return(root);
        }
Пример #8
0
        async UniTask LoadVRM(string path)
        {
#if UNITY_STANDALONE_WIN //|| UNITY_EDITOR
            var meta = await VRMMetaImporter.ImportVRMMeta(path, true);
#else
            VRMMetaObject meta;
            using (UnityWebRequest uwr = UnityWebRequest.Get(path))
            {
                await uwr.SendWebRequest();

                VRMdata = uwr.downloadHandler.data;
            }
            using (var context = new VRMImporterContext())
            {
                context.ParseGlb(VRMdata);
                meta = context.ReadMeta(true);
            }
#endif
            GameObject modalObject = Instantiate(modalWindowPrefabs, canvas.transform) as GameObject;
            var        modalLocale = modalObject.GetComponentInChildren <VRMPreviewLocale>();
            modalLocale.SetLocale(language.captionText.text);

            var modalUi = modalObject.GetComponentInChildren <VRMPreviewUI>();

            modalUi.setMeta(meta);

            modalUi.setLoadable(true);
        }
Пример #9
0
    /// <summary>Create VRMLoaderUI and set callback</summary>
    ///
    // Those codes are imported from VRMLoaderUI sample
    // https://github.com/m2wasabi/VRMLoaderUI/blob/master/Assets/VRMLoaderUI/Example/Scripts/ModelLoaderLegacy.cs
    void SetupVRMLoaderUI(string[] pathes)
    {
        string path = "file:///" + pathes[0];

        // Load file
        var www = new WWW(path);

        m_context = new VRMImporterContext();
        m_context.ParseGlb(www.bytes);
        var meta = m_context.ReadMeta(true);

        // instantinate UI
        GameObject modalObject = Instantiate(m_modalWindowPrefab, m_canvas.transform) as GameObject;

        // // determine language
        // var modalLocale = modalObject.GetComponentInChildren<VRMPreviewLocale>();
        // modalLocale.SetLocale(m_language.captionText.text);

        // input VRM meta information to UI
        var modalUI = modalObject.GetComponentInChildren <VRMPreviewUI>();

        modalUI.setMeta(meta);

        // Permission of file open
        modalUI.setLoadable(true);

        // define callback on load completed
        modalUI.m_ok.onClick.AddListener(ModelLoad);
    }
Пример #10
0
        void LoadVRM()
        {
            var extensions = new[] {
                new ExtensionFilter("VRM Files", "vrm", "VRM"),
                new ExtensionFilter("All Files", "*"),
            };
            string path = StandaloneFileBrowser.OpenFilePanel("Open VRM", "", extensions, true)[0];

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

            var bytes = File.ReadAllBytes(path);
            // なんらかの方法でByte列を得た

            var context = new VRMImporterContext();

            // GLB形式でJSONを取得しParseします
            context.ParseGlb(bytes);

            // metaを取得(todo: thumbnailテクスチャのロード)
            var meta = context.ReadMeta(true);

            Debug.LogFormat("meta: title:{0}", meta.Title);
            ShowMetaInfo(meta); // UIに表示する

            // ParseしたJSONをシーンオブジェクトに変換していく
            context.LoadAsync(() => OnLoaded(context));
        }
Пример #11
0
    private void Start()
    {
        Avatar = null;

        _buttonVRM?.onClick.AddListener(async() =>
        {
            var bytes = await UniTask.Run(() => ReadBytes());

            if (bytes != null)
            {
                var context = new VRMImporterContext();

                await UniTask.Run(() => context.ParseGlb(bytes));
                var meta = context.ReadMeta(false);

                context.LoadAsync(() => OnLoaded(context));
            }
        });

        _buttonAssetBundle?.onClick.AddListener(async() =>
        {
            string path = await Task.Run(() => OpenFileName.ShowDialog("all", "."));

            //前のアバターの消去
            GameObject[] othreAvatars = GameObject.FindGameObjectsWithTag("Avatar");
            foreach (GameObject otherAvatar in othreAvatars)
            {
                Destroy(otherAvatar);
            }

            StartCoroutine(LoadBundleCoroutine(path));
        });
    }
Пример #12
0
    /// ボタンをクリックした時の処理
    public void OnClick()
    {
        // Open file with filter
        var extensions = new [] {
            new ExtensionFilter("VRM Files", "vrm"),
            new ExtensionFilter("All Files", "*"),
        };
        var paths = StandaloneFileBrowser.OpenFilePanel("Open File", "", extensions, true);

        if (paths.Length > 0)
        {
            var file = paths[0];

            byte[] bytes   = FileBrowserHelpers.ReadBytesFromFile(file);
            var    context = new VRMImporterContext();
            try {
                context.ParseGlb(bytes);
                msg.text = "Import VRM finished successfully. (" + file + ")";
                var meta = context.ReadMeta(false); //引数をTrueに変えるとサムネイルも読み込みます
                Debug.LogFormat("meta: title:{0}", meta.Title);
                //同期処理で読み込みます
                context.Load();
                //読込が完了するとcontext.RootにモデルのGameObjectが入っています
                Destroy(instance);
                instance = context.Root;
                instance.transform.position = new Vector3(0, 0, 0);
                instance.transform.rotation = Quaternion.Euler(0, 0, 0);
                instance.AddComponent <PMXExporter>();
                context.ShowMeshes();
            } catch (Exception ex) {
                msg.text = "Error: " + ex.Message;
            }
        }
    }
Пример #13
0
        private async void ImportVRMAsync(string FilePath)
        {
            //VRMファイルのパスを指定します
            var path = FilePath;

            //ファイルをByte配列に読み込みます
            var bytes = File.ReadAllBytes(path);

            //VRMImporterContextがVRMを読み込む機能を提供します
            var context = new VRMImporterContext();

            // GLB形式でJSONを取得しParseします
            context.ParseGlb(bytes);

            // VRMのメタデータを取得
            var meta = context.ReadMeta(false); //引数をTrueに変えるとサムネイルも読み込みます

            //読み込めたかどうかログにモデル名を出力してみる
            Debug.LogFormat("meta: title:{0}", meta.Title);

            //非同期処理で読み込みます
            //context.LoadAsync(_ => OnLoaded(context));
            await context.LoadAsyncTask();

            OnLoaded(context);
        }
Пример #14
0
        public void SerializerCompare()
        {
            // Aliciaを古いデシリアライザでロードする
            var path    = AliciaPath;
            var context = new VRMImporterContext();

            context.ParseGlb(File.ReadAllBytes(path));
            var oldJson = context.GLTF.ToJson().ParseAsJson().ToString("  ");

            // 生成シリアライザでJSON化する
            var f = new JsonFormatter();

            f.GenSerialize(context.GLTF);
            var parsed  = f.ToString().ParseAsJson();
            var newJson = parsed.ToString("  ");

            File.WriteAllText("old.json", oldJson);
            File.WriteAllText("new.json", newJson);

            // 比較
            Assert.AreEqual(oldJson.ParseAsJson().ToString(), newJson.ParseAsJson().ToString());

            // 生成デシリアライザでロードする
            var ff  = new JsonFormatter();
            var des = GltfDeserializer.Deserialize(parsed);

            ff.Clear();
            ff.GenSerialize(des);
            var desJson = ff.ToString().ParseAsJson().ToString("  ");

            Assert.AreEqual(oldJson.ParseAsJson().ToString(), desJson.ParseAsJson().ToString());
        }
Пример #15
0
        IEnumerator LoadVRMCoroutine(string path)
        {
            var www = new WWW(path);

            yield return(www);

            // GLB形式のperse
            m_context = new VRMImporterContext();
            m_context.ParseGlb(www.bytes);

            // meta情報を読み込む
            bool createThumbnail = true;
            var  meta            = m_context.ReadMeta(createThumbnail);

            // ファイル読み込みモーダルウィンドウの呼び出し
            GameObject modalObject = Instantiate(m_modalWindowPrefab, m_canvas.transform) as GameObject;

            // 言語設定を取得・反映する
            var modalLocale = modalObject.GetComponentInChildren <VRMPreviewLocale>();

            modalLocale.SetLocale(m_language.captionText.text);

            // meta情報の反映
            var modalUI = modalObject.GetComponentInChildren <VRMPreviewUI>();

            modalUI.setMeta(meta);

            // ファイルを開くことの許可
            // ToDo: ファイルの読み込み許可を制御する場合はここで
            modalUI.setLoadable(true);

            modalUI.m_ok.onClick.AddListener(ModelLoad);
        }
        void LoadVRM(byte[] bytes)
        {
            // GLB形式のperse
            var context = new VRMImporterContext();

            context.ParseGlb(bytes);

            // meta情報を読み込む
            bool createThumbnail = true;
            var  meta            = context.ReadMeta(createThumbnail);

            // ファイル読み込みモーダルウィンドウの呼び出し
            GameObject modalObject = Instantiate(m_modalWindowPrefab, m_canvas.transform) as GameObject;

            // 言語設定を取得・反映する
            var modalLocale = modalObject.GetComponentInChildren <VRMPreviewLocale>();

            modalLocale.SetLocale(m_language.captionText.text);

            // meta情報の反映
            var modalUI = modalObject.GetComponentInChildren <VRMPreviewUI>();

            modalUI.setMeta(meta);

            // ファイルを開くことの許可
            // ToDo: ファイルの読み込み許可を制御する場合はここで
            modalUI.setLoadable(true);

            // UniRxでイベントリスナ作成
            modalUI.m_ok.onClick.AsObservable().Subscribe(_ => ModelLoad(context)).AddTo(modalObject);
        }
Пример #17
0
        public void GetModelFromName(string name, GameObject parent, GameObject MouseObject)
        {
            try
            {
                string ModelPath = Application.streamingAssetsPath + "../../../Data/vrm/" + name + ".vrm";
                if (System.IO.File.Exists(ModelPath))
                {
                    var bytes   = File.ReadAllBytes(ModelPath);
                    var context = new VRMImporterContext();
                    context.ParseGlb(bytes);
                    var metaObject = context.ReadMeta(false);

                    /*Debug.LogFormat("meta: title:{0}", metaObject.Title);
                     * Debug.LogFormat("meta: version:{0}", metaObject.Version);
                     * Debug.LogFormat("meta: author:{0}", metaObject.Author);
                     * Debug.LogFormat("meta: exporterVersion:{0}", metaObject.ExporterVersion);*/
                    var modelD = Path.GetDirectoryName(ModelPath);
                    context.LoadAsync(() => {
                        OnLoaded(context, parent, metaObject, modelD, MouseObject);
                    }, OnError);
                }
                else
                {
                    throw new Exception(Globle.LangController.GetLang("LOG.FileUnisset"));
                }
            }
            catch (Exception err)
            {
                Globle.AddDataLog("Main", Globle.LangController.GetLang("LOG.ModelAddationException", err.Message));
            }
        }
Пример #18
0
        public static VrmMeta Generate(string vrmFileFullName)
        {
            var bytes = File.ReadAllBytes(vrmFileFullName);
            var vrmImporterContext = new VRMImporterContext();

            vrmImporterContext.ParseGlb(bytes);
            var meta = vrmImporterContext.ReadMeta(true);

            var vrmMeta = new VrmMeta
            {
                VrmFileName        = Path.GetFileName(vrmFileFullName),
                Title              = meta.Title,
                Version            = meta.Version,
                Author             = meta.Author,
                ContactInformation = meta.ContactInformation,
                Reference          = meta.Reference,
                Thumbnail          = meta.Thumbnail?.EncodeToPNG(),
                ThumbnailWidth     = meta.Thumbnail ? meta.Thumbnail.width : 0,
                ThumbnailHeight    = meta.Thumbnail ? meta.Thumbnail.height : 0,
                AllowedUser        = meta.AllowedUser,
                ViolentUssage      = meta.ViolentUssage,
                SexualUssage       = meta.SexualUssage,
                CommercialUssage   = meta.CommercialUssage,
                OtherPermissionUrl = meta.OtherPermissionUrl,
                LicenseType        = meta.LicenseType,
                OtherLicenseUrl    = meta.OtherLicenseUrl,
            };

            vrmImporterContext.Dispose();
            return(vrmMeta);
        }
Пример #19
0
        /// <summary>
        /// 非同期でByte配列からVRMImporterContextの初期化をします
        /// </summary>
        /// <param name="vrmByteArray"></param>
        public async Task InitializeVrmContextFromByteArrayAsync(byte[] vrmByteArray)
        {
#if UNIVRM_LEGACY_IMPORTER
            // VRMImporterContextがVRMを読み込む機能を提供します
            currentContext = new VRMImporterContext();

            // GLB形式でJSONを取得しParseします
            await Task.Run(() => currentContext.ParseGlb(vrmByteArray));
#elif UNIVRM_0_68_IMPORTER
            var parser = new GltfParser();
            await Task.Run(() => parser.ParseGlb(vrmByteArray));

            currentContext = new VRMImporterContext(parser);
#elif UNIVRM_0_77_IMPORTER
            var      parser = new GlbLowLevelParser(string.Empty, vrmByteArray);
            GltfData data   = null;

            await Task.Run(() =>
            {
                data = parser.Parse();
            });

            currentContext  = new VRMImporterContext(data);
            currentInstance = null;
#else
#endif
        }
Пример #20
0
        public void LoadModel(string path)
        {
            if (!File.Exists(path))
            {
                return;
            }

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

            if (ext != ".vrm")
            {
                Debug.LogWarning($"unknown file type: {path}");
                return;
            }

            var context = new VRMImporterContext();
            var file    = File.ReadAllBytes(path);

            context.ParseGlb(file);
            m_texts.UpdateMeta(context);

            context.Load();
            context.ShowMeshes();
            context.EnableUpdateWhenOffscreen();
            context.ShowMeshes();
            SetModel(context.Root);
        }
Пример #21
0
        public void LoadModelOnlyForPreview(string path)
        {
            if (!File.Exists(path))
            {
                return;
            }

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

            switch (ext)
            {
            case ".vrm":
                using (var context = new VRMImporterContext())
                {
                    context.ParseGlb(File.ReadAllBytes(path));
                    m_texts.UpdateMeta(context);
                }
                break;

            default:
                Debug.LogWarningFormat("unknown file type: {0}", path);
                break;
            }
        }
Пример #22
0
    public void LoadRequest(string path, Action <string, byte[]> callback)
    {
        byte[] bytes = File.ReadAllBytes(path);

        var context = new VRMImporterContext();

        context.ParseGlb(bytes);
        var meta = context.ReadMeta(true);

        GameObject modalObject = Instantiate(m_modalWindowPrefab, m_canvas.transform) as GameObject;
        var        modalLocale = modalObject.GetComponentInChildren <VRMPreviewLocale>();

        modalLocale.SetLocale("ja");

        if (modalUI != null)
        {
            modalUI.destroyMe();
            modalUI = null;
        }

        modalUI = modalObject.GetComponentInChildren <VRMPreviewUI>();
        modalUI.setMeta(meta);
        modalUI.setLoadable(true);

        callbackHandler = callback;
        VRMdata         = bytes;
        VRMpath         = path;
    }
Пример #23
0
    /// <summary>
    /// VRMファイルを読み込む
    /// </summary>
    /// <param name="bytes"></param>
    /// <returns></returns>
    async Task <VRMImporterContext> Load(string path)
    {
        var context = new VRMImporterContext();

        try
        {
            context.ParseGlb(File.ReadAllBytes(path));
            await context.LoadAsyncTask();
        }
        catch
        {
            context.Dispose();
            throw;
        }

        if (await AskLoadingVRM(path, context.ReadMeta(true)))
        {
            return(context);
        }
        else
        {
            context.Dispose();
            return(null);
        }
    }
        void OnLoadClicked()
        {
#if UNITY_STANDALONE_WIN
            var path = FileDialogForWindows.FileDialog("open VRM", ".vrm");
#else
            var path = Application.dataPath + "/default.vrm";
#endif
            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            var bytes = File.ReadAllBytes(path);
            // なんらかの方法でByte列を得た

            var context = new VRMImporterContext();

            // GLB形式でJSONを取得しParseします
            context.ParseGlb(bytes);


            // metaを取得(todo: thumbnailテクスチャのロード)
            var meta = context.ReadMeta();
            Debug.LogFormat("meta: title:{0}", meta.Title);

            // ParseしたJSONをシーンオブジェクトに変換していく
            context.LoadAsync(() => OnLoaded(context));
        }
Пример #25
0
        private void LoadModel(string path)
        {
            if (!File.Exists(path))
            {
                return;
            }

            if (Path.GetExtension(path).ToLower() != ".vrm")
            {
                LogOutput.Instance.Write($"unknown file type: {path}");
                return;
            }

            TryWithoutException(() =>
            {
                var context = new VRMImporterContext();
                var file    = File.ReadAllBytes(path);
                context.ParseGlb(file);

                context.Load();
                context.EnableUpdateWhenOffscreen();
                context.ShowMeshes();
                SetModel(context.Root);
            });
        }
Пример #26
0
        //ファイルからモデルを読み込む
        public void LoadVRMFromData(byte[] VRMdata)
        {
            if (isLoading)
            {
                Debug.LogError("Now Loading! load request is rejected.");
                return;
            }
            DestroyModel();

            //読み込み
            VRMImporterContext vrmImporter = new VRMImporterContext();

            vrmImporter.ParseGlb(VRMdata);

            isLoading = true;
            vrmImporter.LoadAsync(() =>
            {
                isLoading = false;
                Model     = vrmImporter.Root;

                //ExternalReceiverの下にぶら下げる
                LoadedModelParent = new GameObject();
                LoadedModelParent.transform.SetParent(transform, false);
                LoadedModelParent.name = "LoadedModelParent";
                //その下にモデルをぶら下げる
                Model.transform.SetParent(LoadedModelParent.transform, false);

                vrmImporter.EnableUpdateWhenOffscreen();
                vrmImporter.ShowMeshes();

                //カメラなどの移動補助のため、頭の位置を格納する
                animator     = Model.GetComponent <Animator>();
                HeadPosition = animator.GetBoneTransform(HumanBodyBones.Head).position;
            });
        }
        /// <summary>
        /// Taskで非同期にロードする例
        /// </summary>
        async void LoadVRMClicked()
        {
#if UNITY_STANDALONE_WIN
            var path = FileDialogForWindows.FileDialog("open VRM", ".vrm");
#else
            var path = Application.dataPath + "/default.vrm";
#endif
            if (string.IsNullOrEmpty(path))
            {
                return;
            }


            var context = new VRMImporterContext();

            var bytes = await ReadBytesAsync(path);

            // GLB形式でJSONを取得しParseします
            context.ParseGlb(bytes);

            // metaを取得(todo: thumbnailテクスチャのロード)
            var meta = context.ReadMeta();
            Debug.LogFormat("meta: title:{0}", meta.Title);

            // ParseしたJSONをシーンオブジェクトに変換していく
            var now = Time.time;
            await context.LoadAsyncTask();

            var delta = Time.time - now;
            Debug.LogFormat("LoadVrmAsync {0:0.0} seconds", delta);
            OnLoaded(context);
        }
Пример #28
0
    private async System.Threading.Tasks.Task onLoadVRMAsync(AvatarSetting setting)
    {
        videoCapture.PlayStop();

        var path = "";

        if (setting.AvatarType == 0)
        {
            path = setting.VRMFilePath;
        }
        else
        {
            path = setting.FBXFilePath;
        }

        if (path != "")
        {
            //ファイルをByte配列に読み込みます
            var bytes = File.ReadAllBytes(path);

            //VRMImporterContextがVRMを読み込む機能を提供します
            var context = new VRMImporterContext();

            // GLB形式でJSONを取得しParseします
            context.ParseGlb(bytes);

            // VRMのメタデータを取得
            var meta = context.ReadMeta(false); //引数をTrueに変えるとサムネイルも読み込みます

            //読み込めたかどうかログにモデル名を出力してみる
            //Debug.LogFormat("meta: title:{0}", meta.Title);

            //非同期処理(Task)で読み込みます
            await context.LoadAsyncTask();

            ///
            //読込が完了するとcontext.RootにモデルのGameObjectが入っています
            var avatarObject = context.Root;
            avatarObject.name = setting.AvatarName;

            //モデルをワールド上に配置します
            avatarObject.transform.SetParent(transform.parent, false);

            SetVRMBounds(avatarObject.transform);

            //メッシュを表示します
            context.ShowMeshes();

            setting.Avatar             = avatarObject.AddComponent <VNectModel>();
            setting.Avatar.ModelObject = avatarObject;
            setting.Avatar.SetNose(setting.FaceOriX, setting.FaceOriY, setting.FaceOriZ);
            setting.Avatar.SkeletonMaterial = skeletonMaterial;
            DiactivateAvatars();
            avatars.options.Add(new Dropdown.OptionData(setting.AvatarName));
            barracudaRunner.InitVNectModel(setting.Avatar, configurationSetting);
        }
    }
Пример #29
0
        void LoadModel(string path)
        {
            if (!File.Exists(path))
            {
                return;
            }

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

            switch (ext)
            {
            case ".vrm":
            {
                var context = new VRMImporterContext();
                var file    = File.ReadAllBytes(path);
                context.ParseGlb(file);
                m_texts.UpdateMeta(context);
                context.Load();
                context.ShowMeshes();
                context.EnableUpdateWhenOffscreen();
                context.ShowMeshes();
                SetModel(context.Root);
                break;
            }

            case ".glb":
            {
                var context = new UniGLTF.ImporterContext();
                var file    = File.ReadAllBytes(path);
                context.ParseGlb(file);
                context.Load();
                context.ShowMeshes();
                context.EnableUpdateWhenOffscreen();
                context.ShowMeshes();
                SetModel(context.Root);
                break;
            }

            case ".gltf":
            case ".zip":
            {
                var context = new UniGLTF.ImporterContext();
                context.Parse(path);
                context.Load();
                context.ShowMeshes();
                context.EnableUpdateWhenOffscreen();
                context.ShowMeshes();
                SetModel(context.Root);
                break;
            }

            default:
                Debug.LogWarningFormat("unknown file type: {0}", path);
                break;
            }
        }
Пример #30
0
    void LoadVRMClicked_WebGL(Byte[] bytes)
    {
        var context = new VRMImporterContext();

        // GLB形式でJSONを取得しParseします
        context.ParseGlb(bytes);

        context.Load();
        OnLoaded(context);
    }