Ejemplo n.º 1
0
// ------------------------------------------------------------------------------------------------
void COBImporter::ReadBitM_Binary(COB::Scene& /*out*/, StreamReaderLE& reader, const ChunkInfo& nfo)
{
    if(nfo.version > 1) {
        return UnsupportedChunk_Binary(reader,nfo,"BitM");
    }

    const chunk_guard cn(nfo,reader);

    const uint32_t len = reader.GetI4();
    reader.IncPtr(len);

    reader.GetI4();
    reader.IncPtr(reader.GetI4());
}
Ejemplo n.º 2
0
// ------------------------------------------------------------------------------------------------
void COBImporter::ReadBasicNodeInfo_Binary(Node& msh, StreamReaderLE& reader, const ChunkInfo& /*nfo*/)
{
    const unsigned int dupes = reader.GetI2();
    ReadString_Binary(msh.name,reader);

    msh.name = format(msh.name)<<'_'<<dupes;

    // skip local axes for the moment
    reader.IncPtr(48);

    msh.transform = aiMatrix4x4();
    for(unsigned int y = 0; y < 3; ++y) {
        for(unsigned int x =0; x < 4; ++x) {
            msh.transform[y][x] = reader.GetF4();
        }
    }
}
Ejemplo n.º 3
0
// ------------------------------------------------------------------------------------------------
void COBImporter::UnsupportedChunk_Binary( StreamReaderLE& reader, const ChunkInfo& nfo, const char* name)
{
    const std::string error = format("Encountered unsupported chunk: ") <<  name <<
        " [version: "<<nfo.version<<", size: "<<nfo.size<<"]";

    // we can recover if the chunk size was specified.
    if(nfo.size != static_cast<unsigned int>(-1)) {
        DefaultLogger::get()->error(error);
        reader.IncPtr(nfo.size);
    }
    else ThrowException(error);
}
Ejemplo n.º 4
0
// ------------------------------------------------------------------------------------------------
void COBImporter::ReadCame_Binary(COB::Scene& out, StreamReaderLE& reader, const ChunkInfo& nfo)
{
    if(nfo.version > 2) {
        return UnsupportedChunk_Binary(reader,nfo,"Came");
    }

    const chunk_guard cn(nfo,reader);

    out.nodes.push_back(std::shared_ptr<Camera>(new Camera()));
    Camera& msh = (Camera&)(*out.nodes.back().get());
    msh = nfo;

    ReadBasicNodeInfo_Binary(msh,reader,nfo);

    // the rest is not interesting for us, so we skip over it.
    if(nfo.version > 1) {
        if (reader.GetI2()==512) {
            reader.IncPtr(42);
        }
    }
}
Ejemplo n.º 5
0
// ------------------------------------------------------------------------------------------------
void COBImporter::ReadUnit_Binary(COB::Scene& out, StreamReaderLE& reader, const ChunkInfo& nfo)
{
     if(nfo.version > 1) {
        return UnsupportedChunk_Binary(reader,nfo,"Unit");
    }

     const chunk_guard cn(nfo,reader);

    // parent chunks preceede their childs, so we should have the
    // corresponding chunk already.
    for(std::shared_ptr< Node >& nd : out.nodes) {
        if (nd->id == nfo.parent_id) {
            const unsigned int t=reader.GetI2();
            nd->unit_scale = t>=sizeof(units)/sizeof(units[0])?(
                ASSIMP_LOG_WARN_F(t," is not a valid value for `Units` attribute in `Unit chunk` ", nfo.id)
                ,1.f):units[t];

            return;
        }
    }
    ASSIMP_LOG_WARN_F( "`Unit` chunk ", nfo.id, " is a child of ", nfo.parent_id, " which does not exist");
}
Ejemplo n.º 6
0
 chunk_guard(const COB::ChunkInfo& nfo, StreamReaderLE& reader)
     : nfo(nfo)
     , reader(reader)
     , cur(reader.GetCurrentPos())
 {
 }
Ejemplo n.º 7
0
// ------------------------------------------------------------------------------------------------
void COBImporter::ReadMat1_Binary(COB::Scene& out, StreamReaderLE& reader, const ChunkInfo& nfo)
{
    if(nfo.version > 8) {
        return UnsupportedChunk_Binary(reader,nfo,"Mat1");
    }

    const chunk_guard cn(nfo,reader);

    out.materials.push_back(Material());
    Material& mat = out.materials.back();
    mat = nfo;

    mat.matnum = reader.GetI2();
    switch(reader.GetI1()) {
        case 'f':
            mat.type = Material::FLAT;
            break;
        case 'p':
            mat.type = Material::PHONG;
            break;
        case 'm':
            mat.type = Material::METAL;
            break;
        default:
            LogError_Ascii(format("Unrecognized shader type in `Mat1` chunk with id ")<<nfo.id);
            mat.type = Material::FLAT;
    }

    switch(reader.GetI1()) {
        case 'f':
            mat.autofacet = Material::FACETED;
            break;
        case 'a':
            mat.autofacet = Material::AUTOFACETED;
            break;
        case 's':
            mat.autofacet = Material::SMOOTH;
            break;
        default:
            LogError_Ascii(format("Unrecognized faceting mode in `Mat1` chunk with id ")<<nfo.id);
            mat.autofacet = Material::FACETED;
    }
    mat.autofacet_angle = static_cast<float>(reader.GetI1());

    mat.rgb.r = reader.GetF4();
    mat.rgb.g = reader.GetF4();
    mat.rgb.b = reader.GetF4();

    mat.alpha = reader.GetF4();
    mat.ka    = reader.GetF4();
    mat.ks    = reader.GetF4();
    mat.exp   = reader.GetF4();
    mat.ior   = reader.GetF4();

    char id[2];
    id[0] = reader.GetI1(),id[1] = reader.GetI1();

    if (id[0] == 'e' && id[1] == ':') {
        mat.tex_env.reset(new Texture());

        reader.GetI1();
        ReadString_Binary(mat.tex_env->path,reader);

        // advance to next texture-id
        id[0] = reader.GetI1(),id[1] = reader.GetI1();
    }

    if (id[0] == 't' && id[1] == ':') {
        mat.tex_color.reset(new Texture());

        reader.GetI1();
        ReadString_Binary(mat.tex_color->path,reader);

        mat.tex_color->transform.mTranslation.x = reader.GetF4();
        mat.tex_color->transform.mTranslation.y = reader.GetF4();

        mat.tex_color->transform.mScaling.x = reader.GetF4();
        mat.tex_color->transform.mScaling.y = reader.GetF4();

        // advance to next texture-id
        id[0] = reader.GetI1(),id[1] = reader.GetI1();
    }

    if (id[0] == 'b' && id[1] == ':') {
        mat.tex_bump.reset(new Texture());

        reader.GetI1();
        ReadString_Binary(mat.tex_bump->path,reader);

        mat.tex_bump->transform.mTranslation.x = reader.GetF4();
        mat.tex_bump->transform.mTranslation.y = reader.GetF4();

        mat.tex_bump->transform.mScaling.x = reader.GetF4();
        mat.tex_bump->transform.mScaling.y = reader.GetF4();

        // skip amplitude for I don't know its purpose.
        reader.GetF4();
    }
    reader.IncPtr(-2);
}
Ejemplo n.º 8
0
// ------------------------------------------------------------------------------------------------
void COBImporter::ReadPolH_Binary(COB::Scene& out, StreamReaderLE& reader, const ChunkInfo& nfo)
{
    if(nfo.version > 8) {
        return UnsupportedChunk_Binary(reader,nfo,"PolH");
    }
    const chunk_guard cn(nfo,reader);

    out.nodes.push_back(std::shared_ptr<Mesh>(new Mesh()));
    Mesh& msh = (Mesh&)(*out.nodes.back().get());
    msh = nfo;

    ReadBasicNodeInfo_Binary(msh,reader,nfo);

    msh.vertex_positions.resize(reader.GetI4());
    for(aiVector3D& v : msh.vertex_positions) {
        v.x = reader.GetF4();
        v.y = reader.GetF4();
        v.z = reader.GetF4();
    }

    msh.texture_coords.resize(reader.GetI4());
    for(aiVector2D& v : msh.texture_coords) {
        v.x = reader.GetF4();
        v.y = reader.GetF4();
    }

    const size_t numf = reader.GetI4();
    msh.faces.reserve(numf);
    for(size_t i = 0; i < numf; ++i) {
        // XXX backface culling flag is 0x10 in flags

        // hole?
        bool hole;
        if ((hole = (reader.GetI1() & 0x08) != 0)) {
            // XXX Basically this should just work fine - then triangulator
            // should output properly triangulated data even for polygons
            // with holes. Test data specific to COB is needed to confirm it.
            if (msh.faces.empty()) {
                ThrowException(format("A hole is the first entity in the `PolH` chunk with id ") << nfo.id);
            }
        }
        else msh.faces.push_back(Face());
        Face& f = msh.faces.back();

        const size_t num = reader.GetI2();
        f.indices.reserve(f.indices.size() + num);

        if(!hole) {
            f.material = reader.GetI2();
            f.flags = 0;
        }

        for(size_t x = 0; x < num; ++x) {
            f.indices.push_back(VertexIndex());

            VertexIndex& v = f.indices.back();
            v.pos_idx = reader.GetI4();
            v.uv_idx = reader.GetI4();
        }

        if(hole) {
            std::reverse(f.indices.rbegin(),f.indices.rbegin()+num);
        }
    }
    if (nfo.version>4) {
        msh.draw_flags = reader.GetI4();
    }
    nfo.version>5 && nfo.version<8 ? reader.GetI4() : 0;
}