2008-05-09 17:24:28 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
2012-02-03 03:38:30 +00:00
|
|
|
Open Asset Import Library (assimp)
|
2008-05-09 17:24:28 +00:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2012-02-03 03:38:30 +00:00
|
|
|
Copyright (c) 2006-2012, assimp team
|
2008-05-09 17:24:28 +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-05-09 17:24:28 +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-05-09 17:24:28 +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.
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
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 ASELoader.cpp
|
|
|
|
* @brief Implementation of the ASE 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_ASE_IMPORTER
|
2008-10-13 16:45:48 +00:00
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
// internal headers
|
2008-05-09 17:24:28 +00:00
|
|
|
#include "ASELoader.h"
|
2008-06-15 10:27:08 +00:00
|
|
|
#include "StringComparison.h"
|
2008-10-31 19:32:00 +00:00
|
|
|
#include "SkeletonMeshBuilder.h"
|
2008-11-16 21:56:45 +00:00
|
|
|
#include "TargetAnimation.h"
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
// utilities
|
2008-05-30 23:01:25 +00:00
|
|
|
#include "fast_atof.h"
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
using namespace Assimp;
|
|
|
|
using namespace Assimp::ASE;
|
|
|
|
|
2012-04-22 22:26:26 +00:00
|
|
|
static const aiImporterDesc desc = {
|
|
|
|
"ASE Importer",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"Similar to 3DS but text-encoded",
|
|
|
|
aiImporterFlags_SupportTextFlavour,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
"ase ask"
|
|
|
|
};
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Constructor to be privately used by Importer
|
|
|
|
ASEImporter::ASEImporter()
|
2009-01-18 23:48:25 +00:00
|
|
|
{}
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Destructor, private as well
|
|
|
|
ASEImporter::~ASEImporter()
|
2009-01-18 23:48:25 +00:00
|
|
|
{}
|
|
|
|
|
2008-05-09 17:24:28 +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 ASEImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool cs) const
|
2008-05-09 17:24:28 +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
|
|
|
// check file extension
|
|
|
|
const std::string extension = GetExtension(pFile);
|
|
|
|
|
2009-04-09 23:31:13 +00:00
|
|
|
if( extension == "ase" || extension == "ask")
|
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
|
|
|
return true;
|
|
|
|
|
|
|
|
if ((!extension.length() || cs) && pIOHandler) {
|
|
|
|
const char* tokens[] = {"*3dsmax_asciiexport"};
|
|
|
|
return SearchFileHeaderForToken(pIOHandler,pFile,tokens,1);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2012-04-22 22:26:26 +00:00
|
|
|
// Loader meta information
|
|
|
|
const aiImporterDesc* ASEImporter::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;
|
2008-10-27 00:36:26 +00:00
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-10-27 00:36:26 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Setup configuration options
|
|
|
|
void ASEImporter::SetupProperties(const Importer* pImp)
|
|
|
|
{
|
|
|
|
configRecomputeNormals = (pImp->GetPropertyInteger(
|
2009-01-18 23:48:25 +00:00
|
|
|
AI_CONFIG_IMPORT_ASE_RECONSTRUCT_NORMALS,1) ? true : false);
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-10-27 00:36:26 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Imports the given file into the given scene structure.
|
2008-10-31 19:32:00 +00:00
|
|
|
void ASEImporter::InternReadFile( const std::string& pFile,
|
|
|
|
aiScene* pScene, IOSystem* pIOHandler)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-07-30 23:00:25 +00:00
|
|
|
boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile, "rb"));
|
2008-05-09 17:24:28 +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 ASE file " + pFile + ".");
|
2009-08-21 22:49:58 +00:00
|
|
|
}
|
2008-08-10 23:58:21 +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
|
|
|
// Allocate storage and copy the contents of the file to a memory buffer
|
2009-08-21 22:49:58 +00:00
|
|
|
std::vector<char> mBuffer2;
|
|
|
|
TextFileToBuffer(file.get(),mBuffer2);
|
2008-08-10 23:58:21 +00:00
|
|
|
|
|
|
|
this->mBuffer = &mBuffer2[0];
|
2008-07-18 20:29:46 +00:00
|
|
|
this->pcScene = pScene;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2009-03-15 00:40:30 +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
|
|
|
// Guess the file format by looking at the extension
|
|
|
|
// ASC is considered to be the older format 110,
|
|
|
|
// ASE is the actual version 200 (that is currently written by max)
|
2009-03-15 00:40:30 +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
|
|
|
unsigned int defaultFormat;
|
|
|
|
std::string::size_type s = pFile.length()-1;
|
2009-08-21 22:49:58 +00:00
|
|
|
switch (pFile.c_str()[s]) {
|
|
|
|
|
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
|
|
|
case 'C':
|
|
|
|
case 'c':
|
|
|
|
defaultFormat = AI_ASE_OLD_FILE_FORMAT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
defaultFormat = AI_ASE_NEW_FILE_FORMAT;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Construct an ASE parser and parse the file
|
|
|
|
ASE::Parser parser(mBuffer,defaultFormat);
|
2008-10-22 20:06:16 +00:00
|
|
|
mParser = &parser;
|
|
|
|
mParser->Parse();
|
2008-08-10 23:58:21 +00:00
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Check whether we god at least one mesh. If we did - generate
|
2008-10-31 19:32:00 +00:00
|
|
|
// materials and copy meshes.
|
2009-03-15 00:40:30 +00:00
|
|
|
// ------------------------------------------------------------------
|
2009-08-21 22:49:58 +00:00
|
|
|
if ( !mParser->m_vMeshes.empty()) {
|
|
|
|
|
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 absolutely no material has been loaded from the file
|
2008-10-31 19:32:00 +00:00
|
|
|
// we need to generate a default material
|
|
|
|
GenerateDefaultMaterial();
|
|
|
|
|
|
|
|
// process all meshes
|
|
|
|
bool tookNormals = false;
|
|
|
|
std::vector<aiMesh*> avOutMeshes;
|
|
|
|
avOutMeshes.reserve(mParser->m_vMeshes.size()*2);
|
2009-03-15 00:40:30 +00:00
|
|
|
for (std::vector<ASE::Mesh>::iterator i = mParser->m_vMeshes.begin();i != mParser->m_vMeshes.end();++i) {
|
2009-08-21 22:49:58 +00:00
|
|
|
if ((*i).bSkip) {
|
|
|
|
continue;
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
BuildUniqueRepresentation(*i);
|
2008-08-28 17:35:36 +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
|
|
|
// Need to generate proper vertex normals if necessary
|
2009-08-21 22:49:58 +00:00
|
|
|
if(GenerateNormals(*i)) {
|
2008-10-31 19:32:00 +00:00
|
|
|
tookNormals = true;
|
2009-08-21 22:49:58 +00:00
|
|
|
}
|
2008-05-28 21:05:05 +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
|
|
|
// Convert all meshes to aiMesh objects
|
2008-10-31 19:32:00 +00:00
|
|
|
ConvertMeshes(*i,avOutMeshes);
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
if (tookNormals) {
|
2008-10-31 19:32:00 +00:00
|
|
|
DefaultLogger::get()->debug("ASE: Taking normals from the file. Use "
|
2009-03-15 00:40:30 +00:00
|
|
|
"the AI_CONFIG_IMPORT_ASE_RECONSTRUCT_NORMALS setting if you "
|
2008-10-31 19:32:00 +00:00
|
|
|
"experience problems");
|
|
|
|
}
|
2008-08-06 23:01:38 +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
|
|
|
// Now build the output mesh list. Remove dummies
|
2008-10-31 19:32:00 +00:00
|
|
|
pScene->mNumMeshes = (unsigned int)avOutMeshes.size();
|
|
|
|
aiMesh** pp = pScene->mMeshes = new aiMesh*[pScene->mNumMeshes];
|
2009-03-15 00:40:30 +00:00
|
|
|
for (std::vector<aiMesh*>::const_iterator i = avOutMeshes.begin();i != avOutMeshes.end();++i) {
|
2009-08-21 22:49:58 +00:00
|
|
|
if (!(*i)->mNumFaces) {
|
|
|
|
continue;
|
|
|
|
}
|
2008-10-31 19:32:00 +00:00
|
|
|
*pp++ = *i;
|
|
|
|
}
|
|
|
|
pScene->mNumMeshes = (unsigned int)(pp - pScene->mMeshes);
|
2008-05-30 23:01:25 +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
|
|
|
// Build final material indices (remove submaterials and setup
|
2008-10-31 19:32:00 +00:00
|
|
|
// the final list)
|
|
|
|
BuildMaterialIndices();
|
2008-08-10 23:58:21 +00:00
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
// ------------------------------------------------------------------
|
2008-10-31 19:32:00 +00:00
|
|
|
// Copy all scene graph nodes - lights, cameras, dummies and meshes
|
2010-03-23 18:22:45 +00:00
|
|
|
// into one huge list.
|
2009-03-15 00:40:30 +00:00
|
|
|
//------------------------------------------------------------------
|
2010-03-23 18:22:45 +00:00
|
|
|
std::vector<BaseNode*> nodes;
|
2008-10-31 19:32:00 +00:00
|
|
|
nodes.reserve(mParser->m_vMeshes.size() +mParser->m_vLights.size()
|
|
|
|
+ mParser->m_vCameras.size() + mParser->m_vDummies.size());
|
|
|
|
|
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
|
|
|
// Lights
|
2008-10-31 19:32:00 +00:00
|
|
|
for (std::vector<ASE::Light>::iterator it = mParser->m_vLights.begin(),
|
|
|
|
end = mParser->m_vLights.end();it != end; ++it)nodes.push_back(&(*it));
|
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
|
|
|
// Cameras
|
2008-10-31 19:32:00 +00:00
|
|
|
for (std::vector<ASE::Camera>::iterator it = mParser->m_vCameras.begin(),
|
|
|
|
end = mParser->m_vCameras.end();it != end; ++it)nodes.push_back(&(*it));
|
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
|
|
|
// Meshes
|
2008-10-31 19:32:00 +00:00
|
|
|
for (std::vector<ASE::Mesh>::iterator it = mParser->m_vMeshes.begin(),
|
|
|
|
end = mParser->m_vMeshes.end();it != end; ++it)nodes.push_back(&(*it));
|
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
|
|
|
// Dummies
|
|
|
|
for (std::vector<ASE::Dummy>::iterator it = mParser->m_vDummies.begin(),
|
|
|
|
end = mParser->m_vDummies.end();it != end; ++it)nodes.push_back(&(*it));
|
2008-07-18 20:29:46 +00:00
|
|
|
|
2008-08-10 23:58:21 +00:00
|
|
|
// build the final node graph
|
2010-03-23 18:22:45 +00:00
|
|
|
BuildNodes(nodes);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-08-10 23:58:21 +00:00
|
|
|
// build output animations
|
2010-03-23 18:22:45 +00:00
|
|
|
BuildAnimations(nodes);
|
2008-10-22 20:06:16 +00:00
|
|
|
|
|
|
|
// build output cameras
|
|
|
|
BuildCameras();
|
|
|
|
|
|
|
|
// build output lights
|
|
|
|
BuildLights();
|
2008-10-31 19:32:00 +00:00
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
// ------------------------------------------------------------------
|
2008-10-31 19:32:00 +00:00
|
|
|
// If we have no meshes use the SkeletonMeshBuilder helper class
|
|
|
|
// to build a mesh for the animation skeleton
|
2009-03-15 00:40:30 +00:00
|
|
|
// FIXME: very strange results
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
if (!pScene->mNumMeshes) {
|
2008-10-31 19:32:00 +00:00
|
|
|
pScene->mFlags |= AI_SCENE_FLAGS_INCOMPLETE;
|
|
|
|
SkeletonMeshBuilder skeleton(pScene);
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-06-03 21:50:53 +00:00
|
|
|
void ASEImporter::GenerateDefaultMaterial()
|
|
|
|
{
|
2008-10-22 20:06:16 +00:00
|
|
|
ai_assert(NULL != mParser);
|
2008-06-03 21:50:53 +00:00
|
|
|
|
2008-07-18 20:29:46 +00:00
|
|
|
bool bHas = false;
|
2009-03-15 00:40:30 +00:00
|
|
|
for (std::vector<ASE::Mesh>::iterator i = mParser->m_vMeshes.begin();i != mParser->m_vMeshes.end();++i) {
|
2008-07-18 20:29:46 +00:00
|
|
|
if ((*i).bSkip)continue;
|
2009-03-15 00:40:30 +00:00
|
|
|
if (ASE::Face::DEFAULT_MATINDEX == (*i).iMaterialIndex) {
|
2008-10-22 20:06:16 +00:00
|
|
|
(*i).iMaterialIndex = (unsigned int)mParser->m_vMaterials.size();
|
2008-07-18 20:29:46 +00:00
|
|
|
bHas = true;
|
|
|
|
}
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
if (bHas || mParser->m_vMaterials.empty()) {
|
2008-10-27 00:36:26 +00:00
|
|
|
// add a simple material without submaterials to the parser's list
|
2008-10-22 20:06:16 +00:00
|
|
|
mParser->m_vMaterials.push_back ( ASE::Material() );
|
|
|
|
ASE::Material& mat = mParser->m_vMaterials.back();
|
2008-07-18 20:29:46 +00:00
|
|
|
|
2008-10-27 00:36:26 +00:00
|
|
|
mat.mDiffuse = aiColor3D(0.6f,0.6f,0.6f);
|
2008-07-18 20:29:46 +00:00
|
|
|
mat.mSpecular = aiColor3D(1.0f,1.0f,1.0f);
|
2008-10-27 00:36:26 +00:00
|
|
|
mat.mAmbient = aiColor3D(0.05f,0.05f,0.05f);
|
2008-10-31 19:32:00 +00:00
|
|
|
mat.mShading = Discreet3DS::Gouraud;
|
2008-10-27 00:36:26 +00:00
|
|
|
mat.mName = AI_DEFAULT_MATERIAL_NAME;
|
2008-07-18 20:29:46 +00:00
|
|
|
}
|
|
|
|
}
|
2008-10-22 20:06:16 +00:00
|
|
|
|
2008-07-18 20:29:46 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2010-03-23 18:22:45 +00:00
|
|
|
void ASEImporter::BuildAnimations(const std::vector<BaseNode*>& nodes)
|
2008-07-18 20:29:46 +00:00
|
|
|
{
|
|
|
|
// check whether we have at least one mesh which has animations
|
2010-03-23 18:22:45 +00:00
|
|
|
std::vector<ASE::BaseNode*>::const_iterator i = nodes.begin();
|
2008-07-18 20:29:46 +00:00
|
|
|
unsigned int iNum = 0;
|
2009-03-15 00:40:30 +00:00
|
|
|
for (;i != nodes.end();++i) {
|
|
|
|
|
2008-10-31 19:32:00 +00:00
|
|
|
// TODO: Implement Bezier & TCB support
|
2009-03-15 00:40:30 +00:00
|
|
|
if ((*i)->mAnim.mPositionType != ASE::Animation::TRACK) {
|
2008-10-31 19:32:00 +00:00
|
|
|
DefaultLogger::get()->warn("ASE: Position controller uses Bezier/TCB keys. "
|
|
|
|
"This is not supported.");
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
if ((*i)->mAnim.mRotationType != ASE::Animation::TRACK) {
|
2008-10-31 19:32:00 +00:00
|
|
|
DefaultLogger::get()->warn("ASE: Rotation controller uses Bezier/TCB keys. "
|
|
|
|
"This is not supported.");
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
if ((*i)->mAnim.mScalingType != ASE::Animation::TRACK) {
|
2008-10-31 19:32:00 +00:00
|
|
|
DefaultLogger::get()->warn("ASE: Position controller uses Bezier/TCB keys. "
|
|
|
|
"This is not supported.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// We compare against 1 here - firstly one key is not
|
|
|
|
// really an animation and secondly MAX writes dummies
|
|
|
|
// that represent the node transformation.
|
2009-03-15 00:40:30 +00:00
|
|
|
if ((*i)->mAnim.akeyPositions.size()>1 || (*i)->mAnim.akeyRotations.size()>1 || (*i)->mAnim.akeyScaling.size()>1){
|
2008-11-16 21:56:45 +00:00
|
|
|
++iNum;
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
if ((*i)->mTargetAnim.akeyPositions.size() > 1 && is_not_qnan( (*i)->mTargetPosition.x )) {
|
2008-07-18 20:29:46 +00:00
|
|
|
++iNum;
|
2008-10-31 19:32:00 +00:00
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
if (iNum) {
|
2008-10-22 20:06:16 +00:00
|
|
|
// Generate a new animation channel and setup everything for it
|
|
|
|
pcScene->mNumAnimations = 1;
|
2008-10-31 19:32:00 +00:00
|
|
|
pcScene->mAnimations = new aiAnimation*[1];
|
|
|
|
aiAnimation* pcAnim = pcScene->mAnimations[0] = new aiAnimation();
|
|
|
|
pcAnim->mNumChannels = iNum;
|
|
|
|
pcAnim->mChannels = new aiNodeAnim*[iNum];
|
2008-10-22 20:06:16 +00:00
|
|
|
pcAnim->mTicksPerSecond = mParser->iFrameSpeed * mParser->iTicksPerFrame;
|
2008-07-18 20:29:46 +00:00
|
|
|
|
|
|
|
iNum = 0;
|
2008-10-31 19:32:00 +00:00
|
|
|
|
2008-10-22 20:06:16 +00:00
|
|
|
// Now iterate through all meshes and collect all data we can find
|
2009-03-15 00:40:30 +00:00
|
|
|
for (i = nodes.begin();i != nodes.end();++i) {
|
|
|
|
|
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
|
|
|
ASE::BaseNode* me = *i;
|
2009-03-15 00:40:30 +00:00
|
|
|
if ( me->mTargetAnim.akeyPositions.size() > 1 && is_not_qnan( me->mTargetPosition.x )) {
|
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
|
|
|
// Generate an extra channel for the camera/light target.
|
|
|
|
// BuildNodes() does also generate an extra node, named
|
|
|
|
// <baseName>.Target.
|
|
|
|
aiNodeAnim* nd = pcAnim->mChannels[iNum++] = new aiNodeAnim();
|
|
|
|
nd->mNodeName.Set(me->mName + ".Target");
|
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
// If there is no input position channel we will need
|
|
|
|
// to supply the default position from the node's
|
|
|
|
// local transformation matrix.
|
|
|
|
/*TargetAnimationHelper helper;
|
|
|
|
if (me->mAnim.akeyPositions.empty())
|
|
|
|
{
|
|
|
|
aiMatrix4x4& mat = (*i)->mTransform;
|
|
|
|
helper.SetFixedMainAnimationChannel(aiVector3D(
|
|
|
|
mat.a4, mat.b4, mat.c4));
|
|
|
|
}
|
|
|
|
else helper.SetMainAnimationChannel (&me->mAnim.akeyPositions);
|
|
|
|
helper.SetTargetAnimationChannel (&me->mTargetAnim.akeyPositions);
|
|
|
|
|
|
|
|
helper.Process(&me->mTargetAnim.akeyPositions);*/
|
|
|
|
|
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
|
|
|
// Allocate the key array and fill it
|
|
|
|
nd->mNumPositionKeys = (unsigned int) me->mTargetAnim.akeyPositions.size();
|
2010-03-23 18:22:45 +00:00
|
|
|
nd->mPositionKeys = new aiVectorKey[nd->mNumPositionKeys];
|
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
|
|
|
|
|
|
|
::memcpy(nd->mPositionKeys,&me->mTargetAnim.akeyPositions[0],
|
|
|
|
nd->mNumPositionKeys * sizeof(aiVectorKey));
|
|
|
|
}
|
|
|
|
|
2010-03-23 18:22:45 +00:00
|
|
|
if (me->mAnim.akeyPositions.size() > 1 || me->mAnim.akeyRotations.size() > 1 || me->mAnim.akeyScaling.size() > 1) {
|
2008-10-22 20:06:16 +00:00
|
|
|
// Begin a new node animation channel for this node
|
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
|
|
|
aiNodeAnim* nd = pcAnim->mChannels[iNum++] = new aiNodeAnim();
|
|
|
|
nd->mNodeName.Set(me->mName);
|
2008-07-18 20:29:46 +00:00
|
|
|
|
|
|
|
// copy position keys
|
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 (me->mAnim.akeyPositions.size() > 1 )
|
2008-07-18 20:29:46 +00:00
|
|
|
{
|
2008-10-22 20:06:16 +00:00
|
|
|
// Allocate the key array and fill it
|
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
|
|
|
nd->mNumPositionKeys = (unsigned int) me->mAnim.akeyPositions.size();
|
2010-03-23 18:22:45 +00:00
|
|
|
nd->mPositionKeys = new aiVectorKey[nd->mNumPositionKeys];
|
2008-07-18 20:29:46 +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
|
|
|
::memcpy(nd->mPositionKeys,&me->mAnim.akeyPositions[0],
|
|
|
|
nd->mNumPositionKeys * sizeof(aiVectorKey));
|
2008-07-18 20:29:46 +00:00
|
|
|
}
|
|
|
|
// copy rotation keys
|
2009-03-15 00:40:30 +00:00
|
|
|
if (me->mAnim.akeyRotations.size() > 1 ) {
|
2008-10-22 20:06:16 +00:00
|
|
|
// Allocate the key array and fill it
|
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
|
|
|
nd->mNumRotationKeys = (unsigned int) me->mAnim.akeyRotations.size();
|
2010-03-23 18:22:45 +00:00
|
|
|
nd->mRotationKeys = new aiQuatKey[nd->mNumRotationKeys];
|
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
|
|
|
|
2009-03-15 00:40:30 +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
|
|
|
// Rotation keys are offsets to the previous keys.
|
|
|
|
// We have the quaternion representations of all
|
|
|
|
// of them, so we just need to concatenate all
|
|
|
|
// (unit-length) quaternions to get the absolute
|
|
|
|
// rotations.
|
2009-03-15 00:40:30 +00:00
|
|
|
// Rotation keys are ABSOLUTE for older files
|
|
|
|
// --------------------------------------------------------------------
|
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
|
|
|
|
|
|
|
aiQuaternion cur;
|
2009-03-15 00:40:30 +00:00
|
|
|
for (unsigned int a = 0; a < nd->mNumRotationKeys;++a) {
|
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
|
|
|
aiQuatKey q = me->mAnim.akeyRotations[a];
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
if (mParser->iFileFormat > 110) {
|
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
|
|
|
cur = (a ? cur*q.mValue : q.mValue);
|
|
|
|
q.mValue = cur.Normalize();
|
|
|
|
}
|
|
|
|
nd->mRotationKeys[a] = q;
|
2009-11-19 23:22:53 +00:00
|
|
|
|
|
|
|
// need this to get to Assimp quaternion conventions
|
|
|
|
nd->mRotationKeys[a].mValue.w *= -1.f;
|
2008-07-18 20:29:46 +00:00
|
|
|
}
|
|
|
|
}
|
2008-10-31 19:32:00 +00:00
|
|
|
// copy scaling keys
|
2009-03-15 00:40:30 +00:00
|
|
|
if (me->mAnim.akeyScaling.size() > 1 ) {
|
2008-10-31 19:32:00 +00:00
|
|
|
// Allocate the key array and fill it
|
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
|
|
|
nd->mNumScalingKeys = (unsigned int) me->mAnim.akeyScaling.size();
|
2010-03-23 18:22:45 +00:00
|
|
|
nd->mScalingKeys = new aiVectorKey[nd->mNumScalingKeys];
|
2008-10-31 19:32:00 +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
|
|
|
::memcpy(nd->mScalingKeys,&me->mAnim.akeyScaling[0],
|
|
|
|
nd->mNumScalingKeys * sizeof(aiVectorKey));
|
2008-10-31 19:32:00 +00:00
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-10-22 20:06:16 +00:00
|
|
|
|
2008-07-18 20:29:46 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-03-15 00:40:30 +00:00
|
|
|
// Build output cameras
|
2008-10-22 20:06:16 +00:00
|
|
|
void ASEImporter::BuildCameras()
|
2008-07-18 20:29:46 +00:00
|
|
|
{
|
2009-03-15 00:40:30 +00:00
|
|
|
if (!mParser->m_vCameras.empty()) {
|
2008-10-22 20:06:16 +00:00
|
|
|
pcScene->mNumCameras = (unsigned int)mParser->m_vCameras.size();
|
|
|
|
pcScene->mCameras = new aiCamera*[pcScene->mNumCameras];
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
for (unsigned int i = 0; i < pcScene->mNumCameras;++i) {
|
2010-03-23 18:22:45 +00:00
|
|
|
aiCamera* out = pcScene->mCameras[i] = new aiCamera();
|
2008-10-22 20:06:16 +00:00
|
|
|
ASE::Camera& in = mParser->m_vCameras[i];
|
|
|
|
|
|
|
|
// copy members
|
|
|
|
out->mClipPlaneFar = in.mFar;
|
|
|
|
out->mClipPlaneNear = (in.mNear ? in.mNear : 0.1f);
|
2008-10-27 00:36:26 +00:00
|
|
|
out->mHorizontalFOV = in.mFOV;
|
2008-10-22 20:06:16 +00:00
|
|
|
|
|
|
|
out->mName.Set(in.mName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-03-15 00:40:30 +00:00
|
|
|
// Build output lights
|
2008-10-22 20:06:16 +00:00
|
|
|
void ASEImporter::BuildLights()
|
|
|
|
{
|
2009-03-15 00:40:30 +00:00
|
|
|
if (!mParser->m_vLights.empty()) {
|
2008-10-22 20:06:16 +00:00
|
|
|
pcScene->mNumLights = (unsigned int)mParser->m_vLights.size();
|
|
|
|
pcScene->mLights = new aiLight*[pcScene->mNumLights];
|
|
|
|
|
2010-03-23 18:22:45 +00:00
|
|
|
for (unsigned int i = 0; i < pcScene->mNumLights;++i) {
|
|
|
|
aiLight* out = pcScene->mLights[i] = new aiLight();
|
2008-10-22 20:06:16 +00:00
|
|
|
ASE::Light& in = mParser->m_vLights[i];
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
// The direction is encoded in the transformation matrix of the node.
|
|
|
|
// In 3DS MAX the light source points into negative Z direction if
|
|
|
|
// the node transformation is the identity.
|
2008-10-31 19:32:00 +00:00
|
|
|
out->mDirection = aiVector3D(0.f,0.f,-1.f);
|
|
|
|
|
2008-10-22 20:06:16 +00:00
|
|
|
out->mName.Set(in.mName);
|
2008-10-31 19:32:00 +00:00
|
|
|
switch (in.mLightType)
|
|
|
|
{
|
|
|
|
case ASE::Light::TARGET:
|
|
|
|
out->mType = aiLightSource_SPOT;
|
|
|
|
out->mAngleInnerCone = AI_DEG_TO_RAD(in.mAngle);
|
2009-03-15 00:40:30 +00:00
|
|
|
out->mAngleOuterCone = (in.mFalloff ? AI_DEG_TO_RAD(in.mFalloff) : out->mAngleInnerCone);
|
2008-10-31 19:32:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ASE::Light::DIRECTIONAL:
|
|
|
|
out->mType = aiLightSource_DIRECTIONAL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
//case ASE::Light::OMNI:
|
|
|
|
out->mType = aiLightSource_POINT;
|
|
|
|
break;
|
|
|
|
};
|
2008-10-27 00:36:26 +00:00
|
|
|
out->mColorDiffuse = out->mColorSpecular = in.mColor * in.mIntensity;
|
2008-10-22 20:06:16 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-03 21:50:53 +00:00
|
|
|
}
|
2008-10-22 20:06:16 +00:00
|
|
|
|
2008-06-03 21:50:53 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2010-03-23 18:22:45 +00:00
|
|
|
void ASEImporter::AddNodes(const std::vector<BaseNode*>& nodes,
|
2008-10-22 20:06:16 +00:00
|
|
|
aiNode* pcParent,const char* szName)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-10-22 20:06:16 +00:00
|
|
|
aiMatrix4x4 m;
|
2008-11-16 21:56:45 +00:00
|
|
|
AddNodes(nodes,pcParent,szName,m);
|
2008-10-22 20:06:16 +00:00
|
|
|
}
|
2008-06-01 12:46:17 +00:00
|
|
|
|
2008-10-27 00:36:26 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-03-15 00:40:30 +00:00
|
|
|
// Add meshes to a given node
|
2008-10-27 00:36:26 +00:00
|
|
|
void ASEImporter::AddMeshes(const ASE::BaseNode* snode,aiNode* node)
|
|
|
|
{
|
2009-03-15 00:40:30 +00:00
|
|
|
for (unsigned int i = 0; i < pcScene->mNumMeshes;++i) {
|
|
|
|
// Get the name of the mesh (the mesh instance has been temporarily stored in the third vertex color)
|
2008-10-27 00:36:26 +00:00
|
|
|
const aiMesh* pcMesh = pcScene->mMeshes[i];
|
|
|
|
const ASE::Mesh* mesh = (const ASE::Mesh*)pcMesh->mColors[2];
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
if (mesh == snode) {
|
|
|
|
++node->mNumMeshes;
|
|
|
|
}
|
2008-10-27 00:36:26 +00:00
|
|
|
}
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
if(node->mNumMeshes) {
|
2008-10-27 00:36:26 +00:00
|
|
|
node->mMeshes = new unsigned int[node->mNumMeshes];
|
2009-03-15 00:40:30 +00:00
|
|
|
for (unsigned int i = 0, p = 0; i < pcScene->mNumMeshes;++i) {
|
|
|
|
|
2008-10-27 00:36:26 +00:00
|
|
|
const aiMesh* pcMesh = pcScene->mMeshes[i];
|
|
|
|
const ASE::Mesh* mesh = (const ASE::Mesh*)pcMesh->mColors[2];
|
2009-03-15 00:40:30 +00:00
|
|
|
if (mesh == snode) {
|
2008-10-27 00:36:26 +00:00
|
|
|
node->mMeshes[p++] = i;
|
|
|
|
|
|
|
|
// Transform all vertices of the mesh back into their local space ->
|
|
|
|
// at the moment they are pretransformed
|
|
|
|
aiMatrix4x4 m = mesh->mTransform;
|
|
|
|
m.Inverse();
|
|
|
|
|
|
|
|
aiVector3D* pvCurPtr = pcMesh->mVertices;
|
|
|
|
const aiVector3D* pvEndPtr = pvCurPtr + pcMesh->mNumVertices;
|
2009-03-15 00:40:30 +00:00
|
|
|
while (pvCurPtr != pvEndPtr) {
|
2008-10-27 00:36:26 +00:00
|
|
|
*pvCurPtr = m * (*pvCurPtr);
|
|
|
|
pvCurPtr++;
|
|
|
|
}
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
// Do the same for the normal vectors, if we have them.
|
|
|
|
// As always, inverse transpose.
|
|
|
|
if (pcMesh->mNormals) {
|
2008-10-27 00:36:26 +00:00
|
|
|
aiMatrix3x3 m3 = aiMatrix3x3( mesh->mTransform );
|
|
|
|
m3.Transpose();
|
|
|
|
|
|
|
|
pvCurPtr = pcMesh->mNormals;
|
|
|
|
pvEndPtr = pvCurPtr + pcMesh->mNumVertices;
|
2009-03-15 00:40:30 +00:00
|
|
|
while (pvCurPtr != pvEndPtr) {
|
2008-10-27 00:36:26 +00:00
|
|
|
*pvCurPtr = m3 * (*pvCurPtr);
|
|
|
|
pvCurPtr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-22 20:06:16 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-03-15 00:40:30 +00:00
|
|
|
// Add child nodes to a given parent node
|
2010-03-23 18:22:45 +00:00
|
|
|
void ASEImporter::AddNodes (const std::vector<BaseNode*>& nodes,
|
2008-10-22 20:06:16 +00:00
|
|
|
aiNode* pcParent, const char* szName,
|
|
|
|
const aiMatrix4x4& mat)
|
|
|
|
{
|
|
|
|
const size_t len = szName ? ::strlen(szName) : 0;
|
2008-05-23 22:38:35 +00:00
|
|
|
ai_assert(4 <= AI_MAX_NUMBER_OF_COLOR_SETS);
|
2008-10-22 20:06:16 +00:00
|
|
|
|
|
|
|
// Receives child nodes for the pcParent node
|
2008-05-30 23:01:25 +00:00
|
|
|
std::vector<aiNode*> apcNodes;
|
2008-07-18 20:29:46 +00:00
|
|
|
|
2008-10-22 20:06:16 +00:00
|
|
|
// Now iterate through all nodes in the scene and search for one
|
|
|
|
// which has *us* as parent.
|
2009-03-15 00:40:30 +00:00
|
|
|
for (std::vector<BaseNode*>::const_iterator it = nodes.begin(), end = nodes.end(); it != end; ++it) {
|
2008-10-22 20:06:16 +00:00
|
|
|
const BaseNode* snode = *it;
|
2009-03-15 00:40:30 +00:00
|
|
|
if (szName) {
|
2008-10-22 20:06:16 +00:00
|
|
|
if (len != snode->mParent.length() || ::strcmp(szName,snode->mParent.c_str()))
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-10-22 20:06:16 +00:00
|
|
|
}
|
|
|
|
else if (snode->mParent.length())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
(*it)->mProcessed = true;
|
2008-05-30 23:01:25 +00:00
|
|
|
|
2008-10-22 20:06:16 +00:00
|
|
|
// Allocate a new node and add it to the output data structure
|
2008-05-30 23:01:25 +00:00
|
|
|
apcNodes.push_back(new aiNode());
|
|
|
|
aiNode* node = apcNodes.back();
|
|
|
|
|
2008-10-22 20:06:16 +00:00
|
|
|
node->mName.Set((snode->mName.length() ? snode->mName.c_str() : "Unnamed_Node"));
|
2008-05-30 23:01:25 +00:00
|
|
|
node->mParent = pcParent;
|
2008-07-18 20:29:46 +00:00
|
|
|
|
2008-10-22 20:06:16 +00:00
|
|
|
// Setup the transformation matrix of the node
|
|
|
|
aiMatrix4x4 mParentAdjust = mat;
|
2008-07-18 20:29:46 +00:00
|
|
|
mParentAdjust.Inverse();
|
2008-10-22 20:06:16 +00:00
|
|
|
node->mTransformation = mParentAdjust*snode->mTransform;
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
// Add sub nodes - prevent stack overflow due to recursive parenting
|
|
|
|
if (node->mName != node->mParent->mName) {
|
2008-11-16 21:56:45 +00:00
|
|
|
AddNodes(nodes,node,node->mName.data,snode->mTransform);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// Further processing depends on the type of the node
|
2009-03-15 00:40:30 +00:00
|
|
|
if (snode->mType == ASE::BaseNode::Mesh) {
|
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 type of this node is "Mesh" we need to search
|
|
|
|
// the list of output meshes in the data structure for
|
|
|
|
// all those that belonged to this node once. This is
|
|
|
|
// slightly inconvinient here and a better solution should
|
|
|
|
// be used when this code is refactored next.
|
2008-10-27 00:36:26 +00:00
|
|
|
AddMeshes(snode,node);
|
2008-07-18 20:29:46 +00:00
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
else if (is_not_qnan( snode->mTargetPosition.x )) {
|
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 this is a target camera or light we generate a small
|
|
|
|
// child node which marks the position of the camera
|
|
|
|
// target (the direction information is contained in *this*
|
|
|
|
// node's animation track but the exact target position
|
|
|
|
// would be lost otherwise)
|
2009-03-15 00:40:30 +00:00
|
|
|
if (!node->mNumChildren) {
|
2008-11-16 21:56:45 +00:00
|
|
|
node->mChildren = new aiNode*[1];
|
|
|
|
}
|
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
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
aiNode* nd = new aiNode();
|
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
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
nd->mName.Set ( snode->mName + ".Target" );
|
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
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
nd->mTransformation.a4 = snode->mTargetPosition.x - snode->mTransform.a4;
|
|
|
|
nd->mTransformation.b4 = snode->mTargetPosition.y - snode->mTransform.b4;
|
|
|
|
nd->mTransformation.c4 = snode->mTargetPosition.z - snode->mTransform.c4;
|
2008-05-30 23:01:25 +00:00
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
nd->mParent = node;
|
2008-10-27 00:36:26 +00:00
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
// The .Target node is always the first child node
|
|
|
|
for (unsigned int m = 0; m < node->mNumChildren;++m)
|
|
|
|
node->mChildren[m+1] = node->mChildren[m];
|
|
|
|
|
|
|
|
node->mChildren[0] = nd;
|
|
|
|
node->mNumChildren++;
|
|
|
|
|
|
|
|
// What we did is so great, it is at least worth a debug message
|
|
|
|
DefaultLogger::get()->debug("ASE: Generating separate target node ("+snode->mName+")");
|
2008-10-27 00:36:26 +00:00
|
|
|
}
|
2008-05-23 22:38:35 +00:00
|
|
|
}
|
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
// Allocate enough space for the child nodes
|
|
|
|
// We allocate one slot more in case this is a target camera/light
|
2008-06-01 12:46:17 +00:00
|
|
|
pcParent->mNumChildren = (unsigned int)apcNodes.size();
|
2009-03-15 00:40:30 +00:00
|
|
|
if (pcParent->mNumChildren) {
|
2008-11-16 21:56:45 +00:00
|
|
|
pcParent->mChildren = new aiNode*[apcNodes.size()+1 /* PLUS ONE !!! */];
|
2008-11-04 20:41:11 +00:00
|
|
|
|
|
|
|
// now build all nodes for our nice new children
|
|
|
|
for (unsigned int p = 0; p < apcNodes.size();++p)
|
|
|
|
pcParent->mChildren[p] = apcNodes[p];
|
2008-05-23 22:38:35 +00:00
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-10-22 20:06:16 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-03-15 00:40:30 +00:00
|
|
|
// Build the output node graph
|
2010-03-23 18:22:45 +00:00
|
|
|
void ASEImporter::BuildNodes(std::vector<BaseNode*>& nodes) {
|
2008-05-30 23:01:25 +00:00
|
|
|
ai_assert(NULL != pcScene);
|
2008-05-28 21:05:05 +00:00
|
|
|
|
2008-10-22 20:06:16 +00:00
|
|
|
// allocate the one and only root node
|
2009-03-15 00:40:30 +00:00
|
|
|
aiNode* root = pcScene->mRootNode = new aiNode();
|
|
|
|
root->mName.Set("<ASERoot>");
|
2008-05-28 21:05:05 +00:00
|
|
|
|
2008-10-31 19:32:00 +00:00
|
|
|
// Setup the coordinate system transformation
|
|
|
|
pcScene->mRootNode->mNumChildren = 1;
|
|
|
|
pcScene->mRootNode->mChildren = new aiNode*[1];
|
2009-03-15 00:40:30 +00:00
|
|
|
aiNode* ch = pcScene->mRootNode->mChildren[0] = new aiNode();
|
|
|
|
ch->mParent = root;
|
2008-10-22 20:06:16 +00:00
|
|
|
|
2008-10-31 19:32:00 +00:00
|
|
|
// Change the transformation matrix of all nodes
|
2009-03-15 00:40:30 +00:00
|
|
|
for (std::vector<BaseNode*>::iterator it = nodes.begin(), end = nodes.end();it != end; ++it) {
|
2008-10-31 19:32:00 +00:00
|
|
|
aiMatrix4x4& m = (*it)->mTransform;
|
|
|
|
m.Transpose(); // row-order vs column-order
|
|
|
|
}
|
2008-10-22 20:06:16 +00:00
|
|
|
|
2008-05-30 23:01:25 +00:00
|
|
|
// add all nodes
|
2009-03-15 00:40:30 +00:00
|
|
|
AddNodes(nodes,ch,NULL);
|
2008-05-30 23:01:25 +00:00
|
|
|
|
2008-10-22 20:06:16 +00:00
|
|
|
// now iterate through al nodes and find those that have not yet
|
2008-06-01 12:46:17 +00:00
|
|
|
// been added to the nodegraph (= their parent could not be recognized)
|
2008-10-22 20:06:16 +00:00
|
|
|
std::vector<const BaseNode*> aiList;
|
2009-03-15 00:40:30 +00:00
|
|
|
for (std::vector<BaseNode*>::iterator it = nodes.begin(), end = nodes.end();it != end; ++it) {
|
|
|
|
if ((*it)->mProcessed) {
|
|
|
|
continue;
|
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
|
2008-06-01 12:46:17 +00:00
|
|
|
// check whether our parent is known
|
|
|
|
bool bKnowParent = false;
|
2008-10-22 20:06:16 +00:00
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
// search the list another time, starting *here* and try to find out whether
|
2008-10-22 20:06:16 +00:00
|
|
|
// there is a node that references *us* as a parent
|
2009-03-15 00:40:30 +00:00
|
|
|
for (std::vector<BaseNode*>::const_iterator it2 = nodes.begin();it2 != end; ++it2) {
|
|
|
|
if (it2 == it) {
|
|
|
|
continue;
|
|
|
|
}
|
2008-10-22 20:06:16 +00:00
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
if ((*it2)->mName == (*it)->mParent) {
|
2008-06-01 12:46:17 +00:00
|
|
|
bKnowParent = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
if (!bKnowParent) {
|
2008-10-22 20:06:16 +00:00
|
|
|
aiList.push_back(*it);
|
2008-06-01 12:46:17 +00:00
|
|
|
}
|
|
|
|
}
|
2008-10-22 20:06:16 +00:00
|
|
|
|
|
|
|
// Are there ane orphaned nodes?
|
2009-03-15 00:40:30 +00:00
|
|
|
if (!aiList.empty()) {
|
2008-06-01 12:46:17 +00:00
|
|
|
std::vector<aiNode*> apcNodes;
|
|
|
|
apcNodes.reserve(aiList.size() + pcScene->mRootNode->mNumChildren);
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < pcScene->mRootNode->mNumChildren;++i)
|
|
|
|
apcNodes.push_back(pcScene->mRootNode->mChildren[i]);
|
|
|
|
|
|
|
|
delete[] pcScene->mRootNode->mChildren;
|
2009-03-15 00:40:30 +00:00
|
|
|
for (std::vector<const BaseNode*>::/*const_*/iterator i = aiList.begin();i != aiList.end();++i) {
|
2008-10-22 20:06:16 +00:00
|
|
|
const ASE::BaseNode* src = *i;
|
2008-06-01 12:46:17 +00:00
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
// The parent is not known, so we can assume that we must add
|
2008-06-01 12:46:17 +00:00
|
|
|
// this node to the root node of the whole scene
|
|
|
|
aiNode* pcNode = new aiNode();
|
|
|
|
pcNode->mParent = pcScene->mRootNode;
|
2008-10-22 20:06:16 +00:00
|
|
|
pcNode->mName.Set(src->mName);
|
2008-10-27 00:36:26 +00:00
|
|
|
AddMeshes(src,pcNode);
|
2008-10-22 20:06:16 +00:00
|
|
|
AddNodes(nodes,pcNode,pcNode->mName.data);
|
2008-06-01 12:46:17 +00:00
|
|
|
apcNodes.push_back(pcNode);
|
|
|
|
}
|
2008-10-22 20:06:16 +00:00
|
|
|
|
|
|
|
// Regenerate our output array
|
2008-06-01 12:46:17 +00:00
|
|
|
pcScene->mRootNode->mChildren = new aiNode*[apcNodes.size()];
|
|
|
|
for (unsigned int i = 0; i < apcNodes.size();++i)
|
|
|
|
pcScene->mRootNode->mChildren[i] = apcNodes[i];
|
|
|
|
|
|
|
|
pcScene->mRootNode->mNumChildren = (unsigned int)apcNodes.size();
|
|
|
|
}
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
// Reset the third color set to NULL - we used this field to store a temporary pointer
|
2008-07-18 20:29:46 +00:00
|
|
|
for (unsigned int i = 0; i < pcScene->mNumMeshes;++i)
|
|
|
|
pcScene->mMeshes[i]->mColors[2] = NULL;
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
// The root node should not have at least one child or the file is valid
|
|
|
|
if (!pcScene->mRootNode->mNumChildren) {
|
2010-03-18 17:00:12 +00:00
|
|
|
throw DeadlyImportError("ASE: No nodes loaded. The file is either empty or corrupt");
|
2008-05-28 21:05:05 +00:00
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
|
|
|
|
// Now rotate the whole scene 90 degrees around the x axis to convert to internal coordinate system
|
|
|
|
pcScene->mRootNode->mTransformation = aiMatrix4x4(1.f,0.f,0.f,0.f,
|
|
|
|
0.f,0.f,1.f,0.f,0.f,-1.f,0.f,0.f,0.f,0.f,0.f,1.f);
|
2008-05-30 23:01:25 +00:00
|
|
|
}
|
2008-10-22 20:06:16 +00:00
|
|
|
|
2008-05-28 21:05:05 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-03-15 00:40:30 +00:00
|
|
|
// Convert the imported data to the internal verbose representation
|
|
|
|
void ASEImporter::BuildUniqueRepresentation(ASE::Mesh& mesh) {
|
2008-05-09 17:24:28 +00:00
|
|
|
// allocate output storage
|
|
|
|
std::vector<aiVector3D> mPositions;
|
|
|
|
std::vector<aiVector3D> amTexCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS];
|
2008-09-27 16:46:05 +00:00
|
|
|
std::vector<aiColor4D> mVertexColors;
|
2008-05-09 17:24:28 +00:00
|
|
|
std::vector<aiVector3D> mNormals;
|
2008-05-28 21:05:05 +00:00
|
|
|
std::vector<BoneVertex> mBoneVertices;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-06-01 12:46:17 +00:00
|
|
|
unsigned int iSize = (unsigned int)mesh.mFaces.size() * 3;
|
2008-05-09 17:24:28 +00:00
|
|
|
mPositions.resize(iSize);
|
|
|
|
|
|
|
|
// optional texture coordinates
|
2009-03-15 00:40:30 +00:00
|
|
|
for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS;++i) {
|
|
|
|
if (!mesh.amTexCoords[i].empty()) {
|
2008-05-09 17:24:28 +00:00
|
|
|
amTexCoords[i].resize(iSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// optional vertex colors
|
2009-03-15 00:40:30 +00:00
|
|
|
if (!mesh.mVertexColors.empty()) {
|
2008-05-09 17:24:28 +00:00
|
|
|
mVertexColors.resize(iSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
// optional vertex normals (vertex normals can simply be copied)
|
2009-03-15 00:40:30 +00:00
|
|
|
if (!mesh.mNormals.empty()) {
|
2008-05-09 17:24:28 +00:00
|
|
|
mNormals.resize(iSize);
|
|
|
|
}
|
2008-05-28 21:05:05 +00:00
|
|
|
// bone vertices. There is no need to change the bone list
|
2009-03-15 00:40:30 +00:00
|
|
|
if (!mesh.mBoneVertices.empty()) {
|
2008-05-28 21:05:05 +00:00
|
|
|
mBoneVertices.resize(iSize);
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// iterate through all faces in the mesh
|
2008-10-31 19:32:00 +00:00
|
|
|
unsigned int iCurrent = 0, fi = 0;
|
2009-03-15 00:40:30 +00:00
|
|
|
for (std::vector<ASE::Face>::iterator i = mesh.mFaces.begin();i != mesh.mFaces.end();++i,++fi) {
|
2008-05-09 17:24:28 +00:00
|
|
|
for (unsigned int n = 0; n < 3;++n,++iCurrent)
|
|
|
|
{
|
2008-05-29 11:07:25 +00:00
|
|
|
mPositions[iCurrent] = mesh.mPositions[(*i).mIndices[n]];
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// add texture coordinates
|
2009-03-15 00:40:30 +00:00
|
|
|
for (unsigned int c = 0; c < AI_MAX_NUMBER_OF_TEXTURECOORDS;++c) {
|
2008-11-16 21:56:45 +00:00
|
|
|
if (mesh.amTexCoords[c].empty())break;
|
|
|
|
amTexCoords[c][iCurrent] = mesh.amTexCoords[c][(*i).amUVIndices[c][n]];
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// add vertex colors
|
2009-03-15 00:40:30 +00:00
|
|
|
if (!mesh.mVertexColors.empty()) {
|
2008-05-09 17:24:28 +00:00
|
|
|
mVertexColors[iCurrent] = mesh.mVertexColors[(*i).mColorIndices[n]];
|
|
|
|
}
|
|
|
|
// add normal vectors
|
2009-03-15 00:40:30 +00:00
|
|
|
if (!mesh.mNormals.empty()) {
|
2008-10-31 19:32:00 +00:00
|
|
|
mNormals[iCurrent] = mesh.mNormals[fi*3+n];
|
2008-09-27 16:46:05 +00:00
|
|
|
mNormals[iCurrent].Normalize();
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-05-28 21:05:05 +00:00
|
|
|
|
|
|
|
// handle bone vertices
|
2009-03-15 00:40:30 +00:00
|
|
|
if ((*i).mIndices[n] < mesh.mBoneVertices.size()) {
|
2008-05-28 21:05:05 +00:00
|
|
|
// (sometimes this will cause bone verts to be duplicated
|
|
|
|
// however, I' quite sure Schrompf' JoinVerticesStep
|
|
|
|
// will fix that again ...)
|
2008-05-29 11:07:25 +00:00
|
|
|
mBoneVertices[iCurrent] = mesh.mBoneVertices[(*i).mIndices[n]];
|
2008-05-28 21:05:05 +00:00
|
|
|
}
|
2008-11-16 21:56:45 +00:00
|
|
|
(*i).mIndices[n] = iCurrent;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// replace the old arrays
|
|
|
|
mesh.mNormals = mNormals;
|
|
|
|
mesh.mPositions = mPositions;
|
|
|
|
mesh.mVertexColors = mVertexColors;
|
|
|
|
|
|
|
|
for (unsigned int c = 0; c < AI_MAX_NUMBER_OF_TEXTURECOORDS;++c)
|
|
|
|
mesh.amTexCoords[c] = amTexCoords[c];
|
2008-11-16 21:56:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-03-15 00:40:30 +00:00
|
|
|
// Copy a texture from the ASE structs to the output material
|
2011-08-22 20:22:51 +00:00
|
|
|
void CopyASETexture(aiMaterial& mat, ASE::Texture& texture, aiTextureType type)
|
2008-11-16 21:56:45 +00:00
|
|
|
{
|
|
|
|
// Setup the texture name
|
|
|
|
aiString tex;
|
|
|
|
tex.Set( texture.mMapName);
|
|
|
|
mat.AddProperty( &tex, AI_MATKEY_TEXTURE(type,0));
|
|
|
|
|
|
|
|
// Setup the texture blend factor
|
|
|
|
if (is_not_qnan(texture.mTextureBlend))
|
|
|
|
mat.AddProperty<float>( &texture.mTextureBlend, 1, AI_MATKEY_TEXBLEND(type,0));
|
|
|
|
|
|
|
|
// Setup texture UV transformations
|
|
|
|
mat.AddProperty<float>(&texture.mOffsetU,5,AI_MATKEY_UVTRANSFORM(type,0));
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-10-22 20:06:16 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-03-15 00:40:30 +00:00
|
|
|
// Convert from ASE material to output material
|
2008-05-09 17:24:28 +00:00
|
|
|
void ASEImporter::ConvertMaterial(ASE::Material& mat)
|
|
|
|
{
|
2008-11-16 21:56:45 +00:00
|
|
|
// LARGE TODO: Much code her is copied from 3DS ... join them maybe?
|
|
|
|
|
|
|
|
// Allocate the output material
|
2011-08-22 20:22:51 +00:00
|
|
|
mat.pcInstance = new aiMaterial();
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// At first add the base ambient color of the
|
|
|
|
// scene to the material
|
2008-11-16 21:56:45 +00:00
|
|
|
mat.mAmbient.r += mParser->m_clrAmbient.r;
|
|
|
|
mat.mAmbient.g += mParser->m_clrAmbient.g;
|
|
|
|
mat.mAmbient.b += mParser->m_clrAmbient.b;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
aiString name;
|
|
|
|
name.Set( mat.mName);
|
|
|
|
mat.pcInstance->AddProperty( &name, AI_MATKEY_NAME);
|
|
|
|
|
|
|
|
// material colors
|
|
|
|
mat.pcInstance->AddProperty( &mat.mAmbient, 1, AI_MATKEY_COLOR_AMBIENT);
|
|
|
|
mat.pcInstance->AddProperty( &mat.mDiffuse, 1, AI_MATKEY_COLOR_DIFFUSE);
|
|
|
|
mat.pcInstance->AddProperty( &mat.mSpecular, 1, AI_MATKEY_COLOR_SPECULAR);
|
|
|
|
mat.pcInstance->AddProperty( &mat.mEmissive, 1, AI_MATKEY_COLOR_EMISSIVE);
|
|
|
|
|
2008-05-28 21:05:05 +00:00
|
|
|
// shininess
|
|
|
|
if (0.0f != mat.mSpecularExponent && 0.0f != mat.mShininessStrength)
|
|
|
|
{
|
|
|
|
mat.pcInstance->AddProperty( &mat.mSpecularExponent, 1, AI_MATKEY_SHININESS);
|
|
|
|
mat.pcInstance->AddProperty( &mat.mShininessStrength, 1, AI_MATKEY_SHININESS_STRENGTH);
|
|
|
|
}
|
2008-11-16 21:56:45 +00:00
|
|
|
// If there is no shininess, we can disable phong lighting
|
2008-10-31 19:32:00 +00:00
|
|
|
else if (D3DS::Discreet3DS::Metal == mat.mShading ||
|
|
|
|
D3DS::Discreet3DS::Phong == mat.mShading ||
|
|
|
|
D3DS::Discreet3DS::Blinn == mat.mShading)
|
2008-05-28 21:05:05 +00:00
|
|
|
{
|
2008-10-31 19:32:00 +00:00
|
|
|
mat.mShading = D3DS::Discreet3DS::Gouraud;
|
2008-05-28 21:05:05 +00:00
|
|
|
}
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// opacity
|
|
|
|
mat.pcInstance->AddProperty<float>( &mat.mTransparency,1,AI_MATKEY_OPACITY);
|
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
// Two sided rendering?
|
|
|
|
if (mat.mTwoSided)
|
|
|
|
{
|
|
|
|
int i = 1;
|
|
|
|
mat.pcInstance->AddProperty<int>(&i,1,AI_MATKEY_TWOSIDED);
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// shading mode
|
|
|
|
aiShadingMode eShading = aiShadingMode_NoShading;
|
|
|
|
switch (mat.mShading)
|
|
|
|
{
|
2008-10-31 19:32:00 +00:00
|
|
|
case D3DS::Discreet3DS::Flat:
|
2008-05-09 17:24:28 +00:00
|
|
|
eShading = aiShadingMode_Flat; break;
|
2008-10-31 19:32:00 +00:00
|
|
|
case D3DS::Discreet3DS::Phong :
|
2008-05-09 17:24:28 +00:00
|
|
|
eShading = aiShadingMode_Phong; break;
|
2008-10-31 19:32:00 +00:00
|
|
|
case D3DS::Discreet3DS::Blinn :
|
2008-05-30 23:01:25 +00:00
|
|
|
eShading = aiShadingMode_Blinn; break;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
// I don't know what "Wire" shading should be,
|
|
|
|
// assume it is simple lambertian diffuse (L dot N) shading
|
2008-10-31 19:32:00 +00:00
|
|
|
case D3DS::Discreet3DS::Wire:
|
2008-11-16 21:56:45 +00:00
|
|
|
{
|
|
|
|
// set the wireframe flag
|
|
|
|
unsigned int iWire = 1;
|
|
|
|
mat.pcInstance->AddProperty<int>( (int*)&iWire,1,AI_MATKEY_ENABLE_WIREFRAME);
|
|
|
|
}
|
2008-10-31 19:32:00 +00:00
|
|
|
case D3DS::Discreet3DS::Gouraud:
|
2008-05-09 17:24:28 +00:00
|
|
|
eShading = aiShadingMode_Gouraud; break;
|
2008-10-31 19:32:00 +00:00
|
|
|
case D3DS::Discreet3DS::Metal :
|
2008-05-09 17:24:28 +00:00
|
|
|
eShading = aiShadingMode_CookTorrance; break;
|
|
|
|
}
|
|
|
|
mat.pcInstance->AddProperty<int>( (int*)&eShading,1,AI_MATKEY_SHADING_MODEL);
|
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
// DIFFUSE texture
|
2008-05-09 17:24:28 +00:00
|
|
|
if( mat.sTexDiffuse.mMapName.length() > 0)
|
2008-11-16 21:56:45 +00:00
|
|
|
CopyASETexture(*mat.pcInstance,mat.sTexDiffuse, aiTextureType_DIFFUSE);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
// SPECULAR texture
|
2008-05-09 17:24:28 +00:00
|
|
|
if( mat.sTexSpecular.mMapName.length() > 0)
|
2008-11-16 21:56:45 +00:00
|
|
|
CopyASETexture(*mat.pcInstance,mat.sTexSpecular, aiTextureType_SPECULAR);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
// AMBIENT texture
|
|
|
|
if( mat.sTexAmbient.mMapName.length() > 0)
|
|
|
|
CopyASETexture(*mat.pcInstance,mat.sTexAmbient, aiTextureType_AMBIENT);
|
|
|
|
|
|
|
|
// OPACITY texture
|
2008-05-09 17:24:28 +00:00
|
|
|
if( mat.sTexOpacity.mMapName.length() > 0)
|
2008-11-16 21:56:45 +00:00
|
|
|
CopyASETexture(*mat.pcInstance,mat.sTexOpacity, aiTextureType_OPACITY);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
// EMISSIVE texture
|
2008-05-09 17:24:28 +00:00
|
|
|
if( mat.sTexEmissive.mMapName.length() > 0)
|
2008-11-16 21:56:45 +00:00
|
|
|
CopyASETexture(*mat.pcInstance,mat.sTexEmissive, aiTextureType_EMISSIVE);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
// BUMP texture
|
2008-05-09 17:24:28 +00:00
|
|
|
if( mat.sTexBump.mMapName.length() > 0)
|
2008-11-16 21:56:45 +00:00
|
|
|
CopyASETexture(*mat.pcInstance,mat.sTexBump, aiTextureType_HEIGHT);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
// SHININESS texture
|
2008-05-09 17:24:28 +00:00
|
|
|
if( mat.sTexShininess.mMapName.length() > 0)
|
2008-11-16 21:56:45 +00:00
|
|
|
CopyASETexture(*mat.pcInstance,mat.sTexShininess, aiTextureType_SHININESS);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// store the name of the material itself, too
|
2009-03-15 00:40:30 +00:00
|
|
|
if( mat.mName.length() > 0) {
|
|
|
|
aiString tex;tex.Set( mat.mName);
|
2008-05-09 17:24:28 +00:00
|
|
|
mat.pcInstance->AddProperty( &tex, AI_MATKEY_NAME);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2008-10-22 20:06:16 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-03-15 00:40:30 +00:00
|
|
|
// Build output meshes
|
2008-05-30 23:01:25 +00:00
|
|
|
void ASEImporter::ConvertMeshes(ASE::Mesh& mesh, std::vector<aiMesh*>& avOutMeshes)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
|
|
|
// validate the material index of the mesh
|
2009-03-15 00:40:30 +00:00
|
|
|
if (mesh.iMaterialIndex >= mParser->m_vMaterials.size()) {
|
2008-10-22 20:06:16 +00:00
|
|
|
mesh.iMaterialIndex = (unsigned int)mParser->m_vMaterials.size()-1;
|
2008-06-15 10:27:08 +00:00
|
|
|
DefaultLogger::get()->warn("Material index is out of range");
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
// If the material the mesh is assigned to is consisting of submeshes, split it
|
|
|
|
if (!mParser->m_vMaterials[mesh.iMaterialIndex].avSubMaterials.empty()) {
|
2008-10-22 20:06:16 +00:00
|
|
|
std::vector<ASE::Material> vSubMaterials = mParser->
|
2008-05-09 17:24:28 +00:00
|
|
|
m_vMaterials[mesh.iMaterialIndex].avSubMaterials;
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
std::vector<unsigned int>* aiSplit = new std::vector<unsigned int>[vSubMaterials.size()];
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// build a list of all faces per submaterial
|
2009-03-15 00:40:30 +00:00
|
|
|
for (unsigned int i = 0; i < mesh.mFaces.size();++i) {
|
2008-05-09 17:24:28 +00:00
|
|
|
// check range
|
2009-03-15 00:40:30 +00:00
|
|
|
if (mesh.mFaces[i].iMaterial >= vSubMaterials.size()) {
|
|
|
|
DefaultLogger::get()->warn("Submaterial index is out of range");
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
// use the last material instead
|
|
|
|
aiSplit[vSubMaterials.size()-1].push_back(i);
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
else aiSplit[mesh.mFaces[i].iMaterial].push_back(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
// now generate submeshes
|
2009-03-15 00:40:30 +00:00
|
|
|
for (unsigned int p = 0; p < vSubMaterials.size();++p) {
|
|
|
|
if (!aiSplit[p].empty()) {
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
aiMesh* p_pcOut = new aiMesh();
|
2008-09-30 20:20:56 +00:00
|
|
|
p_pcOut->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// let the sub material index
|
|
|
|
p_pcOut->mMaterialIndex = p;
|
|
|
|
|
|
|
|
// we will need this material
|
2008-10-22 20:06:16 +00:00
|
|
|
mParser->m_vMaterials[mesh.iMaterialIndex].avSubMaterials[p].bNeed = true;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-05-23 22:38:35 +00:00
|
|
|
// store the real index here ... color channel 3
|
2008-05-09 17:24:28 +00:00
|
|
|
p_pcOut->mColors[3] = (aiColor4D*)(uintptr_t)mesh.iMaterialIndex;
|
2008-05-30 23:01:25 +00:00
|
|
|
|
2008-07-18 20:29:46 +00:00
|
|
|
// store a pointer to the mesh in color channel 2
|
|
|
|
p_pcOut->mColors[2] = (aiColor4D*) &mesh;
|
2008-05-09 17:24:28 +00:00
|
|
|
avOutMeshes.push_back(p_pcOut);
|
|
|
|
|
|
|
|
// convert vertices
|
2008-06-01 12:46:17 +00:00
|
|
|
p_pcOut->mNumVertices = (unsigned int)aiSplit[p].size()*3;
|
|
|
|
p_pcOut->mNumFaces = (unsigned int)aiSplit[p].size();
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-05-28 21:05:05 +00:00
|
|
|
// receive output vertex weights
|
2009-12-24 12:02:06 +00:00
|
|
|
std::vector<std::pair<unsigned int, float> > *avOutputBones = NULL;
|
2009-03-15 00:40:30 +00:00
|
|
|
if (!mesh.mBones.empty()) {
|
2008-05-30 19:29:26 +00:00
|
|
|
avOutputBones = new std::vector<std::pair<unsigned int, float> >[mesh.mBones.size()];
|
2008-05-28 21:05:05 +00:00
|
|
|
}
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// allocate enough storage for faces
|
|
|
|
p_pcOut->mFaces = new aiFace[p_pcOut->mNumFaces];
|
|
|
|
|
2008-10-22 20:06:16 +00:00
|
|
|
unsigned int iBase = 0,iIndex;
|
2009-03-15 00:40:30 +00:00
|
|
|
if (p_pcOut->mNumVertices) {
|
2008-05-09 17:24:28 +00:00
|
|
|
p_pcOut->mVertices = new aiVector3D[p_pcOut->mNumVertices];
|
2008-10-22 20:06:16 +00:00
|
|
|
p_pcOut->mNormals = new aiVector3D[p_pcOut->mNumVertices];
|
2009-03-15 00:40:30 +00:00
|
|
|
for (unsigned int q = 0; q < aiSplit[p].size();++q) {
|
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
iIndex = aiSplit[p][q];
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
p_pcOut->mFaces[q].mIndices = new unsigned int[3];
|
|
|
|
p_pcOut->mFaces[q].mNumIndices = 3;
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
for (unsigned int t = 0; t < 3;++t, ++iBase) {
|
2008-05-29 11:07:25 +00:00
|
|
|
const uint32_t iIndex2 = mesh.mFaces[iIndex].mIndices[t];
|
2008-05-28 21:05:05 +00:00
|
|
|
|
2008-10-22 20:06:16 +00:00
|
|
|
p_pcOut->mVertices[iBase] = mesh.mPositions [iIndex2];
|
|
|
|
p_pcOut->mNormals [iBase] = mesh.mNormals [iIndex2];
|
2008-05-28 21:05:05 +00:00
|
|
|
|
|
|
|
// convert bones, if existing
|
2009-03-15 00:40:30 +00:00
|
|
|
if (!mesh.mBones.empty()) {
|
|
|
|
// check whether there is a vertex weight for this vertex index
|
|
|
|
if (iIndex2 < mesh.mBoneVertices.size()) {
|
|
|
|
|
2008-05-30 19:29:26 +00:00
|
|
|
for (std::vector<std::pair<int,float> >::const_iterator
|
2008-05-28 21:05:05 +00:00
|
|
|
blubb = mesh.mBoneVertices[iIndex2].mBoneWeights.begin();
|
2009-03-15 00:40:30 +00:00
|
|
|
blubb != mesh.mBoneVertices[iIndex2].mBoneWeights.end();++blubb) {
|
|
|
|
|
2008-05-28 21:05:05 +00:00
|
|
|
// NOTE: illegal cases have already been filtered out
|
|
|
|
avOutputBones[(*blubb).first].push_back(std::pair<unsigned int, float>(
|
|
|
|
iBase,(*blubb).second));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-11-16 21:56:45 +00:00
|
|
|
p_pcOut->mFaces[q].mIndices[t] = iBase;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-10-22 20:06:16 +00:00
|
|
|
// convert texture coordinates (up to AI_MAX_NUMBER_OF_TEXTURECOORDS sets supported)
|
2009-03-15 00:40:30 +00:00
|
|
|
for (unsigned int c = 0; c < AI_MAX_NUMBER_OF_TEXTURECOORDS;++c) {
|
2008-05-09 17:24:28 +00:00
|
|
|
if (!mesh.amTexCoords[c].empty())
|
|
|
|
{
|
|
|
|
p_pcOut->mTextureCoords[c] = new aiVector3D[p_pcOut->mNumVertices];
|
2008-10-22 20:06:16 +00:00
|
|
|
iBase = 0;
|
2009-03-15 00:40:30 +00:00
|
|
|
for (unsigned int q = 0; q < aiSplit[p].size();++q) {
|
2008-10-22 20:06:16 +00:00
|
|
|
iIndex = aiSplit[p][q];
|
2009-03-15 00:40:30 +00:00
|
|
|
for (unsigned int t = 0; t < 3;++t) {
|
2008-05-29 11:07:25 +00:00
|
|
|
p_pcOut->mTextureCoords[c][iBase++] = mesh.amTexCoords[c][mesh.mFaces[iIndex].mIndices[t]];
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
2008-11-16 21:56:45 +00:00
|
|
|
// Setup the number of valid vertex components
|
2008-05-09 17:24:28 +00:00
|
|
|
p_pcOut->mNumUVComponents[c] = mesh.mNumUVComponents[c];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
// Convert vertex colors (only one set supported)
|
2009-03-15 00:40:30 +00:00
|
|
|
if (!mesh.mVertexColors.empty()){
|
2008-05-09 17:24:28 +00:00
|
|
|
p_pcOut->mColors[0] = new aiColor4D[p_pcOut->mNumVertices];
|
2008-10-22 20:06:16 +00:00
|
|
|
iBase = 0;
|
2009-03-15 00:40:30 +00:00
|
|
|
for (unsigned int q = 0; q < aiSplit[p].size();++q) {
|
2008-10-22 20:06:16 +00:00
|
|
|
iIndex = aiSplit[p][q];
|
2009-03-15 00:40:30 +00:00
|
|
|
for (unsigned int t = 0; t < 3;++t) {
|
2008-05-29 11:07:25 +00:00
|
|
|
p_pcOut->mColors[0][iBase++] = mesh.mVertexColors[mesh.mFaces[iIndex].mIndices[t]];
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-11-16 21:56:45 +00:00
|
|
|
// Copy bones
|
2009-03-15 00:40:30 +00:00
|
|
|
if (!mesh.mBones.empty()) {
|
2008-05-28 21:05:05 +00:00
|
|
|
p_pcOut->mNumBones = 0;
|
|
|
|
for (unsigned int mrspock = 0; mrspock < mesh.mBones.size();++mrspock)
|
|
|
|
if (!avOutputBones[mrspock].empty())p_pcOut->mNumBones++;
|
|
|
|
|
|
|
|
p_pcOut->mBones = new aiBone* [ p_pcOut->mNumBones ];
|
2008-05-30 23:01:25 +00:00
|
|
|
aiBone** pcBone = p_pcOut->mBones;
|
2008-05-28 21:05:05 +00:00
|
|
|
for (unsigned int mrspock = 0; mrspock < mesh.mBones.size();++mrspock)
|
|
|
|
{
|
2009-03-15 00:40:30 +00:00
|
|
|
if (!avOutputBones[mrspock].empty()) {
|
2008-05-28 21:05:05 +00:00
|
|
|
// we will need this bone. add it to the output mesh and
|
|
|
|
// add all per-vertex weights
|
2008-05-30 23:01:25 +00:00
|
|
|
aiBone* pc = *pcBone = new aiBone();
|
|
|
|
pc->mName.Set(mesh.mBones[mrspock].mName);
|
2008-05-28 21:05:05 +00:00
|
|
|
|
2008-06-01 12:46:17 +00:00
|
|
|
pc->mNumWeights = (unsigned int)avOutputBones[mrspock].size();
|
2008-05-30 23:01:25 +00:00
|
|
|
pc->mWeights = new aiVertexWeight[pc->mNumWeights];
|
2008-05-28 21:05:05 +00:00
|
|
|
|
2008-05-30 23:01:25 +00:00
|
|
|
for (unsigned int captainkirk = 0; captainkirk < pc->mNumWeights;++captainkirk)
|
2008-05-28 21:05:05 +00:00
|
|
|
{
|
|
|
|
const std::pair<unsigned int,float>& ref = avOutputBones[mrspock][captainkirk];
|
2008-05-30 23:01:25 +00:00
|
|
|
pc->mWeights[captainkirk].mVertexId = ref.first;
|
|
|
|
pc->mWeights[captainkirk].mWeight = ref.second;
|
2008-05-28 21:05:05 +00:00
|
|
|
}
|
|
|
|
++pcBone;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// delete allocated storage
|
|
|
|
delete[] avOutputBones;
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// delete storage
|
|
|
|
delete[] aiSplit;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-10-22 20:06:16 +00:00
|
|
|
// Otherwise we can simply copy the data to one output mesh
|
|
|
|
// This codepath needs less memory and uses fast memcpy()s
|
|
|
|
// to do the actual copying. So I think it is worth the
|
|
|
|
// effort here.
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
aiMesh* p_pcOut = new aiMesh();
|
2008-09-30 20:20:56 +00:00
|
|
|
p_pcOut->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// set an empty sub material index
|
|
|
|
p_pcOut->mMaterialIndex = ASE::Face::DEFAULT_MATINDEX;
|
2008-10-22 20:06:16 +00:00
|
|
|
mParser->m_vMaterials[mesh.iMaterialIndex].bNeed = true;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-05-23 22:38:35 +00:00
|
|
|
// store the real index here ... in color channel 3
|
2008-05-09 17:24:28 +00:00
|
|
|
p_pcOut->mColors[3] = (aiColor4D*)(uintptr_t)mesh.iMaterialIndex;
|
2008-05-30 23:01:25 +00:00
|
|
|
|
2008-07-18 20:29:46 +00:00
|
|
|
// store a pointer to the mesh in color channel 2
|
|
|
|
p_pcOut->mColors[2] = (aiColor4D*) &mesh;
|
2008-05-09 17:24:28 +00:00
|
|
|
avOutMeshes.push_back(p_pcOut);
|
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
// If the mesh hasn't faces or vertices, there are two cases
|
2008-07-18 20:29:46 +00:00
|
|
|
// possible: 1. the model is invalid. 2. This is a dummy
|
|
|
|
// helper object which we are going to remove later ...
|
2009-03-15 00:40:30 +00:00
|
|
|
if (mesh.mFaces.empty() || mesh.mPositions.empty()) {
|
2008-07-18 20:29:46 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-05-30 23:01:25 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// convert vertices
|
2008-06-01 12:46:17 +00:00
|
|
|
p_pcOut->mNumVertices = (unsigned int)mesh.mPositions.size();
|
|
|
|
p_pcOut->mNumFaces = (unsigned int)mesh.mFaces.size();
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// allocate enough storage for faces
|
|
|
|
p_pcOut->mFaces = new aiFace[p_pcOut->mNumFaces];
|
|
|
|
|
|
|
|
// copy vertices
|
|
|
|
p_pcOut->mVertices = new aiVector3D[mesh.mPositions.size()];
|
|
|
|
memcpy(p_pcOut->mVertices,&mesh.mPositions[0],
|
|
|
|
mesh.mPositions.size() * sizeof(aiVector3D));
|
|
|
|
|
|
|
|
// copy normals
|
|
|
|
p_pcOut->mNormals = new aiVector3D[mesh.mNormals.size()];
|
|
|
|
memcpy(p_pcOut->mNormals,&mesh.mNormals[0],
|
|
|
|
mesh.mNormals.size() * sizeof(aiVector3D));
|
|
|
|
|
|
|
|
// copy texture coordinates
|
2009-03-15 00:40:30 +00:00
|
|
|
for (unsigned int c = 0; c < AI_MAX_NUMBER_OF_TEXTURECOORDS;++c) {
|
|
|
|
if (!mesh.amTexCoords[c].empty()) {
|
2008-05-09 17:24:28 +00:00
|
|
|
p_pcOut->mTextureCoords[c] = new aiVector3D[mesh.amTexCoords[c].size()];
|
|
|
|
memcpy(p_pcOut->mTextureCoords[c],&mesh.amTexCoords[c][0],
|
|
|
|
mesh.amTexCoords[c].size() * sizeof(aiVector3D));
|
|
|
|
|
|
|
|
// setup the number of valid vertex components
|
|
|
|
p_pcOut->mNumUVComponents[c] = mesh.mNumUVComponents[c];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// copy vertex colors
|
2009-03-15 00:40:30 +00:00
|
|
|
if (!mesh.mVertexColors.empty()) {
|
2008-05-09 17:24:28 +00:00
|
|
|
p_pcOut->mColors[0] = new aiColor4D[mesh.mVertexColors.size()];
|
|
|
|
memcpy(p_pcOut->mColors[0],&mesh.mVertexColors[0],
|
|
|
|
mesh.mVertexColors.size() * sizeof(aiColor4D));
|
|
|
|
}
|
|
|
|
|
|
|
|
// copy faces
|
2009-03-15 00:40:30 +00:00
|
|
|
for (unsigned int iFace = 0; iFace < p_pcOut->mNumFaces;++iFace) {
|
2008-05-09 17:24:28 +00:00
|
|
|
p_pcOut->mFaces[iFace].mNumIndices = 3;
|
|
|
|
p_pcOut->mFaces[iFace].mIndices = new unsigned int[3];
|
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
// copy indices
|
|
|
|
p_pcOut->mFaces[iFace].mIndices[0] = mesh.mFaces[iFace].mIndices[0];
|
2008-05-29 11:07:25 +00:00
|
|
|
p_pcOut->mFaces[iFace].mIndices[1] = mesh.mFaces[iFace].mIndices[1];
|
2008-11-16 21:56:45 +00:00
|
|
|
p_pcOut->mFaces[iFace].mIndices[2] = mesh.mFaces[iFace].mIndices[2];
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-05-28 21:05:05 +00:00
|
|
|
|
|
|
|
// copy vertex bones
|
2009-03-15 00:40:30 +00:00
|
|
|
if (!mesh.mBones.empty() && !mesh.mBoneVertices.empty()) {
|
2012-03-20 20:35:21 +00:00
|
|
|
std::vector<std::vector<aiVertexWeight> > avBonesOut( mesh.mBones.size() );
|
2008-05-28 21:05:05 +00:00
|
|
|
|
|
|
|
// find all vertex weights for this bone
|
|
|
|
unsigned int quak = 0;
|
2009-03-15 00:40:30 +00:00
|
|
|
for (std::vector<BoneVertex>::const_iterator harrypotter = mesh.mBoneVertices.begin();
|
|
|
|
harrypotter != mesh.mBoneVertices.end();++harrypotter,++quak) {
|
|
|
|
|
2008-05-30 19:29:26 +00:00
|
|
|
for (std::vector<std::pair<int,float> >::const_iterator
|
2008-05-28 21:05:05 +00:00
|
|
|
ronaldweasley = (*harrypotter).mBoneWeights.begin();
|
|
|
|
ronaldweasley != (*harrypotter).mBoneWeights.end();++ronaldweasley)
|
|
|
|
{
|
|
|
|
aiVertexWeight weight;
|
|
|
|
weight.mVertexId = quak;
|
|
|
|
weight.mWeight = (*ronaldweasley).second;
|
|
|
|
avBonesOut[(*ronaldweasley).first].push_back(weight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// now build a final bone list
|
|
|
|
p_pcOut->mNumBones = 0;
|
|
|
|
for (unsigned int jfkennedy = 0; jfkennedy < mesh.mBones.size();++jfkennedy)
|
|
|
|
if (!avBonesOut[jfkennedy].empty())p_pcOut->mNumBones++;
|
|
|
|
|
|
|
|
p_pcOut->mBones = new aiBone*[p_pcOut->mNumBones];
|
2008-05-30 23:01:25 +00:00
|
|
|
aiBone** pcBone = p_pcOut->mBones;
|
2009-03-15 00:40:30 +00:00
|
|
|
for (unsigned int jfkennedy = 0; jfkennedy < mesh.mBones.size();++jfkennedy) {
|
|
|
|
if (!avBonesOut[jfkennedy].empty()) {
|
2008-05-30 23:01:25 +00:00
|
|
|
aiBone* pc = *pcBone = new aiBone();
|
|
|
|
pc->mName.Set(mesh.mBones[jfkennedy].mName);
|
2008-06-01 12:46:17 +00:00
|
|
|
pc->mNumWeights = (unsigned int)avBonesOut[jfkennedy].size();
|
2008-05-30 23:01:25 +00:00
|
|
|
pc->mWeights = new aiVertexWeight[pc->mNumWeights];
|
2008-08-09 22:39:57 +00:00
|
|
|
::memcpy(pc->mWeights,&avBonesOut[jfkennedy][0],
|
2008-05-30 23:01:25 +00:00
|
|
|
sizeof(aiVertexWeight) * pc->mNumWeights);
|
2008-05-28 21:05:05 +00:00
|
|
|
++pcBone;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-05-30 23:01:25 +00:00
|
|
|
}
|
2008-09-27 16:46:05 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-03-15 00:40:30 +00:00
|
|
|
// Setup proper material indices and build output materials
|
2008-07-18 20:29:46 +00:00
|
|
|
void ASEImporter::BuildMaterialIndices()
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
|
|
|
ai_assert(NULL != pcScene);
|
|
|
|
|
|
|
|
// iterate through all materials and check whether we need them
|
2008-10-22 20:06:16 +00:00
|
|
|
for (unsigned int iMat = 0; iMat < mParser->m_vMaterials.size();++iMat)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-11-16 21:56:45 +00:00
|
|
|
ASE::Material& mat = mParser->m_vMaterials[iMat];
|
2009-03-15 00:40:30 +00:00
|
|
|
if (mat.bNeed) {
|
2008-11-16 21:56:45 +00:00
|
|
|
// Convert it to the aiMaterial layout
|
2008-10-22 20:06:16 +00:00
|
|
|
ConvertMaterial(mat);
|
2008-07-30 23:00:25 +00:00
|
|
|
++pcScene->mNumMaterials;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-11-16 21:56:45 +00:00
|
|
|
for (unsigned int iSubMat = 0; iSubMat < mat.avSubMaterials.size();++iSubMat)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-11-16 21:56:45 +00:00
|
|
|
ASE::Material& submat = mat.avSubMaterials[iSubMat];
|
2009-03-15 00:40:30 +00:00
|
|
|
if (submat.bNeed) {
|
2008-11-16 21:56:45 +00:00
|
|
|
// Convert it to the aiMaterial layout
|
|
|
|
ConvertMaterial(submat);
|
2008-07-30 23:00:25 +00:00
|
|
|
++pcScene->mNumMaterials;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// allocate the output material array
|
|
|
|
pcScene->mMaterials = new aiMaterial*[pcScene->mNumMaterials];
|
2008-10-31 19:32:00 +00:00
|
|
|
D3DS::Material** pcIntMaterials = new D3DS::Material*[pcScene->mNumMaterials];
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-07-30 23:00:25 +00:00
|
|
|
unsigned int iNum = 0;
|
2009-03-15 00:40:30 +00:00
|
|
|
for (unsigned int iMat = 0; iMat < mParser->m_vMaterials.size();++iMat) {
|
2008-11-16 21:56:45 +00:00
|
|
|
ASE::Material& mat = mParser->m_vMaterials[iMat];
|
|
|
|
if (mat.bNeed)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-11-16 21:56:45 +00:00
|
|
|
ai_assert(NULL != mat.pcInstance);
|
|
|
|
pcScene->mMaterials[iNum] = mat.pcInstance;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
// Store the internal material, too
|
|
|
|
pcIntMaterials[iNum] = &mat;
|
2008-06-03 21:50:53 +00:00
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
// Iterate through all meshes and search for one which is using
|
2008-05-09 17:24:28 +00:00
|
|
|
// this top-level material index
|
|
|
|
for (unsigned int iMesh = 0; iMesh < pcScene->mNumMeshes;++iMesh)
|
|
|
|
{
|
2008-11-16 21:56:45 +00:00
|
|
|
aiMesh* mesh = pcScene->mMeshes[iMesh];
|
|
|
|
if (ASE::Face::DEFAULT_MATINDEX == mesh->mMaterialIndex &&
|
|
|
|
iMat == (uintptr_t)mesh->mColors[3])
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-11-16 21:56:45 +00:00
|
|
|
mesh->mMaterialIndex = iNum;
|
|
|
|
mesh->mColors[3] = NULL;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
iNum++;
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
for (unsigned int iSubMat = 0; iSubMat < mat.avSubMaterials.size();++iSubMat) {
|
2008-11-16 21:56:45 +00:00
|
|
|
ASE::Material& submat = mat.avSubMaterials[iSubMat];
|
2009-03-15 00:40:30 +00:00
|
|
|
if (submat.bNeed) {
|
2008-11-16 21:56:45 +00:00
|
|
|
ai_assert(NULL != submat.pcInstance);
|
|
|
|
pcScene->mMaterials[iNum] = submat.pcInstance;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
// Store the internal material, too
|
|
|
|
pcIntMaterials[iNum] = &submat;
|
2008-06-03 21:50:53 +00:00
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
// Iterate through all meshes and search for one which is using
|
2008-05-09 17:24:28 +00:00
|
|
|
// this sub-level material index
|
2009-03-15 00:40:30 +00:00
|
|
|
for (unsigned int iMesh = 0; iMesh < pcScene->mNumMeshes;++iMesh) {
|
2008-11-16 21:56:45 +00:00
|
|
|
aiMesh* mesh = pcScene->mMeshes[iMesh];
|
2009-03-15 00:40:30 +00:00
|
|
|
|
|
|
|
if (iSubMat == mesh->mMaterialIndex && iMat == (uintptr_t)mesh->mColors[3]) {
|
2008-11-16 21:56:45 +00:00
|
|
|
mesh->mMaterialIndex = iNum;
|
|
|
|
mesh->mColors[3] = NULL;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
iNum++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-06-03 21:50:53 +00:00
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
// Dekete our temporary array
|
2008-06-03 21:50:53 +00:00
|
|
|
delete[] pcIntMaterials;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-11-16 21:56:45 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Generate normal vectors basing on smoothing groups
|
2009-03-15 00:40:30 +00:00
|
|
|
bool ASEImporter::GenerateNormals(ASE::Mesh& mesh) {
|
|
|
|
|
2008-10-27 00:36:26 +00:00
|
|
|
if (!mesh.mNormals.empty() && !configRecomputeNormals)
|
2008-08-08 18:25:55 +00:00
|
|
|
{
|
2009-03-15 00:40:30 +00:00
|
|
|
// Check whether there are only uninitialized normals. If there are
|
2008-08-08 18:25:55 +00:00
|
|
|
// some, skip all normals from the file and compute them on our own
|
2009-03-15 00:40:30 +00:00
|
|
|
for (std::vector<aiVector3D>::const_iterator qq = mesh.mNormals.begin();qq != mesh.mNormals.end();++qq) {
|
2008-10-22 20:06:16 +00:00
|
|
|
if ((*qq).x || (*qq).y || (*qq).z)
|
2008-08-08 18:25:55 +00:00
|
|
|
{
|
2008-10-27 00:36:26 +00:00
|
|
|
return true;
|
2008-08-08 18:25:55 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-27 16:46:05 +00:00
|
|
|
}
|
2010-03-23 18:22:45 +00:00
|
|
|
// The array is reused.
|
2008-10-27 00:36:26 +00:00
|
|
|
ComputeNormalsWithSmoothingsGroups<ASE::Face>(mesh);
|
|
|
|
return false;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
|
|
|
#endif // !! ASSIMP_BUILD_NO_BASE_IMPORTER
|