Beispiel #1
0
        public IEnumerable <GetTextureParam> Enumerate(glTF gltf)
        {
            for (int i = 0; i < gltf.materials.Count; ++i)
            {
                var vrmMaterial = m_vrm.materialProperties[i];
                if (vrmMaterial.shader == MToon.Utils.ShaderName)
                {
                    // MToon
                    foreach (var kv in vrmMaterial.textureProperties)
                    {
                        // SRGB color or normalmap
                        yield return(GetTextureParam.Create(gltf, kv.Value, kv.Key));
                    }
                }
                else
                {
                    // PBR or Unlit
                    foreach (var textureInfo in GltfTextureEnumerator.EnumerateTextures(gltf, gltf.materials[i]))
                    {
                        yield return(textureInfo);
                    }
                }
            }

            // thumbnail
            if (m_vrm.meta != null && m_vrm.meta.texture != -1)
            {
                yield return(GetTextureParam.Create(gltf, m_vrm.meta.texture));
            }
        }
Beispiel #2
0
        public async Awaitable <VRMMetaObject> ReadMetaAsync(bool createThumbnail = false)
        {
            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;
            meta.Thumbnail = await TextureFactory.GetTextureAsync(GLTF, GetTextureParam.Create(GLTF, gltfMeta.texture));

            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 #3
0
 public IEnumerable <GetTextureParam> Enumerate(glTF gltf)
 {
     for (int i = 0; i < gltf.materials.Count; ++i)
     {
         var vrmMaterial = m_vrm.materialProperties[i];
         if (vrmMaterial.shader == MToon.Utils.ShaderName)
         {
             // MToon
             foreach (var kv in vrmMaterial.textureProperties)
             {
                 // SRGB color or normalmap
                 yield return(GetTextureParam.Create(gltf, kv.Value, kv.Key, default, default));
Beispiel #4
0
        public static async Task <Material> CreateAsync(IAwaitCaller awaitCaller, glTF gltf, int m_index, glTF_VRM_Material vrmMaterial, GetTextureAsyncFunc getTexture)
        {
            var item       = vrmMaterial;
            var shaderName = item.shader;
            var shader     = Shader.Find(shaderName);

            if (shader == null)
            {
                //
                // no shader
                //
                if (VRM_SHADER_NAMES.Contains(shaderName))
                {
                    Debug.LogErrorFormat("shader {0} not found. set Assets/VRM/Shaders/VRMShaders to Edit - project setting - Graphics - preloaded shaders", shaderName);
                }
                else
                {
                    // #if VRM_DEVELOP
                    //                     Debug.LogWarningFormat("unknown shader {0}.", shaderName);
                    // #endif
                }
                return(await MaterialFactory.DefaultCreateMaterialAsync(awaitCaller, gltf, m_index, getTexture));
            }

            //
            // restore VRM material
            //
            var material = new Material(shader);

            // use material.name, because material name may renamed in GltfParser.
            material.name        = gltf.materials[m_index].name;
            material.renderQueue = item.renderQueue;

            foreach (var kv in item.floatProperties)
            {
                material.SetFloat(kv.Key, kv.Value);
            }
            foreach (var kv in item.vectorProperties)
            {
                if (item.textureProperties.ContainsKey(kv.Key))
                {
                    // texture offset & scale
                    material.SetTextureOffset(kv.Key, new Vector2(kv.Value[0], kv.Value[1]));
                    material.SetTextureScale(kv.Key, new Vector2(kv.Value[2], kv.Value[3]));
                }
                else
                {
                    // vector4
                    var v = new Vector4(kv.Value[0], kv.Value[1], kv.Value[2], kv.Value[3]);
                    material.SetVector(kv.Key, v);
                }
            }
            foreach (var kv in item.textureProperties)
            {
                var param   = GetTextureParam.Create(gltf, kv.Value, kv.Key, 1, 1);
                var texture = await getTexture(awaitCaller, gltf, param);

                if (texture != null)
                {
                    material.SetTexture(kv.Key, texture);
                }
            }
            foreach (var kv in item.keywordMap)
            {
                if (kv.Value)
                {
                    material.EnableKeyword(kv.Key);
                }
                else
                {
                    material.DisableKeyword(kv.Key);
                }
            }
            foreach (var kv in item.tagMap)
            {
                material.SetOverrideTag(kv.Key, kv.Value);
            }

            if (shaderName == MToon.Utils.ShaderName)
            {
                // TODO: Material拡張にMToonの項目が追加されたら旧バージョンのshaderPropから変換をかける
                // インポート時にUniVRMに含まれるMToonのバージョンに上書きする
                material.SetFloat(MToon.Utils.PropVersion, MToon.Utils.VersionNumber);
            }

            return(material);
        }