def createGenericAsset_EXAMPLE(): base_path = '/Game/GenericAssets/' generic_assets = [ [ base_path + 'sequence', unreal.LevelSequence, unreal.LevelSequenceFactoryNew() ], [base_path + 'material', unreal.Material, unreal.MaterialFactoryNew()], [base_path + 'world', unreal.World, unreal.WorldFactory()], [ base_path + 'particle_system', unreal.ParticleSystem, unreal.ParticleSystemFactoryNew() ], [ base_path + 'paper_flipbook', unreal.PaperFlipbook, unreal.PaperFlipbookFactory() ], [ base_path + 'data_table', unreal.DataTable, unreal.DataTableFactory() ], # Will not work ] for asset in generic_assets: print createGenericAsset(asset[0], True, asset[1], asset[2])
def basic_material(name='test_mat', path='/Game', color={ 'r': 1.000000, 'g': 1.000000, 'b': 1.000000, 'a': 0 }): ''' Create a material with a Constant 3 Vector to the base color input arg: name = str, material name path = str, asset library path where the material will be located color = dict, color vector ''' assetTools = unreal.AssetToolsHelpers.get_asset_tools() material = assetTools.create_asset(asset_name=name, package_path=path, asset_class=unreal.Material, factory=unreal.MaterialFactoryNew()) loaded_yellow = unreal.EditorAssetLibrary.load_asset('{}/{}'.format( path, name)) constant_3vector = unreal.MaterialEditingLibrary.create_material_expression( material, unreal.MaterialExpressionConstant3Vector) constant_3vector.set_editor_property('constant', color) unreal.MaterialEditingLibrary.connect_material_property( constant_3vector, "", unreal.MaterialProperty.MP_BASE_COLOR) unreal.MaterialEditingLibrary.layout_material_expressions(material) unreal.MaterialEditingLibrary.recompile_material(material)
def create_material(asset_fullpath): asset = get_asset_from_path(asset_fullpath) if asset is not None: return asset else: package_path, asset_name = split_path(asset_fullpath) asset_tools = unreal.AssetToolsHelpers.get_asset_tools() factory = unreal.MaterialFactoryNew() my_new_asset = asset_tools.create_asset(asset_name, package_path, None, factory) unreal.EditorAssetLibrary.save_loaded_asset(my_new_asset) return my_new_asset
import unreal material_factory = unreal.MaterialFactoryNew() asset_tools = unreal.AssetToolsHelpers.get_asset_tools() my_new_asset = asset_tools.create_asset('Blades_Material', "/Game/Slicer/", None, material_factory) my_new_asset = asset_tools.create_asset('Body_Material', "/Game/Slicer/", None, material_factory) unreal.EditorAssetLibrary.save_loaded_asset(my_new_asset)
import unreal asset_path = "/Game/Materials/" matref = unreal.AssetToolsHelpers.get_asset_tools().create_asset( "M_Test", asset_path, unreal.Material, unreal.MaterialFactoryNew()) customNode01.set_editor_property("material_domain", "MD_SURFACE") # Attach custom expression node customNode01 = unreal.MaterialEditingLibrary.create_material_expression( matref, unreal.MaterialExpressionCustom, -400, 0) unreal.MaterialEditingLibrary.connect_material_expressions( from_expression, from_output_name, to_expression, to_input_name) customNode01.set_editor_property("description", "SampleText") customNode01.set_editor_property("desc", "Critically important information") customNode01.set_editor_property("output_type", unreal.CustomMaterialOutputType.CMOT_FLOAT1) # List of pins to attach inputpin01 = unreal.CustomInput() inputpin01.set_editor_property("input_name", "UV") inputpin02 = unreal.CustomInput() inputpin02.set_editor_property("input_name", "BlurVal") inputpin03 = unreal.CustomInput() inputpin03.set_editor_property("input_name", "No") inputpin04 = unreal.CustomInput() inputpin04.set_editor_property("input_name", "Distortion") # Inserting pins to custom expression customNode01.set_editor_property(
# Scan for texture files texturepaths = [] for file in os.listdir(inputdir): if file.startswith("texture_") and file[-4:].upper() == '.PNG': texturepaths.append(os.path.join(inputdir, file)) # import textures and set in memory textures reference data = unreal.AutomatedAssetImportData() data.set_editor_property('destination_path', asset_path + material_dir) data.set_editor_property('filenames', texturepaths) textures = unreal.AssetToolsHelpers.get_asset_tools().import_assets_automated( data) # set used tools assetTools = unreal.AssetToolsHelpers.get_asset_tools() mf = unreal.MaterialFactoryNew() for texture in textures: texturename = texture.get_name() matname = 'M_' + texturename.split('texture_')[1] # Create the new material and set property matobj = assetTools.create_asset(matname, asset_path + material_dir, unreal.Material, mf) matobj.set_editor_property('shading_model', unreal.MaterialShadingModel.MSM_DEFAULT_LIT) # Create texturesample expression, constant expression, make connections and set texture asset origin texturesample = unreal.MaterialEditingLibrary.create_material_expression( matobj, unreal.MaterialExpressionTextureSample, -384, -200) specularzero = unreal.MaterialEditingLibrary.create_material_expression(