![]() |
|
Help with ImageBrush - Printable Version +- AB4D Forum (https://forum.ab4d.com) +-- Forum: Products Forums (https://forum.ab4d.com/forumdisplay.php?fid=4) +--- Forum: Ab3d.PowerToys (https://forum.ab4d.com/forumdisplay.php?fid=9) +--- Thread: Help with ImageBrush (/showthread.php?tid=3974) |
Help with ImageBrush - lloyd32552 - 05-03-2016 I see how ImageBrush is used in Xaml, but I'm not having luck figuring out how paint a texture from an image file from a .cs file. And while I'm asking, I have a folder of image files that I'd like to use in the application. Is the constructor 'public class ObjFileToWpfModel3DConverter' with the Property 'Textures Directory' a way to accomplish this and if so, can you show the code to do this in a .cs file? Thanks in advance for your help. Lloyd RE: Help with ImageBrush - abenedik - 05-07-2016 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/aa970069(v=vs.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: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); RE: Help with ImageBrush - lloyd32552 - 05-09-2016 I have successfully drawn a Model3DFactory.CreateCylinder using an imagebrush using the 'siteoforigin' method for sourcing the image file and it draws the cylinder painted with the image exactly as I expected. However, when I use the exact same code with the Mesh3DFactory.CreateExtrudedMeshGeometry method, I no longer see my extruded geometry. My code: Code: private Model3D DrawSegment()If I use a DiffuseMaterial with a solid color, everything draws correctly. Is it possible that ExtrudedMeshGeometry doesn't support an image brush or do I have a syntax error? RE: Help with ImageBrush - abenedik - 05-23-2016 The reason why the textures were not seen, is that extrude method did not yet create texture coordinates. I have implemented that so that in the next version it will be possible to choose how the texture coordinates are generated. A few days ago I have sent link to pre-release version to lloyd32552. If you also need that functionality, let me know and I send you instructions on how to get the pre-release version. |