Skip to content

Commit

Permalink
Better detect_obj_type (Hybrid Mode)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aspirata committed Nov 15, 2024
1 parent 99dae4b commit 38143f8
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 26 deletions.
Binary file modified MiBlend.blend
Binary file not shown.
6 changes: 5 additions & 1 deletion MiBlend_Source/Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,16 @@
"Forest": (0.226964, 0.617207, 0.088656),
"Birch": (0.242279, 0.396756, 0.16203),
"Taiga": (0.25415, 0.467784, 0.250158),
"Dark Forest": (0.021219, 0.03434, 0.003035),
"Bad Land": (0.278893, 0.219526, 0.074214),
}

Foliage_Color = {
"Forest": (0.227161, 0.614651, 0.089036),
"Taiga": (0.152925, 0.366253, 0.147027),
"Swamp": (0.144128, 0.16203, 0.040915)
"Swamp": (0.144128, 0.16203, 0.040915),
"Jungle": (0.227161, 0.614651, 0.089036),
"Mangrove": (0.227161, 0.614651, 0.089036),
}

Emissive_Materials = {
Expand Down
16 changes: 10 additions & 6 deletions MiBlend_Source/MIB_API.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,18 @@ def MaterialIn(Array, material, mode="in"):

def detect_obj_type(obj_name: str = "", mat_name: str = "") -> str:

if ("block" in obj_name or "block" in mat_name) or bpy.data.objects[obj_name].get("MiBlend ID", None) != "item":
dprint(f"{obj_name}; {mat_name} is a block")
return "block"

elif ("item" in obj_name or "item" in mat_name) or bpy.data.objects[obj_name].get("MiBlend ID", None) == "item":
if "item" in obj_name or "item" in mat_name or bpy.data.objects[obj_name].get("MiBlend ID", None) == "item":
dprint(f"{obj_name}; {mat_name} is an item")
return "item"


elif "block" in obj_name or "block" in mat_name or bpy.data.objects[obj_name].get("MiBlend ID", None) == "block":
dprint(f"{obj_name}; {mat_name} is a block")
return "block"

elif "entity" in obj_name or "entity" in mat_name or bpy.data.objects[obj_name].get("MiBlend ID", None) == "entity":
dprint(f"{obj_name}; {mat_name} is a entity")
return "entity"

dprint(f"{obj_name}; {mat_name} is unknown")
return "unknown"

Expand Down
6 changes: 6 additions & 0 deletions MiBlend_Source/Materials/Materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ def fix_world():

if "fern" or "spruce" in texture_parts:
biome = "Taiga"
elif "dark" in texture_parts:
biome = "Dark Forest"
elif "mangrove" in texture_parts:
biome = "Mangrove"
elif "jungle" in texture_parts:
biome = "Jungle"

if "birch" in texture_parts:
biome = "Birch"
Expand Down
5 changes: 0 additions & 5 deletions MiBlend_Source/Properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ class ResourcePackProperties(PropertyGroup):
default=True,
)

compatibility_mode: BoolProperty(
name="Compatibility Mode",
default=False,
)

use_additional_textures: BoolProperty(
name="Use PBR Textures", # 16.09.2024 This was renamed, but i'm too lazy to change the name in the code LoL
default=True,
Expand Down
28 changes: 17 additions & 11 deletions MiBlend_Source/Resource_Packs.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,16 @@ def find_image(image_name: str, root_folder: str, obj_type: str = "unknown") ->
print("Bad Zip File")
else:
for dirpath, dirnames, files in os.walk(root_folder):
if obj_type == "unknown":
dprint(f"Warning ! {image_name} is {obj_type}")

elif not r_props.compatibility_mode and 'textures' in os.path.basename(dirpath) == "textures":
dirpath = os.path.join(dirpath, obj_type)
if "textures" not in dirpath:
continue

if obj_type == "unknown":
dprint(f"{image_name} is {obj_type}")
dprint(f"Switching to hybrid mode...")
dirpath = os.path.join(dirpath, obj_type)
else:
continue
dprint(f"{image_name} is {obj_type} using texture filter...")

if not os.path.exists(dirpath):
continue
Expand All @@ -158,11 +160,14 @@ def zip_unpacker(root_folder: str, image_name: str, obj_type: str , file=None) -
infolist = zip_ref.infolist()

if obj_type == "unknown":
dprint(f"Warning ! {image_name} is {obj_type}")

elif not r_props.compatibility_mode:
dprint(f"{image_name} is {obj_type}")
dprint(f"Switching to hybrid mode...")
filtered_infolist = [item for item in infolist if f"textures" in item.filename]
else:
dprint(f"{image_name} is {obj_type} using texture filter...")
filtered_infolist = [item for item in infolist if f"textures/{obj_type}" in item.filename]
infolist = filtered_infolist

infolist = filtered_infolist

if r_props.animate_textures:
for zip_info in infolist:
Expand All @@ -182,6 +187,7 @@ def zip_unpacker(root_folder: str, image_name: str, obj_type: str , file=None) -
continue

texture = os.path.basename(zip_info.filename)
dprint(f"{texture} ; {image_name}")
extracted_file_path = os.path.join(extract_path, zip_info.filename)

if (texture == image_name) or ("grass" in image_name and (texture == f"short_{image_name}" or texture == image_name.replace("short_", "") or file == image_name)):
Expand Down Expand Up @@ -285,8 +291,8 @@ def animate_texture(texture_node, new_image_texture_path, ITexture_Animator, Cur
if os.path.isfile(animation_file):
with open(animation_file, 'r') as file:
data = json.load(file).get('animation', {})
frametime = data.get('frametime')
interpolate = data.get('interpolate')
frametime = data.get('frametime', 20)
interpolate = data.get('interpolate', False)

if auvf_node:
material.node_tree.nodes.remove(auvf_node)
Expand Down
3 changes: 0 additions & 3 deletions MiBlend_Source/UI.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ def draw(self, context):
row = sbox.row()
row.prop(scene.resource_properties, "ignore_dublicates")

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

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

Expand Down

0 comments on commit 38143f8

Please sign in to comment.