Browse Source

allow negative vertex indices for obj model format

Chris 13 years ago
parent
commit
f58c4167cd
1 changed files with 16 additions and 2 deletions
  1. 16 2
      utils/exporters/obj/convert_obj_three.py

+ 16 - 2
utils/exporters/obj/convert_obj_three.py

@@ -536,16 +536,29 @@ def parse_obj(fname):
                 uv_index = []
                 normal_index = []
 
+                
+                # Precompute vert / normal / uv lists
+                # for negative index lookup
+                vertlen = len(vertices) + 1
+                normlen = len(normals) + 1
+                uvlen = len(uvs) + 1
+
                 for v in chunks[1:]:
                     vertex = parse_vertex(v)
                     if vertex['v']:
+                        if vertex['v'] < 0:
+                            vertex['v'] += vertlen
                         vertex_index.append(vertex['v'])
                     if vertex['t']:
+                        if vertex['t'] < 0:
+                            vertex['t'] += uvlen
                         uv_index.append(vertex['t'])
                     if vertex['n']:
+                        if vertex['n'] < 0:
+                            vertex['n'] += normlen
                         normal_index.append(vertex['n'])
 
-                faces.append({
+                d = {
                     'vertex':vertex_index,
                     'uv':uv_index,
                     'normal':normal_index,
@@ -554,7 +567,8 @@ def parse_obj(fname):
                     'group':group,
                     'object':object,
                     'smooth':smooth,
-                    })
+                    }
+                faces.append(d)
 
             # Group
             if chunks[0] == "g" and len(chunks) == 2: