Geeks With Blogs
Tim Huffam Dotting the I and crossing the T of I.T.


If you are programmatically assigning an image as a DiffuseMaterial to your 3D model, then you need to make sure that you have created TextureCoordinates. 
I was using some sample code that created a 3D object - and tried to change the brush from a color to an image.  The color worked fine, but the image never showed (it was invisible).  The reason was that the sample code only did mesh.Positions.Add() and mesh.TriangleIndicies.Add().  When I added the appropriate mesh.TextureCoordinates.Add() lines the image then showed.  eg:
MeshGeometry3D mesh = new MeshGeometry3D();
mesh.Positions.Add(new Point3D(1, 1, 1));
mesh.Positions.Add(new Point3D(1, 1, -1));
mesh.Positions.Add(new Point3D(-7, 1, -1));
mesh.Positions.Add(new Point3D(-7, 1, 1));
// These are the lines you need to allow an image to be painted onto the 3d model
mesh.TextureCoordinates.Add(new Point(0, 0));
mesh.TextureCoordinates.Add(new Point(0, 1));
mesh.TextureCoordinates.Add(new Point(1, 1));
mesh.TextureCoordinates.Add(new Point(1, 0));
ImageBrush imgBrush = new ImageBrush(new BitmapImage(new Uri("pack://siteoforigin:,,,/myimage.png")));
//GeometryModel3D geometry = new GeometryModel3D(mesh, new DiffuseMaterial(Brushes.Green));  // this line works without the TextureCoordinates
GeometryModel3D geometry = new GeometryModel3D(mesh, newDiffuseMaterial(imgBrush));
geometry.Transform = new Transform3DGroup();
Model3DGroup group = new Model3DGroup();
Posted on Saturday, July 24, 2010 6:39 AM C# .NET , WPF & Silverlight , Graphics | Back to top

Comments on this post: WPF 3D - programmatically adding an image brush

# re: WPF 3D - programmatically adding an image brush
Requesting Gravatar...
You are able to listen closely Perilous looks by means of remaining primarily just exploring any specific titles. You can provide your playlist and put additional a large number of Airport files towards the playlist for no extra charge.
Left by Instagram For Android on Apr 10, 2012 12:52 PM

# re: WPF 3D - programmatically adding an image brush
Requesting Gravatar...
Tôi đọc mãi mà vẫn chưa hiểu được ứng dụng của nó ai có thể giúp tôi chỉ rõ được không
Left by giay nam on Jan 23, 2013 7:36 AM

Your comment:
 (will show your gravatar)

Copyright © Tim Huffam | Powered by: