Ver código fonte

bugfix with texture and invalid node

Johann Woelper 10 anos atrás
pai
commit
bfc940312d
2 arquivos alterados com 6 adições e 11 exclusões
  1. 2 9
      m2b/b2m.py
  2. 4 2
      m2b/m2b.py

+ 2 - 9
m2b/b2m.py

@@ -53,14 +53,11 @@ def import_obj(fp):
 
 def setup_scene():
     print('> SETTING UP SCENE')
-    
-        
 
     print('> texture:', TEXTURE)
     for object in bpy.data.objects:
         if object.name == 'Cube':
             object.select = True
-            # remove it
             bpy.ops.object.delete()
 
     new_items = import_obj(OBJ_FILE)
@@ -74,7 +71,8 @@ def setup_scene():
     mat.use_nodes = True
     texnode = mat.node_tree.nodes.new(type="ShaderNodeTexImage")
     mat.node_tree.links.new(texnode.outputs['Color'], mat.node_tree.nodes['Diffuse BSDF'].inputs['Color'])
-    texnode.image = bpy.data.images.load(TEXTURE)
+    if os.path.isfile(str(TEXTURE)):
+        texnode.image = bpy.data.images.load(TEXTURE)
 
     for item in new_items:
         if item.type == 'MESH':
@@ -116,10 +114,6 @@ def deselect():
 
 def preview_texture(image):
     print('> PREVIEW TEXTURE GENERATION', TEXTURE)
-    img = bpy.data.images.load(image)
-
-
-
 
     for area in bpy.data.screens['Default'].areas:
         if area.type == 'VIEW_3D':
@@ -152,7 +146,6 @@ def export():
 
     update_maya()
 
-
 @persistent
 def save_handler(dummy):
     export()

+ 4 - 2
m2b/m2b.py

@@ -25,6 +25,7 @@ def guess_diffuse_file(node):
         plugs = t.listConnections(plugs=True)
         if any ([p.name() for p in plugs if 'color' in p.name() or 'diff' in p.name()]):
             return t.fileTextureName.get()
+    return 'untextured'
 
 
 def get_blender_path(root='/Applications'):
@@ -155,6 +156,7 @@ class BridgedNode(object):
             return True
         else:
             print '> invalid'
+            print [self.__dict__[key] for key in self.__dict__.keys()]
         
     def has_history(self):
         if os.path.isfile(self.geofile) and os.path.isfile(self.metadatafile) and os.path.isfile(self.blendfile):            
@@ -229,8 +231,8 @@ def init():
             bn.dump_metadata()
 
 
-    open_port(6006)
-    bn.edit_externally(get_blender_path())
+        open_port(6006)
+        bn.edit_externally(get_blender_path())
 
 
 def update(uuid):