2008-05-09 17:24:28 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
2008-05-22 10:20:31 +00:00
|
|
|
Open Asset Import Library (ASSIMP)
|
2008-05-09 17:24:28 +00:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
Copyright (c) 2006-2008, ASSIMP Development Team
|
|
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the following
|
|
|
|
conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the ASSIMP team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the ASSIMP Development Team.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
/** @file Defines the CPP-API to the Asset Import Library. */
|
|
|
|
#ifndef AI_ASSIMP_HPP_INC
|
|
|
|
#define AI_ASSIMP_HPP_INC
|
|
|
|
|
|
|
|
#ifndef __cplusplus
|
|
|
|
#error This header requires C++ to be used.
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
#include "aiDefines.h"
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
struct aiScene;
|
|
|
|
|
|
|
|
namespace Assimp
|
|
|
|
{
|
|
|
|
|
|
|
|
class BaseImporter;
|
|
|
|
class BaseProcess;
|
|
|
|
class IOStream;
|
|
|
|
class IOSystem;
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
/** The Importer class forms an C++ interface to the functionality of the
|
|
|
|
* Asset Import library.
|
|
|
|
*
|
|
|
|
* Create an object of this class and call ReadFile() to import a file.
|
|
|
|
* If the import succeeds, the function returns a pointer to the imported data.
|
|
|
|
* The data remains property of the object, it is intended to be accessed
|
|
|
|
* read-only. The imported data will be destroyed along with the Importer
|
|
|
|
* object. If the import failes, ReadFile() returns a NULL pointer. In this
|
|
|
|
* case you can retrieve a human-readable error description be calling
|
|
|
|
* GetErrorString().
|
|
|
|
*
|
|
|
|
* If you need the Importer to do custom file handling to access the files,
|
2008-05-09 17:24:28 +00:00
|
|
|
* implement IOSystem and IOStream and supply an instance of your custom
|
|
|
|
* IOSystem implementation by calling SetIOHandler() before calling ReadFile().
|
|
|
|
* If you do not assign a custion IO handler, a default handler using the
|
|
|
|
* standard C++ IO logic will be used.
|
|
|
|
*
|
|
|
|
* @note One Importer instance is not thread-safe. If you use multiple
|
|
|
|
* threads for loading each thread should manage its own Importer instance.
|
2008-05-05 12:36:31 +00:00
|
|
|
*/
|
2008-06-22 10:09:26 +00:00
|
|
|
class ASSIMP_API Importer
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-06-15 10:27:08 +00:00
|
|
|
// used internally
|
|
|
|
friend class BaseProcess;
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Constructor. Creates an empty importer object.
|
|
|
|
*
|
|
|
|
* Call ReadFile() to start the import process.
|
|
|
|
*/
|
|
|
|
Importer();
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Destructor. The object kept ownership of the imported data,
|
|
|
|
* which now will be destroyed along with the object.
|
|
|
|
*/
|
|
|
|
~Importer();
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// -------------------------------------------------------------------
|
2008-05-09 17:24:28 +00:00
|
|
|
/** Supplies a custom IO handler to the importer to use to open and
|
|
|
|
* access files. If you need the importer to use custion IO logic to
|
|
|
|
* access the files, you need to provide a custom implementation of
|
|
|
|
* IOSystem and IOFile to the importer. Then create an instance of
|
|
|
|
* your custion IOSystem implementation and supply it by this function.
|
2008-05-05 12:36:31 +00:00
|
|
|
*
|
2008-05-09 17:24:28 +00:00
|
|
|
* The Importer takes ownership of the object and will destroy it
|
|
|
|
* afterwards. The previously assigned handler will be deleted.
|
2008-05-05 12:36:31 +00:00
|
|
|
*
|
2008-05-09 17:24:28 +00:00
|
|
|
* @param pIOHandler The IO handler to be used in all file accesses
|
2008-06-22 10:09:26 +00:00
|
|
|
* of the Importer. NULL resets it to the default handler.
|
2008-05-05 12:36:31 +00:00
|
|
|
*/
|
|
|
|
void SetIOHandler( IOSystem* pIOHandler);
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Retrieves the IO handler that is currently set.
|
|
|
|
* You can use IsDefaultIOHandler() to check whether the returned
|
|
|
|
* interface is the default IO handler provided by ASSIMP. The default
|
|
|
|
* handler is active as long the application doesn't supply its own
|
|
|
|
* custom IO handler via SetIOHandler().
|
|
|
|
* @return A valid IOSystem interface
|
|
|
|
*/
|
|
|
|
IOSystem* GetIOHandler();
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Checks whether a default IO handler is active
|
|
|
|
* A default handler is active as long the application doesn't
|
|
|
|
* supply its own custom IO handler via SetIOHandler().
|
|
|
|
* @return true by default
|
|
|
|
*/
|
|
|
|
bool IsDefaultIOHandler();
|
|
|
|
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Reads the given file and returns its contents if successful.
|
|
|
|
*
|
|
|
|
* If the call succeeds, the contents of the file are returned as a
|
|
|
|
* pointer to an aiScene object. The returned data is intended to be
|
|
|
|
* read-only, the importer object keeps ownership of the data and will
|
|
|
|
* destroy it upon destruction. If the import failes, NULL is returned.
|
|
|
|
* A human-readable error description can be retrieved by calling
|
|
|
|
* GetErrorString().
|
|
|
|
* @param pFile Path and filename to the file to be imported.
|
|
|
|
* @param pFlags Optional post processing steps to be executed after
|
2008-06-22 10:09:26 +00:00
|
|
|
* a successful import. Provide a bitwise combination of the
|
|
|
|
* #aiPostProcessSteps flags.
|
2008-05-05 12:36:31 +00:00
|
|
|
* @return A pointer to the imported data, NULL if the import failed.
|
|
|
|
*/
|
|
|
|
const aiScene* ReadFile( const std::string& pFile, unsigned int pFlags);
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Returns an error description of an error that occured in ReadFile().
|
|
|
|
*
|
|
|
|
* Returns an empty string if no error occured.
|
|
|
|
* @return A description of the last error, an empty string if no
|
2008-06-22 10:09:26 +00:00
|
|
|
* error occured.
|
2008-05-05 12:36:31 +00:00
|
|
|
*/
|
|
|
|
inline const std::string& GetErrorString() const
|
|
|
|
{ return mErrorString; }
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Returns whether a given file extension is supported by ASSIMP
|
|
|
|
*
|
2008-06-22 10:09:26 +00:00
|
|
|
* @param szExtension Extension to be checked.
|
|
|
|
* Must include a leading dot '.'. Example: ".3ds", ".md3"
|
2008-05-09 17:24:28 +00:00
|
|
|
* @return true if the extension is supported, false otherwise
|
|
|
|
*/
|
|
|
|
bool IsExtensionSupported(const std::string& szExtension);
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
2008-06-22 10:09:26 +00:00
|
|
|
/** Get a full list of all file extensions supported by ASSIMP.
|
2008-05-09 17:24:28 +00:00
|
|
|
*
|
|
|
|
* If a file extension is contained in the list this does, of course, not
|
|
|
|
* mean that ASSIMP is able to load all files with this extension.
|
|
|
|
* @param szOut String to receive the extension list.
|
2008-06-22 10:09:26 +00:00
|
|
|
* Format of the list: "*.3ds;*.obj;*.dae".
|
2008-05-09 17:24:28 +00:00
|
|
|
*/
|
|
|
|
void GetExtensionList(std::string& szOut);
|
|
|
|
|
2008-05-23 12:30:52 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Returns the scene loaded by the last successful call to ReadFile()
|
|
|
|
*
|
|
|
|
* @return Current scene or NULL if there is currently no scene loaded
|
|
|
|
*/
|
|
|
|
inline const aiScene* GetScene()
|
|
|
|
{return this->mScene;}
|
|
|
|
|
2008-07-30 23:00:25 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Enables the "extra verbose" mode. In this mode the data
|
|
|
|
* structure is validated after each post-process step to make sure
|
|
|
|
* all steps behave consequently in the same manner when modifying
|
|
|
|
* data structures.
|
|
|
|
*/
|
|
|
|
inline void SetExtraVerbose(bool bDo)
|
|
|
|
{this->bExtraVerbose = bDo;}
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
private:
|
2008-06-22 10:09:26 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
/** Empty copy constructor. */
|
|
|
|
Importer(const Importer &other);
|
|
|
|
|
|
|
|
protected:
|
2008-06-22 10:09:26 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
/** IO handler to use for all file accesses. */
|
|
|
|
IOSystem* mIOHandler;
|
2008-06-22 10:09:26 +00:00
|
|
|
bool mIsDefaultHandler;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
/** Format-specific importer worker objects -
|
|
|
|
* one for each format we can read. */
|
|
|
|
std::vector<BaseImporter*> mImporter;
|
|
|
|
|
|
|
|
/** Post processing steps we can apply at the imported data. */
|
|
|
|
std::vector<BaseProcess*> mPostProcessingSteps;
|
|
|
|
|
|
|
|
/** The imported data, if ReadFile() was successful,
|
|
|
|
* NULL otherwise. */
|
|
|
|
aiScene* mScene;
|
|
|
|
|
|
|
|
/** The error description, if there was one. */
|
|
|
|
std::string mErrorString;
|
2008-07-30 23:00:25 +00:00
|
|
|
|
|
|
|
/** Used for testing */
|
|
|
|
bool bExtraVerbose;
|
2008-05-05 12:36:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End of namespace Assimp
|
|
|
|
|
|
|
|
#endif // AI_ASSIMP_HPP_INC
|