OpenGLContext.bin.vrml_view_shadow
index
/home/mcfletch/pylive/OpenGLContext/bin/vrml_view_shadow.py

Shadow-casting version of the VRML-viewing demonstration
 
This version of the VRML-viewing demonstration functions as
a demonstration of the shadow-casting package.

 
Modules
       
OpenGLContext.shadow.shadowcontext
OpenGLContext.bin.vrml_view

 
Classes
       
TestContext(VRMLContext, PygameInteractiveContext)
TestContext(ShadowContext, TestContext)
ShadowContext
TestContext(ShadowContext, TestContext)

 
class TestContext(ShadowContext, TestContext)
    Shadow-enabled testing context
 
 
Method resolution order:
TestContext
ShadowContext
TestContext
VRMLContext
PygameInteractiveContext
ViewPlatformMixin
InteractiveContext
PygameContext
EventHandlerMixin
EventHandlerMixin
Context
object

Methods inherited from ShadowContext:
getViewPlatform(self)
Get the view platform to use for this context
 
Returns an InfViewPlatform, which provides the required
pinfPerspective-based model-view matrix.

Data and other attributes inherited from ShadowContext:
renderPasses = <OpenGLContext.shadow.passes.ShadowPassSet object at 0x5dcf750>
Callable list of sub-passes

Methods inherited from TestContext:
OnInit(self)
Load the image on initial load of the application

Methods inherited from VRMLContext:
load(self, filename)
Load given url, replacing current scenegraph
setupFontProviders(self)
Load font providers for the context
 
See the OpenGLContext.scenegraph.text package for the
available font providers.

Data descriptors inherited from VRMLContext:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from VRMLContext:
USE_FRUSTUM_CULLING = 1
USE_OCCLUSION_CULLING = 0
initialPosition = (0, 0, 10)
sg = None

Methods inherited from PygameInteractiveContext:
OnIdle(self)
PygameActivateEvent(self, event)
PygameVideoResize(self, event)

Methods inherited from ViewPlatformMixin:
ViewPort(self, width, height)
Set the size of the OpenGL rendering viewport for the context
 
Because the ViewPlatform provide support for
"constant aspect ratio" in scenes, it is necessary
to keep the ViewPlatform updated regarding the current
aspect ratio of the ViewPort.  This implementation
merely calls the platform's setViewport, then
calls the super-class ViewPort method.
 
XXX
    Unfortunately, because Context objects may be
    old-style classes, we can't use super(), so
    this implementation actually calls
    context.Context.ViewPort directly.
Viewpoint(self, mode=None)
Customization point: Sets up the projection matrix
 
This implementation potentially instantiates the
view platform object, and then calls the object's
render method with the mode as argument.
setMovementManager(self, manager)
Set our current movement manager
setupDefaultEventCallbacks(self)
Customization point: Setup application default callbacks
 
This method binds a large number of callbacks which support
the OpenGLContext default camera-manipulation modes.  In
particular:
    * unmodified arrow keys for x,z (in camera coordinate
        space) movement
    * Alt+arrow keys for x,y (in camera coordinate space)
        movement
    * Ctrl+up/down arrow keys for rotating the head backward/
        forward
    * Mouse-button-2 (right) for entering "examine" mode
    * '-' for straightening the view platform

Data and other attributes inherited from ViewPlatformMixin:
initialOrientation = (0, 1, 0, 0)
movementManager = None
platform = None
slider = None

Data and other attributes inherited from InteractiveContext:
EventManagerClasses = [('keyboard', <class 'OpenGLContext.events.keyboardevents.KeyboardEventManager'>), ('keypress', <class 'OpenGLContext.events.keyboardevents.KeypressEventManager'>), ('mousebutton', <class 'OpenGLContext.events.mouseevents.MouseButtonEventManager'>), ('mousemove', <class 'OpenGLContext.events.mouseevents.MouseMoveEventManager'>), ('mousein', <class 'OpenGLContext.events.mouseevents.MouseInEventManager'>), ('mouseout', <class 'OpenGLContext.events.mouseevents.MouseOutEventManager'>)]
TimeManagerClass = <class 'OpenGLContext.events.timeeventgeneratormanager.TimeEventGeneratorManager'>
TimeEventGenerator EventManager object
 
This object conforms to the EventManager interface,
although it doesn't actually inherit from that class.
 
It provides support for the InternalTime generators
on which the Timer object is based.

Methods inherited from PygameContext:
CallVirtual(self, name, *args, **namedarguments)
Call a potentially undefined method
MainLoop(self)
Run indefinitely until program is quit
PygameQuit(self, event)
Return a value indicating that the MainLoop should exit
SwapBuffers(self)
flip opengl doublebuffers
__init__(self, definition=None, **named)
pygameDisplayMode(self, definition=None)

Class methods inherited from PygameContext:
ContextMainLoop(cls, *args, **named) from type
Initialise the context and start the mainloop
pygameFlagsFromDefinition(cls, definition) from type
Setup the various non-initialising flags, return init flags

Methods inherited from EventHandlerMixin:
PygameKeyDown(self, event)
Convert a key-press to a context-style event
PygameKeyUp(self, event)
Convert a key-release to a context-style event
PygameMouseButtonDown(self, event)
Convert a mouse-button-press to a context-style event
PygameMouseButtonUp(self, event)
Convert a mouse-button-release to a context-style event
PygameMouseMotion(self, event)
Convert a mouse-button-move to a context-style event

Methods inherited from EventHandlerMixin:
DoEventCascade(self)
Do pre-rendering event cascade
 
Returns the total number of events generated by
timesensors and/or processed from the event cascade queue
ProcessEvent(self, event)
Primary dispatch point for events.
 
ProcessEvent uses the event's type attribute to determine the
appropriate manager for processing, then dispatches to that manager's
ProcessEvent method.
addEventHandler(self, eventType, *arguments, **namedarguments)
Add a new event handler function for the given event type
 
This is the primary client API for dealing with the event system.
Each event class will define a particular set of data values
required to form the routing key for the event.  Each event handler
class will define a registerCallback function which converts
its arguments into a matching key.
 
This function merely determines the appropriate handler then
dispatches to the handler's registerCallback method (without the
eventType argument).
 
See: mouseevents, keyboardevents
addEventManager(self, eventType, manager=None)
Add an event manager to the internal table of managers.
 
The return value is the previous manager or None if there was
no previous manager.
captureEvents(self, eventType, manager=None)
Temporarily capture events of a particular type.
 
This temporarily replaces a particular manager within the
dispatch set with provided manager.  This will normally be
used to create "modal" interfaces such as active drag
functions (where the interface is in a different "interaction
mode", so that actions have different meaning than in the
"default mode").
 
Passing None as the manager will restore the previous manager
to functioning.
 
Note: this function does not perform a "system capture"
of input (that is, mouse movements are only available if they
occur over the context's window and that window has focus).
 
Note: for capturing mouse input, you will likely want to
capture both movement and button events, it should be possible
to define a single handler to deal with both event types,
and pass that handler twice, once for each event type.
getEventManager(self, eventType)
Retrieve an event manager from the internal table of managers
 
Returns the appropriate manager, or None if there was no
manager registered for the given event type.
getTimeManager(self)
Get the time-event manager for this context
initializeEventManagers(self)
Initialize the event manager classes for this context.
 
This implementation iterates over self.EventManagerClasses
(a list of (eventType, managerClass) values) and calls
addEventManager for each item.

Methods inherited from Context:
Background(self, mode=None)
Customization point for clearing/drawing the background.
 
The default implementation clears the color and depth
buffers, using solid white for the clear color.
 
Note: This method is only called if there is no scene graph,
and if there is no SetupBindables( mode ) method
available on the Context.
DoInit(self)
Call the OnInit method at a time when the context is valid
 
This method provides a customization point where
contexts which do not completely initialize during
their __init__ method can arrange to have the OnInit
method processed after their initialization has
completed.  The default implementation here simply
calls OnInit directly w/ appropriate setCurrent
and unsetCurrent calls and calls the glutInit()
function with an empty argument-list.
Lights(self, mode=None)
Customization point for setting up global illumination parameters
Depending on the mode, should either enable or disable
lighting for all of those lights in the scene.
 
The default implementation enables lighting and light 0
if render mode is not select, disables them otherwise.
 
Note: This method is only called if there is no scene graph,
and if there is no SetupBindables( mode ) method
available on the Context.
OnDraw(self, force=1, *arguments)
Callback for the rendering/drawing mechanism
 
force -- if true, force a redraw.  If false, then only
    do a redraw if the event cascade has generated events.
 
return value is whether a visible change occured
 
This implementation does the following:
 
    * calls lockScenegraph()
        o calls DoEventCascade()
    * calls unlockScenegraph()
    * calls setCurrent()
    * calls renderPasses( self )
        See: passes sub-package
        See: visitor.py, rendervisitor.py, renderpass.py,
        shadow/passes.py for examples of render-pass-sets
        which can be triggered.
        See: flat.py for standard second-generation renderer
 
        The RenderPasses define the core of the rendering
        mechanism.  The default rendering passes will defer
        most rendering options to the scenegraph returned by
        getSceneGraph().  If that value is None (default)
        then the pass will use the Context's callbacks.
 
        You can define new RenderPasses to replace the
        rendering algorithm, override the Context's various
        callbacks to write raw OpenGL code, or work by
        customizing the scene graph library.
    * if there was a visible change (which is the return value
        from the render-pass-set), calls SwapBuffers()
    * calls unsetCurrent()
OnFrameRate(self, event=None)
Print the current frame-rate values
OnNextViewpoint(self, event=None)
Go to the next viewpoint for the scenegraph
OnQuit(self, event=None)
Quit the application (forcibly)
OnResize(self, *arguments)
Resize the window when the windowing library says to
OnSaveImage(self, event=None, template='%(script)s-screen-%(count)04i.png', script=None, date=None, overwrite=False)
Save our current screen to disk (if possible)
Render(self, mode=None)
Customization point for geometry rendering
 
This method is called by the default render passes to
render the geometry for the system.  Wherever possible,
you should pay attention to the rendering modes to allow
for optimization of your geometry (for instance,
selection passes do not require lighting).
 
The default implementation merely ensures that matrix mode
is currently model view.
 
See: visitor.py, rendervisitor.py, renderpass.py,
shadow/passes.py for definitions of the properties of the
mode.
addPickEvent(self, event)
Add event to list of events to be processed by selection-render-mode
 
This is a method of the Context, rather than the
rendering pass (which might seem more elegant given
that it is the rendering pass which deals with the
events being registered) because the requests to
render a pick event occur outside of the rendering
loop.  As a result, there is (almost) never an
active context when the pick-event-request comes in.
drawPoll(self, timeout=None)
Wait timeout seconds for a redraw request
 
timeout -- timeout in seconds, if None, use
    self.drawPollTimeout
 
returns 0 if timeout, 1 if true
getPickEvents(self)
Get the currently active pick-events
getSceneGraph(self)
Get the scene graph for the context (or None)
 
You must return an instance of:
 
    OpenGLContext.scenegraph.scenegraph.SceneGraph
 
Normally you would create that using either a loader
from OpenGLContext.loader:
 
    from OpenGLContext.loader import vrml97
    def OnInit( self ):
        self.sg = vrml97.load( 'c:\somefile\world.wrl' )
 
or by using the classes in OpenGLContext.scenegraph.basenodes:
 
    from OpenGLContext.scenegraph import basenodes
    def OnInit( self ):
        self.sg = basenodes.sceneGraph(
            children = [
                basenodes.Transform(...)
            ],
        )
 
to define the scenegraph in Python code.
getTTFFiles(self)
Get TrueType font-file registry object
getViewPort(self)
Method to retrieve the current dimensions of the context
 
Return value is a width, height tuple. See Context.ViewPort
for setting of this value.
lockScenegraph(self, blocking=1)
Lock scenegraph locks to prevent other update/rendering actions
 
Potentially this could be called from a thread other than the
GUI thread, allowing the other thread to update structures in
the scenegraph without mucking up any active rendering pass.
renderedChildren(self, types=None)
Get the rendered children of the scenegraph
setCurrent(self, blocking=1)
Set the OpenGL focus to this context
setupCache(self)
Setup caching strutures for content
 
This includes the general compiled-geometry caches
and the texture cache
setupCallbacks(self)
Establishes GUI callbacks for asynchronous event GUI systems
 
Subclasses and applications will register events
here for those event types in which they are interested.
Most minor applications should use interactivecontext's
abstract callbacks (which translate the GUI library's
native events into a common event framework for all
interactivecontexts).
 
The default implementation does nothing.
setupExtensionManager(self)
Create an extension manager for this context
setupFrameRateCounter(self)
Setup structures for managing frame-rate
 
This sets self.frameCounter to an instance of
framecounter.FrameCounter, which is a simple node
used to track frame-rate metadata during rendering.
 
Updates to the framecounter are performed by OnDraw
iff there is a visible change processed.
 
Note:
    If you override this method, you need to either use
    an object which has the same API as a FrameCounter or
    use None, anything else will cause failures in the
    core rendering loop!
setupRedrawRequest(self)
Setup the redraw-request (threading) event
setupScenegraphLock(self)
Setup lock to protect scenegraph from updates during rendering
setupThreading(self)
Setup primitives (locks, events) for threading
shouldRedraw(self)
Return whether or not the context contents need to be redrawn
suppressRedraw(self)
Indicate to the context that there is no need to re-render
 
This method signals to the context that there are no updates
currently requiring redrawing of the context's contents.
 
See:
    Context.shouldRedraw and Context.triggerRedraw
triggerPick(self)
Trigger a selection rendering pass
 
If the context is not currently drawing, the selection render will
occur immediately, otherwise it will occur the next time the
rendering loop reaches the selection stage.
triggerRedraw(self, force=0)
Indicate to the context that it should redraw when possible
 
If force is true, the rendering will begin immediately if the
context is not already drawing.  Otherwise only the indicator flag
will be set.
unlockScenegraph(self)
Unlock scenegraph locks to allow other update/rendering actions
 
Potentially this could be called from a thread other than the
GUI thread, allowing the other thread to update structures in
the scenegraph without mucking up any active rendering pass.
unsetCurrent(self)
Give up the OpenGL focus from this context

Class methods inherited from Context:
getApplicationName(cls) from type
Retrieve the application name for configuration purposes
getContextType(cls, entrypoint=None, type=<class 'OpenGLContext.plugins.InteractiveContext'>) from type
Load a single context type via entry-point resolution
 
returns a Context sub-class *or* None if there is no such
context defined/available, will have a ContextMainLoop method 
for running the Context top-level loop.
getContextTypes(cls, type=<class 'OpenGLContext.plugins.InteractiveContext'>) from type
Retrieve the set of defined context types
 
type -- testing type key from setup.py for the registered modules
 
returns list of setuptools entry-point objects which can be passed to 
getContextType( name ) to retrieve the actual context type.
getDefaultContextType(cls) from type
Get the current user's preference for a default context type
getDefaultTTFFont(cls, type='sans') from type
Get the current user's preference for a default font
getUserAppDataDirectory(cls) from type
Retrieve user-specific configuration directory
 
Default implementation gives a directory-name in the
user's (system-specific) "application data" directory
named
setDefaultContextType(cls, name) from type
Set the current user's preference for a default font
setDefaultTTFFont(cls, name, type='sans') from type
Set the current user's preference for a default font

Static methods inherited from Context:
fromConfig(cfg)
Given a ConfigParser instance, produce a configured sub-class

Data and other attributes inherited from Context:
APPLICATION_NAME = 'OpenGLContext'
DEF = '#Context'
PROTO = 'Context'
allContexts = []
alreadyDrawn = None
contextDefinition = None
currentContext = None
drawPollTimeout = 0.01
drawing = None
frameCounter = None
ttfFileRegistry = None
viewportDimensions = (0, 0)

 
Data
        __file__ = '/home/mcfletch/pylive/OpenGLContext/bin/vrml_view_shadow.pyc'
__name__ = 'OpenGLContext.bin.vrml_view_shadow'
__package__ = 'OpenGLContext.bin'