Skip to content

Commit

Permalink
update_texture()
Browse files Browse the repository at this point in the history
  • Loading branch information
Aspirata committed Jun 13, 2024
1 parent b76ef8a commit c60bf16
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 93 deletions.
106 changes: 37 additions & 69 deletions Mcblend Source/Materials/Materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ def fix_world():

if WProperties.lazy_biome_fix:
material_parts = image_texture_node.image.name.lower().replace("-", "_").split("_")
print(material_parts)

if ("grass" in material_parts or "water" in material_parts or "leaves" in material_parts) and "side" not in material_parts:
if lbcf_node == None:
Expand Down Expand Up @@ -446,6 +445,29 @@ def find_texture_users(texture):

return Texture_users

def update_texture(new_image_path, image_texture, texture_node=None, colorspace=None):
# if not r_props.ignore_dublicates then get_node_suffix_number() and replace with the original texture, but when replacing add the index
Users = find_texture_users(bpy.data.images[image_texture])

if image_texture in bpy.data.images:
bpy.data.images.remove(bpy.data.images[image_texture], do_unlink=True)

if texture_node != None:
if not texture_node.image:
if texture_node in bpy.data.images:
texture_node.image = bpy.data.images[image_texture]
else:
texture_node.image = bpy.data.images.load(new_image_path)

for user in Users:
if image_texture in bpy.data.images:
user.image = bpy.data.images[image_texture]
else:
user.image = bpy.data.images.load(new_image_path)

if colorspace != None:
user.image.colorspace_settings.name = colorspace

def animate_texture(texture_node, image_texture, new_image_texture_path, ITexture_Animator, Current_node_tree, image_path=None):
TAnimator_exists = False
Texture_Animator = None
Expand Down Expand Up @@ -637,29 +659,25 @@ def animate_texture(texture_node, image_texture, new_image_texture_path, ITextur
# Texture Update
if image_texture != None:
try:
if abs(image_texture_node.location.x - PBSDF.location.x) < 600:
image_texture_node.location.x = PBSDF.location.x - 600
try:
if abs(image_texture_node.location.x - PBSDF.location.x) < 600:
image_texture_node.location.x = PBSDF.location.x - 600
except:
if abs(ITexture_Animator.location.x - PBSDF.location.x) < 600:
ITexture_Animator.location.x = PBSDF.location.x - 600
except:
if abs(ITexture_Animator.location.x - PBSDF.location.x) < 600:
ITexture_Animator.location.x = PBSDF.location.x - 600
pass

for pack, pack_info in resource_packs.items():
path, enabled = pack_info["path"], pack_info["enabled"]
if not enabled:
continue

new_image_path = find_image(image_texture, path)
if new_image_path != None and os.path.isfile(new_image_path):

Users = find_texture_users(bpy.data.images[image_texture])
if image_texture in bpy.data.images:
bpy.data.images.remove(bpy.data.images[image_texture], do_unlink=True)
if new_image_path != None and os.path.isfile(new_image_path):

for user in Users:
if image_texture in bpy.data.images:
user.image = bpy.data.images[image_texture]
else:
user.image = bpy.data.images.load(new_image_path)
update_texture(new_image_path, image_texture)

image_path = path

Expand Down Expand Up @@ -703,21 +721,7 @@ def animate_texture(texture_node, image_texture, new_image_texture_path, ITextur

normal_texture_node.interpolation = "Closest"

Users = find_texture_users(bpy.data.images[normal_image_name])
if normal_image_name in bpy.data.images:
bpy.data.images.remove(bpy.data.images[normal_image_name], do_unlink=True)

if not normal_texture_node.image:
if normal_image_name in bpy.data.images:
normal_texture_node.image = bpy.data.images[normal_image_name]
else:
normal_texture_node.image = bpy.data.images.load(new_normal_image_path)

for user in Users:
if normal_image_name in bpy.data.images:
user.image = bpy.data.images[normal_image_name]
else:
user.image = bpy.data.images.load(new_normal_image_path)
update_texture(new_normal_image_path, normal_image_name, normal_texture_node)

normal_texture_node.image.colorspace_settings.name = "Non-Color"

Expand Down Expand Up @@ -773,26 +777,7 @@ def animate_texture(texture_node, image_texture, new_image_texture_path, ITextur

specular_texture_node.interpolation = "Closest"

Users = find_texture_users(bpy.data.images[specular_image_name])
if specular_image_name in bpy.data.images:
bpy.data.images.remove(bpy.data.images[specular_image_name], do_unlink=True)

if specular_texture_node != None:
if not specular_texture_node.image:
if specular_image_name in bpy.data.images:
specular_texture_node.image = bpy.data.images[specular_image_name]
else:
specular_texture_node.image = bpy.data.images.load(new_specular_image_path)

specular_texture_node.image.colorspace_settings.name = "Non-Color"

for user in Users:
if specular_image_name in bpy.data.images:
user.image = bpy.data.images[specular_image_name]
else:
user.image = bpy.data.images.load(new_specular_image_path)

user.image.colorspace_settings.name = "Non-Color"
update_texture(new_specular_image_path, specular_image_name, specular_texture_node, "Non-Color")

if LabPBR_s == None:
if "LabPBR Specular" not in bpy.data.node_groups:
Expand Down Expand Up @@ -917,21 +902,7 @@ def animate_texture(texture_node, image_texture, new_image_texture_path, ITextur

emission_texture_node.interpolation = "Closest"

if not emission_texture_node.image:
if emission_image_name in bpy.data.images:
emission_texture_node.image = bpy.data.images[emission_image_name]
else:
emission_texture_node.image = bpy.data.images.load(new_emission_image_path)

Users = find_texture_users(bpy.data.images[emission_image_name])
if emission_image_name in bpy.data.images:
bpy.data.images.remove(bpy.data.images[emission_image_name], do_unlink=True)

for user in Users:
if emission_image_name in bpy.data.images:
user.image = bpy.data.images[emission_image_name]
else:
user.image = bpy.data.images.load(new_emission_image_path)
update_texture(new_emission_image_path, emission_image_name, emission_texture_node)

if blender_version("4.x.x"):
material.node_tree.links.new(emission_texture_node.outputs["Color"], PBSDF.inputs["Emission Color"])
Expand Down Expand Up @@ -1030,10 +1001,7 @@ def setproceduralpbr():
bump_node.location = (PBSDF.location.x - 200, PBSDF.location.y - 100)
material.node_tree.links.new(GetConnectedSocketTo("Base Color", PBSDF), bump_node.inputs['Height'])
material.node_tree.links.new(bump_node.outputs['Normal'], PBSDF.inputs['Normal'])
bump_node.inputs[0].default_value = PProperties.bump_strength

if bump_node is not None:
bump_node.inputs[0].default_value = PProperties.bump_strength
bump_node.inputs[0].default_value = PProperties.bump_strength
else:
if bump_node is not None:
material.node_tree.nodes.remove(bump_node)
Expand Down
11 changes: 11 additions & 0 deletions Mcblend Source/Properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ def emissiondetectionfix():


class ResourcePackProperties(PropertyGroup):

resource_packs_list: BoolProperty(
name="Resource Packs List",
default=True,
)

ignore_dublicates: BoolProperty(
name="Ignore Dublicates",
default=True,
)

use_additional_textures: BoolProperty(
name="Use Additional Textures",
default=True,
Expand Down
58 changes: 34 additions & 24 deletions Mcblend Source/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"version": (0, 5, 0),
"blender": (3, 6, 0),
"location": "View3D > Addons Tab",
"warning": "This is Experimental Branch Build",
"description": "A useful tool for creating minecraft content in blender",
}

Expand Down Expand Up @@ -198,36 +199,45 @@ def draw(self, context):
sbox = box.box()
row = sbox.row()
row.label(text="Resource Packs", icon="FILE_FOLDER")

tbox = sbox.box()
row = tbox.row()
row.label(text="Resource Packs List", icon="OUTLINER")
row.prop(scene.resource_properties, "resource_packs_list", toggle=True, icon=("TRIA_DOWN" if scene.resource_properties.resource_packs_list else "TRIA_LEFT"), icon_only=True)
if scene.resource_properties.resource_packs_list:
try:
resource_packs = get_resource_packs()

try:
tbox = sbox.box()
resource_packs = get_resource_packs()
for pack, pack_info in resource_packs.items():
row = tbox.row()
for pack, pack_info in resource_packs.items():
row = tbox.row()

icon = 'CHECKBOX_HLT' if pack_info["enabled"] else 'CHECKBOX_DEHLT'
toggle_op = row.operator("resource_pack.toggle", text="", icon=icon)
toggle_op.pack_name = pack
icon = 'CHECKBOX_HLT' if pack_info["enabled"] else 'CHECKBOX_DEHLT'
toggle_op = row.operator("resource_pack.toggle", text="", icon=icon)
toggle_op.pack_name = pack

row.label(text=pack)

move_up = row.operator("resource_pack.move_up", text="", icon='TRIA_UP')
move_up.pack_name = pack
row.label(text=pack)
move_up = row.operator("resource_pack.move_up", text="", icon='TRIA_UP')
move_up.pack_name = pack

move_down = row.operator("resource_pack.move_down", text="", icon='TRIA_DOWN')
move_down.pack_name = pack
move_down = row.operator("resource_pack.move_down", text="", icon='TRIA_DOWN')
move_down.pack_name = pack

remove = row.operator("resource_pack.remove", text="", icon='X')
remove.pack_name = pack

row = tbox.row()
row.operator("resource_pack.update_default_pack", icon='NEWFOLDER')
remove = row.operator("resource_pack.remove", text="", icon='X')
remove.pack_name = pack
row = tbox.row()
row.operator("resource_pack.update_default_pack", icon='NEWFOLDER')

row = tbox.row()
row.operator("resource_pack.add", icon='ADD')
except:
row = tbox.row()
row.operator("resource_pack.fix", icon='TOOL_SETTINGS')
row = tbox.row()
row.operator("resource_pack.add", icon='ADD')
except:
row = tbox.row()
row.operator("resource_pack.fix", icon='TOOL_SETTINGS')

tbox = sbox.box()
row = tbox.row()
row.prop(scene.resource_properties, "ignore_dublicates")

tbox = sbox.box()
row = tbox.row()
Expand Down
Binary file modified Mcblend.blend
Binary file not shown.

0 comments on commit c60bf16

Please sign in to comment.