protected override MaterialContent Convert(SharpGLTF.Schema2.Material srcMaterial) { var dstMaterial = new MaterialContent(); dstMaterial.Name = srcMaterial.Name; dstMaterial.Tag = _TagConverter?.Invoke(srcMaterial); dstMaterial.DoubleSided = srcMaterial.DoubleSided; dstMaterial.AlphaCutoff = srcMaterial.AlphaCutoff; switch (srcMaterial.Alpha) { case SharpGLTF.Schema2.AlphaMode.OPAQUE: dstMaterial.Mode = MaterialBlendMode.Opaque; break; case SharpGLTF.Schema2.AlphaMode.MASK: dstMaterial.Mode = MaterialBlendMode.Mask; break; case SharpGLTF.Schema2.AlphaMode.BLEND: dstMaterial.Mode = MaterialBlendMode.Blend; break; } if (srcMaterial.Unlit) { dstMaterial.PreferredShading = "Unlit"; } else if (srcMaterial.FindChannel("SpecularGlossiness") != null) { dstMaterial.PreferredShading = "SpecularGlossiness"; } else if (srcMaterial.FindChannel("MetallicRoughness") != null) { dstMaterial.PreferredShading = "MetallicRoughness"; } foreach (var srcChannel in srcMaterial.Channels) { var dstChannel = dstMaterial.UseChannel(srcChannel.Key); dstChannel.Value = ParamToArray(srcChannel); if (srcChannel.Texture != null) { var imgData = srcChannel.Texture.PrimaryImage.Content.Content.ToArray(); var texContent = new ImageContent(imgData); dstChannel.TextureIndex = UseTexture(texContent); dstChannel.Sampler = ToXna(srcChannel.Texture.Sampler); } else { dstChannel.Sampler = SamplerStateContent.CreateDefault(); } dstChannel.VertexIndexSet = srcChannel.TextureCoordinate; dstChannel.Transform = (srcChannel.TextureTransform?.Matrix ?? System.Numerics.Matrix3x2.Identity).ToXna(); } return(dstMaterial); }
private static void SetTexture(MaterialContent dstMaterial, string slot, Assimp.TextureSlot srcSlot) { var dstChannel = dstMaterial.UseChannel(slot); dstChannel.VertexIndexSet = srcSlot.UVIndex; }