Class AssimpContext
Represents an Assimp Import/Export context that load or save models using the unmanaged library. Additionally, conversion functionality is offered to bypass loading model data into managed memory.
Implements
Inherited Members
Namespace: SharpAssimp
Assembly: SharpAssimp.dll
Syntax
public sealed class AssimpContext : IDisposable
Constructors
| Edit this page View SourceAssimpContext()
Constructs a new instance of the AssimpContext class.
Declaration
public AssimpContext()
Properties
| Edit this page View SourceIsDisposed
Gets if the context has been disposed.
Declaration
public bool IsDisposed { get; }
Property Value
Type | Description |
---|---|
bool |
PropertyConfigurations
Gets the property configurations set to this context. This is only used during import.
Declaration
public Dictionary<string, PropertyConfig> PropertyConfigurations { get; }
Property Value
Type | Description |
---|---|
Dictionary<string, PropertyConfig> |
Scale
Gets or sets the uniform scale for the model. This is multiplied with the existing root node's transform. This is only used during import.
Declaration
public float Scale { get; set; }
Property Value
Type | Description |
---|---|
float |
UsingCustomIOSystem
Gets whether this context is using a user-defined IO system for file handling.
Declaration
public bool UsingCustomIOSystem { get; }
Property Value
Type | Description |
---|---|
bool |
XAxisRotation
Gets or sets the model's rotation about the X-Axis, in degrees. This is multiplied with the existing root node's transform. This is only used during import.
Declaration
public float XAxisRotation { get; set; }
Property Value
Type | Description |
---|---|
float |
YAxisRotation
Gets or sets the model's rotation abut the Y-Axis, in degrees. This is multiplied with the existing root node's transform. This is only used during import.
Declaration
public float YAxisRotation { get; set; }
Property Value
Type | Description |
---|---|
float |
ZAxisRotation
Gets or sets the model's rotation about the Z-Axis, in degrees. This is multiplied with the existing root node's transform. This is only used during import.
Declaration
public float ZAxisRotation { get; set; }
Property Value
Type | Description |
---|---|
float |
Methods
| Edit this page View SourceContainsConfig(string)
Checks if the context has a config set by the specified name.
Declaration
public bool ContainsConfig(string configName)
Parameters
Type | Name | Description |
---|---|---|
string | configName | Name of the config property |
Returns
Type | Description |
---|---|
bool | True if the config is present, false otherwise |
ConvertFromFileToBlob(string, PostProcessSteps, string, PostProcessSteps)
Converts the model contained in the file to the specified format and save it to a data blob.
Declaration
public ExportDataBlob? ConvertFromFileToBlob(string inputFilename, PostProcessSteps importProcessSteps, string exportFormatId, PostProcessSteps exportProcessSteps)
Parameters
Type | Name | Description |
---|---|---|
string | inputFilename | Input file name to import |
PostProcessSteps | importProcessSteps | Post processing steps used for the import |
string | exportFormatId | Format id that specifies what format to export to |
PostProcessSteps | exportProcessSteps | Pre processing steps used for the export |
Returns
Type | Description |
---|---|
ExportDataBlob | Data blob containing the exported scene in a binary form |
Exceptions
Type | Condition |
---|---|
AssimpException | Thrown if there was a general error in importing the model. |
FileNotFoundException | Thrown if the file could not be located. |
ObjectDisposedException | Thrown if the context has already been disposed of. |
ConvertFromFileToBlob(string, string)
Converts the model contained in the file to the specified format and save it to a data blob.
Declaration
public ExportDataBlob? ConvertFromFileToBlob(string inputFilename, string exportFormatId)
Parameters
Type | Name | Description |
---|---|---|
string | inputFilename | Input file name to import |
string | exportFormatId | Format id that specifies what format to export to |
Returns
Type | Description |
---|---|
ExportDataBlob | Data blob containing the exported scene in a binary form |
Exceptions
Type | Condition |
---|---|
AssimpException | Thrown if there was a general error in importing the model. |
FileNotFoundException | Thrown if the file could not be located. |
ObjectDisposedException | Thrown if the context has already been disposed of. |
ConvertFromFileToBlob(string, string, PostProcessSteps)
Converts the model contained in the file to the specified format and save it to a data blob.
Declaration
public ExportDataBlob? ConvertFromFileToBlob(string inputFilename, string exportFormatId, PostProcessSteps exportProcessSteps)
Parameters
Type | Name | Description |
---|---|---|
string | inputFilename | Input file name to import |
string | exportFormatId | Format id that specifies what format to export to |
PostProcessSteps | exportProcessSteps | Pre processing steps used for the export |
Returns
Type | Description |
---|---|
ExportDataBlob | Data blob containing the exported scene in a binary form |
Exceptions
Type | Condition |
---|---|
AssimpException | Thrown if there was a general error in importing the model. |
FileNotFoundException | Thrown if the file could not be located. |
ObjectDisposedException | Thrown if the context has already been disposed of. |
ConvertFromFileToFile(string, PostProcessSteps, string, string, PostProcessSteps)
Converts the model contained in the file to the specified format and save it to a file.
Declaration
public bool ConvertFromFileToFile(string inputFilename, PostProcessSteps importProcessSteps, string outputFilename, string exportFormatId, PostProcessSteps exportProcessSteps)
Parameters
Type | Name | Description |
---|---|---|
string | inputFilename | Input file name to import |
PostProcessSteps | importProcessSteps | Post processing steps used for the import |
string | outputFilename | Output file name to export to |
string | exportFormatId | Format id that specifies what format to export to |
PostProcessSteps | exportProcessSteps | Pre processing steps used for the export |
Returns
Type | Description |
---|---|
bool | True if the conversion was successful or not, false otherwise. |
Exceptions
Type | Condition |
---|---|
AssimpException | Thrown if there was a general error in importing the model. |
FileNotFoundException | Thrown if the file could not be located. |
ObjectDisposedException | Thrown if the context has already been disposed of. |
ConvertFromFileToFile(string, string, string)
Converts the model contained in the file to the specified format and save it to a file.
Declaration
public bool ConvertFromFileToFile(string inputFilename, string outputFilename, string exportFormatId)
Parameters
Type | Name | Description |
---|---|---|
string | inputFilename | Input file name to import |
string | outputFilename | Output file name to export to |
string | exportFormatId | Format id that specifies what format to export to |
Returns
Type | Description |
---|---|
bool | True if the conversion was successful or not, false otherwise. |
Exceptions
Type | Condition |
---|---|
AssimpException | Thrown if there was a general error in importing the model. |
FileNotFoundException | Thrown if the file could not be located. |
ObjectDisposedException | Thrown if the context has already been disposed of. |
ConvertFromFileToFile(string, string, string, PostProcessSteps)
Converts the model contained in the file to the specified format and save it to a file.
Declaration
public bool ConvertFromFileToFile(string inputFilename, string outputFilename, string exportFormatId, PostProcessSteps exportProcessSteps)
Parameters
Type | Name | Description |
---|---|---|
string | inputFilename | Input file name to import |
string | outputFilename | Output file name to export to |
string | exportFormatId | Format id that specifies what format to export to |
PostProcessSteps | exportProcessSteps | Pre processing steps used for the export |
Returns
Type | Description |
---|---|
bool | True if the conversion was successful or not, false otherwise. |
Exceptions
Type | Condition |
---|---|
AssimpException | Thrown if there was a general error in importing the model. |
FileNotFoundException | Thrown if the file could not be located. |
ObjectDisposedException | Thrown if the context has already been disposed of. |
ConvertFromStreamToBlob(Stream, string, PostProcessSteps, string, PostProcessSteps)
Converts the model contained in the stream to the specified format and save it to a data blob. It is up to the caller to dispose of the stream. If the format is distributed across multiple files/streams, set a custom IOSystem and use the "ConvertFromFileToBlob" family of functions.
Declaration
public ExportDataBlob? ConvertFromStreamToBlob(Stream inputStream, string importFormatHint, PostProcessSteps importProcessSteps, string exportFormatId, PostProcessSteps exportProcessSteps)
Parameters
Type | Name | Description |
---|---|---|
Stream | inputStream | Stream to read from |
string | importFormatHint | Optional format extension to serve as a hint to Assimp to choose which importer to use. If null or empty, the system will try to detect what importer to use from the data which may or may not be successful |
PostProcessSteps | importProcessSteps | Post processing steps used for import |
string | exportFormatId | Format id that specifies what format to export to |
PostProcessSteps | exportProcessSteps | Pre processing steps used for the export |
Returns
Type | Description |
---|---|
ExportDataBlob | Data blob containing the exported scene in a binary form |
Exceptions
Type | Condition |
---|---|
AssimpException | Thrown if the stream is not valid (null or write-only). |
ObjectDisposedException | Thrown if the context has already been disposed of. |
ConvertFromStreamToBlob(Stream, string, string)
Converts the model contained in the stream to the specified format and save it to a data blob. It is up to the caller to dispose of the stream. If the format is distributed across multiple files/streams, set a custom IOSystem and use the "ConvertFromFileToBlob" family of functions.
Declaration
public ExportDataBlob? ConvertFromStreamToBlob(Stream inputStream, string importFormatHint, string exportFormatId)
Parameters
Type | Name | Description |
---|---|---|
Stream | inputStream | Stream to read from |
string | importFormatHint | Optional format extension to serve as a hint to Assimp to choose which importer to use. If null or empty, the system will try to detect what importer to use from the data which may or may not be successful |
string | exportFormatId | Format id that specifies what format to export to |
Returns
Type | Description |
---|---|
ExportDataBlob | Data blob containing the exported scene in a binary form |
Exceptions
Type | Condition |
---|---|
AssimpException | Thrown if the stream is not valid (null or write-only). |
ObjectDisposedException | Thrown if the context has already been disposed of. |
ConvertFromStreamToBlob(Stream, string, string, PostProcessSteps)
Converts the model contained in the stream to the specified format and save it to a data blob. It is up to the caller to dispose of the stream. If the format is distributed across multiple files/streams, set a custom IOSystem and use the "ConvertFromFileToBlob" family of functions.
Declaration
public ExportDataBlob? ConvertFromStreamToBlob(Stream inputStream, string importFormatHint, string exportFormatId, PostProcessSteps exportProcessSteps)
Parameters
Type | Name | Description |
---|---|---|
Stream | inputStream | Stream to read from |
string | importFormatHint | Optional format extension to serve as a hint to Assimp to choose which importer to use. If null or empty, the system will try to detect what importer to use from the data which may or may not be successful |
string | exportFormatId | Format id that specifies what format to export to |
PostProcessSteps | exportProcessSteps | Pre processing steps used for the export |
Returns
Type | Description |
---|---|
ExportDataBlob | Data blob containing the exported scene in a binary form |
Exceptions
Type | Condition |
---|---|
AssimpException | Thrown if the stream is not valid (null or write-only). |
ObjectDisposedException | Thrown if the context has already been disposed of. |
ConvertFromStreamToFile(Stream, string, PostProcessSteps, string, string, PostProcessSteps)
Converts the model contained in the stream to the specified format and save it to a file. It is up to the caller to dispose of the stream. If the format is distributed across multiple files/streams, set a custom IOSystem and use the "ConvertFromFileToFile" family of functions.
Declaration
public bool ConvertFromStreamToFile(Stream inputStream, string importFormatHint, PostProcessSteps importProcessSteps, string outputFilename, string exportFormatId, PostProcessSteps exportProcessSteps)
Parameters
Type | Name | Description |
---|---|---|
Stream | inputStream | Stream to read from |
string | importFormatHint | Optional format extension to serve as a hint to Assimp to choose which importer to use. If null or empty, the system will try to detect what importer to use from the data which may or may not be successful |
PostProcessSteps | importProcessSteps | Post processing steps used for import |
string | outputFilename | Output file name to export to |
string | exportFormatId | Format id that specifies what format to export to |
PostProcessSteps | exportProcessSteps | Pre processing steps used for the export |
Returns
Type | Description |
---|---|
bool | True if the conversion was successful or not, false otherwise. |
Exceptions
Type | Condition |
---|---|
AssimpException | Thrown if the stream is not valid (null or write-only). |
ObjectDisposedException | Thrown if the context has already been disposed of. |
ConvertFromStreamToFile(Stream, string, string, string)
Converts the model contained in the stream to the specified format and save it to a file. It is up to the caller to dispose of the stream. If the format is distributed across multiple files/streams, set a custom IOSystem and use the "ConvertFromFileToFile" family of functions.
Declaration
public bool ConvertFromStreamToFile(Stream inputStream, string importFormatHint, string outputFilename, string exportFormatId)
Parameters
Type | Name | Description |
---|---|---|
Stream | inputStream | Stream to read from |
string | importFormatHint | Optional format extension to serve as a hint to Assimp to choose which importer to use. If null or empty, the system will try to detect what importer to use from the data which may or may not be successful |
string | outputFilename | Output file name to export to |
string | exportFormatId | Format id that specifies what format to export to |
Returns
Type | Description |
---|---|
bool | True if the conversion was successful or not, false otherwise. |
Exceptions
Type | Condition |
---|---|
AssimpException | Thrown if the stream is not valid (null or write-only). |
ObjectDisposedException | Thrown if the context has already been disposed of. |
ConvertFromStreamToFile(Stream, string, string, string, PostProcessSteps)
Converts the model contained in the stream to the specified format and save it to a file. It is up to the caller to dispose of the stream. If the format is distributed across multiple files/streams, set a custom IOSystem and use the "ConvertFromFileToFile" family of functions.
Declaration
public bool ConvertFromStreamToFile(Stream inputStream, string importFormatHint, string outputFilename, string exportFormatId, PostProcessSteps exportProcessSteps)
Parameters
Type | Name | Description |
---|---|---|
Stream | inputStream | Stream to read from |
string | importFormatHint | Optional format extension to serve as a hint to Assimp to choose which importer to use. If null or empty, the system will try to detect what importer to use from the data which may or may not be successful |
string | outputFilename | Output file name to export to |
string | exportFormatId | Format id that specifies what format to export to |
PostProcessSteps | exportProcessSteps | Pre processing steps used for the export |
Returns
Type | Description |
---|---|
bool | True if the conversion was successful or not, false otherwise. |
Exceptions
Type | Condition |
---|---|
AssimpException | Thrown if the stream is not valid (null or write-only). |
ObjectDisposedException | Thrown if the context has already been disposed of. |
Dispose()
Disposes of resources held by the context. These include IO systems still attached.
Declaration
public void Dispose()
ExportFile(Scene, string, string)
Exports a scene to the specified format and writes it to a file.
Declaration
public bool ExportFile(Scene scene, string fileName, string exportFormatId)
Parameters
Type | Name | Description |
---|---|---|
Scene | scene | Scene containing the model to export. |
string | fileName | Path to the file. |
string | exportFormatId | FormatID representing the format to export to. |
Returns
Type | Description |
---|---|
bool | True if the scene was exported successfully, false otherwise. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if the scene is null. |
ObjectDisposedException | Thrown if the context has already been disposed of. |
ExportFile(Scene, string, string, PostProcessSteps)
Exports a scene to the specified format and writes it to a file.
Declaration
public bool ExportFile(Scene scene, string fileName, string exportFormatId, PostProcessSteps preProcessing)
Parameters
Type | Name | Description |
---|---|---|
Scene | scene | Scene containing the model to export. |
string | fileName | Path to the file. |
string | exportFormatId | FormatID representing the format to export to. |
PostProcessSteps | preProcessing | Preprocessing flags to apply to the model before it is exported. |
Returns
Type | Description |
---|---|
bool | True if the scene was exported successfully, false otherwise. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if the scene is null. |
ObjectDisposedException | Thrown if the context has already been disposed of. |
ExportToBlob(Scene, string)
Exports a scene to the specified format and writes it to a data blob.
Declaration
public ExportDataBlob? ExportToBlob(Scene scene, string exportFormatId)
Parameters
Type | Name | Description |
---|---|---|
Scene | scene | Scene containing the model to export. |
string | exportFormatId | FormatID representing the format to export to. |
Returns
Type | Description |
---|---|
ExportDataBlob | The resulting data blob, or null if the export failed. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if the scene is null. |
ObjectDisposedException | Thrown if the context has already been disposed of. |
ExportToBlob(Scene, string, PostProcessSteps)
Exports a scene to the specified format and writes it to a data blob.
Declaration
public ExportDataBlob? ExportToBlob(Scene scene, string exportFormatId, PostProcessSteps preProcessing)
Parameters
Type | Name | Description |
---|---|---|
Scene | scene | Scene containing the model to export. |
string | exportFormatId | FormatID representing the format to export to. |
PostProcessSteps | preProcessing | Preprocessing flags to apply to the model before it is exported. |
Returns
Type | Description |
---|---|
ExportDataBlob | The resulting data blob, or null if the export failed. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if the scene is null. |
ObjectDisposedException | Thrown if the context has already been disposed of. |
GetImporterDescriptionFor(string)
Gets an importer description for the specified file extension. If no importers support it, null is returned. Multiple importers may support the file extension, they are called in the order that they were registered.
Declaration
public ImporterDescription? GetImporterDescriptionFor(string fileExtension)
Parameters
Type | Name | Description |
---|---|---|
string | fileExtension | File extension to query importer support for. |
Returns
Type | Description |
---|---|
ImporterDescription | Importer description or null if it does not exist. |
GetImporterDescriptions()
Gets descriptions for each importer that assimp has registered.
Declaration
public ImporterDescription[] GetImporterDescriptions()
Returns
Type | Description |
---|---|
ImporterDescription[] | Descriptions of supported importers. |
GetSupportedExportFormats()
Gets the model formats that are supported for export by Assimp.
Declaration
public ExportFormatDescription[] GetSupportedExportFormats()
Returns
Type | Description |
---|---|
ExportFormatDescription[] | Export formats supported |
GetSupportedImportFormats()
Gets the model formats that are supported for import by Assimp.
Declaration
public string[] GetSupportedImportFormats()
Returns
Type | Description |
---|---|
string[] | Import formats supported |
ImportFile(string)
Imports a model from the specified file without running any post-process steps. The importer sets configurations and loads the model into managed memory, releasing the unmanaged memory used by Assimp.
Declaration
public Scene ImportFile(string file)
Parameters
Type | Name | Description |
---|---|---|
string | file | Full path to the file |
Returns
Type | Description |
---|---|
Scene | The imported scene |
Exceptions
Type | Condition |
---|---|
AssimpException | Thrown if there was a general error in importing the model. |
FileNotFoundException | Thrown if the file could not be located. |
ObjectDisposedException | Thrown if the context has already been disposed of. |
ImportFile(string, PostProcessSteps)
Imports a model from the specified file. The importer sets configurations and loads the model into managed memory, releasing the unmanaged memory used by Assimp.
Declaration
public Scene ImportFile(string file, PostProcessSteps postProcessFlags)
Parameters
Type | Name | Description |
---|---|---|
string | file | Full path to the file |
PostProcessSteps | postProcessFlags | Post processing flags, if any |
Returns
Type | Description |
---|---|
Scene | The imported scene |
Exceptions
Type | Condition |
---|---|
AssimpException | Thrown if there was a general error in importing the model. |
FileNotFoundException | Thrown if the file could not be located. |
ObjectDisposedException | Thrown if the context has already been disposed of. |
ImportFileFromStream(Stream, PostProcessSteps, string?)
Imports a model from the stream. The importer sets configurations and loads the model into managed memory, releasing the unmanaged memory used by Assimp. It is up to the caller to dispose of the stream. If the format is distributed across multiple files/streams, set a custom IOSystem and use the "ImportFile" family of functions.
Declaration
public Scene ImportFileFromStream(Stream stream, PostProcessSteps postProcessFlags, string? formatHint = null)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | Stream to read from |
PostProcessSteps | postProcessFlags | Post processing flags, if any |
string | formatHint | Optional format extension to serve as a hint to Assimp to choose which importer to use. If null or empty, the system will try to detect what importer to use from the data which may or may not be successful. |
Returns
Type | Description |
---|---|
Scene | The imported scene |
Exceptions
Type | Condition |
---|---|
AssimpException | Thrown if the stream is not valid (null or write-only). |
ObjectDisposedException | Thrown if the context has already been disposed of. |
ImportFileFromStream(Stream, string?)
Imports a model from the stream without running any post-process steps. The importer sets configurations and loads the model into managed memory, releasing the unmanaged memory used by Assimp. It is up to the caller to dispose of the stream. If the format is distributed across multiple files/streams, set a custom IOSystem and use the "ImportFile" family of functions.
Declaration
public Scene ImportFileFromStream(Stream stream, string? formatHint = null)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | Stream to read from |
string | formatHint | Optional format extension to serve as a hint to Assimp to choose which importer to use. If null or empty, the system will try to detect what importer to use from the data which may or may not be successful. |
Returns
Type | Description |
---|---|
Scene | The imported scene |
Exceptions
Type | Condition |
---|---|
AssimpException | Thrown if the stream is not valid (null or write-only). |
ObjectDisposedException | Thrown if the context has already been disposed of. |
IsExportFormatSupported(string)
Checks if the format extension (e.g. ".dae" or ".obj") is supported for export.
Declaration
public bool IsExportFormatSupported(string format)
Parameters
Type | Name | Description |
---|---|---|
string | format | Model format |
Returns
Type | Description |
---|---|
bool | True if the format is supported, false otherwise |
IsImportFormatSupported(string)
Checks if the format extension (e.g. ".dae" or ".obj") is supported for import.
Declaration
public static bool IsImportFormatSupported(string format)
Parameters
Type | Name | Description |
---|---|---|
string | format | Model format |
Returns
Type | Description |
---|---|
bool | True if the format is supported, false otherwise |
RemoveConfig(string)
Removes a set configuration property by name.
Declaration
public void RemoveConfig(string configName)
Parameters
Type | Name | Description |
---|---|---|
string | configName | Name of the config property |
RemoveConfigs()
Removes all configuration properties from the context.
Declaration
public void RemoveConfigs()
RemoveIOSystem()
Removes the currently set custom file system implementation from the importer.
Declaration
public void RemoveIOSystem()
SetConfig(PropertyConfig)
Sets a configuration property to the context. This is only used during import.
Declaration
public void SetConfig(PropertyConfig config)
Parameters
Type | Name | Description |
---|---|---|
PropertyConfig | config | Config to set |
SetIOSystem(IOSystem?)
Sets a custom file system implementation that is used by this importer. If it is null, then the default assimp file system is used instead.
Declaration
public void SetIOSystem(IOSystem? ioSystem)
Parameters
Type | Name | Description |
---|---|---|
IOSystem | ioSystem | Custom file system implementation |