Fixed import from obj files
This commit is contained in:
parent
fec1113020
commit
9b5edbfa5f
1 changed files with 18 additions and 19 deletions
|
@ -159,9 +159,7 @@ static bool obj_parseline(const char *line, ObjData &data)
|
||||||
line = endptr;
|
line = endptr;
|
||||||
EATWS();
|
EATWS();
|
||||||
}
|
}
|
||||||
if (*line != 0)
|
data.coordinates.push_back((float)x);
|
||||||
return false;
|
|
||||||
data.coordinates.push_back((float)x);
|
|
||||||
data.coordinates.push_back((float)y);
|
data.coordinates.push_back((float)y);
|
||||||
data.coordinates.push_back((float)z);
|
data.coordinates.push_back((float)z);
|
||||||
data.coordinates.push_back((float)w);
|
data.coordinates.push_back((float)w);
|
||||||
|
@ -210,16 +208,16 @@ static bool obj_parseline(const char *line, ObjData &data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (vertex.coordIdx < 0)
|
if (vertex.coordIdx < 0)
|
||||||
vertex.coordIdx += data.coordinates.size() / 4;
|
vertex.coordIdx += (int)data.coordinates.size() / 4;
|
||||||
else
|
else
|
||||||
-- vertex.coordIdx;
|
-- vertex.coordIdx;
|
||||||
if (vertex.normalIdx < 0)
|
if (vertex.normalIdx < 0)
|
||||||
vertex.normalIdx += data.normals.size() / 3;
|
vertex.normalIdx += (int)data.normals.size() / 3;
|
||||||
else
|
else
|
||||||
-- vertex.normalIdx;
|
-- vertex.normalIdx;
|
||||||
if (vertex.textureCoordIdx < 0)
|
if (vertex.textureCoordIdx < 0)
|
||||||
vertex.textureCoordIdx += data.textureCoordinates.size() / 3;
|
vertex.textureCoordIdx += (int)data.textureCoordinates.size() / 3;
|
||||||
else
|
else
|
||||||
-- vertex.textureCoordIdx;
|
-- vertex.textureCoordIdx;
|
||||||
data.vertices.push_back(vertex);
|
data.vertices.push_back(vertex);
|
||||||
EATWS();
|
EATWS();
|
||||||
|
@ -256,8 +254,8 @@ static bool obj_parseline(const char *line, ObjData &data)
|
||||||
// printf("usemtl %s\r\n", line);
|
// printf("usemtl %s\r\n", line);
|
||||||
EATWS();
|
EATWS();
|
||||||
ObjUseMtl usemtl;
|
ObjUseMtl usemtl;
|
||||||
usemtl.vertexIdxFirst = data.vertices.size();
|
usemtl.vertexIdxFirst = (int)data.vertices.size();
|
||||||
usemtl.name = line;
|
usemtl.name = line;
|
||||||
data.usemtls.push_back(usemtl);
|
data.usemtls.push_back(usemtl);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -272,8 +270,8 @@ static bool obj_parseline(const char *line, ObjData &data)
|
||||||
if (*line != 0)
|
if (*line != 0)
|
||||||
return false;
|
return false;
|
||||||
ObjObject object;
|
ObjObject object;
|
||||||
object.vertexIdxFirst = data.vertices.size();
|
object.vertexIdxFirst = (int)data.vertices.size();
|
||||||
object.name = line;
|
object.name = line;
|
||||||
data.objects.push_back(object);
|
data.objects.push_back(object);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -282,8 +280,8 @@ static bool obj_parseline(const char *line, ObjData &data)
|
||||||
// g [group name]
|
// g [group name]
|
||||||
// printf("group %s\r\n", line);
|
// printf("group %s\r\n", line);
|
||||||
ObjGroup group;
|
ObjGroup group;
|
||||||
group.vertexIdxFirst = data.vertices.size();
|
group.vertexIdxFirst = (int)data.vertices.size();
|
||||||
group.name = line;
|
group.name = line;
|
||||||
data.groups.push_back(group);
|
data.groups.push_back(group);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -303,8 +301,8 @@ static bool obj_parseline(const char *line, ObjData &data)
|
||||||
if (*line != 0)
|
if (*line != 0)
|
||||||
return false;
|
return false;
|
||||||
ObjSmoothingGroup group;
|
ObjSmoothingGroup group;
|
||||||
group.vertexIdxFirst = data.vertices.size();
|
group.vertexIdxFirst = (int)data.vertices.size();
|
||||||
group.smoothingGroupID = g;
|
group.smoothingGroupID = g;
|
||||||
data.smoothingGroups.push_back(group);
|
data.smoothingGroups.push_back(group);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -341,8 +339,9 @@ bool objparse(const char *path, ObjData &data)
|
||||||
lenPrev = len - lastLine;
|
lenPrev = len - lastLine;
|
||||||
memmove(buf, buf + lastLine, lenPrev);
|
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);
|
::fclose(pFile);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue