// ------------------------------------------------------------------------------------------------ void DXFImporter::Parse3DFace(DXF::LineReader& reader, DXF::FileData& output) { // (note) this is also used for for parsing line entities, so we // must handle the vertex_count == 2 case as well. output.blocks.back().lines.push_back( std::shared_ptr<DXF::PolyLine>( new DXF::PolyLine() ) ); DXF::PolyLine& line = *output.blocks.back().lines.back(); aiVector3D vip[4]; aiColor4D clr = AI_DXF_DEFAULT_COLOR; bool b[4] = {false,false,false,false}; while( !reader.End() ) { // next entity with a groupcode == 0 is probably already the next vertex or polymesh entity if (reader.GroupCode() == 0) { break; } switch (reader.GroupCode()) { // 8 specifies the layer case 8: line.layer = reader.Value(); break; // x position of the first corner case 10: vip[0].x = reader.ValueAsFloat(); b[2] = true; break; // y position of the first corner case 20: vip[0].y = reader.ValueAsFloat(); b[2] = true; break; // z position of the first corner case 30: vip[0].z = reader.ValueAsFloat(); b[2] = true; break; // x position of the second corner case 11: vip[1].x = reader.ValueAsFloat(); b[3] = true; break; // y position of the second corner case 21: vip[1].y = reader.ValueAsFloat(); b[3] = true; break; // z position of the second corner case 31: vip[1].z = reader.ValueAsFloat(); b[3] = true; break; // x position of the third corner case 12: vip[2].x = reader.ValueAsFloat(); b[0] = true; break; // y position of the third corner case 22: vip[2].y = reader.ValueAsFloat(); b[0] = true; break; // z position of the third corner case 32: vip[2].z = reader.ValueAsFloat(); b[0] = true; break; // x position of the fourth corner case 13: vip[3].x = reader.ValueAsFloat(); b[1] = true; break; // y position of the fourth corner case 23: vip[3].y = reader.ValueAsFloat(); b[1] = true; break; // z position of the fourth corner case 33: vip[3].z = reader.ValueAsFloat(); b[1] = true; break; // color case 62: clr = g_aclrDxfIndexColors[reader.ValueAsUnsignedInt() % AI_DXF_NUM_INDEX_COLORS]; break; }; ++reader; } // the fourth corner may even be identical to the third, // in this case we treat it as if it didn't exist. if (vip[3] == vip[2]) { b[1] = false; } // sanity checks to see if we got something meaningful if ((b[1] && !b[0]) || !b[2] || !b[3]) { DefaultLogger::get()->warn("DXF: unexpected vertex setup in 3DFACE/LINE/FACE entity; ignoring"); output.blocks.back().lines.pop_back(); return; } const unsigned int cnt = (2+(b[0]?1:0)+(b[1]?1:0)); line.counts.push_back(cnt); for (unsigned int i = 0; i < cnt; ++i) { line.indices.push_back(static_cast<unsigned int>(line.positions.size())); line.positions.push_back(vip[i]); line.colors.push_back(clr); } }
// ------------------------------------------------------------------------------------------------ void DXFImporter::ParsePolyLineVertex(DXF::LineReader& reader, DXF::PolyLine& line) { unsigned int cnti = 0, flags = 0; unsigned int indices[4]; aiVector3D out; aiColor4D clr = AI_DXF_DEFAULT_COLOR; while( !reader.End() ) { if (reader.Is(0)) { // SEQEND or another VERTEX break; } switch (reader.GroupCode()) { case 8: // layer to which the vertex belongs to - assume that // this is always the layer the top-level polyline // entity resides on as well. if(reader.Value() != line.layer) { DefaultLogger::get()->warn("DXF: expected vertex to be part of a polyface but the 0x128 flag isn't set"); } break; case 70: flags = reader.ValueAsUnsignedInt(); break; // VERTEX COORDINATES case 10: out.x = reader.ValueAsFloat();break; case 20: out.y = reader.ValueAsFloat();break; case 30: out.z = reader.ValueAsFloat();break; // POLYFACE vertex indices case 71: case 72: case 73: case 74: if (cnti == 4) { DefaultLogger::get()->warn("DXF: more than 4 indices per face not supported; ignoring"); break; } indices[cnti++] = reader.ValueAsUnsignedInt(); break; // color case 62: clr = g_aclrDxfIndexColors[reader.ValueAsUnsignedInt() % AI_DXF_NUM_INDEX_COLORS]; break; }; reader++; } if (line.flags & DXF_POLYLINE_FLAG_POLYFACEMESH && !(flags & DXF_VERTEX_FLAG_PART_OF_POLYFACE)) { DefaultLogger::get()->warn("DXF: expected vertex to be part of a polyface but the 0x128 flag isn't set"); } if (cnti) { line.counts.push_back(cnti); for (unsigned int i = 0; i < cnti; ++i) { // IMPORTANT NOTE: POLYMESH indices are ONE-BASED if (indices[i] == 0) { DefaultLogger::get()->warn("DXF: invalid vertex index, indices are one-based."); --line.counts.back(); continue; } line.indices.push_back(indices[i]-1); } } else { line.positions.push_back(out); line.colors.push_back(clr); } }