2008-10-13 16:45:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
2012-02-03 03:38:30 +00:00
|
|
|
Open Asset Import Library (assimp)
|
2008-10-13 16:45:48 +00:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2012-02-03 03:38:30 +00:00
|
|
|
Copyright (c) 2006-2012, assimp team
|
2008-10-13 16:45:48 +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-13 16:45:48 +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-13 16:45:48 +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 AC3D importer class */
|
|
|
|
|
|
|
|
#include "AssimpPCH.h"
|
|
|
|
|
2010-05-10 10:22:24 +00:00
|
|
|
#ifndef ASSIMP_BUILD_NO_AC_IMPORTER
|
2008-10-13 16:45:48 +00:00
|
|
|
|
|
|
|
// internal headers
|
|
|
|
#include "ACLoader.h"
|
|
|
|
#include "ParsingUtils.h"
|
|
|
|
#include "fast_atof.h"
|
2010-01-28 21:17:25 +00:00
|
|
|
#include "Subdivision.h"
|
2008-10-13 16:45:48 +00:00
|
|
|
|
|
|
|
using namespace Assimp;
|
|
|
|
|
2012-04-22 22:26:26 +00:00
|
|
|
static const aiImporterDesc desc = {
|
|
|
|
"AC3D Importer",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
aiImporterFlags_SupportTextFlavour,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
"ac acc ac3d"
|
|
|
|
};
|
2008-10-13 16:45:48 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// skip to the next token
|
|
|
|
#define AI_AC_SKIP_TO_NEXT_TOKEN() \
|
|
|
|
if (!SkipSpaces(&buffer)) \
|
|
|
|
{ \
|
|
|
|
DefaultLogger::get()->error("AC3D: Unexpected EOF/EOL"); \
|
|
|
|
continue; \
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-10-31 19:32:00 +00:00
|
|
|
// read a string (may be enclosed in double quotation marks). buffer must point to "
|
2008-10-13 16:45:48 +00:00
|
|
|
#define AI_AC_GET_STRING(out) \
|
|
|
|
++buffer; \
|
|
|
|
const char* sz = buffer; \
|
|
|
|
while ('\"' != *buffer) \
|
|
|
|
{ \
|
|
|
|
if (IsLineEnd( *buffer )) \
|
|
|
|
{ \
|
|
|
|
DefaultLogger::get()->error("AC3D: Unexpected EOF/EOL in string"); \
|
|
|
|
out = "ERROR"; \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
++buffer; \
|
|
|
|
} \
|
|
|
|
if (IsLineEnd( *buffer ))continue; \
|
|
|
|
out = std::string(sz,(unsigned int)(buffer-sz)); \
|
|
|
|
++buffer;
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// read 1 to n floats prefixed with an optional predefined identifier
|
|
|
|
#define AI_AC_CHECKED_LOAD_FLOAT_ARRAY(name,name_length,num,out) \
|
|
|
|
AI_AC_SKIP_TO_NEXT_TOKEN(); \
|
|
|
|
if (name_length) \
|
|
|
|
{ \
|
|
|
|
if (strncmp(buffer,name,name_length) || !IsSpace(buffer[name_length])) \
|
|
|
|
{ \
|
|
|
|
DefaultLogger::get()->error("AC3D: Unexpexted token. " name " was expected."); \
|
|
|
|
continue; \
|
|
|
|
} \
|
|
|
|
buffer += name_length+1; \
|
|
|
|
} \
|
|
|
|
for (unsigned int i = 0; i < num;++i) \
|
|
|
|
{ \
|
|
|
|
AI_AC_SKIP_TO_NEXT_TOKEN(); \
|
2012-01-31 16:18:32 +00:00
|
|
|
buffer = fast_atoreal_move<float>(buffer,((float*)out)[i]); \
|
2008-10-13 16:45:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Constructor to be privately used by Importer
|
|
|
|
AC3DImporter::AC3DImporter()
|
|
|
|
{
|
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
|
|
|
// nothing to be done here
|
2008-10-13 16:45:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Destructor, private as well
|
|
|
|
AC3DImporter::~AC3DImporter()
|
|
|
|
{
|
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
|
|
|
// nothing to be done here
|
2008-10-13 16:45:48 +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 AC3DImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const
|
2008-10-13 16:45:48 +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
|
|
|
std::string extension = GetExtension(pFile);
|
2008-10-13 16:45:48 +00:00
|
|
|
|
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
|
|
|
// fixme: are acc and ac3d *really* used? Some sources say they are
|
|
|
|
if(extension == "ac" || extension == "ac3d" || extension == "acc") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!extension.length() || checkSig) {
|
|
|
|
uint32_t token = AI_MAKE_MAGIC("AC3D");
|
|
|
|
return CheckMagicToken(pIOHandler,pFile,&token,1,0);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2008-10-19 11:32:33 +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
|
|
|
// ------------------------------------------------------------------------------------------------
|
2012-04-22 22:26:26 +00:00
|
|
|
// Loader meta information
|
|
|
|
const aiImporterDesc* AC3DImporter::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-13 16:45:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Get a pointer to the next line from the file
|
|
|
|
bool AC3DImporter::GetNextLine( )
|
|
|
|
{
|
|
|
|
SkipLine(&buffer);
|
|
|
|
return SkipSpaces(&buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Parse an object section in an AC file
|
|
|
|
void AC3DImporter::LoadObjectSection(std::vector<Object>& objects)
|
|
|
|
{
|
|
|
|
if (!TokenMatch(buffer,"OBJECT",6))
|
|
|
|
return;
|
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
SkipSpaces(&buffer);
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
++mNumMeshes;
|
|
|
|
|
|
|
|
objects.push_back(Object());
|
|
|
|
Object& obj = objects.back();
|
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
aiLight* light = NULL;
|
2008-11-26 13:17:39 +00:00
|
|
|
if (!ASSIMP_strincmp(buffer,"light",5))
|
2008-11-16 21:56:45 +00:00
|
|
|
{
|
|
|
|
// This is a light source. Add it to the list
|
|
|
|
mLights->push_back(light = new aiLight());
|
|
|
|
|
|
|
|
// Return a point light with no attenuation
|
|
|
|
light->mType = aiLightSource_POINT;
|
|
|
|
light->mColorDiffuse = light->mColorSpecular = aiColor3D(1.f,1.f,1.f);
|
|
|
|
light->mAttenuationConstant = 1.f;
|
|
|
|
|
|
|
|
// Generate a default name for both the light source and the node
|
2010-01-28 23:01:33 +00:00
|
|
|
// FIXME - what's the right way to print a size_t? Is 'zu' universally available? stick with the safe version.
|
|
|
|
light->mName.length = ::sprintf(light->mName.data,"ACLight_%i",static_cast<unsigned int>(mLights->size())-1);
|
2008-11-16 21:56:45 +00:00
|
|
|
obj.name = std::string( light->mName.data );
|
|
|
|
|
2008-11-26 13:17:39 +00:00
|
|
|
DefaultLogger::get()->debug("AC3D: Light source encountered");
|
|
|
|
obj.type = Object::Light;
|
|
|
|
}
|
|
|
|
else if (!ASSIMP_strincmp(buffer,"group",5))
|
|
|
|
{
|
|
|
|
obj.type = Object::Group;
|
|
|
|
}
|
|
|
|
else if (!ASSIMP_strincmp(buffer,"world",5))
|
|
|
|
{
|
|
|
|
obj.type = Object::World;
|
|
|
|
}
|
2008-12-01 15:25:38 +00:00
|
|
|
else obj.type = Object::Poly;
|
2008-10-13 16:45:48 +00:00
|
|
|
while (GetNextLine())
|
|
|
|
{
|
|
|
|
if (TokenMatch(buffer,"kids",4))
|
|
|
|
{
|
|
|
|
SkipSpaces(&buffer);
|
2011-03-23 14:26:19 +00:00
|
|
|
unsigned int num = strtoul10(buffer,&buffer);
|
2008-10-13 16:45:48 +00:00
|
|
|
GetNextLine();
|
|
|
|
if (num)
|
|
|
|
{
|
|
|
|
// load the children of this object recursively
|
|
|
|
obj.children.reserve(num);
|
2008-10-31 19:32:00 +00:00
|
|
|
for (unsigned int i = 0; i < num; ++i)
|
|
|
|
LoadObjectSection(obj.children);
|
2008-10-13 16:45:48 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(buffer,"name",4))
|
|
|
|
{
|
|
|
|
SkipSpaces(&buffer);
|
|
|
|
AI_AC_GET_STRING(obj.name);
|
2008-11-16 21:56:45 +00:00
|
|
|
|
|
|
|
// If this is a light source, we'll also need to store
|
|
|
|
// the name of the node in it.
|
|
|
|
if (light)
|
|
|
|
{
|
|
|
|
light->mName.Set(obj.name);
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
}
|
|
|
|
else if (TokenMatch(buffer,"texture",7))
|
|
|
|
{
|
|
|
|
SkipSpaces(&buffer);
|
|
|
|
AI_AC_GET_STRING(obj.texture);
|
|
|
|
}
|
|
|
|
else if (TokenMatch(buffer,"texrep",6))
|
|
|
|
{
|
|
|
|
SkipSpaces(&buffer);
|
|
|
|
AI_AC_CHECKED_LOAD_FLOAT_ARRAY("",0,2,&obj.texRepeat);
|
2008-12-01 15:25:38 +00:00
|
|
|
if (!obj.texRepeat.x || !obj.texRepeat.y)
|
|
|
|
obj.texRepeat = aiVector2D (1.f,1.f);
|
2008-10-13 16:45:48 +00:00
|
|
|
}
|
2008-11-26 13:17:39 +00:00
|
|
|
else if (TokenMatch(buffer,"texoff",6))
|
|
|
|
{
|
|
|
|
SkipSpaces(&buffer);
|
|
|
|
AI_AC_CHECKED_LOAD_FLOAT_ARRAY("",0,2,&obj.texOffset);
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(buffer,"rot",3))
|
|
|
|
{
|
|
|
|
SkipSpaces(&buffer);
|
|
|
|
AI_AC_CHECKED_LOAD_FLOAT_ARRAY("",0,9,&obj.rotation);
|
|
|
|
}
|
|
|
|
else if (TokenMatch(buffer,"loc",3))
|
|
|
|
{
|
|
|
|
SkipSpaces(&buffer);
|
|
|
|
AI_AC_CHECKED_LOAD_FLOAT_ARRAY("",0,3,&obj.translation);
|
|
|
|
}
|
2008-11-26 13:17:39 +00:00
|
|
|
else if (TokenMatch(buffer,"subdiv",6))
|
|
|
|
{
|
|
|
|
SkipSpaces(&buffer);
|
2011-03-23 14:26:19 +00:00
|
|
|
obj.subDiv = strtoul10(buffer,&buffer);
|
2008-11-26 13:17:39 +00:00
|
|
|
}
|
2010-01-28 21:17:25 +00:00
|
|
|
else if (TokenMatch(buffer,"crease",6))
|
|
|
|
{
|
|
|
|
SkipSpaces(&buffer);
|
|
|
|
obj.crease = fast_atof(buffer);
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(buffer,"numvert",7))
|
|
|
|
{
|
|
|
|
SkipSpaces(&buffer);
|
|
|
|
|
2011-03-23 14:26:19 +00:00
|
|
|
unsigned int t = strtoul10(buffer,&buffer);
|
2008-10-13 16:45:48 +00:00
|
|
|
obj.vertices.reserve(t);
|
|
|
|
for (unsigned int i = 0; i < t;++i)
|
|
|
|
{
|
|
|
|
if (!GetNextLine())
|
|
|
|
{
|
|
|
|
DefaultLogger::get()->error("AC3D: Unexpected EOF: not all vertices have been parsed yet");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (!IsNumeric(*buffer))
|
|
|
|
{
|
|
|
|
DefaultLogger::get()->error("AC3D: Unexpected token: not all vertices have been parsed yet");
|
|
|
|
--buffer; // make sure the line is processed a second time
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
obj.vertices.push_back(aiVector3D());
|
|
|
|
aiVector3D& v = obj.vertices.back();
|
|
|
|
AI_AC_CHECKED_LOAD_FLOAT_ARRAY("",0,3,&v.x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (TokenMatch(buffer,"numsurf",7))
|
|
|
|
{
|
|
|
|
SkipSpaces(&buffer);
|
|
|
|
|
2008-10-31 19:32:00 +00:00
|
|
|
bool Q3DWorkAround = false;
|
|
|
|
|
2011-03-23 14:26:19 +00:00
|
|
|
const unsigned int t = strtoul10(buffer,&buffer);
|
2008-10-13 16:45:48 +00:00
|
|
|
obj.surfaces.reserve(t);
|
|
|
|
for (unsigned int i = 0; i < t;++i)
|
|
|
|
{
|
|
|
|
GetNextLine();
|
|
|
|
if (!TokenMatch(buffer,"SURF",4))
|
|
|
|
{
|
2008-10-31 19:32:00 +00:00
|
|
|
// FIX: this can occur for some files - Quick 3D for
|
|
|
|
// example writes no surf chunks
|
|
|
|
if (!Q3DWorkAround)
|
|
|
|
{
|
|
|
|
DefaultLogger::get()->warn("AC3D: SURF token was expected");
|
|
|
|
DefaultLogger::get()->debug("Continuing with Quick3D Workaround enabled");
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
--buffer; // make sure the line is processed a second time
|
2008-10-31 19:32:00 +00:00
|
|
|
// break; --- see fix notes above
|
|
|
|
|
|
|
|
Q3DWorkAround = true;
|
2008-10-13 16:45:48 +00:00
|
|
|
}
|
|
|
|
SkipSpaces(&buffer);
|
|
|
|
obj.surfaces.push_back(Surface());
|
|
|
|
Surface& surf = obj.surfaces.back();
|
2011-03-23 14:26:19 +00:00
|
|
|
surf.flags = strtoul_cppstyle(buffer);
|
2008-10-13 16:45:48 +00:00
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
if(!GetNextLine())
|
|
|
|
{
|
|
|
|
DefaultLogger::get()->error("AC3D: Unexpected EOF: surface is incomplete");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (TokenMatch(buffer,"mat",3))
|
|
|
|
{
|
|
|
|
SkipSpaces(&buffer);
|
2011-03-23 14:26:19 +00:00
|
|
|
surf.mat = strtoul10(buffer);
|
2008-10-13 16:45:48 +00:00
|
|
|
}
|
|
|
|
else if (TokenMatch(buffer,"refs",4))
|
|
|
|
{
|
2008-10-31 19:32:00 +00:00
|
|
|
// --- see fix notes above
|
|
|
|
if (Q3DWorkAround)
|
|
|
|
{
|
|
|
|
if (!surf.entries.empty())
|
|
|
|
{
|
|
|
|
buffer -= 6;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
SkipSpaces(&buffer);
|
2011-03-23 14:26:19 +00:00
|
|
|
const unsigned int m = strtoul10(buffer);
|
2008-10-13 16:45:48 +00:00
|
|
|
surf.entries.reserve(m);
|
|
|
|
|
|
|
|
obj.numRefs += m;
|
|
|
|
|
|
|
|
for (unsigned int k = 0; k < m; ++k)
|
|
|
|
{
|
|
|
|
if(!GetNextLine())
|
|
|
|
{
|
|
|
|
DefaultLogger::get()->error("AC3D: Unexpected EOF: surface references are incomplete");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
surf.entries.push_back(Surface::SurfaceEntry());
|
|
|
|
Surface::SurfaceEntry& entry = surf.entries.back();
|
|
|
|
|
2011-03-23 14:26:19 +00:00
|
|
|
entry.first = strtoul10(buffer,&buffer);
|
2008-10-13 16:45:48 +00:00
|
|
|
SkipSpaces(&buffer);
|
|
|
|
AI_AC_CHECKED_LOAD_FLOAT_ARRAY("",0,2,&entry.second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
--buffer; // make sure the line is processed a second time
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DefaultLogger::get()->error("AC3D: Unexpected EOF: \'kids\' line was expected");
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Convert a material from AC3DImporter::Material to aiMaterial
|
|
|
|
void AC3DImporter::ConvertMaterial(const Object& object,
|
|
|
|
const Material& matSrc,
|
2011-08-22 20:22:51 +00:00
|
|
|
aiMaterial& matDest)
|
2008-10-13 16:45:48 +00:00
|
|
|
{
|
|
|
|
aiString s;
|
|
|
|
|
|
|
|
if (matSrc.name.length())
|
|
|
|
{
|
|
|
|
s.Set(matSrc.name);
|
|
|
|
matDest.AddProperty(&s,AI_MATKEY_NAME);
|
|
|
|
}
|
|
|
|
if (object.texture.length())
|
|
|
|
{
|
|
|
|
s.Set(object.texture);
|
|
|
|
matDest.AddProperty(&s,AI_MATKEY_TEXTURE_DIFFUSE(0));
|
2008-11-26 13:17:39 +00:00
|
|
|
|
|
|
|
// UV transformation
|
|
|
|
if (1.f != object.texRepeat.x || 1.f != object.texRepeat.y ||
|
|
|
|
object.texOffset.x || object.texOffset.y)
|
|
|
|
{
|
|
|
|
aiUVTransform transform;
|
|
|
|
transform.mScaling = object.texRepeat;
|
|
|
|
transform.mTranslation = object.texOffset;
|
2010-04-11 22:58:26 +00:00
|
|
|
matDest.AddProperty(&transform,1,AI_MATKEY_UVTRANSFORM_DIFFUSE(0));
|
2008-11-26 13:17:39 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
matDest.AddProperty<aiColor3D>(&matSrc.rgb,1, AI_MATKEY_COLOR_DIFFUSE);
|
|
|
|
matDest.AddProperty<aiColor3D>(&matSrc.amb,1, AI_MATKEY_COLOR_AMBIENT);
|
|
|
|
matDest.AddProperty<aiColor3D>(&matSrc.emis,1,AI_MATKEY_COLOR_EMISSIVE);
|
|
|
|
matDest.AddProperty<aiColor3D>(&matSrc.spec,1,AI_MATKEY_COLOR_SPECULAR);
|
|
|
|
|
2008-10-19 11:32:33 +00:00
|
|
|
int n;
|
|
|
|
if (matSrc.shin)
|
|
|
|
{
|
|
|
|
n = aiShadingMode_Phong;
|
|
|
|
matDest.AddProperty<float>(&matSrc.shin,1,AI_MATKEY_SHININESS);
|
|
|
|
}
|
|
|
|
else n = aiShadingMode_Gouraud;
|
|
|
|
matDest.AddProperty<int>(&n,1,AI_MATKEY_SHADING_MODEL);
|
2008-10-13 16:45:48 +00:00
|
|
|
|
2008-10-19 11:32:33 +00:00
|
|
|
float f = 1.f - matSrc.trans;
|
2008-10-13 16:45:48 +00:00
|
|
|
matDest.AddProperty<float>(&f,1,AI_MATKEY_OPACITY);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Converts the loaded data to the internal verbose representation
|
|
|
|
aiNode* AC3DImporter::ConvertObjectSection(Object& object,
|
|
|
|
std::vector<aiMesh*>& meshes,
|
2011-08-22 20:22:51 +00:00
|
|
|
std::vector<aiMaterial*>& outMaterials,
|
2008-11-26 13:17:39 +00:00
|
|
|
const std::vector<Material>& materials,
|
|
|
|
aiNode* parent)
|
2008-10-13 16:45:48 +00:00
|
|
|
{
|
|
|
|
aiNode* node = new aiNode();
|
2008-11-26 13:17:39 +00:00
|
|
|
node->mParent = parent;
|
2008-10-13 16:45:48 +00:00
|
|
|
if (object.vertices.size())
|
|
|
|
{
|
|
|
|
if (!object.surfaces.size() || !object.numRefs)
|
|
|
|
{
|
|
|
|
/* " An object with 7 vertices (no surfaces, no materials defined).
|
|
|
|
This is a good way of getting point data into AC3D.
|
|
|
|
The Vertex->create convex-surface/object can be used on these
|
|
|
|
vertices to 'wrap' a 3d shape around them "
|
|
|
|
(http://www.opencity.info/html/ac3dfileformat.html)
|
|
|
|
|
|
|
|
therefore: if no surfaces are defined return point data only
|
|
|
|
*/
|
|
|
|
|
|
|
|
DefaultLogger::get()->info("AC3D: No surfaces defined in object definition, "
|
|
|
|
"a point list is returned");
|
|
|
|
|
|
|
|
meshes.push_back(new aiMesh());
|
|
|
|
aiMesh* mesh = meshes.back();
|
|
|
|
|
|
|
|
mesh->mNumFaces = mesh->mNumVertices = (unsigned int)object.vertices.size();
|
|
|
|
aiFace* faces = mesh->mFaces = new aiFace[mesh->mNumFaces];
|
|
|
|
aiVector3D* verts = mesh->mVertices = new aiVector3D[mesh->mNumVertices];
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < mesh->mNumVertices;++i,++faces,++verts)
|
|
|
|
{
|
|
|
|
*verts = object.vertices[i];
|
|
|
|
faces->mNumIndices = 1;
|
|
|
|
faces->mIndices = new unsigned int[1];
|
|
|
|
faces->mIndices[0] = i;
|
|
|
|
}
|
2008-10-19 11:32:33 +00:00
|
|
|
|
|
|
|
// use the primary material in this case. this should be the
|
|
|
|
// default material if all objects of the file contain points
|
|
|
|
// and no faces.
|
|
|
|
mesh->mMaterialIndex = 0;
|
2011-08-22 20:22:51 +00:00
|
|
|
outMaterials.push_back(new aiMaterial());
|
2008-10-19 11:32:33 +00:00
|
|
|
ConvertMaterial(object, materials[0], *outMaterials.back());
|
2008-10-13 16:45:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// need to generate one or more meshes for this object.
|
|
|
|
// find out how many different materials we have
|
|
|
|
typedef std::pair< unsigned int, unsigned int > IntPair;
|
|
|
|
typedef std::vector< IntPair > MatTable;
|
|
|
|
MatTable needMat(materials.size(),IntPair(0,0));
|
|
|
|
|
|
|
|
std::vector<Surface>::iterator it,end = object.surfaces.end();
|
|
|
|
std::vector<Surface::SurfaceEntry>::iterator it2,end2;
|
|
|
|
|
|
|
|
for (it = object.surfaces.begin(); it != end; ++it)
|
|
|
|
{
|
|
|
|
register unsigned int idx = (*it).mat;
|
|
|
|
if (idx >= needMat.size())
|
|
|
|
{
|
2008-11-26 13:17:39 +00:00
|
|
|
DefaultLogger::get()->error("AC3D: material index is out of range");
|
2008-10-13 16:45:48 +00:00
|
|
|
idx = 0;
|
|
|
|
}
|
|
|
|
if ((*it).entries.empty())
|
|
|
|
{
|
|
|
|
DefaultLogger::get()->warn("AC3D: surface her zero vertex references");
|
|
|
|
}
|
|
|
|
|
|
|
|
// validate all vertex indices to make sure we won't crash here
|
|
|
|
for (it2 = (*it).entries.begin(),
|
|
|
|
end2 = (*it).entries.end(); it2 != end2; ++it2)
|
|
|
|
{
|
|
|
|
if ((*it2).first >= object.vertices.size())
|
|
|
|
{
|
|
|
|
DefaultLogger::get()->warn("AC3D: Invalid vertex reference");
|
|
|
|
(*it2).first = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!needMat[idx].first)++node->mNumMeshes;
|
|
|
|
|
|
|
|
switch ((*it).flags & 0xf)
|
|
|
|
{
|
|
|
|
// closed line
|
|
|
|
case 0x1:
|
|
|
|
|
|
|
|
needMat[idx].first += (unsigned int)(*it).entries.size();
|
|
|
|
needMat[idx].second += (unsigned int)(*it).entries.size()<<1u;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// unclosed line
|
|
|
|
case 0x2:
|
|
|
|
|
|
|
|
needMat[idx].first += (unsigned int)(*it).entries.size()-1;
|
|
|
|
needMat[idx].second += ((unsigned int)(*it).entries.size()-1)<<1u;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// 0 == polygon, else unknown
|
|
|
|
default:
|
|
|
|
|
|
|
|
if ((*it).flags & 0xf)
|
|
|
|
{
|
|
|
|
DefaultLogger::get()->warn("AC3D: The type flag of a surface is unknown");
|
|
|
|
(*it).flags &= ~(0xf);
|
|
|
|
}
|
|
|
|
|
|
|
|
// the number of faces increments by one, the number
|
|
|
|
// of vertices by surface.numref.
|
|
|
|
needMat[idx].first++;
|
|
|
|
needMat[idx].second += (unsigned int)(*it).entries.size();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
unsigned int* pip = node->mMeshes = new unsigned int[node->mNumMeshes];
|
|
|
|
unsigned int mat = 0;
|
2010-01-28 21:17:25 +00:00
|
|
|
const size_t oldm = meshes.size();
|
2008-10-13 16:45:48 +00:00
|
|
|
for (MatTable::const_iterator cit = needMat.begin(), cend = needMat.end();
|
|
|
|
cit != cend; ++cit, ++mat)
|
|
|
|
{
|
|
|
|
if (!(*cit).first)continue;
|
|
|
|
|
|
|
|
// allocate a new aiMesh object
|
|
|
|
*pip++ = (unsigned int)meshes.size();
|
|
|
|
aiMesh* mesh = new aiMesh();
|
|
|
|
meshes.push_back(mesh);
|
|
|
|
|
|
|
|
mesh->mMaterialIndex = (unsigned int)outMaterials.size();
|
2011-08-22 20:22:51 +00:00
|
|
|
outMaterials.push_back(new aiMaterial());
|
2008-10-13 16:45:48 +00:00
|
|
|
ConvertMaterial(object, materials[mat], *outMaterials.back());
|
|
|
|
|
|
|
|
// allocate storage for vertices and normals
|
|
|
|
mesh->mNumFaces = (*cit).first;
|
|
|
|
aiFace* faces = mesh->mFaces = new aiFace[mesh->mNumFaces];
|
|
|
|
|
|
|
|
mesh->mNumVertices = (*cit).second;
|
|
|
|
aiVector3D* vertices = mesh->mVertices = new aiVector3D[mesh->mNumVertices];
|
|
|
|
unsigned int cur = 0;
|
|
|
|
|
|
|
|
// allocate UV coordinates, but only if the texture name for the
|
|
|
|
// surface is not empty
|
|
|
|
aiVector3D* uv = NULL;
|
|
|
|
if(object.texture.length())
|
|
|
|
{
|
|
|
|
uv = mesh->mTextureCoords[0] = new aiVector3D[mesh->mNumVertices];
|
|
|
|
mesh->mNumUVComponents[0] = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (it = object.surfaces.begin(); it != end; ++it)
|
|
|
|
{
|
|
|
|
if (mat == (*it).mat)
|
|
|
|
{
|
|
|
|
const Surface& src = *it;
|
|
|
|
|
|
|
|
// closed polygon
|
|
|
|
unsigned int type = (*it).flags & 0xf;
|
|
|
|
if (!type)
|
|
|
|
{
|
|
|
|
aiFace& face = *faces++;
|
|
|
|
if((face.mNumIndices = (unsigned int)src.entries.size()))
|
|
|
|
{
|
|
|
|
face.mIndices = new unsigned int[face.mNumIndices];
|
|
|
|
for (unsigned int i = 0; i < face.mNumIndices;++i,++vertices)
|
|
|
|
{
|
|
|
|
const Surface::SurfaceEntry& entry = src.entries[i];
|
|
|
|
face.mIndices[i] = cur++;
|
|
|
|
|
|
|
|
// copy vertex positions
|
2008-11-26 13:17:39 +00:00
|
|
|
*vertices = object.vertices[entry.first] + object.translation;
|
2008-10-13 16:45:48 +00:00
|
|
|
|
2008-11-26 13:17:39 +00:00
|
|
|
|
|
|
|
// copy texture coordinates
|
2008-10-13 16:45:48 +00:00
|
|
|
if (uv)
|
|
|
|
{
|
2008-11-26 13:17:39 +00:00
|
|
|
uv->x = entry.second.x;
|
|
|
|
uv->y = entry.second.y;
|
2008-10-13 16:45:48 +00:00
|
|
|
++uv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
it2 = (*it).entries.begin();
|
|
|
|
|
|
|
|
// either a closed or an unclosed line
|
|
|
|
register unsigned int tmp = (unsigned int)(*it).entries.size();
|
|
|
|
if (0x2 == type)--tmp;
|
|
|
|
for (unsigned int m = 0; m < tmp;++m)
|
|
|
|
{
|
|
|
|
aiFace& face = *faces++;
|
|
|
|
|
|
|
|
face.mNumIndices = 2;
|
|
|
|
face.mIndices = new unsigned int[2];
|
|
|
|
face.mIndices[0] = cur++;
|
2008-10-19 11:32:33 +00:00
|
|
|
face.mIndices[1] = cur++;
|
2008-10-13 16:45:48 +00:00
|
|
|
|
|
|
|
// copy vertex positions
|
|
|
|
*vertices++ = object.vertices[(*it2).first];
|
|
|
|
|
2008-11-26 13:17:39 +00:00
|
|
|
// copy texture coordinates
|
2008-10-13 16:45:48 +00:00
|
|
|
if (uv)
|
|
|
|
{
|
2008-11-26 13:17:39 +00:00
|
|
|
uv->x = (*it2).second.x;
|
|
|
|
uv->y = (*it2).second.y;
|
2008-10-13 16:45:48 +00:00
|
|
|
++uv;
|
|
|
|
}
|
|
|
|
|
2010-01-28 21:17:25 +00:00
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
if (0x1 == type && tmp-1 == m)
|
|
|
|
{
|
|
|
|
// if this is a closed line repeat its beginning now
|
|
|
|
it2 = (*it).entries.begin();
|
|
|
|
}
|
|
|
|
else ++it2;
|
|
|
|
|
|
|
|
// second point
|
|
|
|
*vertices++ = object.vertices[(*it2).first];
|
|
|
|
|
|
|
|
if (uv)
|
|
|
|
{
|
2008-11-26 13:17:39 +00:00
|
|
|
uv->x = (*it2).second.x;
|
|
|
|
uv->y = (*it2).second.y;
|
2008-10-13 16:45:48 +00:00
|
|
|
++uv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-01-28 21:17:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now apply catmull clark subdivision if necessary. We split meshes into
|
|
|
|
// materials which is not done by AC3D during smoothing, so we need to
|
|
|
|
// collect all meshes using the same material group.
|
|
|
|
if (object.subDiv) {
|
|
|
|
if (configEvalSubdivision) {
|
|
|
|
boost::scoped_ptr<Subdivider> div(Subdivider::Create(Subdivider::CATMULL_CLARKE));
|
|
|
|
DefaultLogger::get()->info("AC3D: Evaluating subdivision surface: "+object.name);
|
|
|
|
|
|
|
|
std::vector<aiMesh*> cpy(meshes.size()-oldm,NULL);
|
|
|
|
div->Subdivide(&meshes[oldm],cpy.size(),&cpy.front(),object.subDiv,true);
|
|
|
|
std::copy(cpy.begin(),cpy.end(),meshes.begin()+oldm);
|
|
|
|
|
|
|
|
// previous meshes are deleted vy Subdivide().
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
DefaultLogger::get()->info("AC3D: Letting the subdivision surface untouched due to my configuration: "
|
|
|
|
+object.name);
|
2008-11-26 13:17:39 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-26 13:17:39 +00:00
|
|
|
if (object.name.length())
|
|
|
|
node->mName.Set(object.name);
|
|
|
|
else
|
2008-10-13 16:45:48 +00:00
|
|
|
{
|
2008-11-26 13:17:39 +00:00
|
|
|
// generate a name depending on the type of the node
|
|
|
|
switch (object.type)
|
2008-10-13 16:45:48 +00:00
|
|
|
{
|
2008-11-26 13:17:39 +00:00
|
|
|
case Object::Group:
|
|
|
|
node->mName.length = ::sprintf(node->mName.data,"ACGroup_%i",groups++);
|
|
|
|
break;
|
|
|
|
case Object::Poly:
|
|
|
|
node->mName.length = ::sprintf(node->mName.data,"ACPoly_%i",polys++);
|
|
|
|
break;
|
|
|
|
case Object::Light:
|
|
|
|
node->mName.length = ::sprintf(node->mName.data,"ACLight_%i",lights++);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// there shouldn't be more than one world, but we don't care
|
|
|
|
case Object::World:
|
|
|
|
node->mName.length = ::sprintf(node->mName.data,"ACWorld_%i",worlds++);
|
|
|
|
break;
|
2008-10-13 16:45:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// setup the local transformation matrix of the object
|
2008-11-26 13:17:39 +00:00
|
|
|
// compute the transformation offset to the parent node
|
2008-10-13 16:45:48 +00:00
|
|
|
node->mTransformation = aiMatrix4x4 ( object.rotation );
|
|
|
|
|
2008-12-01 15:25:38 +00:00
|
|
|
if (object.type == Object::Group || !object.numRefs)
|
|
|
|
{
|
|
|
|
node->mTransformation.a4 = object.translation.x;
|
|
|
|
node->mTransformation.b4 = object.translation.y;
|
|
|
|
node->mTransformation.c4 = object.translation.z;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
|
2008-11-26 13:17:39 +00:00
|
|
|
// add children to the object
|
|
|
|
if (object.children.size())
|
|
|
|
{
|
|
|
|
node->mNumChildren = (unsigned int)object.children.size();
|
|
|
|
node->mChildren = new aiNode*[node->mNumChildren];
|
|
|
|
for (unsigned int i = 0; i < node->mNumChildren;++i)
|
|
|
|
{
|
|
|
|
node->mChildren[i] = ConvertObjectSection(object.children[i],meshes,outMaterials,materials,node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void AC3DImporter::SetupProperties(const Importer* pImp)
|
|
|
|
{
|
|
|
|
configSplitBFCull = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_AC_SEPARATE_BFCULL,1) ? true : false;
|
2010-01-28 21:17:25 +00:00
|
|
|
configEvalSubdivision = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_AC_EVAL_SUBDIVISION,1) ? true : false;
|
2008-10-13 16:45:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Imports the given file into the given scene structure.
|
|
|
|
void AC3DImporter::InternReadFile( const std::string& pFile,
|
|
|
|
aiScene* pScene, IOSystem* pIOHandler)
|
|
|
|
{
|
|
|
|
boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile, "rb"));
|
|
|
|
|
|
|
|
// 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 AC3D file " + pFile + ".");
|
2008-10-13 16:45:48 +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-10-13 16:45:48 +00:00
|
|
|
buffer = &mBuffer2[0];
|
|
|
|
mNumMeshes = 0;
|
|
|
|
|
2008-11-26 13:17:39 +00:00
|
|
|
lights = polys = worlds = groups = 0;
|
|
|
|
|
2009-08-21 22:49:58 +00:00
|
|
|
if (::strncmp(buffer,"AC3D",4)) {
|
2010-03-18 17:00:12 +00:00
|
|
|
throw DeadlyImportError("AC3D: No valid AC3D file, magic sequence not found");
|
2009-08-21 22:49:58 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
|
|
|
|
// print the file format version to the console
|
|
|
|
unsigned int version = HexDigitToDecimal( buffer[4] );
|
2008-10-19 19:51:24 +00:00
|
|
|
char msg[3];
|
2009-01-12 22:06:54 +00:00
|
|
|
ASSIMP_itoa10(msg,3,version);
|
2008-10-13 16:45:48 +00:00
|
|
|
DefaultLogger::get()->info(std::string("AC3D file format version: ") + msg);
|
|
|
|
|
|
|
|
std::vector<Material> materials;
|
|
|
|
materials.reserve(5);
|
|
|
|
|
|
|
|
std::vector<Object> rootObjects;
|
|
|
|
rootObjects.reserve(5);
|
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
std::vector<aiLight*> lights;
|
|
|
|
mLights = & lights;
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
while (GetNextLine())
|
|
|
|
{
|
|
|
|
if (TokenMatch(buffer,"MATERIAL",8))
|
|
|
|
{
|
|
|
|
materials.push_back(Material());
|
|
|
|
Material& mat = materials.back();
|
|
|
|
|
|
|
|
// manually parse the material ... sscanf would use the buldin atof ...
|
|
|
|
// Format: (name) rgb %f %f %f amb %f %f %f emis %f %f %f spec %f %f %f shi %d trans %f
|
|
|
|
|
|
|
|
AI_AC_SKIP_TO_NEXT_TOKEN();
|
|
|
|
if ('\"' == *buffer)
|
|
|
|
{
|
|
|
|
AI_AC_GET_STRING(mat.name);
|
|
|
|
AI_AC_SKIP_TO_NEXT_TOKEN();
|
|
|
|
}
|
|
|
|
|
|
|
|
AI_AC_CHECKED_LOAD_FLOAT_ARRAY("rgb",3,3,&mat.rgb);
|
2008-11-16 21:56:45 +00:00
|
|
|
AI_AC_CHECKED_LOAD_FLOAT_ARRAY("amb",3,3,&mat.amb);
|
|
|
|
AI_AC_CHECKED_LOAD_FLOAT_ARRAY("emis",4,3,&mat.emis);
|
|
|
|
AI_AC_CHECKED_LOAD_FLOAT_ARRAY("spec",4,3,&mat.spec);
|
2008-10-13 16:45:48 +00:00
|
|
|
AI_AC_CHECKED_LOAD_FLOAT_ARRAY("shi",3,1,&mat.shin);
|
|
|
|
AI_AC_CHECKED_LOAD_FLOAT_ARRAY("trans",5,1,&mat.trans);
|
|
|
|
}
|
|
|
|
LoadObjectSection(rootObjects);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rootObjects.empty() || !mNumMeshes)
|
|
|
|
{
|
2010-03-18 17:00:12 +00:00
|
|
|
throw DeadlyImportError("AC3D: No meshes have been loaded");
|
2008-10-13 16:45:48 +00:00
|
|
|
}
|
|
|
|
if (materials.empty())
|
|
|
|
{
|
|
|
|
DefaultLogger::get()->warn("AC3D: No material has been found");
|
|
|
|
materials.push_back(Material());
|
|
|
|
}
|
|
|
|
|
|
|
|
mNumMeshes += (mNumMeshes>>2u) + 1;
|
|
|
|
std::vector<aiMesh*> meshes;
|
|
|
|
meshes.reserve(mNumMeshes);
|
|
|
|
|
2011-08-22 20:22:51 +00:00
|
|
|
std::vector<aiMaterial*> omaterials;
|
2008-10-13 16:45:48 +00:00
|
|
|
materials.reserve(mNumMeshes);
|
|
|
|
|
|
|
|
// generate a dummy root if there are multiple objects on the top layer
|
|
|
|
Object* root;
|
|
|
|
if (1 == rootObjects.size())
|
|
|
|
root = &rootObjects[0];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
root = new Object();
|
|
|
|
}
|
|
|
|
|
|
|
|
// now convert the imported stuff to our output data structure
|
|
|
|
pScene->mRootNode = ConvertObjectSection(*root,meshes,omaterials,materials);
|
|
|
|
if (1 != rootObjects.size())delete root;
|
|
|
|
|
2008-11-16 21:56:45 +00:00
|
|
|
if (!::strncmp( pScene->mRootNode->mName.data, "Node", 4))
|
|
|
|
pScene->mRootNode->mName.Set("<AC3DWorld>");
|
|
|
|
|
2008-11-26 13:17:39 +00:00
|
|
|
// copy meshes
|
2008-10-22 20:06:16 +00:00
|
|
|
if (meshes.empty())
|
|
|
|
{
|
2010-03-18 17:00:12 +00:00
|
|
|
throw DeadlyImportError("An unknown error occured during converting");
|
2008-10-22 20:06:16 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
pScene->mNumMeshes = (unsigned int)meshes.size();
|
|
|
|
pScene->mMeshes = new aiMesh*[pScene->mNumMeshes];
|
|
|
|
::memcpy(pScene->mMeshes,&meshes[0],pScene->mNumMeshes*sizeof(void*));
|
|
|
|
|
2008-11-26 13:17:39 +00:00
|
|
|
// copy materials
|
2008-10-13 16:45:48 +00:00
|
|
|
pScene->mNumMaterials = (unsigned int)omaterials.size();
|
|
|
|
pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials];
|
|
|
|
::memcpy(pScene->mMaterials,&omaterials[0],pScene->mNumMaterials*sizeof(void*));
|
2008-11-16 21:56:45 +00:00
|
|
|
|
2008-11-26 13:17:39 +00:00
|
|
|
// copy lights
|
2008-11-16 21:56:45 +00:00
|
|
|
pScene->mNumLights = (unsigned int)lights.size();
|
|
|
|
if (lights.size())
|
|
|
|
{
|
|
|
|
pScene->mLights = new aiLight*[lights.size()];
|
|
|
|
::memcpy(pScene->mLights,&lights[0],lights.size()*sizeof(void*));
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
}
|
|
|
|
|
2010-05-10 10:22:24 +00:00
|
|
|
#endif //!defined ASSIMP_BUILD_NO_AC_IMPORTER
|