Stand-In: Python scripting
The Simplygon Unreal Engine plugin has a Blueprint library of functions which gives you the possibility to run Simplygon processes using scripts. This guide will showcase a few examples on how to use these.
TIP
The plugin provides an example script using python for doing Simplygon processing related tasks. You can find it under Content → Python → simplygon_examples.py.
Basic Stand-In usage
Below is a basic example of how you can script the creation and building of a Stand-In.
python
# Get Simplygon Blueprint Library
SBL = unreal.SimplygonBlueprintLibrary
# Get all the selected actors in the level. How to get the actors to
# create a Stand-In of is not important. Other potential ways to get the
# actors could be to find all actors with a certain tag or naming standard.
EAS = unreal.get_editor_subsystem(unreal.EditorActorSubsystem)
actors = EAS.get_selected_level_actors()
# Create a Stand-In actor from the chosen actors
standin_actor = SBL.create_standin_actor_from_actors(actors)
# Create a Far Stand-In Pipeline with a screen size of 300px and assign
# it to the Stand-In Actor
far_pipeline = unreal.StandinFarPipeline()
pipeline_settings = far_pipeline.get_editor_property("settings")
remeshing_settings = pipeline_settings.get_editor_property("remeshing_settings")
remeshing_settings.set_editor_property("on_screen_size", 300)
standin_actor.set_editor_property("Pipeline", far_pipeline)
# Build all Stand-Ins in the level and save everything
SBL.build_standin_meshes()
unreal.EditorLoadingAndSavingUtils.save_dirty_packages(True, True)
Generate Stand-In with geometry culling
The following script showcase how to get geometry culling to work from a script.
python
# Get Simplygon Blueprint Library
SBL = unreal.SimplygonBlueprintLibrary
# Get all actors tagged with either "NearStandin" or "Clipping".
# For this to work you would have had to tag the actors beforehand.
# How you get the actors for your Stand-In is not important.
EAS = unreal.get_editor_subsystem(unreal.EditorActorSubsystem)
actors = EAS.get_all_level_actors()
actors_standin = []
actors_clipping = []
for actor in actors:
if actor.actor_has_tag("NearStandin"):
actors_standin.append(actor)
elif actor.actor_has_tag("Clipping"):
actors_clipping.append(actor)
# Create Stand-In from the actors
standin_actor = SBL.create_standin_actor_from_actors(actors_standin)
# Set clipping geometry by adding Simplygon Userdata to Actor
# and add them to the Stand-In
clipping_tag = unreal.SimplygonMetaTagType.CLIPPING_GEOMETRY
for actor in actors_clipping:
SBL.add_simplygon_user_data(actor, clipping_tag)
SBL.add_actor_to_standin_actor(standin_actor, actor)
# Setup a Near pipeline which uses geometry culling
near_pipeline = unreal.StandinNearPipeline()
pipeline_settings = near_pipeline.get_editor_property("settings")
aggregation_settings = pipeline_settings.get_editor_property("aggregation_settings")
aggregation_settings.set_editor_property("enable_geometry_culling", True)
geometry_cull_settings = pipeline_settings.get_editor_property(
"geometry_culling_settings"
)
geometry_cull_settings.set_editor_property("use_clipping_geometry", True)
standin_actor.set_editor_property(
"pipeline", unreal.SimplygonStandinPipeline.cast(near_pipeline)
)
SBL.build_standin_meshes()
unreal.EditorLoadingAndSavingUtils.save_dirty_packages(True, True)