Esempio n. 1
0
def load_scenario():
    scene0 = Scene(
        0,
        "You are Homer Simpson, you want to drink a beer in bar... \n Are you ready?",
        (GoodAction("yes", 1), ExitAction("no")))

    scene1 = Scene(1, "You are in the living room, where do you go?",
                   (GoodAction("entrance", 2), GoodAction("kitchen", 3)))

    scene2 = Scene(
        2,
        "You are opening the entrance door to leave but you meet Marge, she is angry and order you to stay at home to keep an eye on children... \n It's over for the beer today. \n Want to try again?",
        (GoodAction("yes", 0), BadAction("no")))

    scene3 = Scene(
        3,
        "You are now in the kitchen, you want go out through the window but you see the oven that catches fire. You have two choices; \n a: The most important is my beer, go out through the window \n b: Stop the fire \n What do you do?",
        (GoodAction("a", 5), GoodAction("b", 4)))

    scene4 = Scene(
        4,
        "You are trying to put out fire, but you burn yourself. \n You are now in the hospital for several days... \n Want to try again?",
        (GoodAction("yes", 0), BadAction("no")))

    scene5 = Scene(
        5,
        "You're finally out, you walk to the bar. Then you go into the bar, you are so happy! You ask the barman Moe for a beer. But your children and Marge are showing up! Your are learning the house is burned and Marge is very angry. \n You have two choices: Apologize to Marge and go to home or ignore the family and drink your beer.",
        (GoodAction("apologize", 6), WinAction("drink")))

    scene6 = Scene(
        6,
        "You're going to home and it's over for the beer...  \n Want to try again?",
        (GoodAction("yes", 0), BadAction("no")))

    scenario = scene0, scene1, scene2, scene3, scene4, scene5, scene6
    return scenario
Esempio n. 2
0
def scene1(action3, scene2):
    action1 = GoodAction('left', scene2)
    action2 = GoodAction('right', scene2)
    scene = Scene(1, 'my description', (action1, action2, action3))
    return scene
Esempio n. 3
0
def scene2():
    return Scene(2, 'bla bla...')
Esempio n. 4
0
    def __init__(self, args=None):
        QtCore.QObject.__init__(self)

        self.app = QtGui.QApplication(["FireSim"])
        self.args = args
        self.config = Config("data/config.json")

        if self.args.profile:
            try:
                import yappi
                yappi.start()
            except ImportError:
                log.error("Could not enable YaPPI profiling")

        self._selected_fixture_strand = 0
        self._selected_fixture_address = 0
        self._selected_fixture_pixels = 0

        self.selected_fixture = None
        self.is_blurred = False

        self.scene = Scene(
            os.path.join(self.config.get("scene_root"), self.args.scene) +
            ".json")
        self.scenecontroller = SceneController(app=self, scene=self.scene)

        QtDeclarative.qmlRegisterType(CanvasWidget, "FireSim", 1, 0,
                                      "SimCanvas")
        QtDeclarative.qmlRegisterType(FixtureWidget, "FireSim", 1, 0,
                                      "Fixture")

        self.view = QtDeclarative.QDeclarativeView()

        self.view.setWindowTitle("FireSim")
        self.view.setResizeMode(
            QtDeclarative.QDeclarativeView.SizeRootObjectToView)

        self.view.closeEvent = self.on_close

        self.context = self.view.rootContext()
        self.context.setContextProperty('main', self)

        self.fixture_info_list = []
        self.context.setContextProperty('fixtureInfoModel',
                                        self.fixture_info_list)

        self.view.setSource(QtCore.QUrl('ui/qml/FireSimGUI.qml'))

        self.root = self.view.rootObject()
        self.item_frame = self.root.findChild(QtDeclarative.QDeclarativeItem)
        self.canvas = self.root.findChild(CanvasWidget)
        self.canvas.gui = self

        cw, ch = self.scenecontroller.scene.extents()
        self.canvas.setWidth(cw)
        self.canvas.setHeight(ch)

        self.scenecontroller.set_canvas(self.canvas)

        self.root.backdrop_showhide_callback.connect(
            self.on_btn_backdrop_showhide)
        self.root.labels_showhide_callback.connect(self.on_btn_labels_showhide)
        self.root.lock_callback.connect(self.on_btn_lock)
        self.root.show_center_callback.connect(self.on_btn_show_center)
        self.root.toggle_blurred_callback.connect(self.on_btn_toggle_blurred)

        #self.net_thread = QtCore.QThread()
        #self.net_thread.start()
        self.netcontroller = NetController(self)
        #self.netcontroller.moveToThread(self.net_thread)
        #self.netcontroller.start.emit()

        self.net_stats_timer = QtCore.QTimer()
        self.net_stats_timer.setInterval(1000)
        self.net_stats_timer.timeout.connect(self.update_net_stats)
        self.net_stats_timer.start()

        self.netcontroller.data_received.connect(self.on_network_event)
        self.scenecontroller.new_frame.connect(
            self.netcontroller.frame_complete)
        self.netcontroller.data_received.connect(
            self.scenecontroller.process_command)

        self.view.setFixedSize(max(640, cw + 130), max(480, ch))

        log.info("FireSimGUI Ready.")
        self.view.show()
def main():
    white_diffuse = BSDF(BSDFType.Diffuse, np.array([1, 1, 1]))
    red_diffuse = BSDF(BSDFType.Diffuse, np.array([1, 0, 0]))
    blue_diffuse = BSDF(BSDFType.Diffuse, np.array([0, 0, 1]))

    light = BSDF(BSDFType.Light, np.array([2, 2, 2]))

    size = 1.0
    left = size
    right = -size
    top = size
    bottom = -size
    front = size - 2
    back = -size - 2

    # left
    nl = np.array([-1, 0, 0])
    tl0 = Triangle([
        Vertex(np.array([left, bottom, back]), nl, np.array([0, 0])),
        Vertex(np.array([left, bottom, front]), nl, np.array([0, 0])),
        Vertex(np.array([left, top, front]), nl, np.array([0, 0])),
    ], red_diffuse)

    tl1 = Triangle([
        Vertex(np.array([left, top, front]), nl, np.array([0, 0])),
        Vertex(np.array([left, top, back]), nl, np.array([0, 0])),
        Vertex(np.array([left, bottom, back]), nl, np.array([0, 0])),
    ], red_diffuse)

    # right
    nr = np.array([1, 0, 0])
    tr0 = Triangle([
        Vertex(np.array([right, bottom, front]), nr, np.array([0, 0])),
        Vertex(np.array([right, bottom, back]), nr, np.array([0, 0])),
        Vertex(np.array([right, top, back]), nr, np.array([0, 0])),
    ], blue_diffuse)

    tr1 = Triangle([
        Vertex(np.array([right, top, back]), nr, np.array([0, 0])),
        Vertex(np.array([right, top, front]), nr, np.array([0, 0])),
        Vertex(np.array([right, bottom, front]), nr, np.array([0, 0])),
    ], blue_diffuse)

    # top
    nt = np.array([0, -1, 0])
    tt0 = Triangle([
        Vertex(np.array([left, top, front]), nt, np.array([0, 0])),
        Vertex(np.array([right, top, front]), nt, np.array([0, 0])),
        Vertex(np.array([right, top, back]), nt, np.array([0, 0])),
    ], white_diffuse)

    tt1 = Triangle([
        Vertex(np.array([right, top, back]), nt, np.array([0, 0])),
        Vertex(np.array([left, top, back]), nt, np.array([0, 0])),
        Vertex(np.array([left, top, front]), nt, np.array([0, 0])),
    ], white_diffuse)

    # bottom
    nb_ = np.array([0, 1, 0])
    tb_0 = Triangle([
        Vertex(np.array([left, bottom, front]), nb_, np.array([0, 0])),
        Vertex(np.array([right, bottom, front]), nb_, np.array([0, 0])),
        Vertex(np.array([right, bottom, back]), nb_, np.array([0, 0])),
    ], white_diffuse)

    tb_1 = Triangle([
        Vertex(np.array([right, bottom, back]), nb_, np.array([0, 0])),
        Vertex(np.array([left, bottom, back]), nb_, np.array([0, 0])),
        Vertex(np.array([left, bottom, front]), nb_, np.array([0, 0])),
    ], white_diffuse)

    # back
    nb = np.array([0, 0, 1])
    tb0 = Triangle([
        Vertex(np.array([left, bottom, back]), nb, np.array([0, 0])),
        Vertex(np.array([right, bottom, back]), nb, np.array([0, 0])),
        Vertex(np.array([right, top, back]), nb, np.array([0, 0])),
    ], white_diffuse)

    tb1 = Triangle([
        Vertex(np.array([right, top, back]), nb, np.array([0, 0])),
        Vertex(np.array([left, top, back]), nb, np.array([0, 0])),
        Vertex(np.array([left, bottom, back]), nb, np.array([0, 0])),
    ], white_diffuse)

    # light
    l0 = Triangle([
        Vertex(np.array([left, top - 0.01, back]), nt, np.array([0, 0])),
        Vertex(np.array([right, top - 0.01, back]), nt, np.array([0, 0])),
        Vertex(np.array([0, top - 0.01, front]), nt, np.array([0, 0])),
    ], light)

    scene = Scene([tl0, tl1, tr0, tr1, tt0, tt1, tb_0, tb_1, tb0, tb1, l0],
                  [l0])

    world_matrix = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0],
                             [0, 0, 0, 1]])
    camera = Camera(pi / 2, Film(400, 400), world_matrix)
    camera.look_at(np.array([0, 0, 10]), np.array([0, 0, 0]),
                   np.array([-1, 0, 0]))

    render_options = RenderOptions(400, 400, 2, 2, 1, 1, 2, 2.2, 0)

    renderer = Renderer(render_options, camera, scene)
    renderer.render()

    print('Rendering completed.')
    print(datetime.now())