79 lines
4.3 KiB
Python
79 lines
4.3 KiB
Python
"""Uruchom plik w UE: File > Execute Python Script. Zmieniaj i uruchamiaj ponownie."""
|
|
import importlib
|
|
import sys
|
|
|
|
# Ponowny import bibliotek (ue cachuje zaimportowaną biblioteke i jeśli nie bedzie
|
|
# jawnego reloadu/restartu edytora to będzie wykonywał stary kod)
|
|
if "ue_workshop" in sys.modules:
|
|
_render_module = sys.modules.get("ue_workshop.render")
|
|
if _render_module is not None and _render_module.is_rendering():
|
|
raise RuntimeError("Poczekaj na zakonczenie renderu przed przeladowaniem biblioteki.")
|
|
# Najpierw zaleznosci, potem moduly, ktore z nich korzystaja.
|
|
for _name in ("paths", "animation_clip", "animation_catalog", "animations", "progress", "video", "materials", "camera", "lighting", "assets",
|
|
"_gltf", "blender", "characters", "skeletal", "root_motion", "scene", "sequence", "render"):
|
|
_module = sys.modules.get("ue_workshop." + _name)
|
|
if _module is not None:
|
|
importlib.reload(_module)
|
|
importlib.reload(sys.modules["ue_workshop"])
|
|
|
|
from ue_workshop import Scene, Sequence, Renderer, camera, lighting, materials
|
|
from ue_workshop.paths import PROJECT
|
|
from ue_workshop.characters import FIGHTER_MODEL, CREATURE_MODEL
|
|
from ue_workshop.animations import FighterAnimations, CreatureAnimations
|
|
|
|
# 1. MODEL I SCENA. Jednostki: centymetry. Os Z wskazuje gore.
|
|
scene = Scene("MyShot")
|
|
floor = materials.color("Floor", rgb=(0.07, 0.08, 0.11))
|
|
character_fighter = scene.skeletal_model(FIGHTER_MODEL, name="Fighter", height=200, location=(30, -40, 0.16), rotation=(0,0,180))
|
|
character_creature = scene.skeletal_model(CREATURE_MODEL, name="Creature", height=300, location=(0,-850,0))
|
|
|
|
scene.primitive("Cube", name="Floor", location=(0, 0, -10), scale=(20, 20, 0.2), material=floor)
|
|
|
|
lights = [
|
|
lighting.area(scene, "Key", (200, -500, 350), color=(1.0, 0.75, 0.5)),
|
|
lighting.area(scene, "Fill", (100, 300, 250), intensity=7000, color=(0.3, 0.6, 1.0)),
|
|
lighting.area(scene, "Rim", (-200, 0, 300), intensity=15000)
|
|
]
|
|
|
|
cam = camera.create(scene, location=(200, -300, 200), target=(0, 0, 100), fov=90)
|
|
|
|
# 2. ANIMACJA. 120 klatek przy 24 FPS = 5 sekund. Ostatnia klatka ma numer 119.
|
|
shot = Sequence(scene, fps=30, frames=260)
|
|
|
|
# Fighter
|
|
shot.animation(character_fighter, FighterAnimations.DRAW_A_GREAT_SWORD_2, start=0)
|
|
shot.animation(character_fighter, FighterAnimations.GREAT_SWORD_IDLE, start=22, end=55)
|
|
shot.animation(character_fighter, FighterAnimations.GREAT_SWORD_BLOCKING, start=48)
|
|
shot.animation(character_fighter, FighterAnimations.GREAT_SWORD_BLOCKING_2, start=61)
|
|
shot.animation(character_fighter, FighterAnimations.GREAT_SWORD_SLASH, start=80)
|
|
shot.animation(character_fighter, FighterAnimations.GREAT_SWORD_JUMP_ATTACK, start=117, keep_end_position=True)
|
|
shot.animation(character_fighter, FighterAnimations.GREAT_SWORD_STRAFE, start=180, keep_end_position=True)
|
|
shot.animation(character_fighter, FighterAnimations.GREAT_SWORD_RUN_2, start=207, end=259, keep_end_position=True)
|
|
shot.transform_key(character_fighter,58, location=(30, -40, 0.16), interpolation="auto")
|
|
shot.transform_key(character_fighter,64, location=(30, 20, 0.16), interpolation="auto")
|
|
shot.move(character_fighter, start=134, end=146, offset=(0, -170, 0), interpolation="auto")
|
|
|
|
# Creature
|
|
shot.animation(character_creature, CreatureAnimations.MUTANT_RUN, start=0, end=60, keep_end_position=True)
|
|
shot.animation(character_creature, CreatureAnimations.MUTANT_SWIPING, start=20)
|
|
shot.animation(character_creature, CreatureAnimations.MUTANT_WALKING, start=95, end=160, keep_end_position=True, reverse=True)
|
|
shot.animation(character_creature, CreatureAnimations.MUTANT_DYING, start=130, end=259, keep_end_pose=True)
|
|
|
|
# Camera
|
|
shot.camera(cam)
|
|
r = cam.get_actor_rotation()
|
|
shot.transform_key(cam, 0, rotation=(r.roll, r.pitch, r.yaw))
|
|
shot.transform_key(cam, 10, location=(200, -300, 200), interpolation="auto")
|
|
shot.transform_key(cam, 75, location=(450, -550, 300), rotation=(0, -15, 150), interpolation="auto")
|
|
|
|
shot.save()
|
|
|
|
# 3. WYNIK. Najpierw obejrzyj animacje w Sequencerze, potem zmien RENDER na True.
|
|
RENDER = False
|
|
renderer = Renderer(width=1920, height=1080, samples=4, warmup=32, mp4=True)
|
|
# Mozesz tez zaczac od presetu i nadpisac wybrane wartosci:
|
|
# renderer = Renderer.from_preset("final", width=1920, height=1080)
|
|
if RENDER:
|
|
renderer.render(shot)
|
|
# Szybki podglad zamiast filmu: renderer.render(shot, single_frame=24)
|