Beispiel #1
0
        public async Task <VRMMetaObject> ReadMetaAsync(IAwaitCaller awaitCaller, bool createThumbnail = false)
        {
            if (awaitCaller == null)
            {
                throw new ArgumentNullException();
            }

            var meta = ScriptableObject.CreateInstance <VRMMetaObject>();

            meta.name            = "Meta";
            meta.ExporterVersion = VRM.exporterVersion;

            var gltfMeta = VRM.meta;

            meta.Version            = gltfMeta.version; // model version
            meta.Author             = gltfMeta.author;
            meta.ContactInformation = gltfMeta.contactInformation;
            meta.Reference          = gltfMeta.reference;
            meta.Title = gltfMeta.title;
            if (gltfMeta.texture >= 0)
            {
                var(key, param) = GltfTextureImporter.CreateSrgb(Data, gltfMeta.texture, Vector2.zero, Vector2.one);
                meta.Thumbnail  = await TextureFactory.GetTextureAsync(param, awaitCaller) as Texture2D;
            }
            meta.AllowedUser        = gltfMeta.allowedUser;
            meta.ViolentUssage      = gltfMeta.violentUssage;
            meta.SexualUssage       = gltfMeta.sexualUssage;
            meta.CommercialUssage   = gltfMeta.commercialUssage;
            meta.OtherPermissionUrl = gltfMeta.otherPermissionUrl;

            meta.LicenseType     = gltfMeta.licenseType;
            meta.OtherLicenseUrl = gltfMeta.otherLicenseUrl;

            return(meta);
        }
Beispiel #2
0
        public static bool TryGetTextureFromMaterialProperty(GltfData data, glTF_VRM_Material vrmMaterial, string textureKey, out (SubAssetKey, TextureDescriptor) texture)
        {
            // 任意の shader の import を許容する
            if (/*vrmMaterial.shader == MToon.Utils.ShaderName &&*/ vrmMaterial.textureProperties.TryGetValue(textureKey, out var textureIdx))
            {
                var(offset, scale) = (new Vector2(0, 0), new Vector2(1, 1));
                if (TryGetTextureOffsetAndScale(vrmMaterial, textureKey, out var os))
                {
                    offset = os.offset;
                    scale  = os.scale;
                }

                switch (textureKey)
                {
                case MToon.Utils.PropBumpMap:
                    texture = GltfTextureImporter.CreateNormal(data, textureIdx, offset, scale);
                    break;

                default:
                    texture = GltfTextureImporter.CreateSrgb(data, textureIdx, offset, scale);
                    break;
                }
                return(true);
            }

            texture = default;
            return(false);
        }
        private static bool TryGetThumbnailTexture(GltfData data, glTF_VRM_extensions vrm, out (SubAssetKey, TextureDescriptor) texture)
        {
            if (vrm.meta.texture > -1)
            {
                texture = GltfTextureImporter.CreateSrgb(data, vrm.meta.texture, Vector2.zero, Vector2.one);
                return(true);
            }

            texture = default;
            return(false);
        }
Beispiel #4
0
 private static bool TryGetSRGBTexture(GltfData data, Vrm10TextureInfo info, out (SubAssetKey, TextureDescriptor) pair)
 {
     try
     {
         var(offset, scale) = GetTextureOffsetAndScale(info);
         pair = GltfTextureImporter.CreateSrgb(data, info.index, offset, scale);
         return(true);
     }
     catch (NullReferenceException)
     {
         pair = default;
         return(false);
     }
     catch (ArgumentOutOfRangeException)
     {
         pair = default;
         return(false);
     }
 }