Loading bitmaps from code can be a little bit tricky because WPF uses a so called "Pack URI" schemas.
You can read more about that here: https://msdn.microsoft.com/en-us/library....100).aspx
But for your convenience here are the examples on how to read bitmap images and set them as ImageBrush and DiffuseMaterial.
Your second question is probably related to reading obj files that have textures defined in a directory that is different from the directory where the obj file is. In this case I would advice you to use ReadModel3D with an overload that also gets texturesDirectory:
var objImporter = new Ab3d.ReaderObj();
var wpf3DModel = objImporter.ReadModel3D(objFileName, texturesDirectory, defaultMaterial);
You can read more about that here: https://msdn.microsoft.com/en-us/library....100).aspx
But for your convenience here are the examples on how to read bitmap images and set them as ImageBrush and DiffuseMaterial.
Code:
// Load image from Resources folder with image's Build action set to Resource:
var bitmapImage = new BitmapImage(new Uri("pack://application:,,,/Resources/PowerToysTexture.png", UriKind.RelativeOrAbsolute));
// Load image from another assembly (ReferencedAssembly) from its Resources folder with image's Build action set to Resource:
bitmapImage = new BitmapImage(new Uri("pack://application:,,,/ReferencedAssembly;component/Resources/PowerToysTexture.png", UriKind.RelativeOrAbsolute));
// Load image from file
bitmapImage = new BitmapImage(new Uri(@"D:\Images\myImage.png", UriKind.RelativeOrAbsolute));
// Load image from disk from a loaction relative to the current location (site of origin)
bitmapImage = new BitmapImage(new Uri("pack://siteoforigin:,,,/Resources/PowerToysTexture.png", UriKind.RelativeOrAbsolute));
// Same as before but with providing full path to file
bitmapImage = new BitmapImage(new Uri(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources/PowerToysTexture.png"), UriKind.RelativeOrAbsolute));
// After you have the BitmapImage, yuo can create ImageBrush
// ImageBrush allows you to set image tiling or specifying which part of the BitmapImage you want to show
var imageBrush = new ImageBrush(bitmapImage);
// Create DiffuseMaterial
Box1.Material = new DiffuseMaterial(imageBrush);Your second question is probably related to reading obj files that have textures defined in a directory that is different from the directory where the obj file is. In this case I would advice you to use ReadModel3D with an overload that also gets texturesDirectory:
var objImporter = new Ab3d.ReaderObj();
var wpf3DModel = objImporter.ReadModel3D(objFileName, texturesDirectory, defaultMaterial);
Andrej Benedik

