Skip to content

Commit

Permalink
Emssion, some fixes, Auto Build
Browse files Browse the repository at this point in the history
  • Loading branch information
Aspirata committed Jun 2, 2024
1 parent 5b02a5c commit 765596f
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 15 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/Addon Build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build and Zip Blender Addon

on:
push:
branches:
- Experimental
pull_request:
branches:
- Experimental

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10'

- name: Install required packages
run: |
python -m pip install --upgrade pip
- name: Zip Blender Addon
run: |
mkdir -p output
zip -r output/Mcblend.zip Mcblend Source
- name: Upload ZIP as artifact
uses: actions/upload-artifact@v2
with:
name: Mcblend Experimental Build
path: output/Mcblend.zip
56 changes: 41 additions & 15 deletions Mcblend Source/Materials/Materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,28 +428,34 @@ def apply_resources():
normal_map_node = None
specular_texture_node = None
separate_color_node = None
invert_color_node = None
roughness_invert_color_node = None
emission_invert_color_node = None

new_image_path = None
new_normal_image_path = None
new_specular_image_path = None

for node in material.node_tree.nodes:

if node.type == "BSDF_PRINCIPLED":
PBSDF = node

if node.type == "TEX_IMAGE" and node.image:

if not ("_n" in node.image.name) and not ("_s" in node.image.name):
image_texture_node = node
new_name = image_texture_node.image.name.replace("_y", "")
image_texture_node.image.name = new_name
for part in node.image.name.replace(".png", "").split("_"):

if "_n" in node.image.name:
normal_texture_node = node
if part == "n":
normal_texture_node = node
break

if part == "s":
specular_texture_node = node
break

if "_s" in node.image.name:
specular_texture_node = node
#if part == "e":

if part != "s" and part != "n" and part != "e":
image_texture_node = node

if node.type == "NORMAL_MAP":
normal_map_node = node
Expand All @@ -458,10 +464,18 @@ def apply_resources():
separate_color_node = node

if node.type == "INVERT":
invert_color_node = node
if "Roughness Invert" in node.name:
roughness_invert_color_node = node
if "Emission Invert" in node.name:
emission_invert_color_node = node


# Texture Update
if image_texture_node != None:

if abs(image_texture_node.location.x - PBSDF.location.x) < 600:
image_texture_node.location.x = PBSDF.location.x - 600

for pack, pack_info in resource_packs.items():
path, enabled = pack_info["path"], pack_info["enabled"]
if not enabled:
Expand Down Expand Up @@ -539,9 +553,15 @@ def apply_resources():
separate_color_node = material.node_tree.nodes.new("ShaderNodeSeparateColor")
separate_color_node.location = (specular_texture_node.location.x + 260, specular_texture_node.location.y)

if invert_color_node == None:
invert_color_node = material.node_tree.nodes.new("ShaderNodeInvert")
invert_color_node.location = (separate_color_node.location.x + 160, image_texture_node.location.y - 280)
if roughness_invert_color_node == None:
roughness_invert_color_node = material.node_tree.nodes.new("ShaderNodeInvert")
roughness_invert_color_node.location = (separate_color_node.location.x + 160, image_texture_node.location.y - 280)
roughness_invert_color_node.name ="Roughness Invert"

if emission_invert_color_node == None:
emission_invert_color_node = material.node_tree.nodes.new("ShaderNodeInvert")
emission_invert_color_node.location = (separate_color_node.location.x, separate_color_node.location.y - 140)
emission_invert_color_node.name = "Emission Invert"

if specular_image_name in bpy.data.images:
bpy.data.images.remove(bpy.data.images[specular_image_name], do_unlink=True)
Expand All @@ -551,10 +571,16 @@ def apply_resources():
specular_texture_node.image.colorspace_settings.name = "Non-Color"

material.node_tree.links.new(specular_texture_node.outputs["Color"], separate_color_node.inputs[0])
material.node_tree.links.new(separate_color_node.outputs["Red"], invert_color_node.inputs["Color"])

material.node_tree.links.new(separate_color_node.outputs["Red"], roughness_invert_color_node.inputs["Color"])
material.node_tree.links.new(separate_color_node.outputs["Green"], PBSDF.inputs["Metallic"])
#material.node_tree.links.new(separate_color_node.outputs["Blue"], PBSDF.inputs["Emission Strength"])
material.node_tree.links.new(invert_color_node.outputs[0], PBSDF.inputs["Roughness"])

material.node_tree.links.new(specular_texture_node.outputs["Alpha"], emission_invert_color_node.inputs["Color"])
material.node_tree.links.new(image_texture_node.outputs["Color"], PBSDF.inputs["Emission Color"])
material.node_tree.links.new(emission_invert_color_node.outputs[0], PBSDF.inputs["Emission Strength"])

material.node_tree.links.new(roughness_invert_color_node.outputs[0], PBSDF.inputs["Roughness"])

else:
Absolute_Solver("m002", slot)
Expand Down
5 changes: 5 additions & 0 deletions Mcblend Source/Properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class ResourcePackProperties(PropertyGroup):
default=True,
)

use_e: BoolProperty(
name="Use Emission Textures",
default=True,
)




Expand Down
3 changes: 3 additions & 0 deletions Mcblend Source/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ def draw(self, context):
row = sbox.row()
row.prop(scene.resource_properties, "use_s")

row = sbox.row()
row.prop(scene.resource_properties, "use_e")

row = sbox.row()
row.operator("resource_pack.apply", icon='CHECKMARK')

Expand Down
Binary file modified Mcblend.blend
Binary file not shown.

0 comments on commit 765596f

Please sign in to comment.