1 module gfm.assimp.scene; 2 3 import std.string; 4 5 import derelict.assimp3.assimp; 6 7 import gfm.assimp.assimp; 8 9 /// ASSIMP scene wrapper. 10 class AssimpScene 11 { 12 public 13 { 14 /// Import mesh from a file. 15 /// The ASSIMP library must have been loaded. 16 /// Throws: AssimpException on error. 17 this(Assimp assimp, string path, uint postProcessFlags = 0) 18 { 19 _assimp = assimp; 20 _scene = aiImportFile(toStringz(path), postProcessFlags); 21 if (_scene is null) 22 assimp.throwAssimpException("aiImportFile"); 23 } 24 25 /// Import mesh from a memory area. 26 /// The ASSIMP library must have been loaded. 27 /// Throws: AssimpException on error. 28 this(Assimp assimp, ubyte[] data, uint postProcessFlags = 0) 29 { 30 _assimp = assimp; 31 _scene = aiImportFileFromMemory(cast(const(char)*)(data.ptr), 32 cast(uint)data.length, 33 postProcessFlags, 34 null); 35 if (_scene is null) 36 assimp.throwAssimpException("aiImportFileFromMemory"); 37 } 38 39 /// Import mesh from a memory area using specified import properties. 40 /// The ASSIMP library must have been loaded. 41 /// Throws: AssimpException on error. 42 this(Assimp assimp, ubyte[] data, aiPropertyStore* props, uint postProcessFlags = 0) 43 { 44 _assimp = assimp; 45 _scene = aiImportFileFromMemoryWithProperties(cast(const(char)*)(data.ptr), 46 cast(uint)data.length, 47 postProcessFlags, 48 null, 49 props); 50 if (_scene is null) 51 assimp.throwAssimpException("aiImportFileFromMemoryWithProperties"); 52 } 53 54 ~this() 55 { 56 close(); 57 } 58 59 /// Releases the ASSIMP scene resource. 60 void close() 61 { 62 if (_scene !is null) 63 { 64 aiReleaseImport(_scene); 65 _scene = null; 66 } 67 } 68 69 /// Apply post-processing separately, to separate loading from post-processing. 70 /// Throws: AssimpException on error. 71 void applyPostProcessing(uint postProcessFlags) 72 { 73 const(aiScene)* newScene = aiApplyPostProcessing(_scene, postProcessFlags); 74 if (newScene is null) 75 _assimp.throwAssimpException("aiApplyPostProcessing"); 76 _scene = newScene; 77 } 78 79 /// Returns: Wrapped ASSIMP scene handle. 80 const(aiScene)* scene() 81 { 82 return _scene; 83 } 84 } 85 86 private 87 { 88 Assimp _assimp; 89 const(aiScene)* _scene; 90 } 91 }