Include transparency and material rewrite in script
This commit is contained in:
parent
de62343ad4
commit
c816a964b7
18
README.md
18
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
|
||||
|
||||
|
65
materials.py
Normal file
65
materials.py
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user