@@ -260,7 +260,7 @@ typedef struct {
260260typedef struct {
261261 // Linear flattened indices.
262262 std::vector<index_t > indices; // indices for vertices(poly lines)
263- std::vector<int > num_line_vertces ; // The number of vertices per line.
263+ std::vector<int > num_line_vertices ; // The number of vertices per line.
264264} lines_t ;
265265
266266typedef struct {
@@ -592,6 +592,10 @@ struct PrimGroup {
592592 pointGroup.clear ();
593593 }
594594
595+ bool IsEmpty () const {
596+ return faceGroup.empty () && lineGroup.empty () && pointGroup.empty ();
597+ }
598+
595599 // TODO(syoyo): bspline, surface, ...
596600};
597601
@@ -1221,10 +1225,13 @@ static bool exportGroupsToShape(shape_t *shape, const PrimGroup &prim_group,
12211225 const int material_id, const std::string &name,
12221226 bool triangulate,
12231227 const std::vector<real_t > &v) {
1224- if (prim_group.faceGroup . empty () && prim_group. lineGroup . empty ()) {
1228+ if (prim_group.IsEmpty ()) {
12251229 return false ;
12261230 }
12271231
1232+ shape->name = name;
1233+
1234+ // polygon
12281235 if (!prim_group.faceGroup .empty ()) {
12291236 // Flatten vertices and indices
12301237 for (size_t i = 0 ; i < prim_group.faceGroup .size (); i++) {
@@ -1464,13 +1471,28 @@ static bool exportGroupsToShape(shape_t *shape, const PrimGroup &prim_group,
14641471 }
14651472 }
14661473
1467- shape->name = name;
14681474 shape->mesh .tags = tags;
14691475 }
14701476
1471- // if (!lineGroup.empty()) {
1472- // shape->lines.indices.swap(lineGroup);
1473- // }
1477+ // line
1478+ if (!prim_group.lineGroup .empty ()) {
1479+ // Flatten indices
1480+ for (size_t i = 0 ; i < prim_group.lineGroup .size (); i++) {
1481+ for (size_t j = 0 ; j < prim_group.lineGroup [i].vertex_indices .size (); j++) {
1482+
1483+ const vertex_index_t &vi = prim_group.lineGroup [i].vertex_indices [j];
1484+
1485+ index_t idx;
1486+ idx.vertex_index = vi.v_idx ;
1487+ idx.normal_index = vi.vn_idx ;
1488+ idx.texcoord_index = vi.vt_idx ;
1489+
1490+ shape->lines .indices .push_back (idx);
1491+ }
1492+
1493+ shape->lines .num_line_vertices .push_back (int (prim_group.lineGroup [i].vertex_indices .size ()));
1494+ }
1495+ }
14741496
14751497 return true ;
14761498}
0 commit comments