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 Definition of the base class for all importer worker classes. */
|
|
|
|
#ifndef AI_BASEIMPORTER_H_INC
|
|
|
|
#define AI_BASEIMPORTER_H_INC
|
|
|
|
|
|
|
|
#include <string>
|
2008-09-13 22:31:15 +00:00
|
|
|
#include "./../include/aiTypes.h"
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
struct aiScene;
|
|
|
|
|
2008-09-13 22:31:15 +00:00
|
|
|
namespace Assimp {
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
class IOSystem;
|
2008-08-13 23:46:46 +00:00
|
|
|
class Importer;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
/** Simple exception class to be thrown if an error occurs while importing. */
|
2008-09-13 22:31:15 +00:00
|
|
|
class ASSIMP_API ImportErrorException
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** Constructor with arguments */
|
|
|
|
ImportErrorException( const std::string& pErrorText)
|
|
|
|
{
|
|
|
|
mErrorText = pErrorText;
|
|
|
|
}
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// -------------------------------------------------------------------
|
2008-05-05 12:36:31 +00:00
|
|
|
/** Returns the error text provided when throwing the exception */
|
2008-05-09 17:24:28 +00:00
|
|
|
inline const std::string& GetErrorText() const
|
|
|
|
{ return mErrorText; }
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::string mErrorText;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
/** The BaseImporter defines a common interface for all importer worker
|
|
|
|
* classes.
|
|
|
|
*
|
|
|
|
* The interface defines two functions: CanRead() is used to check if the
|
|
|
|
* importer can handle the format of the given file. If an implementation of
|
|
|
|
* this function returns true, the importer then calls ReadFile() which
|
2008-05-09 17:24:28 +00:00
|
|
|
* imports the given file. ReadFile is not overridable, it just calls
|
|
|
|
* InternReadFile() and catches any ImportErrorException that might occur.
|
2008-05-05 12:36:31 +00:00
|
|
|
*/
|
2008-09-13 22:31:15 +00:00
|
|
|
class ASSIMP_API BaseImporter
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
friend class Importer;
|
|
|
|
|
|
|
|
protected:
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
/** Constructor to be privately used by #Importer */
|
2008-05-05 12:36:31 +00:00
|
|
|
BaseImporter();
|
|
|
|
|
|
|
|
/** Destructor, private as well */
|
|
|
|
virtual ~BaseImporter();
|
|
|
|
|
|
|
|
public:
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Returns whether the class can handle the format of the given file.
|
|
|
|
* @param pFile Path and file name of the file to be examined.
|
|
|
|
* @param pIOHandler The IO handler to use for accessing any file.
|
|
|
|
* @return true if the class can read this file, false if not.
|
2008-05-09 17:24:28 +00:00
|
|
|
*
|
|
|
|
* @note Sometimes ASSIMP uses this method to determine whether a
|
|
|
|
* a given file extension is generally supported. In this case the
|
|
|
|
* file extension is passed in the pFile parameter, pIOHandler is NULL
|
2008-05-05 12:36:31 +00:00
|
|
|
*/
|
2008-05-09 17:24:28 +00:00
|
|
|
virtual bool CanRead( const std::string& pFile,
|
|
|
|
IOSystem* pIOHandler) const = 0;
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Imports the given file and returns the imported data.
|
2008-05-09 17:24:28 +00:00
|
|
|
* If the import succeeds, ownership of the data is transferred to
|
2008-06-22 10:09:26 +00:00
|
|
|
* the caller. If the import fails, NULL is returned. The function
|
2008-05-09 17:24:28 +00:00
|
|
|
* takes care that any partially constructed data is destroyed
|
|
|
|
* beforehand.
|
2008-05-05 12:36:31 +00:00
|
|
|
*
|
|
|
|
* @param pFile Path of the file to be imported.
|
|
|
|
* @param pIOHandler IO-Handler used to open this and possible other files.
|
2008-05-09 17:24:28 +00:00
|
|
|
* @return The imported data or NULL if failed. If it failed a
|
|
|
|
* human-readable error description can be retrieved by calling
|
|
|
|
* GetErrorText()
|
2008-05-05 12:36:31 +00:00
|
|
|
*
|
2008-05-09 17:24:28 +00:00
|
|
|
* @note This function is not intended to be overridden. Implement
|
|
|
|
* InternReadFile() to do the import. If an exception is thrown somewhere
|
|
|
|
* in InternReadFile(), this function will catch it and transform it into
|
|
|
|
* a suitable response to the caller.
|
2008-05-05 12:36:31 +00:00
|
|
|
*/
|
|
|
|
aiScene* ReadFile( const std::string& pFile, IOSystem* pIOHandler);
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Returns the error description of the last error that occured.
|
2008-05-09 17:24:28 +00:00
|
|
|
* @return A description of the last error that occured. An empty
|
|
|
|
* string if there was no error.
|
2008-05-05 12:36:31 +00:00
|
|
|
*/
|
2008-05-09 17:24:28 +00:00
|
|
|
inline const std::string& GetErrorText() const
|
|
|
|
{ return mErrorText; }
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-08-08 18:34:14 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Called prior to ReadFile().
|
|
|
|
* The function is a request to the importer to update its configuration
|
|
|
|
* basing on the Importer's configuration property list.
|
2008-10-13 16:45:48 +00:00
|
|
|
* @param pImp Importer instance
|
|
|
|
* @param ppFlags Post-processing steps to be executed on the data
|
|
|
|
* returned by the loaders. This value is provided to allow some
|
|
|
|
* internal optimizations.
|
2008-08-08 18:34:14 +00:00
|
|
|
*/
|
2008-10-13 16:45:48 +00:00
|
|
|
virtual void SetupProperties(const Importer* pImp /*,
|
|
|
|
unsigned int ppFlags*/);
|
2008-08-08 18:34:14 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
protected:
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// -------------------------------------------------------------------
|
2008-05-09 17:24:28 +00:00
|
|
|
/** Called by Importer::GetExtensionList() for each loaded importer.
|
|
|
|
* Importer implementations should append all file extensions
|
|
|
|
* which they supported to the passed string.
|
|
|
|
* Example: "*.blabb;*.quak;*.gug;*.foo" (no comma after the last!)
|
|
|
|
* @param append Output string
|
|
|
|
*/
|
|
|
|
virtual void GetExtensionList(std::string& append) = 0;
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Imports the given file into the given scene structure. The
|
|
|
|
* function is expected to throw an ImportErrorException if there is
|
|
|
|
* an error. If it terminates normally, the data in aiScene is
|
|
|
|
* expected to be correct. Override this function to implement the
|
|
|
|
* actual importing.
|
2008-06-22 10:09:26 +00:00
|
|
|
* <br>
|
2008-09-30 20:20:56 +00:00
|
|
|
* The output scene must meet the following requirements:<br>
|
2008-06-22 10:09:26 +00:00
|
|
|
* - at least a root node must be there<br>
|
2008-09-30 20:20:56 +00:00
|
|
|
* - aiMesh::mPrimitiveTypes may be 0. The types of primitives
|
|
|
|
* in the mesh are determined automatically in this case.<br>
|
|
|
|
* - the vertex data is stored in a pseudo-indexed "verbose" format.
|
|
|
|
* In fact this means that every vertex that is referenced by
|
|
|
|
* a face is unique. Or the other way round: a vertex index may
|
|
|
|
* not occur twice in a single aiMesh.
|
ASE: Added WIP support for *SMOOTHSKINMESH elements in ASE/ASC files. Fixes in the ASE loader. Fixed animation parsing. Temporary implementation of target lights and cameras, including animations.
3DS: Fixed transformation problems (Pivot points), added WIP animation support. No target animation yet (cameras, spot lights). Not yet fully tested, but static models that worked before should still work now, except all look correct now :-) (some problems with very large models remaining)
Further work on the IRR and IRRMESH loaders. IRR still WIP, IRRMESH more stable now.
Work on the LWo loader. Added support for the "one-layer-only" mode. Hierarchy bug still unfixed, UV coords bug still unfixed.
Further work on the FindInvalidDataprocess. Improved validation for normals, no false positives anymore.
Further work on the MDR loader, still WIP.
Moved DeterminePType-Step to ScenePreprocessor.
aiAnimation::mDuration is optional now, ScenePreprocessor computes it automatically if set to -1.
Fixes in the SMD loader. Still crashes on some files.
Updated animation documentation.
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@236 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2008-11-09 23:17:19 +00:00
|
|
|
* - aiAnimation::mDuration may be -1. Assimp determines the length
|
|
|
|
* of the animation automatically in this case as the length of
|
|
|
|
* the longest animation channel.
|
2008-09-30 20:20:56 +00:00
|
|
|
*
|
2008-10-19 11:32:33 +00:00
|
|
|
* If the AI_SCENE_FLAGS_INCOMPLETE-Flag is not set:<br>
|
2008-09-30 20:20:56 +00:00
|
|
|
* - at least one mesh must be there<br>
|
2008-06-22 10:09:26 +00:00
|
|
|
* - at least one material must be there<br>
|
|
|
|
* - there may be no meshes with 0 vertices or faces<br>
|
|
|
|
* This won't be checked (except by the validation step), Assimp will
|
|
|
|
* crash if one of the conditions is not met!
|
|
|
|
*
|
2008-05-05 12:36:31 +00:00
|
|
|
* @param pFile Path of the file to be imported.
|
|
|
|
* @param pScene The scene object to hold the imported data.
|
2008-05-09 17:24:28 +00:00
|
|
|
* NULL is not a valid parameter.
|
2008-05-05 12:36:31 +00:00
|
|
|
* @param pIOHandler The IO handler to use for any file access.
|
2008-05-09 17:24:28 +00:00
|
|
|
* NULL is not a valid parameter.
|
2008-05-05 12:36:31 +00:00
|
|
|
*/
|
2008-05-09 17:24:28 +00:00
|
|
|
virtual void InternReadFile( const std::string& pFile,
|
|
|
|
aiScene* pScene, IOSystem* pIOHandler) = 0;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-10-24 20:37:54 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** A utility for CanRead().
|
|
|
|
*
|
|
|
|
* The function searches the header of a file for a specific token
|
|
|
|
* and returns true if this token is found. This works for text
|
|
|
|
* files only. There is a rudimentary handling if UNICODE files.
|
|
|
|
* The comparison is case independent.
|
|
|
|
*
|
|
|
|
* @param pIOSystem IO System to work with
|
|
|
|
* @param file File name of the file
|
|
|
|
* @param tokens List of tokens to search for
|
|
|
|
* @param numTokens Size of the token array
|
|
|
|
* @param searchBytes Number of bytes to be searched for the tokens.
|
|
|
|
*/
|
|
|
|
static bool SearchFileHeaderForToken(IOSystem* pIOSystem,
|
|
|
|
const std::string& file,
|
|
|
|
const char** tokens,
|
|
|
|
unsigned int numTokens,
|
|
|
|
unsigned int searchBytes = 200);
|
|
|
|
|
2008-10-27 00:36:26 +00:00
|
|
|
#if 0 /** TODO **/
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** An utility for all text file loaders. It converts a file to our
|
|
|
|
* ASCII/UTF8 character set. Special unicode characters are lost.
|
|
|
|
*
|
|
|
|
* @param buffer Input buffer. Needn't be terminated with zero.
|
|
|
|
* @param length Length of the input buffer, in bytes. Receives the
|
|
|
|
* number of output characters, excluding the terminal char.
|
|
|
|
* @return true if the source format did not match our internal
|
|
|
|
* format so it was converted.
|
|
|
|
*/
|
|
|
|
static bool ConvertToUTF8(const char* buffer,
|
|
|
|
unsigned int& length);
|
|
|
|
#endif
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
protected:
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
/** Error description in case there was one. */
|
|
|
|
std::string mErrorText;
|
|
|
|
};
|
|
|
|
|
2008-10-27 00:36:26 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
/** A helper class that can be used by importers which need to load many
|
|
|
|
* extern meshes recursively.
|
|
|
|
*
|
|
|
|
* The class uses several threads to load these meshes (or at least it
|
|
|
|
* could, this has not yet been implemented at the moment).
|
|
|
|
*
|
|
|
|
* @note The class may not be used by more than one thread
|
|
|
|
*/
|
|
|
|
class ASSIMP_API BatchLoader
|
|
|
|
{
|
2008-10-31 19:32:00 +00:00
|
|
|
// friend of Importer
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/** Represents a full list of configuration properties
|
|
|
|
* for the importer.
|
|
|
|
*
|
|
|
|
* Properties can be set using SetGenericProperty
|
|
|
|
*/
|
|
|
|
struct PropertyMap
|
|
|
|
{
|
|
|
|
Importer::IntPropertyMap ints;
|
|
|
|
Importer::FloatPropertyMap floats;
|
|
|
|
Importer::StringPropertyMap strings;
|
|
|
|
};
|
|
|
|
|
2008-10-27 00:36:26 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/** Construct a batch loader from a given IO system
|
|
|
|
*/
|
|
|
|
BatchLoader(IOSystem* pIO);
|
|
|
|
~BatchLoader();
|
|
|
|
|
|
|
|
|
|
|
|
/** Add a new file to the list of files to be loaded.
|
|
|
|
*
|
|
|
|
* @param file File to be loaded
|
2008-10-31 19:32:00 +00:00
|
|
|
* @param steps Steps to be executed on the file
|
|
|
|
* @param map Optional configuration properties
|
2008-10-27 00:36:26 +00:00
|
|
|
*/
|
2008-10-31 19:32:00 +00:00
|
|
|
void AddLoadRequest (const std::string& file,
|
|
|
|
unsigned int steps = 0, const PropertyMap* map = NULL);
|
2008-10-27 00:36:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
/** Get an imported scene.
|
|
|
|
*
|
|
|
|
* This polls the import from the internal request list.
|
|
|
|
* If an import is requested several times, this function
|
|
|
|
* can be called several times, too.
|
|
|
|
*
|
|
|
|
* @param file File name of the scene
|
|
|
|
* @return NULL if there is no scene with this file name
|
|
|
|
* in the queue of the scene hasn't been loaded yet.
|
|
|
|
*/
|
|
|
|
aiScene* GetImport (const std::string& file);
|
|
|
|
|
|
|
|
|
|
|
|
/** Waits until all scenes have been loaded.
|
|
|
|
*/
|
|
|
|
void LoadAll();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// No need to have that in the public API ...
|
|
|
|
void* pimpl;
|
|
|
|
};
|
2008-09-13 22:31:15 +00:00
|
|
|
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
} // end of namespace Assimp
|
|
|
|
|
2008-09-11 20:50:15 +00:00
|
|
|
#endif // AI_BASEIMPORTER_H_INC
|