示例#1
0
def select_master_material(slot_name, normal_location, opacity_location):

    if not all_opacity:
        if any(item in slot_name for item in (opacity)):
            master_mat = ue.load_object(material_class, opacity_location)

        else:
            master_mat = ue.load_object(material_class, normal_location)

    else:
        master_mat = ue.load_object(material_class, opacity_location)

    return master_mat
示例#2
0
    def create_blueprint_from_mesh(self):
        new_blueprint = ue.find_asset(self.path_to_output_asset + '/main_mesh')
        if new_blueprint is None:
            ue.log("blueprint class doesn't exists")
            new_blueprint = ue.create_blueprint(
                Character, self.path_to_output_asset + '/main_mesh')
        else:
            ue.log("blueprint class exists")
            new_blueprint = ue.find_asset(self.path_to_output_asset +
                                          '/main_mesh')
        # new_blueprint.GeneratedClass.get_cdo().Mesh.RelativeLocation = FVector(0, -200, 150)
        # new_blueprint.GeneratedClass.get_cdo().Mesh.RelativeRotation = FRotator(0, 0, 0)
        # add empty static mesh component to blueprint class
        new_blueprint.GeneratedClass.get_cdo(
        ).CapsuleComponent.CapsuleHalfHeight = 150
        new_blueprint.GeneratedClass.get_cdo(
        ).CapsuleComponent.CapsuleRadius = 50
        st_component = ue.add_component_to_blueprint(new_blueprint,
                                                     StaticMeshComponent,
                                                     'dicom_mesh')
        ue.log("self.mesh.get_name() = " + self.mesh.get_name())
        st_component.StaticMesh = ue.load_object(
            StaticMesh, self.path_to_output_asset + "/test_test")

        ue.compile_blueprint(new_blueprint)

        # saves uasset on the hard disk
        new_blueprint.save_package()

        world = ue.get_editor_world()
        new_actor = world.actor_spawn(new_blueprint.GeneratedClass,
                                      FVector(0, 0, 150))
示例#3
0
    def add_mesh_to_level(self):
        dicom_mesh_actor = self.world.actor_spawn(StaticMeshActor)
        dicom_mesh_actor.StaticMeshComponent.StaticMesh = ue.load_object(
            StaticMesh, '/Game/DicomMeshAssets/1/test')
        dicom_mesh_actor.set_actor_label('Dicom Mesh Actor')

        # mesh = ue.load_object(StaticMesh, '/Game/DicomMeshAssets/1/test')
        # obj = ue.get_editor_world().actor_spawn(StaticMeshActor)
        # obj.StaticMeshComponent.StaticMesh = self.mesh
        pass
示例#4
0
def import_texture(texture_map):

    texture_clean = clean(texture_map)

    try:
        #Check if textures exists
        ue.load_object(texture_class, xmodels_path + "textures/" + texture_clean + "." + texture_clean)

    except:
        #If it does not exist, import it. if the texture is also not avialable for import then import the missing texture
        try:
            texture_factory = TextureFactory()
            texture_factory.OverwriteYesOrNoToAllState = 2
            texture_tga = os.path.join(xmodels_directory, '_images/' + texture_map + extension)
            texture_factory.factory_import_object(texture_tga, xmodels_path + 'textures')

        except:
            texture_factory = TextureFactory()
            texture_factory.OverwriteYesOrNoToAllState = 2
            texture_tga = os.path.join(xmodels_directory, '_images/' + missing_texture)
            texture_factory.factory_import_object(texture_tga, xmodels_path + 'textures')
            ue.rename_asset(xmodels_path + "textures/" + missing_texture_name[0] + "." + missing_texture_name[0], texture_clean)
示例#5
0
    def begin_play(self):
        # open the first video capture device
        self.capture = cv2.VideoCapture(0)
        # get its size
        width = int(self.capture.get(cv2.CAP_PROP_FRAME_WIDTH))
        height = int(self.capture.get(cv2.CAP_PROP_FRAME_HEIGHT))
        # create a new texture with the desired size
        self.texture = ue.create_transient_texture(width, height, EPixelFormat.PF_R8G8B8A8)

        # assign the texture to the material mapped to the cube
        self.material = self.uobject.create_material_instance_dynamic(ue.load_object(Material, '/Game/DumbMaterial'))
        self.uobject.get_owner().StaticMeshComponent.set_material(0, self.material)
        self.material.set_material_texture_parameter('Texture', self.texture)
    def get_unreal_master_material(self,
                                   material_name: str) -> (MaterialInterface):
        """Gets an unreal material for use. If it's not already loaded, it will load it automatically and cache it for next time"""
        if material_name in self.loadedParentMaterials:
            return self.loadedParentMaterials[material_name]

        materialFullPath = "/Game/Rainbow/MasterMaterials/{matname}.{matname}".format(
            matname=material_name)
        loadedMaterial = None
        try:
            loadedMaterial = ue.load_object(MaterialInterface,
                                            materialFullPath)
        except:
            pass
        self.loadedParentMaterials[material_name] = loadedMaterial
        return loadedMaterial
示例#7
0
    def begin_play(self):
        # open the first video capture device
        self.capture = cv2.VideoCapture(0)
        # get its size
        width = int(self.capture.get(cv2.CAP_PROP_FRAME_WIDTH))
        height = int(self.capture.get(cv2.CAP_PROP_FRAME_HEIGHT))
        # create a new texture with the desired size
        self.texture = ue.create_transient_texture(width, height,
                                                   EPixelFormat.PF_R8G8B8A8)

        # assign the texture to the material mapped to the cube
        self.material = self.uobject.create_material_instance_dynamic(
            ue.load_object(Material, '/Game/DumbMaterial'))
        self.uobject.get_owner().StaticMeshComponent.set_material(
            0, self.material)
        self.material.set_material_texture_parameter('Texture', self.texture)
    def get_unreal_master_material(self,
                                   material_name: str) -> MaterialInterface:
        """Gets an unreal material for use. If it's not already loaded, it will load it automatically and cache it for next time"""
        if material_name in self.loadedParentMaterials:
            return self.loadedParentMaterials[material_name]

        materialFullPath = "/Game/Rainbow/MasterMaterials/{matname}.{matname}".format(
            matname=material_name)
        loadedMaterial = None
        try:
            loadedMaterial = ue.load_object(MaterialInterface,
                                            materialFullPath)
        except Exception:
            ue.log_warning(
                f"Failed to load material: {materialFullPath} for materialDefinition: {material_name}"
            )
            raise
        self.loadedParentMaterials[material_name] = loadedMaterial
        return loadedMaterial
示例#9
0
#Script to fill default values Spell Classes and Entries in the Spell DataTable as opposed to having to do it manually

import unreal_engine as ue
from unreal_engine.classes import DataTable
from unreal_engine.classes import Blueprint
from unreal_engine.classes import BlueprintGeneratedClass

asset_path = '/Game/RTS_Tutorial/Tables/SpellList.SpellList'
spell_asset_path = '/Game/RTS_Tutorial/Blueprints/SpellSystem/Spells'

table = ue.load_object(DataTable, asset_path)
spellAssets = ue.get_assets(spell_asset_path, True)

tableDict = table.data_table_as_dict()

ue.begin_transaction('SpellTableConfigure')

for key in tableDict.keys():
    row = tableDict[key]
    rowName = tableDict[key].get_field('name')
    rowName = rowName.replace(" ", "")
    rowName = rowName.replace("'", "")

    rowSpellAsset = None

    for spell in spellAssets:
        if spell.get_name().casefold() == rowName.casefold():
            rowSpellAsset = spell

    if rowSpellAsset:
        print('Class: ' + str(rowSpellAsset.get_class())
def setup_sequence(capture):
    ue.open_editor_for_asset(ue.load_object(World, level_sequence_mappings[capture.LevelSequenceAsset.AssetPathName]))
示例#11
0
horizontal = SHorizontalBox()

button = SButton().set_content(STextBlock().set_text('Click ME !'))
button.bind_on_mouse_button_down(clicked)
button.bind_on_clicked(clicked2)

box = SEditableTextBox()

editor = SMultiLineEditableText()
editor.set_text('Hello')

grid = SGridPanel()

grid.add_slot(button, 0, 0)
grid.add_slot(box, 0, 1)
grid.add_slot(editor, 0, 2)

horizontal.add_slot(grid, v_align=2, h_align=2).add_slot(STextBlock().set_text('Second'), v_align=2, h_align=2)

viewport = SPythonEditorViewport()

world = viewport.get_world()
bear_bp = ue.load_object(Blueprint, '/Game/Character3_Blueprint')

bear = world.actor_spawn(bear_bp.GeneratedClass)

horizontal.add_slot(viewport)

window.set_content(horizontal)
if ue.ENGINE_MINOR_VERSION >= 20:
    print(seq.MovieScene.TickResolution.Numerator)

seq.sequencer_set_playback_range(0, 30)

# add an audio track (without sound section ;) to the sequence
audio = seq.sequencer_add_master_track(MovieSceneAudioTrack)

# get a reference to the editor world (to spawn actors)
world = ue.get_editor_world()

# spawn a new character and modify it (post_edit_change will allow the editor/sequencer to be notified of actor updates)
character = world.actor_spawn(Character)
# notify modifications are about to happen...
character.modify()
character.Mesh.SkeletalMesh = ue.load_object(
    SkeletalMesh, '/Game/Mannequin/Character/Mesh/SK_Mannequin.SK_Mannequin')
# finalize the actor
character.post_edit_change()

# add to the sequencer as a possessable (shortcut method returning the guid as string)
guid = seq.sequencer_add_actor(character)

# add an animation track mapped to the just added actor
anim = seq.sequencer_add_track(MovieSceneSkeletalAnimationTrack, guid)

# create 3 animations sections (assign AnimSequence field to set the animation to play)
anim_sequence = anim.sequencer_track_add_section()
anim_sequence.sequencer_set_section_range(1, 3)
anim_sequence.Params.Animation = ue.load_object(
    AnimSequence, '/Game/Mannequin/Animations/ThirdPersonRun.ThirdPersonRun')
anim_sequence.RowIndex = 0
示例#13
0
import unreal_engine as ue
from unreal_engine.classes import Blueprint, K2Node_DynamicCast, Actor, Object
from unreal_engine.structs import EdGraphPinType
from unreal_engine.enums import EEdGraphPinDirection

bp_foo = ue.load_object(Blueprint, '/Game/Foo.Foo')
bp_bar = ue.load_object(Blueprint, '/Game/Bar.Bar')

graph = ue.blueprint_add_function(bp_foo, 'FooCaster')
func = graph.Nodes[0]

cast_node = K2Node_DynamicCast(Outer=graph)
cast_node.TargetType = bp_bar.GeneratedClass

pin_type = EdGraphPinType(PinCategory = 'object', PinSubCategoryObject=Actor)
pin = func.node_create_pin(EEdGraphPinDirection.EGPD_Input, pin_type, 'Arg001')


graph.graph_add_node(cast_node, 600, 0)

cast_node.node_find_pin('Object').category = 'object'
cast_node.node_find_pin('Object').sub_category = Object

pin.make_link_to(cast_node.node_find_pin('Object'))
func.node_find_pin('then').make_link_to(cast_node.node_find_pin('execute'))

ue.compile_blueprint(bp_foo)
 def setUp(self):
     ue.allow_actor_script_execution_in_editor(True)
     ue.begin_transaction('test')
     self.world = ue.get_editor_world()
     self.blueprint = ue.load_object(
         Blueprint, '/Game/PlotterPlatforms.PlotterPlatforms')
示例#15
0
    projectile = new_pawn.add_actor_component(ProjectileMovementComponent,
                                              'Projectile Movement')
    projectile.InitialSpeed = 173.0
    projectile.MaxSpeed = 999.9

# instantiate 10 characters with sensing component
for i in range(0, 10):
    new_character = world.actor_spawn(Character, FVector(i * 100, 0, i * 1000))
    new_character.set_actor_label("FooBarCharacter {0}".format(i))
    sensing = new_character.add_actor_component(PawnSensingComponent, 'Ears')

# add a cone
cone = world.actor_spawn(Actor)
cone.set_actor_label('A Cone')
cone_mesh = cone.add_actor_component(StaticMeshComponent, 'Cone')
cone_mesh.StaticMesh = ue.load_object(StaticMesh, '/Engine/BasicShapes/Cone')
cone.InitialLifeSpan = 30.0

# add a better cone
cone2 = world.actor_spawn(StaticMeshActor)
cone2.StaticMeshComponent.StaticMesh = ue.load_object(
    StaticMesh, '/Engine/BasicShapes/Cone')
cone2.set_actor_label('A Better Cone')

# create a new bleprint
bp = ue.create_blueprint(Pawn, '/Game/SuperEvilPawn')
ue.add_component_to_blueprint(bp, PawnSensingComponent, 'Eyes')
point_light = ue.add_component_to_blueprint(bp, PointLightComponent, 'Light')
point_light.Intensity = 9999.9
ue.blueprint_add_member_variable(bp, 'SightPower', 'float')
ue.blueprint_set_variable_visibility(bp, 'SightPower', False)
import unreal_engine as ue

from unreal_engine.classes import PyFbxFactory, Skeleton
from unreal_engine.enums import EFBXImportType

import os

base_directory = 'D:/Users/rober/Downloads/mixamo'

# get a reference to the skeleton
skeleton = ue.load_object(Skeleton, '/Game/run_Skeleton')

factory = PyFbxFactory()
factory.ImportUI.MeshTypeToImport = EFBXImportType.FBXIT_Animation
factory.ImportUI.Skeleton = skeleton

for item in os.listdir(base_directory):
    if item.endswith('.fbx'):
        animation = factory.factory_import_object(os.path.join(base_directory, item), '/Game/Mixamo002')
# create a new level sequence asset
factory = LevelSequenceFactoryNew()
seq = factory.factory_create_new('/Game/MovieMaster' + str(int(time.time())))

# add an audio track (without sound section ;) to the sequence
audio = seq.sequencer_add_master_track(MovieSceneAudioTrack)

# get a reference to the editor world (to spawn actors)
world = ue.get_editor_world()

# spawn a new character and modify it (post_edit_change will allow the editor/sequencer to be notified of actor updates)
character = world.actor_spawn(Character)
# notify modifications are about to happen...
character.modify()
character.Mesh.SkeletalMesh = ue.load_object(SkeletalMesh, '/Game/InfinityBladeAdversaries/Enemy/Enemy_Bear/Enemy_Bear.Enemy_Bear')
# finalize the actor
character.post_edit_change()

# add to the sequencer as a possessable (shortcut method returning the guid as string)
guid = seq.sequencer_add_actor(character)


# add an animation track mapped to the just added actor
anim = seq.sequencer_add_track(MovieSceneSkeletalAnimationTrack, guid)

# create 3 animations sections (assign AnimSequence field to set the animation to play)
anim_sequence = anim.sequencer_track_add_section()
anim_sequence.StartTime = 1
anim_sequence.EndTime = 3
anim_sequence.RowIndex = 0
示例#18
0
import nltk as n
import unreal_engine as ue

from unreal_engine.classes import BlueprintGeneratedClass
from unreal_engine.classes import BaseWidgetBlueprint
from unreal_engine.classes import WidgetBlueprint
from unreal_engine.classes import ButtonWidgetStyle
from unreal_engine.classes import BlueprintFunctionLibrary
from unreal_engine.classes import Widget
from unreal_engine.classes import EditableTextBox as editablebox

world = ue.get_editor_world()
widget = ue.load_object(WidgetBlueprint, '/Game/ThirdPersonBP/NPC/Player_Input.Player_Input')

widgetAssetObject = widgetAsset.cast(widget, unreal_engine.EditableTextBox)
widgetObject = cast(widget, unreal_engine.EditableTextBox)
#widgetObject = editablebox.cast(widget)
print(widgetObject.get_name())

input = widgetObject.get_text()
print(input)

#on_text_committed

#def cast(object_to_cast, object_class)
    #try:
        #return object_class.cast(object_to_cast)
    #except:
        #return None
示例#19
0
button = SButton().set_content(STextBlock().set_text('Click ME !'))
button.bind_on_mouse_button_down(clicked)
button.bind_on_clicked(clicked2)

box = SEditableTextBox()

editor = SMultiLineEditableText()
editor.set_text('Hello')

grid = SGridPanel()

grid.add_slot(button, 0, 0)
grid.add_slot(box, 0, 1)
grid.add_slot(editor, 0, 2)

horizontal.add_slot(grid, v_align=2,
                    h_align=2).add_slot(STextBlock().set_text('Second'),
                                        v_align=2,
                                        h_align=2)

viewport = SPythonEditorViewport()

world = viewport.get_world()
bear_bp = ue.load_object(Blueprint, '/Game/Character3_Blueprint')

bear = world.actor_spawn(bear_bp.GeneratedClass)

horizontal.add_slot(viewport)

window.set_content(horizontal)
def setup_sequence(capture):
    ue.open_editor_for_asset(ue.load_object(World, level_sequence_mappings[capture.LevelSequenceAsset.AssetPathName]))
示例#21
0
if os.path.isfile(xmodels_directory + "/" + str(prop_clean["Name"]) + "/" + str(prop_clean["Name"]) + "_LOD0.obj"):
    LOD0 = "_LOD0"

unknown_prop_number = 0
#Start importing
for model in props:

    prop_name = model['Name']


    if model["Name"].endswith("_missing"):
        prop_name = model["Name"][:model['Name'].rfind("_missing")]

    if not prop_name == 'None':
        try:
            ue.load_object(mesh_class, xmodels_path + "xmodels/" + prop_name + "." + prop_name)

        except:
            fbx_factory = PyFbxFactory()

            # build the path for the fbx file
            if model["Name"].endswith("_missing"):
                assets_dir = os.path.join(os.path.expanduser(xmodels_directory), error_object_name[0])
                obj = os.path.join(assets_dir, error_object)

            else:
                assets_dir = os.path.join(os.path.expanduser(xmodels_directory), model["Name"])
                obj = os.path.join(assets_dir, model["Name"] + LOD0 + ".obj")

            # configure the factory
            fbx_factory.ImportUI.bCreatePhysicsAsset = False
if ue.ENGINE_MINOR_VERSION >= 20
    print(seq.MovieScene.TickResolution.Numerator)

seq.sequencer_set_playback_range(0, 30)

# add an audio track (without sound section ;) to the sequence
audio = seq.sequencer_add_master_track(MovieSceneAudioTrack)

# get a reference to the editor world (to spawn actors)
world = ue.get_editor_world()

# spawn a new character and modify it (post_edit_change will allow the editor/sequencer to be notified of actor updates)
character = world.actor_spawn(Character)
# notify modifications are about to happen...
character.modify()
character.Mesh.SkeletalMesh = ue.load_object(SkeletalMesh, '/Game/Mannequin/Character/Mesh/SK_Mannequin.SK_Mannequin')
# finalize the actor
character.post_edit_change()

# add to the sequencer as a possessable (shortcut method returning the guid as string)
guid = seq.sequencer_add_actor(character)


# add an animation track mapped to the just added actor
anim = seq.sequencer_add_track(MovieSceneSkeletalAnimationTrack, guid)

# create 3 animations sections (assign AnimSequence field to set the animation to play)
anim_sequence = anim.sequencer_track_add_section()
anim_sequence.sequencer_set_section_range(1, 3)
anim_sequence.Params.Animation = ue.load_object(AnimSequence, '/Game/Mannequin/Animations/ThirdPersonRun.ThirdPersonRun')
anim_sequence.RowIndex = 0
	new_pawn.set_actor_label("FooBarPawn {0}".format(i))
	projectile = new_pawn.add_actor_component(ProjectileMovementComponent, 'Projectile Movement')
	projectile.InitialSpeed = 173.0
	projectile.MaxSpeed = 999.9

# instantiate 10 characters with sensing component
for i in range(0, 10):
	new_character = world.actor_spawn(Character, FVector(i * 100, 0, i * 1000))
	new_character.set_actor_label("FooBarCharacter {0}".format(i))
	sensing = new_character.add_actor_component(PawnSensingComponent, 'Ears')

# add a cone
cone = world.actor_spawn(Actor)
cone.set_actor_label('A Cone')
cone_mesh = cone.add_actor_component(StaticMeshComponent, 'Cone')
cone_mesh.StaticMesh = ue.load_object(StaticMesh, '/Engine/BasicShapes/Cone')
cone.InitialLifeSpan = 30.0

# add a better cone
cone2 = world.actor_spawn(StaticMeshActor)
cone2.StaticMeshComponent.StaticMesh = ue.load_object(StaticMesh, '/Engine/BasicShapes/Cone')
cone2.set_actor_label('A Better Cone')

# create a new bleprint
bp = ue.create_blueprint(Pawn, '/Game/SuperEvilPawn')
ue.add_component_to_blueprint(bp, PawnSensingComponent, 'Eyes')
point_light = ue.add_component_to_blueprint(bp, PointLightComponent, 'Light')
point_light.Intensity = 9999.9
ue.blueprint_add_member_variable(bp, 'SightPower', 'float')
ue.blueprint_set_variable_visibility(bp, 'SightPower', False)
示例#24
0
from unreal_engine.classes import Blueprint
from unreal_engine import FVector, FRotator
from unreal_engine.classes import StaticMeshActor, StaticMesh
import json, os, glob, math

geo_folder = geo_directory + "\\" + geo_map + "\\"
geo_mtl_file = geo_directory + "\\" + geo_map + "\\" + geo_map + ".mtl"


xmodels_directory = geo_directory + r"\xmodels"
xmodels_json = geo_directory + "\\" + geo_map + "\\" + geo_map + "_xmodels.json"

with open(xmodels_json, 'r') as file:
    entities = json.load(file)

cube_placeholder = ue.load_object(StaticMesh, '/Engine/BasicShapes/Cube.Cube')
props_cube = ue.get_editor_world().actor_spawn(StaticMeshActor, FVector(0, 0, 0), FRotator(0, 0, 0))
props_cube.StaticMeshComponent.StaticMesh = cube_placeholder
props_cube.set_actor_label('props')

mesh_number = 0
last_mesh = ''


for actor in entities:

    if 'Name' in actor:

        if actor['Name'].endswith("."):
            actor['Name'] = actor['Name'][:actor['Name'].rfind(".")]
示例#25
0
import unreal_engine as ue

from unreal_engine.classes import PyFbxFactory, Skeleton
from unreal_engine.enums import EFBXImportType

import os

base_directory = 'D:/Users/rober/Downloads/mixamo'

# get a reference to the skeleton
skeleton = ue.load_object(Skeleton, '/Game/run_Skeleton')

factory = PyFbxFactory()
factory.ImportUI.MeshTypeToImport = EFBXImportType.FBXIT_Animation
factory.ImportUI.Skeleton = skeleton

for item in os.listdir(base_directory):
    if item.endswith('.fbx'):
        animation = factory.factory_import_object(os.path.join(base_directory, item), '/Game/Mixamo002')
 def setUp(self):
     ue.allow_actor_script_execution_in_editor(True)
     ue.begin_transaction('test')
     self.world = ue.get_editor_world()
     self.blueprint = ue.load_object(Blueprint, '/Game/PlotterPlatforms.PlotterPlatforms')
import unreal_engine as ue
from unreal_engine.classes import Blueprint, K2Node_DynamicCast, Actor, Object
from unreal_engine.structs import EdGraphPinType
from unreal_engine.enums import EEdGraphPinDirection

bp_foo = ue.load_object(Blueprint, '/Game/Foo.Foo')
bp_bar = ue.load_object(Blueprint, '/Game/Bar.Bar')

cast_node = K2Node_DynamicCast()
cast_node.TargetType = bp_bar.GeneratedClass

graph = ue.blueprint_add_function(bp_foo, 'FooCaster')
func = graph.Nodes[0]

pin_type = EdGraphPinType(PinCategory = 'object', PinSubCategoryObject=Actor)
pin = func.node_create_pin(EEdGraphPinDirection.EGPD_Input, pin_type, 'Arg001')


graph.graph_add_node(cast_node, 600, 0)

cast_node.node_find_pin('Object').category = 'object'
cast_node.node_find_pin('Object').sub_category = Object

pin.make_link_to(cast_node.node_find_pin('Object'))
func.node_find_pin('then').make_link_to(cast_node.node_find_pin('execute'))

ue.compile_blueprint(bp_foo)
示例#28
0
import unreal_engine as ue
from unreal_engine import FVector

from unreal_engine.classes import Actor, Pawn, Character, ProjectileMovementComponent, PawnSensingComponent, StaticMesh
from unreal_engine.classes import StaticMeshComponent, StaticMeshActor, PointLightComponent

world = ue.get_editor_world()
cone2 = world.actor_spawn(StaticMeshActor)
cone2.StaticMeshComponent.StaticMesh = ue.load_object(StaticMesh, '/Game/DicomMeshAssets/1/test')
cone2.set_actor_label('A Better Cone')