From 3cd55c54dbf66a320438d743fbd223952043cd39 Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Wed, 7 Dec 2016 19:33:08 -0500 Subject: Update assimp lib to 3.3.1 The currently included assimp lib is v3.0 from 2012. This updates assimp lib to the latest released version (3.3.1). Change-Id: I15a60e3150c0b268422f23137107b34e4c5c4342 Reviewed-by: Sean Harmer --- src/3rdparty/assimp/code/ColladaParser.h | 519 ++++++++++++++++--------------- 1 file changed, 273 insertions(+), 246 deletions(-) (limited to 'src/3rdparty/assimp/code/ColladaParser.h') diff --git a/src/3rdparty/assimp/code/ColladaParser.h b/src/3rdparty/assimp/code/ColladaParser.h index ee764a23b..9193e2027 100644 --- a/src/3rdparty/assimp/code/ColladaParser.h +++ b/src/3rdparty/assimp/code/ColladaParser.h @@ -1,45 +1,45 @@ /* -Open Asset Import Library (assimp) ----------------------------------------------------------------------- - -Copyright (c) 2006-2012, assimp 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 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. - ----------------------------------------------------------------------- -*/ + Open Asset Import Library (assimp) + ---------------------------------------------------------------------- + + Copyright (c) 2006-2016, assimp 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 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. + + ---------------------------------------------------------------------- + */ /** @file ColladaParser.h - * @brief Defines the parser helper class for the collada loader + * @brief Defines the parser helper class for the collada loader */ #ifndef AI_COLLADAPARSER_H_INC @@ -47,294 +47,321 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "irrXMLWrapper.h" #include "ColladaHelper.h" +#include +#include "TinyFormatter.h" +#include namespace Assimp { -// ------------------------------------------------------------------------------------------ -/** Parser helper class for the Collada loader. - * - * Does all the XML reading and builds internal data structures from it, - * but leaves the resolving of all the references to the loader. -*/ -class ColladaParser -{ - friend class ColladaLoader; + // ------------------------------------------------------------------------------------------ + /** Parser helper class for the Collada loader. + * + * Does all the XML reading and builds internal data structures from it, + * but leaves the resolving of all the references to the loader. + */ + class ColladaParser + { + friend class ColladaLoader; -protected: - /** Constructor from XML file */ - ColladaParser( IOSystem* pIOHandler, const std::string& pFile); + protected: + /** Constructor from XML file */ + ColladaParser( IOSystem* pIOHandler, const std::string& pFile); - /** Destructor */ - ~ColladaParser(); + /** Destructor */ + ~ColladaParser(); - /** Reads the contents of the file */ - void ReadContents(); + /** Reads the contents of the file */ + void ReadContents(); - /** Reads the structure of the file */ - void ReadStructure(); + /** Reads the structure of the file */ + void ReadStructure(); - /** Reads asset informations such as coordinate system informations and legal blah */ - void ReadAssetInfo(); + /** Reads asset informations such as coordinate system informations and legal blah */ + void ReadAssetInfo(); - /** Reads the animation library */ - void ReadAnimationLibrary(); + /** Reads the animation library */ + void ReadAnimationLibrary(); - /** Reads an animation into the given parent structure */ - void ReadAnimation( Collada::Animation* pParent); + /** Reads the animation clip library */ + void ReadAnimationClipLibrary(); - /** Reads an animation sampler into the given anim channel */ - void ReadAnimationSampler( Collada::AnimationChannel& pChannel); + /** Re-build animations from animation clip library, if present, otherwise combine single-channel animations */ + void PostProcessRootAnimations(); - /** Reads the skeleton controller library */ - void ReadControllerLibrary(); + /** Reads an animation into the given parent structure */ + void ReadAnimation( Collada::Animation* pParent); - /** Reads a controller into the given mesh structure */ - void ReadController( Collada::Controller& pController); + /** Reads an animation sampler into the given anim channel */ + void ReadAnimationSampler( Collada::AnimationChannel& pChannel); - /** Reads the joint definitions for the given controller */ - void ReadControllerJoints( Collada::Controller& pController); + /** Reads the skeleton controller library */ + void ReadControllerLibrary(); - /** Reads the joint weights for the given controller */ - void ReadControllerWeights( Collada::Controller& pController); + /** Reads a controller into the given mesh structure */ + void ReadController( Collada::Controller& pController); - /** Reads the image library contents */ - void ReadImageLibrary(); + /** Reads the joint definitions for the given controller */ + void ReadControllerJoints( Collada::Controller& pController); - /** Reads an image entry into the given image */ - void ReadImage( Collada::Image& pImage); + /** Reads the joint weights for the given controller */ + void ReadControllerWeights( Collada::Controller& pController); - /** Reads the material library */ - void ReadMaterialLibrary(); + /** Reads the image library contents */ + void ReadImageLibrary(); - /** Reads a material entry into the given material */ - void ReadMaterial( Collada::Material& pMaterial); + /** Reads an image entry into the given image */ + void ReadImage( Collada::Image& pImage); - /** Reads the camera library */ - void ReadCameraLibrary(); + /** Reads the material library */ + void ReadMaterialLibrary(); - /** Reads a camera entry into the given camera */ - void ReadCamera( Collada::Camera& pCamera); + /** Reads a material entry into the given material */ + void ReadMaterial( Collada::Material& pMaterial); - /** Reads the light library */ - void ReadLightLibrary(); + /** Reads the camera library */ + void ReadCameraLibrary(); - /** Reads a light entry into the given light */ - void ReadLight( Collada::Light& pLight); + /** Reads a camera entry into the given camera */ + void ReadCamera( Collada::Camera& pCamera); - /** Reads the effect library */ - void ReadEffectLibrary(); + /** Reads the light library */ + void ReadLightLibrary(); - /** Reads an effect entry into the given effect*/ - void ReadEffect( Collada::Effect& pEffect); + /** Reads a light entry into the given light */ + void ReadLight( Collada::Light& pLight); - /** Reads an COMMON effect profile */ - void ReadEffectProfileCommon( Collada::Effect& pEffect); + /** Reads the effect library */ + void ReadEffectLibrary(); - /** Read sampler properties */ - void ReadSamplerProperties( Collada::Sampler& pSampler); + /** Reads an effect entry into the given effect*/ + void ReadEffect( Collada::Effect& pEffect); - /** Reads an effect entry containing a color or a texture defining that color */ - void ReadEffectColor( aiColor4D& pColor, Collada::Sampler& pSampler); + /** Reads an COMMON effect profile */ + void ReadEffectProfileCommon( Collada::Effect& pEffect); - /** Reads an effect entry containing a float */ - void ReadEffectFloat( float& pFloat); + /** Read sampler properties */ + void ReadSamplerProperties( Collada::Sampler& pSampler); - /** Reads an effect parameter specification of any kind */ - void ReadEffectParam( Collada::EffectParam& pParam); + /** Reads an effect entry containing a color or a texture defining that color */ + void ReadEffectColor( aiColor4D& pColor, Collada::Sampler& pSampler); - /** Reads the geometry library contents */ - void ReadGeometryLibrary(); + /** Reads an effect entry containing a float */ + void ReadEffectFloat( float& pFloat); - /** Reads a geometry from the geometry library. */ - void ReadGeometry( Collada::Mesh* pMesh); + /** Reads an effect parameter specification of any kind */ + void ReadEffectParam( Collada::EffectParam& pParam); - /** Reads a mesh from the geometry library */ - void ReadMesh( Collada::Mesh* pMesh); + /** Reads the geometry library contents */ + void ReadGeometryLibrary(); - /** Reads a source element - a combination of raw data and an accessor defining - * things that should not be redefinable. Yes, that's another rant. - */ - void ReadSource(); + /** Reads a geometry from the geometry library. */ + void ReadGeometry( Collada::Mesh* pMesh); - /** Reads a data array holding a number of elements, and stores it in the global library. - * Currently supported are array of floats and arrays of strings. - */ - void ReadDataArray(); + /** Reads a mesh from the geometry library */ + void ReadMesh( Collada::Mesh* pMesh); - /** Reads an accessor and stores it in the global library under the given ID - - * accessors use the ID of the parent element - */ - void ReadAccessor( const std::string& pID); + /** Reads a source element - a combination of raw data and an accessor defining + * things that should not be redefinable. Yes, that's another rant. + */ + void ReadSource(); - /** Reads input declarations of per-vertex mesh data into the given mesh */ - void ReadVertexData( Collada::Mesh* pMesh); + /** Reads a data array holding a number of elements, and stores it in the global library. + * Currently supported are array of floats and arrays of strings. + */ + void ReadDataArray(); - /** Reads input declarations of per-index mesh data into the given mesh */ - void ReadIndexData( Collada::Mesh* pMesh); + /** Reads an accessor and stores it in the global library under the given ID - + * accessors use the ID of the parent element + */ + void ReadAccessor( const std::string& pID); - /** Reads a single input channel element and stores it in the given array, if valid */ - void ReadInputChannel( std::vector& poChannels); + /** Reads input declarations of per-vertex mesh data into the given mesh */ + void ReadVertexData( Collada::Mesh* pMesh); - /** Reads a

primitive index list and assembles the mesh data into the given mesh */ - void ReadPrimitives( Collada::Mesh* pMesh, std::vector& pPerIndexChannels, - size_t pNumPrimitives, const std::vector& pVCount, Collada::PrimitiveType pPrimType); + /** Reads input declarations of per-index mesh data into the given mesh */ + void ReadIndexData( Collada::Mesh* pMesh); - /** Extracts a single object from an input channel and stores it in the appropriate mesh data array */ - void ExtractDataObjectFromChannel( const Collada::InputChannel& pInput, size_t pLocalIndex, Collada::Mesh* pMesh); + /** Reads a single input channel element and stores it in the given array, if valid */ + void ReadInputChannel( std::vector& poChannels); - /** Reads the library of node hierarchies and scene parts */ - void ReadSceneLibrary(); + /** Reads a

primitive index list and assembles the mesh data into the given mesh */ + size_t ReadPrimitives( Collada::Mesh* pMesh, std::vector& pPerIndexChannels, + size_t pNumPrimitives, const std::vector& pVCount, Collada::PrimitiveType pPrimType); - /** Reads a scene node's contents including children and stores it in the given node */ - void ReadSceneNode( Collada::Node* pNode); + /** Copies the data for a single primitive into the mesh, based on the InputChannels */ + void CopyVertex(size_t currentVertex, size_t numOffsets, size_t numPoints, size_t perVertexOffset, + Collada::Mesh* pMesh, std::vector& pPerIndexChannels, + size_t currentPrimitive, const std::vector& indices); - /** Reads a node transformation entry of the given type and adds it to the given node's transformation list. */ - void ReadNodeTransformation( Collada::Node* pNode, Collada::TransformType pType); + /** Reads one triangle of a tristrip into the mesh */ + void ReadPrimTriStrips(size_t numOffsets, size_t perVertexOffset, Collada::Mesh* pMesh, + std::vector& pPerIndexChannels, size_t currentPrimitive, const std::vector& indices); - /** Reads a mesh reference in a node and adds it to the node's mesh list */ - void ReadNodeGeometry( Collada::Node* pNode); + /** Extracts a single object from an input channel and stores it in the appropriate mesh data array */ + void ExtractDataObjectFromChannel( const Collada::InputChannel& pInput, size_t pLocalIndex, Collada::Mesh* pMesh); - /** Reads the collada scene */ - void ReadScene(); + /** Reads the library of node hierarchies and scene parts */ + void ReadSceneLibrary(); - // Processes bind_vertex_input and bind elements - void ReadMaterialVertexInputBinding( Collada::SemanticMappingTable& tbl); + /** Reads a scene node's contents including children and stores it in the given node */ + void ReadSceneNode( Collada::Node* pNode); -protected: - /** Aborts the file reading with an exception */ - void ThrowException( const std::string& pError) const; + /** Reads a node transformation entry of the given type and adds it to the given node's transformation list. */ + void ReadNodeTransformation( Collada::Node* pNode, Collada::TransformType pType); - /** Skips all data until the end node of the current element */ - void SkipElement(); + /** Reads a mesh reference in a node and adds it to the node's mesh list */ + void ReadNodeGeometry( Collada::Node* pNode); - /** Skips all data until the end node of the given element */ - void SkipElement( const char* pElement); + /** Reads the collada scene */ + void ReadScene(); - /** Compares the current xml element name to the given string and returns true if equal */ - bool IsElement( const char* pName) const; + // Processes bind_vertex_input and bind elements + void ReadMaterialVertexInputBinding( Collada::SemanticMappingTable& tbl); - /** Tests for the opening tag of the given element, throws an exception if not found */ - void TestOpening( const char* pName); + protected: + /** Aborts the file reading with an exception */ + AI_WONT_RETURN void ThrowException( const std::string& pError) const AI_WONT_RETURN_SUFFIX; + void ReportWarning(const char* msg,...); - /** Tests for the closing tag of the given element, throws an exception if not found */ - void TestClosing( const char* pName); + /** Skips all data until the end node of the current element */ + void SkipElement(); - /** Checks the present element for the presence of the attribute, returns its index - or throws an exception if not found */ - int GetAttribute( const char* pAttr) const; + /** Skips all data until the end node of the given element */ + void SkipElement( const char* pElement); - /** Returns the index of the named attribute or -1 if not found. Does not throw, - therefore useful for optional attributes */ - int TestAttribute( const char* pAttr) const; + /** Compares the current xml element name to the given string and returns true if equal */ + bool IsElement( const char* pName) const; - /** Reads the text contents of an element, throws an exception if not given. - Skips leading whitespace. */ - const char* GetTextContent(); + /** Tests for the opening tag of the given element, throws an exception if not found */ + void TestOpening( const char* pName); - /** Reads the text contents of an element, returns NULL if not given. - Skips leading whitespace. */ - const char* TestTextContent(); + /** Tests for the closing tag of the given element, throws an exception if not found */ + void TestClosing( const char* pName); - /** Reads a single bool from current text content */ - bool ReadBoolFromTextContent(); + /** Checks the present element for the presence of the attribute, returns its index + or throws an exception if not found */ + int GetAttribute( const char* pAttr) const; - /** Reads a single float from current text content */ - float ReadFloatFromTextContent(); + /** Returns the index of the named attribute or -1 if not found. Does not throw, + therefore useful for optional attributes */ + int TestAttribute( const char* pAttr) const; - /** Calculates the resulting transformation from all the given transform steps */ - aiMatrix4x4 CalculateResultTransform( const std::vector& pTransforms) const; + /** Reads the text contents of an element, throws an exception if not given. + Skips leading whitespace. */ + const char* GetTextContent(); - /** Determines the input data type for the given semantic string */ - Collada::InputType GetTypeForSemantic( const std::string& pSemantic); + /** Reads the text contents of an element, returns NULL if not given. + Skips leading whitespace. */ + const char* TestTextContent(); - /** Finds the item in the given library by its reference, throws if not found */ - template const Type& ResolveLibraryReference( - const std::map& pLibrary, const std::string& pURL) const; + /** Reads a single bool from current text content */ + bool ReadBoolFromTextContent(); -protected: - /** Filename, for a verbose error message */ - std::string mFileName; + /** Reads a single float from current text content */ + float ReadFloatFromTextContent(); - /** XML reader, member for everyday use */ - irr::io::IrrXMLReader* mReader; + /** Calculates the resulting transformation from all the given transform steps */ + aiMatrix4x4 CalculateResultTransform( const std::vector& pTransforms) const; - /** All data arrays found in the file by ID. Might be referred to by actually - everyone. Collada, you are a steaming pile of indirection. */ - typedef std::map DataLibrary; - DataLibrary mDataLibrary; + /** Determines the input data type for the given semantic string */ + Collada::InputType GetTypeForSemantic( const std::string& pSemantic); - /** Same for accessors which define how the data in a data array is accessed. */ - typedef std::map AccessorLibrary; - AccessorLibrary mAccessorLibrary; + /** Finds the item in the given library by its reference, throws if not found */ + template const Type& ResolveLibraryReference( + const std::map& pLibrary, const std::string& pURL) const; - /** Mesh library: mesh by ID */ - typedef std::map MeshLibrary; - MeshLibrary mMeshLibrary; + protected: + /** Filename, for a verbose error message */ + std::string mFileName; - /** node library: root node of the hierarchy part by ID */ - typedef std::map NodeLibrary; - NodeLibrary mNodeLibrary; + /** XML reader, member for everyday use */ + irr::io::IrrXMLReader* mReader; - /** Image library: stores texture properties by ID */ - typedef std::map ImageLibrary; - ImageLibrary mImageLibrary; + /** All data arrays found in the file by ID. Might be referred to by actually + everyone. Collada, you are a steaming pile of indirection. */ + typedef std::map DataLibrary; + DataLibrary mDataLibrary; - /** Effect library: surface attributes by ID */ - typedef std::map EffectLibrary; - EffectLibrary mEffectLibrary; + /** Same for accessors which define how the data in a data array is accessed. */ + typedef std::map AccessorLibrary; + AccessorLibrary mAccessorLibrary; - /** Material library: surface material by ID */ - typedef std::map MaterialLibrary; - MaterialLibrary mMaterialLibrary; + /** Mesh library: mesh by ID */ + typedef std::map MeshLibrary; + MeshLibrary mMeshLibrary; - /** Light library: surface light by ID */ - typedef std::map LightLibrary; - LightLibrary mLightLibrary; + /** node library: root node of the hierarchy part by ID */ + typedef std::map NodeLibrary; + NodeLibrary mNodeLibrary; - /** Camera library: surface material by ID */ - typedef std::map CameraLibrary; - CameraLibrary mCameraLibrary; + /** Image library: stores texture properties by ID */ + typedef std::map ImageLibrary; + ImageLibrary mImageLibrary; - /** Controller library: joint controllers by ID */ - typedef std::map ControllerLibrary; - ControllerLibrary mControllerLibrary; + /** Effect library: surface attributes by ID */ + typedef std::map EffectLibrary; + EffectLibrary mEffectLibrary; - /** Pointer to the root node. Don't delete, it just points to one of - the nodes in the node library. */ - Collada::Node* mRootNode; + /** Material library: surface material by ID */ + typedef std::map MaterialLibrary; + MaterialLibrary mMaterialLibrary; - /** Root animation container */ - Collada::Animation mAnims; + /** Light library: surface light by ID */ + typedef std::map LightLibrary; + LightLibrary mLightLibrary; - /** Size unit: how large compared to a meter */ - float mUnitSize; + /** Camera library: surface material by ID */ + typedef std::map CameraLibrary; + CameraLibrary mCameraLibrary; - /** Which is the up vector */ - enum { UP_X, UP_Y, UP_Z } mUpDirection; + /** Controller library: joint controllers by ID */ + typedef std::map ControllerLibrary; + ControllerLibrary mControllerLibrary; - /** Collada file format version */ - Collada::FormatVersion mFormat; -}; + /** Animation library: animation references by ID */ + typedef std::map AnimationLibrary; + AnimationLibrary mAnimationLibrary; -// ------------------------------------------------------------------------------------------------ -// Check for element match -inline bool ColladaParser::IsElement( const char* pName) const -{ - ai_assert( mReader->getNodeType() == irr::io::EXN_ELEMENT); - return ::strcmp( mReader->getNodeName(), pName) == 0; -} - -// ------------------------------------------------------------------------------------------------ -// Finds the item in the given library by its reference, throws if not found -template -const Type& ColladaParser::ResolveLibraryReference( const std::map& pLibrary, const std::string& pURL) const -{ - typename std::map::const_iterator it = pLibrary.find( pURL); - if( it == pLibrary.end()) - ThrowException( boost::str( boost::format( "Unable to resolve library reference \"%s\".") % pURL)); - return it->second; -} + /** Animation clip library: clip animation references by ID */ + typedef std::vector > > AnimationClipLibrary; + AnimationClipLibrary mAnimationClipLibrary; + + /** Pointer to the root node. Don't delete, it just points to one of + the nodes in the node library. */ + Collada::Node* mRootNode; + + /** Root animation container */ + Collada::Animation mAnims; + + /** Size unit: how large compared to a meter */ + float mUnitSize; + + /** Which is the up vector */ + enum { UP_X, UP_Y, UP_Z } mUpDirection; + + /** Collada file format version */ + Collada::FormatVersion mFormat; + }; + + // ------------------------------------------------------------------------------------------------ + // Check for element match + inline bool ColladaParser::IsElement( const char* pName) const + { + ai_assert( mReader->getNodeType() == irr::io::EXN_ELEMENT); + return ::strcmp( mReader->getNodeName(), pName) == 0; + } + + // ------------------------------------------------------------------------------------------------ + // Finds the item in the given library by its reference, throws if not found + template + const Type& ColladaParser::ResolveLibraryReference( const std::map& pLibrary, const std::string& pURL) const + { + typename std::map::const_iterator it = pLibrary.find( pURL); + if( it == pLibrary.end()) + ThrowException( Formatter::format() << "Unable to resolve library reference \"" << pURL << "\"." ); + return it->second; + } } // end of namespace Assimp -- cgit v1.2.3