Beispiel #1
0
def load_motion_from_json(builder,
                          skeleton_data,
                          motion_data,
                          name,
                          collection_id,
                          motion_id,
                          meta_data_str="",
                          skeleton_model=None,
                          is_processed=False,
                          draw_mode=2,
                          visualize=True,
                          color=None,
                          visible=True):
    if color is None:
        color = get_random_color()

    skeleton = SkeletonBuilder().load_from_custom_unity_format(skeleton_data)
    skeleton.skeleton_model = skeleton_model
    motion_vector = MotionVector()
    motion_vector.from_custom_db_format(motion_data)
    motion_vector.skeleton = skeleton
    skeleton.frame_time = motion_vector.frame_time
    #motion_vector.scale_root(scale)
    o = builder.create_object("animation_controller", name, skeleton,
                              motion_vector, motion_vector.frame_time,
                              draw_mode, visualize, color)
    o.visible = visible
    if "data_base_ids" not in builder._scene.internal_vars:
        builder._scene.internal_vars["data_base_ids"] = dict()
    builder._scene.internal_vars["data_base_ids"][o.node_id] = (collection_id,
                                                                motion_id,
                                                                is_processed)
    if meta_data_str != "":
        c = o._components["animation_controller"]
        meta_data = json.loads(meta_data_str)
        if "sections" in meta_data:
            sections = meta_data["sections"]
            print("sections", sections)
            sections = meta_data["sections"]
            if type(sections) == list:
                semantic_annotation = create_annotation_from_sections_list(
                    sections, motion_vector.n_frames)
            else:
                semantic_annotation = create_annotation_from_sections_dict(
                    sections, motion_vector.n_frames)
            color_map = dict()
            for key in semantic_annotation.keys():
                color_map[key] = get_random_color()
            c.set_color_annotation(semantic_annotation, color_map)

        if "time_function" in meta_data:
            print("set time_function")
            time_function = meta_data["time_function"]
            print(meta_data["time_function"])
            c.set_time_function(time_function)
        else:
            print("meta_data", meta_data)

    return o
Beispiel #2
0
def attach_mg_state_machine(builder,
                            scene_object,
                            file_path,
                            use_all_joints=False,
                            config=DEFAULT_CONFIG):
    color = get_random_color()
    loader = MotionStateGraphLoader()
    loader.use_all_joints = use_all_joints  # = set animated joints to all
    if os.path.isfile(file_path):
        loader.set_data_source(file_path[:-4])
        graph = loader.build()
        name = file_path.split("/")[-1]
        start_node = ("walk", "idle")
        animation_controller = MorphableGraphStateMachine(
            scene_object,
            graph,
            start_node,
            use_all_joints=use_all_joints,
            config=config,
            pfnn_data=loader.pfnn_data)
        scene_object.add_component("morphablegraph_state_machine",
                                   animation_controller)
        scene_object.name = name
        if builder._scene.visualize:
            vis = builder.create_component("skeleton_vis", scene_object,
                                           animation_controller.get_skeleton(),
                                           color)
            animation_controller.set_visualization(vis)
        agent = SimpleNavigationAgent(scene_object)
        scene_object.add_component("nav_agent", agent)
        return animation_controller
Beispiel #3
0
def load_motion_from_str(builder,
                         bvh_str,
                         name,
                         node_key,
                         motion_id,
                         meta_info_str="",
                         draw_mode=2,
                         visualize=True,
                         color=None):
    if color is None:
        color = get_random_color()

    bvh_reader = get_bvh_from_str(bvh_str)
    print("loaded motion", bvh_reader.frames.shape)
    animated_joints = [
        key for key in list(bvh_reader.node_names.keys())
        if not key.endswith("EndSite")
    ]
    skeleton = SkeletonBuilder().load_from_bvh(bvh_reader, animated_joints)

    motion_vector = MotionVector()
    motion_vector.from_bvh_reader(bvh_reader, False)
    motion_vector.skeleton = skeleton
    motion_vector.scale_root(0.01)
    o = builder.create_object("animation_controller", name, skeleton,
                              motion_vector, bvh_reader.frame_time, draw_mode,
                              visualize, color)
    if "data_base_ids" not in builder._scene.internal_vars:
        builder._scene.internal_vars["data_base_ids"] = dict()
    builder._scene.internal_vars["data_base_ids"][o.node_id] = (node_key,
                                                                motion_id)
    if meta_info_str != "":
        c = o._components["animation_controller"]
        meta_info = json.loads(meta_info_str)
        if "sections" in meta_info:
            sections = meta_info["sections"]
            if type(sections) == list:
                semantic_annotation = create_annotation_from_sections_list(
                    sections, motion_vector.n_frames)
            else:
                semantic_annotation = create_annotation_from_sections_dict(
                    sections, motion_vector.n_frames)
            color_map = dict()
            for key in semantic_annotation.keys():
                color_map[key] = get_random_color()
            c.set_color_annotation(semantic_annotation, color_map)
    return o
Beispiel #4
0
 def get_semantic_annotation(self):
     n_keys = len(self.motion_primitive.keyframes)
     if n_keys <= 0:
         return None
     else:
         sorted_keyframes = collections.OrderedDict(sorted(self.motion_primitive.keyframes.items(), key=lambda t: t[1]))
         start = 0
         end = int(self.motion_primitive.get_n_canonical_frames())
         semantic_annotation = collections.OrderedDict()
         for k, v in sorted_keyframes.items():
             semantic_annotation[k] = list(range(start,  v))
             self.label_color_map[k] = get_random_color()
             start = v
         k = "contact"+str(n_keys)
         semantic_annotation[k] = list(range(start, end))
         self.label_color_map[k] = get_random_color()
         return list(semantic_annotation.items())
Beispiel #5
0
def load_morphable_graphs_file(builder, filename):
    scene_object = SceneObject()
    animation_controller = MorphableGraphsController(scene_object, filename, color=get_random_color())
    scene_object.add_component("morphablegraphs_controller", animation_controller)
    scene_object.add_component("skeleton_vis", animation_controller._visualization)
    scene_object.name = animation_controller.name
    animation_controller.init_visualization()
    builder._scene.addAnimationController(scene_object, "morphablegraphs_controller")
    return scene_object
Beispiel #6
0
def attach_mg_state_machine_from_db(builder,
                                    scene_object,
                                    model_url,
                                    use_all_joints=False,
                                    config=DEFAULT_CONFIG):
    color = get_random_color()
    loader = MotionStateGraphLoader()
    loader.use_all_joints = use_all_joints  # = set animated joints to all
    split_url = model_url.split("/graph/")
    if len(split_url) < 2:
        return
    db_url = split_url[0]
    split_name = split_url[1].split("/")
    if len(split_name) < 2:
        return
    skeleton_name = split_name[0]
    graph_name = split_name[1]
    print(
        "try to load graph",
        skeleton_name,
        graph_name,
        "from db url",
        db_url,
    )
    graph_list = get_graph_list_from_db(db_url, skeleton_name)
    if graph_list is None:
        return
    graph_id = None
    print("found", len(graph_list), "graphs")
    for _id, _name in graph_list:
        if _name == graph_name:
            graph_id = _id
    if graph_id is not None:
        frame_time = 1.0 / 72
        graph = loader.build_from_database(db_url, skeleton_name, graph_id,
                                           frame_time)
        start_node = None
        name = skeleton_name
        animation_controller = MorphableGraphStateMachine(
            scene_object,
            graph,
            start_node,
            use_all_joints=use_all_joints,
            config=config,
            pfnn_data=loader.pfnn_data)
        scene_object.add_component("morphablegraph_state_machine",
                                   animation_controller)
        scene_object.name = name
        if builder._scene.visualize:
            vis = builder.create_component("skeleton_vis", scene_object,
                                           animation_controller.get_skeleton(),
                                           color)
            animation_controller.set_visualization(vis)
        agent = SimpleNavigationAgent(scene_object)
        scene_object.add_component("nav_agent", agent)
        return animation_controller
Beispiel #7
0
def load_motion_graph_controller(self, name, skeleton, motion_graph, frame_time):
    scene_object = SceneObject()
    motion_graph_controller = MotionGraphController(scene_object, color=get_random_color(), mg=motion_graph)
    motion_graph_controller.name = name
    motion_graph_controller.frameTime = frame_time
    motion_graph_controller.set_skeleton(skeleton)
    motion_graph_controller.init_visualization()
    scene_object.name = motion_graph_controller.name
    scene_object.add_component("motion_graph_controller", motion_graph_controller)
    self.addAnimationController(scene_object, "motion_graph_controller")
    return scene_object
Beispiel #8
0
def attach_mg_generator_from_db(builder,
                                scene_object,
                                db_url,
                                skeleton_name,
                                graph_id,
                                use_all_joints=False,
                                config=DEFAULT_CONFIG):
    color = get_random_color()
    loader = MotionStateGraphLoader()
    # set animated joints to all necessary for combination of models with different joints
    loader.use_all_joints = use_all_joints
    frame_time = 1.0 / 72
    graph = loader.build_from_database(db_url, skeleton_name, graph_id,
                                       frame_time)
    start_node = None
    name = skeleton_name
    animation_controller = MorphableGraphsController(
        scene_object,
        name,
        graph,
        start_node=start_node,
        config=DEFAULT_ALGORITHM_CONFIG,
        color=get_random_color()
    )  #start_node, use_all_joints=use_all_joints, config=config, pfnn_data=loader.pfnn_data)

    #scene_object.add_component("skeleton_vis", animation_controller._visualization)
    scene_object.add_component("morphablegraphs_controller",
                               animation_controller)
    scene_object.name = name
    if builder._scene.visualize:
        vis = builder.create_component("skeleton_vis", scene_object,
                                       animation_controller.get_skeleton(),
                                       color)
        animation_controller.set_visualization(vis)
        #scene_object._components["morphablegraph_state_machine"].update_scene_object.connect(builder._scene.slotUpdateSceneObjectRelay)
    return animation_controller
Beispiel #9
0
 def plot_joint_trajectory(self, joint_name):
     scene_object = None
     if joint_name in list(self._visualization.skeleton.nodes.keys()):
         trajectory = list()
         for f in self._motion.get_frames():
             p = self.get_joint_position(joint_name, f)
             if p is not None:
                 trajectory.append(p)
         if len(trajectory) > 0:
             name = self.scene_object.name + "_" + joint_name + "_trajectory"
             scene_object = self.scene_object.scene.addSplineObject(
                 name, trajectory, get_random_color(), granularity=500)
         else:
             print("No points to plot for joint", joint_name)
     return scene_object
 def detect_foot_contacts(self):
     source_ground_height = float(self.sourceGroundHeightLineEdit.text())
     ground_contacts = self._animation_editor.detect_ground_contacts(
         source_ground_height)
     ground_annotation = collections.OrderedDict()
     color_map = collections.OrderedDict()
     n_frames = self.controller.getNumberOfFrames()
     for idx in range(n_frames):
         for label in ground_contacts[idx]:
             if label not in ground_annotation:
                 color_map[label] = get_random_color()
                 ground_annotation[label] = [[]]
             ground_annotation[label][0].append(idx)
     self.annotation_editor.set_annotation(ground_annotation, color_map)
     self.init_label_time_line()
Beispiel #11
0
def create_motion_primitive(builder, name, data, cluster_tree_data=None):
    scene_object = SceneObject()
    #data = json.loads(data_str)
    animation_controller = MotionPrimitiveController(scene_object,
                                                     name,
                                                     data,
                                                     color=get_random_color())
    if cluster_tree_data is not None:
        animation_controller.load_cluster_tree_from_json(cluster_tree_data)
    scene_object.add_component("motion_primitive_controller",
                               animation_controller)
    scene_object.name = animation_controller.name
    animation_controller.init_visualization()
    builder._scene.addAnimationController(scene_object,
                                          "motion_primitive_controller")
    return scene_object
Beispiel #12
0
def load_motion_primitive(builder, file_path):
    scene_object = SceneObject()
    with open(file_path, "r") as in_file:
        data = json.load(in_file)
    name = file_path.split("/")[-1]
    animation_controller = MotionPrimitiveController(scene_object,
                                                     name,
                                                     data,
                                                     color=get_random_color())
    scene_object.add_component("motion_primitive_controller",
                               animation_controller)
    scene_object.name = animation_controller.name
    animation_controller.init_visualization()
    builder._scene.addAnimationController(scene_object,
                                          "motion_primitive_controller")
    return scene_object
Beispiel #13
0
def load_morphable_graphs_file(builder, filename):
    scene_object = SceneObject()
    loader = MotionStateGraphLoader()
    loader.set_data_source(filename[:-4])
    loader.use_all_joints = False  # = set animated joints to all
    name = filename.split("/")[-1]
    graph = loader.build()
    animation_controller = MorphableGraphsController(scene_object,
                                                     name,
                                                     graph,
                                                     color=get_random_color())
    scene_object.add_component("morphablegraphs_controller",
                               animation_controller)
    scene_object.add_component("skeleton_vis",
                               animation_controller._visualization)
    scene_object.name = animation_controller.name
    animation_controller.init_visualization()
    builder._scene.addAnimationController(scene_object,
                                          "morphablegraphs_controller")
    return scene_object
def create_animation_directory_explorer(builder, directory, filetype):
    scene_object = SceneObject()
    animation_controller = AnimationDirectoryExplorer(scene_object, directory, filetype, color=get_random_color())
    scene_object.add_component("animation_directory_explorer", animation_controller)
    scene_object.name = animation_controller.name
    builder._scene.addAnimationController(scene_object, "animation_directory_explorer")
    return scene_object
    def __init__(self, controller, scene, share_widget, parent=None):
        QDialog.__init__(self, parent)
        Ui_Dialog.setupUi(self, self)
        self.leftView = SceneViewerWidget(parent,
                                          share_widget,
                                          size=(400, 400))
        self.leftView.setObjectName("left")
        self.leftView.setMinimumSize(400, 400)
        self.leftView.initializeGL()
        self.leftView.enable_mouse_interaction = True
        self.leftView.mouse_click.connect(self.on_mouse_click)
        self.leftView.mouse_move.connect(self.on_mouse_move)
        self.leftView.mouse_release.connect(self.on_mouse_release)
        self.leftViewerLayout.addWidget(self.leftView)

        self.radius = 1.0
        self.fps = 60
        self.dt = 1 / 60
        self.timer = QTimer()
        self.timer.timeout.connect(self.draw)
        self.timer.start(0)
        self.timer.setInterval(1000.0 / self.fps)
        self.scene = scene
        self.original_controller = controller
        self.controller = None
        self.skeleton = None
        self.leftView.makeCurrent()
        self.left_scene = EditorScene(True)
        self.left_scene.enable_scene_edit_widget = True
        self.left_scene.scene_edit_widget.register_move_callback(
            self.on_move_widget)
        self._animation_editor = None
        if controller is not None:
            self.controller = self.copy_controller(controller, self.left_scene)
            fps = int(1.0 / self.controller._motion.mv.frame_time)
            self.fpsLineEdit.setText(str(fps))
            self.skeleton = self.controller.get_skeleton()
            n_frames = self.controller.getNumberOfFrames()
            self.skeleton_vis = self.controller.scene_object._components[
                "skeleton_vis"]
            self.init_joints(self.controller)
        else:
            n_frames = 0

        self.selectButton.clicked.connect(self.slot_accept)
        self.cancelButton.clicked.connect(self.slot_reject)

        self.deleteBeforeButton.clicked.connect(self.slot_delete_frames_before)
        self.deleteAfterButton.clicked.connect(self.slot_delete_frames_after)
        self.concatenateButton.clicked.connect(self.slot_concatenate)
        self.translateJointButton.clicked.connect(self.slot_translate_joint)
        self.rotateJointButton.clicked.connect(self.slot_rotate_joint)
        self.smoothFramesButton.clicked.connect(self.slot_smooth_frames)
        self.mirrorAnimationButton.clicked.connect(self.slot_mirror_animation)
        self.fixJointButton.clicked.connect(self.slot_fix_joint)
        self.clearConstraintsButton.clicked.connect(
            self.slot_clear_constraints)
        self.undoButton.clicked.connect(self.slot_undo)
        self.exportCommandsButton.clicked.connect(
            self.slot_export_command_history)
        self.applyConstraintsButton.clicked.connect(
            self.slot_apply_constraints)
        self.resampleButton.clicked.connect(self.slot_resample_motion)
        self.setFPSButton.clicked.connect(self.slot_set_fps)
        self.flipBlenderCoordinateSystemButton.clicked.connect(
            self.flip_blender_coordinate_systems)

        self.leftStartFrameSlider.valueChanged.connect(
            self.left_slider_frame_changed)
        self.leftEndFrameSlider.valueChanged.connect(
            self.left_slider_frame_changed)
        self.leftStartFrameSpinBox.valueChanged.connect(
            self.left_spinbox_frame_changed)
        self.leftEndFrameSpinBox.valueChanged.connect(
            self.left_spinbox_frame_changed)

        self.leftDisplayFrameSlider.valueChanged.connect(
            self.left_display_changed)
        self.leftDisplayFrameSpinBox.valueChanged.connect(
            self.left_display_changed)
        #self.close.triggered.connect(self.on_close)

        self.guessGroundHeightButton.clicked.connect(self.guess_ground_height)
        self.moveToGroundButton.clicked.connect(self.move_to_ground)

        self.detectFootContactsButton.clicked.connect(
            self.detect_foot_contacts)
        self.groundFeetButton.clicked.connect(self.ground_feet)

        self.setAnnotationStartButton.clicked.connect(
            self.set_annotation_edit_start)
        self.createAnnotationButton.clicked.connect(
            self.create_annotation_section)
        self.removeAnnotationButton.clicked.connect(
            self.remove_annotation_section)

        self.edited_knob = None
        self.success = False
        self.n_frames = n_frames
        self.start_frame = 0
        self.end_frame = n_frames - 1  #
        self.set_frame_range()
        self.initialized = False
        self.collect_constraints = True
        self.original_frames = np.array(self.controller.get_frames())
        self.annotation_editor = AnnotationEditor()
        self.contactLabelView.setTimeLineParameters(100000, 10)
        self.contactLabelView.initScene()
        self.contactLabelView.show()
        if not self._animation_editor.motion_grounding.initialized:
            self.detectFootContactsButton.setEnabled(False)
            self.groundFeetButton.setEnabled(False)
        else:
            ground_annotation = collections.OrderedDict()
            color_map = collections.OrderedDict()
            for label in self._animation_editor.foot_constraint_generator.contact_joints:
                color_map[label] = get_random_color()
                ground_annotation[label] = []
            self.annotation_editor.set_annotation(ground_annotation, color_map)
            self.fill_label_combobox()
        self.init_label_time_line()