Skip to content

Commit

Permalink
Further work on the IRR, AC, LWS loaders. Further work on the - still…
Browse files Browse the repository at this point in the history
… unfinished - OptimizeGraph step. SceneCombiner works now properly in all cases I tested yet.

Added missing 'typename' in Colladaparser.h
First implementation of spherical and cylindrical mapping, already in use for IRR and LWO models. For the latter the coordinate system is not yet correct.
Moved vec2d to a separate header and added operators similar to vec3.
Added plane and ray helper classes. Just the data is wrapped, no operators required for the moment.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@249 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
  • Loading branch information
aramis_acg committed Nov 26, 2008
1 parent 9ca66fb commit fd9e6ed
Show file tree
Hide file tree
Showing 45 changed files with 2,639 additions and 851 deletions.
127 changes: 103 additions & 24 deletions code/ACLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "ACLoader.h"
#include "ParsingUtils.h"
#include "fast_atof.h"

//#include "Subdivision.h"

using namespace Assimp;

Expand Down Expand Up @@ -159,7 +159,7 @@ void AC3DImporter::LoadObjectSection(std::vector<Object>& objects)
Object& obj = objects.back();

aiLight* light = NULL;
if (!ASSIMP_stricmp(buffer,"light"))
if (!ASSIMP_strincmp(buffer,"light",5))
{
// This is a light source. Add it to the list
mLights->push_back(light = new aiLight());
Expand All @@ -173,7 +173,22 @@ void AC3DImporter::LoadObjectSection(std::vector<Object>& objects)
light->mName.length = ::sprintf(light->mName.data,"ACLight_%i",mLights->size()-1);
obj.name = std::string( light->mName.data );

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,"poly",4))
{
obj.type = Object::Poly;
}
else if (!ASSIMP_strincmp(buffer,"world",5))
{
obj.type = Object::World;
}


while (GetNextLine())
{
Expand Down Expand Up @@ -213,6 +228,11 @@ void AC3DImporter::LoadObjectSection(std::vector<Object>& objects)
SkipSpaces(&buffer);
AI_AC_CHECKED_LOAD_FLOAT_ARRAY("",0,2,&obj.texRepeat);
}
else if (TokenMatch(buffer,"texoff",6))
{
SkipSpaces(&buffer);
AI_AC_CHECKED_LOAD_FLOAT_ARRAY("",0,2,&obj.texOffset);
}
else if (TokenMatch(buffer,"rot",3))
{
SkipSpaces(&buffer);
Expand All @@ -223,6 +243,11 @@ void AC3DImporter::LoadObjectSection(std::vector<Object>& objects)
SkipSpaces(&buffer);
AI_AC_CHECKED_LOAD_FLOAT_ARRAY("",0,3,&obj.translation);
}
else if (TokenMatch(buffer,"subdiv",6))
{
SkipSpaces(&buffer);
obj.subDiv = strtol10(buffer,&buffer);
}
else if (TokenMatch(buffer,"numvert",7))
{
SkipSpaces(&buffer);
Expand Down Expand Up @@ -352,6 +377,17 @@ void AC3DImporter::ConvertMaterial(const Object& object,
{
s.Set(object.texture);
matDest.AddProperty(&s,AI_MATKEY_TEXTURE_DIFFUSE(0));

// 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;
matDest.AddProperty<float>((float*)&transform,sizeof(aiUVTransform),
AI_MATKEY_UVTRANSFORM_DIFFUSE(0));
}
}

matDest.AddProperty<aiColor3D>(&matSrc.rgb,1, AI_MATKEY_COLOR_DIFFUSE);
Expand All @@ -377,9 +413,11 @@ void AC3DImporter::ConvertMaterial(const Object& object,
aiNode* AC3DImporter::ConvertObjectSection(Object& object,
std::vector<aiMesh*>& meshes,
std::vector<MaterialHelper*>& outMaterials,
const std::vector<Material>& materials)
const std::vector<Material>& materials,
aiNode* parent)
{
aiNode* node = new aiNode();
node->mParent = parent;
if (object.vertices.size())
{
if (!object.surfaces.size() || !object.numRefs)
Expand Down Expand Up @@ -434,7 +472,7 @@ aiNode* AC3DImporter::ConvertObjectSection(Object& object,
register unsigned int idx = (*it).mat;
if (idx >= needMat.size())
{
DefaultLogger::get()->error("AC3D: material index os out of range");
DefaultLogger::get()->error("AC3D: material index is out of range");
idx = 0;
}
if ((*it).entries.empty())
Expand Down Expand Up @@ -539,13 +577,14 @@ aiNode* AC3DImporter::ConvertObjectSection(Object& object,
face.mIndices[i] = cur++;

// copy vertex positions
*vertices = object.vertices[entry.first];
*vertices = object.vertices[entry.first] + object.translation;

// copy texture coordinates (apply the UV offset)

// copy texture coordinates
if (uv)
{
uv->x = entry.second.x * object.texRepeat.x;
uv->y = entry.second.y * object.texRepeat.y;
uv->x = entry.second.x;
uv->y = entry.second.y;
++uv;
}
}
Expand All @@ -571,11 +610,11 @@ aiNode* AC3DImporter::ConvertObjectSection(Object& object,
// copy vertex positions
*vertices++ = object.vertices[(*it2).first];

// copy texture coordinates (apply the UV offset)
// copy texture coordinates
if (uv)
{
uv->x = (*it2).second.x * object.texRepeat.x;
uv->y = (*it2).second.y * object.texRepeat.y;
uv->x = (*it2).second.x;
uv->y = (*it2).second.y;
++uv;
}

Expand All @@ -591,39 +630,76 @@ aiNode* AC3DImporter::ConvertObjectSection(Object& object,

if (uv)
{
uv->x = (*it2).second.x * object.texRepeat.x;
uv->y = (*it2).second.y * object.texRepeat.y;
uv->x = (*it2).second.x;
uv->y = (*it2).second.y;
++uv;
}
}
}
}
}
#if 0
// Now apply catmull clark subdivision if necessary. However, this is
// not *absolutely* correct: it might be we split a mesh up into
// multiple sub meshes, one for each material. AC3D doesn't do that
// in its subdivision implementation, so our output *could* look
// different in some cases.

if (object.subDiv)
{
Subdivider* div = Subdivider::Create(Subdivider::CATMULL_CLARKE);
div->Subdivide(mesh,object.subDiv);
delete div;
}
#endif
}
}
}

// add children to the object
if (object.children.size())
if (object.name.length())
node->mName.Set(object.name);
else
{
node->mNumChildren = (unsigned int)object.children.size();
node->mChildren = new aiNode*[node->mNumChildren];
for (unsigned int i = 0; i < node->mNumChildren;++i)
// generate a name depending on the type of the node
switch (object.type)
{
node->mChildren[i] = ConvertObjectSection(object.children[i],meshes,outMaterials,materials);
node->mChildren[i]->mParent = node;
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;
}
}

node->mName.Set(object.name);

// setup the local transformation matrix of the object
// compute the transformation offset to the parent node
node->mTransformation = aiMatrix4x4 ( object.rotation );

node->mTransformation.a4 = object.translation.x;
node->mTransformation.b4 = -object.translation.y;
node->mTransformation.b4 = object.translation.y;
node->mTransformation.c4 = object.translation.z;

// 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);
}
}

return node;
}

Expand Down Expand Up @@ -653,6 +729,8 @@ void AC3DImporter::InternReadFile( const std::string& pFile,
buffer = &mBuffer2[0];
mNumMeshes = 0;

lights = polys = worlds = groups = 0;

if (::strncmp(buffer,"AC3D",4))
throw new ImportErrorException("AC3D: No valid AC3D file, magic sequence not found");

Expand Down Expand Up @@ -731,7 +809,7 @@ void AC3DImporter::InternReadFile( const std::string& pFile,
if (!::strncmp( pScene->mRootNode->mName.data, "Node", 4))
pScene->mRootNode->mName.Set("<AC3DWorld>");

// build output arrays
// copy meshes
if (meshes.empty())
{
throw new ImportErrorException("An unknown error occured during converting");
Expand All @@ -740,11 +818,12 @@ void AC3DImporter::InternReadFile( const std::string& pFile,
pScene->mMeshes = new aiMesh*[pScene->mNumMeshes];
::memcpy(pScene->mMeshes,&meshes[0],pScene->mNumMeshes*sizeof(void*));


// copy materials
pScene->mNumMaterials = (unsigned int)omaterials.size();
pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials];
::memcpy(pScene->mMaterials,&omaterials[0],pScene->mNumMaterials*sizeof(void*));

// copy lights
pScene->mNumLights = (unsigned int)lights.size();
if (lights.size())
{
Expand Down
23 changes: 21 additions & 2 deletions code/ACLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,20 @@ class AC3DImporter : public BaseImporter
// Represents an AC3D object
struct Object
{
enum Type
{
World = 0x0,
Poly = 0x1,
Group = 0x2,
Light = 0x4
} type;


Object()
: texRepeat(1.f,1.f)
, numRefs (0)
, subDiv (0)
, type (World)
{}

// name of the object
Expand All @@ -128,7 +139,7 @@ class AC3DImporter : public BaseImporter
std::string texture;

// texture repat factors (scaling for all coordinates)
aiVector2D texRepeat;
aiVector2D texRepeat, texOffset;

// rotation matrix
aiMatrix3x3 rotation;
Expand All @@ -144,6 +155,10 @@ class AC3DImporter : public BaseImporter

// number of indices (= num verts in verbose format)
unsigned int numRefs;

// number of subdivisions to be performed on the
// imported data
unsigned int subDiv;
};


Expand Down Expand Up @@ -208,7 +223,8 @@ class AC3DImporter : public BaseImporter
aiNode* ConvertObjectSection(Object& object,
std::vector<aiMesh*>& meshes,
std::vector<MaterialHelper*>& outMaterials,
const std::vector<Material>& materials);
const std::vector<Material>& materials,
aiNode* parent = NULL);


// -------------------------------------------------------------------
Expand Down Expand Up @@ -239,6 +255,9 @@ class AC3DImporter : public BaseImporter

// current list of light sources
std::vector<aiLight*>* mLights;

// name counters
unsigned int lights, groups, polys, worlds;
};

} // end of namespace Assimp
Expand Down
3 changes: 1 addition & 2 deletions code/AssimpPCH.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# include "../include/BoostWorkaround/boost/scoped_ptr.hpp"
# include "../include/BoostWorkaround/boost/scoped_array.hpp"
# include "../include/BoostWorkaround/boost/format.hpp"
# include "../include/BoostWorkaround/boost/common_factor_rt.hpp"
# include "../include/BoostWorkaround/boost/foreach.hpp"

#else

# include <boost/scoped_ptr.hpp>
# include <boost/scoped_array.hpp>
# include <boost/format.hpp>
# include <boost/math/common_factor_rt.hpp>
# include <boost/foreach.hpp>

#endif
Expand Down
Loading

0 comments on commit fd9e6ed

Please sign in to comment.