def build_skeleton(self, pkg_name, obj_name): pkg = ue.get_or_create_package('{0}_Skeleton'.format(pkg_name)) skel = Skeleton('{0}_Skeleton'.format(obj_name), pkg) # add a root bone from which all of the others will descend # (this trick will avoid generating an invalid skeleton [and a crash], as in UE4 only one root can exist) skel.skeleton_add_bone('root', -1, FTransform()) # iterate bones in the json file, note that we move from opengl axis to UE4 # (y on top, x right, z forward right-handed) to (y right, x forward left-handed, z on top) for bone in self.model['bones']: # assume no rotation quat = FQuat() # give priority to quaternions # remember to negate x and y axis, as we invert z on position if 'rotq' in bone: quat = FQuat(bone['rotq'][2], bone['rotq'][0] * -1, bone['rotq'][1] * -1, bone['rotq'][3]) elif 'rot' in bone: quat = FRotator(bone['rot'][2], bone['rot'][0] - 180, bone['rot'][1] - 180).quaternion() pos = FVector(bone['pos'][2] * -1, bone['pos'][0], bone['pos'][1]) * self.scale # always set parent+1 as we added the root bone before skel.skeleton_add_bone(bone['name'], bone['parent'] + 1, FTransform(pos, quat)) skel.save_package() return skel
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 test_default_values(self): transform0 = FTransform() self.assertEqual( transform0.translation, FVector(0, 0, 0)) self.assertEqual( transform0.rotation.roll, 0) self.assertEqual( transform0.rotation.pitch, 0) self.assertEqual( transform0.rotation.yaw, 0) self.assertEqual( transform0.scale, FVector(1, 1, 1))
def AddSequencerSectionTransformKeysByIniFile(SequencerSection, SectionFileName, FileLoc): Config = configparser.ConfigParser() Config.read(FileLoc) for option in Config.options(SectionFileName): frame = float(option)/float(frameRateNumerator) #FrameRate list = Config.get(SectionFileName, option) list = list.split(',') transform = FTransform(FVector(float(list[0]), float(list[1]), float(list[2])), FRotator(float(list[3]), float(list[4]), float(list[5]))) SequencerSection.sequencer_section_add_key(frame,transform)
def build_new_skeleton(self, skeleton, name, root): new_skel = Skeleton(name) new_skel.skeleton_add_bone(root, -1, FTransform()) for index in range(0, skeleton.skeleton_bones_get_num()): bone_name = skeleton.skeleton_get_bone_name(index) bone_parent = skeleton.skeleton_get_parent_index(index) bone_transform = skeleton.skeleton_get_ref_bone_pose(index) if bone_parent == -1: bone_parent_name = root else: bone_parent_name = skeleton.skeleton_get_bone_name(bone_parent) new_bone_parent = new_skel.skeleton_find_bone_index(bone_parent_name) new_skel.skeleton_add_bone(bone_name, new_bone_parent, bone_transform) return new_skel
anim_sequence2.RowIndex = 1 anim_sequence2.sequencer_set_section_range(2, 5) anim_sequence3 = anim.sequencer_track_add_section() anim_sequence3.RowIndex = 1 anim_sequence3.SlotName = 'Hello' anim_sequence3.sequencer_set_section_range(0, 30) # add a transform track/section in one shot to the actor transform = seq.sequencer_add_track(MovieScene3DTransformTrack, guid).sequencer_track_add_section() transform.sequencer_set_section_range(0, 50) # add keyframes to the transform section (from 4.20 you can directly use teh reflection api, and the methods returns the frame numbers) print( transform.sequencer_section_add_key(0, FTransform(FVector(0, 0, 17 * 100)))) print( transform.sequencer_section_add_key(1.1, FTransform(FVector(0, 0, 22 * 100)))) print( transform.sequencer_section_add_key(2.2, FTransform(FVector(0, 0, 26 * 100)))) print( transform.sequencer_section_add_key(3.3, FTransform(FVector(0, 0, 30 * 100)))) # add camera cut track (can be only one) camera_cut_track = seq.sequencer_add_camera_cut_track() # add two camera views # after 4.25 overlapping camera ranges dont seem to work - or give different visualization in the Editor
anim_sequence2 = anim.sequencer_track_add_section() anim_sequence2.RowIndex = 1 anim_sequence2.sequencer_set_section_range(2, 5) anim_sequence3 = anim.sequencer_track_add_section() anim_sequence3.RowIndex = 1 anim_sequence3.SlotName = 'Hello' anim_sequence3.sequencer_set_section_range(0, 30) # add a transform track/section in one shot to the actor transform = seq.sequencer_add_track(MovieScene3DTransformTrack, guid).sequencer_track_add_section() transform.sequencer_set_section_range(0, 50) # add keyframes to the transform section (from 4.20 you can directly use teh reflection api, and the methods returns the frame numbers) print(transform.sequencer_section_add_key(0, FTransform(FVector(0, 0, 17 * 100)))) print(transform.sequencer_section_add_key(1.1, FTransform(FVector(0, 0, 22 * 100)))) print(transform.sequencer_section_add_key(2.2, FTransform(FVector(0, 0, 26 * 100)))) print(transform.sequencer_section_add_key(3.3, FTransform(FVector(0, 0, 30 * 100)))) # add camera cut track (can be only one) camera_cut_track = seq.sequencer_add_camera_cut_track() # add two camera views camera1 = camera_cut_track.sequencer_track_add_section() camera2 = camera_cut_track.sequencer_track_add_section() # spawn 2 cine cameras in the stage and posses them with the sequencer cine_camera = world.actor_spawn(CineCameraActor) camera_guid = seq.sequencer_add_actor(cine_camera)