def set_up(self): self.display_region = base.camNode.get_display_region(0) win = self.display_region.get_window() self.perspective_lens = PerspectiveLens() self.perspective_lens = base.camLens # use panda3d's default for automatic aspect ratio on window resize self.lens = self.perspective_lens self.perspective_lens.set_aspect_ratio(window.aspect_ratio) self.perspective_lens_node = LensNode('perspective_lens_node', self.perspective_lens) self.lens_node = self.perspective_lens_node self.orthographic_lens = OrthographicLens() self.orthographic_lens.set_film_size(self.fov * window.aspect_ratio, self.fov) self.orthographic_lens_node = LensNode('orthographic_lens_node', self.orthographic_lens) application.base.cam.node().set_lens(self.lens) self.orthographic = False self.fov = 40 # horizontal fov # self.fov = 22.5 self.clip_plane_near = 0.1 self.clip_plane_far = 10000 self.ui_display_region = win.make_display_region() self.ui_display_region.set_sort(20) self.ui_camera = NodePath(PandaCamera('ui_camera')) self.ui_lens = OrthographicLens() # moved set_film_size() to window module for correct aspect ratio after setting window size self.ui_lens.set_near_far(-1000, 1000) self.ui_camera.node().set_lens(self.ui_lens) self._ui_lens_node = LensNode('_ui_lens_node', self.ui_lens) self.ui_render = NodePath('ui_render') self.ui_render.set_depth_test(0) self.ui_render.set_depth_write(0) self.ui_camera.reparent_to(self.ui_render) self.ui_display_region.set_camera(self.ui_camera) scene.ui_camera = self.ui_camera self.ui = Entity(eternal=True, name='ui', parent=self.ui_camera, scale=(self.ui_size * .5, self.ui_size * .5)) self.overlay = Entity(parent=self.ui, model='quad', scale=99, color=color.clear, eternal=True, z=-99) # these get created when setting a shader self.filter_manager = None self.filter_quad = None self.render_texture = None self.filter_quad = None self.depth_texture = None
def set_lens(self, lens_type="OrthographicLens"): """ Permite cambiar la lente de la camara :param lens_type: El tipo de lente a utilizar: OrthographicLens/PerspectiveLens :return: None """ self.lens_type = lens_type width = self.panda3d.win.getXSize() height = self.panda3d.win.getYSize() if lens_type is "OrthographicLens": lens = OrthographicLens() lens.setFilmSize(width, height ) if lens_type is "PerspectiveLens": lens = PerspectiveLens() lens.setFilmSize(width , height ) else: # Default value lens = OrthographicLens() lens.setFilmSize(width / 100, height / 100) print("new lens {}: {} {}".format(lens_type, width / 100, height / 100)) print(lens) self.panda3d.cam.node().setLens(lens) shader_control = self.panda3d.shader_control if shader_control is not None: shader_control.update_camera_lens(lens)
def set_up(self, use_filters=True): self.display_region = base.camNode.get_display_region(0) win = self.display_region.get_window() self.perspective_lens = PerspectiveLens() self.lens = self.perspective_lens self.perspective_lens.set_aspect_ratio(window.aspect_ratio) self.perspective_lens.set_focal_length(50) self.perspective_lens_node = LensNode('perspective_lens_node', self.perspective_lens) self.lens_node = self.perspective_lens_node self.orthographic_lens = OrthographicLens() self.orthographic_lens.set_film_size(self.fov * window.aspect_ratio, self.fov) self.orthographic_lens_node = LensNode('orthographic_lens_node', self.orthographic_lens) application.base.cam.node().set_lens(self.lens) self.orthographic = False self.fov = 40 self.clip_plane_near = 0.0001 self.clip_plane_far = 70000000 self.ui_display_region = win.make_display_region() self.ui_display_region.set_sort(20) self.ui_camera = NodePath(PandaCamera('ui_camera')) self.ui_lens = OrthographicLens() self.ui_lens.set_film_size(self.ui_size * .5 * self.aspect_ratio, self.ui_size * .5) self.ui_lens.set_near_far(-1000, 70000) self.ui_camera.node().set_lens(self.ui_lens) self._ui_lens_node = LensNode('_ui_lens_node', self.ui_lens) self.ui_render = NodePath('ui_render') self.ui_render.set_depth_test(0) self.ui_render.set_depth_write(0) self.ui_camera.reparent_to(self.ui_render) self.ui_display_region.set_camera(self.ui_camera) scene.ui_camera = self.ui_camera # ui_camera.hide() # self.black_bars_display_region = win.make_display_region() # self.black_bars_display_region.set_sort(-100) self.ui = Entity(eternal=True, name='ui', parent=self.ui_camera, scale=(self.ui_size * .5, self.ui_size * .5)) scene.ui = self.ui if (use_filters): self.filter_manager = FilterManager(base.win, base.cam) self.render_texture = PandaTexture() self.filter_quad = None
def set_up(self): self.display_region = base.camNode.get_display_region(0) win = self.display_region.get_window() self.perspective_lens = PerspectiveLens() self.lens = self.perspective_lens self.perspective_lens.set_aspect_ratio(window.aspect_ratio) self.perspective_lens.set_focal_length(50) self.perspective_lens_node = LensNode('perspective_lens_node', self.perspective_lens) self.lens_node = self.perspective_lens_node self.orthographic_lens = OrthographicLens() self.orthographic_lens.set_film_size(self.fov * window.aspect_ratio, self.fov) self.orthographic_lens_node = LensNode('orthographic_lens_node', self.orthographic_lens) application.base.cam.node().set_lens(self.lens) self.orthographic = False self.fov = 40 self.clip_plane_near = 0.0001 self.clip_plane_far = 10000 self.ui_display_region = win.make_display_region() self.ui_display_region.set_sort(20) self.ui_camera = NodePath(PandaCamera('ui_camera')) self.ui_lens = OrthographicLens() self.ui_lens.set_film_size(self.ui_size * .5 * self.aspect_ratio, self.ui_size * .5) self.ui_lens.set_near_far(-1000, 1000) self.ui_camera.node().set_lens(self.ui_lens) self._ui_lens_node = LensNode('_ui_lens_node', self.ui_lens) self.ui_render = NodePath('ui_render') self.ui_render.set_depth_test(0) self.ui_render.set_depth_write(0) self.ui_camera.reparent_to(self.ui_render) self.ui_display_region.set_camera(self.ui_camera) scene.ui_camera = self.ui_camera # ui_camera.hide() # self.black_bars_display_region = win.make_display_region() # self.black_bars_display_region.set_sort(-100) self.ui = Entity() self.ui.eternal = True self.ui.name = 'ui' self.ui.parent = self.ui_camera self.ui.scale = (self.ui_size * .5, self.ui_size * .5) # self.ui.model = 'quad' scene.ui = self.ui
def __init__(self): super().__init__() x = float(base.win.get_x_size()) y = float(base.win.get_y_size()) y_aspect = y / x inventory_base_width = INVENTORY_VERTICAL_FRACTION * y_aspect inventory_half_width = inventory_base_width * INVENTORY_HORIZONTAL_FACTOR * 0.5 self.region = base.win.make_display_region( 0.5 - inventory_half_width, # left 0.5 + inventory_half_width, # right 0.0, # bottom INVENTORY_VERTICAL_FRACTION, # top ) self.region.set_sort(INVENTORY_DISPLAY_REGION_SORT) self.cam_node = p3d.Camera('inventory_cam') lens = OrthographicLens() lens.set_film_size(INVENTORY_HORIZONTAL_FACTOR, 1) self.cam_node.set_lens(lens) self.cam_np = NodePath(self.cam_node) self.region.set_camera(self.cam_np) self.inventory = NodePath('inventory') self.cam_np.reparentTo(self.inventory) background_maker = CardMaker('inventory') background_maker.set_frame(-INVENTORY_HORIZONTAL_FACTOR / 2.0, INVENTORY_HORIZONTAL_FACTOR / 2.0, 0, 1) background = p3d.NodePath(background_maker.generate()) background.reparent_to(self.inventory) background.set_pos(0, 5, -0.5)
def __init__(self): base.disableMouse() lens = OrthographicLens() lens.setFilmSize(34.2007, 25.6505) lens.setNear(-10) lens.setFar(100) base.cam.node().setLens(lens) self.container = render.attachNewNode('camContainer') base.camera.reparentTo(self.container) base.camera.setPos(-40, 0, 23) base.camera.lookAt(0, 0, 3) self.container.setHpr(45, 0, 0) self.zoomed = True self.r = False # Load sounds self.toggle_r_snd = base.loader.loadSfx(GAME + '/sounds/camera_toggle_r.ogg') self.rotate_snd = base.loader.loadSfx(GAME + '/sounds/camera_rotate.ogg') self.acceptAll() self.windowEvent(base.win)
def create(self): self.camera = Camera("SkyAOCaptureCam") self.cam_lens = OrthographicLens() self.cam_lens.set_film_size(200, 200) self.cam_lens.set_near_far(0.0, 500.0) self.camera.set_lens(self.cam_lens) self.cam_node = Globals.base.render.attach_new_node(self.camera) self.cam_node.look_at(0, 0, -1) self.cam_node.set_r(0) self.target = self.create_target("SkyAOCapture") self.target.size = 1024 self.target.add_depth_attachment(bits=16) self.target.prepare_render(self.cam_node) self.target_convert = self.create_target("ConvertDepth") self.target_convert.size = 1024 self.target_convert.add_color_attachment(bits=(16, 0, 0, 0)) self.target_convert.prepare_buffer() self.target_convert.set_shader_input("DepthTex", self.target.depth_tex) self.target_convert.set_shader_input("position", self.pta_position) # Register camera self._pipeline.tag_mgr.register_camera("shadow", self.camera)
def __init__(self): super().__init__() self.set_background_color(0.1, 0.1, 0.1, 1) square1 = create_colored_rect(0, 0, 200, 200) square2 = create_colored_rect(350, 100, 200, 200, (0, 0, 1, 1)) square3 = create_colored_rect(-640, -360, 200, 200, (0, 1, 0, 1)) gnode = GeomNode('square') gnode.addGeom(square1) gnode.addGeom(square2) gnode.addGeom(square3) self.render.attachNewNode(gnode) gnode2 = GeomNode('square2') textured_rect = create_textured_rect(-320, 0, 200, 280) gnode2.addGeom(textured_rect) texture = self.loader.loadTexture("assets/images/PlayerShip.png") ship = self.render.attachNewNode(gnode2) ship.setTransparency(TransparencyAttrib.MAlpha) ship.setTexture(texture) lens = OrthographicLens() lens.setFilmSize(1280, 720) lens.setNearFar(-50, 50) self.cam.setPos(0, 0, 0) self.cam.node().setLens(lens)
def enable(self): camNode = Camera('shadowCam') camNode.setCameraMask(CIGlobals.ShadowCameraBitmask) self.shadowLens = OrthographicLens() self.shadowLens.setFilmSize(60 * 4, 60 * 4) camNode.setLens(self.shadowLens) self.shadowCamArm = camera.attachNewNode('shadowCamArm') self.shadowCam = self.shadowCamArm.attachNewNode(camNode) self.shadowCamArm.setPos(0, 40, 0) self.shadowCam.setPos(0, -40, 0) self.shadowTex = Texture('shadow') self.shadowTex.setBorderColor(self.clearColor) self.shadowTex.setWrapU(Texture.WMBorderColor) self.shadowTex.setWrapV(Texture.WMBorderColor) self.casterState = NodePath('temp') self.casterState.setColorScaleOff(10) self.casterState.setColor(self.shadowColor, self.shadowColor, self.shadowColor, 1, 10) self.casterState.setTextureOff(10) self.casterState.setLightOff(10) self.casterState.setFogOff(10) camNode.setInitialState(self.casterState.getState()) render.hide(CIGlobals.ShadowCameraBitmask) self.shadowStage = TextureStage('shadow') self.shadowStage.setSort(1000) self.turnOnShadows()
def __init__(self): super().__init__() self.set_background_color(0.1, 0.1, 0.1, 1) self.jack = self.loader.loadModel("assets/Jack/Jack") self.jack.setScale(0.3) self.jack.reparentTo(self.render) self.jack.find('**/+SequenceNode').node().loop(True, 10, 19) # self.jack.find('**/+SequenceNode').node().loop(True, 0, 9) lens = OrthographicLens() lens.setFilmSize(1280, 720) lens.setNearFar(-50, 50) self.cam.node().setLens(lens) self.accept("arrow_left", update_key_map, ["left", True, self.jack, True]) self.accept("arrow_left-up", update_key_map, ["left", False, self.jack, False]) self.accept("arrow_right", update_key_map, ["right", True, self.jack, True]) self.accept("arrow_right-up", update_key_map, ["right", False, self.jack, False]) self.taskMgr.add(self.move_jack, "move-jack") self.x = 0 self.speed = 200
def create(self): # Create voxelize camera self.voxelizeCamera = Camera("VoxelizeCamera") self.voxelizeCamera.setCameraMask(BitMask32.bit(4)) self.voxelizeCameraNode = Globals.render.attachNewNode( self.voxelizeCamera) self.voxelizeLens = OrthographicLens() self.voxelizeLens.setFilmSize(self.voxelGridSize * 2, self.voxelGridSize * 2) self.voxelizeLens.setNearFar(0.0, self.voxelGridSize * 2) self.voxelizeCamera.setLens(self.voxelizeLens) self.voxelizeCamera.setTagStateKey("VoxelizePassShader") Globals.render.setTag("VoxelizePassShader", "Default") # Create voxelize tareet self.target = RenderTarget("VoxelizePass") self.target.setSize(self.voxelGridResolution * self.gridResolutionMultiplier) if self.pipeline.settings.useDebugAttachments: self.target.addColorTexture() else: self.target.setColorWrite(False) self.target.setCreateOverlayQuad(False) self.target.setSource(self.voxelizeCameraNode, Globals.base.win) self.target.prepareSceneRender() self.target.setActive(False)
def setupCamera(self, _pos, _rot, _filmsize): # Setup lens, position and rotation lens = OrthographicLens() lens.setFilmSize(_filmsize[0], _filmsize[1]) #base.cam.node().setLens(lens) base.cam.setPos(_pos) base.cam.setHpr(_rot)
def __init__(self, app): self.app = app self.do = DirectObject() self.running = False self.displayRegion = None self.root = NodePath('creditsRender') self.camera = Camera('creditsCam') self.cameraNP = NodePath(self.camera) # Set parameters to match those of render2d self.root.setDepthTest(0) self.root.setDepthWrite(0) self.root.setMaterialOff(1) self.root.setTwoSided(1) self.aspect2d = self.root # self.root.attachNewNode('creditsAspect') lens = OrthographicLens() lens.setFilmSize(2, 2) lens.setFilmOffset(0, 0) lens.setNearFar(-1000, 1000) self.camera.setLens(lens) self.cameraNP.reparentTo(self.root) self.scrollTask = None self.lastTime = None self.creditsFileLoaded = False
def setupCamera2d(self, sort=10, displayRegion=(0, 1, 0, 1), coords=(-1, 1, -1, 1)): dr = self.win.makeMonoDisplayRegion(*displayRegion) dr.setSort(10) # Enable clearing of the depth buffer on this new display # region (see the comment in setupRender2d, above). dr.setClearDepthActive(1) # Make any texture reloads on the gui come up immediately. dr.setIncompleteRender(False) left, right, bottom, top = coords # Now make a new Camera node. cam2dNode = Camera('cam2d') lens = OrthographicLens() lens.setFilmSize(right - left, top - bottom) lens.setFilmOffset((right + left) * 0.5, (top + bottom) * 0.5) lens.setNearFar(-1000, 1000) cam2dNode.setLens(lens) # self.camera2d is the analog of self.camera, although it's # not as clear how useful it is. self.camera2d = self.render2d.attachNewNode('camera2d') camera2d = self.camera2d.attachNewNode(cam2dNode) dr.setCamera(camera2d) self.cam2d = camera2d return camera2d
def makeLens(self): lens = OrthographicLens() lens.setNearFar(-100000, 100000) lens.setViewHpr(self.getViewHpr()) lens.setFilmSize(100, 100) return lens
def create(self): winprops = WindowProperties.size(self.size, self.size) props = FrameBufferProperties() props.setRgbColor(0) props.setAlphaBits(0) props.setDepthBits(1) self.buffer = base.graphicsEngine.makeOutput( base.pipe, "shadowsBuffer", -2, props, winprops, GraphicsPipe.BFRefuseWindow, base.win.getGsg(), base.win) if not self.buffer: print("Video driver cannot create an offscreen buffer.") return self.depthmap = Texture() self.buffer.addRenderTexture(self.depthmap, GraphicsOutput.RTMBindOrCopy, GraphicsOutput.RTPDepthStencil) self.depthmap.setMinfilter(Texture.FTShadow) self.depthmap.setMagfilter(Texture.FTShadow) self.depthmap.setBorderColor(LColor(1, 1, 1, 1)) self.depthmap.setWrapU(Texture.WMBorderColor) self.depthmap.setWrapV(Texture.WMBorderColor) self.cam = base.makeCamera(self.buffer, lens=OrthographicLens()) self.cam.reparent_to(render) self.node = self.cam.node() self.node.setInitialState( RenderState.make( CullFaceAttrib.make_reverse(), ColorWriteAttrib.make(ColorWriteAttrib.M_none), )) self.node.setScene(render) if settings.debug_shadow_frustum: self.node.showFrustum()
def __init__(self): DirectObject.__init__(self) self.base = ShowBase() resolution = (1024, 768) wp = WindowProperties() wp.setSize(int(resolution[0]), int(resolution[1])) wp.setOrigin(0, 0) self.base.win.requestProperties(wp) # depth completely doesn't matter for this, since just 2d, and no layers self.depth = 0 self.base.setBackgroundColor(115 / 255, 115 / 255, 115 / 255) # set up a 2d camera camera = self.base.camList[0] lens = OrthographicLens() lens.setFilmSize(int(resolution[0]), int(resolution[1])) lens.setNearFar(-100, 100) camera.node().setLens(lens) camera.reparentTo(self.base.render) self.accept("escape", sys.exit) # spread out some positions self.positions = [(-200, 0, -200), (0, 0, -200), (200, 0, -200), (-200, 0, 0), (0, 0, 0), (200, 0, 0), (-200, 0, 200), (0, 0, 200), (200, 0, 200)] self.all_smiles()
def makeBufferRelCent(np, size=256): #we get a handle to the default window mainWindow = base.win #we now get buffer thats going to hold the texture of our new scene altBuffer = mainWindow.makeTextureBuffer("hello", size, size) altBuffer.setClearColor(Vec4(0.5, 0.5, 0.5, 0)) #now we have to setup a new scene graph to make this scene altRender = NodePath("new render") #this takes care of setting up ther camera properly altCam = base.makeCamera(altBuffer) altCam.reparentTo(altRender) #get the teapot and rotates it for a simple animation teapot = NodePath("dummy") np.instanceTo(teapot) pos, rel, cent = makePosRelCent(teapot) lens = OrthographicLens() lens.setFilmSize(*rel) altCam.setPos(pos) altCam.node().setLens(lens) teapot.reparentTo(altRender) altBuffer.setOneShot(True) return altBuffer, rel, cent
def makeOrthographic(parent, name, campos): v = Viewport(name, parent) v.lens = OrthographicLens() v.lens.setFilmSize(30) v.camPos = campos v.camLookAt = Point3(0, 0, 0) v.grid = DirectGrid(parent=render) if name == 'left': v.grid.setHpr(0, 0, 90) collPlane = CollisionNode('LeftGridCol') collPlane.addSolid(CollisionPlane(Plane(1, 0, 0, 0))) collPlane.setIntoCollideMask(BitMask32.bit(21)) v.collPlane = NodePath(collPlane) v.collPlane.wrtReparentTo(v.grid) #v.grid.gridBack.findAllMatches("**/+GeomNode")[0].setName("_leftViewGridBack") LE_showInOneCam(v.grid, name) elif name == 'front': v.grid.setHpr(90, 0, 90) collPlane = CollisionNode('FrontGridCol') collPlane.addSolid(CollisionPlane(Plane(0, -1, 0, 0))) collPlane.setIntoCollideMask(BitMask32.bit(21)) v.collPlane = NodePath(collPlane) v.collPlane.wrtReparentTo(v.grid) #v.grid.gridBack.findAllMatches("**/+GeomNode")[0].setName("_frontViewGridBack") LE_showInOneCam(v.grid, name) else: collPlane = CollisionNode('TopGridCol') collPlane.addSolid(CollisionPlane(Plane(0, 0, 1, 0))) collPlane.setIntoCollideMask(BitMask32.bit(21)) v.collPlane = NodePath(collPlane) v.collPlane.reparentTo(v.grid) #v.grid.gridBack.findAllMatches("**/+GeomNode")[0].setName("_topViewGridBack") LE_showInOneCam(v.grid, name) return v
def create(self): self.camera = Camera("PSSMDistShadowsESM") self.cam_lens = OrthographicLens() self.cam_lens.set_film_size(12000, 12000) self.cam_lens.set_near_far(10.0, self.sun_distance * 2) self.camera.set_lens(self.cam_lens) self.cam_node = Globals.base.render.attach_new_node(self.camera) self.target = self.create_target("ShadowMap") self.target.size = self.resolution self.target.add_depth_attachment(bits=32) self.target.prepare_render(self.cam_node) self.target_convert = self.create_target("ConvertToESM") self.target_convert.size = self.resolution self.target_convert.add_color_attachment(bits=(32, 0, 0, 0)) self.target_convert.prepare_buffer() self.target_convert.set_shader_input("SourceTex", self.target.depth_tex) self.target_blur_v = self.create_target("BlurVert") self.target_blur_v.size = self.resolution self.target_blur_v.add_color_attachment(bits=(32, 0, 0, 0)) self.target_blur_v.prepare_buffer() self.target_blur_v.set_shader_input("SourceTex", self.target_convert.color_tex) self.target_blur_v.set_shader_input("direction", LVecBase2i(1, 0)) self.target_blur_h = self.create_target("BlurHoriz") self.target_blur_h.size = self.resolution self.target_blur_h.add_color_attachment(bits=(32, 0, 0, 0)) self.target_blur_h.prepare_buffer() self.target_blur_h.set_shader_input("SourceTex", self.target_blur_v.color_tex) self.target_blur_h.set_shader_input("direction", LVecBase2i(0, 1)) # Register shadow camera self._pipeline.tag_mgr.register_camera("shadow", self.camera)
def renderQuadInto(self, mul=1, div=1, align=1, depthtex=None, colortex=None, auxtex0=None, auxtex1=None): texgroup = ( depthtex, colortex, auxtex0, auxtex1) winx, winy = self.getScaledSize(mul, div, align) depthbits = bool(depthtex != None) buffer = self.createBuffer('filter-stage', winx, winy, texgroup, depthbits) if buffer == None: return cm = CardMaker('filter-stage-quad') cm.setFrameFullscreenQuad() quad = NodePath(cm.generate()) quad.setDepthTest(0) quad.setDepthWrite(0) quad.setColor(1, 0.5, 0.5, 1) quadcamnode = Camera('filter-quad-cam') lens = OrthographicLens() lens.setFilmSize(2, 2) lens.setFilmOffset(0, 0) lens.setNearFar(-1000, 1000) quadcamnode.setLens(lens) quadcam = quad.attachNewNode(quadcamnode) dr = buffer.makeDisplayRegion((0, 1, 0, 1)) dr.disableClears() dr.setCamera(quadcam) dr.setActive(True) dr.setScissorEnabled(False) buffer.setClearColor((0, 0, 0, 1)) buffer.setClearColorActive(True) self.buffers.append(buffer) self.sizes.append((mul, div, align)) return quad
def setupOrthographicProjectionAndViewingAccordingToMyConvention( lookat_position=Vec3(0, 0, 0), camera_position=Vec3(5, 5, 2)): # setup orthographic projection, make camera fixed and look at origin. # In this script, the convention is to have the z axis (z axis is up in # p3d) centered horizontally, pointing up, and the 3d world coordinate # space origin centered in the middle of the window, the window only # shows a range of $z \in [-1, +1]$ # the main camera can be accessed by base.cam or base.camera # You can even get the Matrix associated with that camera # I'm not sure what the difference between Lens Matrices and Camera # Matrices are # mat = base.cam.getMat() # print("cam.getMat(): ", mat) # The camera already comes with a Lens(), but I want to set my own # make custom orthographic Lens() (the camera is just a Node) # orthographic: setting the projection matrix lens = OrthographicLens() # The total height ($z \in [-1, +1]$) is here fixed to be 2. # setting the view matrix as a function of the p3d window's # aspect ratio lens_view_height_in_world_coords = 5. lens_view_width_in_world_coords = ( lens_view_height_in_world_coords * engine.tq_graphics_basics.get_window_aspect_ratio()) print(lens_view_width_in_world_coords, lens_view_height_in_world_coords) # setFilmSize specifies the size of the Lens box # I call it a *viewing box* if the projection matrix produces # orthogonal projection, and *viewing frustum* if the projection # matrix includes perspective) lens.setFilmSize(lens_view_width_in_world_coords, lens_view_height_in_world_coords) lens.setNearFar(0.001, 50.) # you can also check for the properties of your lens/camera print("orthographic: ", lens.isOrthographic()) # finally, set the just created Lens() to your main camera base.cam.node().setLens(lens) # Make sure that what you want to display is within the Lenses box # (beware of near and far planes) # Since it's orthogonal projection, letting the camera's position # vary doesn't do anything to the displayed content (except maybe # hiding it beyond the near/far planes) # this manipulates the viewing matrix base.cam.setPos(camera_position[0], camera_position[1], camera_position[2]) base.cam.lookAt(lookat_position) # this manipulates the viewing matrix # -- set faint ambient white lighting from panda3d.core import AmbientLight alight = AmbientLight('alight') alnp = engine.tq_graphics_basics.tq_render.attachNewNode_p3d(alight) alight.setColor(Vec4(0.35, 0.35, 0.35, 1)) engine.tq_graphics_basics.tq_render.setLight(alnp)
def orthographic(): global PERSPECTIVE PERSPECTIVE = False sandbox.base.disableMouse() sandbox.base.camera.setPos(0, 0, 3000) sandbox.base.camera.setHpr(0, -90, 0) lens = OrthographicLens() lens.setFilmSize(10) sandbox.base.cam.node().setLens(lens)
def __init__(self): ShowBase.__init__(self) lens = OrthographicLens() base.cam.node().setLens(lens) panda = TestPanda3d("testPanda3d") #print("panda:" + str(panda.is_empty())) panda.reparentTo(render)
def renderQuadInto(self, mul=1, div=1, align=1, depthtex=None, colortex=None, auxtex0=None, auxtex1=None): """ Creates an offscreen buffer for an intermediate computation. Installs a quad into the buffer. Returns the fullscreen quad. The size of the buffer is initially equal to the size of the main window. The parameters 'mul', 'div', and 'align' can be used to adjust that size. """ texgroup = (depthtex, colortex, auxtex0, auxtex1) winx, winy = self.getScaledSize(mul, div, align) depthbits = bool(depthtex != None) buffer = self.createBuffer("filter-stage", winx, winy, texgroup, depthbits) if (buffer == None): return None cm = CardMaker("filter-stage-quad") cm.setFrameFullscreenQuad() quad = NodePath(cm.generate()) quad.setDepthTest(0) quad.setDepthWrite(0) quad.setColor(1, 0.5, 0.5, 1) quadcamnode = Camera("filter-quad-cam") lens = OrthographicLens() lens.setFilmSize(2, 2) lens.setFilmOffset(0, 0) lens.setNearFar(-1000, 1000) quadcamnode.setLens(lens) quadcam = quad.attachNewNode(quadcamnode) dr = buffer.makeDisplayRegion((0, 1, 0, 1)) dr.disableClears() dr.setCamera(quadcam) dr.setActive(True) dr.setScissorEnabled(False) # This clear stage is important if the buffer is padded, so that # any pixels accidentally sampled in the padded region won't # be reading from unititialised memory. buffer.setClearColor((0, 0, 0, 1)) buffer.setClearColorActive(True) self.buffers.append(buffer) self.sizes.append((mul, div, align)) return quad
def _makeFullscreenCam(self): bufferCam = Camera("BufferCamera") lens = OrthographicLens() lens.setFilmSize(2, 2) lens.setFilmOffset(0, 0) lens.setNearFar(-1000, 1000) bufferCam.setLens(lens) bufferCam.setCullBounds(OmniBoundingVolume()) return bufferCam
def setup(self,task): lens = OrthographicLens() lens.setFilmSize(25,20) base.camNode.setLen(lens) self.player = self.marioGfx self.marioGfx return Task.done
def renderSceneInto(self, depthtex=None, colortex=None, auxtex=None, auxbits=0, textures=None): if textures: colortex = textures.get('color', None) depthtex = textures.get('depth', None) auxtex = textures.get('aux', None) auxtex0 = textures.get('aux0', auxtex) auxtex1 = textures.get('aux1', None) else: auxtex0 = auxtex auxtex1 = None if colortex == None: colortex = Texture('filter-base-color') colortex.setWrapU(Texture.WMClamp) colortex.setWrapV(Texture.WMClamp) texgroup = (depthtex, colortex, auxtex0, auxtex1) winx, winy = self.getScaledSize(1, 1, 1) buffer = self.createBuffer('filter-base', winx, winy, texgroup) if buffer == None: return cm = CardMaker('filter-base-quad') cm.setFrameFullscreenQuad() quad = NodePath(cm.generate()) quad.setDepthTest(0) quad.setDepthWrite(0) quad.setTexture(colortex) quad.setColor(1, 0.5, 0.5, 1) cs = NodePath('dummy') cs.setState(self.camstate) if auxbits: cs.setAttrib(AuxBitplaneAttrib.make(auxbits)) self.camera.node().setInitialState(cs.getState()) quadcamnode = Camera('filter-quad-cam') lens = OrthographicLens() lens.setFilmSize(2, 2) lens.setFilmOffset(0, 0) lens.setNearFar(-1000, 1000) quadcamnode.setLens(lens) quadcam = quad.attachNewNode(quadcamnode) self.region.setCamera(quadcam) self.setStackedClears(buffer, self.rclears, self.wclears) if auxtex0: buffer.setClearActive(GraphicsOutput.RTPAuxRgba0, 1) buffer.setClearValue(GraphicsOutput.RTPAuxRgba0, (0.5, 0.5, 1.0, 0.0)) if auxtex1: buffer.setClearActive(GraphicsOutput.RTPAuxRgba1, 1) self.region.disableClears() if self.isFullscreen(): self.win.disableClears() dr = buffer.makeDisplayRegion() dr.disableClears() dr.setCamera(self.camera) dr.setActive(1) self.buffers.append(buffer) self.sizes.append((1, 1, 1)) return quad
def _make_fullscreen_cam(self): """ Creates an orthographic camera for the buffer """ buffer_cam = Camera("BufferCamera") lens = OrthographicLens() lens.set_film_size(2, 2) lens.set_film_offset(0, 0) lens.set_near_far(-100, 100) buffer_cam.set_lens(lens) buffer_cam.set_cull_bounds(OmniBoundingVolume()) self._camera = self._node.attach_new_node(buffer_cam) self._region.set_camera(self._camera)
def setupOrtographicLens(self, near=0.1, far=100.0, filmSize=(512, 512)): """ Setups a OrtographicLens with a given near plane, far plane and film size. The film size is a tuple in the format (filmWidth, filmHeight) in world space. """ self.lens = OrthographicLens() self.lens.setNearFar(near, far) self.lens.setFilmSize(*filmSize) self.camera.setLens(self.lens) self.nearPlane = near self.farPlane = far self.rebuildMatrixCache()