Reader3dsResolveTextureFileCallback Field |
Namespace: Ab3d
public Reader3dsResolveTextureFileDelegate ResolveTextureFileCallback
With ResolveTextureFileCallback it is possible to get or change the texture file names.
When the ResolveAllTextureFiles property is set to false (its default value), the ResolveTextureFileCallback is called only for missing texture files. When it is set to true, the ResolveTextureFileCallback is called for every texture file name.
The callback method gets an instance of ResolvedTextureFile class as parameters. The class contains a read only OriginalFileName property and two read-write properties: ResolvedFileName and IsTextureSkipped.
The OriginalFileName property contains the file name (without directory) that is written in 3ds file.
The ResolvedFileName property contains the full path with file name of the texture file. The path is get from TexturesPath property (if set) or from the location of the 3ds file. If the 3ds file is read from stream than only TexturesPath property can be used. The value of ResolvedFileName can be changed in the callback method. Its value will be used to create a BitmapImage that will be used to display the texture. If the value is set to empty string or to null this is treated as the IsTextureSkipped property would be set to true.
The IsTextureSkipped property can be set to true to skip the texture file and use null as a texture. If the model also have a color defined, it will be used for its Material.
If the textures in 3ds file are defined by some image formats that are not supported by WPF the Reader3ds tries to find the same file with gif or jpg file extention. Because 3ds file format is quite old, some old 3ds files can contain textures defined in tga file format. The Reader3ds includes a tga file parser and can read the textures from tga files.
The following example shows how to use ResolveTextureFileCallback to collect and display the file names of missing textures.
Note that if ThrowMissingTextureException is set to false (by default) it is not necessary to set the IsTextureSkipped to true for every missing texture file because there will be no exception thrown in this case. But if ThrowMissingTextureException would be set to true, we would need to set the IsTextureSkipped to true to prevent throwing exception.
private List<string> _missingTextures; private Ab3d.Reader3ds _myReader3ds; public Model3DGroup Load3ds(string fileName) { Model3DGroup myModels; if (_myReader3ds == null) _myReader3ds = new Ab3d.Reader3ds(); _missingTextures = null; _myReader3ds.ResolveTextureFileCallback = ResolveMissingTextureFile; myModels = _myReader3ds.ReadFile(fileName); return myModels; } private void ResolveMissingTextureFile(Ab3d.Common.Reader3ds.ResolvedTextureFile resolvedTextureFile) { if (_missingTextures == null) _missingTextures = new List<string>(); _missingTextures.Add(resolvedTextureFile.OriginalFileName); // skip the not found texture resolvedTextureFile.IsTextureSkipped = true; }