176 lines
6 KiB
Python
176 lines
6 KiB
Python
import unreal
|
|
|
|
|
|
def ensure_directory(path):
|
|
if not unreal.EditorAssetLibrary.does_directory_exist(path):
|
|
unreal.EditorAssetLibrary.make_directory(path)
|
|
|
|
|
|
def spawn_actor(actor_class, location=(0, 0, 0), rotation=(0, 0, 0)):
|
|
rot = unreal.Rotator(rotation[0], rotation[1], rotation[2])
|
|
loc = unreal.Vector(location[0], location[1], location[2])
|
|
return unreal.EditorLevelLibrary.spawn_actor_from_class(actor_class, loc, rot)
|
|
|
|
|
|
def find_actor_by_label(label, class_name):
|
|
for actor in unreal.EditorLevelLibrary.get_all_level_actors():
|
|
if actor.get_actor_label() == label:
|
|
return actor
|
|
for actor in unreal.EditorLevelLibrary.get_all_level_actors():
|
|
if actor.get_class().get_name() == class_name:
|
|
return actor
|
|
return None
|
|
|
|
|
|
def create_or_load_preset():
|
|
preset_dir = "/Game/LedVolume/RemoteControl"
|
|
preset_name = "RCP_LedVolumeLive"
|
|
preset_path = f"{preset_dir}/{preset_name}"
|
|
ensure_directory("/Game/LedVolume")
|
|
ensure_directory(preset_dir)
|
|
|
|
if unreal.EditorAssetLibrary.does_asset_exist(preset_path):
|
|
unreal.EditorAssetLibrary.delete_asset(preset_path)
|
|
|
|
asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
|
|
preset_class = unreal.load_class(None, "/Script/RemoteControl.RemoteControlPreset")
|
|
factory_class = unreal.load_class(None, "/Script/RemoteControlUI.RemoteControlPresetFactory")
|
|
factory = unreal.new_object(factory_class) if factory_class else None
|
|
return asset_tools.create_asset(preset_name, preset_dir, preset_class, factory)
|
|
|
|
|
|
def expose_all(preset, controller):
|
|
def expose_property(property_name, display_name=None, group_name="LED Display"):
|
|
args = unreal.RemoteControlOptionalExposeArgs()
|
|
args.display_name = display_name or property_name
|
|
args.group_name = group_name
|
|
result = unreal.RemoteControlFunctionLibrary.expose_property(preset, controller, property_name, args)
|
|
unreal.log(f"Expose property {property_name}: {result}")
|
|
|
|
def expose_function(function_name, display_name=None, group_name="LED Commands"):
|
|
args = unreal.RemoteControlOptionalExposeArgs()
|
|
args.display_name = display_name or function_name
|
|
args.group_name = group_name
|
|
result = unreal.RemoteControlFunctionLibrary.expose_function(preset, controller, function_name, args)
|
|
unreal.log(f"Expose function {function_name}: {result}")
|
|
|
|
property_groups = {
|
|
"LED Target": [
|
|
"TargetActorLabel",
|
|
],
|
|
"LED Layout": [
|
|
"Width",
|
|
"Height",
|
|
"Depth",
|
|
"PixelSize",
|
|
"Spacing",
|
|
"PreviewStride",
|
|
"VoxelShape",
|
|
"CustomVoxelMesh",
|
|
],
|
|
"LED Appearance": [
|
|
"LedMaterial",
|
|
"Brightness",
|
|
"Gamma",
|
|
"SolidColor",
|
|
],
|
|
"LED Animation": [
|
|
"SourceMode",
|
|
"TestPattern",
|
|
"AnimationSpeed",
|
|
"bAnimateInEditor",
|
|
"bUseGpuTestPattern",
|
|
],
|
|
"LED Performance": [
|
|
"MaxEditorInstances",
|
|
"MaxRuntimeInstances",
|
|
"ColorUpdatesPerFrame",
|
|
"ApplyDebounceSeconds",
|
|
],
|
|
"LED Prepared Animation": [
|
|
"VolumeTextureFrames",
|
|
"TextureSliceFrames",
|
|
],
|
|
"LED Sublevel Source": [
|
|
"VoxelizedSublevel",
|
|
"CaptureBoundsExtent",
|
|
"bUseActorBoundsAsCaptureVolume",
|
|
"SourceActorTag",
|
|
"EmptyVoxelColor",
|
|
],
|
|
"LED Status": [
|
|
"RenderedInstanceCount",
|
|
"RequestedVoxelCount",
|
|
],
|
|
}
|
|
|
|
for group_name, properties in property_groups.items():
|
|
for prop in properties:
|
|
expose_property(prop, group_name=group_name)
|
|
|
|
for func in [
|
|
"ApplyToTarget",
|
|
"RebuildTarget",
|
|
"SyncFromTarget",
|
|
"GetTargetDisplay",
|
|
"SetWidth",
|
|
"SetHeight",
|
|
"SetDepth",
|
|
"SetPixelSize",
|
|
"SetSpacing",
|
|
"SetPreviewStride",
|
|
"SetVoxelShape",
|
|
"SetBrightness",
|
|
"SetGamma",
|
|
"SetSolidColor",
|
|
"SetSourceMode",
|
|
"SetTestPattern",
|
|
"SetAnimationSpeed",
|
|
"SetAnimateInEditor",
|
|
"SetUseGpuTestPattern",
|
|
]:
|
|
expose_function(func)
|
|
|
|
args = unreal.RemoteControlOptionalExposeArgs()
|
|
args.display_name = "LED_Remote_Control"
|
|
args.group_name = "Scene Actors"
|
|
try:
|
|
result = unreal.RemoteControlFunctionLibrary.expose_actor(preset, controller, args)
|
|
unreal.log(f"Expose actor LED_Remote_Control: {result}")
|
|
except Exception as exc:
|
|
unreal.log_warning(f"Could not expose LED actor: {exc}")
|
|
|
|
|
|
def ensure_preset_actor(preset):
|
|
for actor in unreal.EditorLevelLibrary.get_all_level_actors():
|
|
if actor.get_actor_label() == "RC_LedVolumeLive":
|
|
actor.set_editor_property("Preset", preset)
|
|
return actor
|
|
|
|
preset_actor_class = unreal.load_class(None, "/Script/RemoteControl.RemoteControlPresetActor")
|
|
preset_actor = spawn_actor(preset_actor_class, (-250, 0, 150), (0, 0, 0))
|
|
preset_actor.set_actor_label("RC_LedVolumeLive")
|
|
preset_actor.set_editor_property("Preset", preset)
|
|
return preset_actor
|
|
|
|
|
|
def main():
|
|
unreal.EditorLevelLibrary.load_level("/Game/LedVolume/Maps/L_LedVolume_Demo_Single")
|
|
|
|
controller = find_actor_by_label("LED_Remote_Control", "LedVolumeRemoteControlActor")
|
|
if not controller:
|
|
raise RuntimeError("LED_Remote_Control actor not found. Open/regenerate L_LedVolume_Demo_Single first.")
|
|
|
|
preset = create_or_load_preset()
|
|
if not preset:
|
|
raise RuntimeError("Could not create/load RCP_LedVolumeLive.")
|
|
|
|
expose_all(preset, controller)
|
|
ensure_preset_actor(preset)
|
|
unreal.EditorAssetLibrary.save_loaded_asset(preset)
|
|
unreal.EditorLoadingAndSavingUtils.save_dirty_packages(True, True)
|
|
unreal.log("Remote Control preset ready: /Game/LedVolume/RemoteControl/RCP_LedVolumeLive")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|