Beispiel #1
0
def create_blend_controller(self, name, skeleton, motions, joint_name=None, constrained_frame=-1):
    joint_name = "hand_l"
    constrained_frame = 50
    count = float(len(motions))
    if count > 0:
        scene_object = SceneObject()
        scene_object.name = name
        blend_animation_controller = BlendAnimationController(scene_object)
        node = AnimationBlendNode()
        for idx, motion in enumerate(motions):
            print("add motion ", idx, count - 1)
            # pos = float(idx)/(count-1)
            if joint_name is None:
                x = motion.frames[constrained_frame][0]
                z = motion.frames[constrained_frame][2]
                node.add_motion("motion_" + str(idx), motion.frames, [x, z])
            else:
                frame = motion.frames[constrained_frame]
                p = skeleton.nodes[joint_name].get_global_position(frame)
                x = p[0]
                y = p[2]
                z = p[2]
                node.add_motion("motion_"+str(idx), motion.frames, [x,y, z])
        node.update_weights()
        if joint_name is None:
            node.set_parameter_labels(["x", "z"])
        else:
            node.set_parameter_labels(["x", "y", "z"])

        node.frame_time = motions[0].frame_time
        blend_animation_controller.set_track(node)
        blend_animation_controller.set_skeleton(skeleton)
        blend_animation_controller.updateTransformation(0)
        scene_object.add_component("blend_controller", blend_animation_controller)
        self._scene.addAnimationController(scene_object, "blend_controller")
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 create_joint_control_knob(builder, anim_controller, joint_name, radius, material=materials.red):
    scene_object = SceneObject()
    geometry = Mesh.build_sphere(20, 20, 2 * radius, material)
    scene_object._components["geometry"] = GeometryDataComponent(scene_object, geometry)

    c = JointControlKnob(scene_object, anim_controller, joint_name)
    scene_object.add_component("joint_control_knob", c)
    builder._scene.addObject(scene_object)
    return scene_object
Beispiel #4
0
def load_mesh_from_obj_file(builder, file_path):
    file_name = os.path.basename(file_path)
    scene_object = SceneObject()
    scene_object.name = file_name
    mesh_list2 = load_obj_file(file_path)
    static_mesh = StaticMesh(scene_object, [0, 0, 0], mesh_list2)
    scene_object.add_component("static_mesh", static_mesh)
    builder._scene.addObject(scene_object)
    return scene_object
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 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 #7
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 #8
0
def load_blend_controller(self, filename):
    with open(filename, "rb") as in_file:
        node = pickle.load(in_file)
        scene_object = SceneObject()
        name = filename.split("/")[-1]
        scene_object.name = name
        blend_animation_controller = BlendAnimationController(scene_object)
        blend_animation_controller.set_track(node)
        blend_animation_controller.set_skeleton(node.skeleton)
        blend_animation_controller.updateTransformation(0)
        scene_object.add_component("blend_controller", blend_animation_controller)
        self._scene.addAnimationController(scene_object, "blend_controller")
Beispiel #9
0
 def create_motion_primitive(builder, name, data_str, cluster_tree_data_str=None):
     scene_object = SceneObject()
     data = json.loads(data_str)
     animation_controller = MotionPrimitiveController(scene_object, name, data, color=get_random_color())
     if cluster_tree_data_str is not None and cluster_tree_data_str !="":
         cluster_tree_data = json.loads(cluster_tree_data_str)
         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 #10
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
Beispiel #11
0
def load_collada_file(builder, file_path):
    """ https://github.com/pycollada/pycollada/blob/master/examples/daeview/renderer/GLSLRenderer.py """
    import collada
    mesh_list = list()
    col = collada.Collada(
        file_path,
        ignore=[collada.DaeUnsupportedError, collada.DaeBrokenRefError])
    if col.scene is not None:
        for geom in col.scene.objects('geometry'):
            for prim in geom.primitives():
                m = dict()
                prim_type = type(prim).__name__
                if prim_type == 'BoundTriangleSet':
                    triangles = prim
                elif prim_type == 'BoundPolylist':
                    triangles = prim.triangleset()
                else:
                    print('Unsupported mesh used:', prim_type)
                    triangles = None
                if triangles is not None:
                    triangles.generateNormals()
                    # We will need flat lists for VBO (batch) initialization
                    m["vertices"] = triangles.vertex.tolist()
                    batch_len = len(m["vertices"]) // 3
                    m["indices"] = triangles.vertex_index.flatten().tolist()
                    m["normals"] = triangles.normal.tolist()
                    m["type"] = "triangles"
                    mesh_list.append(m)

    file_name = os.path.basename(file_path)
    scene_object = SceneObject()
    scene_object.name = file_name
    static_mesh = StaticMesh(scene_object, [0, 0, 0], mesh_list)
    scene_object.add_component("static_mesh", static_mesh)

    builder._scene.addObject(scene_object)
    return scene_object
Beispiel #12
0
def create_scene_rest_interface(builder, port):
    scene_object = SceneObject()
    builder._scene.addObject(scene_object)
    scene_rest_interface = SceneInterface(scene_object, port)
    scene_object.add_component("scene_interface", scene_rest_interface)
    return scene_object
Beispiel #13
0
def create_static_mesh(builder, name, mesh_list):
    scene_object = SceneObject()
    scene_object.name = name
    static_mesh = StaticMesh(scene_object, [0, 0, 0], mesh_list)
    scene_object.add_component("static_mesh", static_mesh)
    return scene_object