From c816a964b7319f09f6ddd0f105f3517597c9068c Mon Sep 17 00:00:00 2001 From: GreenDimond <24834740+GreenXenith@users.noreply.github.com> Date: Mon, 1 Jul 2019 12:03:41 -0700 Subject: [PATCH 1/3] Include transparency and material rewrite in script --- README.md | 18 ++------------- materials.py | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 16 deletions(-) create mode 100644 materials.py diff --git a/README.md b/README.md index 0a0406c..670a213 100644 --- a/README.md +++ b/README.md @@ -14,23 +14,9 @@ Use `/mesh1` and `/mesh2` to set the corners of the area you want exported, then Once the model is exported, you should be able to import the `.obj` file with default settings. Make sure "Image Search" in the import settings is selected to ensure the textures are imported as well. Texture modifiers are ignored, so some materials will likely have to be fixed by hand. -#### Fixing interpolation +#### Fixing materials -If you intend to render the scene, you will want to set the interpolation mode of all the image textures to "Closest" in order to keep the pixelated look. This can either be done manually or by running this script in Blender's text editor: - -```python -import bpy - -for mat in bpy.data.materials: - try: - nodes = mat.node_tree.nodes - - for node in nodes: - if node.type == "TEX_IMAGE": - node.interpolation = "Closest" - except: - continue -``` +Blender's packaged material assigned to OBJ textures are not effective or easy to use. By default, textures will also appear blurry and lack alpha. The `materials.py` script is included in the mod to simplify the materials, change interpolation, and add transparency. Open the script in Blender's text editor and run the script with the mesh selected. #### Fixing vertex normals diff --git a/materials.py b/materials.py new file mode 100644 index 0000000..293ba53 --- /dev/null +++ b/materials.py @@ -0,0 +1,65 @@ +# Original script (interpolation): Techy5 +# Expanded script: GreenXenith + +### Use better materials and support alpha ### +# Usage: Open or copy script in Blender +# Run script while object is selected + +import bpy + +for mat in bpy.data.materials: + try: + nodes = mat.node_tree.nodes + links = mat.node_tree.links + + # Remove all nodes except texture + for node in nodes: + if node.type != "TEX_IMAGE": + nodes.remove(node) + + # Change image interpolation + tex = nodes["Image Texture"] + tex.interpolation = "Closest" + tex.location = 0, 0 + + # Create texture coordinate node + coord = nodes.new("ShaderNodeTexCoord") + coord.location = -600, 0 + + # Create mapping node + map = nodes.new("ShaderNodeMapping") + map.location = -400, 0 + + # Create diffuse shader + diff = nodes.new("ShaderNodeBsdfDiffuse") + diff.location = 200, 0 + + # Create transparent shader + trans = nodes.new("ShaderNodeBsdfTransparent") + trans.location = 200, -150 + + # Create mix shader + mix = nodes.new("ShaderNodeMixShader") + mix.location = 400, 0 + + # Create output + out = nodes.new("ShaderNodeOutputMaterial") + out.location = 600, 0 + + # Link everything + links.new(coord.outputs[2], map.inputs[0]) # Coord > Map + links.new(map.outputs[0], tex.inputs[0]) # Map > Texture + links.new(tex.outputs[0], diff.inputs[0]) # Texture > Diffuse + links.new(diff.outputs[0], mix.inputs[2]) # Diffuse > Mix + + links.new(trans.outputs[0], mix.inputs[1]) # Transparent > Mix + links.new(tex.outputs[1], mix.inputs[0]) # Texture alpha > Mix factor + + links.new(mix.outputs[0], out.inputs[0]) # Mix > Output + + # Deselect all + for node in nodes: + node.select = False + + except: + continue From a507e93f73cee518aa3313037f36be6fc3ab75dd Mon Sep 17 00:00:00 2001 From: GreenDimond <24834740+GreenXenith@users.noreply.github.com> Date: Mon, 1 Jul 2019 12:10:59 -0700 Subject: [PATCH 2/3] Trim whitespace --- materials.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/materials.py b/materials.py index 293ba53..cf6c71b 100644 --- a/materials.py +++ b/materials.py @@ -21,7 +21,7 @@ for mat in bpy.data.materials: tex = nodes["Image Texture"] tex.interpolation = "Closest" tex.location = 0, 0 - + # Create texture coordinate node coord = nodes.new("ShaderNodeTexCoord") coord.location = -600, 0 @@ -29,11 +29,11 @@ for mat in bpy.data.materials: # Create mapping node map = nodes.new("ShaderNodeMapping") map.location = -400, 0 - + # Create diffuse shader diff = nodes.new("ShaderNodeBsdfDiffuse") diff.location = 200, 0 - + # Create transparent shader trans = nodes.new("ShaderNodeBsdfTransparent") trans.location = 200, -150 @@ -45,21 +45,21 @@ for mat in bpy.data.materials: # Create output out = nodes.new("ShaderNodeOutputMaterial") out.location = 600, 0 - + # Link everything links.new(coord.outputs[2], map.inputs[0]) # Coord > Map links.new(map.outputs[0], tex.inputs[0]) # Map > Texture links.new(tex.outputs[0], diff.inputs[0]) # Texture > Diffuse links.new(diff.outputs[0], mix.inputs[2]) # Diffuse > Mix - + links.new(trans.outputs[0], mix.inputs[1]) # Transparent > Mix links.new(tex.outputs[1], mix.inputs[0]) # Texture alpha > Mix factor links.new(mix.outputs[0], out.inputs[0]) # Mix > Output - + # Deselect all for node in nodes: node.select = False - + except: continue From b93d6f6ad0bc291bf0c6c61136915daa60223887 Mon Sep 17 00:00:00 2001 From: GreenDimond <24834740+GreenXenith@users.noreply.github.com> Date: Mon, 8 Jul 2019 13:51:26 -0700 Subject: [PATCH 3/3] Use principled shader --- materials.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/materials.py b/materials.py index cf6c71b..428419b 100644 --- a/materials.py +++ b/materials.py @@ -30,27 +30,28 @@ for mat in bpy.data.materials: map = nodes.new("ShaderNodeMapping") map.location = -400, 0 - # Create diffuse shader - diff = nodes.new("ShaderNodeBsdfDiffuse") - diff.location = 200, 0 + # Create principled shader + prin = nodes.new("ShaderNodeBsdfPrincipled") + prin.location = 200, 0 + prin.inputs["Specular"].default_value = 0 # Create transparent shader trans = nodes.new("ShaderNodeBsdfTransparent") - trans.location = 200, -150 + trans.location = 400, -150 # Create mix shader mix = nodes.new("ShaderNodeMixShader") - mix.location = 400, 0 + mix.location = 600, 0 # Create output out = nodes.new("ShaderNodeOutputMaterial") - out.location = 600, 0 + out.location = 800, 0 # Link everything links.new(coord.outputs[2], map.inputs[0]) # Coord > Map links.new(map.outputs[0], tex.inputs[0]) # Map > Texture - links.new(tex.outputs[0], diff.inputs[0]) # Texture > Diffuse - links.new(diff.outputs[0], mix.inputs[2]) # Diffuse > Mix + links.new(tex.outputs[0], prin.inputs[0]) # Texture > Principled + links.new(prin.outputs[0], mix.inputs[2]) # Principled > Mix links.new(trans.outputs[0], mix.inputs[1]) # Transparent > Mix links.new(tex.outputs[1], mix.inputs[0]) # Texture alpha > Mix factor