I am creating a Model3D cache for an application, that loads Model3Ds from .xaml files which are located in a cache directory somewhere on disk, which may or may not be fixed relative to the application.
The cache works by loading the requested model from xaml in a worker thread, and freezing the model, (same thread). The UI thread loads the model by use of the Clone method, which all works wonderfully, I don't need to use a delegate or otherwise hold up the UI thread.
However, the issue I am now encountering is when I go to load a model that contains a texture. I get the ubiquitous 'The calling thread cannot access this object because a different thread owns it', thrown by BitmapSource.CheckIfSiteOfOrigin during the Clone operation.
The xaml models currently contain an absolute path for the ImageSource, i.e. "c:\myApplication\ModelCache\myShip\myShipHull.png" and checking Microsofts documentation on BitmapSource shows the issue:
BitmapSource.CheckIfSiteOfOrigin Remarks: This method only succeeds if it is passed a Uri that is from a site of origin or that is defined in a pack:. In all other conditions, this method will fail.
So, I clearly need to change the ImageSource to use a pack://siteoforigin:,,, or other pack style which isn't clear to me from the docs.
If I attempt to use http://packsiteoforigin:,,,../../../ModelCache/image.png then I get the exception 'Failed to create a 'ImageSource' from the text, during System.Windows.Markup.XamlReader.Load note: the executable is in the bin\x64\Debug subdirectory of the myApplication folder.
My question is, how do I specify the pack in this instance?
Aucun commentaire:
Enregistrer un commentaire