COB loader does now honour explicit chunk sizes. if none are given in a particular chunk, the loader reverts to the old behaviour.

COB loader converts textures properly now.
Add textured test files to confirm the previous issue.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@652 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
aramis_acg 2010-04-06 00:13:30 +00:00
parent 0fb732de91
commit 3c03e0fca5
5 changed files with 54346 additions and 2 deletions

View File

@ -210,6 +210,14 @@ void COBImporter::InternReadFile( const std::string& pFile,
pScene->mRootNode = BuildNodes(*root.get(),scene,pScene); pScene->mRootNode = BuildNodes(*root.get(),scene,pScene);
} }
// ------------------------------------------------------------------------------------------------
void ConvertTexture(boost::shared_ptr< Texture > tex, MaterialHelper* out, aiTextureType type)
{
const aiString path( tex->path );
out->AddProperty(&path,AI_MATKEY_TEXTURE(type,0));
out->AddProperty(&tex->transform,sizeof(aiUVTransform)/sizeof(float),AI_MATKEY_UVTRANSFORM(type,0));
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
aiNode* COBImporter::BuildNodes(const Node& root,const Scene& scin,aiScene* fill) aiNode* COBImporter::BuildNodes(const Node& root,const Scene& scin,aiScene* fill)
{ {
@ -325,15 +333,33 @@ aiNode* COBImporter::BuildNodes(const Node& root,const Scene& scin,aiScene* fill
c = aiColor3D(min->rgb)*min->ka; c = aiColor3D(min->rgb)*min->ka;
mat->AddProperty(&c,1,AI_MATKEY_COLOR_AMBIENT); mat->AddProperty(&c,1,AI_MATKEY_COLOR_AMBIENT);
// convert textures if some exist.
min->tex_color ? ConvertTexture(min->tex_color,mat,aiTextureType_DIFFUSE) : 0;
min->tex_env ? ConvertTexture(min->tex_env ,mat,aiTextureType_UNKNOWN) : 0;
min->tex_bump ? ConvertTexture(min->tex_bump ,mat,aiTextureType_HEIGHT ) : 0;
} }
} }
} }
} }
else if (Node::TYPE_LIGHT == root.type) { else if (Node::TYPE_LIGHT == root.type) {
const Light& ndlight = dynamic_cast<const Light&>(root); const Light& ndlight = dynamic_cast<const Light&>(root);
aiLight* outlight = fill->mLights[fill->mNumLights++] = new aiLight();
outlight->mName.Set(ndlight.name);
outlight->mColorDiffuse = outlight->mColorAmbient = outlight->mColorSpecular = ndlight.color;
outlight->mAngleOuterCone = AI_DEG_TO_RAD(ndlight.angle);
outlight->mAngleInnerCone = AI_DEG_TO_RAD(ndlight.inner_angle);
// XXX
outlight->mType = ndlight.ltype==Light::SPOT ? aiLightSource_SPOT : aiLightSource_DIRECTIONAL;
} }
else if (Node::TYPE_CAMERA == root.type) { else if (Node::TYPE_CAMERA == root.type) {
const Camera& ndcam = dynamic_cast<const Camera&>(root); const Camera& ndcam = dynamic_cast<const Camera&>(root);
aiCamera* outcam = fill->mCameras[fill->mNumCameras++] = new aiCamera();
outcam->mName.Set(ndcam.name);
} }
// add meshes // add meshes
@ -891,6 +917,32 @@ void COBImporter::UnsupportedChunk_Binary( StreamReaderLE& reader, const ChunkIn
else ThrowException(error); else ThrowException(error);
} }
// ------------------------------------------------------------------------------------------------
// tiny utility guard to aid me at staying within chunk boundaries.
class chunk_guard {
public:
chunk_guard(const COB::ChunkInfo& nfo, StreamReaderLE& reader)
: nfo(nfo)
, reader(reader)
, cur(reader.GetCurrentPos())
{
}
~chunk_guard() {
// don't do anything if the size is not given
nfo.size != static_cast<unsigned int>(-1) ? reader.IncPtr(static_cast<int>(nfo.size)-
reader.GetCurrentPos()+cur) : 0;
}
private:
const COB::ChunkInfo& nfo;
StreamReaderLE& reader;
long cur;
};
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void COBImporter::ReadBinaryFile(Scene& out, StreamReaderLE* reader) void COBImporter::ReadBinaryFile(Scene& out, StreamReaderLE* reader)
{ {
@ -957,6 +1009,7 @@ void COBImporter::ReadPolH_Binary(COB::Scene& out, StreamReaderLE& reader, const
if(nfo.version > 8) { if(nfo.version > 8) {
return UnsupportedChunk_Binary(reader,nfo,"PolH"); return UnsupportedChunk_Binary(reader,nfo,"PolH");
} }
const chunk_guard cn(nfo,reader);
out.nodes.push_back(boost::shared_ptr<Mesh>(new Mesh())); out.nodes.push_back(boost::shared_ptr<Mesh>(new Mesh()));
Mesh& msh = dynamic_cast<Mesh&>(*out.nodes.back().get()); Mesh& msh = dynamic_cast<Mesh&>(*out.nodes.back().get());
@ -1028,6 +1081,8 @@ void COBImporter::ReadBitM_Binary(COB::Scene& out, StreamReaderLE& reader, const
return UnsupportedChunk_Binary(reader,nfo,"BitM"); return UnsupportedChunk_Binary(reader,nfo,"BitM");
} }
const chunk_guard cn(nfo,reader);
const uint32_t len = reader.GetI4(); const uint32_t len = reader.GetI4();
reader.IncPtr(len); reader.IncPtr(len);
@ -1042,6 +1097,8 @@ void COBImporter::ReadMat1_Binary(COB::Scene& out, StreamReaderLE& reader, const
return UnsupportedChunk_Binary(reader,nfo,"Mat1"); return UnsupportedChunk_Binary(reader,nfo,"Mat1");
} }
const chunk_guard cn(nfo,reader);
out.materials.push_back(Material()); out.materials.push_back(Material());
Material& mat = out.materials.back(); Material& mat = out.materials.back();
mat = nfo; mat = nfo;
@ -1142,6 +1199,8 @@ void COBImporter::ReadCame_Binary(COB::Scene& out, StreamReaderLE& reader, const
return UnsupportedChunk_Binary(reader,nfo,"Came"); return UnsupportedChunk_Binary(reader,nfo,"Came");
} }
const chunk_guard cn(nfo,reader);
out.nodes.push_back(boost::shared_ptr<Camera>(new Camera())); out.nodes.push_back(boost::shared_ptr<Camera>(new Camera()));
Camera& msh = dynamic_cast<Camera&>(*out.nodes.back().get()); Camera& msh = dynamic_cast<Camera&>(*out.nodes.back().get());
msh = nfo; msh = nfo;
@ -1163,6 +1222,8 @@ void COBImporter::ReadLght_Binary(COB::Scene& out, StreamReaderLE& reader, const
return UnsupportedChunk_Binary(reader,nfo,"Lght"); return UnsupportedChunk_Binary(reader,nfo,"Lght");
} }
const chunk_guard cn(nfo,reader);
out.nodes.push_back(boost::shared_ptr<Light>(new Light())); out.nodes.push_back(boost::shared_ptr<Light>(new Light()));
Light& msh = dynamic_cast<Light&>(*out.nodes.back().get()); Light& msh = dynamic_cast<Light&>(*out.nodes.back().get());
msh = nfo; msh = nfo;
@ -1177,6 +1238,8 @@ void COBImporter::ReadGrou_Binary(COB::Scene& out, StreamReaderLE& reader, const
return UnsupportedChunk_Binary(reader,nfo,"Grou"); return UnsupportedChunk_Binary(reader,nfo,"Grou");
} }
const chunk_guard cn(nfo,reader);
out.nodes.push_back(boost::shared_ptr<Group>(new Group())); out.nodes.push_back(boost::shared_ptr<Group>(new Group()));
Group& msh = dynamic_cast<Group&>(*out.nodes.back().get()); Group& msh = dynamic_cast<Group&>(*out.nodes.back().get());
msh = nfo; msh = nfo;
@ -1191,6 +1254,8 @@ void COBImporter::ReadUnit_Binary(COB::Scene& out, StreamReaderLE& reader, const
return UnsupportedChunk_Binary(reader,nfo,"Unit"); return UnsupportedChunk_Binary(reader,nfo,"Unit");
} }
const chunk_guard cn(nfo,reader);
// parent chunks preceede their childs, so we should have the // parent chunks preceede their childs, so we should have the
// corresponding chunk already. // corresponding chunk already.
for_each(boost::shared_ptr< Node >& nd, out.nodes) { for_each(boost::shared_ptr< Node >& nd, out.nodes) {

View File

@ -17,7 +17,7 @@ echo #define SVNRevision > tmpfile.txt
if exist ..\..\revision.h del /q ..\..\revision.h if exist ..\..\revision.h del /q ..\..\revision.h
for /f "delims=" %%l in (tmpfile.txt) Do ( for /f "delims=" %%l in (tmpfile.txt) Do (
for /f "delims=M" %%r in ("%addtext%") Do ( for /f "delims=M:" %%r in ("%addtext%") Do (
echo %%l %%r >> ..\..\revision.h echo %%l %%r >> ..\..\revision.h
) )
) )

View File

@ -1 +1 @@
#define SVNRevision 638 #define SVNRevision 647

Binary file not shown.

File diff suppressed because it is too large Load Diff