68 lines
3.3 KiB
Python
68 lines
3.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", "progress", "video", "materials", "camera", "lighting", "assets",
|
|
"_gltf", "blender", "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
|
|
|
|
# WYBOR POSTACI: "primitive", "robot", "pilot" lub "file".
|
|
MODEL = "file"
|
|
MODEL_FILE = PROJECT / "source_assets/character/character_custom.blend"
|
|
MODEL_HEIGHT = 200 # centymetry; None zachowuje oryginalny rozmiar
|
|
MODEL_ROTATION = (0, 0, 0) # roll, pitch, yaw; np. (0, 0, 90) obraca model
|
|
|
|
# 1. MODEL I SCENA. Jednostki: centymetry. Os Z wskazuje gore.
|
|
scene = Scene("MyShot")
|
|
floor = materials.color("Floor", rgb=(0.07, 0.08, 0.11))
|
|
if MODEL == "primitive":
|
|
blue = materials.color("Character", rgb=(0.04, 0.35, 0.8), metallic=0.2)
|
|
character = scene.character(material=blue, head_scale=1.0)
|
|
else:
|
|
sources = {
|
|
"robot": (PROJECT / "DemoAssets/RobotPolice/RobotPolice.fbx", "RobotPolice"),
|
|
"pilot": (PROJECT / "DemoAssets/pilot/pilot.fbx", "Pilot"),
|
|
"file": (MODEL_FILE, "CustomCharacter"),
|
|
}
|
|
if MODEL not in sources:
|
|
raise ValueError("MODEL: primitive, robot, pilot lub file.")
|
|
source, name = sources[MODEL]
|
|
character = scene.model(source, name=name, height=MODEL_HEIGHT, rotation=MODEL_ROTATION)
|
|
scene.primitive("Cube", name="Floor", location=(0, 0, -10), scale=(20, 20, 0.2), material=floor)
|
|
lighting.studio(scene, key_color=(1.0, 0.75, 0.5), fill_color=(0.3, 0.6, 1.0))
|
|
cam = camera.create(scene, location=(450, -550, 300), focal_length=45)
|
|
|
|
# 2. ANIMACJA. 48 klatek przy 24 FPS = 2 sekundy. Ostatnia klatka ma numer 47.
|
|
shot = Sequence(scene, fps=24, frames=48)
|
|
shot.camera(cam)
|
|
# Rotacja: (roll, pitch, yaw), w stopniach.
|
|
shot.transform_key(character, 0, rotation=(0, 0, 0))
|
|
shot.transform_key(character, 47, rotation=(0, 0, 360))
|
|
# Opcjonalny podskok (dziala tak samo dla robota i wlasnego modelu):
|
|
# shot.transform_key(character, 0, location=(0, 0, 0), interpolation="auto")
|
|
# shot.transform_key(character, 24, location=(0, 0, 80), interpolation="auto")
|
|
# shot.transform_key(character, 47, location=(0, 0, 0), interpolation="auto")
|
|
shot.save()
|
|
|
|
# 3. WYNIK. Najpierw obejrzyj animacje w Sequencerze, potem zmien RENDER na True.
|
|
RENDER = True
|
|
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)
|