2008-06-22 10:09:26 +00:00
|
|
|
|
/*
|
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
Open Asset Import Library (ASSIMP)
|
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
2010-04-10 15:30:22 +00:00
|
|
|
|
Copyright (c) 2006-2010, ASSIMP Development Team
|
2008-06-22 10:09:26 +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.
|
|
|
|
|
|
|
|
|
|
* Neither the name of the ASSIMP team, nor the names of its
|
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
|
derived from this software without specific prior
|
|
|
|
|
written permission of the ASSIMP Development Team.
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
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
|
|
|
|
/** @file SMDLoader.cpp
|
|
|
|
|
* @brief Implementation of the SMD importer class
|
|
|
|
|
*/
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
|
#include "AssimpPCH.h"
|
2009-01-18 23:48:25 +00:00
|
|
|
|
#ifndef ASSIMP_BUILD_NO_SMD_IMPORTER
|
2008-10-13 16:45:48 +00:00
|
|
|
|
|
2008-07-10 16:49:01 +00:00
|
|
|
|
// internal headers
|
2008-06-22 10:09:26 +00:00
|
|
|
|
#include "SMDLoader.h"
|
|
|
|
|
#include "fast_atof.h"
|
2008-11-28 23:02:27 +00:00
|
|
|
|
#include "SkeletonMeshBuilder.h"
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
using namespace Assimp;
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
// Constructor to be privately used by Importer
|
|
|
|
|
SMDImporter::SMDImporter()
|
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-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
// Destructor, private as well
|
|
|
|
|
SMDImporter::~SMDImporter()
|
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
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
// Returns whether the class can handle the format of the given file.
|
2011-06-09 14:29:32 +00:00
|
|
|
|
bool SMDImporter::CanRead( const std::string& pFile, IOSystem* /*pIOHandler*/, bool) const
|
2008-06-22 10:09:26 +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
|
|
|
|
// fixme: auto format detection
|
|
|
|
|
return SimpleExtensionCheck(pFile,"smd","vta");
|
2008-06-22 10:09:26 +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 a list of all supported file extensions
|
2010-03-02 17:38:01 +00:00
|
|
|
|
void SMDImporter::GetExtensionList(std::set<std::string>& extensions)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2010-03-02 17:38:01 +00:00
|
|
|
|
extensions.insert("smd");
|
|
|
|
|
extensions.insert("vta");
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2008-11-28 23:02:27 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-08-08 18:34:14 +00:00
|
|
|
|
// Setup configuration properties
|
|
|
|
|
void SMDImporter::SetupProperties(const Importer* pImp)
|
|
|
|
|
{
|
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
|
|
|
|
// The
|
|
|
|
|
// AI_CONFIG_IMPORT_SMD_KEYFRAME option overrides the
|
2008-08-08 18:34:14 +00:00
|
|
|
|
// AI_CONFIG_IMPORT_GLOBAL_KEYFRAME option.
|
2011-04-22 21:29:18 +00:00
|
|
|
|
configFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_SMD_KEYFRAME,-1);
|
|
|
|
|
if(static_cast<unsigned int>(-1) == configFrameID) {
|
2008-10-13 16:45:48 +00:00
|
|
|
|
configFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_GLOBAL_KEYFRAME,0);
|
2008-08-08 18:34:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2008-11-28 23:02:27 +00:00
|
|
|
|
|
2008-08-08 18:34:14 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// Imports the given file into the given scene structure.
|
2011-04-22 21:29:18 +00:00
|
|
|
|
void SMDImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2010-01-19 20:05:14 +00:00
|
|
|
|
boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile, "rb"));
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
// Check whether we can read from the file
|
2009-08-21 22:49:58 +00:00
|
|
|
|
if( file.get() == NULL) {
|
2010-03-18 17:00:12 +00:00
|
|
|
|
throw DeadlyImportError( "Failed to open SMD/VTA file " + pFile + ".");
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
|
iFileSize = (unsigned int)file->FileSize();
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
2008-11-28 23:02:27 +00:00
|
|
|
|
// Allocate storage and copy the contents of the file to a memory buffer
|
2008-06-22 10:09:26 +00:00
|
|
|
|
this->pScene = pScene;
|
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
|
std::vector<char> buff(iFileSize+1);
|
2009-08-21 22:49:58 +00:00
|
|
|
|
TextFileToBuffer(file.get(),buff);
|
2008-10-13 16:45:48 +00:00
|
|
|
|
mBuffer = &buff[0];
|
|
|
|
|
|
|
|
|
|
iSmallestFrame = (1 << 31);
|
|
|
|
|
bHasUVs = true;
|
|
|
|
|
iLineNumber = 1;
|
2008-07-10 16:49:01 +00:00
|
|
|
|
|
2008-11-28 23:02:27 +00:00
|
|
|
|
// Reserve enough space for ... hm ... 10 textures
|
2008-10-13 16:45:48 +00:00
|
|
|
|
aszTextures.reserve(10);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
2008-11-28 23:02:27 +00:00
|
|
|
|
// Reserve enough space for ... hm ... 1000 triangles
|
2008-10-13 16:45:48 +00:00
|
|
|
|
asTriangles.reserve(1000);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
2008-11-28 23:02:27 +00:00
|
|
|
|
// Reserve enough space for ... hm ... 20 bones
|
2008-10-13 16:45:48 +00:00
|
|
|
|
asBones.reserve(20);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
|
// parse the file ...
|
|
|
|
|
ParseFile();
|
|
|
|
|
|
2008-11-28 23:02:27 +00:00
|
|
|
|
// If there are no triangles it seems to be an animation SMD,
|
2008-10-13 16:45:48 +00:00
|
|
|
|
// containing only the animation skeleton.
|
|
|
|
|
if (asTriangles.empty())
|
|
|
|
|
{
|
|
|
|
|
if (asBones.empty())
|
2008-07-10 16:49:01 +00:00
|
|
|
|
{
|
2010-03-18 17:00:12 +00:00
|
|
|
|
throw DeadlyImportError("SMD: No triangles and no bones have "
|
2008-10-13 16:45:48 +00:00
|
|
|
|
"been found in the file. This file seems to be invalid.");
|
2008-07-10 16:49:01 +00:00
|
|
|
|
}
|
2008-11-28 23:02:27 +00:00
|
|
|
|
|
|
|
|
|
// Set the flag in the scene structure which indicates
|
2008-10-13 16:45:48 +00:00
|
|
|
|
// that there is nothing than an animation skeleton
|
2008-10-19 11:32:33 +00:00
|
|
|
|
pScene->mFlags |= AI_SCENE_FLAGS_INCOMPLETE;
|
2008-10-13 16:45:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!asBones.empty())
|
|
|
|
|
{
|
2008-11-28 23:02:27 +00:00
|
|
|
|
// Check whether all bones have been initialized
|
2008-10-13 16:45:48 +00:00
|
|
|
|
for (std::vector<SMD::Bone>::const_iterator
|
|
|
|
|
i = asBones.begin();
|
|
|
|
|
i != asBones.end();++i)
|
2008-07-10 16:49:01 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if (!(*i).mName.length())
|
2008-07-10 16:49:01 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
DefaultLogger::get()->warn("SMD: Not all bones have been initialized");
|
|
|
|
|
break;
|
2008-07-10 16:49:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
|
// now fix invalid time values and make sure the animation starts at frame 0
|
|
|
|
|
FixTimeValues();
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
|
// compute absolute bone transformation matrices
|
2008-11-28 23:02:27 +00:00
|
|
|
|
// ComputeAbsoluteBoneTransformations();
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2008-11-28 23:02:27 +00:00
|
|
|
|
|
2008-10-19 11:32:33 +00:00
|
|
|
|
if (!(pScene->mFlags & AI_SCENE_FLAGS_INCOMPLETE))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
// create output meshes
|
|
|
|
|
CreateOutputMeshes();
|
|
|
|
|
|
|
|
|
|
// build an output material list
|
|
|
|
|
CreateOutputMaterials();
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
|
// build the output animation
|
|
|
|
|
CreateOutputAnimations();
|
|
|
|
|
|
|
|
|
|
// build output nodes (bones are added as empty dummy nodes)
|
|
|
|
|
CreateOutputNodes();
|
2008-11-28 23:02:27 +00:00
|
|
|
|
|
|
|
|
|
if (pScene->mFlags & AI_SCENE_FLAGS_INCOMPLETE)
|
|
|
|
|
{
|
|
|
|
|
SkeletonMeshBuilder skeleton(pScene);
|
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
// Write an error message with line number to the log file
|
|
|
|
|
void SMDImporter::LogErrorNoThrow(const char* msg)
|
|
|
|
|
{
|
|
|
|
|
char szTemp[1024];
|
2008-10-13 16:45:48 +00:00
|
|
|
|
sprintf(szTemp,"Line %i: %s",iLineNumber,msg);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
DefaultLogger::get()->error(szTemp);
|
|
|
|
|
}
|
2008-11-28 23:02:27 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
// Write a warning with line number to the log file
|
|
|
|
|
void SMDImporter::LogWarning(const char* msg)
|
|
|
|
|
{
|
|
|
|
|
char szTemp[1024];
|
|
|
|
|
ai_assert(strlen(msg) < 1000);
|
2011-06-09 14:29:32 +00:00
|
|
|
|
sprintf(szTemp,"Line %i: %s",iLineNumber,msg);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
DefaultLogger::get()->warn(szTemp);
|
|
|
|
|
}
|
2008-11-28 23:02:27 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
// Fix invalid time values in the file
|
|
|
|
|
void SMDImporter::FixTimeValues()
|
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
double dDelta = (double)iSmallestFrame;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
double dMax = 0.0f;
|
|
|
|
|
for (std::vector<SMD::Bone>::iterator
|
2008-10-13 16:45:48 +00:00
|
|
|
|
iBone = asBones.begin();
|
|
|
|
|
iBone != asBones.end();++iBone)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
|
|
|
|
for (std::vector<SMD::Bone::Animation::MatrixKey>::iterator
|
|
|
|
|
iKey = (*iBone).sAnim.asKeys.begin();
|
|
|
|
|
iKey != (*iBone).sAnim.asKeys.end();++iKey)
|
|
|
|
|
{
|
|
|
|
|
(*iKey).dTime -= dDelta;
|
|
|
|
|
dMax = std::max(dMax, (*iKey).dTime);
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
|
dLengthOfAnim = dMax;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2008-11-28 23:02:27 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
// create output meshes
|
|
|
|
|
void SMDImporter::CreateOutputMeshes()
|
|
|
|
|
{
|
2008-11-28 23:02:27 +00:00
|
|
|
|
if (aszTextures.empty())
|
|
|
|
|
aszTextures.push_back(std::string());
|
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// we need to sort all faces by their material index
|
|
|
|
|
// in opposition to other loaders we can be sure that each
|
|
|
|
|
// material is at least used once.
|
2008-10-13 16:45:48 +00:00
|
|
|
|
pScene->mNumMeshes = (unsigned int) aszTextures.size();
|
|
|
|
|
pScene->mMeshes = new aiMesh*[pScene->mNumMeshes];
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
typedef std::vector<unsigned int> FaceList;
|
2008-10-13 16:45:48 +00:00
|
|
|
|
FaceList* aaiFaces = new FaceList[pScene->mNumMeshes];
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
// approximate the space that will be required
|
2008-10-13 16:45:48 +00:00
|
|
|
|
unsigned int iNum = (unsigned int)asTriangles.size() / pScene->mNumMeshes;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
iNum += iNum >> 1;
|
2008-10-13 16:45:48 +00:00
|
|
|
|
for (unsigned int i = 0; i < pScene->mNumMeshes;++i)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
aaiFaces[i].reserve(iNum);
|
2008-11-28 23:02:27 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
// collect all faces
|
|
|
|
|
iNum = 0;
|
|
|
|
|
for (std::vector<SMD::Face>::const_iterator
|
2008-10-13 16:45:48 +00:00
|
|
|
|
iFace = asTriangles.begin();
|
|
|
|
|
iFace != asTriangles.end();++iFace,++iNum)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2011-04-22 21:29:18 +00:00
|
|
|
|
if (UINT_MAX == (*iFace).iTexture)aaiFaces[(*iFace).iTexture].push_back( 0 );
|
2008-10-13 16:45:48 +00:00
|
|
|
|
else if ((*iFace).iTexture >= aszTextures.size())
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
|
|
|
|
DefaultLogger::get()->error("[SMD/VTA] Material index overflow in face");
|
2008-10-13 16:45:48 +00:00
|
|
|
|
aaiFaces[(*iFace).iTexture].push_back((unsigned int)aszTextures.size()-1);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
else aaiFaces[(*iFace).iTexture].push_back(iNum);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// now create the output meshes
|
2008-10-13 16:45:48 +00:00
|
|
|
|
for (unsigned int i = 0; i < pScene->mNumMeshes;++i)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
aiMesh*& pcMesh = pScene->mMeshes[i] = new aiMesh();
|
2008-06-22 10:09:26 +00:00
|
|
|
|
ai_assert(!aaiFaces[i].empty()); // should not be empty ...
|
|
|
|
|
|
2008-09-30 20:20:56 +00:00
|
|
|
|
pcMesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
pcMesh->mNumVertices = (unsigned int)aaiFaces[i].size()*3;
|
|
|
|
|
pcMesh->mNumFaces = (unsigned int)aaiFaces[i].size();
|
|
|
|
|
pcMesh->mMaterialIndex = i;
|
|
|
|
|
|
|
|
|
|
// storage for bones
|
|
|
|
|
typedef std::pair<unsigned int,float> TempWeightListEntry;
|
|
|
|
|
typedef std::vector< TempWeightListEntry > TempBoneWeightList;
|
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
|
TempBoneWeightList* aaiBones = new TempBoneWeightList[asBones.size()]();
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
// try to reserve enough memory without wasting too much
|
2008-10-13 16:45:48 +00:00
|
|
|
|
for (unsigned int iBone = 0; iBone < asBones.size();++iBone)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
aaiBones[iBone].reserve(pcMesh->mNumVertices/asBones.size());
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// allocate storage
|
|
|
|
|
pcMesh->mFaces = new aiFace[pcMesh->mNumFaces];
|
|
|
|
|
aiVector3D* pcNormals = pcMesh->mNormals = new aiVector3D[pcMesh->mNumVertices];
|
|
|
|
|
aiVector3D* pcVerts = pcMesh->mVertices = new aiVector3D[pcMesh->mNumVertices];
|
|
|
|
|
|
|
|
|
|
aiVector3D* pcUVs = NULL;
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if (bHasUVs)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
|
|
|
|
pcUVs = pcMesh->mTextureCoords[0] = new aiVector3D[pcMesh->mNumVertices];
|
|
|
|
|
pcMesh->mNumUVComponents[0] = 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
iNum = 0;
|
|
|
|
|
for (unsigned int iFace = 0; iFace < pcMesh->mNumFaces;++iFace)
|
|
|
|
|
{
|
|
|
|
|
pcMesh->mFaces[iFace].mIndices = new unsigned int[3];
|
|
|
|
|
pcMesh->mFaces[iFace].mNumIndices = 3;
|
|
|
|
|
|
2008-09-30 20:20:56 +00:00
|
|
|
|
// fill the vertices
|
2008-06-22 10:09:26 +00:00
|
|
|
|
unsigned int iSrcFace = aaiFaces[i][iFace];
|
2008-10-13 16:45:48 +00:00
|
|
|
|
SMD::Face& face = asTriangles[iSrcFace];
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
*pcVerts++ = face.avVertices[0].pos;
|
|
|
|
|
*pcVerts++ = face.avVertices[1].pos;
|
2008-07-10 16:49:01 +00:00
|
|
|
|
*pcVerts++ = face.avVertices[2].pos;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
// fill the normals
|
|
|
|
|
*pcNormals++ = face.avVertices[0].nor;
|
|
|
|
|
*pcNormals++ = face.avVertices[1].nor;
|
|
|
|
|
*pcNormals++ = face.avVertices[2].nor;
|
|
|
|
|
|
|
|
|
|
// fill the texture coordinates
|
|
|
|
|
if (pcUVs)
|
|
|
|
|
{
|
|
|
|
|
*pcUVs++ = face.avVertices[0].uv;
|
|
|
|
|
*pcUVs++ = face.avVertices[1].uv;
|
|
|
|
|
*pcUVs++ = face.avVertices[2].uv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (unsigned int iVert = 0; iVert < 3;++iVert)
|
|
|
|
|
{
|
|
|
|
|
float fSum = 0.0f;
|
2008-07-10 16:49:01 +00:00
|
|
|
|
for (unsigned int iBone = 0;iBone < face.avVertices[iVert].aiBoneLinks.size();++iBone)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
|
|
|
|
TempWeightListEntry& pairval = face.avVertices[iVert].aiBoneLinks[iBone];
|
ASE: Added WIP support for *SMOOTHSKINMESH elements in ASE/ASC files. Fixes in the ASE loader. Fixed animation parsing. Temporary implementation of target lights and cameras, including animations.
3DS: Fixed transformation problems (Pivot points), added WIP animation support. No target animation yet (cameras, spot lights). Not yet fully tested, but static models that worked before should still work now, except all look correct now :-) (some problems with very large models remaining)
Further work on the IRR and IRRMESH loaders. IRR still WIP, IRRMESH more stable now.
Work on the LWo loader. Added support for the "one-layer-only" mode. Hierarchy bug still unfixed, UV coords bug still unfixed.
Further work on the FindInvalidDataprocess. Improved validation for normals, no false positives anymore.
Further work on the MDR loader, still WIP.
Moved DeterminePType-Step to ScenePreprocessor.
aiAnimation::mDuration is optional now, ScenePreprocessor computes it automatically if set to -1.
Fixes in the SMD loader. Still crashes on some files.
Updated animation documentation.
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@236 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2008-11-09 23:17:19 +00:00
|
|
|
|
|
|
|
|
|
// FIX: The second check is here just to make sure we won't
|
|
|
|
|
// assign more than one weight to a single vertex index
|
|
|
|
|
if (pairval.first >= asBones.size() ||
|
|
|
|
|
pairval.first == face.avVertices[iVert].iParentNode)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
|
|
|
|
DefaultLogger::get()->error("[SMD/VTA] Bone index overflow. "
|
|
|
|
|
"The bone index will be ignored, the weight will be assigned "
|
|
|
|
|
"to the vertex' parent node");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
aaiBones[pairval.first].push_back(TempWeightListEntry(iNum,pairval.second));
|
|
|
|
|
fSum += pairval.second;
|
|
|
|
|
}
|
ASE: Added WIP support for *SMOOTHSKINMESH elements in ASE/ASC files. Fixes in the ASE loader. Fixed animation parsing. Temporary implementation of target lights and cameras, including animations.
3DS: Fixed transformation problems (Pivot points), added WIP animation support. No target animation yet (cameras, spot lights). Not yet fully tested, but static models that worked before should still work now, except all look correct now :-) (some problems with very large models remaining)
Further work on the IRR and IRRMESH loaders. IRR still WIP, IRRMESH more stable now.
Work on the LWo loader. Added support for the "one-layer-only" mode. Hierarchy bug still unfixed, UV coords bug still unfixed.
Further work on the FindInvalidDataprocess. Improved validation for normals, no false positives anymore.
Further work on the MDR loader, still WIP.
Moved DeterminePType-Step to ScenePreprocessor.
aiAnimation::mDuration is optional now, ScenePreprocessor computes it automatically if set to -1.
Fixes in the SMD loader. Still crashes on some files.
Updated animation documentation.
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@236 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2008-11-09 23:17:19 +00:00
|
|
|
|
// ******************************************************************
|
|
|
|
|
// If the sum of all vertex weights is not 1.0 we must assign
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// the rest to the vertex' parent node. Well, at least the doc says
|
|
|
|
|
// we should ...
|
ASE: Added WIP support for *SMOOTHSKINMESH elements in ASE/ASC files. Fixes in the ASE loader. Fixed animation parsing. Temporary implementation of target lights and cameras, including animations.
3DS: Fixed transformation problems (Pivot points), added WIP animation support. No target animation yet (cameras, spot lights). Not yet fully tested, but static models that worked before should still work now, except all look correct now :-) (some problems with very large models remaining)
Further work on the IRR and IRRMESH loaders. IRR still WIP, IRRMESH more stable now.
Work on the LWo loader. Added support for the "one-layer-only" mode. Hierarchy bug still unfixed, UV coords bug still unfixed.
Further work on the FindInvalidDataprocess. Improved validation for normals, no false positives anymore.
Further work on the MDR loader, still WIP.
Moved DeterminePType-Step to ScenePreprocessor.
aiAnimation::mDuration is optional now, ScenePreprocessor computes it automatically if set to -1.
Fixes in the SMD loader. Still crashes on some files.
Updated animation documentation.
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@236 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2008-11-09 23:17:19 +00:00
|
|
|
|
// FIX: We use 0.975 as limit, floating-point inaccuracies seem to
|
|
|
|
|
// be very strong in some SMD exporters. Furthermore it is possible
|
|
|
|
|
// that the parent of a vertex is 0xffffffff (if the corresponding
|
|
|
|
|
// entry in the file was unreadable)
|
|
|
|
|
// ******************************************************************
|
2011-04-22 21:29:18 +00:00
|
|
|
|
if (fSum < 0.975f && face.avVertices[iVert].iParentNode != UINT_MAX)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if (face.avVertices[iVert].iParentNode >= asBones.size())
|
2008-07-10 16:49:01 +00:00
|
|
|
|
{
|
|
|
|
|
DefaultLogger::get()->error("[SMD/VTA] Bone index overflow. "
|
|
|
|
|
"The index of the vertex parent bone is invalid. "
|
|
|
|
|
"The remaining weights will be normalized to 1.0");
|
|
|
|
|
|
|
|
|
|
if (fSum)
|
|
|
|
|
{
|
|
|
|
|
fSum = 1 / fSum;
|
|
|
|
|
for (unsigned int iBone = 0;iBone < face.avVertices[iVert].aiBoneLinks.size();++iBone)
|
|
|
|
|
{
|
|
|
|
|
TempWeightListEntry& pairval = face.avVertices[iVert].aiBoneLinks[iBone];
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if (pairval.first >= asBones.size())continue;
|
2008-07-10 16:49:01 +00:00
|
|
|
|
aaiBones[pairval.first].back().second *= fSum;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
aaiBones[face.avVertices[iVert].iParentNode].push_back(
|
|
|
|
|
TempWeightListEntry(iNum,1.0f-fSum));
|
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
pcMesh->mFaces[iFace].mIndices[iVert] = iNum++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// now build all bones of the mesh
|
|
|
|
|
iNum = 0;
|
2008-10-13 16:45:48 +00:00
|
|
|
|
for (unsigned int iBone = 0; iBone < asBones.size();++iBone)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
if (!aaiBones[iBone].empty())++iNum;
|
2008-11-28 23:02:27 +00:00
|
|
|
|
|
|
|
|
|
if (false && iNum)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
ASE: Added WIP support for *SMOOTHSKINMESH elements in ASE/ASC files. Fixes in the ASE loader. Fixed animation parsing. Temporary implementation of target lights and cameras, including animations.
3DS: Fixed transformation problems (Pivot points), added WIP animation support. No target animation yet (cameras, spot lights). Not yet fully tested, but static models that worked before should still work now, except all look correct now :-) (some problems with very large models remaining)
Further work on the IRR and IRRMESH loaders. IRR still WIP, IRRMESH more stable now.
Work on the LWo loader. Added support for the "one-layer-only" mode. Hierarchy bug still unfixed, UV coords bug still unfixed.
Further work on the FindInvalidDataprocess. Improved validation for normals, no false positives anymore.
Further work on the MDR loader, still WIP.
Moved DeterminePType-Step to ScenePreprocessor.
aiAnimation::mDuration is optional now, ScenePreprocessor computes it automatically if set to -1.
Fixes in the SMD loader. Still crashes on some files.
Updated animation documentation.
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@236 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2008-11-09 23:17:19 +00:00
|
|
|
|
pcMesh->mNumBones = iNum;
|
|
|
|
|
pcMesh->mBones = new aiBone*[pcMesh->mNumBones];
|
|
|
|
|
iNum = 0;
|
|
|
|
|
for (unsigned int iBone = 0; iBone < asBones.size();++iBone)
|
|
|
|
|
{
|
|
|
|
|
if (aaiBones[iBone].empty())continue;
|
|
|
|
|
aiBone*& bone = pcMesh->mBones[iNum] = new aiBone();
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
ASE: Added WIP support for *SMOOTHSKINMESH elements in ASE/ASC files. Fixes in the ASE loader. Fixed animation parsing. Temporary implementation of target lights and cameras, including animations.
3DS: Fixed transformation problems (Pivot points), added WIP animation support. No target animation yet (cameras, spot lights). Not yet fully tested, but static models that worked before should still work now, except all look correct now :-) (some problems with very large models remaining)
Further work on the IRR and IRRMESH loaders. IRR still WIP, IRRMESH more stable now.
Work on the LWo loader. Added support for the "one-layer-only" mode. Hierarchy bug still unfixed, UV coords bug still unfixed.
Further work on the FindInvalidDataprocess. Improved validation for normals, no false positives anymore.
Further work on the MDR loader, still WIP.
Moved DeterminePType-Step to ScenePreprocessor.
aiAnimation::mDuration is optional now, ScenePreprocessor computes it automatically if set to -1.
Fixes in the SMD loader. Still crashes on some files.
Updated animation documentation.
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@236 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2008-11-09 23:17:19 +00:00
|
|
|
|
bone->mNumWeights = (unsigned int)aaiBones[iBone].size();
|
|
|
|
|
bone->mWeights = new aiVertexWeight[bone->mNumWeights];
|
|
|
|
|
bone->mOffsetMatrix = asBones[iBone].mOffsetMatrix;
|
|
|
|
|
bone->mName.Set( asBones[iBone].mName );
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
ASE: Added WIP support for *SMOOTHSKINMESH elements in ASE/ASC files. Fixes in the ASE loader. Fixed animation parsing. Temporary implementation of target lights and cameras, including animations.
3DS: Fixed transformation problems (Pivot points), added WIP animation support. No target animation yet (cameras, spot lights). Not yet fully tested, but static models that worked before should still work now, except all look correct now :-) (some problems with very large models remaining)
Further work on the IRR and IRRMESH loaders. IRR still WIP, IRRMESH more stable now.
Work on the LWo loader. Added support for the "one-layer-only" mode. Hierarchy bug still unfixed, UV coords bug still unfixed.
Further work on the FindInvalidDataprocess. Improved validation for normals, no false positives anymore.
Further work on the MDR loader, still WIP.
Moved DeterminePType-Step to ScenePreprocessor.
aiAnimation::mDuration is optional now, ScenePreprocessor computes it automatically if set to -1.
Fixes in the SMD loader. Still crashes on some files.
Updated animation documentation.
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@236 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2008-11-09 23:17:19 +00:00
|
|
|
|
asBones[iBone].bIsUsed = true;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
ASE: Added WIP support for *SMOOTHSKINMESH elements in ASE/ASC files. Fixes in the ASE loader. Fixed animation parsing. Temporary implementation of target lights and cameras, including animations.
3DS: Fixed transformation problems (Pivot points), added WIP animation support. No target animation yet (cameras, spot lights). Not yet fully tested, but static models that worked before should still work now, except all look correct now :-) (some problems with very large models remaining)
Further work on the IRR and IRRMESH loaders. IRR still WIP, IRRMESH more stable now.
Work on the LWo loader. Added support for the "one-layer-only" mode. Hierarchy bug still unfixed, UV coords bug still unfixed.
Further work on the FindInvalidDataprocess. Improved validation for normals, no false positives anymore.
Further work on the MDR loader, still WIP.
Moved DeterminePType-Step to ScenePreprocessor.
aiAnimation::mDuration is optional now, ScenePreprocessor computes it automatically if set to -1.
Fixes in the SMD loader. Still crashes on some files.
Updated animation documentation.
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@236 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2008-11-09 23:17:19 +00:00
|
|
|
|
for (unsigned int iWeight = 0; iWeight < bone->mNumWeights;++iWeight)
|
|
|
|
|
{
|
|
|
|
|
bone->mWeights[iWeight].mVertexId = aaiBones[iBone][iWeight].first;
|
|
|
|
|
bone->mWeights[iWeight].mWeight = aaiBones[iBone][iWeight].second;
|
|
|
|
|
}
|
|
|
|
|
++iNum;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
delete[] aaiBones;
|
|
|
|
|
}
|
|
|
|
|
delete[] aaiFaces;
|
|
|
|
|
}
|
2008-11-28 23:02:27 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
// add bone child nodes
|
|
|
|
|
void SMDImporter::AddBoneChildren(aiNode* pcNode, uint32_t iParent)
|
|
|
|
|
{
|
2008-07-10 16:49:01 +00:00
|
|
|
|
ai_assert(NULL != pcNode && 0 == pcNode->mNumChildren && NULL == pcNode->mChildren);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
// first count ...
|
2008-10-13 16:45:48 +00:00
|
|
|
|
for (unsigned int i = 0; i < asBones.size();++i)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
SMD::Bone& bone = asBones[i];
|
2008-06-22 10:09:26 +00:00
|
|
|
|
if (bone.iParent == iParent)++pcNode->mNumChildren;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// now allocate the output array
|
|
|
|
|
pcNode->mChildren = new aiNode*[pcNode->mNumChildren];
|
|
|
|
|
|
|
|
|
|
// and fill all subnodes
|
|
|
|
|
unsigned int qq = 0;
|
2008-10-13 16:45:48 +00:00
|
|
|
|
for (unsigned int i = 0; i < asBones.size();++i)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
SMD::Bone& bone = asBones[i];
|
2008-06-22 10:09:26 +00:00
|
|
|
|
if (bone.iParent != iParent)continue;
|
|
|
|
|
|
|
|
|
|
aiNode* pc = pcNode->mChildren[qq++] = new aiNode();
|
|
|
|
|
pc->mName.Set(bone.mName);
|
|
|
|
|
|
|
|
|
|
// store the local transformation matrix of the bind pose
|
|
|
|
|
pc->mTransformation = bone.sAnim.asKeys[bone.sAnim.iFirstTimeKey].matrix;
|
2008-07-10 16:49:01 +00:00
|
|
|
|
pc->mParent = pcNode;
|
|
|
|
|
|
|
|
|
|
// add children to this node, too
|
|
|
|
|
AddBoneChildren(pc,i);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2008-11-28 23:02:27 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
// create output nodes
|
|
|
|
|
void SMDImporter::CreateOutputNodes()
|
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
pScene->mRootNode = new aiNode();
|
2008-10-19 11:32:33 +00:00
|
|
|
|
if (!(pScene->mFlags & AI_SCENE_FLAGS_INCOMPLETE))
|
2008-07-10 16:49:01 +00:00
|
|
|
|
{
|
|
|
|
|
// create one root node that renders all meshes
|
2008-10-13 16:45:48 +00:00
|
|
|
|
pScene->mRootNode->mNumMeshes = pScene->mNumMeshes;
|
|
|
|
|
pScene->mRootNode->mMeshes = new unsigned int[pScene->mNumMeshes];
|
|
|
|
|
for (unsigned int i = 0; i < pScene->mNumMeshes;++i)
|
|
|
|
|
pScene->mRootNode->mMeshes[i] = i;
|
2008-07-10 16:49:01 +00:00
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
// now add all bones as dummy sub nodes to the graph
|
2008-11-28 23:02:27 +00:00
|
|
|
|
// AddBoneChildren(pScene->mRootNode,(uint32_t)-1);
|
2008-07-10 16:49:01 +00:00
|
|
|
|
|
|
|
|
|
// if we have only one bone we can even remove the root node
|
2008-10-19 11:32:33 +00:00
|
|
|
|
if (pScene->mFlags & AI_SCENE_FLAGS_INCOMPLETE &&
|
2008-10-13 16:45:48 +00:00
|
|
|
|
1 == pScene->mRootNode->mNumChildren)
|
2008-07-10 16:49:01 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
aiNode* pcOldRoot = pScene->mRootNode;
|
|
|
|
|
pScene->mRootNode = pcOldRoot->mChildren[0];
|
2008-07-10 16:49:01 +00:00
|
|
|
|
pcOldRoot->mChildren[0] = NULL;
|
|
|
|
|
delete pcOldRoot;
|
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
|
pScene->mRootNode->mParent = NULL;
|
2008-07-10 16:49:01 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
::strcpy(pScene->mRootNode->mName.data, "<SMD_root>");
|
|
|
|
|
pScene->mRootNode->mName.length = 10;
|
2008-07-10 16:49:01 +00:00
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2008-11-28 23:02:27 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
// create output animations
|
|
|
|
|
void SMDImporter::CreateOutputAnimations()
|
|
|
|
|
{
|
2008-07-10 16:49:01 +00:00
|
|
|
|
unsigned int iNumBones = 0;
|
|
|
|
|
for (std::vector<SMD::Bone>::const_iterator
|
2008-10-13 16:45:48 +00:00
|
|
|
|
i = asBones.begin();
|
|
|
|
|
i != asBones.end();++i)
|
2008-07-10 16:49:01 +00:00
|
|
|
|
{
|
|
|
|
|
if ((*i).bIsUsed)++iNumBones;
|
|
|
|
|
}
|
|
|
|
|
if (!iNumBones)
|
|
|
|
|
{
|
|
|
|
|
// just make sure this case doesn't occur ... (it could occur
|
|
|
|
|
// if the file was invalid)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
|
pScene->mNumAnimations = 1;
|
|
|
|
|
pScene->mAnimations = new aiAnimation*[1];
|
|
|
|
|
aiAnimation*& anim = pScene->mAnimations[0] = new aiAnimation();
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
|
anim->mDuration = dLengthOfAnim;
|
2008-09-30 13:05:48 +00:00
|
|
|
|
anim->mNumChannels = iNumBones;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
anim->mTicksPerSecond = 25.0; // FIXME: is this correct?
|
|
|
|
|
|
2008-09-30 13:05:48 +00:00
|
|
|
|
aiNodeAnim** pp = anim->mChannels = new aiNodeAnim*[anim->mNumChannels];
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
// now build valid keys
|
|
|
|
|
unsigned int a = 0;
|
|
|
|
|
for (std::vector<SMD::Bone>::const_iterator
|
2008-10-13 16:45:48 +00:00
|
|
|
|
i = asBones.begin();
|
|
|
|
|
i != asBones.end();++i)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
|
|
|
|
if (!(*i).bIsUsed)continue;
|
|
|
|
|
|
2008-09-30 13:05:48 +00:00
|
|
|
|
aiNodeAnim* p = pp[a] = new aiNodeAnim();
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
// copy the name of the bone
|
ASE: Added WIP support for *SMOOTHSKINMESH elements in ASE/ASC files. Fixes in the ASE loader. Fixed animation parsing. Temporary implementation of target lights and cameras, including animations.
3DS: Fixed transformation problems (Pivot points), added WIP animation support. No target animation yet (cameras, spot lights). Not yet fully tested, but static models that worked before should still work now, except all look correct now :-) (some problems with very large models remaining)
Further work on the IRR and IRRMESH loaders. IRR still WIP, IRRMESH more stable now.
Work on the LWo loader. Added support for the "one-layer-only" mode. Hierarchy bug still unfixed, UV coords bug still unfixed.
Further work on the FindInvalidDataprocess. Improved validation for normals, no false positives anymore.
Further work on the MDR loader, still WIP.
Moved DeterminePType-Step to ScenePreprocessor.
aiAnimation::mDuration is optional now, ScenePreprocessor computes it automatically if set to -1.
Fixes in the SMD loader. Still crashes on some files.
Updated animation documentation.
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@236 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2008-11-09 23:17:19 +00:00
|
|
|
|
p->mNodeName.Set( i->mName);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
p->mNumRotationKeys = (unsigned int) (*i).sAnim.asKeys.size();
|
|
|
|
|
if (p->mNumRotationKeys)
|
|
|
|
|
{
|
|
|
|
|
p->mNumPositionKeys = p->mNumRotationKeys;
|
|
|
|
|
aiVectorKey* pVecKeys = p->mPositionKeys = new aiVectorKey[p->mNumRotationKeys];
|
|
|
|
|
aiQuatKey* pRotKeys = p->mRotationKeys = new aiQuatKey[p->mNumRotationKeys];
|
|
|
|
|
|
|
|
|
|
for (std::vector<SMD::Bone::Animation::MatrixKey>::const_iterator
|
|
|
|
|
qq = (*i).sAnim.asKeys.begin();
|
|
|
|
|
qq != (*i).sAnim.asKeys.end(); ++qq)
|
|
|
|
|
{
|
|
|
|
|
pRotKeys->mTime = pVecKeys->mTime = (*qq).dTime;
|
|
|
|
|
|
|
|
|
|
// compute the rotation quaternion from the euler angles
|
|
|
|
|
pRotKeys->mValue = aiQuaternion( (*qq).vRot.x, (*qq).vRot.y, (*qq).vRot.z );
|
|
|
|
|
pVecKeys->mValue = (*qq).vPos;
|
|
|
|
|
|
|
|
|
|
++pVecKeys; ++pRotKeys;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
++a;
|
|
|
|
|
|
|
|
|
|
// there are no scaling keys ...
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-11-28 23:02:27 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
void SMDImporter::ComputeAbsoluteBoneTransformations()
|
|
|
|
|
{
|
2008-11-28 23:02:27 +00:00
|
|
|
|
// For each bone: determine the key with the lowest time value
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// theoretically the SMD format should have all keyframes
|
|
|
|
|
// in order. However, I've seen a file where this wasn't true.
|
2008-10-13 16:45:48 +00:00
|
|
|
|
for (unsigned int i = 0; i < asBones.size();++i)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
SMD::Bone& bone = asBones[i];
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
uint32_t iIndex = 0;
|
|
|
|
|
double dMin = 10e10;
|
|
|
|
|
for (unsigned int i = 0; i < bone.sAnim.asKeys.size();++i)
|
|
|
|
|
{
|
|
|
|
|
double d = std::min(bone.sAnim.asKeys[i].dTime,dMin);
|
2008-07-10 16:49:01 +00:00
|
|
|
|
if (d < dMin)
|
|
|
|
|
{
|
|
|
|
|
dMin = d;
|
|
|
|
|
iIndex = i;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
bone.sAnim.iFirstTimeKey = iIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned int iParent = 0;
|
2008-10-13 16:45:48 +00:00
|
|
|
|
while (iParent < asBones.size())
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
for (unsigned int iBone = 0; iBone < asBones.size();++iBone)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
SMD::Bone& bone = asBones[iBone];
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
if (iParent == bone.iParent)
|
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
SMD::Bone& parentBone = asBones[iParent];
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t iIndex = bone.sAnim.iFirstTimeKey;
|
|
|
|
|
const aiMatrix4x4& mat = bone.sAnim.asKeys[iIndex].matrix;
|
|
|
|
|
aiMatrix4x4& matOut = bone.sAnim.asKeys[iIndex].matrixAbsolute;
|
|
|
|
|
|
2008-11-28 23:02:27 +00:00
|
|
|
|
// The same for the parent bone ...
|
2008-06-22 10:09:26 +00:00
|
|
|
|
iIndex = parentBone.sAnim.iFirstTimeKey;
|
2008-11-28 23:02:27 +00:00
|
|
|
|
const aiMatrix4x4& mat2 = parentBone.sAnim.asKeys[iIndex].matrixAbsolute;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
2008-11-28 23:02:27 +00:00
|
|
|
|
// Compute the absolute transformation matrix
|
2008-06-22 10:09:26 +00:00
|
|
|
|
matOut = mat * mat2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
++iParent;
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-28 23:02:27 +00:00
|
|
|
|
// Store the inverse of the absolute transformation matrix
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// of the first key as bone offset matrix
|
2008-10-13 16:45:48 +00:00
|
|
|
|
for (iParent = 0; iParent < asBones.size();++iParent)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
SMD::Bone& bone = asBones[iParent];
|
2008-11-28 23:02:27 +00:00
|
|
|
|
bone.mOffsetMatrix = bone.sAnim.asKeys[bone.sAnim.iFirstTimeKey].matrixAbsolute;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
bone.mOffsetMatrix.Inverse();
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-11-28 23:02:27 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
// create output materials
|
|
|
|
|
void SMDImporter::CreateOutputMaterials()
|
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
pScene->mNumMaterials = (unsigned int)aszTextures.size();
|
|
|
|
|
pScene->mMaterials = new aiMaterial*[std::max(1u, pScene->mNumMaterials)];
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
|
for (unsigned int iMat = 0; iMat < pScene->mNumMaterials;++iMat)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
|
|
|
|
MaterialHelper* pcMat = new MaterialHelper();
|
2008-10-13 16:45:48 +00:00
|
|
|
|
pScene->mMaterials[iMat] = pcMat;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
aiString szName;
|
|
|
|
|
szName.length = (size_t)::sprintf(szName.data,"Texture_%i",iMat);
|
|
|
|
|
pcMat->AddProperty(&szName,AI_MATKEY_NAME);
|
|
|
|
|
|
2008-11-28 23:02:27 +00:00
|
|
|
|
if (aszTextures[iMat].length())
|
|
|
|
|
{
|
|
|
|
|
::strcpy(szName.data, aszTextures[iMat].c_str() );
|
|
|
|
|
szName.length = aszTextures[iMat].length();
|
|
|
|
|
pcMat->AddProperty(&szName,AI_MATKEY_TEXTURE_DIFFUSE(0));
|
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// create a default material if necessary
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if (0 == pScene->mNumMaterials)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
pScene->mNumMaterials = 1;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
MaterialHelper* pcHelper = new MaterialHelper();
|
2008-10-13 16:45:48 +00:00
|
|
|
|
pScene->mMaterials[0] = pcHelper;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
int iMode = (int)aiShadingMode_Gouraud;
|
|
|
|
|
pcHelper->AddProperty<int>(&iMode, 1, AI_MATKEY_SHADING_MODEL);
|
|
|
|
|
|
|
|
|
|
aiColor3D clr;
|
|
|
|
|
clr.b = clr.g = clr.r = 0.7f;
|
|
|
|
|
pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_DIFFUSE);
|
|
|
|
|
pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_SPECULAR);
|
|
|
|
|
|
|
|
|
|
clr.b = clr.g = clr.r = 0.05f;
|
|
|
|
|
pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_AMBIENT);
|
|
|
|
|
|
|
|
|
|
aiString szName;
|
|
|
|
|
szName.Set(AI_DEFAULT_MATERIAL_NAME);
|
|
|
|
|
pcHelper->AddProperty(&szName,AI_MATKEY_NAME);
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-11-28 23:02:27 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
// Parse the file
|
|
|
|
|
void SMDImporter::ParseFile()
|
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
const char* szCurrent = mBuffer;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
// read line per line ...
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
2008-07-10 16:49:01 +00:00
|
|
|
|
if(!SkipSpacesAndLineEnd(szCurrent,&szCurrent)) break;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
// "version <n> \n", <n> should be 1 for hl and hl<68> SMD files
|
2008-11-28 23:02:27 +00:00
|
|
|
|
if (TokenMatch(szCurrent,"version",7))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
|
|
|
|
if(!SkipSpaces(szCurrent,&szCurrent)) break;
|
2011-03-23 14:26:19 +00:00
|
|
|
|
if (1 != strtoul10(szCurrent,&szCurrent))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
|
|
|
|
DefaultLogger::get()->warn("SMD.version is not 1. This "
|
|
|
|
|
"file format is not known. Continuing happily ...");
|
|
|
|
|
}
|
2008-09-12 20:25:11 +00:00
|
|
|
|
continue;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
// "nodes\n" - Starts the node section
|
2008-11-28 23:02:27 +00:00
|
|
|
|
if (TokenMatch(szCurrent,"nodes",5))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
ParseNodesSection(szCurrent,&szCurrent);
|
2008-09-12 20:25:11 +00:00
|
|
|
|
continue;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
// "triangles\n" - Starts the triangle section
|
2008-11-28 23:02:27 +00:00
|
|
|
|
if (TokenMatch(szCurrent,"triangles",9))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
ParseTrianglesSection(szCurrent,&szCurrent);
|
2008-09-12 20:25:11 +00:00
|
|
|
|
continue;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
// "vertexanimation\n" - Starts the vertex animation section
|
2008-11-28 23:02:27 +00:00
|
|
|
|
if (TokenMatch(szCurrent,"vertexanimation",15))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
bHasUVs = false;
|
|
|
|
|
ParseVASection(szCurrent,&szCurrent);
|
2008-09-12 20:25:11 +00:00
|
|
|
|
continue;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
// "skeleton\n" - Starts the skeleton section
|
2008-11-28 23:02:27 +00:00
|
|
|
|
if (TokenMatch(szCurrent,"skeleton",8))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
ParseSkeletonSection(szCurrent,&szCurrent);
|
2008-09-12 20:25:11 +00:00
|
|
|
|
continue;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2008-09-12 20:25:11 +00:00
|
|
|
|
SkipLine(szCurrent,&szCurrent);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2008-11-28 23:02:27 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
unsigned int SMDImporter::GetTextureIndex(const std::string& filename)
|
|
|
|
|
{
|
|
|
|
|
unsigned int iIndex = 0;
|
|
|
|
|
for (std::vector<std::string>::const_iterator
|
2008-10-13 16:45:48 +00:00
|
|
|
|
i = aszTextures.begin();
|
|
|
|
|
i != aszTextures.end();++i,++iIndex)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-11-28 23:02:27 +00:00
|
|
|
|
// case-insensitive ... it's a path
|
2008-06-22 10:09:26 +00:00
|
|
|
|
if (0 == ASSIMP_stricmp ( filename.c_str(),(*i).c_str()))return iIndex;
|
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
|
iIndex = (unsigned int)aszTextures.size();
|
|
|
|
|
aszTextures.push_back(filename);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
return iIndex;
|
|
|
|
|
}
|
2008-11-28 23:02:27 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
// Parse the nodes section of the file
|
|
|
|
|
void SMDImporter::ParseNodesSection(const char* szCurrent,
|
|
|
|
|
const char** szCurrentOut)
|
|
|
|
|
{
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
// "end\n" - Ends the nodes section
|
|
|
|
|
if (0 == ASSIMP_strincmp(szCurrent,"end",3) &&
|
|
|
|
|
IsSpaceOrNewLine(*(szCurrent+3)))
|
|
|
|
|
{
|
|
|
|
|
szCurrent += 4;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
|
ParseNodeInfo(szCurrent,&szCurrent);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
SkipSpacesAndLineEnd(szCurrent,&szCurrent);
|
2008-09-12 20:25:11 +00:00
|
|
|
|
*szCurrentOut = szCurrent;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2008-11-28 23:02:27 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
// Parse the triangles section of the file
|
|
|
|
|
void SMDImporter::ParseTrianglesSection(const char* szCurrent,
|
|
|
|
|
const char** szCurrentOut)
|
|
|
|
|
{
|
2008-11-28 23:02:27 +00:00
|
|
|
|
// Parse a triangle, parse another triangle, parse the next triangle ...
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// and so on until we reach a token that looks quite similar to "end"
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
2008-07-10 16:49:01 +00:00
|
|
|
|
if(!SkipSpacesAndLineEnd(szCurrent,&szCurrent)) break;
|
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// "end\n" - Ends the triangles section
|
2008-11-28 23:02:27 +00:00
|
|
|
|
if (TokenMatch(szCurrent,"end",3))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
break;
|
2008-10-13 16:45:48 +00:00
|
|
|
|
ParseTriangle(szCurrent,&szCurrent);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
SkipSpacesAndLineEnd(szCurrent,&szCurrent);
|
2008-09-12 20:25:11 +00:00
|
|
|
|
*szCurrentOut = szCurrent;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
// Parse the vertex animation section of the file
|
|
|
|
|
void SMDImporter::ParseVASection(const char* szCurrent,
|
|
|
|
|
const char** szCurrentOut)
|
|
|
|
|
{
|
|
|
|
|
unsigned int iCurIndex = 0;
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
2008-07-10 16:49:01 +00:00
|
|
|
|
if(!SkipSpacesAndLineEnd(szCurrent,&szCurrent)) break;
|
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// "end\n" - Ends the "vertexanimation" section
|
2008-11-28 23:02:27 +00:00
|
|
|
|
if (TokenMatch(szCurrent,"end",3))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
break;
|
2008-11-28 23:02:27 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// "time <n>\n"
|
2008-11-28 23:02:27 +00:00
|
|
|
|
if (TokenMatch(szCurrent,"time",4))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
|
|
|
|
// NOTE: The doc says that time values COULD be negative ...
|
2008-11-28 23:02:27 +00:00
|
|
|
|
// NOTE2: this is the shape key -> valve docs
|
2008-06-22 10:09:26 +00:00
|
|
|
|
int iTime = 0;
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if(!ParseSignedInt(szCurrent,&szCurrent,iTime) || configFrameID != (unsigned int)iTime)break;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
SkipLine(szCurrent,&szCurrent);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2008-11-28 23:02:27 +00:00
|
|
|
|
if(0 == iCurIndex)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
asTriangles.push_back(SMD::Face());
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2008-11-28 23:02:27 +00:00
|
|
|
|
if (++iCurIndex == 3)iCurIndex = 0;
|
|
|
|
|
ParseVertex(szCurrent,&szCurrent,asTriangles.back().avVertices[iCurIndex],true);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-28 23:02:27 +00:00
|
|
|
|
if (iCurIndex != 2 && !asTriangles.empty())
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-11-28 23:02:27 +00:00
|
|
|
|
// we want to no degenerates, so throw this triangle away
|
|
|
|
|
asTriangles.pop_back();
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SkipSpacesAndLineEnd(szCurrent,&szCurrent);
|
2008-09-12 20:25:11 +00:00
|
|
|
|
*szCurrentOut = szCurrent;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
// Parse the skeleton section of the file
|
|
|
|
|
void SMDImporter::ParseSkeletonSection(const char* szCurrent,
|
|
|
|
|
const char** szCurrentOut)
|
|
|
|
|
{
|
|
|
|
|
int iTime = 0;
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
2008-07-10 16:49:01 +00:00
|
|
|
|
if(!SkipSpacesAndLineEnd(szCurrent,&szCurrent)) break;
|
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// "end\n" - Ends the skeleton section
|
2008-11-28 23:02:27 +00:00
|
|
|
|
if (TokenMatch(szCurrent,"end",3))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
break;
|
2008-11-28 23:02:27 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// "time <n>\n" - Specifies the current animation frame
|
2008-11-28 23:02:27 +00:00
|
|
|
|
else if (TokenMatch(szCurrent,"time",4))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
|
|
|
|
// NOTE: The doc says that time values COULD be negative ...
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if(!ParseSignedInt(szCurrent,&szCurrent,iTime))break;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
|
iSmallestFrame = std::min(iSmallestFrame,iTime);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
SkipLine(szCurrent,&szCurrent);
|
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
|
else ParseSkeletonElement(szCurrent,&szCurrent,iTime);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
*szCurrentOut = szCurrent;
|
|
|
|
|
}
|
2008-08-13 23:46:46 +00:00
|
|
|
|
|
2008-11-28 23:02:27 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-08-13 23:46:46 +00:00
|
|
|
|
#define SMDI_PARSE_RETURN { \
|
|
|
|
|
SkipLine(szCurrent,&szCurrent); \
|
|
|
|
|
*szCurrentOut = szCurrent; \
|
|
|
|
|
return; \
|
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
// Parse a node line
|
|
|
|
|
void SMDImporter::ParseNodeInfo(const char* szCurrent,
|
|
|
|
|
const char** szCurrentOut)
|
|
|
|
|
{
|
|
|
|
|
unsigned int iBone = 0;
|
2008-07-10 16:49:01 +00:00
|
|
|
|
SkipSpacesAndLineEnd(szCurrent,&szCurrent);
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if(!ParseUnsignedInt(szCurrent,&szCurrent,iBone) || !SkipSpaces(szCurrent,&szCurrent))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing bone index");
|
2008-08-13 23:46:46 +00:00
|
|
|
|
SMDI_PARSE_RETURN;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
// add our bone to the list
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if (iBone >= asBones.size())asBones.resize(iBone+1);
|
|
|
|
|
SMD::Bone& bone = asBones[iBone];
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
bool bQuota = true;
|
|
|
|
|
if ('\"' != *szCurrent)
|
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
LogWarning("Bone name is expcted to be enclosed in "
|
2008-06-22 10:09:26 +00:00
|
|
|
|
"double quotation marks. ");
|
|
|
|
|
bQuota = false;
|
|
|
|
|
}
|
|
|
|
|
else ++szCurrent;
|
|
|
|
|
|
|
|
|
|
const char* szEnd = szCurrent;
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
if (bQuota && '\"' == *szEnd)
|
|
|
|
|
{
|
|
|
|
|
iBone = (unsigned int)(szEnd - szCurrent);
|
|
|
|
|
++szEnd;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (IsSpaceOrNewLine(*szEnd))
|
|
|
|
|
{
|
|
|
|
|
iBone = (unsigned int)(szEnd - szCurrent);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (!(*szEnd))
|
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing bone name");
|
2008-08-13 23:46:46 +00:00
|
|
|
|
SMDI_PARSE_RETURN;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
++szEnd;
|
|
|
|
|
}
|
|
|
|
|
bone.mName = std::string(szCurrent,iBone);
|
2008-07-10 16:49:01 +00:00
|
|
|
|
szCurrent = szEnd;
|
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// the only negative bone parent index that could occur is -1 AFAIK
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if(!ParseSignedInt(szCurrent,&szCurrent,(int&)bone.iParent))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing bone parent index. Assuming -1");
|
2008-08-13 23:46:46 +00:00
|
|
|
|
SMDI_PARSE_RETURN;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// go to the beginning of the next line
|
2008-08-13 23:46:46 +00:00
|
|
|
|
SMDI_PARSE_RETURN;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2008-11-28 23:02:27 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
// Parse a skeleton element
|
|
|
|
|
void SMDImporter::ParseSkeletonElement(const char* szCurrent,
|
|
|
|
|
const char** szCurrentOut,int iTime)
|
|
|
|
|
{
|
|
|
|
|
aiVector3D vPos;
|
|
|
|
|
aiVector3D vRot;
|
|
|
|
|
|
|
|
|
|
unsigned int iBone = 0;
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if(!ParseUnsignedInt(szCurrent,&szCurrent,iBone))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
|
|
|
|
DefaultLogger::get()->error("Unexpected EOF/EOL while parsing bone index");
|
2008-08-13 23:46:46 +00:00
|
|
|
|
SMDI_PARSE_RETURN;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if (iBone >= asBones.size())
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
LogErrorNoThrow("Bone index in skeleton section is out of range");
|
2008-08-13 23:46:46 +00:00
|
|
|
|
SMDI_PARSE_RETURN;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
|
SMD::Bone& bone = asBones[iBone];
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
bone.sAnim.asKeys.push_back(SMD::Bone::Animation::MatrixKey());
|
|
|
|
|
SMD::Bone::Animation::MatrixKey& key = bone.sAnim.asKeys.back();
|
|
|
|
|
|
|
|
|
|
key.dTime = (double)iTime;
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vPos.x))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.pos.x");
|
2008-08-13 23:46:46 +00:00
|
|
|
|
SMDI_PARSE_RETURN;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vPos.y))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.pos.y");
|
2008-08-13 23:46:46 +00:00
|
|
|
|
SMDI_PARSE_RETURN;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vPos.z))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.pos.z");
|
2008-08-13 23:46:46 +00:00
|
|
|
|
SMDI_PARSE_RETURN;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vRot.x))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.rot.x");
|
2008-08-13 23:46:46 +00:00
|
|
|
|
SMDI_PARSE_RETURN;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vRot.y))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.rot.y");
|
2008-08-13 23:46:46 +00:00
|
|
|
|
SMDI_PARSE_RETURN;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vRot.z))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.rot.z");
|
2008-08-13 23:46:46 +00:00
|
|
|
|
SMDI_PARSE_RETURN;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
// build the transformation matrix of the key
|
2008-11-28 23:02:27 +00:00
|
|
|
|
key.matrix.FromEulerAnglesXYZ(vRot.x,vRot.y,vRot.z);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
|
|
|
|
aiMatrix4x4 mTemp;
|
|
|
|
|
mTemp.a4 = vPos.x;
|
|
|
|
|
mTemp.b4 = vPos.y;
|
|
|
|
|
mTemp.c4 = vPos.z;
|
|
|
|
|
key.matrix = key.matrix * mTemp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// go to the beginning of the next line
|
2008-08-13 23:46:46 +00:00
|
|
|
|
SMDI_PARSE_RETURN;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2008-11-28 23:02:27 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
// Parse a triangle
|
|
|
|
|
void SMDImporter::ParseTriangle(const char* szCurrent,
|
|
|
|
|
const char** szCurrentOut)
|
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
asTriangles.push_back(SMD::Face());
|
|
|
|
|
SMD::Face& face = asTriangles.back();
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
if(!SkipSpaces(szCurrent,&szCurrent))
|
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing a triangle");
|
2008-06-22 10:09:26 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// read the texture file name
|
2008-07-10 16:49:01 +00:00
|
|
|
|
const char* szLast = szCurrent;
|
|
|
|
|
while (!IsSpaceOrNewLine(*szCurrent++));
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
2008-11-28 23:02:27 +00:00
|
|
|
|
// ... and get the index that belongs to this file name
|
|
|
|
|
face.iTexture = GetTextureIndex(std::string(szLast,(uintptr_t)szCurrent-(uintptr_t)szLast));
|
2008-07-10 16:49:01 +00:00
|
|
|
|
|
2008-11-28 23:02:27 +00:00
|
|
|
|
SkipSpacesAndLineEnd(szCurrent,&szCurrent);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
// load three vertices
|
|
|
|
|
for (unsigned int iVert = 0; iVert < 3;++iVert)
|
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
ParseVertex(szCurrent,&szCurrent,
|
2008-06-22 10:09:26 +00:00
|
|
|
|
face.avVertices[iVert]);
|
|
|
|
|
}
|
2008-07-10 16:49:01 +00:00
|
|
|
|
*szCurrentOut = szCurrent;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2008-11-28 23:02:27 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
// Parse a float
|
|
|
|
|
bool SMDImporter::ParseFloat(const char* szCurrent,
|
|
|
|
|
const char** szCurrentOut, float& out)
|
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if(!SkipSpaces(&szCurrent))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
return false;
|
2008-09-05 13:21:01 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
*szCurrentOut = fast_atof_move(szCurrent,out);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2008-11-28 23:02:27 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
// Parse an unsigned int
|
|
|
|
|
bool SMDImporter::ParseUnsignedInt(const char* szCurrent,
|
2008-10-13 16:45:48 +00:00
|
|
|
|
const char** szCurrentOut, unsigned int& out)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if(!SkipSpaces(&szCurrent))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
return false;
|
2008-09-05 13:21:01 +00:00
|
|
|
|
|
2011-03-23 14:26:19 +00:00
|
|
|
|
out = strtoul10(szCurrent,szCurrentOut);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2008-11-28 23:02:27 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
// Parse a signed int
|
|
|
|
|
bool SMDImporter::ParseSignedInt(const char* szCurrent,
|
2008-10-13 16:45:48 +00:00
|
|
|
|
const char** szCurrentOut, int& out)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if(!SkipSpaces(&szCurrent))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2011-03-23 14:26:19 +00:00
|
|
|
|
out = strtol10(szCurrent,szCurrentOut);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2008-11-28 23:02:27 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
// Parse a vertex
|
|
|
|
|
void SMDImporter::ParseVertex(const char* szCurrent,
|
|
|
|
|
const char** szCurrentOut, SMD::Vertex& vertex,
|
|
|
|
|
bool bVASection /*= false*/)
|
|
|
|
|
{
|
ASE: Added WIP support for *SMOOTHSKINMESH elements in ASE/ASC files. Fixes in the ASE loader. Fixed animation parsing. Temporary implementation of target lights and cameras, including animations.
3DS: Fixed transformation problems (Pivot points), added WIP animation support. No target animation yet (cameras, spot lights). Not yet fully tested, but static models that worked before should still work now, except all look correct now :-) (some problems with very large models remaining)
Further work on the IRR and IRRMESH loaders. IRR still WIP, IRRMESH more stable now.
Work on the LWo loader. Added support for the "one-layer-only" mode. Hierarchy bug still unfixed, UV coords bug still unfixed.
Further work on the FindInvalidDataprocess. Improved validation for normals, no false positives anymore.
Further work on the MDR loader, still WIP.
Moved DeterminePType-Step to ScenePreprocessor.
aiAnimation::mDuration is optional now, ScenePreprocessor computes it automatically if set to -1.
Fixes in the SMD loader. Still crashes on some files.
Updated animation documentation.
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@236 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2008-11-09 23:17:19 +00:00
|
|
|
|
if (SkipSpaces(&szCurrent) && IsLineEnd(*szCurrent))
|
|
|
|
|
{
|
|
|
|
|
SkipSpacesAndLineEnd(szCurrent,&szCurrent);
|
|
|
|
|
return ParseVertex(szCurrent,szCurrentOut,vertex,bVASection);
|
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if(!ParseSignedInt(szCurrent,&szCurrent,(int&)vertex.iParentNode))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.parent");
|
2008-08-13 23:46:46 +00:00
|
|
|
|
SMDI_PARSE_RETURN;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.pos.x))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.pos.x");
|
2008-08-13 23:46:46 +00:00
|
|
|
|
SMDI_PARSE_RETURN;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.pos.y))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.pos.y");
|
2008-08-13 23:46:46 +00:00
|
|
|
|
SMDI_PARSE_RETURN;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.pos.z))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.pos.z");
|
2008-08-13 23:46:46 +00:00
|
|
|
|
SMDI_PARSE_RETURN;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.nor.x))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.nor.x");
|
2008-08-13 23:46:46 +00:00
|
|
|
|
SMDI_PARSE_RETURN;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.nor.y))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.nor.y");
|
2008-08-13 23:46:46 +00:00
|
|
|
|
SMDI_PARSE_RETURN;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.nor.z))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.nor.z");
|
2008-08-13 23:46:46 +00:00
|
|
|
|
SMDI_PARSE_RETURN;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-08-13 23:46:46 +00:00
|
|
|
|
if (bVASection)SMDI_PARSE_RETURN;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.uv.x))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.uv.x");
|
2008-08-13 23:46:46 +00:00
|
|
|
|
SMDI_PARSE_RETURN;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.uv.y))
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.uv.y");
|
2008-08-13 23:46:46 +00:00
|
|
|
|
SMDI_PARSE_RETURN;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// now read the number of bones affecting this vertex
|
|
|
|
|
// all elements from now are fully optional, we don't need them
|
|
|
|
|
unsigned int iSize = 0;
|
2008-10-13 16:45:48 +00:00
|
|
|
|
if(!ParseUnsignedInt(szCurrent,&szCurrent,iSize))SMDI_PARSE_RETURN;
|
2008-09-12 20:25:11 +00:00
|
|
|
|
vertex.aiBoneLinks.resize(iSize,std::pair<unsigned int, float>(0,0.0f));
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
for (std::vector<std::pair<unsigned int, float> >::iterator
|
|
|
|
|
i = vertex.aiBoneLinks.begin();
|
|
|
|
|
i != vertex.aiBoneLinks.end();++i)
|
|
|
|
|
{
|
2008-11-28 23:02:27 +00:00
|
|
|
|
if(!ParseUnsignedInt(szCurrent,&szCurrent,(*i).first))
|
|
|
|
|
SMDI_PARSE_RETURN;
|
|
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(*i).second))
|
|
|
|
|
SMDI_PARSE_RETURN;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// go to the beginning of the next line
|
2008-08-13 23:46:46 +00:00
|
|
|
|
SMDI_PARSE_RETURN;
|
2008-09-12 20:25:11 +00:00
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
|
|
|
|
|
#endif // !! ASSIMP_BUILD_NO_SMD_IMPORTER
|