private SamplerId ExportSampler(UnityEngine.Texture texture)
        {
            var samplerId = GetSamplerId(_root, texture);

            if (samplerId != null)
            {
                return(samplerId);
            }

            var sampler = new Sampler();

            if (texture.wrapMode == TextureWrapMode.Clamp)
            {
                sampler.WrapS = GLTF.Schema.WrapMode.ClampToEdge;
                sampler.WrapT = GLTF.Schema.WrapMode.ClampToEdge;
            }
            else
            {
                sampler.WrapS = GLTF.Schema.WrapMode.Repeat;
                sampler.WrapT = GLTF.Schema.WrapMode.Repeat;
            }

            if (texture.filterMode == FilterMode.Point)
            {
                sampler.MinFilter = MinFilterMode.NearestMipmapNearest;
                sampler.MagFilter = MagFilterMode.Nearest;
            }
            else if (texture.filterMode == FilterMode.Bilinear)
            {
                sampler.MinFilter = MinFilterMode.NearestMipmapLinear;
                sampler.MagFilter = MagFilterMode.Linear;
            }
            else
            {
                sampler.MinFilter = MinFilterMode.LinearMipmapLinear;
                sampler.MagFilter = MagFilterMode.Linear;
            }

            samplerId = new SamplerId
            {
                Id   = _root.Samplers.Count,
                Root = _root
            };

            _root.Samplers.Add(sampler);

            return(samplerId);
        }
        private TextureId GenerateTexture(Texture2D texture, ImageId imageId)
        {
            if (root.Textures == null)
            {
                root.Textures = new List<GLTF.Schema.Texture>();
            }

            if (root.Samplers == null)
            {
                root.Samplers = new List<GLTF.Schema.Sampler>();
            }

            var hasMipMap = texture.mipmapCount > 0;
            MagFilterMode magFilter = MagFilterMode.None;
            MinFilterMode minFilter = MinFilterMode.None;
            GLTF.Schema.WrapMode wrap = GLTF.Schema.WrapMode.None;

            switch (texture.filterMode)
            {
                case FilterMode.Point:
                    magFilter = MagFilterMode.Nearest;
                    if (hasMipMap)
                    {
                        minFilter = MinFilterMode.NearestMipmapNearest;
                    }
                    else
                    {
                        minFilter = MinFilterMode.Nearest;
                    }
                    break;

                case FilterMode.Bilinear:
                    magFilter = MagFilterMode.Linear;
                    if (hasMipMap)
                    {
                        minFilter = MinFilterMode.LinearMipmapNearest;
                    }
                    else
                    {
                        minFilter = MinFilterMode.Linear;
                    }
                    break;

                case FilterMode.Trilinear:
                    magFilter = MagFilterMode.Linear;
                    if (hasMipMap)
                    {
                        minFilter = MinFilterMode.Linear;
                    }
                    else
                    {
                        minFilter = MinFilterMode.LinearMipmapLinear;
                    }
                    break;
            }

            switch (texture.wrapMode)
            {
                case TextureWrapMode.Clamp:
                    wrap = GLTF.Schema.WrapMode.ClampToEdge;
                    break;
                case TextureWrapMode.Repeat:
                    wrap = GLTF.Schema.WrapMode.Repeat;
                    break;
            }

            var sampler = new Sampler
            {
                MagFilter = magFilter,
                MinFilter = minFilter,
                WrapS = wrap,
                WrapT = wrap
            };
            root.Samplers.Add(sampler);
            var samplerId = new SamplerId { Id = root.Samplers.Count - 1, Root = root };

            var gltfTexture = new GLTF.Schema.Texture { Source = imageId, Sampler = samplerId };
            root.Textures.Add(gltfTexture);

            var id = new TextureId { Id = root.Textures.Count - 1, Root = root };
            _texture2d2ID[texture] = id;

            return id;
        }
Пример #3
0
 internal static void InitSamplerState(SamplerId id)
 {
     if (SamplerObjects[id.Index] == null)
         SamplerObjects[id.Index] = new SamplerState(MyRender11.Device, SamplerStates.Data[id.Index]);
 }
Пример #4
0
 internal static SamplerState GetSampler(SamplerId id)
 {
     return SamplerObjects[id.Index];
 }
Пример #5
0
        internal static SamplerId CreateSamplerState(SamplerStateDescription description)
        {
            var id = new SamplerId { Index = SamplerStates.Allocate() };
            MyArrayHelpers.Reserve(ref SamplerObjects, id.Index + 1);

            SamplerStates.Data[id.Index] = description;

            InitSamplerState(id);
            SamplerIndices.Add(id);

            return id;
        }
Пример #6
0
 internal static void ChangeSamplerState(SamplerId id, SamplerStateDescription description)
 {
     SamplerStates.Data[id.Index] = description;
     if(SamplerObjects[id.Index] != null)
     {
         SamplerObjects[id.Index].Dispose();
     }
     SamplerObjects[id.Index] = new SamplerState(MyRender11.Device, description);
 }