ProjectionScreen

from panda3d.fx import ProjectionScreen
class ProjectionScreen

Bases:

Bases: PandaNode

A ProjectionScreen implements a simple system for projective texturing. The ProjectionScreen node is the parent of a hierarchy of geometry that is considered a “screen”; the ProjectionScreen will automatically recompute all the UV’s (for a particular texture stage) on its subordinate geometry according to the relative position and lens parameters of the indicated LensNode.

All this does is recompute UV’s; the caller is responsible for applying the appropriate texture(s) to the geometry.

This does not take advantage of any hardware-assisted projective texturing; all of the UV’s are computed in the CPU. (Use NodePath.projectTexture() to enable hardware-assisted projective texturing.) However, the ProjectionScreen interface does support any kind of lens, linear or nonlinear, that might be defined using the Lens interface, including fisheye and cylindrical lenses.

Inheritance diagram

Inheritance diagram of ProjectionScreen

__init__(name: str)
clearUndistLut()

Removes the distortion lookup table from the projector, if specified.

generateScreen(projector: panda3d.core.NodePath, screen_name: str, num_x_verts: int, num_y_verts: int, distance: float, fill_ratio: float) panda3d.core.GeomNode

Synthesizes a polygon mesh based on the projection area of the indicated projector. This generates and returns a new GeomNode but does not automatically parent it to the ProjectionScreen node; see regenerateScreen().

The specified projector need not be the same as the projector given to the ProjectionScreen with setProjector() (although this is often what you want).

num_x_verts and num_y_verts specify the number of vertices to make in the grid across the horizontal and vertical dimension of the projector, respectively; distance represents the approximate distance of the screen from the lens center.

The fill_ratio parameter specifies the fraction of the image to cover. If it is 1.0, the entire image is shown full-size; if it is 0.9, 10% of the image around the edges is not part of the grid (and the grid is drawn smaller by the same 10%). This is intended to work around graphics drivers that tend to show dark edges or other unsatisfactory artifacts around the edges of textures: render the texture larger than necessary by a certain fraction, and make the screen smaller by the inverse fraction.

getAutoRecompute() bool

Returns the auto_recompute flag. When this is true, the ProjectionScreen will always be recomputed if necessary before the frame is drawn; when it is false, an explicit call to recomputeIfStale() may be required.

static getClassType() panda3d.core.TypeHandle
getFrameColor() panda3d.core.LColor

Returns the color the screen will be painted at the portions outside of the lens’ frustum. See setFrameColor().

getInvertUvs() bool

Returns whether this screen is compensating for a graphics driver inverting the framebuffer image. See setInvertUvs().

getLastScreen() panda3d.core.UpdateSeq

Returns an UpdateSeq corresponding to the last time a screen mesh was generated for the ProjectionScreen. Each time generateScreen() is called, this number is incremented; this allows other objects (like NonlinearImager) to know when they need to recompute themselves.

getProjector() panda3d.core.NodePath

Returns the NodePath to the LensNode that is to serve as the projector for this screen, or empty if no projector is associated.

getTexcoord3d() bool

See setTexcoord3d().

getTexcoordName() str

Returns the name of the texture coordinates that will be generated by this particular ProjectionScreen, as set by setTexcoordName().

getUndistLut() panda3d.core.PfmFile

Returns the distortion lookup table provided via setUndistLut(), if any.

getVignetteColor() panda3d.core.LColor

Returns the color the screen will be painted at the portions outside of the lens’ frustum. See setVignetteColor().

getVignetteOn() bool

Returns true if vertex-based vignetting is on, false otherwise. See setVignetteOn().

hasUndistLut() bool

Returns true if a valid distortion lookup table was provided via setUndistLut(), false otherwise.

makeFlatMesh(this_np: panda3d.core.NodePath, camera: panda3d.core.NodePath) panda3d.core.PandaNode

Generates a deep copy of the hierarchy at the ProjectionScreen node and below, with vertices flattened into two dimensions as if they were seen by the indicated camera node.

This is useful for rendering an image as seen through a non-linear lens. The resulting mesh will have vertices in the range [-1, 1] in both x and y, and may be then rendered with an ordinary orthographic lens, to generate the effect of seeing the image through the specified non-linear lens.

The returned node has no parent; it is up to the caller to parent it somewhere or store it so that it does not get dereferenced and deleted.

recompute()

Recomputes all the UV’s for geometry below the ProjectionScreen node, as if the texture were projected from the associated projector.

This function is normally called automatically whenever the relevant properties change, so it should not normally need to be called directly by the user. However, it does no harm to call this if there is any doubt.

recomputeIfStale() bool

Calls recompute() only if the relative transform between the ProjectionScreen and the projector has changed, or if any other relevant property has changed. Returns true if recomputed, false otherwise.

recomputeIfStale(this_np: panda3d.core.NodePath) bool

Calls recompute() only if the relative transform between the ProjectionScreen and the projector has changed, or if any other relevant property has changed. Returns true if recomputed, false otherwise.

regenerateScreen(projector: panda3d.core.NodePath, screen_name: str, num_x_verts: int, num_y_verts: int, distance: float, fill_ratio: float)

Removes all the children from the ProjectionScreen node, and adds the newly generated child returned by generateScreen().

setAutoRecompute(auto_recompute: bool)

Sets the auto_recompute flag. When this is true, the ProjectionScreen will always be recomputed if necessary before the frame is drawn; when it is false, an explicit call to recomputeIfStale() may be required.

setFrameColor(frame_color: panda3d.core.LColor)

Specifies the color the screen will be painted at the portions outside of the lens’ frustum; i.e. where the lens can’t see it or illuminate it. This color is only used if the vignette_on flag is true; see setVignetteOn().

setInvertUvs(invert_uvs: bool)

Some OpenGL graphics drivers are known to invert the framebuffer image when they copy it to texture. (This is arguably a problem with the OpenGL spec, which seems to be unclear about the proper ordering of pixels in this operation.)

In any case, set this true to compensate for this effect by inverting the UV’s of the projection screen. The default is taken from the Configrc variable project-invert-uvs.

setProjector(projector: panda3d.core.NodePath)

Specifies the LensNode that is to serve as the projector for this screen. The relative position of the LensNode to the ProjectionScreen, as well as the properties of the lens associated with the LensNode, determines the UV’s that will be assigned to the geometry within the ProjectionScreen.

The NodePath must refer to a LensNode (or a Camera).

setTexcoord3d(texcoord_3d: bool)

Set this true to force 3-D texture coordinates to be created for the geometry. When this is true and the geometry has only 2-D texture coordinates, those texture coordinates are dumped in favor of 3-D coordinates. When this is false, whatever texture coordinates already exist are preserved as-is.

setTexcoordName(texcoord_name: str)

Specifies the name of the texture coordinates that are generated by this particular ProjectionScreen. This can be used in the presence of multitexturing to compute the UV’s for just a subset of all of the active stages of the multitexture pipeline.

setUndistLut(undist_lut: panda3d.core.PfmFile)

Applies a distortion lookup table to the projector. This mapping warps the lens effect by passing each ray through an indirection table: the point (u,v) in the indicated lookup table stores the actual (u,v) that the lens produces.

This does not affect the operation of generateScreen().

setVignetteColor(vignette_color: panda3d.core.LColor)

Specifies the color the screen will be painted at the portions outside of the lens’ frustum; i.e. where the lens can’t see it or illuminate it. This color is only used if the vignette_on flag is true; see setVignetteOn().

setVignetteOn(vignette_on: bool)

Specifies whether vertex-based vignetting should be on. When this is enabled, vertex color will be set on the screen vertices to color the screen two distinct colors, usually white and black, for the parts of the screen in front of and outside the lens’ frustum, respectively. When this is not enabled, the screen color will be left alone.

This effect generally looks terrible, but it does at least make the boundaries of the lens clear.