protected Texture(string name, TextureSampler sampler, ColorSpaceTypes colorSpace, TextureTypes textureType) { Name = name; Sampler = sampler; ColorSpace = colorSpace; TextureType = textureType; }
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; }
public ImageTexture(string name, TextureSampler sampler, Image image, ColorSpaceTypes colorSpace, TextureTypes textureType = TextureTypes.Default) : base(name, sampler, colorSpace, textureType) { Image = image; }
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; }
public SolidTexture(string name, TextureSampler sampler, Vector4 color, ColorSpaceTypes colorSpace, TextureTypes textureType) : base(name, sampler, colorSpace, textureType) { Color = color; }
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; }
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); }