Browse Source

Added safeguard in OBJ converter for not crashing on zero-sized degenerate normals.

alteredq 14 years ago
parent
commit
88a13e7d39
1 changed files with 7 additions and 6 deletions
  1. 7 6
      utils/exporters/convert_obj_threejs_slim.py

+ 7 - 6
utils/exporters/convert_obj_threejs_slim.py

@@ -323,17 +323,18 @@ def normalize(v):
     """Normalize 3d vector"""
     """Normalize 3d vector"""
     
     
     l = math.sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2])
     l = math.sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2])
-    v[0] /= l
-    v[1] /= l
-    v[2] /= l
+    if l:
+        v[0] /= l
+        v[1] /= l
+        v[2] /= l
 
 
 # #####################################################
 # #####################################################
 # MTL parser
 # MTL parser
 # #####################################################
 # #####################################################
 def texture_relative_path(fullpath):
 def texture_relative_path(fullpath):
-	texture_file = os.path.basename(fullpath)
-	return texture_file
-	
+    texture_file = os.path.basename(fullpath)
+    return texture_file
+    
 def parse_mtl(fname):
 def parse_mtl(fname):
     """Parse MTL file.
     """Parse MTL file.
     """
     """