nuclear@0: /* nuclear@0: Open Asset Import Library (assimp) nuclear@0: ---------------------------------------------------------------------- nuclear@0: nuclear@0: Copyright (c) 2006-2012, assimp team nuclear@0: All rights reserved. nuclear@0: nuclear@0: Redistribution and use of this software in source and binary forms, nuclear@0: with or without modification, are permitted provided that the nuclear@0: following conditions are met: nuclear@0: nuclear@0: * Redistributions of source code must retain the above nuclear@0: copyright notice, this list of conditions and the nuclear@0: following disclaimer. nuclear@0: nuclear@0: * Redistributions in binary form must reproduce the above nuclear@0: copyright notice, this list of conditions and the nuclear@0: following disclaimer in the documentation and/or other nuclear@0: materials provided with the distribution. nuclear@0: nuclear@0: * Neither the name of the assimp team, nor the names of its nuclear@0: contributors may be used to endorse or promote products nuclear@0: derived from this software without specific prior nuclear@0: written permission of the assimp team. nuclear@0: nuclear@0: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS nuclear@0: "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT nuclear@0: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR nuclear@0: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT nuclear@0: OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, nuclear@0: SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT nuclear@0: LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, nuclear@0: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY nuclear@0: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT nuclear@0: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE nuclear@0: OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. nuclear@0: nuclear@0: ---------------------------------------------------------------------- nuclear@0: */ nuclear@0: nuclear@0: /** @file Helper class to parse a XFile into a temporary structure */ nuclear@0: #ifndef AI_XFILEPARSER_H_INC nuclear@0: #define AI_XFILEPARSER_H_INC nuclear@0: nuclear@0: #include nuclear@0: #include nuclear@0: nuclear@0: #include "assimp/types.h" nuclear@0: nuclear@0: namespace Assimp nuclear@0: { nuclear@0: namespace XFile nuclear@0: { nuclear@0: struct Node; nuclear@0: struct Mesh; nuclear@0: struct Scene; nuclear@0: struct Material; nuclear@0: struct Animation; nuclear@0: struct AnimBone; nuclear@0: } nuclear@0: nuclear@0: /** The XFileParser reads a XFile either in text or binary form and builds a temporary nuclear@0: * data structure out of it. nuclear@0: */ nuclear@0: class XFileParser nuclear@0: { nuclear@0: public: nuclear@0: /** Constructor. Creates a data structure out of the XFile given in the memory block. nuclear@0: * @param pBuffer Null-terminated memory buffer containing the XFile nuclear@0: */ nuclear@0: XFileParser( const std::vector& pBuffer); nuclear@0: nuclear@0: /** Destructor. Destroys all imported data along with it */ nuclear@0: ~XFileParser(); nuclear@0: nuclear@0: /** Returns the temporary representation of the imported data */ nuclear@0: XFile::Scene* GetImportedData() const { return mScene; } nuclear@0: nuclear@0: protected: nuclear@0: void ParseFile(); nuclear@0: void ParseDataObjectTemplate(); nuclear@0: void ParseDataObjectFrame( XFile::Node *pParent); nuclear@0: void ParseDataObjectTransformationMatrix( aiMatrix4x4& pMatrix); nuclear@0: void ParseDataObjectMesh( XFile::Mesh* pMesh); nuclear@0: void ParseDataObjectSkinWeights( XFile::Mesh* pMesh); nuclear@0: void ParseDataObjectSkinMeshHeader( XFile::Mesh* pMesh); nuclear@0: void ParseDataObjectMeshNormals( XFile::Mesh* pMesh); nuclear@0: void ParseDataObjectMeshTextureCoords( XFile::Mesh* pMesh); nuclear@0: void ParseDataObjectMeshVertexColors( XFile::Mesh* pMesh); nuclear@0: void ParseDataObjectMeshMaterialList( XFile::Mesh* pMesh); nuclear@0: void ParseDataObjectMaterial( XFile::Material* pMaterial); nuclear@0: void ParseDataObjectAnimTicksPerSecond(); nuclear@0: void ParseDataObjectAnimationSet(); nuclear@0: void ParseDataObjectAnimation( XFile::Animation* pAnim); nuclear@0: void ParseDataObjectAnimationKey( XFile::AnimBone *pAnimBone); nuclear@0: void ParseDataObjectTextureFilename( std::string& pName); nuclear@0: void ParseUnknownDataObject(); nuclear@0: nuclear@0: //! places pointer to next begin of a token, and ignores comments nuclear@0: void FindNextNoneWhiteSpace(); nuclear@0: nuclear@0: //! returns next parseable token. Returns empty string if no token there nuclear@0: std::string GetNextToken(); nuclear@0: nuclear@0: //! reads header of dataobject including the opening brace. nuclear@0: //! returns false if error happened, and writes name of object nuclear@0: //! if there is one nuclear@0: void readHeadOfDataObject( std::string* poName = NULL); nuclear@0: nuclear@0: //! checks for closing curly brace, throws exception if not there nuclear@0: void CheckForClosingBrace(); nuclear@0: nuclear@0: //! checks for one following semicolon, throws exception if not there nuclear@0: void CheckForSemicolon(); nuclear@0: nuclear@0: //! checks for a separator char, either a ',' or a ';' nuclear@0: void CheckForSeparator(); nuclear@0: nuclear@0: /// tests and possibly consumes a separator char, but does nothing if there was no separator nuclear@0: void TestForSeparator(); nuclear@0: nuclear@0: //! reads a x file style string nuclear@0: void GetNextTokenAsString( std::string& poString); nuclear@0: nuclear@0: void ReadUntilEndOfLine(); nuclear@0: nuclear@0: unsigned short ReadBinWord(); nuclear@0: unsigned int ReadBinDWord(); nuclear@0: unsigned int ReadInt(); nuclear@0: float ReadFloat(); nuclear@0: aiVector2D ReadVector2(); nuclear@0: aiVector3D ReadVector3(); nuclear@0: aiColor3D ReadRGB(); nuclear@0: aiColor4D ReadRGBA(); nuclear@0: nuclear@0: /** Throws an exception with a line number and the given text. */ nuclear@0: void ThrowException( const std::string& pText); nuclear@0: nuclear@0: /** Filters the imported hierarchy for some degenerated cases that some exporters produce. nuclear@0: * @param pData The sub-hierarchy to filter nuclear@0: */ nuclear@0: void FilterHierarchy( XFile::Node* pNode); nuclear@0: nuclear@0: protected: nuclear@0: unsigned int mMajorVersion, mMinorVersion; ///< version numbers nuclear@0: bool mIsBinaryFormat; ///< true if the file is in binary, false if it's in text form nuclear@0: unsigned int mBinaryFloatSize; ///< float size, either 32 or 64 bits nuclear@0: // counter for number arrays in binary format nuclear@0: unsigned int mBinaryNumCount; nuclear@0: nuclear@0: const char* P; nuclear@0: const char* End; nuclear@0: nuclear@0: /// Line number when reading in text format nuclear@0: unsigned int mLineNumber; nuclear@0: nuclear@0: /// Imported data nuclear@0: XFile::Scene* mScene; nuclear@0: }; nuclear@0: nuclear@0: } nuclear@0: #endif // AI_XFILEPARSER_H_INC