private Wavefront.Material GenerateMaterial(Wavefront.Model Model) { Wavefront.MaterialFilter Kd = default(Wavefront.MaterialFilter); Wavefront.MaterialMap map_d = default(Wavefront.MaterialMap); if (material.HasMaterialColor) { var color = (Color4b)material.light.Light1.Color; Kd = new Wavefront.MaterialFilter(color.r, color.g, color.b); } Wavefront.Image image = null; if (material.HasTexture) { byte[] pixels = new byte[(texture.Width * texture.Height) << 2]; GL.GetTextureImage(texture.ID, 0, PixelFormat.Rgba, PixelType.UnsignedInt8888, pixels.Length, pixels); for (int i = (texture.Width * texture.Height) - 1; i >= 0; i--) { byte r = pixels[(i << 2) | 1]; byte g = pixels[(i << 2) | 2]; byte b = pixels[(i << 2) | 3]; byte a = pixels[(i << 2) | 0]; pixels[(i << 2) | 0] = r; pixels[(i << 2) | 1] = g; pixels[(i << 2) | 2] = b; pixels[(i << 2) | 3] = a; } image = Model.Images[new Wavefront.Image(pixels, (ushort)texture.Width, (ushort)texture.Height)]; map_d = new Wavefront.MaterialMap( image, Clamp: (material.HasClampUV) ? true : (bool?)null, AutoTexRes: true); } var map_Ka = map_d; if (!map_d.IsOmitted) { if ( TextureFormats.GetFormat(material.format).AlphaDepth == 0 || (!image.AlphaVariance && image.AlphaValue == 255)) { map_d = default(Wavefront.MaterialMap); } else { map_d = new Wavefront.MaterialMap(ref map_d, Channel: Wavefront.TextureChannel.Matte); } } return(Model.Materials[new Wavefront.Material( Kd: Kd, Ka: Kd, map_Ka: map_Ka, map_Kd: map_Ka, map_d: map_d, d: map_d.IsOmitted ? default(Wavefront.MaterialD) : (Wavefront.MaterialD) 0.0, illum: material.CalcuateDefaultIlluminationMode(image == (object)null ? true : (!image.AlphaVariance && image.AlphaValue == 255)) )]); }