gitworld / phase2-unreal /EditorScripts /import_gitworld_opening.py
SNAPKITTYWEST's picture
push from SNAPKITTYWEST/gitworld
6281708 verified
Raw
History Blame Contribute Delete
3.9 kB
"""Run inside the Unreal Editor Python environment.
Creates a Media Framework asset for 3099.mp4, builds an emissive screen
material, and places the AGitWorldOpeningScene actor in the current level.
"""
import pathlib
import unreal
PROJECT_DIR = pathlib.Path(unreal.Paths.project_dir())
VIDEO_FILE = PROJECT_DIR / "ReferenceSource" / "Opening" / "3099.mp4"
MEDIA_PATH = "/Game/GitWorld/Media"
MATERIAL_PATH = "/Game/GitWorld/Materials"
def create_asset(asset_tools, name, package_path, asset_class, factory):
existing = unreal.EditorAssetLibrary.load_asset(package_path + "/" + name)
if existing:
return existing
return asset_tools.create_asset(name, package_path, asset_class, factory)
def create_media_assets():
if not VIDEO_FILE.is_file():
raise RuntimeError("Opening video not found: %s" % VIDEO_FILE)
asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
source = create_asset(
asset_tools,
"MS_GitWorldOpening",
MEDIA_PATH,
unreal.FileMediaSource,
unreal.FileMediaSourceFactoryNew(),
)
source.set_editor_property("file_path", str(VIDEO_FILE))
unreal.EditorAssetLibrary.save_loaded_asset(source)
player = create_asset(
asset_tools,
"MP_GitWorldOpening",
MEDIA_PATH,
unreal.MediaPlayer,
unreal.MediaPlayerFactoryNew(),
)
player.set_editor_property("loop", False)
player.set_editor_property("play_on_open", True)
player.set_editor_property("media_source", source)
unreal.EditorAssetLibrary.save_loaded_asset(player)
texture = create_asset(
asset_tools,
"MT_GitWorldOpening",
MEDIA_PATH,
unreal.MediaTexture,
unreal.MediaTextureFactoryNew(),
)
texture.set_editor_property("media_player", player)
unreal.EditorAssetLibrary.save_loaded_asset(texture)
return texture
def create_screen_material(texture):
asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
material = create_asset(
asset_tools,
"M_GitWorldOpeningScreen",
MATERIAL_PATH,
unreal.Material,
unreal.MaterialFactoryNew(),
)
material.set_editor_property("two_sided", True)
material.set_editor_property("shading_model", unreal.MaterialShadingModel.MSM_UNLIT)
sample = unreal.MaterialEditingLibrary.create_material_expression(
material, unreal.MaterialExpressionTextureSampleParameter2D, -400, 0
)
sample.set_editor_property("parameter_name", "OpeningVideo")
sample.set_editor_property("texture", texture)
unreal.MaterialEditingLibrary.connect_material_property(
sample, "RGB", unreal.MaterialProperty.MP_EMISSIVE_COLOR
)
unreal.MaterialEditingLibrary.layout_material_expressions(material)
unreal.EditorAssetLibrary.save_loaded_asset(material)
return material
def place_opening_actor(material):
opening_class = unreal.load_class(None, "/Script/GitWorldUnreal.GitWorldOpeningScene")
if not opening_class:
raise RuntimeError("GitWorldOpeningScene class is unavailable; build the Unreal module first")
actor = unreal.EditorLevelLibrary.spawn_actor_from_class(
opening_class, unreal.Vector(0.0, 0.0, 1050.0), unreal.Rotator(0.0, 0.0, 0.0)
)
actor.set_actor_label("GitWorld_Opening_3099")
actor.set_editor_property("opening_video_file", "ReferenceSource/Opening/3099.mp4")
actor.set_editor_property("screen_material", material)
actor.set_editor_property("b_play_on_begin", True)
return actor
def run():
texture = create_media_assets()
material = create_screen_material(texture)
place_opening_actor(material)
unreal.EditorLevelLibrary.save_current_level()
unreal.log("GitWorld opening scene wired: 3099.mp4")
run()