#!/usr/bin/env python # Copyright (C) 2002-2003 Gideon May (gideon@computer.org) # # Permission to copy, use, sell and distribute this software is granted # provided this copyright notice appears in all copies. # Permission to modify the code and to distribute modified code is granted # provided this copyright notice appears in all copies, and a notice # that the code was modified is included with the copyright notice. # # This software is provided "as is" without express or implied warranty, # and with no claim as to its suitability for any purpose. # -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield # # This application is open source and may be redistributed and/or modified # freely and without restriction, both in commericial and non commericial applications, # as long as this copyright notice is maintained. # # This application is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # import sys from PyOSG import Producer from PyOSG import osg from PyOSG import osgGA from PyOSG import osgDB from PyOSG import osgUtil from PyOSG import osgProducer class UpdateCallback(osg.NodeCallback): def __init__(self): osg.NodeCallback.__init__(self) self._self = self def apply(self, node, nv): print "update callback - pre traverse", node self.traverse(node,nv) print "update callback - post traverse", node class CullCallback(osg.NodeCallback): def __init__(self): osg.NodeCallback.__init__(self) def apply(self, node, nv): print "cull callback - pre traverse", node self.traverse(node,nv) print "cull callback - post traverse", node class DrawableDrawCallback(osg.Drawable.DrawCallback): def __init__(self): osg.Drawable.DrawCallback.__init__(self) def drawImplementation(self, state, drawable): print "draw call back - pre drawImplementation", drawable drawable.drawImplementation(state) print "draw call back - post drawImplementation", drawable class DrawableUpdateCallback(osg.Drawable.UpdateCallback): def __init__(self): osg.Drawable.UpdateCallback.__init__(self) def update(self, nv, drawable): print "Drawable update callback ", drawable class DrawableCullCallback(osg.Drawable.CullCallback): def __init__(self): osg.Drawable.CullCallback.__init__(self) self._self = self # do customized cull code def cull(self, nv, drawable, state): print "Drawable cull callback " return False class InsertCallbacksVisitor(osg.NodeVisitor): def __init__(self): osg.NodeVisitor.__init__(self, osg.NodeVisitor.TRAVERSE_ALL_CHILDREN) def apply_node(self, node): node.setUpdateCallback(UpdateCallback()); node.setCullCallback(CullCallback()); self.traverse(node); def apply(self, node): geode = node.asGeode() transform = node.asTransform() if geode: geode.setUpdateCallback(UpdateCallback()) #note, it makes no sense to attach a cull callback to the node #at there are no nodes to traverse below the geode, only #drawables, and as such the Cull node callbacks is ignored. #If you wish to control the culling of drawables #then use a drawable cullback... for i in range(geode.getNumDrawables()): geode.getDrawable(i).setUpdateCallback(DrawableUpdateCallback()) geode.getDrawable(i).setCullCallback(DrawableCullCallback()) geode.getDrawable(i).setDrawCallback(DrawableDrawCallback()) elif transform: self.apply_node(node) else: self.apply_node(node) # XXX To implement #class MyReadFileCallback : public osgDB::Registry::ReadFileCallback #{ #public: # virtual osgDB::ReaderWriter::ReadResult readNode(const std::string& fileName, osgDB::ReaderWriter::Options* options) # { # std::cout<<"before readNode"<readNodeImplementation(fileName,options); # std::cout<<"after readNode"<