private VrmLib.Model CreateVrmModel(string path)
        {
            var bytes = File.ReadAllBytes(path);

            if (!VrmLib.Glb.TryParse(bytes, out VrmLib.Glb glb, out Exception ex))
            {
                throw ex;
            }

            // version check
            VrmLib.Model       model = null;
            VrmLib.IVrmStorage storage;
            if (VRMVersionCheck.IsVrm10(glb.Json.Bytes.ToArray()))
            {
                storage = new Vrm10.Vrm10Storage(glb.Json.Bytes, glb.Binary.Bytes);
                model   = VrmLib.ModelLoader.Load(storage, Path.GetFileName(path));
                model.ConvertCoordinate(VrmLib.Coordinates.Unity, ignoreVrm: true);
            }
            else
            {
                throw new NotImplementedException();
            }

            return(model);
        }
Beispiel #2
0
        public static Model CreateVrmModel(byte[] bytes, FileInfo path)
        {
            if (!Glb.TryParse(bytes, out Glb glb, out Exception ex))
            {
                throw ex;
            }

            var flag = VRMVersionCheck.GetVRMExtensionFlag(glb.Json.Bytes);

            if (flag.HasFlag(VRMExtensionFlags.Vrm10))
            {
                var storage = new Vrm10.Vrm10Storage(glb.Json.Bytes, glb.Binary.Bytes);
                var model   = ModelLoader.Load(storage, path.Name);
                model.ConvertCoordinate(Coordinates.Unity);
                return(model);
            }

            if (flag.HasFlag(VRMExtensionFlags.Vrm0X))
            {
                var storage = new GltfSerialization.GltfStorage(path, glb.Json.Bytes, glb.Binary.Bytes);
                var model   = ModelLoader.Load(storage, path.Name);

                // convert meta frm 0x to 10
                var meta0x = model.Vrm.Meta.AvatarPermission;
                model.Vrm.Meta.AvatarPermission = new AvatarPermission
                {
                    AvatarUsage        = meta0x.AvatarUsage,
                    CommercialUsage    = meta0x.CommercialUsage,
                    IsAllowedGameUsage = meta0x.IsAllowedGameUsage,
                    IsAllowedPoliticalOrReligiousUsage = meta0x.IsAllowedPoliticalOrReligiousUsage,
                    IsAllowedSexualUsage  = meta0x.IsAllowedSexualUsage,
                    IsAllowedViolentUsage = meta0x.IsAllowedViolentUsage,
                    OtherPermissionUrl    = meta0x.OtherPermissionUrl,
                };
                model.Vrm.Meta.RedistributionLicense = new RedistributionLicense
                {
                    OtherLicenseUrl = VRM0X_LICENSE_URL,
                };
                UnityEngine.Debug.LogWarning($"convert {model.Vrm.ExporterVersion} to 1.0. please update meta information");

                model.ConvertCoordinate(Coordinates.Unity, ignoreVrm: true);
                return(model);
            }

            throw new NotImplementedException();
        }