Skip to content

Commit

Permalink
Some fixes, new scripts in UAS
Browse files Browse the repository at this point in the history
  • Loading branch information
Aspirata committed Jun 7, 2024
1 parent 40f5e45 commit b0fa685
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 55 deletions.
Binary file modified Animated Textures Test.blend
Binary file not shown.
41 changes: 22 additions & 19 deletions Mcblend Source/Assets/Scripts/Contact Shadows.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import bpy

UAS_API = {
Expand All @@ -8,27 +7,31 @@
"distance": {
"Type": "FloatProperty",
"Name": "Distance",
"Default": 0.2,
"Min": 0.0,
"Max": 100000.0
"Default": 0.2
}
}
}

mode = 1
distance = 0.2
bias = 0.03
thickness = 0.01

def CShadows(UProperties):
if bpy.context.scene.utilsproperties.cshadowsselection == 'Only Selected Light Sources':
for obj in bpy.context.selected_objects:
if hasattr(obj.data, 'use_contact_shadow'):
obj.data.use_contact_shadow = True
obj.data.contact_shadow_distance = UProperties.distance
obj.data.contact_shadow_bias = UProperties.bias
obj.data.contact_shadow_thickness = UProperties.thickness
else:
for obj in bpy.context.scene.objects:
if hasattr(obj.data, 'use_contact_shadow'):
obj.data.use_contact_shadow = True
obj.data.contact_shadow_distance = UProperties.distance
obj.data.contact_shadow_bias = UProperties.bias
obj.data.contact_shadow_thickness = UProperties.thickness
if mode == 0:
for obj in bpy.context.selected_objects:
try:
obj.data.use_contact_shadow = True
obj.data.contact_shadow_distance = distance
obj.data.contact_shadow_bias = bias
obj.data.contact_shadow_thickness = thickness
except:
pass
else:
for obj in bpy.context.scene.objects:
try:
obj.data.use_contact_shadow = True
obj.data.contact_shadow_distance = distance
obj.data.contact_shadow_bias = bias
obj.data.contact_shadow_thickness = thickness
except:
pass
6 changes: 0 additions & 6 deletions Mcblend Source/Assets/Scripts/Enchant.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import bpy

UAS_API = {
"divider": {
"Type": float
}
}

def Enchant():
for selected_object in bpy.context.selected_objects:
if selected_object.material_slots:
Expand Down
25 changes: 25 additions & 0 deletions Mcblend Source/Assets/Scripts/Jittered Shadows.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import bpy

mode = 1
overblur = 20.0
world_jitter = True

if mode == 0:
for obj in bpy.context.selected_objects:
try:
obj.data.use_shadow_jitter = True
obj.data.shadow_jitter_overblur = overblur
except:
pass
else:
for obj in bpy.context.scene.objects:
try:
obj.data.use_shadow_jitter = True
obj.data.shadow_jitter_overblur = overblur
except:
pass


if bpy.context.scene.world != None and world_jitter:
bpy.context.scene.world.use_sun_shadow_jitter = True
bpy.context.scene.world.sun_shadow_jitter_overblur = overblur
10 changes: 10 additions & 0 deletions Mcblend Source/Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,16 @@
"Fix Shade Auto Smooth": {
"Blender_version": "< 4.1.0",
"File_name": "Fix Shade Auto Smooth.py",
},

"Enable Jittered Shadows": {
"Blender_version": ">= 4.2.0",
"File_name": "Jittered Shadows.py",
},

"Enable Contact Shadows": {
"Blender_version": "< 4.2.0",
"File_name": "Contact Shadows.py",
}
},
}
50 changes: 20 additions & 30 deletions Mcblend Source/Materials/Materials.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from ..Data import *
import re
from ..MCB_API import *

# This function checks if a given material's name contains any of the keywords in the provided array.
Expand Down Expand Up @@ -281,8 +282,6 @@ def create_env(self=None):

if world_material_name in bpy.data.worlds:
bpy.context.scene.world = bpy.data.worlds.get(world_material_name)
else:
print("World not found (Create Sky)")

if self.create_clouds == 'Recreate Clouds':
for obj in scene.objects:
Expand Down Expand Up @@ -322,13 +321,9 @@ def create_env(self=None):

if clouds_node_tree_name in bpy.data.node_groups:
bpy.data.node_groups[clouds_node_tree_name]
else:
print("Clouds geometry nodes not found (Create Clouds)")

if "Clouds" in bpy.data.materials:
bpy.data.materials["Clouds"]
else:
print("Clouds material not found (Create Clouds)")

for obj in scene.objects:
if obj.get("Mcblend ID") == "Clouds":
Expand Down Expand Up @@ -463,26 +458,21 @@ def apply_resources():

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

for part in node.image.name.replace(".png", "").split("_"):
# image_texture_node misdetecting (_s)

if part == "n":
if node.type == "TEX_IMAGE" and node.image:
image_name = node.image.name.replace(".png", "")
if re.search(r'_n$', image_name):
normal_texture_node = node
break

if part == "s":
elif re.search(r'_s$', image_name):
specular_texture_node = node
break

if part == "e":
elif re.search(r'_e$', image_name):
emission_texture_node = node

if part != "s" and part != "n" and part != "e":
else:
image_texture_node = node
original_name = image_texture_node.image.name
new_name = original_name.replace("_y", "")
image_texture_node.image.name = new_name
image_texture = image_texture_node.image.name
print(image_texture)

if node.type == "GROUP":
if "Animated;" in node.node_tree.name:
Expand Down Expand Up @@ -650,9 +640,9 @@ def apply_resources():
if normal_texture_node == None:
normal_texture_node = material.node_tree.nodes.new("ShaderNodeTexImage")

if image_texture_node != None:
try:
normal_texture_node.location = (image_texture_node.location.x, image_texture_node.location.y - 562)
elif Texture_Animator != None:
except:
normal_texture_node.location = (Texture_Animator.location.x, Texture_Animator.location.y - 562)

normal_texture_node.interpolation = "Closest"
Expand Down Expand Up @@ -697,9 +687,9 @@ def apply_resources():
if specular_texture_node == None:
specular_texture_node = material.node_tree.nodes.new("ShaderNodeTexImage")

if image_texture_node != None:
try:
specular_texture_node.location = (image_texture_node.location.x, image_texture_node.location.y - 280)
elif Texture_Animator != None:
except:
specular_texture_node.location = (Texture_Animator.location.x, Texture_Animator.location.y - 280)

specular_texture_node.interpolation = "Closest"
Expand Down Expand Up @@ -735,15 +725,15 @@ def apply_resources():
material.node_tree.links.new(specular_texture_node.outputs["Alpha"], emission_invert_color_node.inputs["Color"])

if blender_version("4.x.x"):
if image_texture_node == None and Texture_Animator != None:
material.node_tree.links.new(Texture_Animator.outputs["Color"], PBSDF.inputs["Emission Color"])
if image_texture_node != None:
try:
material.node_tree.links.new(image_texture_node.outputs["Color"], PBSDF.inputs["Emission Color"])
except:
material.node_tree.links.new(Texture_Animator.outputs["Color"], PBSDF.inputs["Emission Color"])
else:
if image_texture_node == None and Texture_Animator != None:
material.node_tree.links.new(image_texture_node.outputs["Color"], PBSDF.inputs["Emission"])
if image_texture_node != None:
try:
material.node_tree.links.new(Texture_Animator.outputs["Color"], PBSDF.inputs["Emission"])
except:
material.node_tree.links.new(image_texture_node.outputs["Color"], PBSDF.inputs["Emission"])

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

Expand Down Expand Up @@ -782,9 +772,9 @@ def apply_resources():
if emission_texture_node == None:
emission_texture_node = material.node_tree.nodes.new("ShaderNodeTexImage")

if image_texture_node != None:
try:
emission_texture_node.location = (image_texture_node.location.x, image_texture_node.location.y - 760)
elif Texture_Animator != None:
except:
emission_texture_node.location = (Texture_Animator.location.x, Texture_Animator.location.y - 760)

emission_texture_node.interpolation = "Closest"
Expand Down

0 comments on commit b0fa685

Please sign in to comment.