import matplotlib.pyplot as plt

# set texture/plot dimensions and dpi, ensure dpi is a float !
width = 1024
height = 1024
dpi = 72.0

# create a new figure with the specified sizes
fig = plt.figure(1)
fig.set_dpi(dpi)
fig.set_figwidth(width/dpi)
fig.set_figheight(height/dpi)

# plot a simple graph with a label on the y axis
plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')

# draw the graph (in memory)
fig.canvas.draw()

# create a texture in memory (will be saved later)
texture = ue.create_transient_texture(width, height, EPixelFormat.PF_R8G8B8A8)
# copy pixels from matplotlib canvas to the texture as RGBA
texture.texture_set_data(fig.canvas.buffer_rgba())

# save the texture
texture.save_package('/Game/FirstGraphTexture')

# open its editor
ue.open_editor_for_asset(texture)
Beispiel #2
0
# link variables
intensity_node.node_find_pin('intensity').make_link_to(
    directional_light_set_intensity.node_find_pin('NewIntensity'))
directional_light_node.node_find_pin('Directional_light').make_link_to(
    directional_light_set_intensity.node_find_pin('self'))


# a commodity function for finding an event node
def get_event_node(event_name):
    for node in bp.UberGraphPages[0].Nodes:
        if node.is_a(K2Node_Event):
            if node.EventReference.MemberName == event_name:
                return node


# get the ReceiveBeginPlay event node
begin_play_node = get_event_node('ReceiveBeginPlay')

# link BeginPlay to SetIntensity
begin_play_node.node_find_pin('then').make_link_to(
    directional_light_set_intensity.node_find_pin('execute'))

# compile the blueprint
ue.compile_blueprint(bp)

# open related editor
ue.open_editor_for_asset(bp)

# spawn it
ue.get_editor_world().actor_spawn(bp.GeneratedClass)
        x = numpy.interp(t, keys, x_values)
        y = numpy.interp(t, keys, y_values)
        z = numpy.interp(t, keys, z_values)
        return FVector(x, y, z)

    def interpolate_quaternion(self, timeline, t):
        keys = []
        x_values = []
        y_values = []
        z_values = []
        w_values = []
        for key, value in timeline:
            keys.append(key)
            x_values.append(value[0])
            y_values.append(value[1])
            z_values.append(value[2])
            w_values.append(value[3])

        x = numpy.interp(t, keys, x_values)
        y = numpy.interp(t, keys, y_values)
        z = numpy.interp(t, keys, z_values)
        w = numpy.interp(t, keys, w_values)
        return FQuat(x, y, z, w)


filename = ue.open_file_dialog('Choose a three.js file')[0]

threejs = ThreeJSLoader(filename, 100)

ue.open_editor_for_asset(threejs.animation)
variable.DefaultValue = '17,22,30|30,60,90|1,1,1'

new_struct.struct_add_variable(variable)


variable = StructVariableDescription()
variable.VarName = 'ADictionary'
variable.FriendlyName = 'A Dictionary'
variable.ToolTip = 'A Dictionary'
variable.Category = 'string'
variable.ContainerType = EPinContainerType.Map
# the dictionary value type must be specified with a EdGraphTerminalType struct
terminal_type = EdGraphTerminalType()
terminal_type.TerminalCategory = 'float'
variable.PinValueType = terminal_type

new_guid = new_struct.struct_add_variable(variable)

new_struct.struct_move_variable_up(new_guid)
new_struct.struct_move_variable_up(new_guid)
new_struct.struct_move_variable_up(new_guid)
new_struct.struct_move_variable_up(new_guid)
new_struct.struct_move_variable_down(new_guid)

new_struct.save_package()

for description in new_struct.struct_get_variables():
    print(description.as_dict())

ue.open_editor_for_asset(new_struct)
def stereo_setup_level_bp_variable(player_sets=[]):		
	from unreal_engine.classes import KismetMathLibrary, K2Node_Timeline, K2Node_ExecutionSequence, K2Node_IfThenElse

	world = ue.get_editor_world()
	level_bp = world.CurrentLevel.get_level_script_blueprint()
	left_channel = player_sets[0]
	if len(player_sets==4):
		right_channel = player_sets[1]
	else:
		right_channel = None
		
	pin = EdGraphPinType(PinCategory='object', PinSubCategoryObject=MediaPlayer)
	left_media = ue.blueprint_add_member_variable(level_bp, left_channel.get_name(), pin, None, left_channel.get_path_name())
	right_media = ue.blueprint_add_member_variable(level_bp, right_channel.get_name(), pin, None, right_channel.get_path_name())

	uber_page = level_bp.UberGraphPages[0]

	# 添加media player节点
	# ----------------------------------------------
	y, x = uber_page.graph_get_good_place_for_new_node()
	node_left_media = uber_page.graph_add_node_variable_get(left_channel.get_name(), None, x, y)
	y, x = uber_page.graph_get_good_place_for_new_node()
	node_right_media = uber_page.graph_add_node_variable_get(right_channel.get_name(), None, x, y)

	# 添加open source节点
	# ----------------------------------------------
	y, x = uber_page.graph_get_good_place_for_new_node()
	node_open_source_L = uber_page.graph_add_node_call_function(MediaPlayer.OpenSource, x, y)
	y, x = uber_page.graph_get_good_place_for_new_node()
	node_open_source_R = uber_page.graph_add_node_call_function(MediaPlayer.OpenSource, x, y)

	# 连接media source,没办法单独的设置资源,只能通过变量来设置
	# ----------------------------------------------
	pin = EdGraphPinType(PinCategory='object', PinSubCategoryObject=FileMediaSource)
	ue.blueprint_add_member_variable(level_bp, player_sets[2].get_name(), pin, None, player_sets[2].get_path_name())
	pin = EdGraphPinType(PinCategory='object', PinSubCategoryObject=FileMediaSource)
	ue.blueprint_add_member_variable(level_bp, player_sets[3].get_name(), pin, None, player_sets[3].get_path_name())

	c = uber_page.graph_add_node_variable_get(player_sets[2].get_name(), None, x, y)
	d = uber_page.graph_add_node_variable_get(player_sets[3].get_name(), None, x, y)

	pin1=c.node_find_pin(player_sets[2].get_name())
	pin2=node_open_source_L.node_find_pin("MediaSource")
	pin1.make_link_to(pin2)
	pin1=d.node_find_pin(player_sets[3].get_name())
	pin2=node_open_source_R.node_find_pin("MediaSource")
	pin1.make_link_to(pin2)

	# 添加>=节点, call_function的函数名可以大写也可以小写,直接按照C++文档的来就可以
	# ----------------------------------------------
	y, x = uber_page.graph_get_good_place_for_new_node()
	node_greater = uber_page.graph_add_node_call_function(KismetMathLibrary.EqualEqual_FloatFloat, x, y)
	
	# 添加branch节点
	# ----------------------------------------------
	i = K2Node_IfThenElse()
	y, x = uber_page.graph_get_good_place_for_new_node()
	node_branch = uber_page.graph_add_node(i, x, y)

	# 连接节点
	# ----------------------------------------------
	pin1 = node_greater.node_find_pin("ReturnValue")
	pin2 = node_branch.node_find_pin("Condition")
	pin1.make_link_to(pin2)

	pin1 = node_left_media.node_find_pin(left_channel.get_name())
	pin2 = node_open_source_L.node_find_pin('self')
	pin1.make_link_to(pin2)

	pin1 = node_right_media.node_find_pin(right_channel.get_name())
	pin2 = node_open_source_R.node_find_pin('self')
	pin1.make_link_to(pin2)

	pin1 = node_open_source_L.node_find_pin("then")
	pin2 = node_open_source_R.node_find_pin("execute")
	pin1.make_link_to(pin2)

	pin1 = node_branch.node_find_pin("Then")
	pin2 = node_open_source_L.node_find_pin("execute")
	pin1.make_link_to(pin2)

	# compile the blueprint
	ue.compile_blueprint(level_bp)

	# open related editor
	ue.open_editor_for_asset(level_bp)
	return node_branch.node_find_pin, node_greater.node_find_pin("A")
import time

factory = CurveFloatFactory()

curve = factory.factory_create_new('/Game/CustomFloatCurve' + str(int(time.time())))

keys = []

for i in range(0, 100):
    keys.append(RichCurveKey(Time=i, Value=i))

curve.FloatCurve.Keys = keys

curve.post_edit_change()

ue.open_editor_for_asset(curve)

factory = CurveVectorFactory()

curve = factory.factory_create_new('/Game/CustomVectorCurve' + str(int(time.time())))

# one curve list for each axis
keys_x = []
keys_y = []
keys_z = []

for i in range(0, 100):
    keys_x.append(RichCurveKey(Time=i * 0.1, Value=i * 0.1))
    keys_y.append(RichCurveKey(Time=i * 0.1, Value=i * 0.1))
    keys_z.append(RichCurveKey(Time=i * 0.1, Value=i * 0.1))
        x = numpy.interp(t, keys, x_values)
        y = numpy.interp(t, keys, y_values)
        z = numpy.interp(t, keys, z_values)
        return FVector(x, y, z)

    def interpolate_quaternion(self, timeline, t):
        keys = []
        x_values = []
        y_values = []
        z_values = []
        w_values = []
        for key, value in timeline:
            keys.append(key)
            x_values.append(value[0])
            y_values.append(value[1])
            z_values.append(value[2])
            w_values.append(value[3])

        x = numpy.interp(t, keys, x_values)
        y = numpy.interp(t, keys, y_values)
        z = numpy.interp(t, keys, z_values)
        w = numpy.interp(t, keys, w_values)
        return FQuat(x, y, z, w)


filename = ue.open_file_dialog('Choose a three.js file')[0]

threejs = ThreeJSLoader(filename, 100)

ue.open_editor_for_asset(threejs.animation)
variable.SubCategoryObject = Transform
variable.DefaultValue = '17,22,30|30,60,90|1,1,1'

new_struct.struct_add_variable(variable)

variable = StructVariableDescription()
variable.VarName = 'ADictionary'
variable.FriendlyName = 'A Dictionary'
variable.ToolTip = 'A Dictionary'
variable.Category = 'string'
variable.ContainerType = EPinContainerType.Map
# the dictionary value type must be specified with a EdGraphTerminalType struct
terminal_type = EdGraphTerminalType()
terminal_type.TerminalCategory = 'float'
variable.PinValueType = terminal_type

new_guid = new_struct.struct_add_variable(variable)

new_struct.struct_move_variable_up(new_guid)
new_struct.struct_move_variable_up(new_guid)
new_struct.struct_move_variable_up(new_guid)
new_struct.struct_move_variable_up(new_guid)
new_struct.struct_move_variable_down(new_guid)

new_struct.save_package()

for description in new_struct.struct_get_variables():
    print(description.as_dict())

ue.open_editor_for_asset(new_struct)
from unreal_engine.enums import EPixelFormat
import matplotlib.pyplot as plt

#Use Agg renderer
matplotlib.use('Agg')

width = 1024
height = 1024
dpi = 72.0

fig = plt.figure(1)
fig.set_dpi(dpi)
fig.set_figwidth(width / dpi)
fig.set_figheight(height / dpi)

plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')

#draw the graph in memory
fig.canvas.draw()

texture = ue.create_transient_texture(width, height, EPixelFormat.PF_R8G8B8A8)
#copy pixels from matplotlib canvas to texture as RGBA
texture.texture_set_data(fig.canvas.buffer_rgba())

#save the texture
texture.save_package('/Game/FirstGraphTexture')

#open its editor
ue.open_editor_for_asset(texture)
Beispiel #10
0
widget.modify()

widgetTree = widget.WidgetTree

slot = CanvasPanelSlot('', widgetTree)
image = Image('', widgetTree)

slot.Content = image

slot2 = CanvasPanelSlot('', widgetTree)
text_block = TextBlock('', widgetTree)
text_block.Text = 'Hello World'

slot2.Content = text_block

widgetTree.RootWidget.Slots = [slot, slot2]
widgetTree.AllWidgets = [widgetTree.RootWidget, image, text_block]

slot.LayoutData = AnchorData(
    Offsets=Margin(Left=0, Top=0, Right=300, Bottom=300))

slot2.LayoutData = AnchorData(Anchors=Anchors(Minimum=Vector2D(X=0.5, Y=0.5),
                                              Maximum=Vector2D(X=1, Y=1)))

widget.post_edit_change()

ue.compile_blueprint(widget)

ue.open_editor_for_asset(widget)
Beispiel #11
0
factory = CurveFloatFactory()

curve = factory.factory_create_new('/Game/CustomFloatCurve' +
                                   str(int(time.time())))

keys = []

for i in range(0, 100):
    keys.append(RichCurveKey(Time=i, Value=i))

curve.FloatCurve.Keys = keys

curve.post_edit_change()

ue.open_editor_for_asset(curve)

factory = CurveVectorFactory()

curve = factory.factory_create_new('/Game/CustomVectorCurve' +
                                   str(int(time.time())))

# one curve list for each axis
keys_x = []
keys_y = []
keys_z = []

for i in range(0, 100):
    keys_x.append(RichCurveKey(Time=i * 0.1, Value=i * 0.1))
    keys_y.append(RichCurveKey(Time=i * 0.1, Value=i * 0.1))
    keys_z.append(RichCurveKey(Time=i * 0.1, Value=i * 0.1))
def setup_sequence(capture):
    ue.open_editor_for_asset(ue.load_object(World, level_sequence_mappings[capture.LevelSequenceAsset.AssetPathName]))
def setup_sequence(capture):
    ue.open_editor_for_asset(ue.load_object(World, level_sequence_mappings[capture.LevelSequenceAsset.AssetPathName]))
import unreal_engine as ue
from unreal_engine.structs import EdGraphPinType

world = ue.get_editor_world()
level_bp = world.CurrentLevel.get_level_script_blueprint()
pin = EdGraphPinType(PinCategory='string')
ue.blueprint_add_member_variable(level_bp, 'TestString', pin)
ue.open_editor_for_asset(level_bp)
widget = WidgetBlueprintFactory().factory_create_new( "/Game/W_MyWidgetBlueprint" + str(int(time.time())) )

widget.modify()

widgetTree = widget.WidgetTree


slot = CanvasPanelSlot('', widgetTree)
image = Image('', widgetTree)

slot.Content = image

slot2 = CanvasPanelSlot('', widgetTree)
text_block = TextBlock('', widgetTree)
text_block.Text = 'Hello World'

slot2.Content = text_block

widgetTree.RootWidget.Slots = [slot, slot2]
widgetTree.AllWidgets = [ widgetTree.RootWidget, image, text_block ]

slot.LayoutData = AnchorData(Offsets=Margin(Left=0, Top=0, Right=300, Bottom=300))

slot2.LayoutData = AnchorData(Anchors=Anchors(Minimum=Vector2D(X=0.5, Y=0.5), Maximum=Vector2D(X=1, Y=1)))

widget.post_edit_change()

ue.compile_blueprint(widget)

ue.open_editor_for_asset(widget)
import unreal_engine as ue

from unreal_engine.classes import Material, BlueprintFactory, Blueprint, Actor, Texture2D, SkeletalMesh
from unreal_engine.structs import EdGraphPinType, Vector, Rotator, EdGraphTerminalType
from unreal_engine.enums import EPinContainerType

import time

bp = ue.create_blueprint(Actor, '/Game/FooActor' + str(int(time.time())))

pin = EdGraphPinType(PinCategory='object', PinSubCategoryObject=Material)
ue.blueprint_add_member_variable(bp, 'TestMat', pin, None, '/Engine/MapTemplates/Materials/BasicAsset03.BasicAsset03')

pin = EdGraphPinType(PinCategory='class', PinSubCategoryObject=Texture2D)
ue.blueprint_add_member_variable(bp, 'TestTextureClass', pin)

pin = EdGraphPinType(PinCategory='struct',PinSubCategoryObject=Vector)
ue.blueprint_add_member_variable(bp, 'TestVector', pin, None, '17,22,30')

pin = EdGraphPinType(PinCategory='struct',PinSubCategoryObject=Rotator,ContainerType=EPinContainerType.Array)
ue.blueprint_add_member_variable(bp, 'TestRotator', pin, None, '((Pitch=0.000000,Yaw=3.000000,Roll=0.000000),(Pitch=1.000000,Yaw=0.000000,Roll=0.000000))')

pin = EdGraphPinType(PinCategory='string',ContainerType=EPinContainerType.Map,PinValueType=EdGraphTerminalType(TerminalCategory='object',TerminalSubCategoryObject=SkeletalMesh))
ue.blueprint_add_member_variable(bp, 'TestMap', pin, None, '(("firstKey", SkeletalMesh\'"/Game/Skel001"\'),("secondKey", SkeletalMesh\'"/Game/Skel002"\'))')

ue.compile_blueprint(bp)

ue.open_editor_for_asset(bp)