From bda281327bc6a5b8b729a5c2ae8846bd26f1b309 Mon Sep 17 00:00:00 2001 From: Trung <0znightlord0@gmail.com> Date: Wed, 18 Dec 2024 19:14:22 +0700 Subject: [PATCH] init --- MCprep_addon/materials/generate.py | 4 ++++ MCprep_addon/spawner/mcmodel.py | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/MCprep_addon/materials/generate.py b/MCprep_addon/materials/generate.py index 5dc54375..df3e3e45 100644 --- a/MCprep_addon/materials/generate.py +++ b/MCprep_addon/materials/generate.py @@ -101,6 +101,10 @@ def get_mc_canonical_name(name: str) -> Tuple[str, Optional[Form]]: # mixed up with the new "water": "painting/water" texture. general_name = "water_still" + if "_stem_stage" in general_name: + # For melon/pumpkin stem stage map to only melon_stem/pumpkin_stem + general_name = general_name.split("_stage")[0] + if general_name in env.json_data["blocks"]["block_mapping_mc"]: canon = env.json_data["blocks"]["block_mapping_mc"][general_name] form = "mc" if not jmc_prefix else "jmc2obj" diff --git a/MCprep_addon/spawner/mcmodel.py b/MCprep_addon/spawner/mcmodel.py index dc71e3aa..7bd067f6 100644 --- a/MCprep_addon/spawner/mcmodel.py +++ b/MCprep_addon/spawner/mcmodel.py @@ -116,11 +116,14 @@ def add_element( return verts, edges, faces -def add_material( +def add_get_material( name: str = "material", path: str = "", use_name: bool = False ) -> Optional[Material]: - """Creates a simple material with an image texture from path.""" + """Creates or get an existing created simple material with an image texture from path.""" engine = bpy.context.scene.render.engine + mat = bpy.data.materials.get(name) + if mat: + return mat # Create the base material node tree setup mat, err = generate.generate_base_material(bpy.context, name, path, False) @@ -302,7 +305,9 @@ def add_model( for img in textures: if img != "particle": tex_pth = locate_image(bpy.context, textures, img, model_filepath) - mat = add_material(f"{obj_name}_{img}", tex_pth, use_name=False) + # For json file only use 1 material for all faces + name = f"{obj_name}" if (len(textures) < 3) else f"{obj_name}_{img}" + mat = add_get_material(name, tex_pth, use_name=False) obj_mats = obj.data.materials if f"#{img}" not in materials: obj_mats.append(mat)