Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Link to external texture file in self-contained XAML representing a 3D model

I have a XAML file representing a 3D model with textures.

I want to make the textures read from the same place the file is, or relative to it.

I read the file using a XamlReader, so I want the file to be self-contained.

I place the textures using an ImageBrush which ImageSource is a pack synatx URI.

When I use a 'siteoforigin' syntax, this only works if the texture file is next to the application. I want it to be next to the Xaml, wherever it is.

I tried setting the current directory to the Xaml directory, but it didn't help.

Not using a pack syntax doesn't work as well - it just look for a resource by that name.

How do I need to write the Xaml image source (or is there another way to place textures for a diffuse material brush?) so it will work?

Itai.

like image 556
Itai Bar-Haim Avatar asked Nov 15 '22 14:11

Itai Bar-Haim


1 Answers

I resolved this issue simply by preloading the XAML into a memory stream, replacing the siteoforigin:,,, statements with the path from which the xaml was located, and then loading the Model from the updated memory stream with XamlReader.Load

Incidently, my models are sketchup exports exported with your very own xaml exporter plugin, although I modified it to export normals and rotate the model to the WPF coordinate system, among other things.

like image 107
user4531448 Avatar answered Dec 22 '22 02:12

user4531448