Fixed import from obj files

This commit is contained in:
Enrico Turri 2019-09-09 09:56:36 +02:00
parent fec1113020
commit 9b5edbfa5f

View file

@ -159,9 +159,7 @@ static bool obj_parseline(const char *line, ObjData &data)
line = endptr;
EATWS();
}
if (*line != 0)
return false;
data.coordinates.push_back((float)x);
data.coordinates.push_back((float)x);
data.coordinates.push_back((float)y);
data.coordinates.push_back((float)z);
data.coordinates.push_back((float)w);
@ -210,16 +208,16 @@ static bool obj_parseline(const char *line, ObjData &data)
}
}
if (vertex.coordIdx < 0)
vertex.coordIdx += data.coordinates.size() / 4;
else
vertex.coordIdx += (int)data.coordinates.size() / 4;
else
-- vertex.coordIdx;
if (vertex.normalIdx < 0)
vertex.normalIdx += data.normals.size() / 3;
else
vertex.normalIdx += (int)data.normals.size() / 3;
else
-- vertex.normalIdx;
if (vertex.textureCoordIdx < 0)
vertex.textureCoordIdx += data.textureCoordinates.size() / 3;
else
vertex.textureCoordIdx += (int)data.textureCoordinates.size() / 3;
else
-- vertex.textureCoordIdx;
data.vertices.push_back(vertex);
EATWS();
@ -256,8 +254,8 @@ static bool obj_parseline(const char *line, ObjData &data)
// printf("usemtl %s\r\n", line);
EATWS();
ObjUseMtl usemtl;
usemtl.vertexIdxFirst = data.vertices.size();
usemtl.name = line;
usemtl.vertexIdxFirst = (int)data.vertices.size();
usemtl.name = line;
data.usemtls.push_back(usemtl);
break;
}
@ -272,8 +270,8 @@ static bool obj_parseline(const char *line, ObjData &data)
if (*line != 0)
return false;
ObjObject object;
object.vertexIdxFirst = data.vertices.size();
object.name = line;
object.vertexIdxFirst = (int)data.vertices.size();
object.name = line;
data.objects.push_back(object);
break;
}
@ -282,8 +280,8 @@ static bool obj_parseline(const char *line, ObjData &data)
// g [group name]
// printf("group %s\r\n", line);
ObjGroup group;
group.vertexIdxFirst = data.vertices.size();
group.name = line;
group.vertexIdxFirst = (int)data.vertices.size();
group.name = line;
data.groups.push_back(group);
break;
}
@ -303,8 +301,8 @@ static bool obj_parseline(const char *line, ObjData &data)
if (*line != 0)
return false;
ObjSmoothingGroup group;
group.vertexIdxFirst = data.vertices.size();
group.smoothingGroupID = g;
group.vertexIdxFirst = (int)data.vertices.size();
group.smoothingGroupID = g;
data.smoothingGroups.push_back(group);
break;
}
@ -341,8 +339,9 @@ bool objparse(const char *path, ObjData &data)
lenPrev = len - lastLine;
memmove(buf, buf + lastLine, lenPrev);
}
} catch (std::bad_alloc &ex) {
printf("Out of memory\r\n");
}
catch (std::bad_alloc&) {
printf("Out of memory\r\n");
}
::fclose(pFile);