Beispiel #1
0
    def add_root_to_skeleton(self, mesh, bone='root'):
        base_path = mesh.get_path_name()
        new_path = ue.create_modal_save_asset_dialog(
            'Choose destination path', ue.get_path(base_path),
            ue.get_base_filename(base_path) + '_rooted')
        if not new_path:
            raise DialogException(
                'Please specify a new path for the Skeletal Mesh copy')
        package_name = ue.object_path_to_package_name(new_path)
        object_name = ue.get_base_filename(new_path)
        # the last True allows for overwrites
        new_mesh = mesh.duplicate(package_name, object_name, True)

        # generate a new skeleton
        new_skel = self.build_new_skeleton(mesh.Skeleton,
                                           object_name + '_Skeleton', bone)
        # save the new skeleton in the same package directory of the new skeletal mesh
        new_skel.save_package(package_name)

        # assign the new skeleton to the new mesh
        new_mesh.skeletal_mesh_set_skeleton(new_skel)

        new_skel.save_package()

        self.fix_bones_influences(new_mesh, mesh.Skeleton)

        new_mesh.save_package()
Beispiel #2
0
    def split_hips(self, animation, bone='Hips'):
        self.choosen_skeleton = None
        # first ask for which skeleton to use:
        self.window = SWindow(title='Choose your new Skeleton', modal=True, sizing_rule=1)(
                     SObjectPropertyEntryBox(allowed_class=Skeleton, on_object_changed=self.set_skeleton)
                 )
        self.window.add_modal()
        if not self.choosen_skeleton:
            raise DialogException('Please specify a Skeleton for retargeting')

        factory = AnimSequenceFactory()
        factory.TargetSkeleton = self.choosen_skeleton
        
        base_path = animation.get_path_name()
        package_name = ue.get_path(base_path)
        object_name = ue.get_base_filename(base_path)

        new_anim = factory.factory_create_new(package_name + '/' + object_name + '_rooted')

        new_anim.NumFrames = animation.NumFrames
        new_anim.SequenceLength = animation.SequenceLength

        # first step is generatin the 'root' track
        # we need to do it before anything else, as the 'root' track must be the 0 one
        for index, name in enumerate(animation.AnimationTrackNames):
            if name == bone:
                data = animation.get_raw_animation_track(index)
                # extract root motion
                root_motion = [(position - data.pos_keys[0]) for position in data.pos_keys]

                # create a new track (the root motion one)
                root_data = FRawAnimSequenceTrack()
                root_data.pos_keys = root_motion
                # ensure empty rotations !
                root_data.rot_keys = [FQuat()]
        
                # add  the track
                new_anim.add_new_raw_track('root', root_data)
                break
        else:
            raise DialogException('Unable to find bone {0}'.format(bone))
           
        # now append the original tracks, but removes the position keys
        # from the original root bone
        for index, name in enumerate(animation.AnimationTrackNames):
            data = animation.get_raw_animation_track(index)
            if name == bone:
                # remove root motion from original track
                data.pos_keys = [data.pos_keys[0]]
                new_anim.add_new_raw_track(name, data)
            else:
                new_anim.add_new_raw_track(name, data)

        new_anim.save_package()
 def __init__(self, filename, scale=1.0):
     # we need ordered json dictionaries
     with open(filename) as json_file:
         self.model = json.load(json_file, object_pairs_hook=OrderedDict)
     self.scale = scale
     # ask the user where to generate the new assets
     new_path = ue.create_modal_save_asset_dialog('Choose destination path')
     package_name = ue.object_path_to_package_name(new_path)
     object_name = ue.get_base_filename(new_path)
     self.skeleton = self.build_skeleton(package_name, object_name)
     # this is the list of soft skin vertices (they contains mesh data as well as bone influences)
     self.vertices = []
     # this contain mapping between the soft skin vertices and the json file vertex index (this is required for building morph targets)
     self.vertex_map = []
     self.mesh = self.build_mesh(package_name, object_name)
     self.curves = self.build_morph_targets()
     self.animation = self.build_animation(package_name, object_name)
 def __init__(self, filename, scale=1.0):
     # we need ordered json dictionaries
     with open(filename) as json_file:
         self.model = json.load(json_file, object_pairs_hook=OrderedDict)
     self.scale = scale
     # ask the user where to generate the new assets
     new_path = ue.create_modal_save_asset_dialog('Choose destination path')
     package_name = ue.object_path_to_package_name(new_path)
     object_name = ue.get_base_filename(new_path)
     self.skeleton = self.build_skeleton(package_name, object_name)
     # this is the list of soft skin vertices (they contains mesh data as well as bone influences)
     self.vertices = []
     # this contain mapping between the soft skin vertices and the json file vertex index (this is required for building morph targets)
     self.vertex_map = []
     self.mesh = self.build_mesh(package_name, object_name)
     self.curves = self.build_morph_targets()
     self.animation = self.build_animation(package_name, object_name)
    def add_root_to_skeleton(self, mesh, bone='root'):
        base_path = mesh.get_path_name()
        new_path = ue.create_modal_save_asset_dialog('Choose destination path', ue.get_path(base_path), ue.get_base_filename(base_path) + '_rooted')
        if not new_path:
            raise DialogException('Please specify a new path for the Skeletal Mesh copy')
        package_name = ue.object_path_to_package_name(new_path)
        object_name = ue.get_base_filename(new_path)
        # the last True allows for overwrites
        new_mesh = mesh.duplicate(package_name, object_name, True)

        # generate a new skeleton
        new_skel = self.build_new_skeleton(mesh.Skeleton, object_name + '_Skeleton', bone)
        # save the new skeleton in the same package directory of the new skeletal mesh
        new_skel.save_package(package_name)

        # assign the new skeleton to the new mesh
        new_mesh.skeletal_mesh_set_skeleton(new_skel)

        new_skel.save_package()

        self.fix_bones_influences(new_mesh, mesh.Skeleton)

        new_mesh.save_package()