LifePlay-Revival/Tools/HairImportFbx.py
edujiro5972 2744242609 Protocole de conversion d'une coiffure (13_Protocole_Coiffure.md) et outils HairImportFbx, HairMaterials
Protocole rejoue de bout en bout sur Pocolov 17 : resultat identique.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-02 18:16:09 +02:00

46 lines
2.2 KiB
Python

# Protocole de conversion d'une coiffure (Docs/Migration/13_Protocole_Coiffure.md), etape 2 : import du FBX.
#
# Importe les maillages d'un FBX en maillages statiques separes (sans materiaux ni textures) dans un dossier de travail,
# puis affiche pour chacun : nom, boite englobante, triangles, emplacements de materiaux. Ces informations servent a
# choisir le maillage de la coiffure (-Static) et la tete de reference (-FitHead) de LPHairFromStaticMesh.
#
# Usage :
# UnrealEditor-Cmd.exe <projet> -run=pythonscript "-script=<projet>/Tools/HairImportFbx.py fbx=<fichier.fbx> dest=/Game/Heavy/New5/Hairs/_Work" -unattended -nopause -nosplash
# Sortie : lignes "HAIRIMPORT" du journal.
import sys
import unreal
args = dict(a.split("=", 1) for a in sys.argv[1:] if "=" in a)
fbx = args.get("fbx")
dest = args.get("dest", "/Game/Heavy/New5/Hairs/_Work")
if not fbx:
unreal.log_error("HAIRIMPORT usage : fbx=<fichier.fbx> [dest=/Game/...]")
else:
task = unreal.AssetImportTask()
task.filename = fbx.replace("\\", "/")
task.destination_path = dest
task.automated = True
task.replace_existing = True
task.save = True
ui = unreal.FbxImportUI()
ui.import_mesh = True
ui.import_as_skeletal = False
ui.import_materials = False
ui.import_textures = False
ui.mesh_type_to_import = unreal.FBXImportType.FBXIT_STATIC_MESH
ui.static_mesh_import_data.combine_meshes = False
ui.static_mesh_import_data.auto_generate_collision = False
task.options = ui
unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([task])
count = 0
for path in task.imported_object_paths:
asset = unreal.load_asset(path)
if isinstance(asset, unreal.StaticMesh):
box = asset.get_bounding_box()
size = box.max - box.min
slots = [str(m.material_slot_name) for m in asset.static_materials]
unreal.log_warning("HAIRIMPORT %s : %d triangles, taille X=%.1f Y=%.1f Z=%.1f cm, min Z=%.1f max Z=%.1f, emplacements %s"
% (path, asset.get_num_triangles(0), size.x, size.y, size.z, box.min.z, box.max.z, slots))
count += 1
unreal.log_warning("HAIRIMPORT %d maillage(s) statique(s) importe(s) dans %s" % (count, dest))