Fix the ordefing of a constructor call of vertex_index.
This commit is contained in:
@@ -969,7 +969,7 @@ static bool parseLine(Command *command, const char *p, size_t p_len,
|
|||||||
// vertex
|
// vertex
|
||||||
if (token[0] == 'v' && IS_SPACE((token[1]))) {
|
if (token[0] == 'v' && IS_SPACE((token[1]))) {
|
||||||
token += 2;
|
token += 2;
|
||||||
float x, y, z;
|
float x = 0.0f, y = 0.0f, z = 0.0f;
|
||||||
parseFloat3(&x, &y, &z, &token);
|
parseFloat3(&x, &y, &z, &token);
|
||||||
command->vx = x;
|
command->vx = x;
|
||||||
command->vy = y;
|
command->vy = y;
|
||||||
@@ -981,7 +981,7 @@ static bool parseLine(Command *command, const char *p, size_t p_len,
|
|||||||
// normal
|
// normal
|
||||||
if (token[0] == 'v' && token[1] == 'n' && IS_SPACE((token[2]))) {
|
if (token[0] == 'v' && token[1] == 'n' && IS_SPACE((token[2]))) {
|
||||||
token += 3;
|
token += 3;
|
||||||
float x, y, z;
|
float x = 0.0f, y = 0.0f, z = 0.0f;
|
||||||
parseFloat3(&x, &y, &z, &token);
|
parseFloat3(&x, &y, &z, &token);
|
||||||
command->nx = x;
|
command->nx = x;
|
||||||
command->ny = y;
|
command->ny = y;
|
||||||
@@ -993,7 +993,7 @@ static bool parseLine(Command *command, const char *p, size_t p_len,
|
|||||||
// texcoord
|
// texcoord
|
||||||
if (token[0] == 'v' && token[1] == 't' && IS_SPACE((token[2]))) {
|
if (token[0] == 'v' && token[1] == 't' && IS_SPACE((token[2]))) {
|
||||||
token += 3;
|
token += 3;
|
||||||
float x, y;
|
float x = 0.0f, y = 0.0f;
|
||||||
parseFloat2(&x, &y, &token);
|
parseFloat2(&x, &y, &token);
|
||||||
command->tx = x;
|
command->tx = x;
|
||||||
command->ty = y;
|
command->ty = y;
|
||||||
@@ -1360,10 +1360,11 @@ bool parseObj(attrib_t *attrib, std::vector<shape_t> *shapes, const char *buf,
|
|||||||
num_f += command_count[t].num_f;
|
num_f += command_count[t].num_f;
|
||||||
num_faces += command_count[t].num_faces;
|
num_faces += command_count[t].num_faces;
|
||||||
}
|
}
|
||||||
// std::cout << "# v " << num_v << std::endl;
|
|
||||||
// std::cout << "# vn " << num_vn << std::endl;
|
//std::cout << "# v " << num_v << std::endl;
|
||||||
// std::cout << "# vt " << num_vt << std::endl;
|
//std::cout << "# vn " << num_vn << std::endl;
|
||||||
// std::cout << "# f " << num_f << std::endl;
|
//std::cout << "# vt " << num_vt << std::endl;
|
||||||
|
//std::cout << "# f " << num_f << std::endl;
|
||||||
|
|
||||||
// 4. merge
|
// 4. merge
|
||||||
// @todo { parallelize merge. }
|
// @todo { parallelize merge. }
|
||||||
@@ -1442,9 +1443,9 @@ bool parseObj(attrib_t *attrib, std::vector<shape_t> *shapes, const char *buf,
|
|||||||
for (size_t k = 0; k < commands[t][i].f.size(); k++) {
|
for (size_t k = 0; k < commands[t][i].f.size(); k++) {
|
||||||
vertex_index &vi = commands[t][i].f[k];
|
vertex_index &vi = commands[t][i].f[k];
|
||||||
int v_idx = fixIndex(vi.v_idx, v_count);
|
int v_idx = fixIndex(vi.v_idx, v_count);
|
||||||
int vn_idx = fixIndex(vi.vn_idx, n_count);
|
|
||||||
int vt_idx = fixIndex(vi.vt_idx, t_count);
|
int vt_idx = fixIndex(vi.vt_idx, t_count);
|
||||||
attrib->faces[f_count + k] = vertex_index(v_idx, vn_idx, vt_idx);
|
int vn_idx = fixIndex(vi.vn_idx, n_count);
|
||||||
|
attrib->faces[f_count + k] = vertex_index(v_idx, vt_idx, vn_idx);
|
||||||
}
|
}
|
||||||
attrib->material_ids[face_count] = material_id;
|
attrib->material_ids[face_count] = material_id;
|
||||||
attrib->face_num_verts[face_count] = commands[t][i].f.size();
|
attrib->face_num_verts[face_count] = commands[t][i].f.size();
|
||||||
|
|||||||
@@ -234,6 +234,9 @@ bool LoadObjAndConvert(float bmin[3], float bmax[3], const char* filename, int n
|
|||||||
bmin[0] = bmin[1] = bmin[2] = std::numeric_limits<float>::max();
|
bmin[0] = bmin[1] = bmin[2] = std::numeric_limits<float>::max();
|
||||||
bmax[0] = bmax[1] = bmax[2] = -std::numeric_limits<float>::max();
|
bmax[0] = bmax[1] = bmax[2] = -std::numeric_limits<float>::max();
|
||||||
|
|
||||||
|
//std::cout << "vertices.size() = " << attrib.vertices.size() << std::endl;
|
||||||
|
//std::cout << "normals.size() = " << attrib.normals.size() << std::endl;
|
||||||
|
|
||||||
{
|
{
|
||||||
DrawObject o;
|
DrawObject o;
|
||||||
std::vector<float> vb; // pos(3float), normal(3float), color(3float)
|
std::vector<float> vb; // pos(3float), normal(3float), color(3float)
|
||||||
@@ -268,18 +271,18 @@ bool LoadObjAndConvert(float bmin[3], float bmax[3], const char* filename, int n
|
|||||||
float n[3][3];
|
float n[3][3];
|
||||||
|
|
||||||
if (attrib.normals.size() > 0) {
|
if (attrib.normals.size() > 0) {
|
||||||
int f0 = idx0.vn_idx;
|
int nf0 = idx0.vn_idx;
|
||||||
int f1 = idx1.vn_idx;
|
int nf1 = idx1.vn_idx;
|
||||||
int f2 = idx2.vn_idx;
|
int nf2 = idx2.vn_idx;
|
||||||
|
|
||||||
if (f0 >= 0 && f1 >= 0 && f2 >= 0) {
|
if (nf0 >= 0 && nf1 >= 0 && nf2 >= 0) {
|
||||||
assert(3*f0+2 < attrib.normals.size());
|
assert(3*nf0+2 < attrib.normals.size());
|
||||||
assert(3*f1+2 < attrib.normals.size());
|
assert(3*nf1+2 < attrib.normals.size());
|
||||||
assert(3*f2+2 < attrib.normals.size());
|
assert(3*nf2+2 < attrib.normals.size());
|
||||||
for (int k = 0; k < 3; k++) {
|
for (int k = 0; k < 3; k++) {
|
||||||
n[0][k] = attrib.normals[3*f0+k];
|
n[0][k] = attrib.normals[3*nf0+k];
|
||||||
n[1][k] = attrib.normals[3*f1+k];
|
n[1][k] = attrib.normals[3*nf1+k];
|
||||||
n[2][k] = attrib.normals[3*f2+k];
|
n[2][k] = attrib.normals[3*nf2+k];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// compute geometric normal
|
// compute geometric normal
|
||||||
@@ -304,7 +307,7 @@ bool LoadObjAndConvert(float bmin[3], float bmax[3], const char* filename, int n
|
|||||||
// Use normal as color.
|
// Use normal as color.
|
||||||
float c[3] = {n[k][0], n[k][1], n[k][2]};
|
float c[3] = {n[k][0], n[k][1], n[k][2]};
|
||||||
float len2 = c[0] * c[0] + c[1] * c[1] + c[2] * c[2];
|
float len2 = c[0] * c[0] + c[1] * c[1] + c[2] * c[2];
|
||||||
if (len2 > 0.0f) {
|
if (len2 > 1.0e-6f) {
|
||||||
float len = sqrtf(len2);
|
float len = sqrtf(len2);
|
||||||
|
|
||||||
c[0] /= len;
|
c[0] /= len;
|
||||||
|
|||||||
Reference in New Issue
Block a user