update compiler for blender 3.4.1
[carveJwlIkooP6JGAAIwe30JlM.git] / blender_export.py
index b6ca3e7208c71d054a869d3b65eeae01902907af..8cd60ea7d15240eb82ade9c56dc8afb5471a9b93 100644 (file)
@@ -1009,8 +1009,8 @@ cxr_graph_mapping = \
          },
          "Mix":
          {
-            "Color1": material_tex_image("tex_diffuse"),
-            "Color2": material_tex_image("tex_decal")
+            "A": material_tex_image("tex_diffuse"),
+            "B": material_tex_image("tex_decal")
          },
       },
       "Normal":
@@ -1063,9 +1063,20 @@ def material_info(mat):
 
          if isinstance( link_def, dict ):
          #{
-            node_link = node.inputs[link]
+            node_link = None
+            for x in node.inputs:
+            #{
+               if isinstance( x, bpy.types.NodeSocketColor ):
+               #{
+                  if link == x.name:
+                  #{
+                     node_link = x
+                     break
+                  #}
+               #}
+            #}
 
-            if node_link.is_linked:
+            if node_link and node_link.is_linked:
             #{
                # look for definitions for the connected node type
                #
@@ -1124,8 +1135,11 @@ def encoder_process_material( mat ):
    dest.pstr_name = encoder_process_pstr( mat.name )
    
    flags = 0x00
-   if mat.cv_data.skate_surface: flags |= 0x1
-   if mat.cv_data.collision: flags |= 0x2
+   if mat.cv_data.collision: 
+      flags |= 0x2
+      if mat.cv_data.skate_surface: flags |= 0x1
+      if mat.cv_data.grind_surface: flags |= (0x8|0x1)
+
    if mat.cv_data.grow_grass: flags |= 0x4
    dest.flags = flags
 
@@ -1336,18 +1350,18 @@ def encoder_vertex_push( vertex_reference, co,norm,uv,colour,groups,weights ):
           int(norm[2]*m+0.5),
           int(uv[0]*m+0.5),
           int(uv[1]*m+0.5),
-          colour[0]*m+0.5,    # these guys are already quantized
-          colour[1]*m+0.5,    # .
-          colour[2]*m+0.5,    # .
-          colour[3]*m+0.5,    # .
-          weights[0]*m+0.5,   # v
-          weights[1]*m+0.5,
-          weights[2]*m+0.5,
-          weights[3]*m+0.5,
-          groups[0]*m+0.5,
-          groups[1]*m+0.5,
-          groups[2]*m+0.5,
-          groups[3]*m+0.5)
+          colour[0],    # these guys are already quantized
+          colour[1],    # .
+          colour[2],    # .
+          colour[3],    # .
+          weights[0],   # v
+          weights[1],
+          weights[2],
+          weights[3],
+          groups[0],
+          groups[1],
+          groups[2],
+          groups[3])
 
    if key in vertex_reference:
       return vertex_reference[key]
@@ -1535,6 +1549,20 @@ def encoder_compile_mesh( node, node_def ):
                      weights[ml] = max( weights[ml], 0 )
                   #}
                #}
+            #}
+            else:
+            #{
+               li1 = tri.loops[(j+1)%3]
+               vi1 = data.loops[li1].vertex_index
+               e0 = data.edges[ data.loops[li].edge_index ]
+
+               if e0.use_freestyle_mark and \
+                     ((e0.vertices[0] == vi and e0.vertices[1] == vi1) or \
+                      (e0.vertices[0] == vi1 and e0.vertices[1] == vi)):
+               #{
+                  weights[0] = 1
+               #}
+            #}
             
             # Add vertex and expand bound box
             #
@@ -1943,6 +1971,9 @@ def write_model(collection_name):
 #{
    global g_encoder
    print( F"Model graph | Create mode '{collection_name}'" )
+   folder = bpy.path.abspath(bpy.context.scene.cv_data.export_dir)
+   path = F"{folder}{collection_name}.mdl"
+   print( path )
    
    collection = bpy.data.collections[collection_name]
 
@@ -1958,8 +1989,6 @@ def write_model(collection_name):
 
    # Write 
    #
-   # TODO HOLY
-   path = F"/home/harry/Documents/carve/models_src/{collection_name}.mdl"
    encoder_write_to_file( path )
 
    print( F"Completed {collection_name}.mdl" )
@@ -2476,6 +2505,11 @@ class CV_MATERIAL_SETTINGS(bpy.types.PropertyGroup):
          default=True,\
          description = "Should the game try to target this surface?" \
    )
+   grind_surface: bpy.props.BoolProperty( \
+         name="Grind Surface", \
+         default=False,\
+         description = "Grind face?" \
+   )
    grow_grass: bpy.props.BoolProperty( \
          name="Grow Grass", \
          default=False,\
@@ -2528,12 +2562,19 @@ class CV_MATERIAL_PANEL(bpy.types.Panel):
 
       info = material_info( active_mat )
 
+      if 'tex_diffuse' in info:
+      #{
+         _.layout.label( icon='INFO', \
+            text=F"{info['tex_diffuse'].name} will be compiled" )
+      #}
+
       _.layout.prop( active_mat.cv_data, "shader" )
       _.layout.prop( active_mat.cv_data, "surface_prop" )
       _.layout.prop( active_mat.cv_data, "collision" )
 
       if active_mat.cv_data.collision:
          _.layout.prop( active_mat.cv_data, "skate_surface" )
+         _.layout.prop( active_mat.cv_data, "grind_surface" )
          _.layout.prop( active_mat.cv_data, "grow_grass" )
 
       if active_mat.cv_data.shader == "terrain_blend":