Add first WIP version of a TrueSpace loader. Currently only ASCII COB/SCNs are supported.

Add some fast_atof overloads to simplify calling it.
Add another convenience c'tor to aiColorMM.
Add COB test models.
Remove unreferenced member in B3D importer.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@633 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
aramis_acg 2010-04-02 04:17:05 +00:00
parent bb5aca8a17
commit 4c1b5a532d
21 changed files with 11369 additions and 52 deletions

View File

@ -105,7 +105,7 @@ private:
void ReadBB3D( aiScene *scene ); void ReadBB3D( aiScene *scene );
unsigned _pos; unsigned _pos;
unsigned _size; // unsigned _size;
std::vector<unsigned char> _buf; std::vector<unsigned char> _buf;
std::vector<unsigned> _stack; std::vector<unsigned> _stack;

View File

@ -137,6 +137,8 @@ SOURCE_GROUP( Common FILES
Subdivision.cpp Subdivision.cpp
Subdivision.h Subdivision.h
Vertex.h Vertex.h
LineSplitter.h
TinyFormatter.h
) )
SOURCE_GROUP( 3DS FILES SOURCE_GROUP( 3DS FILES
@ -295,6 +297,12 @@ SOURCE_GROUP(MS3D FILES
MS3DLoader.h MS3DLoader.h
) )
SOURCE_GROUP(COB FILES
COBLoader.cpp
COBLoader.h
COBScene.h
)
SOURCE_GROUP( PostProcessing FILES SOURCE_GROUP( PostProcessing FILES
CalcTangentsProcess.cpp CalcTangentsProcess.cpp
CalcTangentsProcess.h CalcTangentsProcess.h
@ -661,6 +669,11 @@ ADD_LIBRARY( assimp SHARED
Vertex.h Vertex.h
MS3DLoader.h MS3DLoader.h
MS3DLoader.cpp MS3DLoader.cpp
COBLoader.cpp
COBLoader.h
COBScene.h
TinyFormatter.h
LineSplitter.h
# Necessary to show the headers in the project when using the VC++ generator: # Necessary to show the headers in the project when using the VC++ generator:
BoostWorkaround/boost/math/common_factor_rt.hpp BoostWorkaround/boost/math/common_factor_rt.hpp

882
code/COBLoader.cpp 100644
View File

@ -0,0 +1,882 @@
/*
Open Asset Import Library (ASSIMP)
----------------------------------------------------------------------
Copyright (c) 2006-2008, ASSIMP Development Team
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.
* Neither the name of the ASSIMP team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the ASSIMP Development Team.
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 COBLoader.cpp
* @brief Implementation of the TrueSpace COB/SCN importer class.
*/
#include "AssimpPCH.h"
#ifndef AI_BUILD_NO_COB_IMPORTER
#include "COBLoader.h"
#include "COBScene.h"
#include "StreamReader.h"
#include "ParsingUtils.h"
#include "fast_atof.h"
#include "LineSplitter.h"
#include "TinyFormatter.h"
using namespace Assimp;
using namespace Assimp::COB;
using namespace Assimp::Formatter;
#define for_each BOOST_FOREACH
// ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer
COBImporter::COBImporter()
{}
// ------------------------------------------------------------------------------------------------
// Destructor, private as well
COBImporter::~COBImporter()
{}
// ------------------------------------------------------------------------------------------------
// Returns whether the class can handle the format of the given file.
bool COBImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const
{
const std::string& extension = GetExtension(pFile);
if (extension == "cob" || extension == "scn") {
return true;
}
else if (!extension.length() || checkSig) {
if (!pIOHandler) {
return true;
}
const char* tokens[] = {"Caligary"};
return SearchFileHeaderForToken(pIOHandler,pFile,tokens,1);
}
return false;
}
// ------------------------------------------------------------------------------------------------
// List all extensions handled by this loader
void COBImporter::GetExtensionList(std::set<std::string>& app)
{
app.insert("cob");
app.insert("scn");
}
// ------------------------------------------------------------------------------------------------
// Setup configuration properties for the loader
void COBImporter::SetupProperties(const Importer* pImp)
{
// nothing to be done for the moment
}
// ------------------------------------------------------------------------------------------------
/*static*/ void COBImporter::ThrowException(const std::string& msg)
{
throw DeadlyImportError("COB: "+msg);
}
// ------------------------------------------------------------------------------------------------
// Imports the given file into the given scene structure.
void COBImporter::InternReadFile( const std::string& pFile,
aiScene* pScene, IOSystem* pIOHandler)
{
COB::Scene scene;
boost::scoped_ptr<StreamReaderLE> stream(new StreamReaderLE(
pIOHandler->Open(pFile,"rb")) );
// check header
char head[32];
stream->CopyAndAdvance(head,32);
if (strncmp(head,"Caligari ",9)) {
ThrowException("Could not found magic id: `Caligari`");
}
DefaultLogger::get()->info("File format tag: "+std::string(head+9,6));
void (COBImporter::* load)(Scene&,StreamReaderLE*)= head[15]=='A'?&COBImporter::ReadAsciiFile:&COBImporter::ReadBinaryFile;
if (head[16]!='L') {
ThrowException("File is big-endian, which is not supported");
}
// load data into intermediate structures
(this->*load)(scene,stream.get());
if(scene.nodes.empty()) {
ThrowException("No nodes loaded");
}
// sort faces by material indices
for_each(boost::shared_ptr< Node >& n,scene.nodes) {
try {
Mesh& mesh = dynamic_cast<Mesh&>(*n.get());
for_each(Face& f,mesh.faces) {
mesh.temp_map[f.material].push_back(&f);
}
} catch (std::bad_cast&) {}
}
// count meshes
for_each(boost::shared_ptr< Node >& n,scene.nodes) {
try {
Mesh& mesh = dynamic_cast<Mesh&>(*n.get());
if (mesh.vertex_positions.size() && mesh.texture_coords.size()) {
pScene->mNumMeshes += mesh.temp_map.size();
}
} catch (std::bad_cast&) {}
}
pScene->mMeshes = new aiMesh*[pScene->mNumMeshes]();
pScene->mMaterials = new aiMaterial*[pScene->mNumMeshes]();
pScene->mNumMeshes = 0;
// count lights and cameras
for_each(boost::shared_ptr< Node >& n,scene.nodes) {
if (n->type == Node::TYPE_LIGHT) {
++pScene->mNumLights;
}
else if (n->type == Node::TYPE_CAMERA) {
++pScene->mNumCameras;
}
}
if (pScene->mNumLights) {
pScene->mLights = new aiLight*[pScene->mNumLights]();
}
if (pScene->mNumCameras) {
pScene->mCameras = new aiCamera*[pScene->mNumCameras]();
}
pScene->mNumLights = pScene->mNumCameras = 0;
// resolve parents by their IDs and build the output graph
boost::scoped_ptr<Node> root(new Group());
for(size_t n = 0; n < scene.nodes.size(); ++n) {
const Node& nn = *scene.nodes[n].get();
if(nn.parent_id==0) {
root->temp_children.push_back(&nn);
}
for(size_t m = n; m < scene.nodes.size(); ++m) {
const Node& mm = *scene.nodes[m].get();
if (mm.parent_id == nn.id) {
nn.temp_children.push_back(&mm);
}
}
}
pScene->mRootNode = BuildNodes(*root.get(),scene,pScene);
}
// ------------------------------------------------------------------------------------------------
aiNode* COBImporter::BuildNodes(const Node& root,const Scene& scin,aiScene* fill)
{
aiNode* nd = new aiNode();
nd->mName.Set(root.name);
nd->mTransformation = root.transform;
// Note to everybody believing Voodoo is appropriate here:
// I know polymorphism, run as fast as you can ;-)
if (Node::TYPE_MESH == root.type) {
const Mesh& ndmesh = dynamic_cast<const Mesh&>(root);
if (ndmesh.vertex_positions.size() && ndmesh.texture_coords.size()) {
typedef std::pair<unsigned int,Mesh::FaceRefList> Entry;
for_each(const Entry& reflist,ndmesh.temp_map) {
{ // create mesh
size_t n = 0;
for_each(Face* f, reflist.second) {
n += f->indices.size();
}
if (!n) {
continue;
}
aiMesh* outmesh = fill->mMeshes[fill->mNumMeshes++] = new aiMesh();
++nd->mNumMeshes;
outmesh->mVertices = new aiVector3D[n];
outmesh->mTextureCoords[0] = new aiVector3D[n];
outmesh->mFaces = new aiFace[reflist.second.size()]();
for_each(Face* f, reflist.second) {
if (f->indices.empty()) {
continue;
}
aiFace& fout = outmesh->mFaces[outmesh->mNumFaces++];
fout.mIndices = new unsigned int[f->indices.size()];
for_each(VertexIndex& v, f->indices) {
if (v.pos_idx >= ndmesh.vertex_positions.size()) {
ThrowException("Position index out of range");
}
if (v.uv_idx >= ndmesh.texture_coords.size()) {
ThrowException("UV index out of range");
}
outmesh->mVertices[outmesh->mNumVertices] = ndmesh.vertex_positions[ v.pos_idx ];
outmesh->mTextureCoords[0][outmesh->mNumVertices] = aiVector3D(
ndmesh.texture_coords[ v.uv_idx ].x,
ndmesh.texture_coords[ v.uv_idx ].y,
0.f
);
fout.mIndices[fout.mNumIndices++] = outmesh->mNumVertices++;
}
}
outmesh->mMaterialIndex = fill->mNumMaterials;
}{ // create material
const Material* min = NULL;
for_each(const Material& m, scin.materials) {
if (m.parent_id == ndmesh.id && m.matnum == reflist.first) {
min = &m;
break;
}
}
boost::scoped_ptr<const Material> defmat;
if(!min) {
DefaultLogger::get()->debug(format()<<"Could not resolve material index "
<<reflist.first<<" - creating default material for this slot");
defmat.reset(min=new Material());
}
MaterialHelper* mat = new MaterialHelper();
fill->mMaterials[fill->mNumMaterials++] = mat;
aiString s;
s.Set(min->type);
mat->AddProperty(&s,AI_MATKEY_NAME);
if(int tmp = ndmesh.draw_flags & Mesh::WIRED ? 1 : 0) {
mat->AddProperty(&tmp,1,AI_MATKEY_ENABLE_WIREFRAME);
}
{ int shader;
switch(min->shader)
{
case Material::FLAT:
shader = aiShadingMode_Gouraud;
break;
case Material::PHONG:
shader = aiShadingMode_Phong;
break;
case Material::METAL:
shader = aiShadingMode_CookTorrance;
break;
default:
ai_assert(false); // shouldn't be here
}
mat->AddProperty(&shader,1,AI_MATKEY_SHADING_MODEL);
if(shader != aiShadingMode_Gouraud) {
mat->AddProperty(&min->exp,1,AI_MATKEY_SHININESS);
}
}
mat->AddProperty(&min->ior,1,AI_MATKEY_REFRACTI);
mat->AddProperty(&min->rgb,1,AI_MATKEY_COLOR_DIFFUSE);
aiColor3D c = aiColor3D(min->rgb)*min->ks;
mat->AddProperty(&c,1,AI_MATKEY_COLOR_SPECULAR);
c = aiColor3D(min->rgb)*min->ka;
mat->AddProperty(&c,1,AI_MATKEY_COLOR_AMBIENT);
}
}
}
}
else if (Node::TYPE_LIGHT == root.type) {
const Light& ndlight = dynamic_cast<const Light&>(root);
}
else if (Node::TYPE_CAMERA == root.type) {
const Camera& ndcam = dynamic_cast<const Camera&>(root);
}
// add meshes
if (nd->mNumMeshes) { // mMeshes must be NULL if count is 0
nd->mMeshes = new unsigned int[nd->mNumMeshes];
for(unsigned int i = 0; i < nd->mNumMeshes;++i) {
nd->mMeshes[i] = fill->mNumMeshes-i-1;
}
}
// add children recursively
nd->mChildren = new aiNode*[root.temp_children.size()]();
for_each(const Node* n, root.temp_children) {
(nd->mChildren[nd->mNumChildren++] = BuildNodes(*n,scin,fill))->mParent = nd;
}
return nd;
}
// ------------------------------------------------------------------------------------------------
// Read an ASCII file into the given scene data structure
void COBImporter::ReadAsciiFile(Scene& out, StreamReaderLE* stream)
{
ChunkInfo ci;
for(LineSplitter splitter(*stream);splitter;++splitter) {
// add all chunks to be recognized here. /else ../ ommitted intentionally.
if (splitter.match_start("PolH ")) {
ReadChunkInfo_Ascii(ci,splitter);
ReadPolH_Ascii(out,splitter,ci);
}
if (splitter.match_start("BitM ")) {
ReadChunkInfo_Ascii(ci,splitter);
ReadBitM_Ascii(out,splitter,ci);
}
if (splitter.match_start("Mat1 ")) {
ReadChunkInfo_Ascii(ci,splitter);
ReadMat1_Ascii(out,splitter,ci);
}
if (splitter.match_start("Grou ")) {
ReadChunkInfo_Ascii(ci,splitter);
ReadGrou_Ascii(out,splitter,ci);
}
if (splitter.match_start("Lght ")) {
ReadChunkInfo_Ascii(ci,splitter);
ReadLght_Ascii(out,splitter,ci);
}
if (splitter.match_start("Came ")) {
ReadChunkInfo_Ascii(ci,splitter);
ReadCame_Ascii(out,splitter,ci);
}
if (splitter.match_start("Bone ")) {
ReadChunkInfo_Ascii(ci,splitter);
ReadBone_Ascii(out,splitter,ci);
}
if (splitter.match_start("Chan ")) {
ReadChunkInfo_Ascii(ci,splitter);
ReadChan_Ascii(out,splitter,ci);
}
if (splitter.match_start("Unit ")) {
ReadChunkInfo_Ascii(ci,splitter);
ReadUnit_Ascii(out,splitter,ci);
}
if (splitter.match_start("END ")) {
// we don't need this, but I guess there is a reason this
// chunk has been implemented into COB for.
return;
}
}
}
// ------------------------------------------------------------------------------------------------
void COBImporter::ReadChunkInfo_Ascii(ChunkInfo& out, const LineSplitter& splitter)
{
const char* all_tokens[8];
splitter.get_tokens(all_tokens);
out.version = (all_tokens[1][1]-'0')*100+(all_tokens[1][3]-'0')*10+(all_tokens[1][4]-'0');
out.id = strtol10(all_tokens[3]);
out.parent_id = strtol10(all_tokens[5]);
out.size = strtol10s(all_tokens[7]);
}
// ------------------------------------------------------------------------------------------------
void COBImporter::UnsupportedChunk_Ascii(LineSplitter& splitter, const ChunkInfo& nfo, const char* name)
{
std::string error = "Encountered unsupported chunk: "; error += name;
// we can recover if the chunk size was specified.
if(nfo.size) {
DefaultLogger::get()->error(error);
// (HACK) - our current position in the stream is the beginning of the
// head line of the next chunk. That's fine, but the caller is going
// to call ++ on `splitter`, which we need to swallow to avoid
// missing the next line.
splitter.get_stream().IncPtr(nfo.size);
splitter.swallow_next_increment();
}
else ThrowException(error);
}
// ------------------------------------------------------------------------------------------------
void COBImporter::LogWarn_Ascii(const LineSplitter& splitter, const format& message) {
LogWarn_Ascii(message << " [at line "<< splitter.get_index()<<"]");
}
// ------------------------------------------------------------------------------------------------
void COBImporter::LogError_Ascii(const LineSplitter& splitter, const format& message) {
LogError_Ascii(message << " [at line "<< splitter.get_index()<<"]");
}
// ------------------------------------------------------------------------------------------------
void COBImporter::LogInfo_Ascii(const LineSplitter& splitter, const format& message) {
LogInfo_Ascii(message << " [at line "<< splitter.get_index()<<"]");
}
// ------------------------------------------------------------------------------------------------
void COBImporter::LogDebug_Ascii(const LineSplitter& splitter, const format& message) {
LogDebug_Ascii(message << " [at line "<< splitter.get_index()<<"]");
}
// ------------------------------------------------------------------------------------------------
void COBImporter::LogWarn_Ascii(const std::string& message) {
DefaultLogger::get()->warn("COB: "+message);
}
// ------------------------------------------------------------------------------------------------
void COBImporter::LogError_Ascii(const std::string& message) {
DefaultLogger::get()->error("COB: "+message);
}
// ------------------------------------------------------------------------------------------------
void COBImporter::LogInfo_Ascii(const std::string& message) {
DefaultLogger::get()->info("COB: "+message);
}
// ------------------------------------------------------------------------------------------------
void COBImporter::LogDebug_Ascii(const std::string& message) {
DefaultLogger::get()->debug("COB: "+message);
}
// ------------------------------------------------------------------------------------------------
void COBImporter::ReadBasicNodeInfo_Ascii(Node& msh, LineSplitter& splitter, const ChunkInfo& nfo)
{
for(;splitter;++splitter) {
if (splitter.match_start("Name")) {
msh.name = std::string(splitter[1]);
// make nice names by merging the dupe count
std::replace(msh.name.begin(),msh.name.end(),
',','_');
}
else if (splitter.match_start("Transform")) {
for(unsigned int y = 0; y < 4 && ++splitter; ++y) {
const char* s = splitter->c_str();
for(unsigned int x = 0; x < 4; ++x) {
SkipSpaces(&s);
msh.transform[y][x] = fast_atof(&s);
}
}
// we need the transform chunk, so we won't return until we have it.
return;
}
}
}
// ------------------------------------------------------------------------------------------------
template <typename T>
void COBImporter::ReadFloat3Tuple_Ascii(T& fill, const char** in)
{
const char* rgb = *in;
for(unsigned int i = 0; i < 3; ++i) {
SkipSpaces(&rgb);
if (*rgb == ',')++rgb;
SkipSpaces(&rgb);
fill[i] = fast_atof(&rgb);
}
*in = rgb;
}
// ------------------------------------------------------------------------------------------------
void COBImporter::ReadMat1_Ascii(Scene& out, LineSplitter& splitter, const ChunkInfo& nfo)
{
if(nfo.version > 8) {
return UnsupportedChunk_Ascii(splitter,nfo,"Mat1");
}
++splitter;
if (!splitter.match_start("mat# ")) {
LogWarn_Ascii(splitter,format()<<
"Expected `mat#` line in `Mat1` chunk "<<nfo.id);
return;
}
out.materials.push_back(Material());
Material& mat = out.materials.back();
mat = nfo;
mat.matnum = strtol10(splitter[1]);
++splitter;
if (!splitter.match_start("shader: ")) {
LogWarn_Ascii(splitter,format()<<
"Expected `mat#` line in `Mat1` chunk "<<nfo.id);
return;
}
std::string shader = std::string(splitter[1]);
shader = shader.substr(0,shader.find_first_of(" \t"));
if (shader == "metal") {
mat.shader = Material::METAL;
}
else if (shader == "phong") {
mat.shader = Material::PHONG;
}
else if (shader != "flat") {
LogWarn_Ascii(splitter,format()<<
"Unknown value for `shader` in `Mat1` chunk "<<nfo.id);
}
++splitter;
if (!splitter.match_start("rgb ")) {
LogWarn_Ascii(splitter,format()<<
"Expected `rgb` line in `Mat1` chunk "<<nfo.id);
}
const char* rgb = splitter[1];
ReadFloat3Tuple_Ascii(mat.rgb,&rgb);
++splitter;
if (!splitter.match_start("alpha ")) {
LogWarn_Ascii(splitter,format()<<
"Expected `alpha` line in `Mat1` chunk "<<nfo.id);
}
const char* tokens[10];
splitter.get_tokens(tokens);
mat.alpha = fast_atof( tokens[1] );
mat.ka = fast_atof( tokens[3] );
mat.ks = fast_atof( tokens[5] );
mat.exp = fast_atof( tokens[7] );
mat.ior = fast_atof( tokens[9] );
}
// ------------------------------------------------------------------------------------------------
void COBImporter::ReadUnit_Ascii(Scene& out, LineSplitter& splitter, const ChunkInfo& nfo)
{
if(nfo.version > 1) {
return UnsupportedChunk_Ascii(splitter,nfo,"Unit");
}
++splitter;
if (!splitter.match_start("Units ")) {
LogWarn_Ascii(splitter,format()<<
"Expected `Units` line in `Unit` chunk "<<nfo.id);
return;
}
// parent chunks preceede their childs, so we should have the
// corresponding chunk already.
for_each(boost::shared_ptr< Node >& nd, out.nodes) {
if (nd->id == nfo.parent_id) {
unsigned int t;
static const float units[] = {1000.f,100.f,1.f,0.001f,
1.f/0.0254f,1.f/0.3048f,1.f/0.9144f,1.f/1609.344f
};
nd->unit_scale = (t=strtol10(splitter[1]))>=sizeof(units)/sizeof(units[0])?(
LogWarn_Ascii(splitter,format()<<t<<" is not a valid value for `Units` attribute in `Unit chunk` "<<nfo.id)
,1.f):units[t];
return;
}
}
LogWarn_Ascii(splitter,format()<<"`Unit` chunk "<<nfo.id<<" is a child of "
<<nfo.parent_id<<" which does not exist");
}
// ------------------------------------------------------------------------------------------------
void COBImporter::ReadChan_Ascii(Scene& out, LineSplitter& splitter, const ChunkInfo& nfo)
{
if(nfo.version > 8) {
return UnsupportedChunk_Ascii(splitter,nfo,"Chan");
}
}
// ------------------------------------------------------------------------------------------------
void COBImporter::ReadLght_Ascii(Scene& out, LineSplitter& splitter, const ChunkInfo& nfo)
{
if(nfo.version > 8) {
return UnsupportedChunk_Ascii(splitter,nfo,"Lght");
}
out.nodes.push_back(boost::shared_ptr<Light>(new Light()));
Light& msh = *dynamic_cast<Light*>(out.nodes.back().get());
msh = nfo;
ReadBasicNodeInfo_Ascii(msh,++splitter,nfo);
if (splitter.match_start("Infinite ")) {
msh.ltype = Light::INFINITE;
}
else if (splitter.match_start("Local ")) {
msh.ltype = Light::LOCAL;
}
else if (splitter.match_start("Spot ")) {
msh.ltype = Light::SPOT;
}
else {
LogWarn_Ascii(splitter,format()<<
"Unknown kind of light source in `Lght` chunk "<<nfo.id<<" : "<<*splitter);
msh.ltype = Light::SPOT;
}
++splitter;
if (!splitter.match_start("color ")) {
LogWarn_Ascii(splitter,format()<<
"Expected `color` line in `Lght` chunk "<<nfo.id);
}
const char* rgb = splitter[1];
ReadFloat3Tuple_Ascii(msh.color ,&rgb);
SkipSpaces(&rgb);
if (strncmp(rgb,"cone angle",10)) {
LogWarn_Ascii(splitter,format()<<
"Expected `cone angle` entity in `color` line in `Lght` chunk "<<nfo.id);
}
SkipSpaces(rgb+10,&rgb);
msh.angle = fast_atof(&rgb);
SkipSpaces(&rgb);
if (strncmp(rgb,"inner angle",11)) {
LogWarn_Ascii(splitter,format()<<
"Expected `inner angle` entity in `color` line in `Lght` chunk "<<nfo.id);
}
SkipSpaces(rgb+11,&rgb);
msh.inner_angle = fast_atof(&rgb);
// skip the rest for we can't handle this kind of physically-based lighting information.
}
// ------------------------------------------------------------------------------------------------
void COBImporter::ReadCame_Ascii(Scene& out, LineSplitter& splitter, const ChunkInfo& nfo)
{
if(nfo.version > 2) {
return UnsupportedChunk_Ascii(splitter,nfo,"Came");
}
out.nodes.push_back(boost::shared_ptr<Camera>(new Camera()));
Camera& msh = *dynamic_cast<Camera*>(out.nodes.back().get());
msh = nfo;
ReadBasicNodeInfo_Ascii(msh,++splitter,nfo);
// skip the next line, we don't know this differenciation between a
// standard camera and a panoramic camera.
++splitter;
}
// ------------------------------------------------------------------------------------------------
void COBImporter::ReadBone_Ascii(Scene& out, LineSplitter& splitter, const ChunkInfo& nfo)
{
if(nfo.version > 5) {
return UnsupportedChunk_Ascii(splitter,nfo,"Bone");
}
out.nodes.push_back(boost::shared_ptr<Bone>(new Bone()));
Bone& msh = *dynamic_cast<Bone*>(out.nodes.back().get());
msh = nfo;
ReadBasicNodeInfo_Ascii(msh,++splitter,nfo);
// TODO
}
// ------------------------------------------------------------------------------------------------
void COBImporter::ReadGrou_Ascii(Scene& out, LineSplitter& splitter, const ChunkInfo& nfo)
{
if(nfo.version > 1) {
return UnsupportedChunk_Ascii(splitter,nfo,"Grou");
}
out.nodes.push_back(boost::shared_ptr<Group>(new Group()));
Group& msh = *dynamic_cast<Group*>(out.nodes.back().get());
msh = nfo;
ReadBasicNodeInfo_Ascii(msh,++splitter,nfo);
}
// ------------------------------------------------------------------------------------------------
void COBImporter::ReadPolH_Ascii(Scene& out, LineSplitter& splitter, const ChunkInfo& nfo)
{
if(nfo.version > 8) {
return UnsupportedChunk_Ascii(splitter,nfo,"PolH");
}
out.nodes.push_back(boost::shared_ptr<Mesh>(new Mesh()));
Mesh& msh = *dynamic_cast<Mesh*>(out.nodes.back().get());
msh = nfo;
ReadBasicNodeInfo_Ascii(msh,++splitter,nfo);
// the chunk has a fixed order of components, but some are not interesting of us so
// we're just looking for keywords in arbitrary order. The end of the chunk is
// either the last `Face` or the `DrawFlags` attribute, depending on the format ver.
for(;splitter;++splitter) {
if (splitter.match_start("World Vertices")) {
const unsigned int cnt = strtol10(splitter[2]);
msh.vertex_positions.resize(cnt);
for(unsigned int cur = 0;cur < cnt && ++splitter;++cur) {
const char* s = splitter->c_str();
aiVector3D& v = msh.vertex_positions[cur];
SkipSpaces(&s);
v.x = fast_atof(&s);
SkipSpaces(&s);
v.y = fast_atof(&s);
SkipSpaces(&s);
v.z = fast_atof(&s);
}
}
else if (splitter.match_start("Texture Vertices")) {
const unsigned int cnt = strtol10(splitter[2]);
msh.texture_coords.resize(cnt);
for(unsigned int cur = 0;cur < cnt && ++splitter;++cur) {
const char* s = splitter->c_str();
aiVector2D& v = msh.texture_coords[cur];
SkipSpaces(&s);
v.x = fast_atof(&s);
SkipSpaces(&s);
v.y = fast_atof(&s);
}
}
else if (splitter.match_start("Faces")) {
const unsigned int cnt = strtol10(splitter[1]);
msh.faces.reserve(cnt);
for(unsigned int cur = 0; cur < cnt && ++splitter ;++cur) {
if (splitter.match_start("Hole")) {
LogWarn_Ascii(splitter,"Skipping unsupported `Hole` line");
continue;
}
if (!splitter.match_start("Face")) {
ThrowException("Expected Face line");
}
std::back_inserter(msh.faces) = Face();
Face& face = msh.faces.back();
face.indices.resize(strtol10(splitter[2]));
face.flags = strtol10(splitter[4]);
face.material = strtol10(splitter[6]);
const char* s = (++splitter)->c_str();
for(size_t i = 0; i < face.indices.size(); ++i) {
if(!SkipSpaces(&s)) {
ThrowException("Expected EOL token in Face entry");
}
if ('<' != *s++) {
ThrowException("Expected < token in Face entry");
}
face.indices[i].pos_idx = strtol10(s,&s);
if (',' != *s++) {
ThrowException("Expected , token in Face entry");
}
face.indices[i].uv_idx = strtol10(s,&s);
if ('>' != *s++) {
ThrowException("Expected < token in Face entry");
}
}
}
if (nfo.version <= 4) {
break;
}
}
else if (splitter.match_start("DrawFlags")) {
msh.draw_flags = strtol10(splitter[1]);
break;
}
}
}
// ------------------------------------------------------------------------------------------------
void COBImporter::ReadBitM_Ascii(Scene& out, LineSplitter& splitter, const ChunkInfo& nfo)
{
if(nfo.version > 1) {
return UnsupportedChunk_Ascii(splitter,nfo,"BitM");
}
/*
"\nThumbNailHdrSize %ld"
"\nThumbHeader: %02hx 02hx %02hx "
"\nColorBufSize %ld"
"\nColorBufZipSize %ld"
"\nZippedThumbnail: %02hx 02hx %02hx "
*/
const unsigned int head = strtol10((++splitter)[1]);
if (head != sizeof(Bitmap::BitmapHeader)) {
LogWarn_Ascii(splitter,"Unexpected ThumbNailHdrSize, skipping this chunk");
return;
}
//union {
// Bitmap::BitmapHeader data;
// char opaq[sizeof Bitmap::BitmapHeader];
//};
// ReadHexOctets(opaq,head,(++splitter)[1]);
}
// ------------------------------------------------------------------------------------------------
void COBImporter::ReadBinaryFile(Scene& out, StreamReaderLE* stream)
{
}
// ------------------------------------------------------------------------------------------------
void COBImporter::ReadPolH_Binary(COB::Scene& out, StreamReaderLE& reader)
{
}
// ------------------------------------------------------------------------------------------------
void COBImporter::ReadBitM_Binary(COB::Scene& out, StreamReaderLE& reader)
{
}
// ------------------------------------------------------------------------------------------------
void COBImporter::ReadMat1_Binary(COB::Scene& out, StreamReaderLE& reader)
{
}
// ------------------------------------------------------------------------------------------------
void COBImporter::ReadBone_Binary(COB::Scene& out, StreamReaderLE& reader)
{
}
// ------------------------------------------------------------------------------------------------
void COBImporter::ReadCame_Binary(COB::Scene& out, StreamReaderLE& reader)
{
}
// ------------------------------------------------------------------------------------------------
void COBImporter::ReadLght_Binary(COB::Scene& out, StreamReaderLE& reader)
{
}
// ------------------------------------------------------------------------------------------------
void COBImporter::ReadGrou_Binary(COB::Scene& out, StreamReaderLE& reader)
{
}
#endif

171
code/COBLoader.h 100644
View File

@ -0,0 +1,171 @@
/*
Open Asset Import Library (ASSIMP)
----------------------------------------------------------------------
Copyright (c) 2006-2008, ASSIMP Development Team
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.
* Neither the name of the ASSIMP team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the ASSIMP Development Team.
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 COBLoader.h
* @brief Declaration of the TrueSpace (*.cob,*.scn) importer class.
*/
#ifndef INCLUDED_AI_COB_LOADER_H
#define INCLUDED_AI_COB_LOADER_H
#include "BaseImporter.h"
namespace Assimp {
class LineSplitter;
// TinyFormatter.h
namespace Formatter {
template <typename T,typename TR, typename A> class basic_formatter;
typedef class basic_formatter< char, std::char_traits<char>, std::allocator<char> > format;
}
// COBScene.h
namespace COB {
struct ChunkInfo;
struct Node;
struct Scene;
}
// -------------------------------------------------------------------------------------------
/** Importer class to load TrueSpace files (cob,scn) up to v6.
*
* Currently relatively limited, loads only ASCII files and needs more test coverage. */
// -------------------------------------------------------------------------------------------
class COBImporter : public BaseImporter
{
friend class Importer;
protected:
/** Constructor to be privately used by Importer */
COBImporter();
/** Destructor, private as well */
~COBImporter();
public:
// --------------------
bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
bool checkSig) const;
protected:
// --------------------
void GetExtensionList(std::set<std::string>& app);
// --------------------
void SetupProperties(const Importer* pImp);
// --------------------
void InternReadFile( const std::string& pFile, aiScene* pScene,
IOSystem* pIOHandler);
private:
// -------------------------------------------------------------------
/** Prepend 'COB: ' and throw msg.*/
static void ThrowException(const std::string& msg);
// -------------------------------------------------------------------
/** @brief Read from an ascii scene/object file
* @param out Receives output data.
* @param stream Stream to read from. */
void ReadAsciiFile(COB::Scene& out, StreamReaderLE* stream);
// -------------------------------------------------------------------
/** @brief Read from a binary scene/object file
* @param out Receives output data.
* @param stream Stream to read from. */
void ReadBinaryFile(COB::Scene& out, StreamReaderLE* stream);
private:
// Conversion to Assimp output format
aiNode* BuildNodes(const COB::Node& root,const COB::Scene& scin,aiScene* fill);
private:
// ASCII file support
void UnsupportedChunk_Ascii(LineSplitter& splitter, const COB::ChunkInfo& nfo, const char* name);
void ReadChunkInfo_Ascii(COB::ChunkInfo& out, const LineSplitter& splitter);
void ReadBasicNodeInfo_Ascii(COB::Node& msh, LineSplitter& splitter, const COB::ChunkInfo& nfo);
template <typename T> void ReadFloat3Tuple_Ascii(T& fill, const char** in);
void ReadPolH_Ascii(COB::Scene& out, LineSplitter& splitter, const COB::ChunkInfo& nfo);
void ReadBitM_Ascii(COB::Scene& out, LineSplitter& splitter, const COB::ChunkInfo& nfo);
void ReadMat1_Ascii(COB::Scene& out, LineSplitter& splitter, const COB::ChunkInfo& nfo);
void ReadGrou_Ascii(COB::Scene& out, LineSplitter& splitter, const COB::ChunkInfo& nfo);
void ReadBone_Ascii(COB::Scene& out, LineSplitter& splitter, const COB::ChunkInfo& nfo);
void ReadCame_Ascii(COB::Scene& out, LineSplitter& splitter, const COB::ChunkInfo& nfo);
void ReadLght_Ascii(COB::Scene& out, LineSplitter& splitter, const COB::ChunkInfo& nfo);
void ReadUnit_Ascii(COB::Scene& out, LineSplitter& splitter, const COB::ChunkInfo& nfo);
void ReadChan_Ascii(COB::Scene& out, LineSplitter& splitter, const COB::ChunkInfo& nfo);
// ASCII file logging stuff to add proper line numbers to messages
static void LogWarn_Ascii (const LineSplitter& splitter, const Formatter::format& message);
static void LogError_Ascii(const LineSplitter& splitter, const Formatter::format& message);
static void LogInfo_Ascii (const LineSplitter& splitter, const Formatter::format& message);
static void LogDebug_Ascii(const LineSplitter& splitter, const Formatter::format& message);
static void LogWarn_Ascii (const std::string& message);
static void LogError_Ascii (const std::string& message);
static void LogInfo_Ascii (const std::string& message);
static void LogDebug_Ascii (const std::string& message);
// Binary file support
void ReadPolH_Binary(COB::Scene& out, StreamReaderLE& reader);
void ReadBitM_Binary(COB::Scene& out, StreamReaderLE& reader);
void ReadMat1_Binary(COB::Scene& out, StreamReaderLE& reader);
void ReadBone_Binary(COB::Scene& out, StreamReaderLE& reader);
void ReadCame_Binary(COB::Scene& out, StreamReaderLE& reader);
void ReadLght_Binary(COB::Scene& out, StreamReaderLE& reader);
void ReadGrou_Binary(COB::Scene& out, StreamReaderLE& reader);
}; // !class COBImporter
} // end of namespace Assimp
#endif // AI_UNREALIMPORTER_H_INC

249
code/COBScene.h 100644
View File

@ -0,0 +1,249 @@
/*
Open Asset Import Library (ASSIMP)
----------------------------------------------------------------------
Copyright (c) 2006-2008, ASSIMP Development Team
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.
* Neither the name of the ASSIMP team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the ASSIMP Development Team.
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 COBScene.h
* @brief Utilities for the COB importer.
*/
#ifndef INCLUDED_AI_COB_SCENE_H
#define INCLUDED_AI_COB_SCENE_H
#include <boost/shared_ptr.hpp>
#include "BaseImporter.h"
namespace Assimp {
namespace COB {
// ------------------
/** Represents a single vertex index in a face */
struct VertexIndex
{
// intentionally uninitialized
unsigned int pos_idx,uv_idx;
};
// ------------------
/** COB Face data structure */
struct Face
{
// intentionally uninitialized
unsigned int material, flags;
std::vector<VertexIndex> indices;
};
// ------------------
/** COB chunk header information */
struct ChunkInfo
{
enum {NO_SIZE=0xffffffff};
ChunkInfo ()
: id (0)
, parent_id (0)
, version (0)
, size (NO_SIZE)
{}
// Id of this chunk, unique within file
unsigned int id;
// and the corresponding parent
unsigned int parent_id;
// version. v1.23 becomes 123
unsigned int version;
// chunk size in bytes, only relevant for binary files
// NO_SIZE is also valid.
unsigned int size;
};
// ------------------
/** A node in the scenegraph */
struct Node : public ChunkInfo
{
enum Type {
TYPE_MESH,TYPE_GROUP,TYPE_LIGHT,TYPE_CAMERA,TYPE_BONE
};
virtual ~Node() {}
Node(Type type) : type(type), unit_scale(1.f){}
Type type;
// used during resolving
typedef std::deque<const Node*> ChildList;
mutable ChildList temp_children;
// unique name
std::string name;
// local mesh transformation
aiMatrix4x4 transform;
// scaling for this node to get to the metric system
float unit_scale;
};
// ------------------
/** COB Mesh data structure */
struct Mesh : public Node
{
using ChunkInfo::operator=;
enum DrawFlags {
SOLID = 0x1,
TRANS = 0x2,
WIRED = 0x4,
BBOX = 0x8,
HIDE = 0x10
};
Mesh()
: Node(TYPE_MESH)
, draw_flags(SOLID)
{}
// vertex elements
std::vector<aiVector2D> texture_coords;
std::vector<aiVector3D> vertex_positions;
// face data
std::vector<Face> faces;
// misc. drawing flags
unsigned int draw_flags;
// used during resolving
typedef std::deque<Face*> FaceRefList;
typedef std::map< unsigned int,FaceRefList > TempMap;
TempMap temp_map;
};
// ------------------
/** COB Group data structure */
struct Group : public Node
{
using ChunkInfo::operator=;
Group() : Node(TYPE_GROUP) {}
};
// ------------------
/** COB Bone data structure */
struct Bone : public Node
{
using ChunkInfo::operator=;
Bone() : Node(TYPE_BONE) {}
};
// ------------------
/** COB Light data structure */
struct Light : public Node
{
enum LightType {
SPOT,LOCAL,INFINITE
};
using ChunkInfo::operator=;
Light() : Node(TYPE_LIGHT),angle(),inner_angle(),ltype(SPOT) {}
aiColor3D color;
float angle,inner_angle;
LightType ltype;
};
// ------------------
/** COB Camera data structure */
struct Camera : public Node
{
using ChunkInfo::operator=;
Camera() : Node(TYPE_CAMERA) {}
};
// ------------------
/** COB Material data structure */
struct Material : ChunkInfo
{
using ChunkInfo::operator=;
enum Shader {
FLAT,PHONG,METAL
};
Material() : alpha(),exp(),ior(),ka(),ks(1.f),matnum(0xffffffff),shader(FLAT) {}
std::string type;
aiColor3D rgb;
float alpha, exp, ior,ka,ks;
unsigned int matnum;
Shader shader;
};
// ------------------
/** Embedded bitmap, for instance for the thumbnail image */
struct Bitmap : ChunkInfo
{
Bitmap() : orig_size() {}
struct BitmapHeader
{
};
BitmapHeader head;
size_t orig_size;
std::vector<char> buff_zipped;
};
typedef std::deque< boost::shared_ptr<Node> > NodeList;
typedef std::vector< Material > MaterialList;
// ------------------
/** Represents a master COB scene, even if we loaded just a single COB file */
struct Scene
{
NodeList nodes;
MaterialList materials;
// becomes *0 later
Bitmap thumbnail;
};
} // end COB
} // end Assimp
#endif

View File

@ -164,6 +164,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef AI_BUILD_NO_MS3D_IMPORTER #ifndef AI_BUILD_NO_MS3D_IMPORTER
# include "MS3DLoader.h" # include "MS3DLoader.h"
#endif #endif
#ifndef AI_BUILD_NO_COB_IMPORTER
# include "COBLoader.h"
#endif
// ....................................................................................... // .......................................................................................
// PostProcess-Steps // PostProcess-Steps
@ -278,7 +281,7 @@ Importer::Importer()
// Add an instance of each worker class here // Add an instance of each worker class here
// (register_new_importers_here) // (register_new_importers_here)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
pimpl->mImporter.reserve(25); pimpl->mImporter.reserve(64);
#if (!defined AI_BUILD_NO_X_IMPORTER) #if (!defined AI_BUILD_NO_X_IMPORTER)
pimpl->mImporter.push_back( new XFileImporter()); pimpl->mImporter.push_back( new XFileImporter());
#endif #endif
@ -372,7 +375,9 @@ Importer::Importer()
#if (!defined AI_BUILD_NO_MS3D_IMPORTER) #if (!defined AI_BUILD_NO_MS3D_IMPORTER)
pimpl->mImporter.push_back( new MS3DImporter()); pimpl->mImporter.push_back( new MS3DImporter());
#endif #endif
#if (!defined AI_BUILD_NO_COB_IMPORTER)
pimpl->mImporter.push_back( new COBImporter());
#endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Add an instance of each post processing step here in the order // Add an instance of each post processing step here in the order

217
code/LineSplitter.h 100644
View File

@ -0,0 +1,217 @@
/*
Open Asset Import Library (ASSIMP)
----------------------------------------------------------------------
Copyright (c) 2006-2008, ASSIMP Development Team
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.
* Neither the name of the ASSIMP team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the ASSIMP Development Team.
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 LineSplitter.h
* @brief LineSplitter, a helper class to iterate through all lines
* of a file easily. Works with StreamReader.
*/
#ifndef INCLUDED_LINE_SPLITTER_H
#define INCLUDED_LINE_SPLITTER_H
#include <stdexcept>
#include "StreamReader.h"
#include "ParsingUtils.h"
namespace Assimp {
// ------------------------------------------------------------------------------------------------
/** Usage:
@code
for(LineSplitter splitter(stream);splitter;++splitter) {
if (*splitter == "hi!") {
...
}
else if (splitter->substr(0,5) == "hello") {
...
// access the third token in the line (tokens are space-separated)
if (strtol(splitter[2]) > 5) { .. }
}
std::cout << "Current line is: " << splitter.get_index() << std::endl;
}
@endcode */
// ------------------------------------------------------------------------------------------------
class LineSplitter
{
public:
typedef size_t line_idx;
public:
// -----------------------------------------
/** construct from existing stream reader */
LineSplitter(StreamReaderLE& stream)
: stream(stream)
, swallow()
{
cur.reserve(1024);
operator++();
idx = 0;
}
public:
// -----------------------------------------
/** pseudo-iterator increment */
LineSplitter& operator++() {
if(swallow) {
swallow = false;
return *this;
}
if (!*this) {
throw std::logic_error("End of file, no more lines to be retrieved.");
}
char s;
cur.clear(); // I will kill you if you deallocate.
while(stream.GetRemainingSize() && (s = stream.GetI1(),1)) {
if (s == '\n' || s == '\r') {
while (stream.GetRemainingSize() && ((s = stream.GetI1()) == ' ' || s == '\r' || s == '\n'));
if (stream.GetRemainingSize()) {
stream.IncPtr(-1);
}
break;
}
cur += s;
}
++idx;
return *this;
}
// -----------------------------------------
/** get a pointer to the beginning of a particular token */
const char* operator[] (size_t idx) const {
const char* s = operator->()->c_str();
SkipSpaces(&s);
for(size_t i = 0; i < idx; ++i) {
for(;!IsSpace(*s); ++s) {
if(IsLineEnd(*s)) {
throw std::range_error("Token index out of range, EOL reached");
}
}
SkipSpaces(&s);
}
return s;
}
// -----------------------------------------
/** extract the start positions of N tokens from the current line*/
template <size_t N>
void get_tokens(const char* (&tokens)[N]) const {
const char* s = operator->()->c_str();
SkipSpaces(&s);
for(size_t i = 0; i < N; ++i) {
if(IsLineEnd(*s)) {
throw std::range_error("Token count out of range, EOL reached");
}
tokens[i] = s;
for(;*s && !IsSpace(*s); ++s);
SkipSpaces(&s);
}
}
// -----------------------------------------
/** member access */
const std::string* operator -> () const {
return &cur;
}
const std::string& operator* () const {
return cur;
}
// -----------------------------------------
/** boolean context */
operator bool() const {
return stream.GetRemainingSize()>0;
}
// -----------------------------------------
/** line indices are zero-based, empty lines are included */
operator line_idx() const {
return idx;
}
line_idx get_index() const {
return idx;
}
// -----------------------------------------
/** access the underlying stream object */
StreamReaderLE& get_stream() {
return stream;
}
// -----------------------------------------
/** !strcmp((*this)->substr(0,strlen(check)),check) */
bool match_start(const char* check) {
const size_t len = strlen(check);
return len <= cur.length() && std::equal(check,check+len,cur.begin());
}
// -----------------------------------------
/** swallow the next call to ++, return the previous value. */
void swallow_next_increment() {
swallow = true;
}
private:
line_idx idx;
std::string cur;
StreamReaderLE& stream;
bool swallow;
};
}
#endif // INCLUDED_LINE_SPLITTER_H

View File

@ -178,7 +178,7 @@ public:
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
/** Increase the file pointer (relative seeking) */ /** Increase the file pointer (relative seeking) */
void IncPtr(unsigned int plus) { void IncPtr(int plus) {
current += plus; current += plus;
if (current > end) { if (current > end) {
throw DeadlyImportError("End of file was reached"); throw DeadlyImportError("End of file was reached");

View File

@ -92,7 +92,7 @@ public:
public: public:
operator string () { operator string () const {
return underlying.str(); return underlying.str();
} }

View File

@ -274,7 +274,6 @@ inline const char* fast_atof_move( const char* c, float& out)
return c; return c;
} }
// ------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------
// The same but more human. // The same but more human.
inline float fast_atof(const char* c) inline float fast_atof(const char* c)
@ -284,6 +283,23 @@ inline float fast_atof(const char* c)
return ret; return ret;
} }
inline float fast_atof( const char* c, const char** cout)
{
float ret;
*cout = fast_atof_move(c, ret);
return ret;
}
inline float fast_atof( const char** inout)
{
float ret;
*inout = fast_atof_move(*inout, ret);
return ret;
}
} // end of namespace Assimp } // end of namespace Assimp
#endif #endif

View File

@ -59,6 +59,7 @@ struct aiColor4D
aiColor4D () : r(0.0f), g(0.0f), b(0.0f), a(0.0f) {} aiColor4D () : r(0.0f), g(0.0f), b(0.0f), a(0.0f) {}
aiColor4D (float _r, float _g, float _b, float _a) aiColor4D (float _r, float _g, float _b, float _a)
: r(_r), g(_g), b(_b), a(_a) {} : r(_r), g(_g), b(_b), a(_a) {}
aiColor4D (float _r) : r(_r), g(_r), b(_r), a(_r) {}
aiColor4D (const aiColor4D& o) aiColor4D (const aiColor4D& o)
: r(o.r), g(o.g), b(o.b), a(o.a) {} : r(o.r), g(o.g), b(o.b), a(o.a) {}

View File

@ -153,6 +153,7 @@ struct aiColor3D
#ifdef __cplusplus #ifdef __cplusplus
aiColor3D () : r(0.0f), g(0.0f), b(0.0f) {} aiColor3D () : r(0.0f), g(0.0f), b(0.0f) {}
aiColor3D (float _r, float _g, float _b) : r(_r), g(_g), b(_b) {} aiColor3D (float _r, float _g, float _b) : r(_r), g(_g), b(_b) {}
aiColor3D (float _r) : r(_r), g(_r), b(_r) {}
aiColor3D (const aiColor3D& o) : r(o.r), g(o.g), b(o.b) {} aiColor3D (const aiColor3D& o) : r(o.r), g(o.g), b(o.b) {}
/** Component-wise comparison */ /** Component-wise comparison */

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -31,6 +31,9 @@ def process_dir(thisdir):
res += process_dir(fullpath) res += process_dir(fullpath)
continue continue
# import twice, importing the same file again introduces extra risk
# to crash due to garbage data lying around in the importer.
command.append(fullpath)
command.append(fullpath) command.append(fullpath)
if len(command)>2: if len(command)>2:

View File

@ -1149,46 +1149,6 @@
> >
</File> </File>
</Filter> </Filter>
<Filter
Name="BoostWorkaround"
>
<File
RelativePath="..\..\include\BoostWorkaround\boost\foreach.hpp"
>
</File>
<File
RelativePath="..\..\include\BoostWorkaround\boost\format.hpp"
>
</File>
<File
RelativePath="..\..\include\BoostWorkaround\boost\scoped_array.hpp"
>
</File>
<File
RelativePath="..\..\include\BoostWorkaround\boost\scoped_ptr.hpp"
>
</File>
<File
RelativePath="..\..\include\BoostWorkaround\boost\static_assert.hpp"
>
</File>
<Filter
Name="tuple"
>
<File
RelativePath="..\..\include\BoostWorkaround\boost\tuple\tuple.hpp"
>
</File>
</Filter>
<Filter
Name="math"
>
<File
RelativePath="..\..\include\BoostWorkaround\boost\math\common_factor_rt.hpp"
>
</File>
</Filter>
</Filter>
<Filter <Filter
Name="C" Name="C"
> >
@ -1503,6 +1463,10 @@
<Filter <Filter
Name="lwo" Name="lwo"
> >
<File
RelativePath="..\..\code\IFF.h"
>
</File>
<File <File
RelativePath="..\..\code\LWOBLoader.cpp" RelativePath="..\..\code\LWOBLoader.cpp"
> >
@ -2000,6 +1964,22 @@
> >
</File> </File>
</Filter> </Filter>
<Filter
Name="cob"
>
<File
RelativePath="..\..\code\COBLoader.cpp"
>
</File>
<File
RelativePath="..\..\code\COBLoader.h"
>
</File>
<File
RelativePath="..\..\code\COBScene.h"
>
</File>
</Filter>
</Filter> </Filter>
<Filter <Filter
Name="process" Name="process"
@ -3557,11 +3537,11 @@
> >
</File> </File>
<File <File
RelativePath="..\..\code\IFF.h" RelativePath="..\..\code\Importer.cpp"
> >
</File> </File>
<File <File
RelativePath="..\..\code\Importer.cpp" RelativePath="..\..\code\LineSplitter.h"
> >
</File> </File>
<File <File
@ -3668,6 +3648,10 @@
RelativePath="..\..\code\TargetAnimation.h" RelativePath="..\..\code\TargetAnimation.h"
> >
</File> </File>
<File
RelativePath="..\..\code\TinyFormatter.h"
>
</File>
<File <File
RelativePath="..\..\code\VertexTriangleAdjacency.cpp" RelativePath="..\..\code\VertexTriangleAdjacency.cpp"
> >
@ -3677,6 +3661,42 @@
> >
</File> </File>
</Filter> </Filter>
<Filter
Name="noboost"
>
<File
RelativePath="..\..\code\BoostWorkaround\boost\math\common_factor_rt.hpp"
>
</File>
<File
RelativePath="..\..\code\BoostWorkaround\boost\foreach.hpp"
>
</File>
<File
RelativePath="..\..\code\BoostWorkaround\boost\format.hpp"
>
</File>
<File
RelativePath="..\..\code\BoostWorkaround\boost\scoped_array.hpp"
>
</File>
<File
RelativePath="..\..\code\BoostWorkaround\boost\scoped_ptr.hpp"
>
</File>
<File
RelativePath="..\..\code\BoostWorkaround\boost\shared_ptr.hpp"
>
</File>
<File
RelativePath="..\..\code\BoostWorkaround\boost\static_assert.hpp"
>
</File>
<File
RelativePath="..\..\code\BoostWorkaround\boost\tuple\tuple.hpp"
>
</File>
</Filter>
</Filter> </Filter>
<Filter <Filter
Name="doc" Name="doc"

View File

@ -1139,6 +1139,10 @@
RelativePath="..\..\code\BoostWorkaround\boost\scoped_ptr.hpp" RelativePath="..\..\code\BoostWorkaround\boost\scoped_ptr.hpp"
> >
</File> </File>
<File
RelativePath="..\..\code\BoostWorkaround\boost\shared_ptr.hpp"
>
</File>
<File <File
RelativePath="..\..\code\BoostWorkaround\boost\static_assert.hpp" RelativePath="..\..\code\BoostWorkaround\boost\static_assert.hpp"
> >
@ -1739,10 +1743,6 @@
> >
</File> </File>
</Filter> </Filter>
<Filter
Name="vrml97"
>
</Filter>
<Filter <Filter
Name="off" Name="off"
> >
@ -1971,6 +1971,22 @@
> >
</File> </File>
</Filter> </Filter>
<Filter
Name="cob"
>
<File
RelativePath="..\..\code\COBLoader.cpp"
>
</File>
<File
RelativePath="..\..\code\COBLoader.h"
>
</File>
<File
RelativePath="..\..\code\COBScene.h"
>
</File>
</Filter>
</Filter> </Filter>
<Filter <Filter
Name="process" Name="process"
@ -2347,6 +2363,10 @@
RelativePath="..\..\code\Importer.cpp" RelativePath="..\..\code\Importer.cpp"
> >
</File> </File>
<File
RelativePath="..\..\code\LineSplitter.h"
>
</File>
<File <File
RelativePath="..\..\code\MaterialSystem.cpp" RelativePath="..\..\code\MaterialSystem.cpp"
> >
@ -2435,6 +2455,10 @@
RelativePath="..\..\code\TargetAnimation.h" RelativePath="..\..\code\TargetAnimation.h"
> >
</File> </File>
<File
RelativePath="..\..\code\TinyFormatter.h"
>
</File>
<File <File
RelativePath="..\..\code\VertexTriangleAdjacency.cpp" RelativePath="..\..\code\VertexTriangleAdjacency.cpp"
> >