advanced example
This commit is contained in:
1 parent
8c0a639fba
commit
6fe57915e8
99 files changed
+1329
-56
No files matched your search
@@ -19,6 +19,7 @@ class Scene:
|
||||
if current_sequence and current_sequence.get_path_name().startswith(GENERATED + "/"):
|
||||
unreal.LevelSequenceEditorBlueprintLibrary.close_level_sequence()
|
||||
self.name = slug(name)
|
||||
self._skeletal_models = {}
|
||||
self.map_path = f"{GENERATED}/{name}/Map"
|
||||
self.subsystem = unreal.get_editor_subsystem(unreal.EditorActorSubsystem)
|
||||
editor = unreal.get_editor_subsystem(unreal.LevelEditorSubsystem)
|
||||
@@ -68,7 +69,7 @@ class Scene:
|
||||
raise ValueError("Ksztalt: Cube, Sphere, Cylinder, Cone lub Plane.")
|
||||
return self.mesh(f"/Engine/BasicShapes/{shape}.{shape}", **kwargs)
|
||||
|
||||
def model(self, filename, name="Character", height=200, rotation=(0, 0, 0)):
|
||||
def model(self, filename, name="Character", height=200, rotation=(0, 0, 0), reimport=False):
|
||||
"""Import a model, fit its height (cm), and give it a floor-centered pivot.
|
||||
|
||||
Returns a parent actor for transform animation; imported materials stay
|
||||
@@ -81,10 +82,10 @@ class Scene:
|
||||
source = source if source.is_absolute() else PROJECT / source
|
||||
if source.suffix.lower() == ".blend":
|
||||
from .blender import import_character
|
||||
mesh = import_character(source, name=name)
|
||||
mesh = import_character(source, name=name, reimport=reimport)
|
||||
else:
|
||||
from .assets import import_model
|
||||
mesh = import_model(source, name=name)
|
||||
mesh = import_model(source, name=name, reimport=reimport)
|
||||
actor = self.mesh(mesh, name=name + "Mesh")
|
||||
roll, pitch, yaw = rotation
|
||||
actor.set_actor_rotation(unreal.Rotator(roll=roll, pitch=pitch, yaw=yaw), False)
|
||||
@@ -103,6 +104,45 @@ class Scene:
|
||||
unreal.AttachmentRule.KEEP_WORLD, unreal.AttachmentRule.KEEP_WORLD, False)
|
||||
return root
|
||||
|
||||
def skeletal_model(self, filename, name="Character", height=200, rotation=(0, 0, 0),
|
||||
location=(0, 0, 0), animations=None, collection="Character", reimport=False):
|
||||
"""Import an animated FBX/.blend; return a parent actor for transform keys.
|
||||
|
||||
By default all animation FBXs beside the model are available by filename:
|
||||
shot.animation(actor, "great_sword_walk"). Optional animations={...}
|
||||
selects specific files; animations={} keeps only embedded animations.
|
||||
"""
|
||||
from .skeletal import import_model
|
||||
if height is not None and (not isinstance(height, (int, float)) or
|
||||
not math.isfinite(height) or height <= 0):
|
||||
raise ValueError("Wysokosc modelu musi byc dodatnia; None zachowuje rozmiar pliku.")
|
||||
imported = import_model(filename, name, animations, collection, reimport=reimport)
|
||||
child = self.spawn(unreal.SkeletalMeshActor, name + "Mesh")
|
||||
component = child.skeletal_mesh_component
|
||||
component.set_mobility(unreal.ComponentMobility.MOVABLE)
|
||||
component.set_skeletal_mesh_asset(imported.mesh)
|
||||
component.set_update_animation_in_editor(True)
|
||||
component.set_editor_property("visibility_based_anim_tick_option",
|
||||
unreal.VisibilityBasedAnimTickOption.ALWAYS_TICK_POSE_AND_REFRESH_BONES)
|
||||
roll, pitch, yaw = rotation
|
||||
child.set_actor_rotation(unreal.Rotator(roll=roll, pitch=pitch, yaw=yaw), False)
|
||||
origin, extent = child.get_actor_bounds(False)
|
||||
if extent.z <= 0:
|
||||
self.subsystem.destroy_actor(child)
|
||||
raise ValueError("Model ma zerowa wysokosc. Sprawdz geometrie i rotacje.")
|
||||
if height is not None:
|
||||
factor = float(height) / (2 * extent.z)
|
||||
child.set_actor_scale3d(unreal.Vector(factor, factor, factor))
|
||||
origin, extent = child.get_actor_bounds(False)
|
||||
child.set_actor_location(unreal.Vector(-origin.x, -origin.y, extent.z - origin.z), False, False)
|
||||
root = self.spawn(unreal.StaticMeshActor, name)
|
||||
root.static_mesh_component.set_mobility(unreal.ComponentMobility.MOVABLE)
|
||||
child.attach_to_actor(root, "", unreal.AttachmentRule.KEEP_WORLD,
|
||||
unreal.AttachmentRule.KEEP_WORLD, unreal.AttachmentRule.KEEP_WORLD, False)
|
||||
root.set_actor_location(unreal.Vector(*location), False, False)
|
||||
self._skeletal_models[root.get_path_name()] = (child, imported)
|
||||
return root
|
||||
|
||||
def character(self, material=None, head_scale=1.0):
|
||||
root = self.spawn(unreal.StaticMeshActor, "Character")
|
||||
root.static_mesh_component.set_mobility(unreal.ComponentMobility.MOVABLE)
|
||||
|
||||
Reference in new issue
Block a user