1 /*
2 
3 Boost Software License - Version 1.0 - August 17th, 2003
4 
5 Permission is hereby granted, free of charge, to any person or organization
6 obtaining a copy of the software and accompanying documentation covered by
7 this license (the "Software") to use, reproduce, display, distribute,
8 execute, and transmit the Software, and to prepare derivative works of the
9 Software, and to permit third-parties to whom the Software is furnished to
10 do so, all subject to the following:
11 
12 The copyright notices in the Software and this entire statement, including
13 the above license grant, this restriction and the following disclaimer,
14 must be included in all copies of the Software, in whole or in part, and
15 all derivative works of the Software, unless such copies or derivative
16 works are solely in the form of machine-executable object code generated by
17 a source language processor.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
22 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
23 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 DEALINGS IN THE SOFTWARE.
26 
27 */
28 module derelict.assimp3.assimp;
29 
30 public {
31     import derelict.assimp3.types;
32 }
33 
34 private {
35     import derelict.util.loader;
36     import derelict.util.system;
37 
38     static if(Derelict_OS_Windows) {
39         static if(size_t.sizeof == 4)
40             enum libNames = "assimp.dll, Assimp32.dll";
41         else static if(size_t.sizeof == 8)
42             enum libNames = "assimp.dll, Assimp64.dll";
43         else
44             static assert(0);
45     }
46     else static if(Derelict_OS_Mac)
47         enum libNames = "libassimp.3.dylib";
48     else static if(Derelict_OS_Posix)
49         enum libNames = "libassimp.so.3, libassimp.so.3.0.0";
50     else
51         static assert(0, "Need to implement ASSIMP3 libNames for this operating system.");
52 }
53 
54 aiReturn aiGetMaterialFloat(const(aiMaterial)* mat, const(char)* key, uint type, uint index, float* _out) {
55     return aiGetMaterialFloatArray(mat, key, type, index, _out, null);
56 }
57 
58 aiReturn aiGetMaterialInteger(const(aiMaterial)* mat, const(char)* key, uint type, uint index, int* _out) {
59     return aiGetMaterialIntegerArray(mat, key, type, index, _out, null);
60 }
61 
62 extern(C) @nogc nothrow {
63     // cexport.h
64     alias da_aiGetExportFormatCount = size_t function();
65     alias da_aiGetExportFormatDescription = aiExportFormatDesc* function(size_t);
66     alias da_aiReleaseExportFormatDescription = void function(const(aiExportFormatDesc)*);
67     alias da_aiCopyScene = void function(const(aiScene)*,aiScene**);
68     alias da_aiFreeScene = void function(const(aiScene)*);
69     alias da_aiExportScene = aiReturn function(const(aiScene)*,const(char)*,const(char)*,uint );
70     alias da_aiExportSceneEx = aiReturn function(const(aiScene)*,const(char)*,const(char)*,aiFileIO*,uint);
71     alias da_aiExportSceneToBlob = const(aiExportDataBlob)* function(const(aiScene)*,const(char)*,uint);
72     alias da_aiReleaseExportBlob = void function(const(aiExportDataBlob)*);
73 
74     // cimport.h
75     alias da_aiImportFile = const(aiScene*) function(const(char)*,uint);
76     alias da_aiImportFileEx = const(aiScene*) function(const(char)*,uint,aiFileIO*);
77     alias da_aiImportFileExWithProperties = const(aiScene*) function(const(char)*,uint,aiFileIO*,const(aiPropertyStore)*);
78     alias da_aiImportFileFromMemory = const(aiScene*) function(const(void)*,uint,uint,const(char)*);
79     alias da_aiImportFileFromMemoryWithProperties = const(aiScene*) function(const(void)*,uint,uint,const(char)*,const(aiPropertyStore)*);
80     alias da_aiApplyPostProcessing = const(aiScene*) function(const(aiScene*),uint);
81     alias da_aiGetPredefinedLogStream = aiLogStream function(aiDefaultLogStream,const(char)*);
82     alias da_aiAttachLogStream = void function(const(aiLogStream)*);
83     alias da_aiEnableVerboseLogging = void function(aiBool);
84     alias da_aiDetachLogStream = aiReturn function(const(aiLogStream)*);
85     alias da_aiDetachAllLogStreams = void function();
86     alias da_aiReleaseImport = void function(const(aiScene)*);
87     alias da_aiGetErrorString = const(char)* function();
88     alias da_aiIsExtensionSupported = aiBool function(const(char)*);
89     alias da_aiGetExtensionList = void function(aiString*);
90     alias da_aiGetMemoryRequirements = void function(const(aiScene)*,aiMemoryInfo*);
91     alias da_aiCreatePropertyStore = aiPropertyStore* function();
92     alias da_aiReleasePropertyStore = void function(aiPropertyStore*);
93     alias da_aiSetImportPropertyInteger = void function(aiPropertyStore*,const(char)*,int);
94     alias da_aiSetImportPropertyFloat = void function(aiPropertyStore*,const(char)*,float);
95     alias da_aiSetImportPropertyString = void function(aiPropertyStore*,const(char)*,const(aiString)*);
96     alias da_aiSetImportPropertyMatrix = void function(aiPropertyStore*,const(char)*,aiMatrix4x4*);
97     alias da_aiCreateQuaternionFromMatrix = void function(aiQuaternion*,const(aiMatrix3x3)*);
98     alias da_aiDecomposeMatrix = void function(const(aiMatrix4x4)*,aiVector3D*,aiQuaternion*,aiVector3D*);
99     alias da_aiTransposeMatrix4 = void function(aiMatrix4x4*);
100     alias da_aiTransposeMatrix3 = void function(aiMatrix3x3*);
101     alias da_aiTransformVecByMatrix3 = void function(aiVector3D*,const(aiMatrix3x3)*);
102     alias da_aiTransformVecByMatrix4 = void function(aiVector3D*,const(aiMatrix4x4)*);
103     alias da_aiMultiplyMatrix4 = void function(aiMatrix4x4*,const(aiMatrix4x4)*);
104     alias da_aiMultiplyMatrix3 = void function(aiMatrix3x3*,const(aiMatrix3x3)*);
105     alias da_aiIdentityMatrix3 = void function(aiMatrix3x3*);
106     alias da_aiIdentityMatrix4 = void function(aiMatrix4x4*);
107     alias da_aiGetImportFormatCount = size_t function();
108     alias da_aiGetImportFormatDescription = aiImporterDesc* function(size_t);
109 
110     // importerdesc.h
111     alias da_aiGetImporterDesc = const(aiImporterDesc)* function(const(char)*);
112 
113     // material.h
114     alias da_aiGetMaterialProperty = aiReturn function(const(aiMaterial)*,const(char)*,uint,uint,aiMaterialProperty**);
115     alias da_aiGetMaterialFloatArray = aiReturn function(const(aiMaterial)*,const(char)*,uint,uint,float*,uint*);
116     alias da_aiGetMaterialIntegerArray = aiReturn function(const(aiMaterial)*,const(char)*,uint,uint,int*,uint*);
117     alias da_aiGetMaterialColor = aiReturn function(const(aiMaterial)*,const(char)*,uint,uint,aiColor4D*);
118     alias da_aiGetMaterialUVTransform = aiReturn function(const(aiMaterial)*,const(char)*,uint,uint,aiUVTransform*);
119     alias da_aiGetMaterialString = aiReturn function(const(aiMaterial)*,const(char)*,uint,uint,aiString*);
120     alias da_aiGetMaterialTextureCount = uint function(const(aiMaterial)*,aiTextureType);
121     alias da_aiGetMaterialTexture = aiReturn function(const(aiMaterial)*,aiTextureType,uint,aiString*,aiTextureMapping* m=null,uint* uvindex = null,float* blend = null,aiTextureOp* op = null,aiTextureMapMode* mm = null,uint* flags = null);
122 
123     // version.h
124     alias da_aiGetLegalString = const(char)* function();
125     alias da_aiGetVersionMinor = uint function();
126     alias da_aiGetVersionMajor = uint function();
127     alias da_aiGetVersionRevision = uint function();
128     alias da_aiGetCompileFlags = uint function();
129 }
130 
131 __gshared {
132     da_aiGetExportFormatCount aiGetExportFormatCount;
133     da_aiGetExportFormatDescription aiGetExportFormatDescription;
134     da_aiReleaseExportFormatDescription aiReleaseExportFormatDescription;
135     da_aiCopyScene aiCopyScene;
136     da_aiFreeScene aiFreeScene;
137     da_aiExportScene aiExportScene;
138     da_aiExportSceneEx aiExportSceneEx;
139     da_aiExportSceneToBlob aiExportSceneToBlob;
140     da_aiReleaseExportBlob aiReleaseExportBlob;
141     da_aiImportFile aiImportFile;
142     da_aiImportFileEx aiImportFileEx;
143     da_aiImportFileExWithProperties aiImportFileExWithProperties;
144     da_aiImportFileFromMemory aiImportFileFromMemory;
145     da_aiImportFileFromMemoryWithProperties aiImportFileFromMemoryWithProperties;
146     da_aiApplyPostProcessing aiApplyPostProcessing;
147     da_aiGetPredefinedLogStream aiGetPredefinedLogStream;
148     da_aiAttachLogStream aiAttachLogStream;
149     da_aiEnableVerboseLogging aiEnableVerboseLogging;
150     da_aiDetachLogStream aiDetachLogStream;
151     da_aiDetachAllLogStreams aiDetachAllLogStreams;
152     da_aiReleaseImport aiReleaseImport;
153     da_aiGetErrorString aiGetErrorString;
154     da_aiIsExtensionSupported aiIsExtensionSupported;
155     da_aiGetExtensionList aiGetExtensionList;
156     da_aiGetMemoryRequirements aiGetMemoryRequirements;
157     da_aiCreatePropertyStore aiCreatePropertyStore;
158     da_aiReleasePropertyStore aiReleasePropertyStore;
159     da_aiSetImportPropertyInteger aiSetImportPropertyInteger;
160     da_aiSetImportPropertyFloat aiSetImportPropertyFloat;
161     da_aiSetImportPropertyString aiSetImportPropertyString;
162     da_aiSetImportPropertyMatrix aiSetImportPropertyMatrix;
163     da_aiCreateQuaternionFromMatrix aiCreateQuaternionFromMatrix;
164     da_aiDecomposeMatrix aiDecomposeMatrix;
165     da_aiTransposeMatrix4 aiTransposeMatrix4;
166     da_aiTransposeMatrix3 aiTransposeMatrix3;
167     da_aiTransformVecByMatrix3 aiTransformVecByMatrix3;
168     da_aiTransformVecByMatrix4 aiTransformVecByMatrix4;
169     da_aiMultiplyMatrix4 aiMultiplyMatrix4;
170     da_aiMultiplyMatrix3 aiMultiplyMatrix3;
171     da_aiIdentityMatrix3 aiIdentityMatrix3;
172     da_aiIdentityMatrix4 aiIdentityMatrix4;
173     da_aiGetImportFormatCount aiGetImportFormatCount;
174     da_aiGetImportFormatDescription aiGetImportFormatDescription;
175     da_aiGetMaterialProperty aiGetMaterialProperty;
176     da_aiGetMaterialFloatArray aiGetMaterialFloatArray;
177     da_aiGetMaterialIntegerArray aiGetMaterialIntegerArray;
178     da_aiGetMaterialColor aiGetMaterialColor;
179     da_aiGetMaterialString aiGetMaterialString;
180     da_aiGetMaterialTextureCount aiGetMaterialTextureCount;
181     da_aiGetMaterialTexture aiGetMaterialTexture;
182     da_aiGetLegalString aiGetLegalString;
183     da_aiGetVersionMinor aiGetVersionMinor;
184     da_aiGetVersionMajor aiGetVersionMajor;
185     da_aiGetVersionRevision aiGetVersionRevision;
186     da_aiGetCompileFlags aiGetCompileFlags;
187 }
188 
189 class DerelictASSIMP3Loader : SharedLibLoader {
190     public this() {
191         super(libNames);
192     }
193 
194     protected override void loadSymbols() {
195         bindFunc(cast(void**)&aiGetExportFormatCount, "aiGetExportFormatCount");
196         bindFunc(cast(void**)&aiGetExportFormatDescription, "aiGetExportFormatDescription");
197         bindFunc(cast(void**)&aiReleaseExportFormatDescription, "aiReleaseExportFormatDescription");
198         bindFunc(cast(void**)&aiCopyScene, "aiCopyScene");
199         bindFunc(cast(void**)&aiFreeScene, "aiFreeScene");
200         bindFunc(cast(void**)&aiExportScene, "aiExportScene");
201         bindFunc(cast(void**)&aiExportSceneEx, "aiExportSceneEx");
202         bindFunc(cast(void**)&aiExportSceneToBlob, "aiExportSceneToBlob");
203         bindFunc(cast(void**)&aiReleaseExportBlob, "aiReleaseExportBlob");
204         bindFunc(cast(void**)&aiImportFile, "aiImportFile");
205         bindFunc(cast(void**)&aiImportFileEx, "aiImportFileEx");
206         bindFunc(cast(void**)&aiImportFileExWithProperties, "aiImportFileExWithProperties");
207         bindFunc(cast(void**)&aiImportFileFromMemory, "aiImportFileFromMemory");
208         bindFunc(cast(void**)&aiImportFileFromMemoryWithProperties, "aiImportFileFromMemoryWithProperties");
209         bindFunc(cast(void**)&aiApplyPostProcessing, "aiApplyPostProcessing");
210         bindFunc(cast(void**)&aiGetPredefinedLogStream, "aiGetPredefinedLogStream");
211         bindFunc(cast(void**)&aiAttachLogStream, "aiAttachLogStream");
212         bindFunc(cast(void**)&aiEnableVerboseLogging, "aiEnableVerboseLogging");
213         bindFunc(cast(void**)&aiDetachLogStream, "aiDetachLogStream");
214         bindFunc(cast(void**)&aiDetachAllLogStreams, "aiDetachAllLogStreams");
215         bindFunc(cast(void**)&aiReleaseImport, "aiReleaseImport");
216         bindFunc(cast(void**)&aiGetErrorString, "aiGetErrorString");
217         bindFunc(cast(void**)&aiIsExtensionSupported, "aiIsExtensionSupported");
218         bindFunc(cast(void**)&aiGetExtensionList, "aiGetExtensionList");
219         bindFunc(cast(void**)&aiGetMemoryRequirements, "aiGetMemoryRequirements");
220         bindFunc(cast(void**)&aiCreatePropertyStore, "aiCreatePropertyStore");
221         bindFunc(cast(void**)&aiReleasePropertyStore, "aiReleasePropertyStore");
222         bindFunc(cast(void**)&aiSetImportPropertyInteger, "aiSetImportPropertyInteger");
223         bindFunc(cast(void**)&aiSetImportPropertyFloat, "aiSetImportPropertyFloat");
224         bindFunc(cast(void**)&aiSetImportPropertyString, "aiSetImportPropertyString");
225         bindFunc(cast(void**)&aiSetImportPropertyMatrix, "aiSetImportPropertyMatrix");
226         bindFunc(cast(void**)&aiCreateQuaternionFromMatrix, "aiCreateQuaternionFromMatrix");
227         bindFunc(cast(void**)&aiDecomposeMatrix, "aiDecomposeMatrix");
228         bindFunc(cast(void**)&aiTransposeMatrix4, "aiTransposeMatrix4");
229         bindFunc(cast(void**)&aiTransposeMatrix3, "aiTransposeMatrix3");
230         bindFunc(cast(void**)&aiTransformVecByMatrix3, "aiTransformVecByMatrix3");
231         bindFunc(cast(void**)&aiTransformVecByMatrix4, "aiTransformVecByMatrix4");
232         bindFunc(cast(void**)&aiMultiplyMatrix4, "aiMultiplyMatrix4");
233         bindFunc(cast(void**)&aiMultiplyMatrix3, "aiMultiplyMatrix3");
234         bindFunc(cast(void**)&aiIdentityMatrix3, "aiIdentityMatrix3");
235         bindFunc(cast(void**)&aiIdentityMatrix4, "aiIdentityMatrix4");
236         bindFunc(cast(void**)&aiGetImportFormatCount, "aiGetImportFormatCount");
237         bindFunc(cast(void**)&aiGetImportFormatDescription, "aiGetImportFormatDescription");
238         bindFunc(cast(void**)&aiGetMaterialProperty, "aiGetMaterialProperty");
239         bindFunc(cast(void**)&aiGetMaterialFloatArray, "aiGetMaterialFloatArray");
240         bindFunc(cast(void**)&aiGetMaterialIntegerArray, "aiGetMaterialIntegerArray");
241         bindFunc(cast(void**)&aiGetMaterialColor, "aiGetMaterialColor");
242         bindFunc(cast(void**)&aiGetMaterialString, "aiGetMaterialString");
243         bindFunc(cast(void**)&aiGetMaterialTextureCount, "aiGetMaterialTextureCount");
244         bindFunc(cast(void**)&aiGetMaterialTexture, "aiGetMaterialTexture");
245         bindFunc(cast(void**)&aiGetLegalString, "aiGetLegalString");
246         bindFunc(cast(void**)&aiGetVersionMinor, "aiGetVersionMinor");
247         bindFunc(cast(void**)&aiGetVersionMajor, "aiGetVersionMajor");
248         bindFunc(cast(void**)&aiGetVersionRevision, "aiGetVersionRevision");
249         bindFunc(cast(void**)&aiGetCompileFlags, "aiGetCompileFlags");
250     }
251 }
252 
253 __gshared DerelictASSIMP3Loader DerelictASSIMP3;
254 
255 shared static this() {
256     DerelictASSIMP3 = new DerelictASSIMP3Loader;
257 }