예제 #1
0
    def __init__(self, actor, label, sz, offset, rot):
        print(actor)
        self.width = sz[0]
        self.height = sz[1]
        #print("before attach",actor.get_actor_components())
        mesh = actor.get_actor_component_by_type(SkeletalMeshComponent)

        # we need three parts, SceneCaptureActor, ATextureReader, RenderTargetTextures
        self.rendertarget = TextureRenderTarget2D()
        self.rendertarget.set_property("SizeX", self.width)
        self.rendertarget.set_property("SizeY", self.height)

        xform = FTransform()
        xform.translation = FVector(offset[0], offset[1], offset[2])
        xform.rotation = FRotator(rot[0], rot[1], rot[2])
        ue.log("vcam xlate {} rot {}".format(xform.translation,
                                             xform.rotation))
        self.scene_capture = actor.get_actor_component_by_type(
            SceneCaptureComponent2D)
        self.scene_capture.set_relative_location(offset[0], offset[1],
                                                 offset[2])
        self.scene_capture.set_relative_rotation(rot[0], rot[1], rot[2])
        self.scene_capture.set_property("TextureTarget", self.rendertarget)

        # add reader last
        self.reader = actor.add_actor_component(
            ue.find_class('ATextureReader'), label + "_rendertarget")
        self.reader.set_property('RenderTarget', self.rendertarget)
        self.reader.SetWidthHeight(sz[0], sz[1])
def refresh_class_references():
    """Called to load blueprint class references. Can be run at anytime to ensure class references are valid."""
    # pylint: disable=global-statement
    # Global statement warning disabled in this function as this is a work around for delayed loading of blueprint classes
    try:
        global bp_RoomComponent
        bp_RoomComponent = ue.find_class('BP_RoomComponent_C')
    except Exception:
        ue.log_warning(
            "Unable to load class BP_RoomComponent_C. This happens during cooking. If this is happening during gameplay something has gone wrong."
        )
예제 #3
0
 def loadAndSpawnObjects(self):
     ue.log("+++++++++++++++++++")
     ue.log("loadAndSpawnObjects")
     ue.log("checking for " + self.datapath)
     if os.path.exists(self.datapath):
         with codecs.open(self.datapath, "r", "utf-8") as f:
             data = json.loads(f.read())
             ue.log(data)
             for obj in data:
                 objclass = ue.find_class(obj["type"])
                 #ue.log(str(type(objclass))+str(objclass)+"="+obj["json"])
                 objinst = self.uobject.actor_spawn(objclass,
                                                    FVector(0, 0, 0),
                                                    FRotator(0, 0, 0))
                 jsonstr = obj["json"]
                 self.objects.append(objinst)
                 objinst.call_function("loadjson", jsonstr)
     ue.log("------------------")
예제 #4
0
all_opacity = True # I dont recommend having this as False unless you are in black ops 2.
opacity = ["grass", "foliage", "glass", "paper", "tree", "ivy", "flag", "hedge", "graffiti", "snow"]

#Some other stuff (I recommend not touching these)
missing_texture = "missing.tga"
error_object= "error.fbx"

#Script
import unreal_engine as ue
from unreal_engine.classes import Actor, Character, PyFbxFactory, TextureFactory, Material, StaticMesh
from unreal_engine.structs import StaticMaterial, MeshUVChannelInfo
import glob, os, json

#Basic/Necessary things.
mesh_class = ue.find_class("StaticMesh")
material_class = ue.find_class("Material")
texture_class = ue.find_class("Texture2D")
material_instance_class = ue.find_class("MaterialInstanceConstant")


geo_folder = geo_directory + "\\" + geo_map + "\\" # This is the folder where the map geometry is stored. Its basically the directory + the map name.
geo_mtl_file = geo_directory + "\\" + geo_map + "\\" + geo_map + ".mtl" # This is the folder where the mtl of the map geometry is stored.


xmodels_directory = geo_directory + r"\xmodels" # This is the xmodels directory.
xmodels_json = geo_directory + "\\" + geo_map + "\\" + geo_map + "_xmodels.json" #This is where the json file is stored.

geo_map_original = geo_map #Save original geo map name in case of it being changed

missing_texture_name = missing_texture.rsplit(".", 1)
예제 #5
0
    def begin_play(self):
        ue.log('Begin Play on class')
        print(tf.__version__)
        # set input
        player = GameplayStatics.GetPlayerController(self.uobject)
        self.uobject.EnableInput(player)
        self.uobject.bind_key('C', ue.IE_PRESSED, self.you_pressed_C)
        self.uobject.bind_key('M', ue.IE_PRESSED, self.you_pressed_M)

        self.bSimulation = True
        self.auto_move_mode = True

        # Load mesh as proceduralmesh
        self.Procedural_mesh = self.uobject.add_actor_root_component(ProceduralMesh.CustomProceduralMeshComponent, 'ProceduralMesh')
        self.Procedural_mesh.import_renderable(simdata_path)

        # spawn a new PyActor
        self.sphere_actor = self.uobject.actor_spawn(ue.find_class('PyActor'), FVector(0, 0, 0),FRotator(0, 0, 0))
        # add a sphere component as the root one
        self.sphere_component = self.sphere_actor.add_actor_root_component(ProceduralMesh.CustomProceduralMeshComponent, 'SphereMesh')
        # set the mesh as the Sphere asset
        self.sphere_component.import_renderable(simdatacollision_path)

        self.scale_factor = 200
        scale = self.scale_factor
        self.uobject.set_actor_scale(FVector(scale,scale,scale))
        self.uobject.set_actor_rotation(FRotator(-90, 0, 0))
        self.uobject.set_actor_location(FVector(0, 0, 0))

        self.sphere_actor.set_actor_scale(FVector(scale,scale,scale))
        self.sphere_actor.set_actor_rotation(FRotator(-90, 0, 0))
        self.sphere_actor.set_actor_location(FVector(0, 0, 0))

        # Load model
        self.model = keras.models.load_model(model_path)
        self.model.summary()


        # Load paras
        self.z = np.load(z_path)
        self.w = np.load(w_path)
        self.alpha = np.load(alpha_path)
        self.beta = np.load(beta_path)
        self.x_transform_mat = np.load(x_transform_path)
        self.x_mean = np.load(x_mean_path)
        self.y_transform_mat = np.load(y_transform_path)
        self.y_mean = np.load(y_mean_path)
        
        self.z_init_last_2 =  self.z[0, :]
        self.z_init_last_1 =  self.z[1, :]
        self.sphere_location_last = self.sphere_actor.get_actor_location()

        # select t=2, make sure t >= 2
        # input data for model [/zt;zt-1;wt]
        self.t = 0+2
        # for auto move 
        self.z_last_2_auto =  self.z[self.t-2, :]
        self.z_last_1_auto =  self.z[self.t-1, :]


        self.tick_frequency = 100
        self.elapsed_time = 0.0