From: hgn Date: Fri, 29 Apr 2022 23:43:20 +0000 (+0100) Subject: refactor config for wvt X-Git-Url: https://harrygodden.com/git/?p=convexer.git;a=commitdiff_plain;h=4c8d56259c110af8a97ff44402ed6152921727b2 refactor config for wvt --- diff --git a/__init__.py b/__init__.py index 65e29e9..c8fbad9 100644 --- a/__init__.py +++ b/__init__.py @@ -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) diff --git a/config.py b/config.py index cb5597c..e485027 100644 --- 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": "" } }