Beispiel #1
0
 public MaterialImporter(IShaderStore shaderStore, Func <int, TextureItem> getTextureFunc)
 {
     m_shaderStore  = shaderStore;
     GetTextureFunc = getTextureFunc;
 }
Beispiel #2
0
 public MaterialImporter(IShaderStore shaderStore, ImporterContext context)
 {
     m_shaderStore = shaderStore;
     m_context     = context;
 }
Beispiel #3
0
        /// StandardShader vaiables
        ///
        /// _Color
        /// _MainTex
        /// _Cutoff
        /// _Glossiness
        /// _Metallic
        /// _MetallicGlossMap
        /// _BumpScale
        /// _BumpMap
        /// _Parallax
        /// _ParallaxMap
        /// _OcclusionStrength
        /// _OcclusionMap
        /// _EmissionColor
        /// _EmissionMap
        /// _DetailMask
        /// _DetailAlbedoMap
        /// _DetailNormalMapScale
        /// _DetailNormalMap
        /// _UVSec
        /// _EmissionScaleUI
        /// _EmissionColorUI
        /// _Mode
        /// _SrcBlend
        /// _DstBlend
        /// _ZWrite
        public static CreateMaterialFunc CreateMaterialFuncFromShader(IShaderStore shaderStore)
        {
            if (shaderStore == null)
            {
                return(null);
            }

            return((ctx, i) =>
            {
                var material = new Material(shaderStore.GetShader(ctx, i));
                material.name = string.Format("material_{0:00}", i);

                if (i >= 0 && i < ctx.GLTF.materials.Count)
                {
                    var x = ctx.GLTF.materials[i];
                    if (x != null)
                    {
                        if (!string.IsNullOrEmpty(x.name))
                        {
                            material.name = ctx.GLTF.GetUniqueMaterialName(i);
                        }
                        //Debug.LogFormat("{0}: {1}", i, material.name);

                        if (x.pbrMetallicRoughness != null)
                        {
                            if (x.pbrMetallicRoughness.baseColorFactor != null)
                            {
                                var color = x.pbrMetallicRoughness.baseColorFactor;
                                material.color = new Color(color[0], color[1], color[2], color[3]);
                            }

                            if (x.pbrMetallicRoughness.baseColorTexture.index != -1)
                            {
                                var texture = ctx.Textures[x.pbrMetallicRoughness.baseColorTexture.index];
                                material.mainTexture = texture.Texture;
                            }

                            if (x.pbrMetallicRoughness.metallicRoughnessTexture.index != -1)
                            {
                                material.EnableKeyword("_METALLICGLOSSMAP");
                                var texture = ctx.Textures[x.pbrMetallicRoughness.metallicRoughnessTexture.index];
                                material.SetTexture("_MetallicGlossMap", texture.GetMetallicRoughnessOcclusionConverted());
                            }
                        }

                        if (x.normalTexture.index != -1)
                        {
                            material.EnableKeyword("_NORMALMAP");
                            var texture = ctx.Textures[x.normalTexture.index];
#if UNITY_EDITOR
                            var textureAssetPath = AssetDatabase.GetAssetPath(texture.Texture);
                            if (!string.IsNullOrEmpty(textureAssetPath))
                            {
                                MarkTextureAssetAsNormalMap(textureAssetPath);
                            }
#endif
                            material.SetTexture("_BumpMap", texture.Texture);
                        }

                        if (x.occlusionTexture.index != -1)
                        {
                            var texture = ctx.Textures[x.occlusionTexture.index];
                            material.SetTexture("_OcclusionMap", texture.GetMetallicRoughnessOcclusionConverted());
                        }

                        if (x.emissiveFactor != null ||
                            x.emissiveTexture.index != -1)
                        {
                            material.EnableKeyword("_EMISSION");
                            material.globalIlluminationFlags &= ~MaterialGlobalIlluminationFlags.EmissiveIsBlack;

                            if (x.emissiveFactor != null)
                            {
                                material.SetColor("_EmissionColor", new Color(x.emissiveFactor[0], x.emissiveFactor[1], x.emissiveFactor[2]));
                            }

                            if (x.emissiveTexture.index != -1)
                            {
                                var texture = ctx.Textures[x.emissiveTexture.index];
                                material.SetTexture("_EmissionMap", texture.Texture);
                            }
                        }
                    }
                }

                return material;
            });
        }
Beispiel #4
0
 public ImporterContext(IShaderStore shaderStore)
 {
     m_shaderStore = shaderStore;
 }
Beispiel #5
0
 public GLTFImporter(IShaderStore shaderStore)
 {
     _shaderStore = shaderStore;
 }