def createBlueprintScene(self): # New Asset Name try: newname = self.fbxName.partition('.')[0] if newname[0:3] == "SM_": #todo if there are any other prefixes in the future, test for them asset_name = "ASB_"+ newname[3:] h_name = "ASH_"+ newname[3:] elif newname[0:4] == "CAM_": #todo if there are any other prefixes in the future, test for them asset_name = "ASB_"+ newname[4:] h_name = "ASH_"+ newname[4:] elif newname[0:4] == "LGT_": #todo if there are any other prefixes in the future, test for them asset_name = "ASB_"+ newname[4:] h_name = "ASH_"+ newname[4:] else: asset_name = "ASB_"+ newname h_name = "ASH_"+ newname # Save Path package_path = self.UEMeshDirectory unreal.log_warning(package_path) # Derive a Class from a string path root_class = '/OVFPPlugin/generalResources/blenderToUnrealAdgBridge/B2UAdgBridge_ImportedSceneObject.B2UAdgBridge_ImportedSceneObject' root_class_generated = root_class + "_C" root_class_loaded = unreal.EditorAssetLibrary.load_asset(root_class) # Derive a BlueprintGeneratedClass from a UBlueprint # If you have a C++ class, you can replace all this with just ue.CPPCLASSNAMEHERE parent_class = unreal.get_default_object(unreal.load_object(None, root_class_generated)).get_class() # Factory Setup factory = unreal.BlueprintFactory() factory.set_editor_property("ParentClass", parent_class) # Get Asset Tools asset_tools = unreal.AssetToolsHelpers.get_asset_tools() #todo test if asset already exists. If so, do not try to create a new one? # Create Asset childBP = asset_tools.create_asset(asset_name, package_path, root_class_loaded.static_class(), factory) #bp_gc = unreal.EditorAssetLibrary.load_blueprint_class(childBP.get_path_name()) #bp_cdo = unreal.get_default_object(bp_gc) bploc = package_path + "/" + asset_name + "." + asset_name + "_C" bp_cdo = unreal.get_default_object(unreal.load_object(None, bploc)) unreal.log_warning(h_name) bp_cdo.set_editor_property('Hierarchy', unreal.load_object(None, package_path + "/" + h_name + "." + h_name)) sceneactor = unreal.EditorLevelLibrary.spawn_actor_from_class(bp_cdo.get_class(),unreal.Vector(x=0.0, y=0.0, z=0.0)) #spawn the imported geo out into the world. TODO decide if I want to test to see if there is already a scene out in the world unreal.EditorAssetLibrary.save_directory(self.UEMeshDirectory) #save directory we imported into unreal.EditorAssetLibrary.sync_browser_to_objects([bploc]) except Exception: unreal.log_warning("Issue creating ASM blueprint")
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 get_default_class_object(asset_path): # アセットのPathを"."で分ける Str = asset_path.split(".") # 分けた右側部分 + "Default__" + 分けた左側部分 + "_C"となるように文字列を生成 result_path = ".".join((Str[0], "Default__{}_C".format(Str[1]))) # 生成したデフォルトクラスオブジェクトのパスからオブジェクトを生成して返す print(result_path) return unreal.load_object(None, result_path)
def spawn_actor(location, meshpath): new_actor = unreal.EditorLevelLibrary.spawn_actor_from_class( unreal.StaticMeshActor, location=location) mesh = unreal.load_object(None, meshpath) mesh_component = new_actor.get_editor_property( "static_mesh_component") # type: ignore mesh_component.set_static_mesh(mesh) return new_actor
def create_level_sequence(asset_name, package_path='/Game/'): sequence = unreal.AssetToolsHelpers.get_asset_tools().create_asset( asset_name, package_path, unreal.LevelSequence, unreal.LevelSequenceFactoryNew()) floor = unreal.load_object(None, "/Game/NewMap.NewMap:PersistentLevel.Floor") sm_component = unreal.load_object( None, "/Game/NewMap.NewMap:PersistentLevel.Floor.StaticMeshComponent0") floor_binding = sequence.add_possessable(floor) floor_binding.add_track(unreal.MovieScene3DTransformTrack) populate_binding(sequence, floor_binding, 5) print("Floor {0} is bound as {1}".format(floor, floor_binding.get_id())) sm_component_binding = sequence.add_possessable(sm_component) sm_component_binding.add_track(unreal.MovieSceneSkeletalAnimationTrack) populate_binding(sequence, sm_component_binding, 5) print("Static mesh component {0} is bound as {1}".format( sm_component, sm_component_binding.get_id())) # Create a spawnable from the floor instance spawnable_floor_binding = sequence.add_spawnable_from_instance(floor) transform_track = spawnable_floor_binding.add_track( unreal.MovieScene3DTransformTrack) populate_track(sequence, transform_track, 5) # Create a spawnable from an actor class spawnable_camera_binding = sequence.add_spawnable_from_class( unreal.CineCameraActor) # add an infinite transform track spawnable_camera_binding.add_track( unreal.MovieScene3DTransformTrack).add_section().set_range( unreal.SequencerScriptingRange()) return sequence
def import_data_table_as_json(filename): task = unreal.AssetImportTask() task.filename = filename task.destination_path = "/Game/DataTables" task.replace_existing = True task.automated = True task.save = False task.factory = unreal.ReimportDataTableFactory() task.factory.automated_import_settings.import_row_struct = unreal.load_object(None, '/Game/DataTables/S_TestStruct.S_TestStruct') task.factory.automated_import_settings.import_type = unreal.CSVImportType.ECSV_DATA_TABLE unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([task])
def spawn_actor(location): """ Spawn a cube at a defined location :param unreal.Vector location: The location to place the cube """ new_cube = unreal.EditorLevelLibrary.spawn_actor_from_class( unreal.StaticMeshActor, location=location, ) mesh = unreal.load_object(None, MESH_TO_SPAWN) mesh_component = new_cube.get_editor_property('static_mesh_component') mesh_component.set_static_mesh(mesh) return new_cube
def create_master_level_sequence(asset_name, package_path='/Game/', num_subsequences=1, length_seconds=5): master_sequence = unreal.AssetToolsHelpers.get_asset_tools().create_asset( asset_name, package_path, unreal.LevelSequence, unreal.LevelSequenceFactoryNew()) cinematic_shot_track = master_sequence.add_master_track( unreal.MovieSceneCinematicShotTrack) camera = unreal.load_object( None, "/Game/Map.Map:PersistentLevel.CineCameraActor_1") for i in range(num_subsequences): subsequence_asset_name = 'shot_' + str(i) subsequence = unreal.AssetToolsHelpers.get_asset_tools().create_asset( subsequence_asset_name, package_path, unreal.LevelSequence, unreal.LevelSequenceFactoryNew()) # add a subsection for this subsequence subsequence_section = cinematic_shot_track.add_section() subsequence_section.set_sequence(subsequence) subsequence_section.set_start_frame_seconds(0) subsequence_section.set_end_frame_seconds(length_seconds) # add a camera cut track camera_cut_track = subsequence.add_master_track( unreal.MovieSceneCameraCutTrack) camera_cut_section = camera_cut_track.add_section() camera_cut_section.set_start_frame_seconds(0) camera_cut_section.set_end_frame_seconds(length_seconds) # add a binding for the camera camera_binding = subsequence.add_possessable(camera) transform_track = camera_binding.add_track( unreal.MovieScene3DTransformTrack) transform_section = transform_track.add_section() transform_section.set_start_frame_bounded(0) transform_section.set_end_frame_bounded(0) # add the binding for the camera cut section camera_binding_id = subsequence.make_binding_id( camera_binding, unreal.MovieSceneObjectBindingSpace.LOCAL) camera_cut_section.set_camera_binding_id(camera_binding_id) return master_sequence
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 update_table(self): data_list = self.model.get_data_list() for i, data in enumerate(data_list[:]): asset = data["asset"] try: name = asset.get_name() except: data_list.pop(i) self.update_table() return path = asset.get_path_name() search = self.Search_LE.text() replace = self.Replace_LE.text() if not unreal.load_object(None, path): data_list.pop(i) self.update_table() return if not self.RE_CB.isChecked(): search = re.escape(search) if self.Convention_CB.isChecked(): name = self.handle_convention(data) flags = re.I if self.Ignore_Case_CB.isChecked() else 0 replace, prefix, suffix = self.handle_replace(i, data, replace) try: reg = re.compile(search, flags) replace = reg.sub(replace, name) except: search = False if search and reg.search(name): data[u'新名称'] = "%s%s%s" % (prefix, replace, suffix) data["bg_color"] = QtGui.QColor("purple") else: data[u'新名称'] = "%s%s%s" % (prefix, name, suffix) data["bg_color"] = QtGui.QColor("transparent") self.model.set_data_list(data_list) self.save_settings()
def export_fbx(asset_path, destination_folder=None): task = ue.AssetExportTask() task.object = ue.load_object(None, asset_path) print("Exporting object: {0}".format(task.object)) if task.object is None: return asset_name, content_path, mirrored_path = mirrored_asset_path(asset_path) if not destination_folder: destination_folder = os.path.join(get_ue_project_root(), "AssetsFiles", "ImportFiles", mirrored_path) if not os.path.isdir(destination_folder): os.mkdir(destination_folder) filename = os.path.join(destination_folder, asset_name + ".fbx") task.automated = True task.filename = filename task.selected = False task.replace_identical = True task.prompt = False task.use_file_archive = False task.write_empty_files = False fbx_export_options = ue.FbxExportOption() fbx_export_options.collision = True fbx_export_options.fbx_export_compatibility = ue.FbxExportCompatibility.FBX_2013 fbx_export_options.force_front_x_axis = False fbx_export_options.level_of_detail = True fbx_export_options.map_skeletal_motion_to_root = False fbx_export_options.vertex_color = True task.options = fbx_export_options export_result = ue.Exporter.run_asset_export_tasks([task]) print("Export result: {0}".format(export_result)) return filename
def align_selected(self): align_actor = self.Align_LE.text() origin = unreal.load_object(None, align_actor) if origin: targets = level_lib.get_selected_level_actors() else: origin, targets = self.get_selected_actors() # NOTE 配置 undo # NOTE https://github.com/20tab/UnrealEnginePython/blob/master/docs/Transactions_API.md sys_lib.begin_transaction(TRANSCATION, "align selected", None) for target in targets: location = origin.get_actor_location() rotation = origin.get_actor_rotation() # NOTE 设置 undo target.modify(True) target.set_actor_location_and_rotation(location, rotation, False, False) # NOTE 选择 actors level_lib.set_selected_level_actors([target]) target.modify(False) sys_lib.end_transaction()
def get_geo_asset(): return unreal.load_object(None, get_geo_asset_path())
def get_test_hda(): return unreal.load_object(None, get_test_hda_path())
def get_cylinder_asset(): return unreal.load_object(None, get_cylinder_asset_path())
def get_copy_curve_hda(): return unreal.load_object(None, get_copy_curve_hda_path())
def get_pig_head_hda(): return unreal.load_object(None, get_pig_head_hda_path())
def load_settings(self): CB_list = self.findChildren(QtWidgets.QCheckBox) RB_list = self.findChildren(QtWidgets.QRadioButton) LE_list = self.findChildren(QtWidgets.QLineEdit) SP_list = self.findChildren(QtWidgets.QSpinBox) Combo_list = self.findChildren(QtWidgets.QComboBox) widget_dict = {} for B in self.check_loop(CB_list + RB_list): val = self.settings.value(B.objectName()) if val is not None: val = True if str(val).lower() == "true" else False widget_dict[B.setChecked] = val for LE in self.check_loop(LE_list): val = self.settings.value(LE.objectName()) if val is not None: widget_dict[LE.setText] = val for SP in self.check_loop(SP_list): val = self.settings.value(SP.objectName()) if val is not None: widget_dict[SP.setValue] = int(val) for Combo in self.check_loop(Combo_list): val = self.settings.value(Combo.objectName()) if val is not None: widget_dict[Combo.setCurrentIndex] = int(val) # NOTE 添加 data_list asset_data = self.settings.value("table_asset") # NOTE 批量设置属性值 for setter, val in widget_dict.items(): setter(val) if not asset_data: return actor_list = [] asset_list = [] for path in asset_data: asset = unreal.load_object(None, path) if isinstance(asset, unreal.Actor): actor_list.append(asset) elif asset_lib.does_asset_exist(path): asset_list.append(asset) data_list = self.model.get_data_list() data_list.extend([{ 'bg_color': QtGui.QColor("transparent"), 'asset': asset, u"原名称": asset.get_name(), u"新名称": "", u"文件类型": type(asset).__name__, } for asset in asset_list]) data_list.extend([{ 'bg_color': QtGui.QColor("transparent"), 'asset': actor, u"原名称": actor.get_actor_label(), u"新名称": "", u"文件类型": type(actor).__name__, } for actor in actor_list]) self.model.set_data_list(data_list) self.update_table()
from __future__ import absolute_import __author__ = 'timmyliang' __email__ = '*****@*****.**' __date__ = '2020-09-28 08:40:07' import unreal mat_lib = unreal.MaterialEditingLibrary() MP_OPACITY = unreal.MaterialProperty.MP_OPACITY BLEND_TRANSLUCENT = unreal.BlendMode.BLEND_TRANSLUCENT for material in unreal.EditorUtilityLibrary.get_selected_assets(): if not isinstance(material,unreal.Material): continue blend_mode = material.get_editor_property("blend_mode") if blend_mode != BLEND_TRANSLUCENT: continue # NOTE 这个是 第二个贴图节点 material_path = material.get_full_name().split(' ')[-1] path = "%s:MaterialExpressionTextureSample_1" % material_path texture = unreal.load_object(None,path) if not texture: print("texture None : %s" % material_path) continue mat_lib.connect_material_property(texture, "A", MP_OPACITY) unreal.MaterialEditingLibrary.recompile_material(material)
def create_actor(location): cube = unreal.EditorLevelLibrary.spawn_actor_from_class( unreal.StaticMeshActor, location=location) mesh = unreal.load_object(None, MESH_PATH)