Пример #1
0
 protected Texture(string name, TextureSampler sampler, ColorSpaceTypes colorSpace, TextureTypes textureType)
 {
     Name        = name;
     Sampler     = sampler;
     ColorSpace  = colorSpace;
     TextureType = textureType;
 }
Пример #2
0
 protected Texture(string name, TextureSampler sampler, ColorSpaceTypes colorSpace, TextureTypes textureType)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     Name        = name;
     Sampler     = sampler;
     ColorSpace  = colorSpace;
     TextureType = textureType;
 }
Пример #3
0
 public ImageTexture(string name, TextureSampler sampler, Image image, ColorSpaceTypes colorSpace, TextureTypes textureType = TextureTypes.Default) : base(name, sampler, colorSpace, textureType)
 {
     Image = image;
 }
Пример #4
0
 public RenderTexture(string name, TextureSampler sampler, ColorSpaceTypes colorSpace, TextureTypes textureType, int width = 256, int height = 256) : base(name, sampler, colorSpace, textureType)
 {
     Width  = width;
     Height = height;
 }
Пример #5
0
 public SolidTexture(string name, TextureSampler sampler, Vector4 color, ColorSpaceTypes colorSpace, TextureTypes textureType) : base(name, sampler, colorSpace, textureType)
 {
     Color = color;
 }
Пример #6
0
 public MetallicRoughnessImageTexture(string name, TextureSampler sampler, Image image, float roughnessFactor, ColorSpaceTypes colorSpace, TextureTypes textureType = TextureTypes.Default)
     : base(name, sampler, image, colorSpace, textureType)
 {
     Image           = image;
     RoughnessFactor = roughnessFactor;
 }
Пример #7
0
        public VrmLib.TextureInfo GetOrCreateTexture(UnityEngine.Material material, UnityEngine.Texture srcTexture, VrmLib.Texture.ColorSpaceTypes colorSpace, VrmLib.Texture.TextureTypes textureType)
        {
            var texture = srcTexture as Texture2D;

            if (texture is null)
            {
                return(null);
            }

            if (!Textures.TryGetValue(texture, out VrmLib.TextureInfo info))
            {
                UnityEngine.Material converter = null;
                if (textureType == VrmLib.Texture.TextureTypes.NormalMap)
                {
                    converter = TextureConvertMaterial.GetNormalMapConvertUnityToGltf();
                }
                else if (textureType == VrmLib.Texture.TextureTypes.MetallicRoughness)
                {
                    float smoothness = 0.0f;
                    if (material.HasProperty("_GlossMapScale"))
                    {
                        smoothness = material.GetFloat("_GlossMapScale");
                    }

                    converter = TextureConvertMaterial.GetMetallicRoughnessUnityToGltf(smoothness);
                }
                else if (textureType == VrmLib.Texture.TextureTypes.Occlusion)
                {
                    converter = TextureConvertMaterial.GetOcclusionUnityToGltf();
                }

                var(bytes, mime) = GetImageEncodedBytes(
                    texture,
                    (colorSpace == VrmLib.Texture.ColorSpaceTypes.Linear) ? RenderTextureReadWrite.Linear : RenderTextureReadWrite.sRGB,
                    converter
                    );

                if (converter != null)
                {
                    UnityEngine.Object.DestroyImmediate(converter);
                }

                var sampler = new VrmLib.TextureSampler
                {
                    MagFilter = texture.filterMode.ToVrmLibMagFilter(),
                    MinFilter = texture.filterMode.ToVrmLibMinFilter(),
                    WrapS     = texture.wrapMode.ToVrmLib(),
                    WrapT     = texture.wrapMode.ToVrmLib(),
                };
                var image = new VrmLib.Image(texture.name, mime, VrmLib.ImageUsage.None, new ArraySegment <byte>(bytes));
                info = new VrmLib.TextureInfo(new VrmLib.ImageTexture(texture.name, sampler, image, colorSpace, textureType));
                Textures.Add(texture, info);

                if (Model != null)
                {
                    Model.Images.Add(image);
                    Model.Textures.Add(info.Texture);
                }
            }

            return(info);
        }