04-06-2011, 09:54 PM
Your problem is caused by ImageBrush that is used in DiffuseMaterial to specify the texture file. When the image file is shown in ImageBrush, WPF locks the file and prevents its deletion.
This can be simply tested with the following:
<Rectangle Width="100" Height="100">
<Rectangle.Fill>
<ImageBrush ImageSource="myImage.jpg" />
</Rectangle.Fill>
</Rectangle>
In your case I would recommend you that after reading the 3ds file, you go through all the materials in the read 3d objects (use Materials on Reader3ds class) and in case ImageBrush is used in the material, read the image file into memory stream and use it instead of the file on the disk.
This could release the lock on the file - I did not test it, but I think this should at least give the the direction in which to search for the solution.
This can be simply tested with the following:
<Rectangle Width="100" Height="100">
<Rectangle.Fill>
<ImageBrush ImageSource="myImage.jpg" />
</Rectangle.Fill>
</Rectangle>
In your case I would recommend you that after reading the 3ds file, you go through all the materials in the read 3d objects (use Materials on Reader3ds class) and in case ImageBrush is used in the material, read the image file into memory stream and use it instead of the file on the disk.
This could release the lock on the file - I did not test it, but I think this should at least give the the direction in which to search for the solution.
Andrej Benedik

