예제 #1
0
        async void LoadModelAsync(string path)
        {
            var ext = Path.GetExtension(path).ToLower();

            switch (ext)
            {
            case ".gltf":
            case ".glb":
            case ".zip":
            {
                var instance = await GltfUtility.LoadAsync(path,
                                                           GetIAwaitCaller(m_useAsync.isOn),
                                                           GetGltfMaterialGenerator(m_useUrpMaterial.isOn));

                break;
            }

            case ".vrm":
            {
                VrmUtility.MaterialGeneratorCallback materialCallback = (VRM.glTF_VRM_extensions vrm) => GetVrmMaterialGenerator(m_useUrpMaterial.isOn, vrm);
                VrmUtility.MetaCallback metaCallback = m_texts.UpdateMeta;
                var instance = await VrmUtility.LoadAsync(path, GetIAwaitCaller(m_useAsync.isOn), materialCallback, metaCallback, loadAnimation : m_loadAnimation.isOn);

                SetModel(instance);
                break;
            }

            case ".bvh":
                LoadMotion(path, File.ReadAllText(path));
                break;
            }
        }
예제 #2
0
        async void LoadModel(string path)
        {
            if (!File.Exists(path))
            {
                return;
            }

            Debug.LogFormat("{0}", path);
            var instance = await Vrm10Utility.LoadAsync(path, true, m_useNormalization.isOn,
                                                        awaitCaller : new RuntimeOnlyAwaitCaller(),
                                                        materialGenerator : GetVrmMaterialDescriptorGenerator(m_useUrpMaterial.isOn),
                                                        metaCallback : m_texts.UpdateMeta);

            if (instance == null)
            {
                // fallback to gltf
                instance = await GltfUtility.LoadAsync(path, awaitCaller : new RuntimeOnlyAwaitCaller());
            }
            SetModel(instance);
        }
예제 #3
0
        async void LoadModel(string path)
        {
            if (!File.Exists(path))
            {
                return;
            }

            _cancellationTokenSource?.Dispose();
            _cancellationTokenSource = new CancellationTokenSource();
            var cancellationToken = _cancellationTokenSource.Token;

            try
            {
                Debug.LogFormat("{0}", path);
                var vrm10Instance = await Vrm10.LoadPathAsync(path,
                                                              canLoadVrm0X : true,
                                                              normalizeTransform : m_useNormalization.isOn,
                                                              showMeshes : false,
                                                              awaitCaller : m_useAsync.enabled?(IAwaitCaller) new RuntimeOnlyAwaitCaller() : (IAwaitCaller) new ImmediateCaller(),
                                                                  materialGenerator : GetVrmMaterialDescriptorGenerator(m_useUrpMaterial.isOn),
                                                                  vrmMetaInformationCallback : m_texts.UpdateMeta,
                                                                  ct : cancellationToken);

                if (vrm10Instance != null)
                {
                    // test. error にならなければよい
                    vrm10Instance.Runtime.Expression.SetWeight(ExpressionKey.Aa, 0);

                    if (cancellationToken.IsCancellationRequested)
                    {
                        UnityObjectDestoyer.DestroyRuntimeOrEditor(vrm10Instance.gameObject);
                        cancellationToken.ThrowIfCancellationRequested();
                    }

                    SetModel(vrm10Instance.GetComponent <RuntimeGltfInstance>());
                }
                else
                {
                    // NOTE: load as glTF model if failed to load as VRM 1.0.
                    // TODO: Hand over CancellationToken
                    var gltfModel = await GltfUtility.LoadAsync(path,
                                                                awaitCaller : m_useAsync.enabled?(IAwaitCaller) new RuntimeOnlyAwaitCaller() : (IAwaitCaller) new ImmediateCaller());

                    if (gltfModel == null)
                    {
                        throw new Exception("Failed to load the file as glTF format.");
                    }

                    if (cancellationToken.IsCancellationRequested)
                    {
                        gltfModel.Dispose();
                        cancellationToken.ThrowIfCancellationRequested();
                    }

                    SetModel(gltfModel);
                }
            }
            catch (Exception ex)
            {
                if (ex is OperationCanceledException)
                {
                    Debug.LogWarning($"Canceled to Load: {path}");
                }
                else
                {
                    Debug.LogError($"Failed to Load: {path}");
                    Debug.LogException(ex);
                }
            }
        }