- changing Assimp's coordinate system from RH z-up to RH y-up
 - fixing coordinate system for LWO, 3DS, ASE, MD5, MDL, B3D, IRR, IRRMESH 
 - converttolh moved to three separate steps -> flipuv, flipwinding, makelh

LWO 
 - fixing texture coordinate generation -> mapping axis is correct now 
 - fixing z-fighting bug

ASE 
 - fixing crash due to invalid normal setup 
 - fixing parenting bug 
 - code cleanup

IRR 
 - code cleanup
 - fixing placement of externally loaded meshes 

MDL 
 - fixing texture coordinate space

PLY 
 - cleanup 
 - two-sided maat property is now set 

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@366 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
This commit is contained in:
aramis_acg
2009-03-15 00:40:30 +00:00
parent 68d7e43056
commit c2d8881549
48 changed files with 1518 additions and 1802 deletions

View File

@@ -70,16 +70,12 @@ using namespace boost::math;
// ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer
IRRImporter::IRRImporter()
{
// nothing to do here
}
{}
// ------------------------------------------------------------------------------------------------
// Destructor, private as well
IRRImporter::~IRRImporter()
{
// nothing to do here
}
{}
// ------------------------------------------------------------------------------------------------
// Returns whether the class can handle the format of the given file.
@@ -174,17 +170,14 @@ aiMesh* IRRImporter::BuildSingleQuadMesh(const SkyboxVertex& v1,
*vec++ = v2.uv;
*vec++ = v3.uv;
*vec = v4.uv;
return out;
}
// ------------------------------------------------------------------------------------------------
void IRRImporter::BuildSkybox(std::vector<aiMesh*>& meshes, std::vector<aiMaterial*> materials)
{
// Update the material of the skybox - replace the name
// and disable shading for skyboxes.
for (unsigned int i = 0; i < 6;++i)
{
// Update the material of the skybox - replace the name and disable shading for skyboxes.
for (unsigned int i = 0; i < 6;++i) {
MaterialHelper* out = ( MaterialHelper* ) (*(materials.end()-(6-i)));
aiString s;
@@ -256,8 +249,7 @@ void IRRImporter::CopyMaterial(std::vector<aiMaterial*>& materials,
unsigned int& defMatIdx,
aiMesh* mesh)
{
if (inmaterials.empty())
{
if (inmaterials.empty()) {
// Do we have a default material? If not we need to create one
if (0xffffffff == defMatIdx)
{
@@ -274,8 +266,7 @@ void IRRImporter::CopyMaterial(std::vector<aiMaterial*>& materials,
mesh->mMaterialIndex = defMatIdx;
return;
}
else if (inmaterials.size() > 1)
{
else if (inmaterials.size() > 1) {
DefaultLogger::get()->info("IRR: Skipping additional materials");
}
@@ -307,24 +298,20 @@ void IRRImporter::ComputeAnimations(Node* root, aiNode* real, std::vector<aiNode
{
ai_assert(NULL != root && NULL != real);
if (root->animators.empty())return;
// const aiMatrix4x4& transform = real->mTransformation;
if (root->animators.empty()) {
return;
}
unsigned int total = 0;
for (std::list<Animator>::iterator it = root->animators.begin();
it != root->animators.end(); ++it)
{
if ((*it).type == Animator::UNKNOWN || (*it).type == Animator::OTHER)
{
for (std::list<Animator>::iterator it = root->animators.begin();it != root->animators.end(); ++it) {
if ((*it).type == Animator::UNKNOWN || (*it).type == Animator::OTHER) {
DefaultLogger::get()->warn("IRR: Skipping unknown or unsupported animator");
continue;
}
++total;
}
if (!total)return;
else if (1 == total)
{
DefaultLogger::get()->warn("IRR: Generating dummy nodes to simulate multiple animators");
else if (1 == total) {
DefaultLogger::get()->warn("IRR: Adding dummy nodes to simulate multiple animators");
}
// NOTE: 1 tick == i millisecond
@@ -338,8 +325,7 @@ void IRRImporter::ComputeAnimations(Node* root, aiNode* real, std::vector<aiNode
Animator& in = *it ;
aiNodeAnim* anim = new aiNodeAnim();
if (cur != total-1)
{
if (cur != total-1) {
// Build a new name - a prefix instead of a suffix because it is
// easier to check against
anim->mNodeName.length = ::sprintf(anim->mNodeName.data,
@@ -367,8 +353,7 @@ void IRRImporter::ComputeAnimations(Node* root, aiNode* real, std::vector<aiNode
else anim->mNodeName.Set(root->name);
++cur;
switch (in.type)
{
switch (in.type) {
case Animator::ROTATION:
{
// -----------------------------------------------------
@@ -463,8 +448,7 @@ void IRRImporter::ComputeAnimations(Node* root, aiNode* real, std::vector<aiNode
// from Irrlicht, what else should we do than copying it?
aiVector3D vecU,vecV;
if (in.direction.y)
{
if (in.direction.y) {
vecV = aiVector3D(50,0,0) ^ in.direction;
}
else vecV = aiVector3D(0,50,00) ^ in.direction;
@@ -472,8 +456,7 @@ void IRRImporter::ComputeAnimations(Node* root, aiNode* real, std::vector<aiNode
vecU = (vecV ^ in.direction).Normalize();
// build the output keys
for (unsigned int i = 0; i < anim->mNumPositionKeys;++i)
{
for (unsigned int i = 0; i < anim->mNumPositionKeys;++i) {
aiVectorKey& key = anim->mPositionKeys[i];
key.mTime = i * tdelta;
@@ -502,8 +485,7 @@ void IRRImporter::ComputeAnimations(Node* root, aiNode* real, std::vector<aiNode
const double timeFactor = lengthOfWay / in.timeForWay;
// build the output keys
for (unsigned int i = 0; i < anim->mNumPositionKeys;++i)
{
for (unsigned int i = 0; i < anim->mNumPositionKeys;++i) {
aiVectorKey& key = anim->mPositionKeys[i];
key.mTime = i * tdelta;
key.mValue = in.circleCenter + diff * float(timeFactor * key.mTime);
@@ -516,16 +498,14 @@ void IRRImporter::ComputeAnimations(Node* root, aiNode* real, std::vector<aiNode
// repeat outside the defined time range
anim->mPostState = anim->mPreState = aiAnimBehaviour_REPEAT;
const int size = (int)in.splineKeys.size();
if (!size)
{
if (!size) {
// We have no point in the spline. That's bad. Really bad.
DefaultLogger::get()->warn("IRR: Spline animators with no points defined");
delete anim;anim = NULL;
break;
}
else if (size == 1)
{
else if (size == 1) {
// We have just one point in the spline so we don't need the full calculation
anim->mNumPositionKeys = 1;
anim->mPositionKeys = new aiVectorKey[anim->mNumPositionKeys];
@@ -576,8 +556,7 @@ void IRRImporter::ComputeAnimations(Node* root, aiNode* real, std::vector<aiNode
}
break;
};
if (anim)
{
if (anim) {
anims.push_back(anim);
++total;
}
@@ -598,8 +577,7 @@ void SetupMapping (MaterialHelper* mat, aiTextureMapping mode, const aiVector3D&
for (unsigned int i = 0; i < mat->mNumProperties;++i)
{
aiMaterialProperty* prop = mat->mProperties[i];
if (!::strcmp( prop->mKey.data, "$tex.file"))
{
if (!::strcmp( prop->mKey.data, "$tex.file")) {
// Setup the mapping key
aiMaterialProperty* m = new aiMaterialProperty();
m->mKey.Set("$tex.mapping");
@@ -615,9 +593,7 @@ void SetupMapping (MaterialHelper* mat, aiTextureMapping mode, const aiVector3D&
p.push_back(m);
// Setup the mapping axis
if (mode == aiTextureMapping_CYLINDER || mode == aiTextureMapping_PLANE ||
mode == aiTextureMapping_SPHERE)
{
if (mode == aiTextureMapping_CYLINDER || mode == aiTextureMapping_PLANE || mode == aiTextureMapping_SPHERE) {
m = new aiMaterialProperty();
m->mKey.Set("$tex.mapaxis");
m->mIndex = prop->mIndex;
@@ -674,63 +650,24 @@ void IRRImporter::GenerateGraph(Node* root,aiNode* rootOut ,aiScene* scene,
// the list of all scenes to be attached to the
// graph we're currently building
aiScene* scene = batch.GetImport(root->id);
if (!scene)
{
DefaultLogger::get()->error("IRR: Unable to load external file: "
+ root->meshPath);
if (!scene) {
DefaultLogger::get()->error("IRR: Unable to load external file: " + root->meshPath);
break;
}
attach.push_back(AttachmentInfo(scene,rootOut));
#if 0 /* currently unused */
meshTrafoAssign = 1;
// If the root node of the scene is animated - and *this* node
// is animated, too, we need to insert a dummy node into the
// hierarchy in order to avoid interferences with animations
for (unsigned int i = 0; i < scene->mNumAnimations;++i)
{
aiAnimation* anim = scene->mAnimations[i];
for (unsigned int a = 0; a < anim->mNumChannels;++a) {
if (scene->mRootNode->mName == anim->mChannels[a]->mNodeName) {
if (root->animators.empty()) {
meshTrafoAssign = 2;
}
else {
meshTrafoAssign = 3;
aiNode* dummy = new aiNode();
dummy->mName.Set("$CSpaceSeam$");
dummy->mNumChildren = 1;
dummy->mChildren = new aiNode*[1];
dummy->mChildren[0] = scene->mRootNode;
scene->mRootNode->mParent = dummy;
scene->mRootNode = dummy;
scene->mRootNode->mTransformation = AI_TO_IRR_MATRIX;
}
break;
}
}
}
#endif
// if (1 == meshTrafoAssign)
// scene->mRootNode->mTransformation = AI_TO_IRR_MATRIX * scene->mRootNode->mTransformation;
// Now combine the material we've loaded for this mesh
// with the real materials we got from the file. As we
// don't execute any pp-steps on the file, the numbers
// should be equal. If they are not, we can impossibly
// do this ...
if (root->materials.size() != (unsigned int)scene->mNumMaterials)
{
if (root->materials.size() != (unsigned int)scene->mNumMaterials) {
DefaultLogger::get()->warn("IRR: Failed to match imported materials "
"with the materials found in the IRR scene file");
break;
}
for (unsigned int i = 0; i < scene->mNumMaterials;++i)
{
for (unsigned int i = 0; i < scene->mNumMaterials;++i) {
// Delete the old material, we don't need it anymore
delete scene->mMaterials[i];
@@ -741,8 +678,7 @@ void IRRImporter::GenerateGraph(Node* root,aiNode* rootOut ,aiScene* scene,
// NOTE: Each mesh should have exactly one material assigned,
// but we do it in a separate loop if this behaviour changes
// in future.
for (unsigned int i = 0; i < scene->mNumMeshes;++i)
{
for (unsigned int i = 0; i < scene->mNumMeshes;++i) {
// Process material flags
aiMesh* mesh = scene->mMeshes[i];
@@ -751,25 +687,21 @@ void IRRImporter::GenerateGraph(Node* root,aiNode* rootOut ,aiScene* scene,
// and check whether they have a common alpha value. This is quite
// often the case so we can simply extract it to a shared oacity
// value.
std::pair<aiMaterial*, unsigned int>& src = root->materials[
mesh->mMaterialIndex];
std::pair<aiMaterial*, unsigned int>& src = root->materials[mesh->mMaterialIndex];
MaterialHelper* mat = (MaterialHelper*)src.first;
if (mesh->HasVertexColors(0) && src.second & AI_IRRMESH_MAT_trans_vertex_alpha)
{
bool bdo = true;
for (unsigned int a = 1; a < mesh->mNumVertices;++a)
{
if (mesh->mColors[0][a].a != mesh->mColors[0][a-1].a)
{
for (unsigned int a = 1; a < mesh->mNumVertices;++a) {
if (mesh->mColors[0][a].a != mesh->mColors[0][a-1].a) {
bdo = false;
break;
}
}
if (bdo)
{
DefaultLogger::get()->info("IRR: Replacing mesh vertex "
"alpha with common opacity");
if (bdo) {
DefaultLogger::get()->info("IRR: Replacing mesh vertex alpha with common opacity");
for (unsigned int a = 0; a < mesh->mNumVertices;++a)
mesh->mColors[0][a].a = 1.f;
@@ -782,8 +714,8 @@ void IRRImporter::GenerateGraph(Node* root,aiNode* rootOut ,aiScene* scene,
// (either lightmap, normalmap, 2layered material) we need to
// setup the correct UV index for it. The texture can either
// be diffuse (lightmap & 2layer) or a normal map (normal & parallax)
if (mesh->HasTextureCoords(1))
{
if (mesh->HasTextureCoords(1)) {
int idx = 1;
if (src.second & (AI_IRRMESH_MAT_solid_2layer | AI_IRRMESH_MAT_lightmap)) {
mat->AddProperty(&idx,1,AI_MATKEY_UVWSRC_DIFFUSE(0));
@@ -852,11 +784,8 @@ void IRRImporter::GenerateGraph(Node* root,aiNode* rootOut ,aiScene* scene,
case Node::SKYBOX:
{
// A skybox is defined by six materials
if (root->materials.size() < 6)
{
DefaultLogger::get()->error("IRR: There should be six materials "
"for a skybox");
if (root->materials.size() < 6) {
DefaultLogger::get()->error("IRR: There should be six materials for a skybox");
break;
}
@@ -888,8 +817,8 @@ void IRRImporter::GenerateGraph(Node* root,aiNode* rootOut ,aiScene* scene,
// Check whether we added a mesh (or more than one ...). In this case
// we'll also need to attach it to the node
if (oldMeshSize != (unsigned int) meshes.size())
{
if (oldMeshSize != (unsigned int) meshes.size()) {
rootOut->mNumMeshes = (unsigned int)meshes.size() - oldMeshSize;
rootOut->mMeshes = new unsigned int[rootOut->mNumMeshes];
@@ -904,7 +833,7 @@ void IRRImporter::GenerateGraph(Node* root,aiNode* rootOut ,aiScene* scene,
// Now compute the final local transformation matrix of the
// node from the given translation, rotation and scaling values.
// (the rotation is given in Euler angles, XYZ order)
std::swap((float&)root->rotation.z,(float&)root->rotation.y);
//std::swap((float&)root->rotation.z,(float&)root->rotation.y);
rootOut->mTransformation.FromEulerAnglesXYZ(AI_DEG_TO_RAD(root->rotation) );
// apply scaling
@@ -912,20 +841,17 @@ void IRRImporter::GenerateGraph(Node* root,aiNode* rootOut ,aiScene* scene,
mat.a1 *= root->scaling.x;
mat.b1 *= root->scaling.x;
mat.c1 *= root->scaling.x;
mat.a2 *= root->scaling.z;
mat.b2 *= root->scaling.z;
mat.c2 *= root->scaling.z;
mat.a3 *= root->scaling.y;
mat.b3 *= root->scaling.y;
mat.c3 *= root->scaling.y;
mat.a2 *= root->scaling.y;
mat.b2 *= root->scaling.y;
mat.c2 *= root->scaling.y;
mat.a3 *= root->scaling.z;
mat.b3 *= root->scaling.z;
mat.c3 *= root->scaling.z;
// apply translation
mat.a4 += root->position.x;
mat.b4 += root->position.z;
mat.c4 += root->position.y;
//if (meshTrafoAssign == 2)
// mat *= AI_TO_IRR_MATRIX;
mat.b4 += root->position.y;
mat.c4 += root->position.z;
// now compute animations for the node
ComputeAnimations(root,rootOut, anims);
@@ -933,11 +859,11 @@ void IRRImporter::GenerateGraph(Node* root,aiNode* rootOut ,aiScene* scene,
// Add all children recursively. First allocate enough storage
// for them, then call us again
rootOut->mNumChildren = (unsigned int)root->children.size();
if (rootOut->mNumChildren)
{
if (rootOut->mNumChildren) {
rootOut->mChildren = new aiNode*[rootOut->mNumChildren];
for (unsigned int i = 0; i < rootOut->mNumChildren;++i)
{
for (unsigned int i = 0; i < rootOut->mNumChildren;++i) {
aiNode* node = rootOut->mChildren[i] = new aiNode();
node->mParent = rootOut;
GenerateGraph(root->children[i],node,scene,batch,meshes,
@@ -989,14 +915,11 @@ void IRRImporter::InternReadFile( const std::string& pFile,
unsigned int guessedAnimCnt = 0, guessedMeshCnt = 0, guessedMatCnt = 0;
// Parse the XML file
while (reader->read())
{
switch (reader->getNodeType())
{
while (reader->read()) {
switch (reader->getNodeType()) {
case EXN_ELEMENT:
if (!ASSIMP_stricmp(reader->getNodeName(),"node"))
{
if (!ASSIMP_stricmp(reader->getNodeName(),"node")) {
// ***********************************************************************
/* What we're going to do with the node depends
* on its type:
@@ -1019,24 +942,20 @@ void IRRImporter::InternReadFile( const std::string& pFile,
// ***********************************************************************
const char* sz = reader->getAttributeValueSafe("type");
Node* nd;
if (!ASSIMP_stricmp(sz,"mesh") || !ASSIMP_stricmp(sz,"octTree"))
{
if (!ASSIMP_stricmp(sz,"mesh") || !ASSIMP_stricmp(sz,"octTree")) {
// OctTree's and meshes are treated equally
nd = new Node(Node::MESH);
}
else if (!ASSIMP_stricmp(sz,"cube"))
{
else if (!ASSIMP_stricmp(sz,"cube")) {
nd = new Node(Node::CUBE);
++guessedMeshCnt;
// meshes.push_back(StandardShapes::MakeMesh(&StandardShapes::MakeHexahedron));
}
else if (!ASSIMP_stricmp(sz,"skybox"))
{
else if (!ASSIMP_stricmp(sz,"skybox")) {
nd = new Node(Node::SKYBOX);
guessedMeshCnt += 6;
}
else if (!ASSIMP_stricmp(sz,"camera"))
{
else if (!ASSIMP_stricmp(sz,"camera")) {
nd = new Node(Node::CAMERA);
// Setup a temporary name for the camera
@@ -1044,8 +963,7 @@ void IRRImporter::InternReadFile( const std::string& pFile,
cam->mName.Set( nd->name );
cameras.push_back(cam);
}
else if (!ASSIMP_stricmp(sz,"light"))
{
else if (!ASSIMP_stricmp(sz,"light")) {
nd = new Node(Node::LIGHT);
// Setup a temporary name for the light
@@ -1053,31 +971,25 @@ void IRRImporter::InternReadFile( const std::string& pFile,
cam->mName.Set( nd->name );
lights.push_back(cam);
}
else if (!ASSIMP_stricmp(sz,"sphere"))
{
else if (!ASSIMP_stricmp(sz,"sphere")) {
nd = new Node(Node::SPHERE);
++guessedMeshCnt;
}
else if (!ASSIMP_stricmp(sz,"animatedMesh"))
{
else if (!ASSIMP_stricmp(sz,"animatedMesh")) {
nd = new Node(Node::ANIMMESH);
}
else if (!ASSIMP_stricmp(sz,"empty"))
{
else if (!ASSIMP_stricmp(sz,"empty")) {
nd = new Node(Node::DUMMY);
}
else if (!ASSIMP_stricmp(sz,"terrain"))
{
else if (!ASSIMP_stricmp(sz,"terrain")) {
nd = new Node(Node::TERRAIN);
}
else if (!ASSIMP_stricmp(sz,"billBoard"))
{
else if (!ASSIMP_stricmp(sz,"billBoard")) {
// We don't support billboards, so ignore them
DefaultLogger::get()->error("IRR: Billboards are not supported by Assimp");
nd = new Node(Node::DUMMY);
}
else
{
else {
DefaultLogger::get()->warn("IRR: Found unknown node: " + std::string(sz));
/* We skip the contents of nodes we don't know.
@@ -1093,21 +1005,17 @@ void IRRImporter::InternReadFile( const std::string& pFile,
nd->parent = curParent;
curParent->children.push_back(nd);
}
else if (!ASSIMP_stricmp(reader->getNodeName(),"materials"))
{
else if (!ASSIMP_stricmp(reader->getNodeName(),"materials")) {
inMaterials = true;
}
else if (!ASSIMP_stricmp(reader->getNodeName(),"animators"))
{
else if (!ASSIMP_stricmp(reader->getNodeName(),"animators")) {
inAnimator = true;
}
else if (!ASSIMP_stricmp(reader->getNodeName(),"attributes"))
{
else if (!ASSIMP_stricmp(reader->getNodeName(),"attributes")) {
/* We should have a valid node here
* FIX: no ... the scene root node is also contained in an attributes block
*/
if (!curNode)
{
if (!curNode) {
#if 0
DefaultLogger::get()->error("IRR: Encountered <attributes> element, but "
"there is no node active");
@@ -1118,8 +1026,7 @@ void IRRImporter::InternReadFile( const std::string& pFile,
Animator* curAnim = NULL;
// Materials can occur for nearly any type of node
if (inMaterials && curNode->type != Node::DUMMY)
{
if (inMaterials && curNode->type != Node::DUMMY) {
/* This is a material description - parse it!
*/
curNode->materials.push_back(std::pair< aiMaterial*, unsigned int > () );
@@ -1130,8 +1037,7 @@ void IRRImporter::InternReadFile( const std::string& pFile,
++guessedMatCnt;
continue;
}
else if (inAnimator)
{
else if (inAnimator) {
/* This is an animation path - add a new animator
* to the list.
*/
@@ -1144,28 +1050,21 @@ void IRRImporter::InternReadFile( const std::string& pFile,
/* Parse all elements in the attributes block
* and process them.
*/
while (reader->read())
{
if (reader->getNodeType() == EXN_ELEMENT)
{
if (!ASSIMP_stricmp(reader->getNodeName(),"vector3d"))
{
while (reader->read()) {
if (reader->getNodeType() == EXN_ELEMENT) {
if (!ASSIMP_stricmp(reader->getNodeName(),"vector3d")) {
VectorProperty prop;
ReadVectorProperty(prop);
if (inAnimator)
{
if (curAnim->type == Animator::ROTATION && prop.name == "Rotation")
{
if (inAnimator) {
if (curAnim->type == Animator::ROTATION && prop.name == "Rotation") {
// We store the rotation euler angles in 'direction'
curAnim->direction = prop.value;
}
else if (curAnim->type == Animator::FOLLOW_SPLINE)
{
else if (curAnim->type == Animator::FOLLOW_SPLINE) {
// Check whether the vector follows the PointN naming scheme,
// here N is the ONE-based index of the point
if (prop.name.length() >= 6 && prop.name.substr(0,5) == "Point")
{
if (prop.name.length() >= 6 && prop.name.substr(0,5) == "Point") {
// Add a new key to the list
curAnim->splineKeys.push_back(aiVectorKey());
aiVectorKey& key = curAnim->splineKeys.back();
@@ -1175,203 +1074,158 @@ void IRRImporter::InternReadFile( const std::string& pFile,
key.mTime = strtol10(&prop.name[5]);
}
}
else if (curAnim->type == Animator::FLY_CIRCLE)
{
if (prop.name == "Center")
{
else if (curAnim->type == Animator::FLY_CIRCLE) {
if (prop.name == "Center") {
curAnim->circleCenter = prop.value;
}
else if (prop.name == "Direction")
{
else if (prop.name == "Direction") {
curAnim->direction = prop.value;
// From Irrlicht source - a workaround for backward
// compatibility with Irrlicht 1.1
if (curAnim->direction == aiVector3D())
{
// From Irrlicht's source - a workaround for backward compatibility with Irrlicht 1.1
if (curAnim->direction == aiVector3D()) {
curAnim->direction = aiVector3D(0.f,1.f,0.f);
}
else curAnim->direction.Normalize();
}
}
else if (curAnim->type == Animator::FLY_STRAIGHT)
{
if (prop.name == "Start")
{
else if (curAnim->type == Animator::FLY_STRAIGHT) {
if (prop.name == "Start") {
// We reuse the field here
curAnim->circleCenter = prop.value;
}
else if (prop.name == "End")
{
else if (prop.name == "End") {
// We reuse the field here
curAnim->direction = prop.value;
}
}
}
else
{
if (prop.name == "Position")
{
else {
if (prop.name == "Position") {
curNode->position = prop.value;
}
else if (prop.name == "Rotation")
{
else if (prop.name == "Rotation") {
curNode->rotation = prop.value;
}
else if (prop.name == "Scale")
{
else if (prop.name == "Scale") {
curNode->scaling = prop.value;
}
else if (Node::CAMERA == curNode->type)
{
aiCamera* cam = cameras.back();
if (prop.name == "Target")
{
if (prop.name == "Target") {
cam->mLookAt = prop.value;
}
else if (prop.name == "UpVector")
{
else if (prop.name == "UpVector") {
cam->mUp = prop.value;
}
}
}
}
else if (!ASSIMP_stricmp(reader->getNodeName(),"bool"))
{
else if (!ASSIMP_stricmp(reader->getNodeName(),"bool")) {
BoolProperty prop;
ReadBoolProperty(prop);
if (inAnimator && curAnim->type == Animator::FLY_CIRCLE && prop.name == "Loop")
{
if (inAnimator && curAnim->type == Animator::FLY_CIRCLE && prop.name == "Loop") {
curAnim->loop = prop.value;
}
}
else if (!ASSIMP_stricmp(reader->getNodeName(),"float"))
{
else if (!ASSIMP_stricmp(reader->getNodeName(),"float")) {
FloatProperty prop;
ReadFloatProperty(prop);
if (inAnimator)
{
if (inAnimator) {
// The speed property exists for several animators
if (prop.name == "Speed")
{
if (prop.name == "Speed") {
curAnim->speed = prop.value;
}
else if (curAnim->type == Animator::FLY_CIRCLE && prop.name == "Radius")
{
else if (curAnim->type == Animator::FLY_CIRCLE && prop.name == "Radius") {
curAnim->circleRadius = prop.value;
}
else if (curAnim->type == Animator::FOLLOW_SPLINE && prop.name == "Tightness")
{
else if (curAnim->type == Animator::FOLLOW_SPLINE && prop.name == "Tightness") {
curAnim->tightness = prop.value;
}
}
else
{
if (prop.name == "FramesPerSecond" &&
Node::ANIMMESH == curNode->type)
{
else {
if (prop.name == "FramesPerSecond" && Node::ANIMMESH == curNode->type) {
curNode->framesPerSecond = prop.value;
}
else if (Node::CAMERA == curNode->type)
{
else if (Node::CAMERA == curNode->type) {
/* This is the vertical, not the horizontal FOV.
* We need to compute the right FOV from the
* screen aspect which we don't know yet.
*/
if (prop.name == "Fovy")
{
if (prop.name == "Fovy") {
cameras.back()->mHorizontalFOV = prop.value;
}
else if (prop.name == "Aspect")
{
else if (prop.name == "Aspect") {
cameras.back()->mAspect = prop.value;
}
else if (prop.name == "ZNear")
{
else if (prop.name == "ZNear") {
cameras.back()->mClipPlaneNear = prop.value;
}
else if (prop.name == "ZFar")
{
else if (prop.name == "ZFar") {
cameras.back()->mClipPlaneFar = prop.value;
}
}
else if (Node::LIGHT == curNode->type)
{
else if (Node::LIGHT == curNode->type) {
/* Additional light information
*/
if (prop.name == "Attenuation")
{
if (prop.name == "Attenuation") {
lights.back()->mAttenuationLinear = prop.value;
}
else if (prop.name == "OuterCone")
{
else if (prop.name == "OuterCone") {
lights.back()->mAngleOuterCone = AI_DEG_TO_RAD( prop.value );
}
else if (prop.name == "InnerCone")
{
else if (prop.name == "InnerCone") {
lights.back()->mAngleInnerCone = AI_DEG_TO_RAD( prop.value );
}
}
// radius of the sphere to be generated -
// or alternatively, size of the cube
else if (Node::SPHERE == curNode->type && prop.name == "Radius" ||
Node::CUBE == curNode->type && prop.name == "Size" )
{
curNode->sphereRadius = prop.value;
else if (Node::SPHERE == curNode->type && prop.name == "Radius"
|| Node::CUBE == curNode->type && prop.name == "Size" ) {
curNode->sphereRadius = prop.value;
}
}
}
else if (!ASSIMP_stricmp(reader->getNodeName(),"int"))
{
else if (!ASSIMP_stricmp(reader->getNodeName(),"int")) {
IntProperty prop;
ReadIntProperty(prop);
if (inAnimator)
{
if (curAnim->type == Animator::FLY_STRAIGHT && prop.name == "TimeForWay")
{
if (inAnimator) {
if (curAnim->type == Animator::FLY_STRAIGHT && prop.name == "TimeForWay") {
curAnim->timeForWay = prop.value;
}
}
else
{
else {
// sphere polgon numbers in each direction
if (Node::SPHERE == curNode->type)
{
if (prop.name == "PolyCountX")
{
if (Node::SPHERE == curNode->type) {
if (prop.name == "PolyCountX") {
curNode->spherePolyCountX = prop.value;
}
else if (prop.name == "PolyCountY")
{
else if (prop.name == "PolyCountY") {
curNode->spherePolyCountY = prop.value;
}
}
}
}
else if (!ASSIMP_stricmp(reader->getNodeName(),"string") ||
!ASSIMP_stricmp(reader->getNodeName(),"enum"))
{
else if (!ASSIMP_stricmp(reader->getNodeName(),"string") ||!ASSIMP_stricmp(reader->getNodeName(),"enum")) {
StringProperty prop;
ReadStringProperty(prop);
if (prop.value.length())
{
if (prop.name == "Name")
{
if (prop.value.length()) {
if (prop.name == "Name") {
curNode->name = prop.value;
/* If we're either a camera or a light source
* we need to update the name in the aiLight/
* aiCamera structure, too.
*/
if (Node::CAMERA == curNode->type)
{
if (Node::CAMERA == curNode->type) {
cameras.back()->mName.Set(prop.value);
}
else if (Node::LIGHT == curNode->type)
{
else if (Node::LIGHT == curNode->type) {
lights.back()->mName.Set(prop.value);
}
}
@@ -1404,10 +1258,9 @@ void IRRImporter::InternReadFile( const std::string& pFile,
unsigned int pp = 0;
BatchLoader::PropertyMap map;
/* If the mesh is a static one remove all animations
/* If the mesh is a static one remove all animations from the impor data
*/
if (Node::ANIMMESH != curNode->type)
{
if (Node::ANIMMESH != curNode->type) {
pp |= aiProcess_RemoveComponent;
SetGenericProperty<int>(map.ints,AI_CONFIG_PP_RVC_FLAGS,
aiComponent_ANIMATIONS | aiComponent_BONEWEIGHTS);
@@ -1419,51 +1272,33 @@ void IRRImporter::InternReadFile( const std::string& pFile,
* file referencing each other *could* cause the system to
* recurse forever.
*/
std::string::size_type pos = prop.value.find_last_of('.');
// no file extension - can't read, so we don't need to try it
if( pos == std::string::npos)
{
DefaultLogger::get()->error("IRR: Can't load files without a file extension");
const std::string extension = GetExtension(prop.value);
if ("irr" == extension) {
DefaultLogger::get()->error("IRR: Can't load another IRR file recursively");
}
else
{
std::string extension = prop.value.substr( pos);
for (std::string::iterator i = extension.begin(); i != extension.end();++i)
*i = ::tolower(*i);
if (".irr" == prop.value)
{
DefaultLogger::get()->error("IRR: Can't load another IRR file recursively");
}
else
{
curNode->id = batch.AddLoadRequest(prop.value,pp,&map);
curNode->meshPath = prop.value;
}
curNode->id = batch.AddLoadRequest(prop.value,pp,&map);
curNode->meshPath = prop.value;
}
}
else if (inAnimator && prop.name == "Type")
{
// type of the animator
if (prop.value == "rotation")
{
if (prop.value == "rotation") {
curAnim->type = Animator::ROTATION;
}
else if (prop.value == "flyCircle")
{
else if (prop.value == "flyCircle") {
curAnim->type = Animator::FLY_CIRCLE;
}
else if (prop.value == "flyStraight")
{
else if (prop.value == "flyStraight") {
curAnim->type = Animator::FLY_CIRCLE;
}
else if (prop.value == "followSpline")
{
else if (prop.value == "followSpline") {
curAnim->type = Animator::FOLLOW_SPLINE;
}
else
{
else {
DefaultLogger::get()->warn("IRR: Ignoring unknown animator: "
+ prop.value);
@@ -1473,9 +1308,7 @@ void IRRImporter::InternReadFile( const std::string& pFile,
}
}
}
else if (reader->getNodeType() == EXN_ELEMENT_END &&
!ASSIMP_stricmp(reader->getNodeName(),"attributes"))
{
else if (reader->getNodeType() == EXN_ELEMENT_END && !ASSIMP_stricmp(reader->getNodeName(),"attributes")) {
break;
}
}
@@ -1485,14 +1318,11 @@ void IRRImporter::InternReadFile( const std::string& pFile,
case EXN_ELEMENT_END:
// If we reached the end of a node, we need to continue processing its parent
if (!ASSIMP_stricmp(reader->getNodeName(),"node"))
{
if (!curNode)
{
if (!ASSIMP_stricmp(reader->getNodeName(),"node")) {
if (!curNode) {
// currently is no node set. We need to go
// back in the node hierarchy
if (!curParent)
{
if (!curParent) {
curParent = root;
DefaultLogger::get()->error("IRR: Too many closing <node> elements");
}
@@ -1501,12 +1331,10 @@ void IRRImporter::InternReadFile( const std::string& pFile,
else curNode = NULL;
}
// clear all flags
else if (!ASSIMP_stricmp(reader->getNodeName(),"materials"))
{
else if (!ASSIMP_stricmp(reader->getNodeName(),"materials")) {
inMaterials = false;
}
else if (!ASSIMP_stricmp(reader->getNodeName(),"animators"))
{
else if (!ASSIMP_stricmp(reader->getNodeName(),"animators")) {
inAnimator = false;
}
break;
@@ -1519,11 +1347,11 @@ void IRRImporter::InternReadFile( const std::string& pFile,
/* Now iterate through all cameras and compute their final (horizontal) FOV
*/
for (std::vector<aiCamera*>::iterator it = cameras.begin(), end = cameras.end();
it != end; ++it) {
for (std::vector<aiCamera*>::iterator it = cameras.begin(), end = cameras.end();it != end; ++it) {
aiCamera* cam = *it;
if (cam->mAspect) // screen aspect could be missing
{
// screen aspect could be missing
if (cam->mAspect) {
cam->mHorizontalFOV *= cam->mAspect;
}
else DefaultLogger::get()->warn("IRR: Camera aspect is not given, can't compute horizontal FOV");
@@ -1539,8 +1367,7 @@ void IRRImporter::InternReadFile( const std::string& pFile,
/* Copy the cameras to the output array
*/
if (!cameras.empty())
{
if (!cameras.empty()) {
tempScene->mNumCameras = (unsigned int)cameras.size();
tempScene->mCameras = new aiCamera*[tempScene->mNumCameras];
::memcpy(tempScene->mCameras,&cameras[0],sizeof(void*)*tempScene->mNumCameras);
@@ -1548,8 +1375,7 @@ void IRRImporter::InternReadFile( const std::string& pFile,
/* Copy the light sources to the output array
*/
if (!lights.empty())
{
if (!lights.empty()) {
tempScene->mNumLights = (unsigned int)lights.size();
tempScene->mLights = new aiLight*[tempScene->mNumLights];
::memcpy(tempScene->mLights,&lights[0],sizeof(void*)*tempScene->mNumLights);
@@ -1593,8 +1419,7 @@ void IRRImporter::InternReadFile( const std::string& pFile,
an->mChannels = new aiNodeAnim*[an->mNumChannels];
::memcpy(an->mChannels, & anims [0], sizeof(void*)*an->mNumChannels);
}
if (!meshes.empty())
{
if (!meshes.empty()) {
// copy all meshes to the temporary scene
tempScene->mNumMeshes = (unsigned int)meshes.size();
tempScene->mMeshes = new aiMesh*[tempScene->mNumMeshes];
@@ -1604,8 +1429,7 @@ void IRRImporter::InternReadFile( const std::string& pFile,
/* Copy all materials to the output array
*/
if (!materials.empty())
{
if (!materials.empty()) {
tempScene->mNumMaterials = (unsigned int)materials.size();
tempScene->mMaterials = new aiMaterial*[tempScene->mNumMaterials];
::memcpy(tempScene->mMaterials,&materials[0],sizeof(void*)*
@@ -1624,8 +1448,7 @@ void IRRImporter::InternReadFile( const std::string& pFile,
* scene flag. This is necessary if we failed to load all
* models from external files
*/
if (!pScene->mNumMeshes || !pScene->mNumMaterials)
{
if (!pScene->mNumMeshes || !pScene->mNumMaterials) {
DefaultLogger::get()->warn("IRR: No meshes loaded, setting AI_SCENE_FLAGS_INCOMPLETE");
pScene->mFlags |= AI_SCENE_FLAGS_INCOMPLETE;
}