コード例 #1
0
        void Load(VrmMeta vrmMeta)
        {
            var localVrmItem = Instantiate(localVrmItemPrefab, localVrmItemRoot);

            localVrmItem.transform.SetSiblingIndex(0);
            localVrmItem.Initialize(vrmMeta, vrmSpawner, downloadVrmItemSpawner);
        }
コード例 #2
0
ファイル: VrmMeta.cs プロジェクト: d30835nm/vrmviewerforquest
        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);
        }
コード例 #3
0
        public void Initialize(VrmMeta vrmMeta, VrmSpawner vrmSpawner, DownloadVrmItemSpawner downloadVrmItemSpawner)
        {
            this.vrmMeta                = vrmMeta;
            this.vrmSpawner             = vrmSpawner;
            this.downloadVrmItemSpawner = downloadVrmItemSpawner;

            if (vrmMeta.Thumbnail != null)
            {
                thumbnailTexture = new Texture2D(vrmMeta.ThumbnailWidth, vrmMeta.ThumbnailHeight);
                thumbnailTexture.LoadImage(vrmMeta.Thumbnail);
                thumbnailSprite = Sprite.Create(texture: thumbnailTexture, rect: new Rect(0, 0, thumbnailTexture.width, thumbnailTexture.height),
                                                pivot: new Vector2(0.5f, 0.5f));
            }

            thumbnail.sprite = thumbnailSprite;

            var parameterList = vrmMeta.GetParameterList();

            foreach (var parameter in parameterList)
            {
                var textElement = Instantiate(textElementPrefab, this.transform);
                textElement.Initialize(parameter.Key, parameter.Value);
            }

            selectButton.onClick.AddListener(() => Select());
            removeButton.onClick.AddListener(() => Remove());
        }
コード例 #4
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;
        }
コード例 #5
0
        IEnumerator Loading(Camera mainCamera, int defaultCullingMask, string vrmFileFullName)
        {
            //Loading表示に切り替えるために1フレーム待つ
            yield return(null);

            var vrmMeta = VrmMeta.Generate(vrmFileFullName);

            vrmMeta.Save();
            Load(vrmMeta);
            mainCamera.cullingMask = defaultCullingMask;
        }
コード例 #6
0
        void LoadAll()
        {
            if (!Directory.Exists(GlobalPath.VrmHomePath))
            {
                return;
            }

            var dir                 = new DirectoryInfo(GlobalPath.VrmHomePath);
            var vrmMetaInfos        = dir.GetFiles("*" + VrmMeta.Extension);
            var orderedVrmMetaInfos = vrmMetaInfos.OrderBy(f => f.LastWriteTime);

            foreach (var vrmMetaInfo in orderedVrmMetaInfos)
            {
                Load(VrmMeta.Load(vrmMetaInfo.FullName));
            }
        }
コード例 #7
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);
            vrmImporterContext.EnableUpdateWhenOffscreen();
            vrmImporterContext.ShowMeshes();
            poolingVrmImporterContexts.Add(new KeyValuePair <string, VRMImporterContext>(vrmMeta.VrmFileName, vrmImporterContext));
            mainCamera.cullingMask = defaultCullingMask;
        }
コード例 #8
0
        public void SelectVrm(VrmMeta vrmMeta)
        {
            var currentVrmImporterContext = poolingVrmImporterContexts.SingleOrDefault(v => v.Key == vrmMeta.VrmFileName);

            if (!currentVrmImporterContext.Equals(default(KeyValuePair <string, VRMImporterContext>)))
            {
                foreach (var poolingVrmImporterContext in poolingVrmImporterContexts)
                {
                    poolingVrmImporterContext.Value.Root.SetActive(false);
                }

                currentVrmImporterContext.Value.Root.SetActive(true);
                return;
            }

            if (!File.Exists(GlobalPath.VrmHomePath + "/" + vrmMeta.VrmFileName))
            {
                Debug.LogError(GlobalPath.VrmHomePath + "/" + vrmMeta.VrmFileName + "のファイルが存在しません。");
                return;
            }

            if (poolingVrmImporterContexts.Count >= MaxPoolingNum)
            {
                poolingVrmImporterContexts[0].Value.Dispose();
                poolingVrmImporterContexts.RemoveAt(0);
            }

            foreach (var poolingVrmImporterContext in poolingVrmImporterContexts)
            {
                poolingVrmImporterContext.Value.Root.SetActive(false);
            }

            var mainCamera         = Camera.main;
            var defaultCullingMask = mainCamera.cullingMask;

            mainCamera.cullingMask = 1 << LayerMask.NameToLayer("Loading");
            StartCoroutine(Loading(mainCamera, defaultCullingMask, vrmMeta));
        }