// ------------------------------------------------------------------------------------------------ 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; } } }
// ------------------------------------------------------------------------------------------------ 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(std::shared_ptr<Mesh>(new Mesh())); Mesh& msh = (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 = strtoul10(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 = strtoul10(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 = strtoul10(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"); } msh.faces.push_back(Face()); Face& face = msh.faces.back(); face.indices.resize(strtoul10(splitter[2])); face.flags = strtoul10(splitter[4]); face.material = strtoul10(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 = strtoul10(s,&s); if (',' != *s++) { ThrowException("Expected , token in Face entry"); } face.indices[i].uv_idx = strtoul10(s,&s); if ('>' != *s++) { ThrowException("Expected < token in Face entry"); } } } if (nfo.version <= 4) { break; } } else if (splitter.match_start("DrawFlags")) { msh.draw_flags = strtoul10(splitter[1]); break; } } }