示例#1
0
    def initialize(self):
        print("Initializing program...")

        self.renderer = Renderer()
        self.scene = Scene()
        self.camera = Camera()

        geometry = BoxGeometry()
        material = SurfaceBasicMaterial({"useVertexColors": 1})
        self.mesh = Mesh(geometry, material)
        self.mesh.rotateX(0.6)
        self.mesh.rotateY(-0.6)
        self.mesh.rotateZ(-0.4)

        self.scene.add(self.mesh)

        # pull camera towards viewer
        self.camera.setPosition(0, 0, 4)

        # add a backdrop
        backGeometry = BoxGeometry(width=2, height=2, depth=0.01)
        backMaterial = SurfaceBasicMaterial({"baseColor": [1, 1, 0]})
        self.backdrop = Mesh(backGeometry, backMaterial)
        self.backdrop.rotateX(1.57)
        self.backdrop.setPosition(0, -1, 0)
        self.scene.add(self.backdrop)
示例#2
0
class Test(Base):

    def initialize(self):
        print("Initializing program...")

        self.renderer = Renderer()
        self.scene = Scene()
        self.camera = Camera()
        # pull camera towards viewer
        self.camera.setPosition(0, 0, 7)

        geometry = Geometry()
        posData = []
        for x in range(-32, 32, 3):
            posData.append([x/10, sin(x/10), 0])
        geometry.addAttribute("vec3", "vertexPosition", posData)
        geometry.countVertices()

        pointMaterial = PointBasicMaterial({"baseColor": [1,1,0]})
        self.pointMesh = Mesh(geometry, pointMaterial)

        lineMaterial = LineBasicMaterial({"baseColor": [1,0,1]})
        self.lineMesh = Mesh(geometry,lineMaterial)

        self.scene.add(self.pointMesh)
        self.scene.add(self.lineMesh)

    def update(self):

        self.renderer.render(self.scene, self.camera)
示例#3
0
class Test(Base):

    def initialize(self):
        print("Initializing program...")

        self.renderer = Renderer()
        self.scene = Scene()
        self.camera = Camera()
        # pull camera towards viewer
        self.camera.setPosition(0, 0, 7)

        geometry = SphereGeometry(radius=3)

        vsCode = """
        in vec3 vertexPosition;
        in vec3 vertexColor;
        uniform mat4 modelMatrix;
        uniform mat4 viewMatrix;
        uniform mat4 projectionMatrix;
        out vec3 color;
        uniform float time;
        
        void main()
        {
            float offset = 0.2 * sin(2.0 * vertexPosition.x + time);
            vec3 pos = vertexPosition + vec3(0, offset, 0);
            gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(pos, 1);
            color = vertexColor;
        }
        """

        fsCode = """
        in vec3 color;
        uniform float time;
        out vec4 fragColor;
        
        void main()
        {
            float r = abs(sin(time));
            vec4 c = vec4(r, -0.5*r, -0.5*r, 0);
            fragColor = vec4(color , 1) + c;
        }
        """

        material = Material(vsCode, fsCode)
        material.addUniform("float", "time", 0)
        material.locateUniforms()

        self.time = 0

        self.mesh = Mesh(geometry, material)

        self.scene.add(self.mesh)

    def update(self):

        self.time += 1/60
        self.mesh.material.uniforms["time"].data = self.time
        self.renderer.render(self.scene, self.camera)
示例#4
0
 def __init__(self, w, h):
     self._context = Context()
     self._camera = Camera(0, 0, w, h)
     self._camera.set_active()
     self._running = False
     self._mode = SELECT_MODE
     self._selected = []
     self._ruler = (0, 0, 0, 0)
     self._selection_area = (0, 0, 0, 0)
     self._frames = []
def record_video(filename, framerate, recTime, exposure):
    """
    Records video from selected camera
    [exposure]: exposure level for camera
    """
    cam = Camera()
    filename_timestamp = cam.rawObservation(filename,
                                            frame_rate=framerate,
                                            video_time=recTime,
                                            shutterSpeed=exposure)
    return filename_timestamp
示例#6
0
class Test(Base):

    def initialize(self):
        print("Initializing program...")

        self.renderer = Renderer()
        self.scene = Scene()
        self.camera = Camera()
        # pull camera towards viewer
        self.camera.setPosition(0, 0, 7)

        geometry = SphereGeometry(radius=3)

        vsCode = """
        in vec3 vertexPosition;
        out vec3 position;
        uniform mat4 modelMatrix;
        uniform mat4 viewMatrix;
        uniform mat4 projectionMatrix;
        
        void main()
        {
            
            vec4 pos = vec4(vertexPosition, 1);
            gl_Position = projectionMatrix * viewMatrix * modelMatrix * pos;
            position = vertexPosition;
        }
        """

        fsCode = """
        in vec3 position;
        out vec4 fragColor;
        
        void main()
        {
            vec3 color = fract(position);
            fragColor = vec4(color,1);
        }
        """
        material = Material(vsCode, fsCode)
        material.locateUniforms()

        self.mesh = Mesh(geometry, material)

        self.scene.add(self.mesh)

    def update(self):

        self.mesh.rotateY(0.01)
        self.renderer.render(self.scene, self.camera)
示例#7
0
    def initialize(self):
        print("Initializing program...")

        self.renderer = Renderer()
        self.scene = Scene()
        self.camera = Camera()
        # pull camera towards viewer
        self.camera.setPosition(0, 0, 4)

        geometry = BoxGeometry()
        material = SurfaceBasicMaterial({"useVertexColors": 1})
        self.mesh = Mesh(geometry, material)

        self.scene.add(self.mesh)
示例#8
0
def main():

    config = pyglet.gl.Config(double_buffer=True, sample_buffers=1, samples=4)

    win = pyglet.window.Window(config=config)

    renderer = Renderer()
    scene = Scene()
    camera = Camera()

    camera.translate(0, 0, 2)

    particleSystem = ParticleSystem()

    scene.add(particleSystem.boundBoxMesh)
    scene.add(particleSystem.particleMesh)

    def update(dt: float):
        particleSystem()
        # mesh.rotate(0, 0.1, 0.1)

    clock = pyglet.clock.schedule_interval(update, 1 / 120)

    @win.event
    def on_draw():
        win.clear()
        renderer.render(scene, camera)

    @win.event
    def on_mouse_drag(x, y, dx, dy, buttons, modifiers):
        if buttons & pyglet.window.mouse.RIGHT:
            scene.rotate(-dy / 10, dx / 10, 0)

    @win.event
    def on_mouse_scroll(x, y, scroll_x, scroll_y):
        camera.translate(0, 0, -scroll_y)

    # @win.event
    # def on_key_press(symbol, modifiers):
    #     if symbol == pyglet.window.key.A:
    #         camera.translate(-0.1, 0, 0)
    #     if symbol == pyglet.window.key.D:
    #         camera.translate(0.1, 0, 0)
    #     if symbol == pyglet.window.key.W:
    #         camera.translate(0, 0.1, 0)
    #     if symbol == pyglet.window.key.S:
    #         camera.translate(0,-0.1, 0)

    pyglet.app.run()
示例#9
0
文件: selfie.py 项目: xe1gyq/NuupXe
    def __init__(self, voicesynthetizer):

        self.modulename = 'Selfie'
	self.camera = Camera(voicesynthetizer)
        self.phonetic = Phonetic()
	self.twitterc = TwitterC('twython')
        self.voicesynthetizer = voicesynthetizer
示例#10
0
    def initialize(self):
        print("Initializing program...")

        self.renderer = Renderer()
        self.scene = Scene()
        self.camera = Camera()

        self.rig = MovementRig()
        self.rig.add(self.camera)
        self.scene.add(self.rig)
        self.rig.setPosition(0, 0, 4)

        geometry = BoxGeometry()
        material = SurfaceBasicMaterial({"useVertexColors": 1})
        self.mesh = Mesh(geometry, material)
        self.mesh.rotateX(0.6)
        self.mesh.rotateY(-0.6)
        self.mesh.rotateZ(-0.4)

        self.scene.add(self.mesh)

        # add a backdrop
        backGeometry = PolygonGeometry(sides=64, radius=2)
        backMaterial = SurfaceBasicMaterial({"baseColor": [1, 1, 0]})
        self.backdrop = Mesh(backGeometry, backMaterial)
        self.backdrop.rotateX(1.57)
        self.backdrop.setPosition(0, -1, 0)
        self.scene.add(self.backdrop)
示例#11
0
文件: media.py 项目: codewrite/PiCam1
 def get(self):
     response = make_response(
         send_file(BytesIO(Camera().get_frame()), mimetype='image/jpg'))
     response.headers[
         'Cache-Control'] = "no-store, no-cache, must-revalidate"
     response.headers['Expires'] = datetime.utcnow().strftime(
         '%a, %d %b %Y %H:%M:%S GMT')
     return response
示例#12
0
    def enter(self, **kwargs):
        game_instance = game.instance
        level = game_instance.state.get_current_level()
        map = level.map

        camera_limits = pygame.Rect(0, 0, map.size[0] * TILE_SIZE,
                                    map.size[1] * TILE_SIZE)
        camera_limits.width = max(camera_limits.width, DISPLAY_SIZE[0])
        camera_limits.height = max(camera_limits.height, DISPLAY_SIZE[1])
        camera_limits.inflate_ip(DISPLAY_SIZE[0] // 2, DISPLAY_SIZE[1] // 2)

        self.camera = Camera(DISPLAY_SIZE,
                             pos=(0, 0),
                             pan_speed=HALF_TILE_SIZE,
                             limits=camera_limits)

        map_surf = render.create_level_surf(level)
        render.render_level_map(map_surf, level)
        self.map_surf = map_surf
def check_cams():
    try:
        mux = CameraMux()
        mux.selectCamera(1)
    except Exception as e:
        log_error(e)
        logger.error("MUX init failed. Not attempting to init cameras")
    else:
        logger.info("MUX initialized successfully")
        camera = Camera()
        for i in [1, 2, 3]:
            try:
                mux.selectCamera(i)
                f, t = camera.rawObservation(
                    f"initialization-{i}-{int(time())}")
            except Exception as e:
                log_error(e)
                logger.error(f"CAM{i} init failed")
            else:
                logger.info(f"CAM{i} initialized successfully: {f}: {t}")
示例#14
0
def main():

    renderer, scene, camera = Renderer(), Scene(), Camera()

    geometry = TorusGeometry()
    material = SurfaceMaterial()
    mesh = Mesh(geometry, material)

    scene.add(mesh)
    mesh.translate(0, 0, -5)

    win = Window(renderer, scene, camera)
示例#15
0
文件: selfie.py 项目: xe1gyq/NuupXe
class Selfie(object):

    def __init__(self, voicesynthetizer):

        self.modulename = 'Selfie'
	self.camera = Camera(voicesynthetizer)
        self.phonetic = Phonetic()
	self.twitterc = TwitterC('twython')
        self.voicesynthetizer = voicesynthetizer

    def setup(self):

        logging.info('Selfie Setup')
        self.conf = ConfigParser.ConfigParser()
        self.path = "configuration/general.config"
        self.conf.read(self.path)
        self.hashtag = self.conf.get("system", "hashtag")

    def get(self):

        logging.info('Selfie Get')
        self.setup()

        try:
            self.camera.pictureCapture()
            media = self.camera.picturePath()
            message = Randomizer(2) + ' ' + self.hashtag + ' #Selfie '
            message = message + 'Voice Infrastructure ... Visit me @ https://github.com/xe1gyq/nuupxe'
            logging.info(message)
            self.twitterc.timeline_set(message, media)
            message = "Hola! Mi selfie en twitter.com/ " + 'nuup x e'
            self.voicesynthetizer.speechit(message)
            message = ' '.join(self.phonetic.decode("nuupxe"))
            self.voicesynthetizer.speechit(message)
        except:
            logging.error('Cannot open Camera device')

        alive(modulename=self.modulename, media=media)
示例#16
0
    def enter(self, **kwargs):
        game_instance = game.instance
        level = game_instance.state.get_current_level()
        map = level.map

        camera_limits = pygame.Rect(0, 0, map.size[0] * TILE_SIZE, map.size[1] * TILE_SIZE)
        camera_limits.width = max(camera_limits.width, DISPLAY_SIZE[0])
        camera_limits.height = max(camera_limits.height, DISPLAY_SIZE[1])
        camera_limits.inflate_ip(DISPLAY_SIZE[0] // 2, DISPLAY_SIZE[1] // 2)

        self.camera = Camera(DISPLAY_SIZE, pos=(0, 0), pan_speed=HALF_TILE_SIZE, limits=camera_limits)

        map_surf = render.create_level_surf(level)
        render.render_level_map(map_surf, level)
        self.map_surf = map_surf
示例#17
0
    def initialize(self):
        print("Initializing program...")

        self.renderer = Renderer()
        self.scene = Scene()
        self.camera = Camera()
        self.rig = MovementRig(unitsPerSecond=25, degreesPerSecond=90)
        self.rig.add(self.camera)
        self.scene.add(self.rig)
        self.rig.setPosition(0, 0, 4)

        geometry = GridDotGeometry(width=1000,
                                   height=1000,
                                   heightResolution=300,
                                   widthResolution=300)
        material = SurfaceBasicMaterial({"useVertexColors": 1})
        self.mesh = Mesh(geometry, material)

        self.scene.add(self.mesh)
        self.scene.add(AxesHelper(axisLength=3, lineWidth=2))
示例#18
0
    def initialize(self):
        print("Initializing program...")

        self.renderer = Renderer()
        self.scene = Scene()
        self.camera = Camera()

        self.rig = MovementRig()
        self.rig.add(self.camera)
        self.scene.add(self.rig)
        self.rig.setPosition(0, 0, 4)

        geometry = PlaneGeometry(width=100, height=100,widthResolution=100, heightResolution=100)
        material = SurfaceBasicMaterial({"useVertexColors":1})
        self.terrain = Mesh(geometry, material)
        self.terrain.rotateX(3.14/2)
        self.scene.add(self.terrain)





        self.scene.add(AxesHelper(axisLength=3))
示例#19
0
 def put(self):
     Camera().TakeStillShot()
示例#20
0
 def get(self):
     return Utils.convertToDictinary(Camera().camera)
示例#21
0
 def put(self):
     parser = reqparse.RequestParser()
     parser.add_argument("text", default="", type=str)
     args = parser.parse_args()
     Camera().annotateText = args["text"]
示例#22
0
class GameLayer(SceneLayer):
    def __init__(self):
        super(GameLayer, self).__init__()
        self.camera = None
        self.map_surf = None

    def enter(self, **kwargs):
        game_instance = game.instance
        level = game_instance.state.get_current_level()
        map = level.map

        camera_limits = pygame.Rect(0, 0, map.size[0] * TILE_SIZE,
                                    map.size[1] * TILE_SIZE)
        camera_limits.width = max(camera_limits.width, DISPLAY_SIZE[0])
        camera_limits.height = max(camera_limits.height, DISPLAY_SIZE[1])
        camera_limits.inflate_ip(DISPLAY_SIZE[0] // 2, DISPLAY_SIZE[1] // 2)

        self.camera = Camera(DISPLAY_SIZE,
                             pos=(0, 0),
                             pan_speed=HALF_TILE_SIZE,
                             limits=camera_limits)

        map_surf = render.create_level_surf(level)
        render.render_level_map(map_surf, level)
        self.map_surf = map_surf

    def update(self, **kwargs):
        keys = kwargs['keys']

        scroll_dir = [0, 0]
        if keys[pygame.K_LEFT]:
            scroll_dir[0] = -1
        if keys[pygame.K_RIGHT]:
            scroll_dir[0] = 1
        if keys[pygame.K_UP]:
            scroll_dir[1] = -1
        if keys[pygame.K_DOWN]:
            scroll_dir[1] = 1
        self.camera.pan(scroll_dir)

    def draw(self, surf, **kwargs):
        game_instance = game.instance
        level = game_instance.state.get_current_level()

        camera = self.camera

        surf.blit(self.map_surf, (0, 0, camera.view.width, camera.view.height),
                  camera.view)
        render.render_level_rooms(surf, level, self.camera)
        render.render_level_beings(surf, level, self.camera)

    def on_mouse_button_down(self, pos, button):
        game_instance = game.instance
        level = game_instance.state.get_current_level()
        map = level.map

        camera = self.camera

        if button == MOUSE_BUTTON_RIGHT:
            click_tile = util.pixel_to_tile(pos, camera.view.topleft)
            if map.get_passable(click_tile[0], click_tile[1]):

                for being in level.get_beings_owned_by(level.human_player):
                    being_tile = being.pos
                    path = pathing.astar(being_tile, click_tile,
                                         level.map.passability_data)

                    move = action.MoveAction(path)
                    being.action.clear()
                    being.action.swap_action(move)

                return True

        return False
示例#23
0
文件: media.py 项目: codewrite/PiCam1
 def get(self):
     return Response(gen(Camera()),
                     mimetype='multipart/x-mixed-replace; boundary=frame')
示例#24
0
class ContextWrapper(metaclass=singleton.Singleton):
    def __init__(self, w, h):
        self._context = Context()
        self._camera = Camera(0, 0, w, h)
        self._camera.set_active()
        self._running = False
        self._mode = SELECT_MODE
        self._selected = []
        self._ruler = (0, 0, 0, 0)
        self._selection_area = (0, 0, 0, 0)
        self._frames = []

    def get_data(self):
        return self._context._get_objects_data()

    def set_data(self, data):
        self._context._set_objects_data(data)

    def get_ruler(self):
        return self._ruler

    def set_ruler(self, *args):
        self._ruler = args

    def get_objects(self):
        return self._context._objects

    def get_camera(self):
        return self._camera

    def get_selected(self):
        return tuple(self._selected)

    def get_mode(self):
        return self._mode

    def get_selection_area(self):
        return self._selection_area

    def set_selection_area(self, x1, y1, x2, y2):
        self._selection_area = (x1, y1, x2, y2)

    def set_select_mode(self):
        self._mode = SELECT_MODE
        window = tuple(pyglet.app.windows)[0]
        cursor = window.get_system_mouse_cursor(window.CURSOR_DEFAULT)
        window.set_mouse_cursor(cursor)

    def set_move_mode(self):
        self._mode = MOVE_MODE
        window = tuple(pyglet.app.windows)[0]
        cursor = window.get_system_mouse_cursor(window.CURSOR_SIZE)
        window.set_mouse_cursor(cursor)

    def set_ruler_mode(self):
        self._mode = RULER_MODE
        window = tuple(pyglet.app.windows)[0]
        cursor = window.get_system_mouse_cursor(window.CURSOR_CROSSHAIR)
        window.set_mouse_cursor(cursor)

    def resize(self, w, h):
        self._camera.w = w
        self._camera.h = h

    def add_object(self, *args, **kwargs):
        obj = RigidBody(*args, **kwargs)
        self._context._objects.append(obj)

    def delete_selected(self):
        while self._selected:
            obj = self._selected.pop()
            self._objects.remove(obj)

    def select_closer(self, x, y):
        point_x = (x - self._camera.centerx) / self._camera.zoom
        point_y = (y - self._camera.centery) / self._camera.zoom
        min_dist = 20 * self._camera.zoom
        closer = None

        for obj in self._context._objects:
            dist_x = point_x - obj.position[0]
            dist_y = point_y - obj.position[1]
            dist = (dist_x * dist_x + dist_y * dist_y)**0.5

            if dist < min_dist:
                min_dist = dist
                closer = obj

        self._selected.clear()
        if closer is not None:
            self._selected = [closer]

    def select_area(self):
        if self._selection_area is not None:
            x1, y1, x2, y2 = self._selection_area
            x1, x2 = sorted((x1, x2))
            y1, y2 = sorted((y1, y2))

            zoom = self._camera.zoom
            for obj in self._context._objects:
                pos = obj.position * zoom
                x = pos[0] + self._camera.centerx
                y = pos[1] + self._camera.centery
                if x1 < x < x2 and y1 < y < y2:
                    self._selected.append(obj)

    def zoom_out(self):
        if self._camera.zoom > 0.05:
            self._camera.zoom *= 10 / 11
            self._camera.x *= 10 / 11
            self._camera.y *= 10 / 11

    def zoom_in(self):
        self._camera.zoom *= 11 / 10
        self._camera.x *= 11 / 10
        self._camera.y *= 11 / 10

    def move_camera(self, dx, dy):
        self._camera.x += dx
        self._camera.y += dy

    def move_selected(self, x, y):
        for obj in self.get_selected():
            obj.position += (x, y)

    def toggle_pause(self):
        self._running = not self._running

    def camera_to_home(self):
        self._camera.to_home()

    def update(self, dt):
        if self._running:
            self._context._update(dt)
示例#25
0
Create a light source.
Add objects to the Scene.
Generate data structure for the Scene with optimize().

Create an engine object with that contains methods for ray tracings.
Give the scene to the engine that outputs a picture.

Show the picture.

"""

if __name__ == "__main__":

    engine = Engine(500, 500)

    camera = Camera([0, 0, 0], [1, 0, 0], [0, -1, 0], fov=1)
    #camera = ThinLensCamera([0,0,0], [1,0,0], [0,-1,0], radius=0.0, focal_distance=6, fov=1)

    #light = Light([10,0,10])
    #light = LightProb("hdrmap/grace_probe.pfm")
    light = LightProb("hdrmap/stpeters_probe.pfm")

    scene = Scene(light)

    #scene.addobject(Sphere([0,0,0], 1000, anti=True))

    #scene.addobject(Triangle(([-1000, -1000, 200], [1000,-1000, 200], [1000,1000, 200]), color=[255,0,0]))
    #scene.addobject(Triangle(([-1000, -1000, 200], [1000,1000, 200], [-1000, 1000, 200])))

    #scene.addobject(Triangle(([-10000, -10000, -1000], [10000,-10000, -1000], [10000,10000, -1000])))
    #scene.addobject(Triangle(([-10000, -10000, -1000], [10000,10000, -1000], [-10000, 10000, -1000])))
示例#26
0
 def get(self):
     text = Camera().annotateText
     return {'text': text}
示例#27
0
class GameLayer(SceneLayer):
    def __init__(self):
        super(GameLayer, self).__init__()
        self.camera = None
        self.map_surf = None

    def enter(self, **kwargs):
        game_instance = game.instance
        level = game_instance.state.get_current_level()
        map = level.map

        camera_limits = pygame.Rect(0, 0, map.size[0] * TILE_SIZE, map.size[1] * TILE_SIZE)
        camera_limits.width = max(camera_limits.width, DISPLAY_SIZE[0])
        camera_limits.height = max(camera_limits.height, DISPLAY_SIZE[1])
        camera_limits.inflate_ip(DISPLAY_SIZE[0] // 2, DISPLAY_SIZE[1] // 2)

        self.camera = Camera(DISPLAY_SIZE, pos=(0, 0), pan_speed=HALF_TILE_SIZE, limits=camera_limits)

        map_surf = render.create_level_surf(level)
        render.render_level_map(map_surf, level)
        self.map_surf = map_surf

    def update(self, **kwargs):
        keys = kwargs['keys']

        scroll_dir = [0, 0]
        if keys[pygame.K_LEFT]:
            scroll_dir[0] = -1
        if keys[pygame.K_RIGHT]:
            scroll_dir[0] = 1
        if keys[pygame.K_UP]:
            scroll_dir[1] = -1
        if keys[pygame.K_DOWN]:
            scroll_dir[1] = 1
        self.camera.pan(scroll_dir)

    def draw(self, surf, **kwargs):
        game_instance = game.instance
        level = game_instance.state.get_current_level()

        camera = self.camera

        surf.blit(self.map_surf, (0, 0, camera.view.width, camera.view.height), camera.view)
        render.render_level_rooms(surf, level, self.camera)
        render.render_level_beings(surf, level, self.camera)

    def on_mouse_button_down(self, pos, button):
        game_instance = game.instance
        level = game_instance.state.get_current_level()
        map = level.map

        camera = self.camera

        if button == MOUSE_BUTTON_RIGHT:
            click_tile = util.pixel_to_tile(pos, camera.view.topleft)
            if map.get_passable(click_tile[0], click_tile[1]):

                for being in level.get_beings_owned_by(level.human_player):
                    being_tile = being.pos
                    path = pathing.astar(being_tile, click_tile, level.map.passability_data)

                    move = action.MoveAction(path)
                    being.action.clear()
                    being.action.swap_action(move)

                return True

        return False
def video_feed():
    """Video streaming route. Put this in the src attribute of an img tag."""
    return Response(gen(Camera()),
                    mimetype='multipart/x-mixed-replace; boundary=frame')