miniassimp

view include/miniassimp/cimport.h @ 0:879c81d94345

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 28 Jan 2019 18:19:26 +0200
parents
children
line source
1 /*
2 ---------------------------------------------------------------------------
3 Open Asset Import Library (assimp)
4 ---------------------------------------------------------------------------
6 Copyright (c) 2006-2018, assimp team
10 All rights reserved.
12 Redistribution and use of this software in source and binary forms,
13 with or without modification, are permitted provided that the following
14 conditions are met:
16 * Redistributions of source code must retain the above
17 copyright notice, this list of conditions and the
18 following disclaimer.
20 * Redistributions in binary form must reproduce the above
21 copyright notice, this list of conditions and the
22 following disclaimer in the documentation and/or other
23 materials provided with the distribution.
25 * Neither the name of the assimp team, nor the names of its
26 contributors may be used to endorse or promote products
27 derived from this software without specific prior
28 written permission of the assimp team.
30 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 ---------------------------------------------------------------------------
42 */
44 /** @file cimport.h
45 * @brief Defines the C-API to the Open Asset Import Library.
46 */
47 #pragma once
48 #ifndef AI_ASSIMP_H_INC
49 #define AI_ASSIMP_H_INC
51 #include <miniassimp/types.h>
52 #include "importerdesc.h"
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
58 struct aiScene; // aiScene.h
59 struct aiFileIO; // aiFileIO.h
60 typedef void (*aiLogStreamCallback)(const char* /* message */, char* /* user */);
62 // --------------------------------------------------------------------------------
63 /** C-API: Represents a log stream. A log stream receives all log messages and
64 * streams them _somewhere_.
65 * @see aiGetPredefinedLogStream
66 * @see aiAttachLogStream
67 * @see aiDetachLogStream */
68 // --------------------------------------------------------------------------------
69 struct aiLogStream
70 {
71 /** callback to be called */
72 aiLogStreamCallback callback;
74 /** user data to be passed to the callback */
75 char* user;
76 };
79 // --------------------------------------------------------------------------------
80 /** C-API: Represents an opaque set of settings to be used during importing.
81 * @see aiCreatePropertyStore
82 * @see aiReleasePropertyStore
83 * @see aiImportFileExWithProperties
84 * @see aiSetPropertyInteger
85 * @see aiSetPropertyFloat
86 * @see aiSetPropertyString
87 * @see aiSetPropertyMatrix
88 */
89 // --------------------------------------------------------------------------------
90 struct aiPropertyStore { char sentinel; };
92 /** Our own C boolean type */
93 typedef int aiBool;
95 #define AI_FALSE 0
96 #define AI_TRUE 1
98 // --------------------------------------------------------------------------------
99 /** Reads the given file and returns its content.
100 *
101 * If the call succeeds, the imported data is returned in an aiScene structure.
102 * The data is intended to be read-only, it stays property of the ASSIMP
103 * library and will be stable until aiReleaseImport() is called. After you're
104 * done with it, call aiReleaseImport() to free the resources associated with
105 * this file. If the import fails, NULL is returned instead. Call
106 * aiGetErrorString() to retrieve a human-readable error text.
107 * @param pFile Path and filename of the file to be imported,
108 * expected to be a null-terminated c-string. NULL is not a valid value.
109 * @param pFlags Optional post processing steps to be executed after
110 * a successful import. Provide a bitwise combination of the
111 * #aiPostProcessSteps flags.
112 * @return Pointer to the imported data or NULL if the import failed.
113 */
114 ASSIMP_API const C_STRUCT aiScene* aiImportFile(
115 const char* pFile,
116 unsigned int pFlags);
118 // --------------------------------------------------------------------------------
119 /** Reads the given file using user-defined I/O functions and returns
120 * its content.
121 *
122 * If the call succeeds, the imported data is returned in an aiScene structure.
123 * The data is intended to be read-only, it stays property of the ASSIMP
124 * library and will be stable until aiReleaseImport() is called. After you're
125 * done with it, call aiReleaseImport() to free the resources associated with
126 * this file. If the import fails, NULL is returned instead. Call
127 * aiGetErrorString() to retrieve a human-readable error text.
128 * @param pFile Path and filename of the file to be imported,
129 * expected to be a null-terminated c-string. NULL is not a valid value.
130 * @param pFlags Optional post processing steps to be executed after
131 * a successful import. Provide a bitwise combination of the
132 * #aiPostProcessSteps flags.
133 * @param pFS aiFileIO structure. Will be used to open the model file itself
134 * and any other files the loader needs to open. Pass NULL to use the default
135 * implementation.
136 * @return Pointer to the imported data or NULL if the import failed.
137 * @note Include <aiFileIO.h> for the definition of #aiFileIO.
138 */
139 ASSIMP_API const C_STRUCT aiScene* aiImportFileEx(
140 const char* pFile,
141 unsigned int pFlags,
142 C_STRUCT aiFileIO* pFS);
144 // --------------------------------------------------------------------------------
145 /** Same as #aiImportFileEx, but adds an extra parameter containing importer settings.
146 *
147 * @param pFile Path and filename of the file to be imported,
148 * expected to be a null-terminated c-string. NULL is not a valid value.
149 * @param pFlags Optional post processing steps to be executed after
150 * a successful import. Provide a bitwise combination of the
151 * #aiPostProcessSteps flags.
152 * @param pFS aiFileIO structure. Will be used to open the model file itself
153 * and any other files the loader needs to open. Pass NULL to use the default
154 * implementation.
155 * @param pProps #aiPropertyStore instance containing import settings.
156 * @return Pointer to the imported data or NULL if the import failed.
157 * @note Include <aiFileIO.h> for the definition of #aiFileIO.
158 * @see aiImportFileEx
159 */
160 ASSIMP_API const C_STRUCT aiScene* aiImportFileExWithProperties(
161 const char* pFile,
162 unsigned int pFlags,
163 C_STRUCT aiFileIO* pFS,
164 const C_STRUCT aiPropertyStore* pProps);
166 // --------------------------------------------------------------------------------
167 /** Reads the given file from a given memory buffer,
168 *
169 * If the call succeeds, the contents of the file are returned as a pointer to an
170 * aiScene object. The returned data is intended to be read-only, the importer keeps
171 * ownership of the data and will destroy it upon destruction. If the import fails,
172 * NULL is returned.
173 * A human-readable error description can be retrieved by calling aiGetErrorString().
174 * @param pBuffer Pointer to the file data
175 * @param pLength Length of pBuffer, in bytes
176 * @param pFlags Optional post processing steps to be executed after
177 * a successful import. Provide a bitwise combination of the
178 * #aiPostProcessSteps flags. If you wish to inspect the imported
179 * scene first in order to fine-tune your post-processing setup,
180 * consider to use #aiApplyPostProcessing().
181 * @param pHint An additional hint to the library. If this is a non empty string,
182 * the library looks for a loader to support the file extension specified by pHint
183 * and passes the file to the first matching loader. If this loader is unable to
184 * completely the request, the library continues and tries to determine the file
185 * format on its own, a task that may or may not be successful.
186 * Check the return value, and you'll know ...
187 * @return A pointer to the imported data, NULL if the import failed.
188 *
189 * @note This is a straightforward way to decode models from memory
190 * buffers, but it doesn't handle model formats that spread their
191 * data across multiple files or even directories. Examples include
192 * OBJ or MD3, which outsource parts of their material info into
193 * external scripts. If you need full functionality, provide
194 * a custom IOSystem to make Assimp find these files and use
195 * the regular aiImportFileEx()/aiImportFileExWithProperties() API.
196 */
197 ASSIMP_API const C_STRUCT aiScene* aiImportFileFromMemory(
198 const char* pBuffer,
199 unsigned int pLength,
200 unsigned int pFlags,
201 const char* pHint);
203 // --------------------------------------------------------------------------------
204 /** Same as #aiImportFileFromMemory, but adds an extra parameter containing importer settings.
205 *
206 * @param pBuffer Pointer to the file data
207 * @param pLength Length of pBuffer, in bytes
208 * @param pFlags Optional post processing steps to be executed after
209 * a successful import. Provide a bitwise combination of the
210 * #aiPostProcessSteps flags. If you wish to inspect the imported
211 * scene first in order to fine-tune your post-processing setup,
212 * consider to use #aiApplyPostProcessing().
213 * @param pHint An additional hint to the library. If this is a non empty string,
214 * the library looks for a loader to support the file extension specified by pHint
215 * and passes the file to the first matching loader. If this loader is unable to
216 * completely the request, the library continues and tries to determine the file
217 * format on its own, a task that may or may not be successful.
218 * Check the return value, and you'll know ...
219 * @param pProps #aiPropertyStore instance containing import settings.
220 * @return A pointer to the imported data, NULL if the import failed.
221 *
222 * @note This is a straightforward way to decode models from memory
223 * buffers, but it doesn't handle model formats that spread their
224 * data across multiple files or even directories. Examples include
225 * OBJ or MD3, which outsource parts of their material info into
226 * external scripts. If you need full functionality, provide
227 * a custom IOSystem to make Assimp find these files and use
228 * the regular aiImportFileEx()/aiImportFileExWithProperties() API.
229 * @see aiImportFileFromMemory
230 */
231 ASSIMP_API const C_STRUCT aiScene* aiImportFileFromMemoryWithProperties(
232 const char* pBuffer,
233 unsigned int pLength,
234 unsigned int pFlags,
235 const char* pHint,
236 const C_STRUCT aiPropertyStore* pProps);
238 // --------------------------------------------------------------------------------
239 /** Apply post-processing to an already-imported scene.
240 *
241 * This is strictly equivalent to calling #aiImportFile()/#aiImportFileEx with the
242 * same flags. However, you can use this separate function to inspect the imported
243 * scene first to fine-tune your post-processing setup.
244 * @param pScene Scene to work on.
245 * @param pFlags Provide a bitwise combination of the #aiPostProcessSteps flags.
246 * @return A pointer to the post-processed data. Post processing is done in-place,
247 * meaning this is still the same #aiScene which you passed for pScene. However,
248 * _if_ post-processing failed, the scene could now be NULL. That's quite a rare
249 * case, post processing steps are not really designed to 'fail'. To be exact,
250 * the #aiProcess_ValidateDataStructure flag is currently the only post processing step
251 * which can actually cause the scene to be reset to NULL.
252 */
253 ASSIMP_API const C_STRUCT aiScene* aiApplyPostProcessing(
254 const C_STRUCT aiScene* pScene,
255 unsigned int pFlags);
257 // --------------------------------------------------------------------------------
258 /** Get one of the predefine log streams. This is the quick'n'easy solution to
259 * access Assimp's log system. Attaching a log stream can slightly reduce Assimp's
260 * overall import performance.
261 *
262 * Usage is rather simple (this will stream the log to a file, named log.txt, and
263 * the stdout stream of the process:
264 * @code
265 * struct aiLogStream c;
266 * c = aiGetPredefinedLogStream(aiDefaultLogStream_FILE,"log.txt");
267 * aiAttachLogStream(&c);
268 * c = aiGetPredefinedLogStream(aiDefaultLogStream_STDOUT,NULL);
269 * aiAttachLogStream(&c);
270 * @endcode
271 *
272 * @param pStreams One of the #aiDefaultLogStream enumerated values.
273 * @param file Solely for the #aiDefaultLogStream_FILE flag: specifies the file to write to.
274 * Pass NULL for all other flags.
275 * @return The log stream. callback is set to NULL if something went wrong.
276 */
277 ASSIMP_API C_STRUCT aiLogStream aiGetPredefinedLogStream(
278 C_ENUM aiDefaultLogStream pStreams,
279 const char* file);
281 // --------------------------------------------------------------------------------
282 /** Attach a custom log stream to the libraries' logging system.
283 *
284 * Attaching a log stream can slightly reduce Assimp's overall import
285 * performance. Multiple log-streams can be attached.
286 * @param stream Describes the new log stream.
287 * @note To ensure proper destruction of the logging system, you need to manually
288 * call aiDetachLogStream() on every single log stream you attach.
289 * Alternatively (for the lazy folks) #aiDetachAllLogStreams is provided.
290 */
291 ASSIMP_API void aiAttachLogStream(
292 const C_STRUCT aiLogStream* stream);
294 // --------------------------------------------------------------------------------
295 /** Enable verbose logging. Verbose logging includes debug-related stuff and
296 * detailed import statistics. This can have severe impact on import performance
297 * and memory consumption. However, it might be useful to find out why a file
298 * didn't read correctly.
299 * @param d AI_TRUE or AI_FALSE, your decision.
300 */
301 ASSIMP_API void aiEnableVerboseLogging(aiBool d);
303 // --------------------------------------------------------------------------------
304 /** Detach a custom log stream from the libraries' logging system.
305 *
306 * This is the counterpart of #aiAttachLogStream. If you attached a stream,
307 * don't forget to detach it again.
308 * @param stream The log stream to be detached.
309 * @return AI_SUCCESS if the log stream has been detached successfully.
310 * @see aiDetachAllLogStreams
311 */
312 ASSIMP_API C_ENUM aiReturn aiDetachLogStream(
313 const C_STRUCT aiLogStream* stream);
315 // --------------------------------------------------------------------------------
316 /** Detach all active log streams from the libraries' logging system.
317 * This ensures that the logging system is terminated properly and all
318 * resources allocated by it are actually freed. If you attached a stream,
319 * don't forget to detach it again.
320 * @see aiAttachLogStream
321 * @see aiDetachLogStream
322 */
323 ASSIMP_API void aiDetachAllLogStreams(void);
325 // --------------------------------------------------------------------------------
326 /** Releases all resources associated with the given import process.
327 *
328 * Call this function after you're done with the imported data.
329 * @param pScene The imported data to release. NULL is a valid value.
330 */
331 ASSIMP_API void aiReleaseImport(
332 const C_STRUCT aiScene* pScene);
334 // --------------------------------------------------------------------------------
335 /** Returns the error text of the last failed import process.
336 *
337 * @return A textual description of the error that occurred at the last
338 * import process. NULL if there was no error. There can't be an error if you
339 * got a non-NULL #aiScene from #aiImportFile/#aiImportFileEx/#aiApplyPostProcessing.
340 */
341 ASSIMP_API const char* aiGetErrorString(void);
343 // --------------------------------------------------------------------------------
344 /** Returns whether a given file extension is supported by ASSIMP
345 *
346 * @param szExtension Extension for which the function queries support for.
347 * Must include a leading dot '.'. Example: ".3ds", ".md3"
348 * @return AI_TRUE if the file extension is supported.
349 */
350 ASSIMP_API aiBool aiIsExtensionSupported(
351 const char* szExtension);
353 // --------------------------------------------------------------------------------
354 /** Get a list of all file extensions supported by ASSIMP.
355 *
356 * If a file extension is contained in the list this does, of course, not
357 * mean that ASSIMP is able to load all files with this extension.
358 * @param szOut String to receive the extension list.
359 * Format of the list: "*.3ds;*.obj;*.dae". NULL is not a valid parameter.
360 */
361 ASSIMP_API void aiGetExtensionList(
362 C_STRUCT aiString* szOut);
364 // --------------------------------------------------------------------------------
365 /** Get the approximated storage required by an imported asset
366 * @param pIn Input asset.
367 * @param in Data structure to be filled.
368 */
369 ASSIMP_API void aiGetMemoryRequirements(
370 const C_STRUCT aiScene* pIn,
371 C_STRUCT aiMemoryInfo* in);
375 // --------------------------------------------------------------------------------
376 /** Create an empty property store. Property stores are used to collect import
377 * settings.
378 * @return New property store. Property stores need to be manually destroyed using
379 * the #aiReleasePropertyStore API function.
380 */
381 ASSIMP_API C_STRUCT aiPropertyStore* aiCreatePropertyStore(void);
383 // --------------------------------------------------------------------------------
384 /** Delete a property store.
385 * @param p Property store to be deleted.
386 */
387 ASSIMP_API void aiReleasePropertyStore(C_STRUCT aiPropertyStore* p);
389 // --------------------------------------------------------------------------------
390 /** Set an integer property.
391 *
392 * This is the C-version of #Assimp::Importer::SetPropertyInteger(). In the C
393 * interface, properties are always shared by all imports. It is not possible to
394 * specify them per import.
395 *
396 * @param store Store to modify. Use #aiCreatePropertyStore to obtain a store.
397 * @param szName Name of the configuration property to be set. All supported
398 * public properties are defined in the config.h header file (AI_CONFIG_XXX).
399 * @param value New value for the property
400 */
401 ASSIMP_API void aiSetImportPropertyInteger(
402 C_STRUCT aiPropertyStore* store,
403 const char* szName,
404 int value);
406 // --------------------------------------------------------------------------------
407 /** Set a floating-point property.
408 *
409 * This is the C-version of #Assimp::Importer::SetPropertyFloat(). In the C
410 * interface, properties are always shared by all imports. It is not possible to
411 * specify them per import.
412 *
413 * @param store Store to modify. Use #aiCreatePropertyStore to obtain a store.
414 * @param szName Name of the configuration property to be set. All supported
415 * public properties are defined in the config.h header file (AI_CONFIG_XXX).
416 * @param value New value for the property
417 */
418 ASSIMP_API void aiSetImportPropertyFloat(
419 C_STRUCT aiPropertyStore* store,
420 const char* szName,
421 ai_real value);
423 // --------------------------------------------------------------------------------
424 /** Set a string property.
425 *
426 * This is the C-version of #Assimp::Importer::SetPropertyString(). In the C
427 * interface, properties are always shared by all imports. It is not possible to
428 * specify them per import.
429 *
430 * @param store Store to modify. Use #aiCreatePropertyStore to obtain a store.
431 * @param szName Name of the configuration property to be set. All supported
432 * public properties are defined in the config.h header file (AI_CONFIG_XXX).
433 * @param st New value for the property
434 */
435 ASSIMP_API void aiSetImportPropertyString(
436 C_STRUCT aiPropertyStore* store,
437 const char* szName,
438 const C_STRUCT aiString* st);
440 // --------------------------------------------------------------------------------
441 /** Set a matrix property.
442 *
443 * This is the C-version of #Assimp::Importer::SetPropertyMatrix(). In the C
444 * interface, properties are always shared by all imports. It is not possible to
445 * specify them per import.
446 *
447 * @param store Store to modify. Use #aiCreatePropertyStore to obtain a store.
448 * @param szName Name of the configuration property to be set. All supported
449 * public properties are defined in the config.h header file (AI_CONFIG_XXX).
450 * @param mat New value for the property
451 */
452 ASSIMP_API void aiSetImportPropertyMatrix(
453 C_STRUCT aiPropertyStore* store,
454 const char* szName,
455 const C_STRUCT aiMatrix4x4* mat);
457 // --------------------------------------------------------------------------------
458 /** Construct a quaternion from a 3x3 rotation matrix.
459 * @param quat Receives the output quaternion.
460 * @param mat Matrix to 'quaternionize'.
461 * @see aiQuaternion(const aiMatrix3x3& pRotMatrix)
462 */
463 ASSIMP_API void aiCreateQuaternionFromMatrix(
464 C_STRUCT aiQuaternion* quat,
465 const C_STRUCT aiMatrix3x3* mat);
467 // --------------------------------------------------------------------------------
468 /** Decompose a transformation matrix into its rotational, translational and
469 * scaling components.
470 *
471 * @param mat Matrix to decompose
472 * @param scaling Receives the scaling component
473 * @param rotation Receives the rotational component
474 * @param position Receives the translational component.
475 * @see aiMatrix4x4::Decompose (aiVector3D&, aiQuaternion&, aiVector3D&) const;
476 */
477 ASSIMP_API void aiDecomposeMatrix(
478 const C_STRUCT aiMatrix4x4* mat,
479 C_STRUCT aiVector3D* scaling,
480 C_STRUCT aiQuaternion* rotation,
481 C_STRUCT aiVector3D* position);
483 // --------------------------------------------------------------------------------
484 /** Transpose a 4x4 matrix.
485 * @param mat Pointer to the matrix to be transposed
486 */
487 ASSIMP_API void aiTransposeMatrix4(
488 C_STRUCT aiMatrix4x4* mat);
490 // --------------------------------------------------------------------------------
491 /** Transpose a 3x3 matrix.
492 * @param mat Pointer to the matrix to be transposed
493 */
494 ASSIMP_API void aiTransposeMatrix3(
495 C_STRUCT aiMatrix3x3* mat);
497 // --------------------------------------------------------------------------------
498 /** Transform a vector by a 3x3 matrix
499 * @param vec Vector to be transformed.
500 * @param mat Matrix to transform the vector with.
501 */
502 ASSIMP_API void aiTransformVecByMatrix3(
503 C_STRUCT aiVector3D* vec,
504 const C_STRUCT aiMatrix3x3* mat);
506 // --------------------------------------------------------------------------------
507 /** Transform a vector by a 4x4 matrix
508 * @param vec Vector to be transformed.
509 * @param mat Matrix to transform the vector with.
510 */
511 ASSIMP_API void aiTransformVecByMatrix4(
512 C_STRUCT aiVector3D* vec,
513 const C_STRUCT aiMatrix4x4* mat);
515 // --------------------------------------------------------------------------------
516 /** Multiply two 4x4 matrices.
517 * @param dst First factor, receives result.
518 * @param src Matrix to be multiplied with 'dst'.
519 */
520 ASSIMP_API void aiMultiplyMatrix4(
521 C_STRUCT aiMatrix4x4* dst,
522 const C_STRUCT aiMatrix4x4* src);
524 // --------------------------------------------------------------------------------
525 /** Multiply two 3x3 matrices.
526 * @param dst First factor, receives result.
527 * @param src Matrix to be multiplied with 'dst'.
528 */
529 ASSIMP_API void aiMultiplyMatrix3(
530 C_STRUCT aiMatrix3x3* dst,
531 const C_STRUCT aiMatrix3x3* src);
533 // --------------------------------------------------------------------------------
534 /** Get a 3x3 identity matrix.
535 * @param mat Matrix to receive its personal identity
536 */
537 ASSIMP_API void aiIdentityMatrix3(
538 C_STRUCT aiMatrix3x3* mat);
540 // --------------------------------------------------------------------------------
541 /** Get a 4x4 identity matrix.
542 * @param mat Matrix to receive its personal identity
543 */
544 ASSIMP_API void aiIdentityMatrix4(
545 C_STRUCT aiMatrix4x4* mat);
547 // --------------------------------------------------------------------------------
548 /** Returns the number of import file formats available in the current Assimp build.
549 * Use aiGetImportFormatDescription() to retrieve infos of a specific import format.
550 */
551 ASSIMP_API size_t aiGetImportFormatCount(void);
553 // --------------------------------------------------------------------------------
554 /** Returns a description of the nth import file format. Use #aiGetImportFormatCount()
555 * to learn how many import formats are supported.
556 * @param pIndex Index of the import format to retrieve information for. Valid range is
557 * 0 to #aiGetImportFormatCount()
558 * @return A description of that specific import format. NULL if pIndex is out of range.
559 */
560 ASSIMP_API const C_STRUCT aiImporterDesc* aiGetImportFormatDescription( size_t pIndex);
561 #ifdef __cplusplus
562 }
563 #endif
565 #endif // AI_ASSIMP_H_INC