refactor config for wvt
authorhgn <hgodden00@gmail.com>
Fri, 29 Apr 2022 23:43:20 +0000 (00:43 +0100)
committerhgn <hgodden00@gmail.com>
Fri, 29 Apr 2022 23:43:20 +0000 (00:43 +0100)
__init__.py
config.py

index 65e29e90811ea1940c26fe571539dd63a8984784..c8fbad983495b7a3f434666bba8aa79b79cee504 100644 (file)
@@ -986,12 +986,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 +1000,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)
    
index cb5597cc0286ac33fd79671b070c9e9227d1eef6..e485027af5a609b50d9829093540f234a28facc8 100644 (file)
--- a/config.py
+++ b/config.py
@@ -14,7 +14,8 @@ cxr_shaders = \
    "LightMappedGeneric": { "name": "Light Mapped" },
    "VertexLitGeneric": { "name": "Vertex Lit" },
    "UnlitGeneric": { "name": "Unlit" },
-   "Builtin": { "name": "Builtin" }
+   "Builtin": { "name": "Builtin" },
+   "WorldVertexTransition": { "name": "Light Mapped Blend" }
 }
 
 # Shader graph mapping
@@ -22,7 +23,7 @@ cxr_shaders = \
 
 def material_tex_image(v):
    return {
-      "ShaderNodeTexImage":
+      "Image Texture":
       {
          "image": F"${v}"
       }
@@ -30,18 +31,29 @@ def material_tex_image(v):
 
 cxr_graph_mapping = \
 {
-   "ShaderNodeBsdfPrincipled":
+   # 'Special' shader for wvt
+   "cxr_blend":
+   {
+      "modulate": material_tex_image("blendmodulatetexture"),
+      "basetexture": material_tex_image("basetexture"),
+      "basetexture2": material_tex_image("basetexture2"),
+      "bumpmap": material_tex_image("bumpmap"),
+      "bumpmap2": material_tex_image("bumpmap2")
+   },
+
+   # Default shader setup 
+   "Principled BSDF":
    {
       "Base Color":
       {
-         "ShaderNodeMixRGB":
+         "Mix":
          {
             "Color1": material_tex_image("basetexture"),
             "Color2": material_tex_image("decaltexture")
          },
-         "ShaderNodeTexImage":
+         "Image Texture":
          {
-            "image":"$basetexture"
+            "image": "$basetexture"
          },
          "default":
             [("VertexLitGeneric","$color2"),\
@@ -50,7 +62,7 @@ cxr_graph_mapping = \
       },
       "Normal":
       {
-         "ShaderNodeNormalMap":
+         "Normal Map":
          {
             "Color": material_tex_image("bumpmap")
          }
@@ -66,7 +78,10 @@ cxr_shader_params = \
    "Textures":
    {
       "type": "ui",
-      "shaders": ("UnlitGeneric","VertexLitGeneric","LightMappedGeneric"),
+      "shaders": ("UnlitGeneric",\
+                  "VertexLitGeneric",\
+                  "LightMappedGeneric",\
+                  "WorldVertexTransition"),
 
       "$basetexture":
       {
@@ -74,6 +89,18 @@ cxr_shader_params = \
          "type": "intrinsic",
          "default": None
       },
+      "$basetexture2":
+      {
+         "name": "Base Texture 2",
+         "type": "intrinsic",
+         "default": None
+      },
+      "$blendmodulatetexture":
+      {
+         "name": "Blend Modulate",
+         "type": "intrinsic",
+         "default": None
+      },
       "$decaltexture":
       {
          "name": "Decal Texture",
@@ -100,6 +127,13 @@ cxr_shader_params = \
          "type": "intrinsic",
          "flags": NBVTF_TEXTUREFLAGS_NORMAL, # OpenGL (correct) normal maps.
          "default": None
+      },
+      "$bumpmap2":
+      {
+         "name": "Normal Map 2",
+         "type": "intrinsic",
+         "flags": NBVTF_TEXTUREFLAGS_NORMAL, 
+         "default": None
       }
    },
    "$color":
@@ -119,7 +153,7 @@ cxr_shader_params = \
    "Lighting":
    {
       "type": "ui",
-      "shaders": ("VertexLitGeneric", "LightMappedGeneric"),
+      "shaders": ("VertexLitGeneric", "LightMappedGeneric", "WorldVertexTransition"),
 
       "$phong":
       {
@@ -240,6 +274,13 @@ cxr_shader_params = \
       "name": "Surface",
       "type": "string",
       "default": ""
+   },
+   "$surfaceprop2":
+   {
+      "shaders": ("WorldVertexTransition",),
+      "name": "Surface 2",
+      "type": "string",
+      "default": ""
    }
 }