more features

This commit is contained in:
Vysyr committed 2026-10-31 23:43:04 +01:00
1 parent bd8edf5afb
commit 1530b74d04
10 files changed
+563 -39

No files matched your search

+27 -9
View File
@@ -3,7 +3,7 @@ import unreal
from pathlib import Path
from .paths import GENERATED, slug
from .paths import GENERATED, PROJECT, slug
def color(name, rgb=(0.15, 0.5, 0.8), roughness=0.55, metallic=0.0):
@@ -16,6 +16,7 @@ def color(name, rgb=(0.15, 0.5, 0.8), roughness=0.55, metallic=0.0):
raise TypeError(f"{path} nie jest materialem.")
lib = unreal.MaterialEditingLibrary
lib.delete_all_material_expressions(material)
material.set_editor_property("used_with_skeletal_mesh", True)
base = lib.create_material_expression(material, unreal.MaterialExpressionConstant3Vector, -300, 0)
base.set_editor_property("constant", unreal.LinearColor(*rgb, 1.0))
lib.connect_material_property(base, "", unreal.MaterialProperty.MP_BASE_COLOR)
@@ -29,16 +30,27 @@ def color(name, rgb=(0.15, 0.5, 0.8), roughness=0.55, metallic=0.0):
return material
def assign(actor, material, slot=0):
component = actor.get_component_by_class(unreal.StaticMeshComponent)
if component is None:
raise TypeError("Material mozna przypisac do aktora ze StaticMeshComponent.")
component.set_material(slot, material)
def assign(actor, material, slot=None):
"""Set a material on an actor and all attached meshes; slot=None replaces every slot."""
components = [component for part in [actor, *actor.get_attached_actors(True, True)]
for component in part.get_components_by_class(unreal.MeshComponent)
if component.get_num_materials() > 0]
if not components:
raise TypeError("Material mozna przypisac do aktora z siatka.")
for component in components:
for index in range(component.get_num_materials()) if slot is None else [slot]:
component.set_material(index, material)
def texture_set(name, *, base_color, normal=None, roughness=None, metallic=None, emissive=None):
"""Create one atlas material from adjacent PBR textures (PNG/JPEG)."""
def texture_set(name, *, base_color, normal=None, roughness=None, metallic=None, emissive=None, tiling=1):
"""Create one atlas material from adjacent PBR textures (PNG/JPEG).
tiling repeats the textures: one number, or (u, v) for separate directions.
"""
slug(name)
u_tiling, v_tiling = tiling if isinstance(tiling, (tuple, list)) else (tiling, tiling)
if u_tiling <= 0 or v_tiling <= 0:
raise ValueError("tiling musi byc dodatnie.")
tools = unreal.AssetToolsHelpers.get_asset_tools()
path = f"{GENERATED}/Materials/M_{name}"
material = unreal.load_asset(path)
@@ -47,6 +59,10 @@ def texture_set(name, *, base_color, normal=None, roughness=None, metallic=None,
unreal.Material, unreal.MaterialFactoryNew())
lib = unreal.MaterialEditingLibrary
lib.delete_all_material_expressions(material)
material.set_editor_property("used_with_skeletal_mesh", True)
coordinates = lib.create_material_expression(material, unreal.MaterialExpressionTextureCoordinate, -600, 0)
coordinates.set_editor_property("u_tiling", float(u_tiling))
coordinates.set_editor_property("v_tiling", float(v_tiling))
entries = [("BaseColor", base_color, unreal.MaterialProperty.MP_BASE_COLOR, "RGB", "color"),
("Normal", normal, unreal.MaterialProperty.MP_NORMAL, "RGB", "normal"),
("Roughness", roughness, unreal.MaterialProperty.MP_ROUGHNESS, "R", "linear"),
@@ -59,7 +75,8 @@ def texture_set(name, *, base_color, normal=None, roughness=None, metallic=None,
node.set_editor_property("r", 0.6 if label == "Roughness" else 0.0)
lib.connect_material_property(node, "", prop)
continue
source = Path(filename).resolve()
source = Path(filename).expanduser()
source = (source if source.is_absolute() else PROJECT / source).resolve()
if not source.is_file():
raise FileNotFoundError(source)
task = unreal.AssetImportTask()
@@ -85,6 +102,7 @@ def texture_set(name, *, base_color, normal=None, roughness=None, metallic=None,
node.set_editor_property("sampler_type", unreal.MaterialSamplerType.SAMPLERTYPE_NORMAL
if role == "normal" else unreal.MaterialSamplerType.SAMPLERTYPE_MASKS
if role == "linear" else unreal.MaterialSamplerType.SAMPLERTYPE_COLOR)
lib.connect_material_expressions(coordinates, "", node, "UVs")
lib.connect_material_property(node, channel, prop)
lib.recompile_material(material)
unreal.EditorAssetLibrary.save_loaded_asset(material)