Added line paths.
This commit is contained in:
@@ -236,9 +236,14 @@ typedef struct {
|
|||||||
std::vector<tag_t> tags; // SubD tag
|
std::vector<tag_t> tags; // SubD tag
|
||||||
} mesh_t;
|
} mesh_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
std::vector<int> indices; // pairs of indices for lines
|
||||||
|
} path_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
std::string name;
|
std::string name;
|
||||||
mesh_t mesh;
|
mesh_t mesh;
|
||||||
|
path_t path;
|
||||||
} shape_t;
|
} shape_t;
|
||||||
|
|
||||||
// Vertex attributes
|
// Vertex attributes
|
||||||
@@ -401,6 +406,11 @@ struct face_t {
|
|||||||
face_t() : smoothing_group_id(0) {}
|
face_t() : smoothing_group_id(0) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct line_t {
|
||||||
|
int idx0;
|
||||||
|
int idx1;
|
||||||
|
};
|
||||||
|
|
||||||
struct tag_sizes {
|
struct tag_sizes {
|
||||||
tag_sizes() : num_ints(0), num_reals(0), num_strings(0) {}
|
tag_sizes() : num_ints(0), num_reals(0), num_strings(0) {}
|
||||||
int num_ints;
|
int num_ints;
|
||||||
@@ -1015,15 +1025,17 @@ static int pnpoly(int nvert, T *vertx, T *verty, T testx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO(syoyo): refactor function.
|
// TODO(syoyo): refactor function.
|
||||||
static bool exportFaceGroupToShape(shape_t *shape,
|
static bool exportGroupsToShape(shape_t *shape,
|
||||||
const std::vector<face_t> &faceGroup,
|
const std::vector<face_t> &faceGroup,
|
||||||
|
const std::vector<int> &lineGroup,
|
||||||
const std::vector<tag_t> &tags,
|
const std::vector<tag_t> &tags,
|
||||||
const int material_id,
|
const int material_id,
|
||||||
const std::string &name, bool triangulate,
|
const std::string &name, bool triangulate,
|
||||||
const std::vector<real_t> &v) {
|
const std::vector<real_t> &v) {
|
||||||
if (faceGroup.empty()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
if (!faceGroup.empty()) {
|
||||||
|
|
||||||
// Flatten vertices and indices
|
// Flatten vertices and indices
|
||||||
for (size_t i = 0; i < faceGroup.size(); i++) {
|
for (size_t i = 0; i < faceGroup.size(); i++) {
|
||||||
@@ -1031,10 +1043,11 @@ static bool exportFaceGroupToShape(shape_t *shape,
|
|||||||
|
|
||||||
size_t npolys = face.vertex_indices.size();
|
size_t npolys = face.vertex_indices.size();
|
||||||
|
|
||||||
|
/*
|
||||||
if (npolys < 3) {
|
if (npolys < 3) {
|
||||||
// Face must have 3+ vertices.
|
// Face must have 3+ vertices.
|
||||||
continue;
|
continue;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
vertex_index_t i0 = face.vertex_indices[0];
|
vertex_index_t i0 = face.vertex_indices[0];
|
||||||
vertex_index_t i1(-1);
|
vertex_index_t i1(-1);
|
||||||
@@ -1254,6 +1267,12 @@ static bool exportFaceGroupToShape(shape_t *shape,
|
|||||||
|
|
||||||
shape->name = name;
|
shape->name = name;
|
||||||
shape->mesh.tags = tags;
|
shape->mesh.tags = tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(!lineGroup.empty()){
|
||||||
|
shape->path.indices = std::move(lineGroup);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1765,6 +1784,7 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
|||||||
std::vector<real_t> vc;
|
std::vector<real_t> vc;
|
||||||
std::vector<tag_t> tags;
|
std::vector<tag_t> tags;
|
||||||
std::vector<face_t> faceGroup;
|
std::vector<face_t> faceGroup;
|
||||||
|
std::vector<int> lineGroup;
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
// material
|
// material
|
||||||
@@ -1842,6 +1862,32 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// line
|
||||||
|
if (token[0] == 'l' && IS_SPACE((token[1]))){
|
||||||
|
token += 2;
|
||||||
|
|
||||||
|
line_t line_cache;
|
||||||
|
bool end_line_bit = 0;
|
||||||
|
while(!IS_NEW_LINE(token[0])){
|
||||||
|
//get index from string
|
||||||
|
int idx;
|
||||||
|
fixIndex(parseInt(&token), 0, &idx);
|
||||||
|
// move to next space or end of string (\0 / \n)
|
||||||
|
token += strcspn(token, " \t\r")+1;
|
||||||
|
|
||||||
|
if(!end_line_bit){
|
||||||
|
line_cache.idx0 = idx;
|
||||||
|
} else {
|
||||||
|
line_cache.idx1 = idx;
|
||||||
|
lineGroup.push_back(line_cache.idx0);
|
||||||
|
lineGroup.push_back(line_cache.idx1);
|
||||||
|
line_cache = line_t();
|
||||||
|
}
|
||||||
|
end_line_bit = !end_line_bit;
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
// face
|
// face
|
||||||
if (token[0] == 'f' && IS_SPACE((token[1]))) {
|
if (token[0] == 'f' && IS_SPACE((token[1]))) {
|
||||||
token += 2;
|
token += 2;
|
||||||
@@ -1892,7 +1938,7 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
|||||||
// Create per-face material. Thus we don't add `shape` to `shapes` at
|
// Create per-face material. Thus we don't add `shape` to `shapes` at
|
||||||
// this time.
|
// this time.
|
||||||
// just clear `faceGroup` after `exportFaceGroupToShape()` call.
|
// just clear `faceGroup` after `exportFaceGroupToShape()` call.
|
||||||
exportFaceGroupToShape(&shape, faceGroup, tags, material, name,
|
exportGroupsToShape(&shape, faceGroup, lineGroup, tags, material, name,
|
||||||
triangulate, v);
|
triangulate, v);
|
||||||
faceGroup.clear();
|
faceGroup.clear();
|
||||||
material = newMaterialId;
|
material = newMaterialId;
|
||||||
@@ -1947,7 +1993,7 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
|||||||
// group name
|
// group name
|
||||||
if (token[0] == 'g' && IS_SPACE((token[1]))) {
|
if (token[0] == 'g' && IS_SPACE((token[1]))) {
|
||||||
// flush previous face group.
|
// flush previous face group.
|
||||||
bool ret = exportFaceGroupToShape(&shape, faceGroup, tags, material, name,
|
bool ret = exportGroupsToShape(&shape, faceGroup, lineGroup, tags, material, name,
|
||||||
triangulate, v);
|
triangulate, v);
|
||||||
(void)ret; // return value not used.
|
(void)ret; // return value not used.
|
||||||
|
|
||||||
@@ -1984,7 +2030,7 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
|||||||
// object name
|
// object name
|
||||||
if (token[0] == 'o' && IS_SPACE((token[1]))) {
|
if (token[0] == 'o' && IS_SPACE((token[1]))) {
|
||||||
// flush previous face group.
|
// flush previous face group.
|
||||||
bool ret = exportFaceGroupToShape(&shape, faceGroup, tags, material, name,
|
bool ret = exportGroupsToShape(&shape, faceGroup, lineGroup, tags, material, name,
|
||||||
triangulate, v);
|
triangulate, v);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
shapes->push_back(shape);
|
shapes->push_back(shape);
|
||||||
@@ -2092,7 +2138,7 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
|||||||
// Ignore unknown command.
|
// Ignore unknown command.
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ret = exportFaceGroupToShape(&shape, faceGroup, tags, material, name,
|
bool ret = exportGroupsToShape(&shape, faceGroup, lineGroup, tags, material, name,
|
||||||
triangulate, v);
|
triangulate, v);
|
||||||
// exportFaceGroupToShape return false when `usemtl` is called in the last
|
// exportFaceGroupToShape return false when `usemtl` is called in the last
|
||||||
// line.
|
// line.
|
||||||
@@ -2103,6 +2149,12 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
|||||||
}
|
}
|
||||||
faceGroup.clear(); // for safety
|
faceGroup.clear(); // for safety
|
||||||
|
|
||||||
|
|
||||||
|
for(int i=0;i<lineGroup.size();i++){
|
||||||
|
//printf("facegroup indices size: %i\n", faceGroup[i].vertex_indices.size());
|
||||||
|
printf("linegroup[%i]: %i\n", i, lineGroup[i]);
|
||||||
|
}
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
(*err) += errss.str();
|
(*err) += errss.str();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user