@@ -24,6 +24,8 @@ THE SOFTWARE.
2424
2525//
2626// version 2.0.0 : Add new object oriented API. 1.x API is still provided.
27+ // * Support line primitive.
28+ // * Support points primitive.
2729// version 1.4.0 : Modifed ParseTextureNameAndOption API
2830// version 1.3.1 : Make ParseTextureNameAndOption API public
2931// version 1.3.0 : Separate warning and error message(breaking API of LoadObj)
@@ -410,13 +412,20 @@ class ObjReader {
410412 // /
411413 // / Load .obj and .mtl from a file.
412414 // /
415+ // / @param[in] filename wavefront .obj filename
416+ // / @param[in] config Reader configuration
417+ // /
413418 bool ParseFromFile (const std::string &filename, const ObjReaderConfig &config);
414419
415420 // /
416421 // / Parse .obj from a text string.
417422 // / Need to supply .mtl text string by `mtl_text`.
418423 // / This function ignores `mtllib` line in .obj text.
419424 // /
425+ // / @param[in] obj_text wavefront .obj filename
426+ // / @param[in] mtl_text wavefront .mtl filename
427+ // / @param[in] config Reader configuration
428+ // /
420429 bool ParseFromString (const std::string &obj_text, const std::string &mtl_text, const ObjReaderConfig &config);
421430
422431 // /
@@ -551,15 +560,15 @@ struct face_t {
551560};
552561
553562// Internal data structure for line representation
554- struct line_t {
563+ struct __line_t {
555564 // l v1/vt1 v2/vt2 ...
556565 // In the specification, line primitrive does not have normal index, but
557566 // TinyObjLoader allow it
558567 std::vector<vertex_index_t > vertex_indices;
559568};
560569
561- // Internal data structure for pint representation
562- struct point_t {
570+ // Internal data structure for points representation
571+ struct __points_t {
563572 // p v1 v2 ...
564573 // In the specification, point primitrive does not have normal index and
565574 // texture coord index, but TinyObjLoader allow it.
@@ -580,20 +589,20 @@ struct obj_shape {
580589};
581590
582591//
583- // Manages group of primitives(face, line, point , ...)
592+ // Manages group of primitives(face, line, points , ...)
584593struct PrimGroup {
585594 std::vector<face_t > faceGroup;
586- std::vector<line_t > lineGroup;
587- std::vector<point_t > pointGroup ;
595+ std::vector<__line_t > lineGroup;
596+ std::vector<__points_t > pointsGroup ;
588597
589598 void clear () {
590599 faceGroup.clear ();
591600 lineGroup.clear ();
592- pointGroup .clear ();
601+ pointsGroup .clear ();
593602 }
594603
595604 bool IsEmpty () const {
596- return faceGroup.empty () && lineGroup.empty () && pointGroup .empty ();
605+ return faceGroup.empty () && lineGroup.empty () && pointsGroup .empty ();
597606 }
598607
599608 // TODO(syoyo): bspline, surface, ...
@@ -1494,6 +1503,24 @@ static bool exportGroupsToShape(shape_t *shape, const PrimGroup &prim_group,
14941503 }
14951504 }
14961505
1506+ // points
1507+ if (!prim_group.pointsGroup .empty ()) {
1508+ // Flatten & convert indices
1509+ for (size_t i = 0 ; i < prim_group.pointsGroup .size (); i++) {
1510+ for (size_t j = 0 ; j < prim_group.pointsGroup [i].vertex_indices .size (); j++) {
1511+
1512+ const vertex_index_t &vi = prim_group.pointsGroup [i].vertex_indices [j];
1513+
1514+ index_t idx;
1515+ idx.vertex_index = vi.v_idx ;
1516+ idx.normal_index = vi.vn_idx ;
1517+ idx.texcoord_index = vi.vt_idx ;
1518+
1519+ shape->points .indices .push_back (idx);
1520+ }
1521+ }
1522+ }
1523+
14971524 return true ;
14981525}
14991526
@@ -2077,7 +2104,7 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
20772104 if (token[0 ] == ' l' && IS_SPACE ((token[1 ]))) {
20782105 token += 2 ;
20792106
2080- line_t line;
2107+ __line_t line;
20812108
20822109 while (!IS_NEW_LINE (token[0 ])) {
20832110 vertex_index_t vi;
@@ -2086,7 +2113,7 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
20862113 static_cast <int >(vt.size () / 2 ), &vi)) {
20872114 if (err) {
20882115 std::stringstream ss;
2089- ss << " Failed parse `l' line(e.g. zero value for face index. line "
2116+ ss << " Failed parse `l' line(e.g. zero value for vertex index. line "
20902117 << line_num << " .)\n " ;
20912118 (*err) += ss.str ();
20922119 }
@@ -2104,6 +2131,37 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
21042131 continue ;
21052132 }
21062133
2134+ // points
2135+ if (token[0 ] == ' p' && IS_SPACE ((token[1 ]))) {
2136+ token += 2 ;
2137+
2138+ __points_t pts;
2139+
2140+ while (!IS_NEW_LINE (token[0 ])) {
2141+ vertex_index_t vi;
2142+ if (!parseTriple (&token, static_cast <int >(v.size () / 3 ),
2143+ static_cast <int >(vn.size () / 3 ),
2144+ static_cast <int >(vt.size () / 2 ), &vi)) {
2145+ if (err) {
2146+ std::stringstream ss;
2147+ ss << " Failed parse `p' line(e.g. zero value for vertex index. line "
2148+ << line_num << " .)\n " ;
2149+ (*err) += ss.str ();
2150+ }
2151+ return false ;
2152+ }
2153+
2154+ pts.vertex_indices .push_back (vi);
2155+
2156+ size_t n = strspn (token, " \t\r " );
2157+ token += n;
2158+ }
2159+
2160+ prim_group.pointsGroup .push_back (pts);
2161+
2162+ continue ;
2163+ }
2164+
21072165 // face
21082166 if (token[0 ] == ' f' && IS_SPACE ((token[1 ]))) {
21092167 token += 2 ;
0 commit comments