Exemple #1
0
    def save_scene(self):

        # cache character info and motions
        character_motion_maps = []
        character_infos = []
        for t in self.toons:
            motion_maps = {}
            character_info = {}
            for joint in t.joint_list():
                motion_maps[joint.name] = joint.generate_map_from_retargets()
                character_info[joint.name] = joint.get_info()

            character_motion_maps.append(motion_maps)
            character_infos.append(character_info)

        # organize into scene file
        scene_file = {
            "mocap": MocapHandle().last_loaded,
            "character_filepaths": self.toon_filepaths,
            "character_info": character_infos,
            "character_motion_maps": character_motion_maps,
        }

        # save
        filepath = Dialogs.save_file(self.p, AppSettings.save_dir)[0]
        f = open(filepath, "w")
        f.write(json.dumps(scene_file, sort_keys=True, indent=4, separators=(",", ": ")))
        f.close()
Exemple #2
0
    def load_scene(self, filepath=""):
        if filepath == "":
            filepath = Dialogs.open_file(self.p, AppSettings.save_dir)[0]
        if not os.path.isfile(filepath):
            Scene().set_status("file selected is not valid.", "warning")
            return

        # open
        f = open(filepath, "r")
        scene_file = json.loads(f.read())
        f.close()

        # Load mocap (if it was there)
        if scene_file["mocap"] != "":
            MocapHandle().load_mocap("%s/%s" % (AppSettings.demuddle_dir, scene_file["mocap"]))

        # Load characters.
        for fp in scene_file["character_filepaths"]:
            self.add_toon_from_file("%s/%s" % (AppSettings.demuddle_dir, fp))

        # Apply info and motion onto characters
        cindex = 0
        for cindex in range(len(scene_file["character_motion_maps"])):
            motion_maps = scene_file["character_motion_maps"][cindex]
            character_infos = scene_file["character_info"][cindex]

            for joint_name in motion_maps.keys():
                character_info = character_infos[joint_name]
                motion_map = motion_maps[joint_name]
                joint_obj = self.toons[cindex].joint_by_name(joint_name)
                joint_obj.set_info(character_info)
                joint_obj.generate_retargets_from_map(motion_map)
            cindex += 1

        self.p.update()
Exemple #3
0
    def save_graph(self, filepath=""):
        if filepath == "":
            filepath = Dialogs.save_file(self.p, AppSettings.demuddle_dir)[0]

        data_fp = filepath + ".meta.json"
        self.p.paintImage(filepath)
        self.save_meta_data(data_fp)
Exemple #4
0
    def load_mocap(self, filepath=""):
        if filepath == "":
            filepath = Dialogs.open_file(None, AppSettings.data_dir)[0]

        if os.path.isfile(filepath):
            self.last_loaded = filepath
            data = self.load_from_file(filepath)

            self.motion = data[AppSettings.motion_type]
            first_key = self.motion.keys()[0]
            first_dof = self.motion[first_key].keys()[0]
            first_curve = self.motion[first_key][first_dof]

            Timeline().set_frame_range(data["start_frame"], len(first_curve))
            Animation.mocap_reset()
Exemple #5
0
 def scale_toon(self):
     for t in self.toons:
         if t.joint_selected() != None:
             v = Dialogs.float(self.p, "Scale", "scale character")
             if v != None:
                 t.modify_position_scaling(v)
Exemple #6
0
 def rotate_toon(self):
     for t in self.toons:
         if t.selection_active():
             v = Dialogs.int(self.p, "Rotate", "degrees anticlockwise")
             if v != None:
                 t.modify_rotation_offset(v)
Exemple #7
0
 def load_toon(self):
     filepath = Dialogs.open_file(self.p, AppSettings.toon_dir)[0]
     if os.path.isfile(filepath):
         self.add_toon_from_file(filepath)
     else:
         Scene().set_status("File selected is not valid", "error")