def spawn_actors(): actors = [] # Spawn a static mesh actor and assign a cylinder to its static mesh # component actor = unreal.EditorLevelLibrary.spawn_actor_from_class( unreal.StaticMeshActor, location=(0, 0, 0)) actor.static_mesh_component.set_static_mesh(get_cylinder_asset()) actor.set_actor_label('Cylinder') actor.set_actor_transform(unreal.Transform( (-200, 0, 0), (0, 0, 0), (2, 2, 2), ), sweep=False, teleport=True) actors.append(actor) # Spawn a static mesh actor and assign a cube to its static mesh # component actor = unreal.EditorLevelLibrary.spawn_actor_from_class( unreal.StaticMeshActor, location=(0, 0, 0)) actor.static_mesh_component.set_static_mesh(get_geo_asset()) actor.set_actor_label('Cube') actor.set_actor_transform(unreal.Transform( (200, 0, 100), (45, 0, 45), (2, 2, 2), ), sweep=False, teleport=True) actors.append(actor) return actors
def configure_inputs(in_wrapper): print('configure_inputs') # Unbind from the delegate in_wrapper.on_post_instantiation_delegate.remove_callable(configure_inputs) # Deprecated input functions # in_wrapper.set_input_type(0, unreal.HoudiniInputType.GEOMETRY) # in_wrapper.set_input_objects(0, (get_geo_asset(), )) # in_wrapper.set_input_type(1, unreal.HoudiniInputType.GEOMETRY) # in_wrapper.set_input_objects(1, (get_geo_asset(), )) # in_wrapper.set_input_import_as_reference(1, True) # Create a geometry input geo_input = in_wrapper.create_empty_input(unreal.HoudiniPublicAPIGeoInput) # Set the input objects/assets for this input geo_asset = get_geo_asset() geo_input.set_input_objects((geo_asset, )) # Set the transform of the input geo geo_input.set_object_transform_offset( geo_asset, unreal.Transform( (200, 0, 100), (45, 0, 45), (2, 2, 2), )) # copy the input data to the HDA as node input 0 in_wrapper.set_input_at_index(0, geo_input) # We can now discard the API input object geo_input = None # Create a another geometry input geo_input = in_wrapper.create_empty_input(unreal.HoudiniPublicAPIGeoInput) # Set the input objects/assets for this input (cylinder in this case) geo_asset = get_cylinder_asset() geo_input.set_input_objects((geo_asset, )) # Set the transform of the input geo geo_input.set_object_transform_offset( geo_asset, unreal.Transform( (-200, 0, 0), (0, 0, 0), (2, 2, 2), )) # copy the input data to the HDA as input parameter 'objpath1' in_wrapper.set_input_parameter('objpath1', geo_input) # We can now discard the API input object geo_input = None # Set the subnet_test HDA to output its first input in_wrapper.set_int_parameter_value('enable_geo', 1)
def transform_from_usd_transform(self, usd_transform, unit_scale=1.0, up_axis='y', extra_rotate=None): transform = None if up_axis == 'z': transform = TransformAttributes.convert_rotation_from_usd_z_up( usd_transform).transform() elif up_axis == 'y': transform = TransformAttributes.convert_rotation_from_usd_y_up( usd_transform).transform() # Cameras/Lights in unreal may face a different direction if extra_rotate != None and not extra_rotate.is_identity(): t = unreal.Transform() t.rotation = extra_rotate transform.translation = unreal.MathLibrary.transform_location( t, transform.translation) transform.rotation = extra_rotate * transform.rotation transform.translation.x *= unit_scale transform.translation.y *= unit_scale transform.translation.z *= unit_scale return transform
def run(): # get the API singleton api = unreal.HoudiniPublicAPIBlueprintLib.get_api() global _g_wrapper1, _g_wrapper2 # instantiate the input HDA with auto-cook enabled _g_wrapper1 = api.instantiate_asset(get_pig_head_hda(), unreal.Transform()) # instantiate the copy curve HDA _g_wrapper2 = api.instantiate_asset(get_copy_curve_hda(), unreal.Transform()) # Configure inputs on_post_instantiation, after instantiation, but before first cook _g_wrapper2.on_post_instantiation_delegate.add_callable(configure_inputs) # Print the input state after the cook and output creation. _g_wrapper2.on_post_processing_delegate.add_callable(print_inputs)
def deferredSpawnActor(): world = unreal.EditorLevelLibrary.get_editor_world() # ! blueprint actor actor_class = unreal.EditorAssetLibrary.load_blueprint_class( '/Game/BluePrint/bp_actor') actor_location = unreal.Vector(random.uniform(0.0, 2000.0), random.uniform(0.0, 2000.0), 0.0) actor_rotation = unreal.Rotator(random.uniform(0.0, 360.0), random.uniform(0.0, 360.0), random.uniform(0.0, 360.0)) actor_scale = unreal.Vector(random.uniform(0.1, 2.0), random.uniform(0.1, 2.0), random.uniform(0.1, 2.0)) actor_transform = unreal.Transform(actor_location, actor_rotation, actor_scale) # ! "GameplayStatics.begin_spawning_actor_from_class()" is deprecated. Use BeginDeferredActorSpawnFromClass instead. # actor = unreal.GameplayStatics.begin_spawning_actor_from_class(world, actor_class, actor_transform) # unreal.GameplayStatics.finish_spawning_actor(actor, actor_transform) actor = unreal.EditorCppLib.begin_spawn_actor(world, actor_class, actor_transform) unreal.EditorCppLib.finish_spawn_actor(actor, actor_transform) # import EditorFunction_1 as ef # reload(ef) # ef.executeSlowTask()
def _set_inputs(self, in_wrapper): """ Configure our inputs: input 0 is a cube and input 1 a helix. """ # Create an empty geometry input geo_input = in_wrapper.create_empty_input(unreal.HoudiniPublicAPIGeoInput) # Load the cube static mesh asset cube = unreal.load_object(None, '/Engine/BasicShapes/Cube.Cube') # Set the input object array for our geometry input, in this case containing only the cube geo_input.set_input_objects((cube, )) # Set the input on the instantiated HDA via the wrapper in_wrapper.set_input_at_index(0, geo_input) # Create a curve input curve_input = in_wrapper.create_empty_input(unreal.HoudiniPublicAPICurveInput) # Create a curve wrapper/helper curve_object = unreal.HoudiniPublicAPICurveInputObject(curve_input) # Make it a Nurbs curve curve_object.set_curve_type(unreal.HoudiniPublicAPICurveType.NURBS) # Set the points of the curve, for this example we create a helix # consisting of 100 points curve_points = [] for i in range(100): t = i / 20.0 * math.pi * 2.0 x = 100.0 * math.cos(t) y = 100.0 * math.sin(t) z = i curve_points.append(unreal.Transform([x, y, z], [0, 0, 0], [1, 1, 1])) curve_object.set_curve_points(curve_points) # Set the curve wrapper as an input object curve_input.set_input_objects((curve_object, )) # Copy the input data to the HDA as node input 1 in_wrapper.set_input_at_index(1, curve_input) # unbind from the delegate, since we are done with setting inputs in_wrapper.on_post_instantiation_delegate.remove_function(self, '_set_inputs')
def capture(self, deltatime): """ Render the scene out of the selected camera viewport for every frame's track. :param deltatime: time tick of each frame on the engine's renderer :type deltatime: float """ try: frame_pos = next(self.positions) x = frame_pos[2] y = frame_pos[0] z = frame_pos[1] r1 = frame_pos[3] * 180.0 r2 = frame_pos[4] * 180.0 r3 = frame_pos[5] * 180.0 transformation = unreal.Transform(location=[x, y, z], rotation=[r1, r2, r3], scale=[0.0, 0.0, 0.0]) self.camera_actor.set_actor_transform(transformation, False, False) unreal.EditorLevelLibrary.pilot_level_actor(camera_actor) unreal.AutomationLibrary.take_high_res_screenshot( 1920, 1080, "shot" + str(self.frame_index) + ".png") unreal.EditorLevelLibrary.eject_pilot_level_actor() self.frame_index += 1 except Exception as error: print(error) unreal.unregister_slate_pre_tick_callback(self.on_pre_tick)
def get_socket_transform(socket): """ Convenience method for getting a sockets transform. :param Socket socket: The socket to get the transform for. :return: Returns the sockets transform as an unreal Transform object. :rtype: Transform """ return unreal.Transform(socket.relative_location, socket.relative_rotation, socket.relative_scale)
def run(): # get the API singleton api = unreal.HoudiniPublicAPIBlueprintLib.get_api() global _g_wrapper # instantiate an asset with auto-cook enabled _g_wrapper = api.instantiate_asset(get_test_hda(), unreal.Transform()) # Bind on_post_instantiation (before the first cook) callback to set parameters _g_wrapper.on_post_instantiation_delegate.add_callable( on_post_instantiation)
def run(): # get the API singleton api = unreal.HoudiniPublicAPIBlueprintLib.get_api() global _g_wrapper # instantiate an asset with auto-cook enabled _g_wrapper = api.instantiate_asset(get_test_hda(), unreal.Transform()) # Bind to the on post processing delegate (after a cook and after all # outputs have been generated in Unreal) _g_wrapper.on_post_processing_delegate.add_callable(on_post_process)
def configure_inputs(in_wrapper): print('configure_inputs') # Unbind from the delegate in_wrapper.on_post_instantiation_delegate.remove_callable(configure_inputs) # Create a geo input geo_input = in_wrapper.create_empty_input(unreal.HoudiniPublicAPIGeoInput) # Set the input objects/assets for this input geo_object = get_geo_asset() if not geo_input.set_input_objects((geo_object, )): # If any errors occurred, get the last error message print('Error on geo_input: {0}'.format( geo_input.get_last_error_message())) # copy the input data to the HDA as node input 0 in_wrapper.set_input_at_index(0, geo_input) # We can now discard the API input object geo_input = None # Create a curve input curve_input = in_wrapper.create_empty_input( unreal.HoudiniPublicAPICurveInput) # Create a curve wrapper/helper curve_object = unreal.HoudiniPublicAPICurveInputObject(curve_input) # Make it a Nurbs curve curve_object.set_curve_type(unreal.HoudiniPublicAPICurveType.NURBS) # Set the points of the curve, for this example we create a helix # consisting of 100 points curve_points = [] for i in range(100): t = i / 20.0 * math.pi * 2.0 x = 100.0 * math.cos(t) y = 100.0 * math.sin(t) z = i curve_points.append(unreal.Transform([x, y, z], [0, 0, 0], [1, 1, 1])) curve_object.set_curve_points(curve_points) # Error handling/message example: try to set geo_object on curve input if not curve_input.set_input_objects((geo_object, )): print( 'Error (example) while setting \'{0}\' on curve input: {1}'.format( geo_object.get_name(), curve_input.get_last_error_message())) # Set the curve wrapper as an input object curve_input.set_input_objects((curve_object, )) # Copy the input data to the HDA as node input 1 in_wrapper.set_input_at_index(1, curve_input) # We can now discard the API input object curve_input = None # Check for errors on the wrapper last_error = in_wrapper.get_last_error_message() if last_error: print('Error on wrapper during input configuration: {0}'.format( last_error))
def run(): # get the API singleton api = unreal.HoudiniPublicAPIBlueprintLib.get_api() global _g_wrapper # instantiate an asset with auto-cook enabled _g_wrapper = api.instantiate_asset(get_test_hda(), unreal.Transform()) # Configure inputs on_post_instantiation, after instantiation, but before first cook _g_wrapper.on_post_instantiation_delegate.add_callable(configure_inputs) # Bind on_post_processing, after cook + output creation _g_wrapper.on_post_processing_delegate.add_callable(print_inputs)
def run(): # get the API singleton api = unreal.HoudiniPublicAPIBlueprintLib.get_api() global _g_wrapper # instantiate an asset with auto-cook enabled _g_wrapper = api.instantiate_asset(get_test_hda(), unreal.Transform()) # Set the float and color ramps on post instantiation, before the first # cook. _g_wrapper.on_post_instantiation_delegate.add_callable(set_parameters) # Print the parameter state after the cook and output creation. _g_wrapper.on_post_processing_delegate.add_callable(print_parameters)
def run(): # get the API singleton api = unreal.HoudiniPublicAPIBlueprintLib.get_api() global _g_wrapper # instantiate an asset, disabling auto-cook of the asset _g_wrapper = api.instantiate_asset(get_test_hda(), unreal.Transform(), enable_auto_cook=False) # Bind to the on pre instantiation delegate (before the first cook) and # set parameters _g_wrapper.on_pre_instantiation_delegate.add_callable(on_pre_instantiation) # Bind to the on post processing delegate (after a cook and after all # outputs have been generated in Unreal) _g_wrapper.on_post_processing_delegate.add_callable(on_post_process)
def deferredSpawnActor(): world = unreal.EditorLevelLibrary.get_editor_world() actor_class = unreal.EditorAssetLibrary.load_blueprint_class('/Game/BluePrint/MyActor') actor_location = unreal.Vector(0.0, 0.0, 0.0) actor_rotation = unreal.Rotator(0.0, 0.0, 0.0) actor_scale = unreal.Vector(1.0, 1.0, 1.0) actor_transform = unreal.Transform(actor_location, actor_rotation, actor_scale) actor = unreal.EditorCppLib.begin_spawn_actor(world, actor_class, actor_transform) actor_tags = actor.get_editor_property('tags') actor_tags.append('My Python Tag') actor.set_editor_property('tags', actor_tags) unreal.EditorCppLib.finish_spawn_actor(actor, actor_transform) # import WorldFunctions as wf # reload(wf) # wf.spawnActor()
def run_curve_input_example(self): # Get the API instance api = unreal.HoudiniPublicAPIBlueprintLib.get_api() # Ensure we have a running session if not api.is_session_valid(): api.create_session() # Load our HDA uasset example_hda = unreal.load_object(None, '/HoudiniEngine/Examples/hda/copy_to_curve_1_0.copy_to_curve_1_0') # Create an API wrapper instance for instantiating the HDA and interacting with it wrapper = api.instantiate_asset(example_hda, instantiate_at=unreal.Transform()) if wrapper: # Pre-instantiation is the earliest point where we can set parameter values wrapper.on_pre_instantiation_delegate.add_function(self, '_set_initial_parameter_values') # Jumping ahead a bit: we also want to configure inputs, but inputs are only available after instantiation wrapper.on_post_instantiation_delegate.add_function(self, '_set_inputs') # Jumping ahead a bit: we also want to print the outputs after the node has cook and the plug-in has processed the output wrapper.on_post_processing_delegate.add_function(self, '_print_outputs') self.set_editor_property('_asset_wrapper', wrapper)
def ZeroSelectedElementsInitialTransfrom(rig): """ Set selected rig elements' intial transform to default :param rig: The control rig object :type rig: unreal.ControlRigBlueprint :return: Nothing :rtype: None """ hierarchy_mod = rig.get_hierarchy_modifier() selection = hierarchy_mod.get_selection() for item in selection: updated_xform = unreal.Transform(location=[0, 0, 0], rotation=[0, 0, 0], scale=[1, 1, 1]) hierarchy_mod.set_initial_global_transform(item, updated_xform)
def configure_inputs(in_wrapper): print('configure_inputs') # Unbind from the delegate in_wrapper.on_post_instantiation_delegate.remove_callable(configure_inputs) # Create a geo input asset_input = in_wrapper.create_empty_input( unreal.HoudiniPublicAPIAssetInput) # Set the input objects/assets for this input # asset_input.set_input_objects((_g_wrapper1.get_houdini_asset_actor().houdini_asset_component, )) asset_input.set_input_objects((_g_wrapper1, )) # copy the input data to the HDA as node input 0 in_wrapper.set_input_at_index(0, asset_input) # We can now discard the API input object asset_input = None # Create a curve input curve_input = in_wrapper.create_empty_input( unreal.HoudiniPublicAPICurveInput) # Create a curve wrapper/helper curve_object = unreal.HoudiniPublicAPICurveInputObject(curve_input) # Make it a Nurbs curve curve_object.set_curve_type(unreal.HoudiniPublicAPICurveType.NURBS) # Set the points of the curve, for this example we create a helix # consisting of 100 points curve_points = [] for i in range(10): t = i / 10.0 * math.pi * 2.0 x = 100.0 * math.cos(t) y = 100.0 * math.sin(t) z = i * 10.0 curve_points.append(unreal.Transform([x, y, z], [0, 0, 0], [1, 1, 1])) curve_object.set_curve_points(curve_points) # Set the curve wrapper as an input object curve_input.set_input_objects((curve_object, )) # Copy the input data to the HDA as node input 1 in_wrapper.set_input_at_index(1, curve_input) # We can now discard the API input object curve_input = None
def build_inputs(): print('configure_inputs') # get the API singleton houdini_api = unreal.HoudiniPublicAPIBlueprintLib.get_api() node_inputs = {} # Create a geo input geo_input = houdini_api.create_empty_input(unreal.HoudiniPublicAPIGeoInput) # Set the input objects/assets for this input geo_object = get_geo_asset() geo_input.set_input_objects((geo_object, )) # store the input data to the HDA as node input 0 node_inputs[0] = geo_input # Create a curve input curve_input = houdini_api.create_empty_input( unreal.HoudiniPublicAPICurveInput) # Create a curve wrapper/helper curve_object = unreal.HoudiniPublicAPICurveInputObject(curve_input) # Make it a Nurbs curve curve_object.set_curve_type(unreal.HoudiniPublicAPICurveType.NURBS) # Set the points of the curve, for this example we create a helix # consisting of 100 points curve_points = [] for i in range(100): t = i / 20.0 * math.pi * 2.0 x = 100.0 * math.cos(t) y = 100.0 * math.sin(t) z = i curve_points.append(unreal.Transform([x, y, z], [0, 0, 0], [1, 1, 1])) curve_object.set_curve_points(curve_points) # Set the curve wrapper as an input object curve_input.set_input_objects((curve_object, )) # Store the input data to the HDA as node input 1 node_inputs[1] = curve_input return node_inputs
def spawnBlueprintActor(path='', actor_location=None, actor_rotation=None, actor_scale=None, world=None, properties={}): actor_class = unreal.EditorAssetLibrary.load_blueprint_class(path) actor_transform = unreal.Transform(actor_location, actor_rotation, actor_scale) world = world if world is not None else unreal.EditorLevelLibrary.get_editor_world( ) # Make sure to have a valid world # Begin Spawn actor = unreal.GameplayStatics.begin_spawning_actor_from_class( world_context_object=world, actor_class=actor_class, spawn_transform=actor_transform, no_collision_fail=True) # Edit Properties for x in properties: actor.set_editor_property(x, properties[x]) # Complete Spawn unreal.GameplayStatics.finish_spawning_actor( actor=actor, spawn_transform=actor_transform) return actor
varCam = unreal.Variant() varCam.set_display_text("From cam") varViewport = unreal.Variant() varViewport.set_display_text("From viewport") lvs.add_variant_set(var_set1) var_set1.add_variant(varTexture) var_set1.add_variant(varPath) var_set1.add_variant(varCam) var_set1.add_variant(varViewport) # Set thumbnail from an unreal texture texture = import_texture("C:\\Path\\To\\Image.jpg", "/Game/Textures") if texture: varTexture.set_thumbnail_from_texture(texture) var_set1.set_thumbnail_from_texture(texture) # Set thumbnail directly from a filepath varPath.set_thumbnail_from_file("C:\\Path\\To\\Image.png") # Set thumbnail from camera transform and properties trans = unreal.Transform() fov = 50 minZ = 50 gamma = 2.2 varCam.set_thumbnail_from_camera(lvs_actor, trans, fov, minZ, gamma) # Set thumbnail directly from the active editor viewport varViewport.set_thumbnail_from_editor_viewport()
unreal.AttachmentRule.KEEP_WORLD, unreal.AttachmentRule.KEEP_WORLD, unreal.AttachmentRule.KEEP_WORLD, False) # delete unnecessary nodes actors_to_delete = [ a for a in [old_actor] + get_actor_hierarchy(old_actor) if a.__class__ != unreal.StaticMeshActor ] for delete_actor in actors_to_delete: print("deleting actor " + delete_actor.get_actor_label()) unreal.EditorLevelLibrary.destroy_actor(delete_actor) continue print("merging all static meshes under " + actor.get_actor_label()) backup_transform = actor.get_actor_transform() actor.set_actor_transform(unreal.Transform(), False, False) cleaned_actor_name = re.sub('[^-a-zA-Z0-9_]+', '_', actor.get_actor_label()) new_path_name = content_folder + cleaned_actor_name print("new path name " + new_path_name) merge_options = unreal.EditorScriptingMergeStaticMeshActorsOptions() merge_options.base_package_name = new_path_name merge_options.destroy_source_actors = False merge_options.mesh_merging_settings.bake_vertex_data_to_mesh = False merge_options.mesh_merging_settings.computed_light_map_resolution = False merge_options.mesh_merging_settings.generate_light_map_uv = False merge_options.mesh_merging_settings.lod_selection_type = unreal.MeshLODSelectionType.ALL_LO_DS # only if single LOD level is merged # merge_options.mesh_merging_settings.lod_selection_type = unreal.MeshLODSelectionType.SPECIFIC_LOD
def create_rig_element_key(rig, key_type): """ Given a RigElementType, add desired rig element to the rig with specific identifier. If there are selected rig elements, this will add desired rig element with selected transforms and name attached. :param rig: The rig we are looking at :type rig: unreal.ControlRigBlueprint :param key_type: enum value of Rig Element Type :type key_type: unreal.RigElementType value :return: A list of the selected object :rtype: list[unreal.RigElementKey] | list[] """ element_list = [] if key_type == unreal.RigElementType.BONE: type_name = "bone" elif key_type == unreal.RigElementType.SPACE: type_name = "space" elif key_type == unreal.RigElementType.CONTROL: type_name = "ctrl" elif key_type == unreal.RigElementType.CURVE: type_name = "curve" elif key_type == unreal.RigElementType.NONE or key_type == unreal.RigElementType.ALL: return element_list hierarchy_mod = rig.get_hierarchy_modifier() selection = hierarchy_mod.get_selection() if not selection: global_xform = unreal.Transform() element_name = type_name element = add_element_with_init_transform(hierarchy_mod, element_name, key_type, global_xform) element_list.append(element) for item in selection: global_xform = hierarchy_mod.get_global_transform(item) element_name = "{0}_{1}".format(item.get_editor_property("Name"), type_name) element = add_element_with_init_transform(hierarchy_mod, element_name, key_type, global_xform) element_list.append(element) return element_list
def __init__( self, houdini_asset, instantiate_at=unreal.Transform(), parameters=None, node_inputs=None, parameter_inputs=None, world_context_object=None, spawn_in_level_override=None, enable_auto_cook=True, enable_auto_bake=False, bake_directory_path="", bake_method=unreal.HoudiniEngineBakeOption.TO_ACTOR, remove_output_after_bake=False, recenter_baked_actors=False, replace_previous_bake=False, delete_instantiated_asset_on_completion_or_failure=False): """ Instantiates an HDA in the specified world/level. Sets parameters and inputs supplied in InParameters, InNodeInputs and parameter_inputs. If bInEnableAutoCook is true, cooks the HDA. If bInEnableAutoBake is true, bakes the cooked outputs according to the supplied baking parameters. This all happens asynchronously, with the various output pins firing at the various points in the process: - PreInstantiation: before the HDA is instantiated, a good place to set parameter values before the first cook (parameter values from ``parameters`` are automatically applied at this point) - PostInstantiation: after the HDA is instantiated, a good place to set/configure inputs before the first cook (inputs from ``node_inputs`` and ``parameter_inputs`` are automatically applied at this point) - PostAutoCook: right after a cook - PreProcess: after a cook but before output objects have been created/processed - PostProcessing: after output objects have been created - PostAutoBake: after outputs have been baked - Completed: upon successful completion (could be PostInstantiation if auto cook is disabled, PostProcessing if auto bake is disabled, or after PostAutoBake if auto bake is enabled). - Failed: If the process failed at any point. Args: houdini_asset (HoudiniAsset): The HDA to instantiate. instantiate_at (Transform): The Transform to instantiate the HDA with. parameters (Map(Name, HoudiniParameterTuple)): The parameters to set before cooking the instantiated HDA. node_inputs (Map(int32, HoudiniPublicAPIInput)): The node inputs to set before cooking the instantiated HDA. parameter_inputs (Map(Name, HoudiniPublicAPIInput)): The parameter-based inputs to set before cooking the instantiated HDA. world_context_object (Object): A world context object for identifying the world to spawn in, if spawn_in_level_override is null. spawn_in_level_override (Level): If not nullptr, then the HoudiniAssetActor is spawned in that level. If both spawn_in_level_override and world_context_object are null, then the actor is spawned in the current editor context world's current level. enable_auto_cook (bool): If true (the default) the HDA will cook automatically after instantiation and after parameter, transform and input changes. enable_auto_bake (bool): If true, the HDA output is automatically baked after a cook. Defaults to false. bake_directory_path (str): The directory to bake to if the bake path is not set via attributes on the HDA output. bake_method (HoudiniEngineBakeOption): The bake target (to actor vs blueprint). @see HoudiniEngineBakeOption. remove_output_after_bake (bool): If true, HDA temporary outputs are removed after a bake. Defaults to false. recenter_baked_actors (bool): Recenter the baked actors to their bounding box center. Defaults to false. replace_previous_bake (bool): If true, on every bake replace the previous bake's output (assets + actors) with the new bake's output. Defaults to false. delete_instantiated_asset_on_completion_or_failure (bool): If true, deletes the instantiated asset actor on completion or failure. Defaults to false. """ super(ProcessHDA, self).__init__() self._houdini_asset = houdini_asset self._instantiate_at = instantiate_at self._parameters = parameters self._node_inputs = node_inputs self._parameter_inputs = parameter_inputs self._world_context_object = world_context_object self._spawn_in_level_override = spawn_in_level_override self._enable_auto_cook = enable_auto_cook self._enable_auto_bake = enable_auto_bake self._bake_directory_path = bake_directory_path self._bake_method = bake_method self._remove_output_after_bake = remove_output_after_bake self._recenter_baked_actors = recenter_baked_actors self._replace_previous_bake = replace_previous_bake self._delete_instantiated_asset_on_completion_or_failure = delete_instantiated_asset_on_completion_or_failure self._asset_wrapper = None self._cook_success = False self._bake_success = False
class ControlRigBPExt(unreal.BlueprintFunctionLibrary): @unreal.ufunction(params=[unreal.ControlRigBlueprint], ret=unreal.Array(unreal.RigElementKey), static=True, meta=dict(Category="Control Rig Blueprint Ext")) def GetSelectedControls(rig): """ Returns the controls that are selected in the hierarchy panel. These return in a first-in/last-out manner :param rig: The rig we are looking at :type rig: unreal.ControlRigBlueprint :return: A list of the selected object :rtype: list[unreal.RigElementKey] """ return rig.get_hierarchy_modifier().get_selection() @unreal.ufunction(params=[unreal.ControlRigBlueprint, unreal.Name], ret=unreal.RigElementKey, static=True, meta=dict(Category="Control Rig Blueprint Ext")) def GetIndexByControlName(rig, control_name): """ Given a name, returns the associated RigElementKey. :param rig: The control rig object :type rig: unreal.ControlRigBlueprint :param control_name: The path of the key to query :type control_name: str :return: The RigElementKeys with the given name, if any :rtype: unreal.RigElementKey """ hierarchy_mod = rig.get_hierarchy_modifier() indexes = hierarchy_mod.get_elements() for ind in indexes: if ind.name == control_name: return ind return None @unreal.ufunction(params=[unreal.ControlRigBlueprint], static=True, meta=dict(Category="Control Rig Blueprint Ext")) def CopyPasteSelectedGlobalXform(rig): """ Given a selection, copy the global transform from the first control into the initial transform of the second control :param rig: The control rig object :type rig: unreal.ControlRigBlueprint :return: Nothing :rtype: None """ hierarchy_mod = rig.get_hierarchy_modifier() selection = hierarchy_mod.get_selection() if not len(selection) == 2: unreal.log("Not enough Control Rig controls selected") return global_xform = hierarchy_mod.get_global_transform(selection[1]) hierarchy_mod.set_initial_global_transform(selection[0], global_xform) @unreal.ufunction( params=[unreal.ControlRigBlueprint, unreal.RigElementType], ret=unreal.Array(unreal.RigElementKey), static=True, meta=dict(Category="Control Rig Blueprint Ext")) def CreateRigElement(rig, element_type): """ Given an element type, create a RigElement of that type. If any RigElement is selected, the new element will have the selected element's global transform as initial. :param rig: The control rig object :type rig: unreal.ControlRigBlueprint :return: elements :rtype: list[unreal.RigElementKey] """ elements = control_rig_utils.create_rig_element_key(rig, element_type) return elements @unreal.ufunction(params=[ unreal.ControlRigBlueprint, unreal.RigElementKey, unreal.RigElementKey ], static=True, meta=dict(Category="Control Rig Blueprint Ext")) def ParentRigElements(rig, parent, child): """ Given 2 rig elements, parent one to the other in the rig hierarchy :param rig: The control rig object :type rig: unreal.ControlRigBlueprint :param parent: The parent element :type parent: unreal.RigElementKey :param child: The child element :type child: unreal.RigElementKey :return: elements :rtype: list[unreal.RigElementKey] """ hierarchy_mod = rig.get_hierarchy_modifier() hierarchy_mod.reparent_element(child, parent) @unreal.ufunction(params=[unreal.ControlRigBlueprint], static=True, meta=dict(Category="Control Rig Blueprint Ext")) def UpdateSelectedElementsInitialTransfromFromCurrentGlobal(rig): """ Get selected rig elements, take the current transforms as the initial transforms :param rig: The control rig object :type rig: unreal.ControlRigBlueprint :return: Nothing :rtype: None """ hierarchy_mod = rig.get_hierarchy_modifier() selection = hierarchy_mod.get_selection() for item in selection: updated_xform = hierarchy_mod.get_global_transform(item) hierarchy_mod.set_initial_global_transform(item, updated_xform) @unreal.ufunction(params=[unreal.ControlRigBlueprint], static=True, meta=dict(Category="Control Rig Blueprint Ext")) def ZeroSelectedElementsInitialTransfrom(rig): """ Set selected rig elements' intial transform to default :param rig: The control rig object :type rig: unreal.ControlRigBlueprint :return: Nothing :rtype: None """ hierarchy_mod = rig.get_hierarchy_modifier() selection = hierarchy_mod.get_selection() for item in selection: updated_xform = unreal.Transform(location=[0, 0, 0], rotation=[0, 0, 0], scale=[1, 1, 1]) hierarchy_mod.set_initial_global_transform(item, updated_xform) @unreal.ufunction(params=[unreal.ControlRigBlueprint], static=True, meta=dict(Category="Control Rig Blueprint Ext")) def CopyPasteSelectedGizmos(rig): """ Copy the first selected control gizmo attributes and paste it to the second control. :param rig: The control rig object :type rig: unreal.ControlRigBlueprint :return: Nothing :rtype: None """ hierarchy_mod = rig.get_hierarchy_modifier() selection = hierarchy_mod.get_selection() if not len(selection) == 2: return src_element = control_rig_utils.cast_key_to_type(rig, selection[1]) dst_element = control_rig_utils.cast_key_to_type(rig, selection[0]) if type(src_element) != unreal.RigControl and type( dst_element) != unreal.RigControl: return gizmo_name = src_element.get_editor_property("gizmo_name") gizmo_color = src_element.get_editor_property("gizmo_color") gizmo_transform = src_element.get_editor_property("gizmo_transform") gizmo_enabled = src_element.get_editor_property("gizmo_enabled") dst_element.set_editor_property("gizmo_name", gizmo_name) dst_element.set_editor_property("gizmo_color", gizmo_color) dst_element.set_editor_property("gizmo_transform", gizmo_transform) dst_element.set_editor_property("gizmo_enabled", gizmo_enabled) hierarchy_mod.set_control(dst_element) @unreal.ufunction(params=[unreal.ControlRigBlueprint, unreal.LinearColor], static=True, meta=dict(Category="Control Rig Blueprint Ext")) def EditGizmoColor(rig, color): """ Given a color, set selected controls' gizmo to that color :param rig: The control rig object :type rig: unreal.ControlRigBlueprint :param color: The color object :type color: unreal.LinearColor :return: Nothing :rtype: None """ hierarchy_mod = rig.get_hierarchy_modifier() selection = hierarchy_mod.get_selection() rig_elements = control_rig_utils.get_elements_by_rig_type( rig, selection, unreal.RigControl) for rig_element in rig_elements: rig_element.set_editor_property("gizmo_color", color) hierarchy_mod.set_control(rig_element) @unreal.ufunction(params=[unreal.ControlRigBlueprint, unreal.Transform()], static=True, meta=dict(Category="Control Rig Blueprint Ext")) def EditGizmoTransform(rig, transform): """ Given a transform, set selected controls' gizmo to that color :param rig: The control rig object :type rig: unreal.ControlRigBlueprint :param transform: The transform object :type transform: unreal.Transform :return: Nothing :rtype: None """ hierarchy_mod = rig.get_hierarchy_modifier() selection = hierarchy_mod.get_selection() rig_elements = control_rig_utils.get_elements_by_rig_type( rig, selection, unreal.RigControl) for rig_element in rig_elements: rig_element.set_editor_property("gizmo_transform", transform) hierarchy_mod.set_control(rig_element) @unreal.ufunction(params=[unreal.ControlRigBlueprint, bool], static=True, meta=dict(Category="Control Rig Blueprint Ext")) def EditGizmoEnabled(rig, is_enabled): """ Given a boolean, set selected controls' gizmo to that color :param rig: The control rig object :type rig: unreal.ControlRigBlueprint :param is_enabled: is gizmo enabled :type is_enabled: bool :return: Nothing :rtype: None """ hierarchy_mod = rig.get_hierarchy_modifier() selection = hierarchy_mod.get_selection() rig_elements = control_rig_utils.get_elements_by_rig_type( rig, selection, unreal.RigControl) for rig_element in rig_elements: rig_element.set_editor_property("gizmo_enabled", is_enabled) hierarchy_mod.set_control(rig_element) @unreal.ufunction(params=[unreal.ControlRigBlueprint, str], static=True, meta=dict(Category="Control Rig Blueprint Ext")) def EditGizmoName(rig, gizmo_name): """ Given a name, set selected controls' gizmo to that name :param rig: The control rig object :type rig: unreal.ControlRigBlueprint :param gizmo_name: Gizmo name :type gizmo_name: str :return: Nothing :rtype: None """ hierarchy_mod = rig.get_hierarchy_modifier() selection = hierarchy_mod.get_selection() rig_elements = control_rig_utils.get_elements_by_rig_type( rig, selection, unreal.RigControl) for rig_element in rig_elements: rig_element.set_editor_property("gizmo_name", gizmo_name) hierarchy_mod.set_control(rig_element) @unreal.ufunction(params=[unreal.ControlRigBlueprint, str, str], static=True, meta=dict(Category="Control Rig Blueprint Ext")) def SearchAndReplaceRigElementNames(rig, search_string, replace_string): """ Given a string, search for it in the selected rig elements' name and replace it with another string in the selected rig elements' name :param rig: The control rig object :type rig: unreal.ControlRigBlueprint :param search_string: search for string :type search_string: string :param replace_string: string for replace :type replace_string: string :return: Nothing :rtype: None """ hierarchy_mod = rig.get_hierarchy_modifier() selection = hierarchy_mod.get_selection() if not selection: return for item in selection: src_name = str(item.get_editor_property("name")) new_name = src_name.replace(search_string, replace_string) hierarchy_mod.rename_element(item, new_name) @unreal.ufunction(params=[unreal.ControlRigBlueprint, str, bool], static=True, meta=dict(Category="Control Rig Blueprint Ext")) def AddStringPrefixOrSuffixToSelected(rig, insert_text, is_suffix): """ Given a string, insert it at the start or end of the selected rig elements' name :param rig: The control rig object :type rig: unreal.ControlRigBlueprint :param insert_text: the insert string :type insert_text: string :param is_suffix: adding it to the end or start? :type is_suffix: bool :return: Nothing :rtype: None """ hierarchy_mod = rig.get_hierarchy_modifier() selection = hierarchy_mod.get_selection() if not selection: return for item in selection: src_name = str(item.get_editor_property("name")) new_name = "{0}_{1}".format(insert_text, src_name) if is_suffix: new_name = "{0}_{1}".format(src_name, insert_text) hierarchy_mod.rename_element(item, new_name) @unreal.ufunction(params=[unreal.ControlRigBlueprint, str, int, int], static=True, meta=dict(Category="Control Rig Blueprint Ext")) def RenameAndNumberSelectedControls(rig, name, start_number, number_padding): """ Given a name, start number, and number padding, set selected rig elements' name to a newly created name :param rig: The control rig object :type rig: unreal.ControlRigBlueprint :param name: replacement name :type name: string :param start_number: start number for numberring items :type start_number: int :param number_padding: this many digits padded for text :type number_padding: int :return: Nothing :rtype: None """ hierarchy_mod = rig.get_hierarchy_modifier() selection = hierarchy_mod.get_selection() if not selection: return x = start_number for item in selection: new_name = "{0}_{1}".format(name, str(x).zfill(number_padding)) hierarchy_mod.rename_element(item, new_name) x += 1 @unreal.ufunction(params=[unreal.ControlRigBlueprint], ret=unreal.Array(str), static=True, meta=dict(Category="Control Rig Blueprint Ext")) def GetControlGizmoListFromRig(rig): """ Get a list of gizmo names from rig :param rig: The control rig object :type rig: unreal.ControlRigBlueprint :return: Nothing :rtype: None """ gizmo_library = rig.get_editor_property("gizmo_library") gizmos = gizmo_library.get_editor_property("gizmos") gizmo_names = [] for gizmo in gizmos: gizmo_names.append(gizmo.get_editor_property("gizmo_name")) return gizmo_names
bIsNew = True else: space = key name_c = "{}_c".format(humanoidBone) key = unreal.RigElementKey(unreal.RigElementType.CONTROL, name_c) control = h_mod.get_control(key) if (control.get_editor_property('index') < 0): control = h_mod.add_control( name_c, space_name=space.name, gizmo_color=[1.0, 0.0, 0.0, 1.0], ) #h_mod.get_control(control).gizmo_transform = gizmo_trans if (24 <= boneNo & boneNo <= 53): gizmo_trans = unreal.Transform([0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.1, 0.1, 0.1]) else: gizmo_trans = unreal.Transform([0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [1, 1, 1]) if (17 <= boneNo & boneNo <= 18): gizmo_trans = unreal.Transform([0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [1, 1, 1]) cc = h_mod.get_control(control) cc.set_editor_property('gizmo_transform', gizmo_trans) cc.set_editor_property('control_type', unreal.RigControlType.ROTATOR) h_mod.set_control(cc) #h_mod.set_control_value_transform(control,gizmo_trans) bIsNew = True else: control = key