Пример #1
0
        async Task <Vrm10Instance> LoadAsync(string path, VRMShaders.IAwaitCaller awaitCaller)
        {
            var instance = await Vrm10.LoadPathAsync(path, awaitCaller : awaitCaller);

            // VR用 FirstPerson 設定
            await instance.Vrm.FirstPerson.SetupAsync(instance.gameObject, awaitCaller);

            return(instance);
        }
Пример #2
0
        async void Run()
        {
            var src      = new FileInfo(m_vrmPath);
            var instance = await Vrm10.LoadPathAsync(m_vrmPath, true, true);

            var exportedBytes = Vrm10Exporter.Export(instance.gameObject);

            // Import 1.0
            var vrm10 = await Vrm10.LoadBytesAsync(exportedBytes, false, true);

            var pos = vrm10.transform.position;

            pos.x += 1.5f;
            vrm10.transform.position = pos;
            vrm10.name = vrm10.name + "_Imported_v1_0";

            // write
            var path = Path.GetFullPath("vrm10.vrm");

            Debug.Log($"write : {path}");
            File.WriteAllBytes(path, exportedBytes);
        }
Пример #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);
                }
            }
        }