blender customization

This commit is contained in:
Vysyr committed 2026-10-31 17:21:00 +01:00
1 parent fb39e290c0
commit 8c0a639fba
12 files changed
+264 -8

No files matched your search

+24 -4
View File
@@ -3,11 +3,12 @@ from pathlib import Path
import unreal
from .paths import GENERATED, slug
from .paths import GENERATED, PROJECT, slug
def import_model(filename, name="Character"):
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(f"Brak modelu: {source}")
if source.suffix.lower() not in {".glb", ".gltf", ".fbx", ".obj"}:
@@ -31,6 +32,10 @@ def import_model(filename, name="Character"):
pipeline = unreal.AssetToolsHelpers.get_asset_tools().duplicate_asset(
"GLTFWorkshop", GENERATED + "/Pipelines", template)
pipeline.set_editor_property("reimport_strategy", unreal.ReimportStrategyFlags.APPLY_PIPELINE_PROPERTIES)
pipeline.common_meshes_properties.set_editor_property(
"force_all_mesh_as_type", unreal.InterchangeForceMeshType.IFMT_STATIC_MESH)
pipeline.mesh_pipeline.set_editor_property("combine_static_meshes", True)
pipeline.mesh_pipeline.set_editor_property("import_skeletal_meshes", False)
pipeline.material_pipeline.set_editor_property("import_materials", True)
# PBR images are imported explicitly into WorkshopTextures below. This
# avoids Interchange's dependency-preserving material reimport behavior.
@@ -47,9 +52,11 @@ def import_model(filename, name="Character"):
unreal.SoftObjectPath(pipeline.get_path_name()),
unreal.SoftObjectPath("/Interchange/Pipelines/DefaultGLTFPipeline.DefaultGLTFPipeline")])
task.set_editor_property("options", options)
if source.suffix.lower() == ".fbx":
if source.suffix.lower() in {".fbx", ".obj"}:
options = unreal.FbxImportUI()
options.set_editor_property("import_mesh", True)
options.set_editor_property("import_as_skeletal", False)
options.set_editor_property("import_animations", False)
options.set_editor_property("mesh_type_to_import", unreal.FBXImportType.FBXIT_STATIC_MESH)
options.set_editor_property("automated_import_should_detect_type", False)
options.static_mesh_import_data.set_editor_property("combine_meshes", True)
@@ -59,10 +66,23 @@ def import_model(filename, name="Character"):
if len(meshes) != 1:
raise RuntimeError(
f"Import {source.name}: oczekiwano jednego StaticMesh, otrzymano {len(meshes)}. "
"Polacz obiekty przed eksportem albo uzyj workshop.blender.import_character().")
"Plik musi zawierac statyczna geometrie modelu.")
if source.suffix.lower() in {".glb", ".gltf"}:
# UE preserves material edits on mesh reimport. In this workflow Blender
# owns the look; explicitly synchronize the supported PBR parameters.
from ._gltf import link_textures
link_textures(source, meshes[0], destination)
else:
# Optional single-atlas convention, also used by the bundled FBX demos.
files = {file.stem.lower(): file for file in source.parent.iterdir()
if file.suffix.lower() in {".png", ".jpg", ".jpeg"}}
maps = {parameter: files.get(source.stem.lower() + suffix)
for suffix, parameter in (("_bc", "base_color"), ("_n", "normal"),
("_r", "roughness"), ("_m", "metallic"), ("_e", "emissive"))}
if maps["base_color"] is not None:
from .materials import texture_set
material = texture_set(name + "Imported", **maps)
for index in range(len(meshes[0].static_materials)):
meshes[0].set_material(index, material)
unreal.EditorAssetLibrary.save_loaded_asset(meshes[0])
return meshes[0]