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 .3ds importer class. */
|
|
|
|
#ifndef AI_3DSIMPORTER_H_INC
|
|
|
|
#define AI_3DSIMPORTER_H_INC
|
|
|
|
|
|
|
|
#include "BaseImporter.h"
|
|
|
|
#include "../include/aiTypes.h"
|
|
|
|
|
|
|
|
struct aiNode;
|
|
|
|
#include "3DSHelper.h"
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
namespace Assimp
|
|
|
|
{
|
2008-05-09 17:24:28 +00:00
|
|
|
class MaterialHelper;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
using namespace Dot3DS;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
/** The Dot3DSImporter is a worker class capable of importing a scene from a
|
|
|
|
* 3ds Max 4/5 Files (.3ds)
|
|
|
|
*/
|
|
|
|
class Dot3DSImporter : public BaseImporter
|
|
|
|
{
|
|
|
|
friend class Importer;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/** Constructor to be privately used by Importer */
|
|
|
|
Dot3DSImporter();
|
|
|
|
|
|
|
|
/** Destructor, private as well */
|
|
|
|
~Dot3DSImporter();
|
|
|
|
|
|
|
|
public:
|
2008-08-09 22:39:57 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Returns whether the class can handle the format of the given file.
|
|
|
|
* See BaseImporter::CanRead() for details. */
|
|
|
|
bool CanRead( const std::string& pFile, IOSystem* pIOHandler) const;
|
|
|
|
|
2008-08-09 22:39:57 +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.
|
|
|
|
*/
|
|
|
|
void SetupProperties(const Importer* pImp);
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
protected:
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Called by Importer::GetExtensionList() for each loaded importer.
|
|
|
|
* See BaseImporter::GetExtensionList() for details
|
|
|
|
*/
|
|
|
|
void GetExtensionList(std::string& append)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-05-09 17:24:28 +00:00
|
|
|
append.append("*.3ds");
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Imports the given file into the given scene structure.
|
|
|
|
* See BaseImporter::InternReadFile() for details
|
|
|
|
*/
|
|
|
|
void InternReadFile( const std::string& pFile, aiScene* pScene,
|
|
|
|
IOSystem* pIOHandler);
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Converts a temporary material to the outer representation
|
|
|
|
*/
|
|
|
|
void ConvertMaterial(Dot3DS::Material& p_cMat,
|
|
|
|
MaterialHelper& p_pcOut);
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Read a chunk, get a pointer to it
|
|
|
|
* The mCurrent pointer will be increased by sizeof(Dot3DSFile::Chunk),
|
|
|
|
* thus pointing directly to the data of the chunk
|
|
|
|
*/
|
|
|
|
void ReadChunk(const Dot3DSFile::Chunk** p_ppcOut);
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Parse a percentage chunk. mCurrent will point to the next
|
|
|
|
* chunk behind afterwards. If no percentage chunk is found
|
|
|
|
* QNAN is returned.
|
|
|
|
*/
|
|
|
|
float ParsePercentageChunk();
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Parse a color chunk. mCurrent will point to the next
|
|
|
|
* chunk behind afterwards. If no color chunk is found
|
|
|
|
* QNAN is returned in all members.
|
|
|
|
*/
|
|
|
|
void ParseColorChunk(aiColor3D* p_pcOut,
|
|
|
|
bool p_bAcceptPercent = true);
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Skip a chunk in the file
|
|
|
|
*/
|
|
|
|
void SkipChunk();
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Generate the nodegraph
|
|
|
|
*/
|
|
|
|
void GenerateNodeGraph(aiScene* pcOut);
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Parse a main top-level chunk in the file
|
|
|
|
*/
|
2008-07-10 16:49:01 +00:00
|
|
|
void ParseMainChunk(int& piRemaining);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Parse a top-level chunk in the file
|
|
|
|
*/
|
2008-07-10 16:49:01 +00:00
|
|
|
void ParseChunk(int& piRemaining);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Parse a top-level editor chunk in the file
|
|
|
|
*/
|
2008-07-10 16:49:01 +00:00
|
|
|
void ParseEditorChunk(int& piRemaining);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Parse a top-level object chunk in the file
|
|
|
|
*/
|
2008-07-10 16:49:01 +00:00
|
|
|
void ParseObjectChunk(int& piRemaining);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Parse a material chunk in the file
|
|
|
|
*/
|
2008-07-10 16:49:01 +00:00
|
|
|
void ParseMaterialChunk(int& piRemaining);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Parse a mesh chunk in the file
|
|
|
|
*/
|
2008-07-10 16:49:01 +00:00
|
|
|
void ParseMeshChunk(int& piRemaining);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Parse a face list chunk in the file
|
|
|
|
*/
|
2008-07-10 16:49:01 +00:00
|
|
|
void ParseFaceChunk(int& piRemaining);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Parse a keyframe chunk in the file
|
|
|
|
*/
|
2008-07-10 16:49:01 +00:00
|
|
|
void ParseKeyframeChunk(int& piRemaining);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Parse a hierarchy chunk in the file
|
|
|
|
*/
|
2008-07-10 16:49:01 +00:00
|
|
|
void ParseHierarchyChunk(int& piRemaining);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Parse a texture chunk in the file
|
|
|
|
*/
|
2008-07-10 16:49:01 +00:00
|
|
|
void ParseTextureChunk(int& piRemaining,Dot3DS::Texture* pcOut);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Convert the meshes in the file
|
|
|
|
*/
|
|
|
|
void ConvertMeshes(aiScene* pcOut);
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Replace the default material in the scene
|
|
|
|
*/
|
|
|
|
void ReplaceDefaultMaterial();
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Convert the whole scene
|
|
|
|
*/
|
|
|
|
void ConvertScene(aiScene* pcOut);
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** generate unique vertices for a mesh
|
|
|
|
*/
|
2008-08-28 17:35:36 +00:00
|
|
|
void MakeUnique(Dot3DS::Mesh& sMesh);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Add a node to the node graph
|
|
|
|
*/
|
|
|
|
void AddNodeToGraph(aiScene* pcSOut,aiNode* pcOut,Dot3DS::Node* pcIn);
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Search for a node in the graph.
|
|
|
|
* Called recursively
|
|
|
|
*/
|
|
|
|
void InverseNodeSearch(Dot3DS::Node* pcNode,Dot3DS::Node* pcCurrent);
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Apply the master scaling factor to the mesh
|
|
|
|
*/
|
|
|
|
void ApplyMasterScale(aiScene* pScene);
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
/** Clamp all indices in the file to a valid range
|
|
|
|
*/
|
2008-08-28 17:35:36 +00:00
|
|
|
void CheckIndices(Dot3DS::Mesh& sMesh);
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
protected:
|
2008-08-09 22:39:57 +00:00
|
|
|
|
|
|
|
/** Configuration option: skip pivot chunks */
|
|
|
|
bool configSkipPivot;
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
/** Buffer to hold the loaded file */
|
|
|
|
unsigned char* mBuffer;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
/** Pointer to the current read position */
|
|
|
|
const unsigned char* mCurrent;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
/** Used to store old chunk addresses to jump back in the file*/
|
|
|
|
const unsigned char* mLast;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
/** Last touched node index */
|
|
|
|
short mLastNodeIndex;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
/** Current node, root node */
|
|
|
|
Dot3DS::Node* mCurrentNode, *mRootNode;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
/** Scene under construction */
|
|
|
|
Dot3DS::Scene* mScene;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
/** Ambient base color of the scene */
|
|
|
|
aiColor3D mClrAmbient;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
/** Master scaling factor of the scene */
|
|
|
|
float mMasterScale;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
/** Path to the background image of the scene */
|
|
|
|
std::string mBackgroundImage;
|
|
|
|
bool bHasBG;
|
|
|
|
};
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
} // end of namespace Assimp
|
|
|
|
|
|
|
|
#endif // AI_3DSIMPORTER_H_INC
|