support obj with negative indices

This commit is contained in:
PanPan 2017-04-27 16:24:09 +08:00
parent d730ee66a4
commit 3cdfac7ed2

View file

@ -168,18 +168,23 @@ Error ResourceImporterOBJ::import(const String &p_source_file, const String &p_s
if (face[idx].size() == 3) { if (face[idx].size() == 3) {
int norm = face[idx][2].to_int() - 1; int norm = face[idx][2].to_int() - 1;
if (norm < 0)
norm += normals.size() + 1;
ERR_FAIL_INDEX_V(norm, normals.size(), ERR_PARSE_ERROR); ERR_FAIL_INDEX_V(norm, normals.size(), ERR_PARSE_ERROR);
surf_tool->add_normal(normals[norm]); surf_tool->add_normal(normals[norm]);
} }
if (face[idx].size() >= 2 && face[idx][1] != String()) { if (face[idx].size() >= 2 && face[idx][1] != String()) {
int uv = face[idx][1].to_int() - 1; int uv = face[idx][1].to_int() - 1;
if (uv < 0)
uv += uvs.size() + 1;
ERR_FAIL_INDEX_V(uv, uvs.size(), ERR_PARSE_ERROR); ERR_FAIL_INDEX_V(uv, uvs.size(), ERR_PARSE_ERROR);
surf_tool->add_uv(uvs[uv]); surf_tool->add_uv(uvs[uv]);
} }
int vtx = face[idx][0].to_int() - 1; int vtx = face[idx][0].to_int() - 1;
if (vtx < 0)
vtx += vertices.size() + 1;
ERR_FAIL_INDEX_V(vtx, vertices.size(), ERR_PARSE_ERROR); ERR_FAIL_INDEX_V(vtx, vertices.size(), ERR_PARSE_ERROR);
Vector3 vertex = vertices[vtx]; Vector3 vertex = vertices[vtx];