Пример #1
0
        public static void SetSampler(this Texture2D texture, GLTFTextureSampler sampler)
        {
            if (texture == null)
            {
                return;
            }
            var wrapModes = GetUnityWrapModes(sampler);

            foreach (var kv in wrapModes)
            {
                switch (kv.Key)
                {
                case TextureWrapType.All:
                    texture.wrapMode = kv.Value;
                    break;

                case TextureWrapType.U:
                    texture.wrapModeU = kv.Value;
                    break;

                case TextureWrapType.V:
                    texture.wrapModeV = kv.Value;
                    break;

                case TextureWrapType.W:
                    texture.wrapModeW = kv.Value;
                    break;

                default:
                    throw new NotImplementedException();
                }
            }

            texture.filterMode = sampler.minFilter.ToFilterMode();
        }
Пример #2
0
        private static IEnumerable <KeyValuePair <TextureWrapType, TextureWrapMode> > GetUnityWrapModes(GLTFTextureSampler sampler)
        {
            if (sampler.wrapS == sampler.wrapT)
            {
                switch (sampler.wrapS)
                {
                case GLTFWrap.NONE:     // default
                    yield return(TypeWithMode(TextureWrapType.All, TextureWrapMode.Repeat));

                    break;

                case GLTFWrap.CLAMP_TO_EDGE:
                    yield return(TypeWithMode(TextureWrapType.All, TextureWrapMode.Clamp));

                    break;

                case GLTFWrap.REPEAT:
                    yield return(TypeWithMode(TextureWrapType.All, TextureWrapMode.Repeat));

                    break;

                case GLTFWrap.MIRRORED_REPEAT:
                    yield return(TypeWithMode(TextureWrapType.All, TextureWrapMode.Mirror));

                    break;

                default:
                    throw new NotImplementedException();
                }
            }
            else
            {
                switch (sampler.wrapS)
                {
                case GLTFWrap.NONE:     // default
                    yield return(TypeWithMode(TextureWrapType.U, TextureWrapMode.Repeat));

                    break;

                case GLTFWrap.CLAMP_TO_EDGE:
                    yield return(TypeWithMode(TextureWrapType.U, TextureWrapMode.Clamp));

                    break;

                case GLTFWrap.REPEAT:
                    yield return(TypeWithMode(TextureWrapType.U, TextureWrapMode.Repeat));

                    break;

                case GLTFWrap.MIRRORED_REPEAT:
                    yield return(TypeWithMode(TextureWrapType.U, TextureWrapMode.Mirror));

                    break;

                default:
                    throw new NotImplementedException();
                }
                switch (sampler.wrapT)
                {
                case GLTFWrap.NONE:     // default
                    yield return(TypeWithMode(TextureWrapType.V, TextureWrapMode.Repeat));

                    break;

                case GLTFWrap.CLAMP_TO_EDGE:
                    yield return(TypeWithMode(TextureWrapType.V, TextureWrapMode.Clamp));

                    break;

                case GLTFWrap.REPEAT:
                    yield return(TypeWithMode(TextureWrapType.V, TextureWrapMode.Repeat));

                    break;

                case GLTFWrap.MIRRORED_REPEAT:
                    yield return(TypeWithMode(TextureWrapType.V, TextureWrapMode.Mirror));

                    break;

                default:
                    throw new NotImplementedException();
                }
            }
        }