2008-10-24 20:37:54 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
2012-02-03 03:38:30 +00:00
|
|
|
Open Asset Import Library (assimp)
|
2008-10-24 20:37:54 +00:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2012-02-03 03:38:30 +00:00
|
|
|
Copyright (c) 2006-2012, assimp team
|
2008-10-24 20:37:54 +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-10-24 20:37:54 +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-10-24 20:37:54 +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.
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file Implementation of the IrrMesh importer class */
|
|
|
|
|
2015-04-15 23:00:17 +00:00
|
|
|
|
2008-10-24 20:37:54 +00:00
|
|
|
|
2013-10-07 23:32:46 +00:00
|
|
|
#ifndef ASSIMP_BUILD_NO_IRRMESH_IMPORTER
|
2012-12-20 11:43:09 +00:00
|
|
|
|
2008-10-24 20:37:54 +00:00
|
|
|
#include "IRRMeshLoader.h"
|
|
|
|
#include "ParsingUtils.h"
|
2015-04-15 23:00:17 +00:00
|
|
|
#include "fast_atof.h"
|
|
|
|
#include <boost/scoped_ptr.hpp>
|
|
|
|
#include "../include/assimp/IOSystem.hpp"
|
|
|
|
#include "../include/assimp/mesh.h"
|
|
|
|
#include "../include/assimp/DefaultLogger.hpp"
|
|
|
|
#include "../include/assimp/material.h"
|
|
|
|
#include "../include/assimp/scene.h"
|
|
|
|
#include "Macros.h"
|
|
|
|
|
2008-10-24 20:37:54 +00:00
|
|
|
|
|
|
|
using namespace Assimp;
|
2009-03-03 15:43:26 +00:00
|
|
|
using namespace irr;
|
|
|
|
using namespace irr::io;
|
2008-10-24 20:37:54 +00:00
|
|
|
|
2012-04-22 22:26:26 +00:00
|
|
|
static const aiImporterDesc desc = {
|
|
|
|
"Irrlicht Mesh Reader",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"http://irrlicht.sourceforge.net/",
|
|
|
|
aiImporterFlags_SupportTextFlavour,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
"xml irrmesh"
|
|
|
|
};
|
|
|
|
|
2008-10-27 00:36:26 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Constructor to be privately used by Importer
|
|
|
|
IRRMeshImporter::IRRMeshImporter()
|
2009-03-15 00:40:30 +00:00
|
|
|
{}
|
2008-10-27 00:36:26 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Destructor, private as well
|
|
|
|
IRRMeshImporter::~IRRMeshImporter()
|
2009-03-15 00:40:30 +00:00
|
|
|
{}
|
2008-10-27 00:36:26 +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 IRRMeshImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const
|
2008-10-27 00:36:26 +00:00
|
|
|
{
|
|
|
|
/* NOTE: A simple check for the file extension is not enough
|
|
|
|
* here. Irrmesh and irr are easy, but xml is too generic
|
|
|
|
* and could be collada, too. So we need to open the file and
|
|
|
|
* search for typical tokens.
|
|
|
|
*/
|
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
|
|
|
const std::string extension = GetExtension(pFile);
|
2008-10-27 00:36:26 +00:00
|
|
|
|
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
|
|
|
if (extension == "irrmesh")return true;
|
|
|
|
else if (extension == "xml" || checkSig)
|
2008-10-27 00:36:26 +00:00
|
|
|
{
|
|
|
|
/* If CanRead() is called to check whether the loader
|
|
|
|
* supports a specific file extension in general we
|
|
|
|
* must return true here.
|
|
|
|
*/
|
|
|
|
if (!pIOHandler)return true;
|
|
|
|
const char* tokens[] = {"irrmesh"};
|
|
|
|
return SearchFileHeaderForToken(pIOHandler,pFile,tokens,1);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Get a list of all file extensions which are handled by this class
|
2012-04-22 22:26:26 +00:00
|
|
|
const aiImporterDesc* IRRMeshImporter::GetInfo () const
|
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
|
|
|
{
|
2012-04-22 22:26:26 +00:00
|
|
|
return &desc;
|
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
|
|
|
}
|
|
|
|
|
2008-10-24 20:37:54 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Imports the given file into the given scene structure.
|
|
|
|
void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
|
|
|
aiScene* pScene, IOSystem* pIOHandler)
|
|
|
|
{
|
|
|
|
boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile));
|
|
|
|
|
|
|
|
// Check whether we can read from the file
|
|
|
|
if( file.get() == NULL)
|
2010-03-18 17:00:12 +00:00
|
|
|
throw DeadlyImportError( "Failed to open IRRMESH file " + pFile + "");
|
2008-10-24 20:37:54 +00:00
|
|
|
|
|
|
|
// Construct the irrXML parser
|
|
|
|
CIrrXML_IOStreamReader st(file.get());
|
|
|
|
reader = createIrrXMLReader((IFileReadCallBack*) &st);
|
|
|
|
|
|
|
|
// final data
|
|
|
|
std::vector<aiMaterial*> materials;
|
|
|
|
std::vector<aiMesh*> meshes;
|
|
|
|
materials.reserve (5);
|
|
|
|
meshes.reserve (5);
|
|
|
|
|
|
|
|
// temporary data - current mesh buffer
|
|
|
|
aiMaterial* curMat = NULL;
|
|
|
|
aiMesh* curMesh = NULL;
|
2011-09-04 15:09:45 +00:00
|
|
|
unsigned int curMatFlags = 0;
|
2008-10-24 20:37:54 +00:00
|
|
|
|
|
|
|
std::vector<aiVector3D> curVertices,curNormals,curTangents,curBitangents;
|
|
|
|
std::vector<aiColor4D> curColors;
|
|
|
|
std::vector<aiVector3D> curUVs,curUV2s;
|
|
|
|
|
|
|
|
// some temporary variables
|
|
|
|
int textMeaning = 0;
|
|
|
|
int vertexFormat = 0; // 0 = normal; 1 = 2 tcoords, 2 = tangents
|
|
|
|
bool useColors = false;
|
|
|
|
|
|
|
|
// Parse the XML file
|
2009-03-15 00:40:30 +00:00
|
|
|
while (reader->read()) {
|
|
|
|
switch (reader->getNodeType()) {
|
2008-10-24 20:37:54 +00:00
|
|
|
case EXN_ELEMENT:
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
if (!ASSIMP_stricmp(reader->getNodeName(),"buffer") && (curMat || curMesh)) {
|
2008-10-24 20:37:54 +00:00
|
|
|
// end of previous buffer. A material and a mesh should be there
|
2009-03-15 00:40:30 +00:00
|
|
|
if ( !curMat || !curMesh) {
|
2008-10-24 20:37:54 +00:00
|
|
|
DefaultLogger::get()->error("IRRMESH: A buffer must contain a mesh and a material");
|
|
|
|
delete curMat;
|
|
|
|
delete curMesh;
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
else {
|
2008-10-24 20:37:54 +00:00
|
|
|
materials.push_back(curMat);
|
|
|
|
meshes.push_back(curMesh);
|
|
|
|
}
|
|
|
|
curMat = NULL;
|
|
|
|
curMesh = NULL;
|
|
|
|
|
|
|
|
curVertices.clear();
|
|
|
|
curColors.clear();
|
|
|
|
curNormals.clear();
|
|
|
|
curUV2s.clear();
|
|
|
|
curUVs.clear();
|
2008-10-27 00:36:26 +00:00
|
|
|
curTangents.clear();
|
|
|
|
curBitangents.clear();
|
2008-10-24 20:37:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
if (!ASSIMP_stricmp(reader->getNodeName(),"material")) {
|
|
|
|
if (curMat) {
|
2008-10-24 20:37:54 +00:00
|
|
|
DefaultLogger::get()->warn("IRRMESH: Only one material description per buffer, please");
|
2008-11-16 21:56:45 +00:00
|
|
|
delete curMat;curMat = NULL;
|
2008-10-24 20:37:54 +00:00
|
|
|
}
|
|
|
|
curMat = ParseMaterial(curMatFlags);
|
|
|
|
}
|
|
|
|
/* no else here! */ if (!ASSIMP_stricmp(reader->getNodeName(),"vertices"))
|
|
|
|
{
|
|
|
|
int num = reader->getAttributeValueAsInt("vertexCount");
|
2008-11-16 21:56:45 +00:00
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
if (!num) {
|
|
|
|
// This is possible ... remove the mesh from the list and skip further reading
|
2008-11-16 21:56:45 +00:00
|
|
|
DefaultLogger::get()->warn("IRRMESH: Found mesh with zero vertices");
|
|
|
|
|
|
|
|
delete curMat;curMat = NULL;
|
|
|
|
|
|
|
|
curMesh = NULL;
|
|
|
|
textMeaning = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-10-24 20:37:54 +00:00
|
|
|
curVertices.reserve (num);
|
|
|
|
curNormals.reserve (num);
|
|
|
|
curColors.reserve (num);
|
|
|
|
curUVs.reserve (num);
|
|
|
|
|
|
|
|
// Determine the file format
|
|
|
|
const char* t = reader->getAttributeValueSafe("type");
|
2009-03-15 00:40:30 +00:00
|
|
|
if (!ASSIMP_stricmp("2tcoords", t)) {
|
2008-10-24 20:37:54 +00:00
|
|
|
curUV2s.reserve (num);
|
|
|
|
vertexFormat = 1;
|
2008-11-05 12:26:11 +00:00
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
if (curMatFlags & AI_IRRMESH_EXTRA_2ND_TEXTURE) {
|
2008-11-05 12:26:11 +00:00
|
|
|
// *********************************************************
|
|
|
|
// We have a second texture! So use this UV channel
|
|
|
|
// for it. The 2nd texture can be either a normal
|
|
|
|
// texture (solid_2layer or lightmap_xxx) or a normal
|
|
|
|
// map (normal_..., parallax_...)
|
|
|
|
// *********************************************************
|
|
|
|
int idx = 1;
|
2011-08-22 20:22:51 +00:00
|
|
|
aiMaterial* mat = ( aiMaterial* ) curMat;
|
2008-11-05 12:26:11 +00:00
|
|
|
|
2009-02-11 22:24:17 +00:00
|
|
|
if (curMatFlags & AI_IRRMESH_MAT_lightmap){
|
2009-02-11 20:56:05 +00:00
|
|
|
mat->AddProperty(&idx,1,AI_MATKEY_UVWSRC_LIGHTMAP(0));
|
2008-11-05 12:26:11 +00:00
|
|
|
}
|
2009-02-11 20:56:05 +00:00
|
|
|
else if (curMatFlags & AI_IRRMESH_MAT_normalmap_solid){
|
2008-11-05 12:26:11 +00:00
|
|
|
mat->AddProperty(&idx,1,AI_MATKEY_UVWSRC_NORMALS(0));
|
|
|
|
}
|
2009-02-11 22:24:17 +00:00
|
|
|
else if (curMatFlags & AI_IRRMESH_MAT_solid_2layer) {
|
|
|
|
mat->AddProperty(&idx,1,AI_MATKEY_UVWSRC_DIFFUSE(1));
|
|
|
|
}
|
2008-11-05 12:26:11 +00:00
|
|
|
}
|
2008-10-24 20:37:54 +00:00
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
else if (!ASSIMP_stricmp("tangents", t)) {
|
2008-10-24 20:37:54 +00:00
|
|
|
curTangents.reserve (num);
|
|
|
|
curBitangents.reserve (num);
|
|
|
|
vertexFormat = 2;
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
else if (ASSIMP_stricmp("standard", t)) {
|
2008-11-16 21:56:45 +00:00
|
|
|
delete curMat;
|
2008-10-24 20:37:54 +00:00
|
|
|
DefaultLogger::get()->warn("IRRMESH: Unknown vertex format");
|
|
|
|
}
|
|
|
|
else vertexFormat = 0;
|
|
|
|
textMeaning = 1;
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
else if (!ASSIMP_stricmp(reader->getNodeName(),"indices")) {
|
|
|
|
if (curVertices.empty() && curMat) {
|
2008-11-16 21:56:45 +00:00
|
|
|
delete curMat;
|
2010-03-18 17:00:12 +00:00
|
|
|
throw DeadlyImportError("IRRMESH: indices must come after vertices");
|
2008-11-16 21:56:45 +00:00
|
|
|
}
|
2008-10-24 20:37:54 +00:00
|
|
|
|
|
|
|
textMeaning = 2;
|
|
|
|
|
|
|
|
// start a new mesh
|
|
|
|
curMesh = new aiMesh();
|
|
|
|
|
|
|
|
// allocate storage for all faces
|
|
|
|
curMesh->mNumVertices = reader->getAttributeValueAsInt("indexCount");
|
2009-03-15 00:40:30 +00:00
|
|
|
if (!curMesh->mNumVertices) {
|
|
|
|
// This is possible ... remove the mesh from the list and skip further reading
|
2008-11-16 21:56:45 +00:00
|
|
|
DefaultLogger::get()->warn("IRRMESH: Found mesh with zero indices");
|
|
|
|
|
|
|
|
// mesh - away
|
|
|
|
delete curMesh; curMesh = NULL;
|
|
|
|
|
|
|
|
// material - away
|
|
|
|
delete curMat;curMat = NULL;
|
|
|
|
|
|
|
|
textMeaning = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
if (curMesh->mNumVertices % 3) {
|
2008-10-24 20:37:54 +00:00
|
|
|
DefaultLogger::get()->warn("IRRMESH: Number if indices isn't divisible by 3");
|
|
|
|
}
|
|
|
|
|
|
|
|
curMesh->mNumFaces = curMesh->mNumVertices / 3;
|
|
|
|
curMesh->mFaces = new aiFace[curMesh->mNumFaces];
|
|
|
|
|
|
|
|
// setup some members
|
|
|
|
curMesh->mMaterialIndex = (unsigned int)materials.size();
|
|
|
|
curMesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
|
|
|
|
|
|
|
|
// allocate storage for all vertices
|
|
|
|
curMesh->mVertices = new aiVector3D[curMesh->mNumVertices];
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
if (curNormals.size() == curVertices.size()) {
|
2008-10-24 20:37:54 +00:00
|
|
|
curMesh->mNormals = new aiVector3D[curMesh->mNumVertices];
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
if (curTangents.size() == curVertices.size()) {
|
2008-10-24 20:37:54 +00:00
|
|
|
curMesh->mTangents = new aiVector3D[curMesh->mNumVertices];
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
if (curBitangents.size() == curVertices.size()) {
|
2008-10-24 20:37:54 +00:00
|
|
|
curMesh->mBitangents = new aiVector3D[curMesh->mNumVertices];
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
if (curColors.size() == curVertices.size() && useColors) {
|
2008-10-24 20:37:54 +00:00
|
|
|
curMesh->mColors[0] = new aiColor4D[curMesh->mNumVertices];
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
if (curUVs.size() == curVertices.size()) {
|
2008-10-24 20:37:54 +00:00
|
|
|
curMesh->mTextureCoords[0] = new aiVector3D[curMesh->mNumVertices];
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
if (curUV2s.size() == curVertices.size()) {
|
2008-10-24 20:37:54 +00:00
|
|
|
curMesh->mTextureCoords[1] = new aiVector3D[curMesh->mNumVertices];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EXN_TEXT:
|
|
|
|
{
|
|
|
|
const char* sz = reader->getNodeData();
|
2009-03-15 00:40:30 +00:00
|
|
|
if (textMeaning == 1) {
|
2008-10-24 20:37:54 +00:00
|
|
|
textMeaning = 0;
|
|
|
|
|
|
|
|
// read vertices
|
2009-03-15 00:40:30 +00:00
|
|
|
do {
|
2008-10-24 20:37:54 +00:00
|
|
|
SkipSpacesAndLineEnd(&sz);
|
|
|
|
aiVector3D temp;aiColor4D c;
|
|
|
|
|
|
|
|
// Read the vertex position
|
2012-01-31 16:18:32 +00:00
|
|
|
sz = fast_atoreal_move<float>(sz,(float&)temp.x);
|
2008-10-24 20:37:54 +00:00
|
|
|
SkipSpaces(&sz);
|
|
|
|
|
2012-01-31 16:18:32 +00:00
|
|
|
sz = fast_atoreal_move<float>(sz,(float&)temp.y);
|
2008-10-24 20:37:54 +00:00
|
|
|
SkipSpaces(&sz);
|
|
|
|
|
2012-01-31 16:18:32 +00:00
|
|
|
sz = fast_atoreal_move<float>(sz,(float&)temp.z);
|
2008-10-24 20:37:54 +00:00
|
|
|
SkipSpaces(&sz);
|
|
|
|
curVertices.push_back(temp);
|
|
|
|
|
|
|
|
// Read the vertex normals
|
2012-01-31 16:18:32 +00:00
|
|
|
sz = fast_atoreal_move<float>(sz,(float&)temp.x);
|
2008-10-24 20:37:54 +00:00
|
|
|
SkipSpaces(&sz);
|
|
|
|
|
2012-01-31 16:18:32 +00:00
|
|
|
sz = fast_atoreal_move<float>(sz,(float&)temp.y);
|
2008-10-24 20:37:54 +00:00
|
|
|
SkipSpaces(&sz);
|
|
|
|
|
2012-01-31 16:18:32 +00:00
|
|
|
sz = fast_atoreal_move<float>(sz,(float&)temp.z);
|
2008-10-24 20:37:54 +00:00
|
|
|
SkipSpaces(&sz);
|
|
|
|
curNormals.push_back(temp);
|
|
|
|
|
|
|
|
// read the vertex colors
|
2011-03-23 14:26:19 +00:00
|
|
|
uint32_t clr = strtoul16(sz,&sz);
|
2008-10-24 20:37:54 +00:00
|
|
|
ColorFromARGBPacked(clr,c);
|
|
|
|
|
|
|
|
if (!curColors.empty() && c != *(curColors.end()-1))
|
|
|
|
useColors = true;
|
|
|
|
|
|
|
|
curColors.push_back(c);
|
|
|
|
SkipSpaces(&sz);
|
|
|
|
|
|
|
|
|
|
|
|
// read the first UV coordinate set
|
2012-01-31 16:18:32 +00:00
|
|
|
sz = fast_atoreal_move<float>(sz,(float&)temp.x);
|
2008-10-24 20:37:54 +00:00
|
|
|
SkipSpaces(&sz);
|
|
|
|
|
2012-01-31 16:18:32 +00:00
|
|
|
sz = fast_atoreal_move<float>(sz,(float&)temp.y);
|
2008-10-24 20:37:54 +00:00
|
|
|
SkipSpaces(&sz);
|
|
|
|
temp.z = 0.f;
|
|
|
|
temp.y = 1.f - temp.y; // DX to OGL
|
|
|
|
curUVs.push_back(temp);
|
|
|
|
|
|
|
|
// read the (optional) second UV coordinate set
|
2009-03-15 00:40:30 +00:00
|
|
|
if (vertexFormat == 1) {
|
2012-01-31 16:18:32 +00:00
|
|
|
sz = fast_atoreal_move<float>(sz,(float&)temp.x);
|
2008-10-24 20:37:54 +00:00
|
|
|
SkipSpaces(&sz);
|
|
|
|
|
2012-01-31 16:18:32 +00:00
|
|
|
sz = fast_atoreal_move<float>(sz,(float&)temp.y);
|
2008-10-24 20:37:54 +00:00
|
|
|
temp.y = 1.f - temp.y; // DX to OGL
|
|
|
|
curUV2s.push_back(temp);
|
|
|
|
}
|
|
|
|
// read optional tangent and bitangent vectors
|
2009-03-15 00:40:30 +00:00
|
|
|
else if (vertexFormat == 2) {
|
2008-10-24 20:37:54 +00:00
|
|
|
// tangents
|
2012-01-31 16:18:32 +00:00
|
|
|
sz = fast_atoreal_move<float>(sz,(float&)temp.x);
|
2008-10-24 20:37:54 +00:00
|
|
|
SkipSpaces(&sz);
|
|
|
|
|
2012-01-31 16:18:32 +00:00
|
|
|
sz = fast_atoreal_move<float>(sz,(float&)temp.z);
|
2008-10-24 20:37:54 +00:00
|
|
|
SkipSpaces(&sz);
|
|
|
|
|
2012-01-31 16:18:32 +00:00
|
|
|
sz = fast_atoreal_move<float>(sz,(float&)temp.y);
|
2008-10-24 20:37:54 +00:00
|
|
|
SkipSpaces(&sz);
|
|
|
|
temp.y *= -1.0f;
|
|
|
|
curTangents.push_back(temp);
|
|
|
|
|
|
|
|
// bitangents
|
2012-01-31 16:18:32 +00:00
|
|
|
sz = fast_atoreal_move<float>(sz,(float&)temp.x);
|
2008-10-24 20:37:54 +00:00
|
|
|
SkipSpaces(&sz);
|
|
|
|
|
2012-01-31 16:18:32 +00:00
|
|
|
sz = fast_atoreal_move<float>(sz,(float&)temp.z);
|
2008-10-24 20:37:54 +00:00
|
|
|
SkipSpaces(&sz);
|
|
|
|
|
2012-01-31 16:18:32 +00:00
|
|
|
sz = fast_atoreal_move<float>(sz,(float&)temp.y);
|
2008-10-24 20:37:54 +00:00
|
|
|
SkipSpaces(&sz);
|
|
|
|
temp.y *= -1.0f;
|
|
|
|
curBitangents.push_back(temp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IMPORTANT: We assume that each vertex is specified in one
|
|
|
|
line. So we can skip the rest of the line - unknown vertex
|
|
|
|
elements are ignored.
|
|
|
|
*/
|
|
|
|
|
|
|
|
while (SkipLine(&sz));
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
else if (textMeaning == 2) {
|
2008-10-24 20:37:54 +00:00
|
|
|
textMeaning = 0;
|
|
|
|
|
|
|
|
// read indices
|
|
|
|
aiFace* curFace = curMesh->mFaces;
|
|
|
|
aiFace* const faceEnd = curMesh->mFaces + curMesh->mNumFaces;
|
|
|
|
|
|
|
|
aiVector3D* pcV = curMesh->mVertices;
|
|
|
|
aiVector3D* pcN = curMesh->mNormals;
|
|
|
|
aiVector3D* pcT = curMesh->mTangents;
|
|
|
|
aiVector3D* pcB = curMesh->mBitangents;
|
|
|
|
aiColor4D* pcC0 = curMesh->mColors[0];
|
|
|
|
aiVector3D* pcT0 = curMesh->mTextureCoords[0];
|
|
|
|
aiVector3D* pcT1 = curMesh->mTextureCoords[1];
|
|
|
|
|
|
|
|
unsigned int curIdx = 0;
|
|
|
|
unsigned int total = 0;
|
2009-03-15 00:40:30 +00:00
|
|
|
while(SkipSpacesAndLineEnd(&sz)) {
|
|
|
|
if (curFace >= faceEnd) {
|
2008-10-24 20:37:54 +00:00
|
|
|
DefaultLogger::get()->error("IRRMESH: Too many indices");
|
|
|
|
break;
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
if (!curIdx) {
|
2008-10-24 20:37:54 +00:00
|
|
|
curFace->mNumIndices = 3;
|
|
|
|
curFace->mIndices = new unsigned int[3];
|
|
|
|
}
|
|
|
|
|
2011-03-23 14:26:19 +00:00
|
|
|
unsigned int idx = strtoul10(sz,&sz);
|
2009-03-15 00:40:30 +00:00
|
|
|
if (idx >= curVertices.size()) {
|
2008-10-24 20:37:54 +00:00
|
|
|
DefaultLogger::get()->error("IRRMESH: Index out of range");
|
|
|
|
idx = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
curFace->mIndices[curIdx] = total++;
|
|
|
|
|
|
|
|
*pcV++ = curVertices[idx];
|
|
|
|
if (pcN)*pcN++ = curNormals[idx];
|
|
|
|
if (pcT)*pcT++ = curTangents[idx];
|
|
|
|
if (pcB)*pcB++ = curBitangents[idx];
|
|
|
|
if (pcC0)*pcC0++ = curColors[idx];
|
|
|
|
if (pcT0)*pcT0++ = curUVs[idx];
|
|
|
|
if (pcT1)*pcT1++ = curUV2s[idx];
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
if (++curIdx == 3) {
|
2008-10-24 20:37:54 +00:00
|
|
|
++curFace;
|
|
|
|
curIdx = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (curFace != faceEnd)
|
|
|
|
DefaultLogger::get()->error("IRRMESH: Not enough indices");
|
|
|
|
|
|
|
|
// Finish processing the mesh - do some small material workarounds
|
2009-03-15 00:40:30 +00:00
|
|
|
if (curMatFlags & AI_IRRMESH_MAT_trans_vertex_alpha && !useColors) {
|
2008-10-24 20:37:54 +00:00
|
|
|
// Take the opacity value of the current material
|
|
|
|
// from the common vertex color alpha
|
2011-08-22 20:22:51 +00:00
|
|
|
aiMaterial* mat = (aiMaterial*)curMat;
|
2008-10-24 20:37:54 +00:00
|
|
|
mat->AddProperty(&curColors[0].a,1,AI_MATKEY_OPACITY);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
// GCC complains here ...
|
|
|
|
break;
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
// End of the last buffer. A material and a mesh should be there
|
2009-03-15 00:40:30 +00:00
|
|
|
if (curMat || curMesh) {
|
|
|
|
if ( !curMat || !curMesh) {
|
2008-10-24 20:37:54 +00:00
|
|
|
DefaultLogger::get()->error("IRRMESH: A buffer must contain a mesh and a material");
|
|
|
|
delete curMat;
|
|
|
|
delete curMesh;
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
else {
|
2008-10-24 20:37:54 +00:00
|
|
|
materials.push_back(curMat);
|
|
|
|
meshes.push_back(curMesh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-27 00:36:26 +00:00
|
|
|
if (materials.empty())
|
2010-03-18 17:00:12 +00:00
|
|
|
throw DeadlyImportError("IRRMESH: Unable to read a mesh from this file");
|
2008-10-27 00:36:26 +00:00
|
|
|
|
2008-11-04 20:41:11 +00:00
|
|
|
|
2008-10-24 20:37:54 +00:00
|
|
|
// now generate the output scene
|
|
|
|
pScene->mNumMeshes = (unsigned int)meshes.size();
|
|
|
|
pScene->mMeshes = new aiMesh*[pScene->mNumMeshes];
|
2009-03-15 00:40:30 +00:00
|
|
|
for (unsigned int i = 0; i < pScene->mNumMeshes;++i) {
|
2008-11-04 20:41:11 +00:00
|
|
|
pScene->mMeshes[i] = meshes[i];
|
|
|
|
|
|
|
|
// clean this value ...
|
|
|
|
pScene->mMeshes[i]->mNumUVComponents[3] = 0;
|
|
|
|
}
|
2008-10-24 20:37:54 +00:00
|
|
|
|
|
|
|
pScene->mNumMaterials = (unsigned int)materials.size();
|
|
|
|
pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials];
|
|
|
|
::memcpy(pScene->mMaterials,&materials[0],sizeof(void*)*pScene->mNumMaterials);
|
|
|
|
|
|
|
|
pScene->mRootNode = new aiNode();
|
|
|
|
pScene->mRootNode->mName.Set("<IRRMesh>");
|
|
|
|
pScene->mRootNode->mNumMeshes = pScene->mNumMeshes;
|
|
|
|
pScene->mRootNode->mMeshes = new unsigned int[pScene->mNumMeshes];
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < pScene->mNumMeshes;++i)
|
|
|
|
pScene->mRootNode->mMeshes[i] = i;
|
|
|
|
|
2009-01-18 23:48:25 +00:00
|
|
|
// clean up and return
|
2008-10-24 20:37:54 +00:00
|
|
|
delete reader;
|
|
|
|
AI_DEBUG_INVALIDATE_PTR(reader);
|
2008-12-07 20:00:58 +00:00
|
|
|
}
|
2012-12-20 11:43:09 +00:00
|
|
|
|
2013-10-07 23:32:46 +00:00
|
|
|
#endif // !! ASSIMP_BUILD_NO_IRRMESH_IMPORTER
|