WVT alpha
[convexer.git] / __init__.py
index 6b6185cb6a208c2844e42d026110df0cc8997204..3ce19bdce4b7eb645e855d44fbcde0b1f9250d88 100644 (file)
@@ -258,7 +258,8 @@ class cxr_edge(Structure):
 class cxr_static_loop(Structure):
    _fields_ = [("index",c_int32),
                ("edge_index",c_int32),
-               ("uv",c_double * 2)]
+               ("uv",c_double * 2),
+               ("alpha",c_double)]
 
 class cxr_polygon(Structure):
    _fields_ =  [("loop_start",c_int32),
@@ -351,6 +352,14 @@ def mesh_cxr_format(obj):
          else:
              loop_data[loop_index].uv[0] = c_double(0.0)
              loop_data[loop_index].uv[1] = c_double(0.0)
+
+         if data.vertex_colors:
+            alpha = data.vertex_colors.active.data[loop_index].color[0]
+         else:
+            alpha = 0.0
+
+         loop_data[loop_index].alpha = alpha
+
       center = obj.matrix_world @ poly.center
       normal = mtx_rot @ poly.normal
 
@@ -986,12 +995,13 @@ def material_info(mat):
       def _variant_apply( val ):
          nonlocal mat
          
-         if isinstance( val, str ):
-            return val
-         else:
+         if isinstance( val, list ):
             for shader_variant in val:
                if shader_variant[0] == mat.cxr_data.shader:
                   return shader_variant[1]
+            return val[0][1]
+         else:
+            return val
       
       # Find rootnodes
       if node == None:
@@ -999,36 +1009,38 @@ def material_info(mat):
 
          for node_idname in node_def:
             for n in mat.node_tree.nodes:
-               if n.bl_idname == node_idname:
+               if n.name == node_idname:
                   node_def = node_def[node_idname]
                   node = n
                   break
 
       for link in node_def:
-         if isinstance( node_def[link], dict ):
-            inputt = node.inputs[link]
-            inputt_def = node_def[link]
+         link_def = _variant_apply( node_def[link] )
+
+         if isinstance( link_def, dict ):
+            node_link = node.inputs[link]
 
-            if inputt.is_linked:
+            if node_link.is_linked:
 
                # look for definitions for the connected node type
-               con = inputt.links[0].from_node
+               from_node = node_link.links[0].from_node
                
-               for node_idname in inputt_def:
-                  if con.bl_idname == node_idname:
-                     con_def = inputt_def[ node_idname ]
-                     _graph_read( con_def, con, depth+1 )
+               node_name = from_node.name.split('.')[0]
+               if node_name in link_def:
+                  from_node_def = link_def[ node_name ]
+
+                  _graph_read( from_node_def, from_node, depth+1 )
                
-               # No definition found! :(
+               # No definition! :(
                #  TODO: Make a warning for this?
 
             else:
-               if "default" in inputt_def:
-                  prop = _variant_apply( inputt_def['default'] )
-                  info[prop] = inputt.default_value
+               if "default" in link_def:
+                  prop = _variant_apply( link_def['default'] )
+                  info[prop] = node_link.default_value
          else:
-            prop = _variant_apply( node_def[link] )
-            info[prop] = getattr(node,link)
+            prop = _variant_apply( link_def )
+            info[prop] = getattr( node, link )
 
    _graph_read(cxr_graph_mapping)
    
@@ -1660,7 +1672,7 @@ def cxr_temp_file( fn ):
    else:
       filepath = bpy.data.filepath
       directory = os.path.dirname(filepath)
-      return F"{directory}/{fn}.txt"
+      return F"{directory}/{fn}"
 
 def cxr_winepath( path ):
    if CXR_GNU_LINUX == 1:
@@ -1789,6 +1801,8 @@ class CXR_COMPILER_CHAIN(bpy.types.Operator):
       return {'PASS_THROUGH'}
 
    def invoke(_,context,event):
+      global cxr_error_inf
+
       static = _.__class__
       wm = context.window_manager
       
@@ -1834,7 +1848,12 @@ class CXR_COMPILER_CHAIN(bpy.types.Operator):
             if ms.material.cxr_data.shader == 'VertexLitGeneric':
                errmat = ms.material.name
                errnam = brush['object'].name
+
+               cxr_error_inf = ( "Shader error", \
+                  F"Vertex shader ({errmat}) used on model ({errnam})" )
+
                print( F"Vertex shader {errmat} used on {errnam}")
+               scene_redraw()
                return {'CANCELLED'}
       
       a_models = set()
@@ -1875,7 +1894,12 @@ class CXR_COMPILER_CHAIN(bpy.types.Operator):
 
                   errmat = ms.material.name
                   errnam = obj.name
+
+                  cxr_error_inf = ( "Shader error", \
+                     F"Lightmapped shader ({errmat}) used on model ({errnam})" )
+
                   print( F"Lightmapped shader {errmat} used on {errnam}")
+                  scene_redraw()
                   return {'CANCELLED'}
       
       # Collect images