2008-11-12 17:07:44 +00:00
/*
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2012-02-03 03:38:30 +00:00
Open Asset Import Library ( assimp )
2008-11-12 17:07:44 +00:00
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2012-02-03 03:38:30 +00:00
Copyright ( c ) 2006 - 2012 , assimp team
2008-11-12 17:07:44 +00:00
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 .
2012-02-03 03:38:30 +00:00
* Neither the name of the assimp team , nor the names of its
2008-11-12 17:07:44 +00:00
contributors may be used to endorse or promote products
derived from this software without specific prior
2012-02-03 03:38:30 +00:00
written permission of the assimp team .
2008-11-12 17:07:44 +00:00
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 .
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
2009-01-10 17:58:06 +00:00
/** @file Implementation of the Collada loader */
2008-11-12 17:07:44 +00:00
# include "AssimpPCH.h"
2012-07-07 18:53:24 +00:00
# ifndef ASSIMP_BUILD_NO_COLLADA_IMPORTER
2009-01-18 23:48:25 +00:00
2012-02-03 17:04:06 +00:00
# include "../include/assimp/anim.h"
2008-11-12 17:07:44 +00:00
# include "ColladaLoader.h"
# include "ColladaParser.h"
2009-02-08 22:55:51 +00:00
# include "fast_atof.h"
# include "ParsingUtils.h"
2009-04-10 22:10:11 +00:00
# include "SkeletonMeshBuilder.h"
2009-02-08 22:55:51 +00:00
# include "time.h"
2008-11-12 17:07:44 +00:00
using namespace Assimp ;
2012-04-22 22:26:26 +00:00
static const aiImporterDesc desc = {
" Collada Importer " ,
" " ,
" " ,
" http://collada.org " ,
aiImporterFlags_SupportTextFlavour ,
1 ,
3 ,
1 ,
5 ,
" dae "
} ;
2008-11-12 17:07:44 +00:00
// ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer
ColladaLoader : : ColladaLoader ( )
2013-07-27 01:34:48 +00:00
: noSkeletonMesh ( ) , ignoreUpDirection ( false )
2009-01-10 17:58:06 +00:00
{ }
2008-11-12 17:07:44 +00:00
// ------------------------------------------------------------------------------------------------
// Destructor, private as well
ColladaLoader : : ~ ColladaLoader ( )
2009-01-10 17:58:06 +00:00
{ }
2008-11-12 17:07:44 +00:00
// ------------------------------------------------------------------------------------------------
// Returns whether the class can handle the format of the given file.
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
bool ColladaLoader : : CanRead ( const std : : string & pFile , IOSystem * pIOHandler , bool checkSig ) const
2008-11-12 17:07:44 +00:00
{
// check file extension
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
std : : string extension = GetExtension ( pFile ) ;
if ( extension = = " dae " )
2008-11-12 17:07:44 +00:00
return true ;
2009-01-10 17:58:06 +00:00
// XML - too generic, we need to open the file and search for typical keywords
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
if ( extension = = " xml " | | ! extension . length ( ) | | checkSig ) {
2009-01-10 17:58:06 +00:00
/* If CanRead() is called in order to check whether we
* support a specific file extension in general pIOHandler
* might be NULL and it ' s our duty to return true here .
*/
if ( ! pIOHandler ) return true ;
const char * tokens [ ] = { " collada " } ;
return SearchFileHeaderForToken ( pIOHandler , pFile , tokens , 1 ) ;
}
2008-11-12 17:07:44 +00:00
return false ;
}
2012-06-21 15:24:50 +00:00
// ------------------------------------------------------------------------------------------------
void ColladaLoader : : SetupProperties ( const Importer * pImp )
{
noSkeletonMesh = pImp - > GetPropertyInteger ( AI_CONFIG_IMPORT_NO_SKELETON_MESHES , 0 ) ! = 0 ;
2013-07-27 01:34:48 +00:00
ignoreUpDirection = pImp - > GetPropertyInteger ( AI_CONFIG_IMPORT_COLLADA_IGNORE_UP_DIRECTION , 0 ) ! = 0 ;
2012-06-21 15:24:50 +00:00
}
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
// ------------------------------------------------------------------------------------------------
// Get file extension list
2012-04-22 22:26:26 +00:00
const aiImporterDesc * ColladaLoader : : GetInfo ( ) const
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
{
2012-04-22 22:26:26 +00:00
return & desc ;
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
}
2008-11-12 17:07:44 +00:00
// ------------------------------------------------------------------------------------------------
// Imports the given file into the given scene structure.
void ColladaLoader : : InternReadFile ( const std : : string & pFile , aiScene * pScene , IOSystem * pIOHandler )
{
mFileName = pFile ;
2009-02-08 22:55:51 +00:00
// clean all member arrays - just for safety, it should work even if we did not
mMeshIndexByID . clear ( ) ;
mMaterialIndexByName . clear ( ) ;
mMeshes . clear ( ) ;
newMats . clear ( ) ;
mLights . clear ( ) ;
mCameras . clear ( ) ;
2009-02-11 20:56:05 +00:00
mTextures . clear ( ) ;
2014-06-13 08:56:10 +00:00
mAnims . clear ( ) ;
2009-02-08 22:55:51 +00:00
2008-11-12 17:07:44 +00:00
// parse the input file
2009-03-03 15:43:26 +00:00
ColladaParser parser ( pIOHandler , pFile ) ;
2008-11-12 17:07:44 +00:00
2008-12-04 17:06:26 +00:00
if ( ! parser . mRootNode )
2010-03-18 17:00:12 +00:00
throw DeadlyImportError ( " Collada: File came out empty. Something is wrong here. " ) ;
2008-12-04 17:06:26 +00:00
2009-02-11 20:56:05 +00:00
// reserve some storage to avoid unnecessary reallocs
newMats . reserve ( parser . mMaterialLibrary . size ( ) * 2 ) ;
mMeshes . reserve ( parser . mMeshLibrary . size ( ) * 2 ) ;
mCameras . reserve ( parser . mCameraLibrary . size ( ) ) ;
mLights . reserve ( parser . mLightLibrary . size ( ) ) ;
2008-12-04 17:06:26 +00:00
// create the materials first, for the meshes to find
BuildMaterials ( parser , pScene ) ;
2008-11-12 17:07:44 +00:00
// build the node hierarchy from it
pScene - > mRootNode = BuildHierarchy ( parser , parser . mRootNode ) ;
2009-02-08 22:55:51 +00:00
// ... then fill the materials with the now adjusted settings
FillMaterials ( parser , pScene ) ;
2013-05-23 00:15:14 +00:00
// Apply unitsize scale calculation
pScene - > mRootNode - > mTransformation * = aiMatrix4x4 ( parser . mUnitSize , 0 , 0 , 0 ,
0 , parser . mUnitSize , 0 , 0 ,
0 , 0 , parser . mUnitSize , 0 ,
0 , 0 , 0 , 1 ) ;
2013-07-27 01:34:48 +00:00
if ( ! ignoreUpDirection ) {
2013-05-23 00:15:14 +00:00
// Convert to Y_UP, if different orientation
2013-07-27 01:34:48 +00:00
if ( parser . mUpDirection = = ColladaParser : : UP_X )
pScene - > mRootNode - > mTransformation * = aiMatrix4x4 (
0 , - 1 , 0 , 0 ,
1 , 0 , 0 , 0 ,
0 , 0 , 1 , 0 ,
0 , 0 , 0 , 1 ) ;
else if ( parser . mUpDirection = = ColladaParser : : UP_Z )
pScene - > mRootNode - > mTransformation * = aiMatrix4x4 (
1 , 0 , 0 , 0 ,
0 , 0 , 1 , 0 ,
0 , - 1 , 0 , 0 ,
0 , 0 , 0 , 1 ) ;
}
2008-11-25 17:58:11 +00:00
// store all meshes
StoreSceneMeshes ( pScene ) ;
2009-02-08 22:55:51 +00:00
// store all materials
StoreSceneMaterials ( pScene ) ;
// store all lights
StoreSceneLights ( pScene ) ;
// store all cameras
StoreSceneCameras ( pScene ) ;
2009-04-06 17:00:03 +00:00
2009-04-10 22:10:11 +00:00
// store all animations
2009-04-06 17:00:03 +00:00
StoreAnimations ( pScene , parser ) ;
2009-04-10 22:10:11 +00:00
// If no meshes have been loaded, it's probably just an animated skeleton.
if ( ! pScene - > mNumMeshes ) {
2012-06-21 15:24:50 +00:00
if ( ! noSkeletonMesh ) {
SkeletonMeshBuilder hero ( pScene ) ;
}
2009-04-10 22:10:11 +00:00
pScene - > mFlags | = AI_SCENE_FLAGS_INCOMPLETE ;
}
2008-11-12 17:07:44 +00:00
}
// ------------------------------------------------------------------------------------------------
// Recursively constructs a scene node for the given parser node and returns it.
2008-11-26 15:45:34 +00:00
aiNode * ColladaLoader : : BuildHierarchy ( const ColladaParser & pParser , const Collada : : Node * pNode )
2008-11-12 17:07:44 +00:00
{
// create a node for it
2009-02-08 22:55:51 +00:00
aiNode * node = new aiNode ( ) ;
2010-06-04 14:36:41 +00:00
// find a name for the new node. It's more complicated than you might think
node - > mName . Set ( FindNameForNode ( pNode ) ) ;
2010-01-10 10:38:52 +00:00
2008-11-12 17:07:44 +00:00
// calculate the transformation matrix for it
node - > mTransformation = pParser . CalculateResultTransform ( pNode - > mTransforms ) ;
2009-02-08 22:55:51 +00:00
// now resolve node instances
2010-09-13 14:40:25 +00:00
std : : vector < const Collada : : Node * > instances ;
2009-02-08 22:55:51 +00:00
ResolveNodeInstances ( pParser , pNode , instances ) ;
// add children. first the *real* ones
node - > mNumChildren = pNode - > mChildren . size ( ) + instances . size ( ) ;
2008-11-12 17:07:44 +00:00
node - > mChildren = new aiNode * [ node - > mNumChildren ] ;
2009-02-08 22:55:51 +00:00
2010-06-04 14:36:41 +00:00
for ( size_t a = 0 ; a < pNode - > mChildren . size ( ) ; a + + )
2008-11-12 17:07:44 +00:00
{
node - > mChildren [ a ] = BuildHierarchy ( pParser , pNode - > mChildren [ a ] ) ;
node - > mChildren [ a ] - > mParent = node ;
}
2009-02-08 22:55:51 +00:00
// ... and finally the resolved node instances
2010-06-04 14:36:41 +00:00
for ( size_t a = 0 ; a < instances . size ( ) ; a + + )
2009-02-08 22:55:51 +00:00
{
2010-06-04 14:36:41 +00:00
node - > mChildren [ pNode - > mChildren . size ( ) + a ] = BuildHierarchy ( pParser , instances [ a ] ) ;
node - > mChildren [ pNode - > mChildren . size ( ) + a ] - > mParent = node ;
2009-02-08 22:55:51 +00:00
}
2008-11-25 17:58:11 +00:00
// construct meshes
BuildMeshesForNode ( pParser , pNode , node ) ;
2009-02-08 22:55:51 +00:00
// construct cameras
BuildCamerasForNode ( pParser , pNode , node ) ;
// construct lights
BuildLightsForNode ( pParser , pNode , node ) ;
2008-11-12 17:07:44 +00:00
return node ;
}
2008-11-25 17:58:11 +00:00
2009-02-08 22:55:51 +00:00
// ------------------------------------------------------------------------------------------------
// Resolve node instances
void ColladaLoader : : ResolveNodeInstances ( const ColladaParser & pParser , const Collada : : Node * pNode ,
2010-09-13 14:40:25 +00:00
std : : vector < const Collada : : Node * > & resolved )
2009-02-08 22:55:51 +00:00
{
// reserve enough storage
resolved . reserve ( pNode - > mNodeInstances . size ( ) ) ;
// ... and iterate through all nodes to be instanced as children of pNode
for ( std : : vector < Collada : : NodeInstance > : : const_iterator it = pNode - > mNodeInstances . begin ( ) ,
end = pNode - > mNodeInstances . end ( ) ; it ! = end ; + + it )
{
// find the corresponding node in the library
2010-09-13 14:40:25 +00:00
const ColladaParser : : NodeLibrary : : const_iterator itt = pParser . mNodeLibrary . find ( ( * it ) . mNode ) ;
2012-03-20 21:11:05 +00:00
const Collada : : Node * nd = itt = = pParser . mNodeLibrary . end ( ) ? NULL : ( * itt ) . second ;
2010-09-11 19:44:06 +00:00
// FIX for http://sourceforge.net/tracker/?func=detail&aid=3054873&group_id=226462&atid=1067632
2010-09-13 14:40:25 +00:00
// need to check for both name and ID to catch all. To avoid breaking valid files,
// the workaround is only enabled when the first attempt to resolve the node has failed.
if ( ! nd ) {
2012-03-20 21:11:05 +00:00
nd = FindNode ( pParser . mRootNode , ( * it ) . mNode ) ;
2010-09-13 14:40:25 +00:00
}
2010-09-11 19:44:06 +00:00
if ( ! nd )
2009-02-08 22:55:51 +00:00
DefaultLogger : : get ( ) - > error ( " Collada: Unable to resolve reference to instanced node " + ( * it ) . mNode ) ;
else {
// attach this node to the list of children
2010-09-11 19:44:06 +00:00
resolved . push_back ( nd ) ;
2009-02-08 22:55:51 +00:00
}
}
}
// ------------------------------------------------------------------------------------------------
// Resolve UV channels
void ColladaLoader : : ApplyVertexToEffectSemanticMapping ( Collada : : Sampler & sampler ,
const Collada : : SemanticMappingTable & table )
{
std : : map < std : : string , Collada : : InputSemanticMapEntry > : : const_iterator it = table . mMap . find ( sampler . mUVChannel ) ;
if ( it ! = table . mMap . end ( ) ) {
if ( it - > second . mType ! = Collada : : IT_Texcoord )
DefaultLogger : : get ( ) - > error ( " Collada: Unexpected effect input mapping " ) ;
sampler . mUVId = it - > second . mSet ;
}
}
// ------------------------------------------------------------------------------------------------
// Builds lights for the given node and references them
void ColladaLoader : : BuildLightsForNode ( const ColladaParser & pParser , const Collada : : Node * pNode , aiNode * pTarget )
{
BOOST_FOREACH ( const Collada : : LightInstance & lid , pNode - > mLights )
{
// find the referred light
ColladaParser : : LightLibrary : : const_iterator srcLightIt = pParser . mLightLibrary . find ( lid . mLight ) ;
if ( srcLightIt = = pParser . mLightLibrary . end ( ) )
{
DefaultLogger : : get ( ) - > warn ( " Collada: Unable to find light for ID \" " + lid . mLight + " \" . Skipping. " ) ;
continue ;
}
const Collada : : Light * srcLight = & srcLightIt - > second ;
// now fill our ai data structure
aiLight * out = new aiLight ( ) ;
out - > mName = pTarget - > mName ;
out - > mType = ( aiLightSourceType ) srcLight - > mType ;
// collada lights point in -Z by default, rest is specified in node transform
out - > mDirection = aiVector3D ( 0.f , 0.f , - 1.f ) ;
out - > mAttenuationConstant = srcLight - > mAttConstant ;
out - > mAttenuationLinear = srcLight - > mAttLinear ;
out - > mAttenuationQuadratic = srcLight - > mAttQuadratic ;
// collada doesn't differenciate between these color types
out - > mColorDiffuse = out - > mColorSpecular = out - > mColorAmbient = srcLight - > mColor * srcLight - > mIntensity ;
// convert falloff angle and falloff exponent in our representation, if given
if ( out - > mType = = aiLightSource_SPOT ) {
out - > mAngleInnerCone = AI_DEG_TO_RAD ( srcLight - > mFalloffAngle ) ;
2013-03-21 19:00:33 +00:00
// ... some extension magic.
if ( srcLight - > mOuterAngle > = ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET * ( 1 - 1e-6 f ) )
2009-02-08 22:55:51 +00:00
{
2013-03-21 18:54:55 +00:00
// ... some deprecation magic.
2013-03-21 19:00:33 +00:00
if ( srcLight - > mPenumbraAngle > = ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET * ( 1 - 1e-6 f ) )
2009-02-08 22:55:51 +00:00
{
// Need to rely on falloff_exponent. I don't know how to interpret it, so I need to guess ....
// epsilon chosen to be 0.1
out - > mAngleOuterCone = AI_DEG_TO_RAD ( acos ( pow ( 0.1f , 1.f / srcLight - > mFalloffExponent ) ) +
srcLight - > mFalloffAngle ) ;
}
else {
out - > mAngleOuterCone = out - > mAngleInnerCone + AI_DEG_TO_RAD ( srcLight - > mPenumbraAngle ) ;
if ( out - > mAngleOuterCone < out - > mAngleInnerCone )
std : : swap ( out - > mAngleInnerCone , out - > mAngleOuterCone ) ;
}
}
else out - > mAngleOuterCone = AI_DEG_TO_RAD ( srcLight - > mOuterAngle ) ;
}
// add to light list
mLights . push_back ( out ) ;
}
}
// ------------------------------------------------------------------------------------------------
// Builds cameras for the given node and references them
void ColladaLoader : : BuildCamerasForNode ( const ColladaParser & pParser , const Collada : : Node * pNode , aiNode * pTarget )
{
BOOST_FOREACH ( const Collada : : CameraInstance & cid , pNode - > mCameras )
{
// find the referred light
ColladaParser : : CameraLibrary : : const_iterator srcCameraIt = pParser . mCameraLibrary . find ( cid . mCamera ) ;
if ( srcCameraIt = = pParser . mCameraLibrary . end ( ) )
{
DefaultLogger : : get ( ) - > warn ( " Collada: Unable to find camera for ID \" " + cid . mCamera + " \" . Skipping. " ) ;
continue ;
}
const Collada : : Camera * srcCamera = & srcCameraIt - > second ;
// orthographic cameras not yet supported in Assimp
if ( srcCamera - > mOrtho ) {
DefaultLogger : : get ( ) - > warn ( " Collada: Orthographic cameras are not supported. " ) ;
}
// now fill our ai data structure
aiCamera * out = new aiCamera ( ) ;
out - > mName = pTarget - > mName ;
// collada cameras point in -Z by default, rest is specified in node transform
out - > mLookAt = aiVector3D ( 0.f , 0.f , - 1.f ) ;
// near/far z is already ok
out - > mClipPlaneFar = srcCamera - > mZFar ;
out - > mClipPlaneNear = srcCamera - > mZNear ;
// ... but for the rest some values are optional
2013-03-21 18:54:55 +00:00
// and we need to compute the others in any combination.
2009-02-08 22:55:51 +00:00
if ( srcCamera - > mAspect ! = 10e10 f )
out - > mAspect = srcCamera - > mAspect ;
if ( srcCamera - > mHorFov ! = 10e10 f ) {
out - > mHorizontalFOV = srcCamera - > mHorFov ;
2010-04-13 15:45:18 +00:00
if ( srcCamera - > mVerFov ! = 10e10 f & & srcCamera - > mAspect = = 10e10 f ) {
out - > mAspect = tan ( AI_DEG_TO_RAD ( srcCamera - > mHorFov ) ) /
tan ( AI_DEG_TO_RAD ( srcCamera - > mVerFov ) ) ;
2009-02-08 22:55:51 +00:00
}
}
else if ( srcCamera - > mAspect ! = 10e10 f & & srcCamera - > mVerFov ! = 10e10 f ) {
2010-04-13 15:45:18 +00:00
out - > mHorizontalFOV = 2.0f * AI_RAD_TO_DEG ( atan ( srcCamera - > mAspect *
tan ( AI_DEG_TO_RAD ( srcCamera - > mVerFov ) * 0.5f ) ) ) ;
2009-02-08 22:55:51 +00:00
}
// Collada uses degrees, we use radians
out - > mHorizontalFOV = AI_DEG_TO_RAD ( out - > mHorizontalFOV ) ;
// add to camera list
mCameras . push_back ( out ) ;
}
}
2008-11-25 17:58:11 +00:00
// ------------------------------------------------------------------------------------------------
// Builds meshes for the given node and references them
2008-11-26 15:45:34 +00:00
void ColladaLoader : : BuildMeshesForNode ( const ColladaParser & pParser , const Collada : : Node * pNode , aiNode * pTarget )
2008-11-25 17:58:11 +00:00
{
// accumulated mesh references by this node
std : : vector < size_t > newMeshRefs ;
2009-02-11 20:56:05 +00:00
newMeshRefs . reserve ( pNode - > mMeshes . size ( ) ) ;
2008-11-25 17:58:11 +00:00
2009-01-18 00:52:20 +00:00
// add a mesh for each subgroup in each collada mesh
2008-11-27 15:54:35 +00:00
BOOST_FOREACH ( const Collada : : MeshInstance & mid , pNode - > mMeshes )
2008-11-25 17:58:11 +00:00
{
2009-03-25 21:10:28 +00:00
const Collada : : Mesh * srcMesh = NULL ;
const Collada : : Controller * srcController = NULL ;
2008-11-25 17:58:11 +00:00
// find the referred mesh
2009-03-25 21:10:28 +00:00
ColladaParser : : MeshLibrary : : const_iterator srcMeshIt = pParser . mMeshLibrary . find ( mid . mMeshOrController ) ;
2008-11-25 17:58:11 +00:00
if ( srcMeshIt = = pParser . mMeshLibrary . end ( ) )
{
2009-03-25 21:10:28 +00:00
// if not found in the mesh-library, it might also be a controller referring to a mesh
ColladaParser : : ControllerLibrary : : const_iterator srcContrIt = pParser . mControllerLibrary . find ( mid . mMeshOrController ) ;
if ( srcContrIt ! = pParser . mControllerLibrary . end ( ) )
{
srcController = & srcContrIt - > second ;
srcMeshIt = pParser . mMeshLibrary . find ( srcController - > mMeshId ) ;
if ( srcMeshIt ! = pParser . mMeshLibrary . end ( ) )
srcMesh = srcMeshIt - > second ;
}
if ( ! srcMesh )
{
DefaultLogger : : get ( ) - > warn ( boost : : str ( boost : : format ( " Collada: Unable to find geometry for ID \" %s \" . Skipping. " ) % mid . mMeshOrController ) ) ;
continue ;
}
} else
{
// ID found in the mesh library -> direct reference to an unskinned mesh
srcMesh = srcMeshIt - > second ;
2008-11-25 17:58:11 +00:00
}
2008-12-04 17:06:26 +00:00
// build a mesh for each of its subgroups
size_t vertexStart = 0 , faceStart = 0 ;
for ( size_t sm = 0 ; sm < srcMesh - > mSubMeshes . size ( ) ; + + sm )
2008-11-25 17:58:11 +00:00
{
2008-12-04 17:06:26 +00:00
const Collada : : SubMesh & submesh = srcMesh - > mSubMeshes [ sm ] ;
2009-02-08 22:55:51 +00:00
if ( submesh . mNumFaces = = 0 )
continue ;
2009-01-18 00:52:20 +00:00
2008-12-04 17:06:26 +00:00
// find material assigned to this submesh
2010-11-19 12:49:51 +00:00
std : : string meshMaterial ;
2009-02-08 22:55:51 +00:00
std : : map < std : : string , Collada : : SemanticMappingTable > : : const_iterator meshMatIt = mid . mMaterials . find ( submesh . mMaterial ) ;
2010-11-19 12:49:51 +00:00
const Collada : : SemanticMappingTable * table = NULL ;
2008-12-04 17:06:26 +00:00
if ( meshMatIt ! = mid . mMaterials . end ( ) )
2010-11-19 12:49:51 +00:00
{
2009-02-08 22:55:51 +00:00
table = & meshMatIt - > second ;
2010-11-19 12:49:51 +00:00
meshMaterial = table - > mMatName ;
}
else
{
2013-06-15 22:00:40 +00:00
DefaultLogger : : get ( ) - > warn ( boost : : str ( boost : : format ( " Collada: No material specified for subgroup <%s> in geometry <%s>. " ) % submesh . mMaterial % mid . mMeshOrController ) ) ;
2010-11-19 12:49:51 +00:00
if ( ! mid . mMaterials . empty ( ) )
meshMaterial = mid . mMaterials . begin ( ) - > second . mMatName ;
2009-02-08 22:55:51 +00:00
}
// OK ... here the *real* fun starts ... we have the vertex-input-to-effect-semantic-table
// given. The only mapping stuff which we do actually support is the UV channel.
std : : map < std : : string , size_t > : : const_iterator matIt = mMaterialIndexByName . find ( meshMaterial ) ;
unsigned int matIdx ;
if ( matIt ! = mMaterialIndexByName . end ( ) )
matIdx = matIt - > second ;
2008-12-04 17:06:26 +00:00
else
2009-02-08 22:55:51 +00:00
matIdx = 0 ;
if ( table & & ! table - > mMap . empty ( ) ) {
std : : pair < Collada : : Effect * , aiMaterial * > & mat = newMats [ matIdx ] ;
// Iterate through all texture channels assigned to the effect and
// check whether we have mapping information for it.
ApplyVertexToEffectSemanticMapping ( mat . first - > mTexDiffuse , * table ) ;
ApplyVertexToEffectSemanticMapping ( mat . first - > mTexAmbient , * table ) ;
ApplyVertexToEffectSemanticMapping ( mat . first - > mTexSpecular , * table ) ;
ApplyVertexToEffectSemanticMapping ( mat . first - > mTexEmissive , * table ) ;
ApplyVertexToEffectSemanticMapping ( mat . first - > mTexTransparent , * table ) ;
ApplyVertexToEffectSemanticMapping ( mat . first - > mTexBump , * table ) ;
}
2008-12-04 17:06:26 +00:00
// built lookup index of the Mesh-Submesh-Material combination
2009-03-25 21:10:28 +00:00
ColladaMeshIndex index ( mid . mMeshOrController , sm , meshMaterial ) ;
2008-12-04 17:06:26 +00:00
// if we already have the mesh at the library, just add its index to the node's array
std : : map < ColladaMeshIndex , size_t > : : const_iterator dstMeshIt = mMeshIndexByID . find ( index ) ;
2009-04-10 22:51:12 +00:00
if ( dstMeshIt ! = mMeshIndexByID . end ( ) ) {
2008-12-04 17:06:26 +00:00
newMeshRefs . push_back ( dstMeshIt - > second ) ;
2009-04-10 22:51:12 +00:00
}
else
2008-11-25 17:58:11 +00:00
{
2008-12-04 17:06:26 +00:00
// else we have to add the mesh to the collection and store its newly assigned index at the node
2009-03-27 20:43:22 +00:00
aiMesh * dstMesh = CreateMesh ( pParser , srcMesh , submesh , srcController , vertexStart , faceStart ) ;
2008-12-04 17:06:26 +00:00
// store the mesh, and store its new index in the node
newMeshRefs . push_back ( mMeshes . size ( ) ) ;
mMeshIndexByID [ index ] = mMeshes . size ( ) ;
mMeshes . push_back ( dstMesh ) ;
2009-03-27 20:43:22 +00:00
vertexStart + = dstMesh - > mNumVertices ; faceStart + = submesh . mNumFaces ;
2008-12-04 17:06:26 +00:00
// assign the material index
2009-02-08 22:55:51 +00:00
dstMesh - > mMaterialIndex = matIdx ;
2013-08-15 04:21:00 +00:00
if ( dstMesh - > mName . length = = 0 )
{
dstMesh - > mName = mid . mMeshOrController ;
}
2012-09-21 08:44:37 +00:00
}
2008-11-25 17:58:11 +00:00
}
}
// now place all mesh references we gathered in the target node
pTarget - > mNumMeshes = newMeshRefs . size ( ) ;
if ( newMeshRefs . size ( ) )
{
2008-11-30 20:32:53 +00:00
pTarget - > mMeshes = new unsigned int [ pTarget - > mNumMeshes ] ;
2008-11-25 17:58:11 +00:00
std : : copy ( newMeshRefs . begin ( ) , newMeshRefs . end ( ) , pTarget - > mMeshes ) ;
}
}
2009-03-27 20:43:22 +00:00
// ------------------------------------------------------------------------------------------------
// Creates a mesh for the given ColladaMesh face subset and returns the newly created mesh
aiMesh * ColladaLoader : : CreateMesh ( const ColladaParser & pParser , const Collada : : Mesh * pSrcMesh , const Collada : : SubMesh & pSubMesh ,
2009-04-23 14:13:20 +00:00
const Collada : : Controller * pSrcController , size_t pStartVertex , size_t pStartFace )
2009-03-27 20:43:22 +00:00
{
aiMesh * dstMesh = new aiMesh ;
2013-08-15 04:14:19 +00:00
dstMesh - > mName = pSrcMesh - > mName ;
2009-03-27 20:43:22 +00:00
// count the vertices addressed by its faces
const size_t numVertices = std : : accumulate ( pSrcMesh - > mFaceSize . begin ( ) + pStartFace ,
pSrcMesh - > mFaceSize . begin ( ) + pStartFace + pSubMesh . mNumFaces , 0 ) ;
// copy positions
dstMesh - > mNumVertices = numVertices ;
dstMesh - > mVertices = new aiVector3D [ numVertices ] ;
std : : copy ( pSrcMesh - > mPositions . begin ( ) + pStartVertex , pSrcMesh - > mPositions . begin ( ) +
pStartVertex + numVertices , dstMesh - > mVertices ) ;
2013-03-21 18:54:55 +00:00
// normals, if given. HACK: (thom) Due to the glorious Collada spec we never
2009-03-27 20:43:22 +00:00
// know if we have the same number of normals as there are positions. So we
// also ignore any vertex attribute if it has a different count
2009-06-02 20:03:08 +00:00
if ( pSrcMesh - > mNormals . size ( ) > = pStartVertex + numVertices )
2009-03-27 20:43:22 +00:00
{
dstMesh - > mNormals = new aiVector3D [ numVertices ] ;
std : : copy ( pSrcMesh - > mNormals . begin ( ) + pStartVertex , pSrcMesh - > mNormals . begin ( ) +
pStartVertex + numVertices , dstMesh - > mNormals ) ;
}
// tangents, if given.
2009-06-02 20:03:08 +00:00
if ( pSrcMesh - > mTangents . size ( ) > = pStartVertex + numVertices )
2009-03-27 20:43:22 +00:00
{
dstMesh - > mTangents = new aiVector3D [ numVertices ] ;
std : : copy ( pSrcMesh - > mTangents . begin ( ) + pStartVertex , pSrcMesh - > mTangents . begin ( ) +
pStartVertex + numVertices , dstMesh - > mTangents ) ;
}
// bitangents, if given.
2009-06-02 20:03:08 +00:00
if ( pSrcMesh - > mBitangents . size ( ) > = pStartVertex + numVertices )
2009-03-27 20:43:22 +00:00
{
dstMesh - > mBitangents = new aiVector3D [ numVertices ] ;
std : : copy ( pSrcMesh - > mBitangents . begin ( ) + pStartVertex , pSrcMesh - > mBitangents . begin ( ) +
pStartVertex + numVertices , dstMesh - > mBitangents ) ;
}
// same for texturecoords, as many as we have
2009-04-23 14:13:20 +00:00
// empty slots are not allowed, need to pack and adjust UV indexes accordingly
for ( size_t a = 0 , real = 0 ; a < AI_MAX_NUMBER_OF_TEXTURECOORDS ; a + + )
2009-03-27 20:43:22 +00:00
{
2009-06-02 20:03:08 +00:00
if ( pSrcMesh - > mTexCoords [ a ] . size ( ) > = pStartVertex + numVertices )
2009-03-27 20:43:22 +00:00
{
2009-04-23 14:13:20 +00:00
dstMesh - > mTextureCoords [ real ] = new aiVector3D [ numVertices ] ;
2009-03-27 20:43:22 +00:00
for ( size_t b = 0 ; b < numVertices ; + + b )
2009-04-23 14:13:20 +00:00
dstMesh - > mTextureCoords [ real ] [ b ] = pSrcMesh - > mTexCoords [ a ] [ pStartVertex + b ] ;
2009-03-27 20:43:22 +00:00
2009-04-23 14:13:20 +00:00
dstMesh - > mNumUVComponents [ real ] = pSrcMesh - > mNumUVComponents [ a ] ;
+ + real ;
2009-03-27 20:43:22 +00:00
}
}
2009-04-23 14:13:20 +00:00
// same for vertex colors, as many as we have. again the same packing to avoid empty slots
for ( size_t a = 0 , real = 0 ; a < AI_MAX_NUMBER_OF_COLOR_SETS ; a + + )
2009-03-27 20:43:22 +00:00
{
2009-06-02 20:03:08 +00:00
if ( pSrcMesh - > mColors [ a ] . size ( ) > = pStartVertex + numVertices )
2009-03-27 20:43:22 +00:00
{
2009-04-23 14:13:20 +00:00
dstMesh - > mColors [ real ] = new aiColor4D [ numVertices ] ;
std : : copy ( pSrcMesh - > mColors [ a ] . begin ( ) + pStartVertex , pSrcMesh - > mColors [ a ] . begin ( ) + pStartVertex + numVertices , dstMesh - > mColors [ real ] ) ;
+ + real ;
2009-03-27 20:43:22 +00:00
}
}
// create faces. Due to the fact that each face uses unique vertices, we can simply count up on each vertex
size_t vertex = 0 ;
dstMesh - > mNumFaces = pSubMesh . mNumFaces ;
dstMesh - > mFaces = new aiFace [ dstMesh - > mNumFaces ] ;
for ( size_t a = 0 ; a < dstMesh - > mNumFaces ; + + a )
{
size_t s = pSrcMesh - > mFaceSize [ pStartFace + a ] ;
aiFace & face = dstMesh - > mFaces [ a ] ;
face . mNumIndices = s ;
face . mIndices = new unsigned int [ s ] ;
for ( size_t b = 0 ; b < s ; + + b )
face . mIndices [ b ] = vertex + + ;
}
// create bones if given
if ( pSrcController )
{
// refuse if the vertex count does not match
// if( pSrcController->mWeightCounts.size() != dstMesh->mNumVertices)
2010-03-18 17:00:12 +00:00
// throw DeadlyImportError( "Joint Controller vertex count does not match mesh vertex count");
2009-03-27 20:43:22 +00:00
// resolve references - joint names
const Collada : : Accessor & jointNamesAcc = pParser . ResolveLibraryReference ( pParser . mAccessorLibrary , pSrcController - > mJointNameSource ) ;
const Collada : : Data & jointNames = pParser . ResolveLibraryReference ( pParser . mDataLibrary , jointNamesAcc . mSource ) ;
// joint offset matrices
const Collada : : Accessor & jointMatrixAcc = pParser . ResolveLibraryReference ( pParser . mAccessorLibrary , pSrcController - > mJointOffsetMatrixSource ) ;
const Collada : : Data & jointMatrices = pParser . ResolveLibraryReference ( pParser . mDataLibrary , jointMatrixAcc . mSource ) ;
// joint vertex_weight name list - should refer to the same list as the joint names above. If not, report and reconsider
const Collada : : Accessor & weightNamesAcc = pParser . ResolveLibraryReference ( pParser . mAccessorLibrary , pSrcController - > mWeightInputJoints . mAccessor ) ;
if ( & weightNamesAcc ! = & jointNamesAcc )
2010-03-18 17:00:12 +00:00
throw DeadlyImportError ( " Temporary implementational lazyness. If you read this, please report to the author. " ) ;
2009-03-27 20:43:22 +00:00
// vertex weights
const Collada : : Accessor & weightsAcc = pParser . ResolveLibraryReference ( pParser . mAccessorLibrary , pSrcController - > mWeightInputWeights . mAccessor ) ;
const Collada : : Data & weights = pParser . ResolveLibraryReference ( pParser . mDataLibrary , weightsAcc . mSource ) ;
if ( ! jointNames . mIsStringArray | | jointMatrices . mIsStringArray | | weights . mIsStringArray )
2010-03-18 17:00:12 +00:00
throw DeadlyImportError ( " Data type mismatch while resolving mesh joints " ) ;
2009-03-27 20:43:22 +00:00
// sanity check: we rely on the vertex weights always coming as pairs of BoneIndex-WeightIndex
if ( pSrcController - > mWeightInputJoints . mOffset ! = 0 | | pSrcController - > mWeightInputWeights . mOffset ! = 1 )
2013-06-15 22:00:40 +00:00
throw DeadlyImportError ( " Unsupported vertex_weight addressing scheme. " ) ;
2009-03-27 20:43:22 +00:00
// create containers to collect the weights for each bone
size_t numBones = jointNames . mStrings . size ( ) ;
std : : vector < std : : vector < aiVertexWeight > > dstBones ( numBones ) ;
// build a temporary array of pointers to the start of each vertex's weights
typedef std : : vector < std : : pair < size_t , size_t > > IndexPairVector ;
2012-02-03 18:05:38 +00:00
std : : vector < IndexPairVector : : const_iterator > weightStartPerVertex ;
weightStartPerVertex . resize ( pSrcController - > mWeightCounts . size ( ) , pSrcController - > mWeights . end ( ) ) ;
2009-03-27 20:43:22 +00:00
IndexPairVector : : const_iterator pit = pSrcController - > mWeights . begin ( ) ;
for ( size_t a = 0 ; a < pSrcController - > mWeightCounts . size ( ) ; + + a )
{
weightStartPerVertex [ a ] = pit ;
pit + = pSrcController - > mWeightCounts [ a ] ;
}
// now for each vertex put the corresponding vertex weights into each bone's weight collection
for ( size_t a = pStartVertex ; a < pStartVertex + numVertices ; + + a )
{
// which position index was responsible for this vertex? that's also the index by which
// the controller assigns the vertex weights
size_t orgIndex = pSrcMesh - > mFacePosIndices [ a ] ;
// find the vertex weights for this vertex
IndexPairVector : : const_iterator iit = weightStartPerVertex [ orgIndex ] ;
size_t pairCount = pSrcController - > mWeightCounts [ orgIndex ] ;
for ( size_t b = 0 ; b < pairCount ; + + b , + + iit )
{
size_t jointIndex = iit - > first ;
size_t vertexIndex = iit - > second ;
2009-04-06 17:00:03 +00:00
float weight = ReadFloat ( weightsAcc , weights , vertexIndex , 0 ) ;
2010-11-19 14:06:32 +00:00
// one day I gonna kill that XSI Collada exporter
if ( weight > 0.0f )
{
aiVertexWeight w ;
w . mVertexId = a - pStartVertex ;
w . mWeight = weight ;
dstBones [ jointIndex ] . push_back ( w ) ;
}
2009-03-27 20:43:22 +00:00
}
}
// count the number of bones which influence vertices of the current submesh
size_t numRemainingBones = 0 ;
for ( std : : vector < std : : vector < aiVertexWeight > > : : const_iterator it = dstBones . begin ( ) ; it ! = dstBones . end ( ) ; + + it )
if ( it - > size ( ) > 0 )
numRemainingBones + + ;
// create bone array and copy bone weights one by one
dstMesh - > mNumBones = numRemainingBones ;
dstMesh - > mBones = new aiBone * [ numRemainingBones ] ;
size_t boneCount = 0 ;
for ( size_t a = 0 ; a < numBones ; + + a )
{
// omit bones without weights
if ( dstBones [ a ] . size ( ) = = 0 )
continue ;
// create bone with its weights
aiBone * bone = new aiBone ;
2009-04-06 17:00:03 +00:00
bone - > mName = ReadString ( jointNamesAcc , jointNames , a ) ;
bone - > mOffsetMatrix . a1 = ReadFloat ( jointMatrixAcc , jointMatrices , a , 0 ) ;
bone - > mOffsetMatrix . a2 = ReadFloat ( jointMatrixAcc , jointMatrices , a , 1 ) ;
bone - > mOffsetMatrix . a3 = ReadFloat ( jointMatrixAcc , jointMatrices , a , 2 ) ;
bone - > mOffsetMatrix . a4 = ReadFloat ( jointMatrixAcc , jointMatrices , a , 3 ) ;
bone - > mOffsetMatrix . b1 = ReadFloat ( jointMatrixAcc , jointMatrices , a , 4 ) ;
bone - > mOffsetMatrix . b2 = ReadFloat ( jointMatrixAcc , jointMatrices , a , 5 ) ;
bone - > mOffsetMatrix . b3 = ReadFloat ( jointMatrixAcc , jointMatrices , a , 6 ) ;
bone - > mOffsetMatrix . b4 = ReadFloat ( jointMatrixAcc , jointMatrices , a , 7 ) ;
bone - > mOffsetMatrix . c1 = ReadFloat ( jointMatrixAcc , jointMatrices , a , 8 ) ;
bone - > mOffsetMatrix . c2 = ReadFloat ( jointMatrixAcc , jointMatrices , a , 9 ) ;
bone - > mOffsetMatrix . c3 = ReadFloat ( jointMatrixAcc , jointMatrices , a , 10 ) ;
bone - > mOffsetMatrix . c4 = ReadFloat ( jointMatrixAcc , jointMatrices , a , 11 ) ;
2009-03-27 20:43:22 +00:00
bone - > mNumWeights = dstBones [ a ] . size ( ) ;
bone - > mWeights = new aiVertexWeight [ bone - > mNumWeights ] ;
std : : copy ( dstBones [ a ] . begin ( ) , dstBones [ a ] . end ( ) , bone - > mWeights ) ;
2010-11-19 14:06:32 +00:00
// apply bind shape matrix to offset matrix
aiMatrix4x4 bindShapeMatrix ;
bindShapeMatrix . a1 = pSrcController - > mBindShapeMatrix [ 0 ] ;
bindShapeMatrix . a2 = pSrcController - > mBindShapeMatrix [ 1 ] ;
bindShapeMatrix . a3 = pSrcController - > mBindShapeMatrix [ 2 ] ;
bindShapeMatrix . a4 = pSrcController - > mBindShapeMatrix [ 3 ] ;
bindShapeMatrix . b1 = pSrcController - > mBindShapeMatrix [ 4 ] ;
bindShapeMatrix . b2 = pSrcController - > mBindShapeMatrix [ 5 ] ;
bindShapeMatrix . b3 = pSrcController - > mBindShapeMatrix [ 6 ] ;
bindShapeMatrix . b4 = pSrcController - > mBindShapeMatrix [ 7 ] ;
bindShapeMatrix . c1 = pSrcController - > mBindShapeMatrix [ 8 ] ;
bindShapeMatrix . c2 = pSrcController - > mBindShapeMatrix [ 9 ] ;
bindShapeMatrix . c3 = pSrcController - > mBindShapeMatrix [ 10 ] ;
bindShapeMatrix . c4 = pSrcController - > mBindShapeMatrix [ 11 ] ;
bindShapeMatrix . d1 = pSrcController - > mBindShapeMatrix [ 12 ] ;
bindShapeMatrix . d2 = pSrcController - > mBindShapeMatrix [ 13 ] ;
bindShapeMatrix . d3 = pSrcController - > mBindShapeMatrix [ 14 ] ;
bindShapeMatrix . d4 = pSrcController - > mBindShapeMatrix [ 15 ] ;
bone - > mOffsetMatrix * = bindShapeMatrix ;
// HACK: (thom) Some exporters address the bone nodes by SID, others address them by ID or even name.
// Therefore I added a little name replacement here: I search for the bone's node by either name, ID or SID,
// and replace the bone's name by the node's name so that the user can use the standard
// find-by-name method to associate nodes with bones.
const Collada : : Node * bnode = FindNode ( pParser . mRootNode , bone - > mName . data ) ;
if ( ! bnode )
bnode = FindNodeBySID ( pParser . mRootNode , bone - > mName . data ) ;
// assign the name that we would have assigned for the source node
if ( bnode )
bone - > mName . Set ( FindNameForNode ( bnode ) ) ;
else
DefaultLogger : : get ( ) - > warn ( boost : : str ( boost : : format ( " ColladaLoader::CreateMesh(): could not find corresponding node for joint \" %s \" . " ) % bone - > mName . data ) ) ;
// and insert bone
2009-03-27 20:43:22 +00:00
dstMesh - > mBones [ boneCount + + ] = bone ;
}
}
return dstMesh ;
}
2008-11-25 17:58:11 +00:00
// ------------------------------------------------------------------------------------------------
// Stores all meshes in the given scene
void ColladaLoader : : StoreSceneMeshes ( aiScene * pScene )
{
pScene - > mNumMeshes = mMeshes . size ( ) ;
if ( mMeshes . size ( ) > 0 )
{
pScene - > mMeshes = new aiMesh * [ mMeshes . size ( ) ] ;
std : : copy ( mMeshes . begin ( ) , mMeshes . end ( ) , pScene - > mMeshes ) ;
2009-04-02 15:16:01 +00:00
mMeshes . clear ( ) ;
2008-11-25 17:58:11 +00:00
}
}
2008-12-04 17:06:26 +00:00
2009-02-08 22:55:51 +00:00
// ------------------------------------------------------------------------------------------------
// Stores all cameras in the given scene
void ColladaLoader : : StoreSceneCameras ( aiScene * pScene )
{
pScene - > mNumCameras = mCameras . size ( ) ;
if ( mCameras . size ( ) > 0 )
{
pScene - > mCameras = new aiCamera * [ mCameras . size ( ) ] ;
std : : copy ( mCameras . begin ( ) , mCameras . end ( ) , pScene - > mCameras ) ;
2009-04-02 15:16:01 +00:00
mCameras . clear ( ) ;
2009-02-08 22:55:51 +00:00
}
}
// ------------------------------------------------------------------------------------------------
// Stores all lights in the given scene
void ColladaLoader : : StoreSceneLights ( aiScene * pScene )
{
pScene - > mNumLights = mLights . size ( ) ;
if ( mLights . size ( ) > 0 )
{
pScene - > mLights = new aiLight * [ mLights . size ( ) ] ;
std : : copy ( mLights . begin ( ) , mLights . end ( ) , pScene - > mLights ) ;
2009-04-02 15:16:01 +00:00
mLights . clear ( ) ;
2009-02-08 22:55:51 +00:00
}
2009-02-11 20:56:05 +00:00
}
// ------------------------------------------------------------------------------------------------
// Stores all textures in the given scene
void ColladaLoader : : StoreSceneTextures ( aiScene * pScene )
{
pScene - > mNumTextures = mTextures . size ( ) ;
if ( mTextures . size ( ) > 0 )
{
pScene - > mTextures = new aiTexture * [ mTextures . size ( ) ] ;
std : : copy ( mTextures . begin ( ) , mTextures . end ( ) , pScene - > mTextures ) ;
2009-04-02 15:16:01 +00:00
mTextures . clear ( ) ;
2009-02-11 20:56:05 +00:00
}
2009-02-08 22:55:51 +00:00
}
// ------------------------------------------------------------------------------------------------
// Stores all materials in the given scene
void ColladaLoader : : StoreSceneMaterials ( aiScene * pScene )
{
pScene - > mNumMaterials = newMats . size ( ) ;
2009-02-11 20:56:05 +00:00
2009-04-02 15:16:01 +00:00
if ( newMats . size ( ) > 0 ) {
pScene - > mMaterials = new aiMaterial * [ newMats . size ( ) ] ;
for ( unsigned int i = 0 ; i < newMats . size ( ) ; + + i )
pScene - > mMaterials [ i ] = newMats [ i ] . second ;
newMats . clear ( ) ;
}
2009-02-08 22:55:51 +00:00
}
2009-04-06 17:00:03 +00:00
// ------------------------------------------------------------------------------------------------
// Stores all animations
void ColladaLoader : : StoreAnimations ( aiScene * pScene , const ColladaParser & pParser )
{
// recursivly collect all animations from the collada scene
StoreAnimations ( pScene , pParser , & pParser . mAnims , " " ) ;
2010-09-04 15:36:38 +00:00
// catch special case: many animations with the same length, each affecting only a single node.
// we need to unite all those single-node-anims to a proper combined animation
for ( size_t a = 0 ; a < mAnims . size ( ) ; + + a )
{
aiAnimation * templateAnim = mAnims [ a ] ;
if ( templateAnim - > mNumChannels = = 1 )
{
// search for other single-channel-anims with the same duration
std : : vector < size_t > collectedAnimIndices ;
for ( size_t b = a + 1 ; b < mAnims . size ( ) ; + + b )
{
aiAnimation * other = mAnims [ b ] ;
if ( other - > mNumChannels = = 1 & & other - > mDuration = = templateAnim - > mDuration & & other - > mTicksPerSecond = = templateAnim - > mTicksPerSecond )
collectedAnimIndices . push_back ( b ) ;
}
// if there are other animations which fit the template anim, combine all channels into a single anim
if ( ! collectedAnimIndices . empty ( ) )
{
aiAnimation * combinedAnim = new aiAnimation ( ) ;
combinedAnim - > mName = aiString ( std : : string ( " combinedAnim_ " ) + char ( ' 0 ' + a ) ) ;
combinedAnim - > mDuration = templateAnim - > mDuration ;
combinedAnim - > mTicksPerSecond = templateAnim - > mTicksPerSecond ;
combinedAnim - > mNumChannels = collectedAnimIndices . size ( ) + 1 ;
combinedAnim - > mChannels = new aiNodeAnim * [ combinedAnim - > mNumChannels ] ;
// add the template anim as first channel by moving its aiNodeAnim to the combined animation
combinedAnim - > mChannels [ 0 ] = templateAnim - > mChannels [ 0 ] ;
templateAnim - > mChannels [ 0 ] = NULL ;
delete templateAnim ;
// combined animation replaces template animation in the anim array
mAnims [ a ] = combinedAnim ;
// move the memory of all other anims to the combined anim and erase them from the source anims
for ( size_t b = 0 ; b < collectedAnimIndices . size ( ) ; + + b )
{
aiAnimation * srcAnimation = mAnims [ collectedAnimIndices [ b ] ] ;
combinedAnim - > mChannels [ 1 + b ] = srcAnimation - > mChannels [ 0 ] ;
srcAnimation - > mChannels [ 0 ] = NULL ;
delete srcAnimation ;
}
// in a second go, delete all the single-channel-anims that we've stripped from their channels
// back to front to preserve indices - you know, removing an element from a vector moves all elements behind the removed one
while ( ! collectedAnimIndices . empty ( ) )
{
mAnims . erase ( mAnims . begin ( ) + collectedAnimIndices . back ( ) ) ;
collectedAnimIndices . pop_back ( ) ;
}
}
}
}
2009-04-06 17:00:03 +00:00
// now store all anims in the scene
if ( ! mAnims . empty ( ) )
{
pScene - > mNumAnimations = mAnims . size ( ) ;
pScene - > mAnimations = new aiAnimation * [ mAnims . size ( ) ] ;
std : : copy ( mAnims . begin ( ) , mAnims . end ( ) , pScene - > mAnimations ) ;
}
2014-06-13 08:56:10 +00:00
mAnims . clear ( ) ;
2009-04-06 17:00:03 +00:00
}
// ------------------------------------------------------------------------------------------------
// Constructs the animations for the given source anim
void ColladaLoader : : StoreAnimations ( aiScene * pScene , const ColladaParser & pParser , const Collada : : Animation * pSrcAnim , const std : : string pPrefix )
{
std : : string animName = pPrefix . empty ( ) ? pSrcAnim - > mName : pPrefix + " _ " + pSrcAnim - > mName ;
// create nested animations, if given
for ( std : : vector < Collada : : Animation * > : : const_iterator it = pSrcAnim - > mSubAnims . begin ( ) ; it ! = pSrcAnim - > mSubAnims . end ( ) ; + + it )
StoreAnimations ( pScene , pParser , * it , animName ) ;
// create animation channels, if any
if ( ! pSrcAnim - > mChannels . empty ( ) )
CreateAnimation ( pScene , pParser , pSrcAnim , animName ) ;
}
// ------------------------------------------------------------------------------------------------
// Constructs the animation for the given source anim
void ColladaLoader : : CreateAnimation ( aiScene * pScene , const ColladaParser & pParser , const Collada : : Animation * pSrcAnim , const std : : string & pName )
{
// collect a list of animatable nodes
std : : vector < const aiNode * > nodes ;
CollectNodes ( pScene - > mRootNode , nodes ) ;
std : : vector < aiNodeAnim * > anims ;
for ( std : : vector < const aiNode * > : : const_iterator nit = nodes . begin ( ) ; nit ! = nodes . end ( ) ; + + nit )
{
// find all the collada anim channels which refer to the current node
2009-08-18 16:17:27 +00:00
std : : vector < Collada : : ChannelEntry > entries ;
2009-04-06 17:00:03 +00:00
std : : string nodeName = ( * nit ) - > mName . data ;
// find the collada node corresponding to the aiNode
const Collada : : Node * srcNode = FindNode ( pParser . mRootNode , nodeName ) ;
// ai_assert( srcNode != NULL);
if ( ! srcNode )
continue ;
// now check all channels if they affect the current node
for ( std : : vector < Collada : : AnimationChannel > : : const_iterator cit = pSrcAnim - > mChannels . begin ( ) ;
cit ! = pSrcAnim - > mChannels . end ( ) ; + + cit )
{
const Collada : : AnimationChannel & srcChannel = * cit ;
2009-08-18 16:17:27 +00:00
Collada : : ChannelEntry entry ;
2009-04-06 17:00:03 +00:00
2012-05-05 07:38:14 +00:00
// we expect the animation target to be of type "nodeName/transformID.subElement". Ignore all others
2009-04-06 17:00:03 +00:00
// find the slash that separates the node name - there should be only one
std : : string : : size_type slashPos = srcChannel . mTarget . find ( ' / ' ) ;
if ( slashPos = = std : : string : : npos )
continue ;
if ( srcChannel . mTarget . find ( ' / ' , slashPos + 1 ) ! = std : : string : : npos )
continue ;
2009-08-01 13:57:29 +00:00
std : : string targetID = srcChannel . mTarget . substr ( 0 , slashPos ) ;
if ( targetID ! = srcNode - > mID )
2009-04-06 17:00:03 +00:00
continue ;
// find the dot that separates the transformID - there should be only one or zero
std : : string : : size_type dotPos = srcChannel . mTarget . find ( ' . ' ) ;
if ( dotPos ! = std : : string : : npos )
{
if ( srcChannel . mTarget . find ( ' . ' , dotPos + 1 ) ! = std : : string : : npos )
continue ;
entry . mTransformId = srcChannel . mTarget . substr ( slashPos + 1 , dotPos - slashPos - 1 ) ;
std : : string subElement = srcChannel . mTarget . substr ( dotPos + 1 ) ;
if ( subElement = = " ANGLE " )
entry . mSubElement = 3 ; // last number in an Axis-Angle-Transform is the angle
2009-08-01 13:57:29 +00:00
else if ( subElement = = " X " )
entry . mSubElement = 0 ;
else if ( subElement = = " Y " )
entry . mSubElement = 1 ;
else if ( subElement = = " Z " )
entry . mSubElement = 2 ;
2009-04-06 17:00:03 +00:00
else
2013-06-15 22:00:40 +00:00
DefaultLogger : : get ( ) - > warn ( boost : : str ( boost : : format ( " Unknown anim subelement <%s>. Ignoring " ) % subElement ) ) ;
2009-04-06 17:00:03 +00:00
} else
{
// no subelement following, transformId is remaining string
entry . mTransformId = srcChannel . mTarget . substr ( slashPos + 1 ) ;
}
// determine which transform step is affected by this channel
2011-04-22 21:29:18 +00:00
entry . mTransformIndex = SIZE_MAX ;
2009-04-06 17:00:03 +00:00
for ( size_t a = 0 ; a < srcNode - > mTransforms . size ( ) ; + + a )
if ( srcNode - > mTransforms [ a ] . mID = = entry . mTransformId )
entry . mTransformIndex = a ;
2011-04-22 21:29:18 +00:00
if ( entry . mTransformIndex = = SIZE_MAX ) {
2009-04-06 17:00:03 +00:00
continue ;
2011-04-22 21:29:18 +00:00
}
2009-04-06 17:00:03 +00:00
entry . mChannel = & ( * cit ) ;
entries . push_back ( entry ) ;
}
// if there's no channel affecting the current node, we skip it
if ( entries . empty ( ) )
continue ;
// resolve the data pointers for all anim channels. Find the minimum time while we're at it
2009-04-18 18:03:54 +00:00
float startTime = 1e20 f , endTime = - 1e20 f ;
2009-08-18 16:17:27 +00:00
for ( std : : vector < Collada : : ChannelEntry > : : iterator it = entries . begin ( ) ; it ! = entries . end ( ) ; + + it )
2009-04-06 17:00:03 +00:00
{
2009-08-18 16:17:27 +00:00
Collada : : ChannelEntry & e = * it ;
2009-04-06 17:00:03 +00:00
e . mTimeAccessor = & pParser . ResolveLibraryReference ( pParser . mAccessorLibrary , e . mChannel - > mSourceTimes ) ;
e . mTimeData = & pParser . ResolveLibraryReference ( pParser . mDataLibrary , e . mTimeAccessor - > mSource ) ;
e . mValueAccessor = & pParser . ResolveLibraryReference ( pParser . mAccessorLibrary , e . mChannel - > mSourceValues ) ;
e . mValueData = & pParser . ResolveLibraryReference ( pParser . mDataLibrary , e . mValueAccessor - > mSource ) ;
// time count and value count must match
if ( e . mTimeAccessor - > mCount ! = e . mValueAccessor - > mCount )
2010-03-18 17:00:12 +00:00
throw DeadlyImportError ( boost : : str ( boost : : format ( " Time count / value count mismatch in animation channel \" %s \" . " ) % e . mChannel - > mTarget ) ) ;
2009-04-06 17:00:03 +00:00
2012-05-05 07:38:14 +00:00
if ( e . mTimeAccessor - > mCount > 0 )
{
// find bounding times
startTime = std : : min ( startTime , ReadFloat ( * e . mTimeAccessor , * e . mTimeData , 0 , 0 ) ) ;
endTime = std : : max ( endTime , ReadFloat ( * e . mTimeAccessor , * e . mTimeData , e . mTimeAccessor - > mCount - 1 , 0 ) ) ;
}
2009-04-06 17:00:03 +00:00
}
2012-05-05 07:38:14 +00:00
std : : vector < aiMatrix4x4 > resultTrafos ;
if ( ! entries . empty ( ) & & entries . front ( ) . mTimeAccessor - > mCount > 0 )
{
// create a local transformation chain of the node's transforms
std : : vector < Collada : : Transform > transforms = srcNode - > mTransforms ;
// now for every unique point in time, find or interpolate the key values for that time
// and apply them to the transform chain. Then the node's present transformation can be calculated.
float time = startTime ;
while ( 1 )
{
for ( std : : vector < Collada : : ChannelEntry > : : iterator it = entries . begin ( ) ; it ! = entries . end ( ) ; + + it )
{
Collada : : ChannelEntry & e = * it ;
// find the keyframe behind the current point in time
size_t pos = 0 ;
float postTime = 0.f ;
while ( 1 )
{
if ( pos > = e . mTimeAccessor - > mCount )
break ;
postTime = ReadFloat ( * e . mTimeAccessor , * e . mTimeData , pos , 0 ) ;
if ( postTime > = time )
break ;
+ + pos ;
}
pos = std : : min ( pos , e . mTimeAccessor - > mCount - 1 ) ;
// read values from there
float temp [ 16 ] ;
for ( size_t c = 0 ; c < e . mValueAccessor - > mSize ; + + c )
temp [ c ] = ReadFloat ( * e . mValueAccessor , * e . mValueData , pos , c ) ;
// if not exactly at the key time, interpolate with previous value set
if ( postTime > time & & pos > 0 )
{
float preTime = ReadFloat ( * e . mTimeAccessor , * e . mTimeData , pos - 1 , 0 ) ;
float factor = ( time - postTime ) / ( preTime - postTime ) ;
for ( size_t c = 0 ; c < e . mValueAccessor - > mSize ; + + c )
{
float v = ReadFloat ( * e . mValueAccessor , * e . mValueData , pos - 1 , c ) ;
temp [ c ] + = ( v - temp [ c ] ) * factor ;
}
}
// Apply values to current transformation
std : : copy ( temp , temp + e . mValueAccessor - > mSize , transforms [ e . mTransformIndex ] . f + e . mSubElement ) ;
}
// Calculate resulting transformation
aiMatrix4x4 mat = pParser . CalculateResultTransform ( transforms ) ;
// out of lazyness: we store the time in matrix.d4
mat . d4 = time ;
resultTrafos . push_back ( mat ) ;
// find next point in time to evaluate. That's the closest frame larger than the current in any channel
float nextTime = 1e20 f ;
for ( std : : vector < Collada : : ChannelEntry > : : iterator it = entries . begin ( ) ; it ! = entries . end ( ) ; + + it )
{
Collada : : ChannelEntry & e = * it ;
// find the next time value larger than the current
size_t pos = 0 ;
while ( pos < e . mTimeAccessor - > mCount )
{
float t = ReadFloat ( * e . mTimeAccessor , * e . mTimeData , pos , 0 ) ;
if ( t > time )
{
nextTime = std : : min ( nextTime , t ) ;
break ;
}
+ + pos ;
}
}
// no more keys on any channel after the current time -> we're done
if ( nextTime > 1e19 )
break ;
// else construct next keyframe at this following time point
time = nextTime ;
}
}
// there should be some keyframes, but we aren't that fixated on valid input data
// ai_assert( resultTrafos.size() > 0);
2009-04-06 17:00:03 +00:00
// build an animation channel for the given node out of these trafo keys
2012-05-05 07:38:14 +00:00
if ( ! resultTrafos . empty ( ) )
{
aiNodeAnim * dstAnim = new aiNodeAnim ;
dstAnim - > mNodeName = nodeName ;
dstAnim - > mNumPositionKeys = resultTrafos . size ( ) ;
dstAnim - > mNumRotationKeys = resultTrafos . size ( ) ;
dstAnim - > mNumScalingKeys = resultTrafos . size ( ) ;
dstAnim - > mPositionKeys = new aiVectorKey [ resultTrafos . size ( ) ] ;
dstAnim - > mRotationKeys = new aiQuatKey [ resultTrafos . size ( ) ] ;
dstAnim - > mScalingKeys = new aiVectorKey [ resultTrafos . size ( ) ] ;
for ( size_t a = 0 ; a < resultTrafos . size ( ) ; + + a )
{
aiMatrix4x4 mat = resultTrafos [ a ] ;
double time = double ( mat . d4 ) ; // remember? time is stored in mat.d4
mat . d4 = 1.0f ;
dstAnim - > mPositionKeys [ a ] . mTime = time ;
dstAnim - > mRotationKeys [ a ] . mTime = time ;
dstAnim - > mScalingKeys [ a ] . mTime = time ;
mat . Decompose ( dstAnim - > mScalingKeys [ a ] . mValue , dstAnim - > mRotationKeys [ a ] . mValue , dstAnim - > mPositionKeys [ a ] . mValue ) ;
}
anims . push_back ( dstAnim ) ;
} else
{
DefaultLogger : : get ( ) - > warn ( " Collada loader: found empty animation channel, ignored. Please check your exporter. " ) ;
}
2009-04-06 17:00:03 +00:00
}
if ( ! anims . empty ( ) )
{
aiAnimation * anim = new aiAnimation ;
anim - > mName . Set ( pName ) ;
anim - > mNumChannels = anims . size ( ) ;
anim - > mChannels = new aiNodeAnim * [ anims . size ( ) ] ;
std : : copy ( anims . begin ( ) , anims . end ( ) , anim - > mChannels ) ;
anim - > mDuration = 0.0f ;
for ( size_t a = 0 ; a < anims . size ( ) ; + + a )
{
anim - > mDuration = std : : max ( anim - > mDuration , anims [ a ] - > mPositionKeys [ anims [ a ] - > mNumPositionKeys - 1 ] . mTime ) ;
anim - > mDuration = std : : max ( anim - > mDuration , anims [ a ] - > mRotationKeys [ anims [ a ] - > mNumRotationKeys - 1 ] . mTime ) ;
anim - > mDuration = std : : max ( anim - > mDuration , anims [ a ] - > mScalingKeys [ anims [ a ] - > mNumScalingKeys - 1 ] . mTime ) ;
}
anim - > mTicksPerSecond = 1 ;
mAnims . push_back ( anim ) ;
}
}
2009-02-08 22:55:51 +00:00
// ------------------------------------------------------------------------------------------------
// Add a texture to a material structure
2011-08-22 20:22:51 +00:00
void ColladaLoader : : AddTexture ( aiMaterial & mat , const ColladaParser & pParser ,
2009-02-08 22:55:51 +00:00
const Collada : : Effect & effect ,
const Collada : : Sampler & sampler ,
aiTextureType type , unsigned int idx )
{
// first of all, basic file name
2010-09-15 20:29:48 +00:00
const aiString name = FindFilenameForEffectTexture ( pParser , effect , sampler . mName ) ;
mat . AddProperty ( & name , _AI_MATKEY_TEXTURE_BASE , type , idx ) ;
2009-02-08 22:55:51 +00:00
// mapping mode
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
int map = aiTextureMapMode_Clamp ;
2009-02-08 22:55:51 +00:00
if ( sampler . mWrapU )
map = aiTextureMapMode_Wrap ;
if ( sampler . mWrapU & & sampler . mMirrorU )
map = aiTextureMapMode_Mirror ;
mat . AddProperty ( & map , 1 , _AI_MATKEY_MAPPINGMODE_U_BASE , type , idx ) ;
map = aiTextureMapMode_Clamp ;
if ( sampler . mWrapV )
map = aiTextureMapMode_Wrap ;
if ( sampler . mWrapV & & sampler . mMirrorV )
map = aiTextureMapMode_Mirror ;
mat . AddProperty ( & map , 1 , _AI_MATKEY_MAPPINGMODE_V_BASE , type , idx ) ;
// UV transformation
mat . AddProperty ( & sampler . mTransform , 1 ,
_AI_MATKEY_UVTRANSFORM_BASE , type , idx ) ;
// Blend mode
mat . AddProperty ( ( int * ) & sampler . mOp , 1 ,
_AI_MATKEY_TEXBLEND_BASE , type , idx ) ;
// Blend factor
mat . AddProperty ( ( float * ) & sampler . mWeighting , 1 ,
_AI_MATKEY_TEXBLEND_BASE , type , idx ) ;
2011-04-22 21:29:18 +00:00
// UV source index ... if we didn't resolve the mapping, it is actually just
2009-02-08 22:55:51 +00:00
// a guess but it works in most cases. We search for the frst occurence of a
// number in the channel name. We assume it is the zero-based index into the
2009-04-23 14:13:20 +00:00
// UV channel array of all corresponding meshes. It could also be one-based
// for some exporters, but we won't care of it unless someone complains about.
2011-04-22 21:29:18 +00:00
if ( sampler . mUVId ! = UINT_MAX )
2009-02-08 22:55:51 +00:00
map = sampler . mUVId ;
else {
2009-04-23 14:13:20 +00:00
map = - 1 ;
for ( std : : string : : const_iterator it = sampler . mUVChannel . begin ( ) ; it ! = sampler . mUVChannel . end ( ) ; + + it ) {
2009-02-08 22:55:51 +00:00
if ( IsNumeric ( * it ) ) {
2011-03-23 14:26:19 +00:00
map = strtoul10 ( & ( * it ) ) ;
2009-02-08 22:55:51 +00:00
break ;
}
}
2009-04-23 14:13:20 +00:00
if ( - 1 = = map ) {
2009-02-08 22:55:51 +00:00
DefaultLogger : : get ( ) - > warn ( " Collada: unable to determine UV channel for texture " ) ;
map = 0 ;
}
}
mat . AddProperty ( & map , 1 , _AI_MATKEY_UVWSRC_BASE , type , idx ) ;
}
// ------------------------------------------------------------------------------------------------
// Fills materials from the collada material definitions
2011-06-09 14:29:32 +00:00
void ColladaLoader : : FillMaterials ( const ColladaParser & pParser , aiScene * /*pScene*/ )
2009-02-08 22:55:51 +00:00
{
for ( std : : vector < std : : pair < Collada : : Effect * , aiMaterial * > > : : iterator it = newMats . begin ( ) ,
end = newMats . end ( ) ; it ! = end ; + + it )
{
2011-08-22 20:22:51 +00:00
aiMaterial & mat = ( aiMaterial & ) * it - > second ;
2009-02-08 22:55:51 +00:00
Collada : : Effect & effect = * it - > first ;
// resolve shading mode
int shadeMode ;
if ( effect . mFaceted ) /* fixme */
shadeMode = aiShadingMode_Flat ;
else {
switch ( effect . mShadeType )
{
case Collada : : Shade_Constant :
shadeMode = aiShadingMode_NoShading ;
break ;
case Collada : : Shade_Lambert :
shadeMode = aiShadingMode_Gouraud ;
break ;
case Collada : : Shade_Blinn :
shadeMode = aiShadingMode_Blinn ;
break ;
case Collada : : Shade_Phong :
shadeMode = aiShadingMode_Phong ;
break ;
default :
DefaultLogger : : get ( ) - > warn ( " Collada: Unrecognized shading mode, using gouraud shading " ) ;
shadeMode = aiShadingMode_Gouraud ;
break ;
}
}
mat . AddProperty < int > ( & shadeMode , 1 , AI_MATKEY_SHADING_MODEL ) ;
// double-sided?
shadeMode = effect . mDoubleSided ;
mat . AddProperty < int > ( & shadeMode , 1 , AI_MATKEY_TWOSIDED ) ;
// wireframe?
shadeMode = effect . mWireframe ;
mat . AddProperty < int > ( & shadeMode , 1 , AI_MATKEY_ENABLE_WIREFRAME ) ;
// add material colors
2009-02-11 20:56:05 +00:00
mat . AddProperty ( & effect . mAmbient , 1 , AI_MATKEY_COLOR_AMBIENT ) ;
2009-02-08 22:55:51 +00:00
mat . AddProperty ( & effect . mDiffuse , 1 , AI_MATKEY_COLOR_DIFFUSE ) ;
2009-02-11 20:56:05 +00:00
mat . AddProperty ( & effect . mSpecular , 1 , AI_MATKEY_COLOR_SPECULAR ) ;
mat . AddProperty ( & effect . mEmissive , 1 , AI_MATKEY_COLOR_EMISSIVE ) ;
mat . AddProperty ( & effect . mTransparent , 1 , AI_MATKEY_COLOR_TRANSPARENT ) ;
mat . AddProperty ( & effect . mReflective , 1 , AI_MATKEY_COLOR_REFLECTIVE ) ;
// scalar properties
2009-02-08 22:55:51 +00:00
mat . AddProperty ( & effect . mShininess , 1 , AI_MATKEY_SHININESS ) ;
2009-11-22 14:06:51 +00:00
mat . AddProperty ( & effect . mReflectivity , 1 , AI_MATKEY_REFLECTIVITY ) ;
2009-02-08 22:55:51 +00:00
mat . AddProperty ( & effect . mRefractIndex , 1 , AI_MATKEY_REFRACTI ) ;
2009-04-10 22:51:12 +00:00
// transparency, a very hard one. seemingly not all files are following the
// specification here .. but we can trick.
2012-03-16 13:06:56 +00:00
if ( effect . mTransparency > = 0.f & & effect . mTransparency < 1.f ) {
2009-04-10 22:51:12 +00:00
effect . mTransparency = 1.f - effect . mTransparency ;
mat . AddProperty ( & effect . mTransparency , 1 , AI_MATKEY_OPACITY ) ;
mat . AddProperty ( & effect . mTransparent , 1 , AI_MATKEY_COLOR_TRANSPARENT ) ;
}
2009-02-08 22:55:51 +00:00
// add textures, if given
if ( ! effect . mTexAmbient . mName . empty ( ) )
2009-02-11 20:56:05 +00:00
/* It is merely a lightmap */
2009-03-12 14:15:57 +00:00
AddTexture ( mat , pParser , effect , effect . mTexAmbient , aiTextureType_LIGHTMAP ) ;
2009-02-08 22:55:51 +00:00
if ( ! effect . mTexEmissive . mName . empty ( ) )
2009-03-12 14:15:57 +00:00
AddTexture ( mat , pParser , effect , effect . mTexEmissive , aiTextureType_EMISSIVE ) ;
2009-02-08 22:55:51 +00:00
if ( ! effect . mTexSpecular . mName . empty ( ) )
2009-03-12 14:15:57 +00:00
AddTexture ( mat , pParser , effect , effect . mTexSpecular , aiTextureType_SPECULAR ) ;
2009-02-08 22:55:51 +00:00
if ( ! effect . mTexDiffuse . mName . empty ( ) )
2009-03-12 14:15:57 +00:00
AddTexture ( mat , pParser , effect , effect . mTexDiffuse , aiTextureType_DIFFUSE ) ;
2009-02-08 22:55:51 +00:00
if ( ! effect . mTexBump . mName . empty ( ) )
2011-09-14 09:41:48 +00:00
AddTexture ( mat , pParser , effect , effect . mTexBump , aiTextureType_NORMALS ) ;
2009-02-08 22:55:51 +00:00
if ( ! effect . mTexTransparent . mName . empty ( ) )
2009-03-12 14:15:57 +00:00
AddTexture ( mat , pParser , effect , effect . mTexTransparent , aiTextureType_OPACITY ) ;
2009-02-11 20:56:05 +00:00
if ( ! effect . mTexReflective . mName . empty ( ) )
2009-03-12 14:15:57 +00:00
AddTexture ( mat , pParser , effect , effect . mTexReflective , aiTextureType_REFLECTION ) ;
2009-02-08 22:55:51 +00:00
}
}
2008-12-04 17:06:26 +00:00
// ------------------------------------------------------------------------------------------------
// Constructs materials from the collada material definitions
2012-03-21 22:17:42 +00:00
void ColladaLoader : : BuildMaterials ( ColladaParser & pParser , aiScene * /*pScene*/ )
2008-12-04 17:06:26 +00:00
{
2009-02-08 22:55:51 +00:00
newMats . reserve ( pParser . mMaterialLibrary . size ( ) ) ;
2008-12-04 17:06:26 +00:00
for ( ColladaParser : : MaterialLibrary : : const_iterator matIt = pParser . mMaterialLibrary . begin ( ) ; matIt ! = pParser . mMaterialLibrary . end ( ) ; + + matIt )
{
const Collada : : Material & material = matIt - > second ;
// a material is only a reference to an effect
2012-03-21 22:17:42 +00:00
ColladaParser : : EffectLibrary : : iterator effIt = pParser . mEffectLibrary . find ( material . mEffect ) ;
2008-12-04 17:06:26 +00:00
if ( effIt = = pParser . mEffectLibrary . end ( ) )
continue ;
2012-03-21 22:17:42 +00:00
Collada : : Effect & effect = effIt - > second ;
2008-12-04 17:06:26 +00:00
// create material
2011-08-22 20:22:51 +00:00
aiMaterial * mat = new aiMaterial ;
2008-12-04 17:06:26 +00:00
aiString name ( matIt - > first ) ;
2009-02-08 22:55:51 +00:00
mat - > AddProperty ( & name , AI_MATKEY_NAME ) ;
2008-12-04 17:06:26 +00:00
// store the material
mMaterialIndexByName [ matIt - > first ] = newMats . size ( ) ;
2012-03-21 22:17:42 +00:00
newMats . push_back ( std : : pair < Collada : : Effect * , aiMaterial * > ( & effect , mat ) ) ;
2008-12-04 17:06:26 +00:00
}
2009-04-02 15:16:01 +00:00
// ScenePreprocessor generates a default material automatically if none is there.
// All further code here in this loader works well without a valid material so
// we can safely let it to ScenePreprocessor.
#if 0
2008-12-04 17:06:26 +00:00
if ( newMats . size ( ) = = 0 )
{
2011-08-22 20:22:51 +00:00
aiMaterial * mat = new aiMaterial ;
2009-02-08 22:55:51 +00:00
aiString name ( AI_DEFAULT_MATERIAL_NAME ) ;
2008-12-04 17:06:26 +00:00
mat - > AddProperty ( & name , AI_MATKEY_NAME ) ;
2009-02-08 22:55:51 +00:00
const int shadeMode = aiShadingMode_Phong ;
2008-12-04 17:06:26 +00:00
mat - > AddProperty < int > ( & shadeMode , 1 , AI_MATKEY_SHADING_MODEL ) ;
aiColor4D colAmbient ( 0.2f , 0.2f , 0.2f , 1.0f ) , colDiffuse ( 0.8f , 0.8f , 0.8f , 1.0f ) , colSpecular ( 0.5f , 0.5f , 0.5f , 0.5f ) ;
mat - > AddProperty ( & colAmbient , 1 , AI_MATKEY_COLOR_AMBIENT ) ;
mat - > AddProperty ( & colDiffuse , 1 , AI_MATKEY_COLOR_DIFFUSE ) ;
mat - > AddProperty ( & colSpecular , 1 , AI_MATKEY_COLOR_SPECULAR ) ;
2009-02-08 22:55:51 +00:00
const float specExp = 5.0f ;
2008-12-04 17:06:26 +00:00
mat - > AddProperty ( & specExp , 1 , AI_MATKEY_SHININESS ) ;
}
2009-04-02 15:16:01 +00:00
# endif
2008-12-04 17:06:26 +00:00
}
// ------------------------------------------------------------------------------------------------
// Resolves the texture name for the given effect texture entry
2010-06-04 14:36:41 +00:00
aiString ColladaLoader : : FindFilenameForEffectTexture ( const ColladaParser & pParser ,
2009-02-11 20:56:05 +00:00
const Collada : : Effect & pEffect , const std : : string & pName )
2008-12-04 17:06:26 +00:00
{
// recurse through the param references until we end up at an image
std : : string name = pName ;
while ( 1 )
{
// the given string is a param entry. Find it
Collada : : Effect : : ParamLibrary : : const_iterator it = pEffect . mParams . find ( name ) ;
// if not found, we're at the end of the recursion. The resulting string should be the image ID
if ( it = = pEffect . mParams . end ( ) )
break ;
// else recurse on
name = it - > second . mReference ;
}
// find the image referred by this name in the image library of the scene
ColladaParser : : ImageLibrary : : const_iterator imIt = pParser . mImageLibrary . find ( name ) ;
2009-03-25 21:10:28 +00:00
if ( imIt = = pParser . mImageLibrary . end ( ) )
{
2010-03-18 17:00:12 +00:00
throw DeadlyImportError ( boost : : str ( boost : : format (
2009-02-11 20:56:05 +00:00
" Collada: Unable to resolve effect texture entry \" %s \" , ended up at ID \" %s \" . " ) % pName % name ) ) ;
}
2009-03-25 21:10:28 +00:00
2010-06-04 14:05:06 +00:00
aiString result ;
2009-02-11 20:56:05 +00:00
// if this is an embedded texture image setup an aiTexture for it
2009-03-25 21:10:28 +00:00
if ( imIt - > second . mFileName . empty ( ) )
{
2009-10-22 08:08:04 +00:00
if ( imIt - > second . mImageData . empty ( ) ) {
2010-03-18 17:00:12 +00:00
throw DeadlyImportError ( " Collada: Invalid texture, no data or file reference given " ) ;
2009-10-22 08:08:04 +00:00
}
2009-03-25 21:10:28 +00:00
2009-02-11 20:56:05 +00:00
aiTexture * tex = new aiTexture ( ) ;
// setup format hint
2009-10-22 08:08:04 +00:00
if ( imIt - > second . mEmbeddedFormat . length ( ) > 3 ) {
2009-02-11 20:56:05 +00:00
DefaultLogger : : get ( ) - > warn ( " Collada: texture format hint is too long, truncating to 3 characters " ) ;
2009-10-22 08:08:04 +00:00
}
2009-03-25 21:10:28 +00:00
strncpy ( tex - > achFormatHint , imIt - > second . mEmbeddedFormat . c_str ( ) , 3 ) ;
2009-02-11 20:56:05 +00:00
// and copy texture data
tex - > mHeight = 0 ;
tex - > mWidth = imIt - > second . mImageData . size ( ) ;
tex - > pcData = ( aiTexel * ) new char [ tex - > mWidth ] ;
2009-03-25 21:10:28 +00:00
memcpy ( tex - > pcData , & imIt - > second . mImageData [ 0 ] , tex - > mWidth ) ;
2009-02-11 20:56:05 +00:00
// setup texture reference string
result . data [ 0 ] = ' * ' ;
result . length = 1 + ASSIMP_itoa10 ( result . data + 1 , MAXLEN - 1 , mTextures . size ( ) ) ;
// and add this texture to the list
mTextures . push_back ( tex ) ;
}
2009-03-25 21:10:28 +00:00
else
{
2009-02-11 20:56:05 +00:00
result . Set ( imIt - > second . mFileName ) ;
ConvertPath ( result ) ;
}
2008-12-04 17:06:26 +00:00
return result ;
}
2009-01-12 00:00:13 +00:00
// ------------------------------------------------------------------------------------------------
// Convert a path read from a collada file to the usual representation
void ColladaLoader : : ConvertPath ( aiString & ss )
{
// TODO: collada spec, p 22. Handle URI correctly.
// For the moment we're just stripping the file:// away to make it work.
// Windoes doesn't seem to be able to find stuff like
// 'file://..\LWO\LWO2\MappingModes\earthSpherical.jpg'
2009-03-25 21:10:28 +00:00
if ( 0 = = strncmp ( ss . data , " file:// " , 7 ) )
2009-01-12 00:00:13 +00:00
{
ss . length - = 7 ;
2009-03-25 21:10:28 +00:00
memmove ( ss . data , ss . data + 7 , ss . length ) ;
2009-01-12 00:00:13 +00:00
ss . data [ ss . length ] = ' \0 ' ;
}
2012-03-08 16:08:46 +00:00
2012-04-02 10:43:18 +00:00
// Maxon Cinema Collada Export writes "file:///C:\andsoon" with three slashes...
// I need to filter it without destroying linux paths starting with "/somewhere"
if ( ss . data [ 0 ] = = ' / ' & & isalpha ( ss . data [ 1 ] ) & & ss . data [ 2 ] = = ' : ' )
{
ss . length - - ;
memmove ( ss . data , ss . data + 1 , ss . length ) ;
ss . data [ ss . length ] = 0 ;
}
2013-03-27 11:52:22 +00:00
// find and convert all %xy special chars
2012-03-08 16:08:46 +00:00
char * out = ss . data ;
for ( const char * it = ss . data ; it ! = ss . data + ss . length ; /**/ )
{
2013-03-27 11:52:22 +00:00
if ( * it = = ' % ' & & ( it + 3 ) < ss . data + ss . length )
2012-03-08 16:08:46 +00:00
{
2013-03-27 11:52:22 +00:00
// separate the number to avoid dragging in chars from behind into the parsing
char mychar [ 3 ] = { it [ 1 ] , it [ 2 ] , 0 } ;
size_t nbr = strtoul16 ( mychar ) ;
it + = 3 ;
2012-03-19 17:33:21 +00:00
* out + + = ( char ) ( nbr & 0xFF ) ;
2012-03-08 16:08:46 +00:00
} else
{
* out + + = * it + + ;
}
}
// adjust length and terminator of the shortened string
* out = 0 ;
ss . length = ( ptrdiff_t ) ( out - ss . data ) ;
2009-01-12 00:00:13 +00:00
}
2009-01-18 23:48:25 +00:00
2009-04-06 17:00:03 +00:00
// ------------------------------------------------------------------------------------------------
// Reads a float value from an accessor and its data array.
float ColladaLoader : : ReadFloat ( const Collada : : Accessor & pAccessor , const Collada : : Data & pData , size_t pIndex , size_t pOffset ) const
{
// FIXME: (thom) Test for data type here in every access? For the moment, I leave this to the caller
size_t pos = pAccessor . mStride * pIndex + pAccessor . mOffset + pOffset ;
ai_assert ( pos < pData . mValues . size ( ) ) ;
return pData . mValues [ pos ] ;
}
// ------------------------------------------------------------------------------------------------
// Reads a string value from an accessor and its data array.
const std : : string & ColladaLoader : : ReadString ( const Collada : : Accessor & pAccessor , const Collada : : Data & pData , size_t pIndex ) const
{
size_t pos = pAccessor . mStride * pIndex + pAccessor . mOffset ;
ai_assert ( pos < pData . mStrings . size ( ) ) ;
return pData . mStrings [ pos ] ;
}
// ------------------------------------------------------------------------------------------------
// Collects all nodes into the given array
void ColladaLoader : : CollectNodes ( const aiNode * pNode , std : : vector < const aiNode * > & poNodes ) const
{
poNodes . push_back ( pNode ) ;
for ( size_t a = 0 ; a < pNode - > mNumChildren ; + + a )
CollectNodes ( pNode - > mChildren [ a ] , poNodes ) ;
}
// ------------------------------------------------------------------------------------------------
// Finds a node in the collada scene by the given name
2010-01-10 10:38:52 +00:00
const Collada : : Node * ColladaLoader : : FindNode ( const Collada : : Node * pNode , const std : : string & pName ) const
2009-04-06 17:00:03 +00:00
{
2009-08-01 20:20:22 +00:00
if ( pNode - > mName = = pName | | pNode - > mID = = pName )
2009-04-06 17:00:03 +00:00
return pNode ;
for ( size_t a = 0 ; a < pNode - > mChildren . size ( ) ; + + a )
{
const Collada : : Node * node = FindNode ( pNode - > mChildren [ a ] , pName ) ;
if ( node )
return node ;
}
return NULL ;
}
2010-01-10 10:38:52 +00:00
// ------------------------------------------------------------------------------------------------
// Finds a node in the collada scene by the given SID
const Collada : : Node * ColladaLoader : : FindNodeBySID ( const Collada : : Node * pNode , const std : : string & pSID ) const
{
if ( pNode - > mSID = = pSID )
return pNode ;
for ( size_t a = 0 ; a < pNode - > mChildren . size ( ) ; + + a )
{
const Collada : : Node * node = FindNodeBySID ( pNode - > mChildren [ a ] , pSID ) ;
if ( node )
return node ;
}
return NULL ;
}
// ------------------------------------------------------------------------------------------------
// Finds a proper name for a node derived from the collada-node's properties
std : : string ColladaLoader : : FindNameForNode ( const Collada : : Node * pNode ) const
{
// now setup the name of the node. We take the name if not empty, otherwise the collada ID
// FIX: Workaround for XSI calling the instanced visual scene 'untitled' by default.
if ( ! pNode - > mName . empty ( ) & & pNode - > mName ! = " untitled " )
return pNode - > mName ;
else if ( ! pNode - > mID . empty ( ) )
return pNode - > mID ;
else if ( ! pNode - > mSID . empty ( ) )
return pNode - > mSID ;
else
{
// No need to worry. Unnamed nodes are no problem at all, except
// if cameras or lights need to be assigned to them.
return boost : : str ( boost : : format ( " $ColladaAutoName$_%d " ) % clock ( ) ) ;
}
}
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
# endif // !! ASSIMP_BUILD_NO_DAE_IMPORTER