def post_load_scene(scn, openvr_frame_renderer, gui):
    if catalogue is None or not len(catalogue):
        return
    # get the trigger
    for trigger_object, data in catalogue.items():
        node = scn.GetNode(trigger_object)
        if node is not None:
            catalogue[trigger_object]["node"] = node
            catalogue[trigger_object]["nb_texture"] = 0

            for name_object, data_object in data["object"].items():
                node = scn.GetNode(name_object)
                if node is not None:
                    data_object["node"] = node

                    # add the rigid body to raycast later
                    if node.GetComponent("RigidBody") is None:
                        node.AddComponent(gs.MakeRigidBody())
                        mesh_col = gs.MakeMeshCollision()
                        mesh_col.SetGeometry(
                            gs.LoadCoreGeometry(
                                node.GetObject().GetGeometry().GetName()))
                        mesh_col.SetMass(0)
                        node.AddComponent(mesh_col)
                        node.SetIsStatic(True)

                    # load all texture to gputexture
                    data_object["diffuse_gpu"] = []
                    for diffuse_map in data_object["diffuse_map"]:
                        data_object["diffuse_gpu"].append(
                            plus.GetRendererAsync().LoadTexture("export/" +
                                                                diffuse_map))
                        catalogue[trigger_object]["nb_texture"] += 1
Esempio n. 2
0
def load_new_scene(filename):
    global current_filename_scn, authorise_ground_node, authorise_ground_geo

    if getattr(sys, 'frozen', False):
        os.chdir(os.path.dirname(sys.executable))
    else:
        os.chdir(os.path.dirname(os.path.realpath(__file__)))

    # create new scene
    create_new_scene()

    if not os.path.exists(filename):
        print("{0} doesn't exist".format(filename))
        return

    # load new scene
    gs.MountFileDriver(gs.StdFileDriver(os.path.dirname(filename)))
    gs.MountFileDriver(gs.StdFileDriver(os.path.dirname(filename)), "export")
    scn.Load(filename, gs.SceneLoadContext(plus.GetRenderSystem()))

    # call twice to be sure it's loaded
    plus.UpdateScene(scn, gs.time(1.0 / 60))
    plus.UpdateScene(scn, gs.time(1.0 / 60))
    plus.UpdateScene(scn, gs.time(1.0 / 60))
    plus.UpdateScene(scn, gs.time(1.0 / 60))

    # find the authorise ground
    authorise_ground_node = scn.GetNode("chaperone_area")
    if authorise_ground_node is not None:
        p = authorise_ground_node.GetTransform().GetPosition()
        p.y += 0.01
        authorise_ground_node.GetTransform().SetPosition(p)
        rb = gs.MakeRigidBody()
        rb.SetCollisionLayer(2)
        authorise_ground_node.AddComponent(rb)
        mesh_col = gs.MakeMeshCollision()
        mesh_col.SetGeometry(
            gs.LoadCoreGeometry(
                authorise_ground_node.GetObject().GetGeometry().GetName()))
        mesh_col.SetMass(0)
        authorise_ground_node.AddComponent(mesh_col)
        authorise_ground_node.GetObject().GetGeometry().SetMaterial(
            0, authorise_ground_mat)
        authorise_ground_node.SetIsStatic(True)

    # move the camera to see the fbx entirely
    camera.reset_view(scn, cam, camera_handler, openvr_frame_renderer)
    current_filename_scn = filename

    scn.SetCurrentCamera(cam)

    # create the list of object to switch
    switch_object.load_switch_object(scn)

    vr_controller.update_controller(scn)
Esempio n. 3
0
def post_load_scene(scn, openvr_frame_renderer, gui):
    if switch_object_textures is None or not len(switch_object_textures):
        return

    for name_object, data in switch_object_textures.items():
        node = scn.GetNode(name_object)
        if node is not None:
            switch_object_textures[name_object]["node"] = node

            # add the rigid body to raycast later
            if node.GetComponent("RigidBody") is None:
                node.AddComponent(gs.MakeRigidBody())
                mesh_col = gs.MakeMeshCollision()
                mesh_col.SetGeometry(
                    gs.LoadCoreGeometry(
                        node.GetObject().GetGeometry().GetName()))
                mesh_col.SetMass(0)
                node.AddComponent(mesh_col)
                node.SetIsStatic(True)
Esempio n. 4
0
def load_switch_object(scn):
    global switch_objects
    switch_objects = {}

    for node in scn.GetNodes():
        name = node.GetName()
        if "_switch_" in name:
            name = name[:-2]
            if name not in switch_objects:
                switch_objects[name] = {"current_display": 0, "nodes": []}
            else:
                node.SetEnabled(False)

            switch_objects[name]["nodes"].append(node)

            # add the rigid body to raycast later
            node.AddComponent(gs.MakeRigidBody())
            mesh_col = gs.MakeMeshCollision()
            mesh_col.SetGeometry(
                gs.LoadCoreGeometry(node.GetObject().GetGeometry().GetName()))
            mesh_col.SetMass(0)
            node.AddComponent(mesh_col)
            node.SetIsStatic(True)
Esempio n. 5
0
def render_star():
    global plus

    strings = [[
        "Collision detection in AMOS", 30, 1, 0, "bilko-opti-bold", 42
    ], ["uses special masks.", 55, 1, 0, "bilko-opti-bold", 42],
               ["This method is very", 80, 1, 0, "bilko-opti-bold", 42],
               ["fast and gives 100%", 105, 1, 0, "bilko-opti-bold", 42],
               ["accuracy.", 130, 1, 0, "bilko-opti-bold", 42]]

    render_text_screen(strings,
                       duration=5.0,
                       plus=plus,
                       exit_callback=demo_exit_test)

    strings = [["Watch the balls in this", 30, 1, 0, "bilko-opti-bold", 42],
               ["next demo. They only", 55, 1, 0, "bilko-opti-bold", 42],
               ["change colour when in", 80, 1, 0, "bilko-opti-bold", 42],
               ["contact with a solid", 105, 1, 0, "bilko-opti-bold", 42],
               ["part of the large star.", 130, 1, 0, "bilko-opti-bold", 42]]

    render_text_screen(strings,
                       duration=5.0,
                       plus=plus,
                       exit_callback=demo_exit_test)

    scn = plus.NewScene()
    scn.Load("@assets/star.scn", gs.SceneLoadContext(plus.GetRenderSystem()))
    cam = plus.AddCamera(
        scn, gs.Matrix4.TranslationMatrix(gs.Vector3(0, -45, -100) * 1))
    cam.GetTransform().SetRotation(gs.Vector3(math.pi * -24 / 180, 0, 0))
    cam.GetComponent("Camera").SetZoomFactor(22.0)  ## * 0.5)
    # plus.AddEnvironment(scn, gs.Color.Black, gs.Color.White)
    plus.AddLight(scn, gs.Matrix4.TranslationMatrix((6, 4, -6)))

    while not scn.IsReady():
        dt = plus.UpdateClock()
        plus.UpdateScene(scn, dt)

    _w = 15

    pos = gs.Vector3(0, -_w * 0.75, 0)
    rb = plus.AddPhysicCube(scn, gs.Matrix4.TranslationMatrix(pos), _w * 2, 1,
                            1, 0)
    rb[1].SetRestitution(1.0)

    pos = gs.Vector3(0, _w * 0.75, 0)
    rb = plus.AddPhysicCube(scn, gs.Matrix4.TranslationMatrix(pos), _w * 2, 1,
                            1, 0)
    rb[1].SetRestitution(1.0)

    pos = gs.Vector3(_w, 0, 0)
    rb = plus.AddPhysicCube(scn, gs.Matrix4.TranslationMatrix(pos), 1, _w * 2,
                            1, 0)
    rb[1].SetRestitution(1.0)

    pos = gs.Vector3(-_w, 0, 0)
    rb = plus.AddPhysicCube(scn, gs.Matrix4.TranslationMatrix(pos), 1, _w * 2,
                            1, 0)
    rb[1].SetRestitution(1.0)

    _w = 8

    scn.GetPhysicSystem().SetForceRigidBodyAxisLockOnCreation(gs.LockZ +
                                                              gs.LockRotX +
                                                              gs.LockRotY +
                                                              gs.LockRotZ)
    scn.GetPhysicSystem().SetGravity(gs.Vector3(0, 0, 0))

    balls = {}
    prev_pos = None
    for i in range(15):
        _rnd = uniform(0, 1)
        if _rnd < 0.25:
            pos = gs.Vector3(-_w, -_w, 0)
        elif _rnd < 0.5:
            pos = gs.Vector3(_w, -_w, 0)
        elif _rnd < 0.75:
            pos = gs.Vector3(_w, _w, 0)
        else:
            pos = gs.Vector3(-_w, _w, 0)

        while prev_pos is not None and gs.Vector3.Dist(prev_pos, pos) < 2.0:
            pos += rvect(2.0)
            pos.z = 0

        prev_pos = pos

        ball = plus.AddPhysicSphere(scn, gs.Matrix4.TranslationMatrix(pos),
                                    0.5, 6, 16, 1, "@assets/blue.mat")

        ball[1].ApplyLinearImpulse(pos * -1.0 * uniform(0.05, 0.5))
        ball[1].SetRestitution(1.1)

        col_ball = plus.AddSphere(
            scn, gs.Matrix4.TranslationMatrix(gs.Vector3(0, 0, 0)), 0.5, 6, 16,
            "@assets/red.mat")
        col_ball.GetTransform().SetParent(ball[0])
        col_ball.GetComponent("Object").SetEnabled(False)

        plus.UpdateScene(scn, plus.UpdateClock())
        balls[str(ball[0].GetUid())] = [ball[0], col_ball, 0.0]

    star_mesh_edges = scn.GetNode("star_mesh_edges")
    star_mesh_edges.RemoveComponent(star_mesh_edges.GetComponent("Object"))

    star = scn.GetNode("star_mesh")
    rb = gs.MakeRigidBody()
    rb.SetRestitution(1.0)
    star.AddComponent(rb)
    star.RemoveComponent(star.GetComponent("Object"))

    star_bitmap = scn.GetNode("star_bitmap")
    star_bitmap.GetTransform().SetRotation(gs.Vector3(-0.15, 0, 0))

    star_geo = gs.LoadCoreGeometry("@assets/star_mesh.geo")
    star_col = gs.MakeMeshCollision()
    star_col.SetGeometry(star_geo)
    star_col.SetMass(10)
    star.AddComponent(star_col)

    fx_timer = 0.0
    fx_duration = 12.0

    ps = scn.GetPhysicSystem()
    while fx_timer < fx_duration:
        demo_exit_test()
        dt = plus.UpdateClock()
        plus.UpdateScene(scn, dt)
        fx_timer += dt.to_sec()

        for colp in ps.GetCollisionPairs(star):
            if colp.GetNodeA().GetName == "star_mesh":
                col_node = colp.GetNodeB()
            else:
                col_node = colp.GetNodeA()

            balls[str(col_node.GetUid())][2] = 1.0

        for ball_key in balls:
            ball = balls[ball_key]
            if ball[2] > 0.0:
                ball[1].GetComponent("Object").SetEnabled(True)
                ball[0].GetComponent("Object").SetEnabled(False)
            else:
                ball[1].GetComponent("Object").SetEnabled(False)
                ball[0].GetComponent("Object").SetEnabled(True)

            ball[2] = max(0.0, ball[2] - dt.to_sec())

        plus.Flip()