class SlideEventHandler (osgGA.GUIEventHandler) : SlideEventHandler() META_Object(osgStereImageApp,SlideEventHandler) set = void(osg.Switch* sw, float offsetX, float offsetY, osg.TexMat* texmatLeft, osg.TexMat* texmatRight, float timePerSlide, bool autoSteppingActive) set = void(FileList fileList, osg.Switch* sw, float offsetX, float offsetY, osg.TexMat* texmatLeft, osg.TexMat* texmatRight, float radius, float height, float length, float timePerSlide, bool autoSteppingActive) handle = virtual bool( osgGA.GUIEventAdapter ea,osgGA.GUIActionAdapter) virtual void getUsage(osg.ApplicationUsage usage) virtual void operator()(osg.Node* node, osg.NodeVisitor* nv) nextSlide = void() previousSlide = void() scaleImage = void(float s) offsetImage = void(float ds,float dt) rotateImage = void(float rx,float ry) initTexMatrices = void() ~SlideEventHandler() SlideEventHandler( SlideEventHandler, osg.CopyOp) _switch = osg.Switch() _texmatLeft = osg.TexMat() _texmatRight = osg.TexMat() _radius = float() _height = float() _length = float() _firstTraversal = bool() _activeSlide = unsigned int() _previousTime = double() _timePerSlide = double() _autoSteppingActive = bool() _initSeperationX = float() _currentSeperationX = float() _initSeperationY = float() _currentSeperationY = float() _fileList = FileList()
def createSkyBox(): stateset = osg.StateSet() te = osg.TexEnv() te.setMode(osg.TexEnv.REPLACE) stateset.setTextureAttributeAndModes(0, te, osg.StateAttribute.ON) tg = osg.TexGen() tg.setMode(osg.TexGen.NORMAL_MAP) stateset.setTextureAttributeAndModes(0, tg, osg.StateAttribute.ON) tm = osg.TexMat() stateset.setTextureAttribute(0, tm) skymap = readCubeMap() stateset.setTextureAttributeAndModes(0, skymap, osg.StateAttribute.ON) stateset.setMode( GL_LIGHTING, osg.StateAttribute.OFF ) stateset.setMode( GL_CULL_FACE, osg.StateAttribute.OFF ) # clear the depth to the far plane. depth = osg.Depth() depth.setFunction(osg.Depth.ALWAYS) depth.setRange(1.0,1.0) stateset.setAttributeAndModes(depth, osg.StateAttribute.ON ) stateset.setRenderBinDetails(-1,"RenderBin") drawable = osg.ShapeDrawable(osg.Sphere(osg.Vec3(0.0,0.0,0.0),1)) geode = osg.Geode() geode.setCullingActive(False) geode.setStateSet( stateset ) geode.addDrawable(drawable) transform = MoveEarthySkyWithEyePointTransform() transform.setCullingActive(False) transform.addChild(geode) clearNode = osg.ClearNode() # clearNode.setRequiresClear(False) clearNode.setCullCallback(TexMatCallback(*tm)) clearNode.addChild(transform) return clearNode
# scale the texture coordinates to the viewport #ifdef USE_TEXTURE_RECTANGLE m.postMultScale(osg.Vec3d(viewport.width(), viewport.height(), 1)) #else: #ifndef USE_NON_POWER_OF_TWO_TEXTURE m.postMultScale(osg.Vec3d(viewport.width()/double(_texWidth), viewport.height()/double(_texHeight), 1)) #endif #endif if _texUnit not = 0 and _offsetValue : # Kind of polygon offset: note this way, we can also offset lines and points. # Whereas with the polygon offset we could only handle surface primitives. m.postMultTranslate(osg.Vec3d(0, 0, -ldexp(double(_offsetValue), -24))) texMat = osg.TexMat(m) stateSet = osg.StateSet() stateSet.setTextureAttribute(_texUnit, texMat) if _texUnit not = 0 : # # GLSL pipeline support # #ifdef USE_TEXTURE_RECTANGLE # osg.Uniform.SAMPLER_2D_RECT_SHADOW not yet available in OSG 3.0.1 # osg.Uniform* depthUniform = osg.Uniform(osg.Uniform.SAMPLER_2D_RECT_SHADOW, "depthtex") # depthUniform.set((int)_texUnit) depthUniform = osg.Uniform("depthtex", (int)_texUnit) invWidthUniform = osg.Uniform("invWidth", (float)1.0) invHeightUniform = osg.Uniform("invHeight", (float)1.0)
def addRefractStateSet(node): stateset = osg.StateSet() reflectmap = readCubeMap() stateset.setTextureAttributeAndModes( 0, reflectmap, osg.StateAttribute.ON | osg.StateAttribute.OVERRIDE ) stateset.setTextureAttributeAndModes( 1, reflectmap, osg.StateAttribute.ON | osg.StateAttribute.OVERRIDE ) texMat = osg.TexMat() stateset.setTextureAttribute(0, texMat) # --------------------------------------------------- # Vertex Program # --------------------------------------------------- vp = osg.VertexProgram() vp.setVertexProgram( vpstr ) vp.setProgramLocalParameter( 0, osg.Vec4( fresnel, fresnel, fresnel, 1.0 ) ) vp.setProgramLocalParameter( 1, osg.Vec4( refract, refract*refract, 0.0, 0.0 ) ) stateset.setAttributeAndModes( vp, osg.StateAttribute.ON | osg.StateAttribute.OVERRIDE ) # --------------------------------------------------- # fragment = refraction*(1-fresnel) + reflection*fresnel # T0 = texture unit 0, refraction map # T1 = texture unit 1, reflection map # C.rgb = primary color, water color # C.a = primary color, fresnel factor # Cp = result from previous texture environment # --------------------------------------------------- # REPLACE function: Arg0 # = T0 te0 = osg.TexEnvCombine() te0.setCombine_RGB(osg.TexEnvCombine.REPLACE) te0.setSource0_RGB(osg.TexEnvCombine.TEXTURE0) te0.setOperand0_RGB(osg.TexEnvCombine.SRC_COLOR) # INTERPOLATE function: Arg0 * (Arg2) + Arg1 * (1-Arg2) # = T1 * C0.a + Cp * (1-C0.a) te1 = osg.TexEnvCombine() # rgb = Cp + Ct te1.setCombine_RGB(osg.TexEnvCombine.INTERPOLATE) te1.setSource0_RGB(osg.TexEnvCombine.TEXTURE1) te1.setOperand0_RGB(osg.TexEnvCombine.SRC_COLOR) te1.setSource1_RGB(osg.TexEnvCombine.PREVIOUS) te1.setOperand1_RGB(osg.TexEnvCombine.SRC_COLOR) te1.setSource2_RGB(osg.TexEnvCombine.PRIMARY_COLOR) te1.setOperand2_RGB(osg.TexEnvCombine.SRC_COLOR) stateset.setTextureAttributeAndModes(0, te0, osg.StateAttribute.ON | osg.StateAttribute.OVERRIDE) stateset.setTextureAttributeAndModes(1, te1, osg.StateAttribute.ON | osg.StateAttribute.OVERRIDE) group = osg.Group() group.addChild(node) group.setCullCallback(TexMatCallback(*texMat)) group.setStateSet( stateset ) return group
virtual void operator()(osg.Node* node, osg.NodeVisitor* nv) cv = dynamic_cast<osgUtil.CullVisitor*>(nv) if cv : MV = *(cv.getModelViewMatrix()) R = osg.Matrix.rotate( osg.DegreesToRadians(112.0), 0.0,0.0,1.0)* osg.Matrix.rotate( osg.DegreesToRadians(90.0), 1.0,0.0,0.0) q = MV.getRotate() C = osg.Matrix.rotate( q.inverse() ) _texMat.setMatrix( C*R ) traverse(node,nv) _texMat = osg.TexMat() class MoveEarthySkyWithEyePointTransform (osg.Transform) : #* Get the transformation matrix which moves from local coords to world coords. def computeLocalToWorldMatrix(matrix, nv): cv = dynamic_cast<osgUtil.CullVisitor*>(nv) if cv : eyePointLocal = cv.getEyeLocal() matrix.preMultTranslate(eyePointLocal) return True #* Get the transformation matrix which moves from world coords to local coords. def computeWorldToLocalMatrix(matrix, nv):
texgenNode.getTexGen().setMode(osg.TexGen.REFLECTION_MAP) texgenNode.setTextureUnit(unit) group.addChild(texgenNode) # set the reflected subgraph so that it uses the texture and tex gen settings. reflectorNode = reflectorNodePath.front() group.addChild(reflectorNode) stateset = reflectorNode.getOrCreateStateSet() stateset.setTextureAttributeAndModes(unit,texture,osg.StateAttribute.ON) stateset.setTextureMode(unit,GL_TEXTURE_GEN_S,osg.StateAttribute.ON) stateset.setTextureMode(unit,GL_TEXTURE_GEN_T,osg.StateAttribute.ON) stateset.setTextureMode(unit,GL_TEXTURE_GEN_R,osg.StateAttribute.ON) stateset.setTextureMode(unit,GL_TEXTURE_GEN_Q,osg.StateAttribute.ON) texmat = osg.TexMat() stateset.setTextureAttributeAndModes(unit,texmat,osg.StateAttribute.ON) reflectorNode.setCullCallback(TexMatCullCallback(texmat)) # add the reflector scene to draw just as normal group.addChild(reflectedSubgraph) # set an update callback to keep moving the camera and tex gen in the right direction. group.setUpdateCallback(UpdateCameraAndTexGenCallback(reflectorNodePath, Cameras)) return group def main(argv):
fileList.push_back("Images/dog_right_eye.jpg") elif fileList.size()<2 : arguments.getApplicationUsage().write(std.cout,osg.ApplicationUsage.COMMAND_LINE_OPTION) return 1 # now the windows have been realized we switch off the cursor to prevent it # distracting the people seeing the stereo images. double fovy, aspectRatio, zNear, zFar viewer.getCamera().getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar) radius = 1.0 height = 2*radius*tan(osg.DegreesToRadians(fovy)*0.5) length = osg.PI*radius # half a cylinder. # use a texture matrix to control the placement of the image. texmatLeft = osg.TexMat() texmatRight = osg.TexMat() # creat the scene from the file list. rootNode = osg.Switch() if not onDisk : rootNode = createScene(fileList,texmatLeft,texmatRight,radius,height,length) rootNode = osg.Switch() #osgDB.writeNodeFile(*rootNode,"test.osgt") viewer.getCamera().setCullMask(0xffffffff) viewer.getCamera().setCullMaskLeft(0x00000001) viewer.getCamera().setCullMaskRight(0x00000002)
def createRectangle(bb, filename): top_left = osg.Vec3(bb.xMin(),bb.yMax(),bb.zMax()) bottom_left = osg.Vec3(bb.xMin(),bb.yMax(),bb.zMin()) bottom_right = osg.Vec3(bb.xMax(),bb.yMax(),bb.zMin()) top_right = osg.Vec3(bb.xMax(),bb.yMax(),bb.zMax()) # create geometry geom = osg.Geometry() vertices = osg.Vec3Array(4) (*vertices)[0] = top_left (*vertices)[1] = bottom_left (*vertices)[2] = bottom_right (*vertices)[3] = top_right geom.setVertexArray(vertices) texcoords = osg.Vec2Array(4) (*texcoords)[0].set(0.0, 0.0) (*texcoords)[1].set(1.0, 0.0) (*texcoords)[2].set(1.0, 1.0) (*texcoords)[3].set(0.0, 1.0) geom.setTexCoordArray(0,texcoords) normals = osg.Vec3Array(1) (*normals)[0].set(0.0,-1.0,0.0) geom.setNormalArray(normals, osg.Array.BIND_OVERALL) colors = osg.Vec4Array(1) (*colors)[0].set(1.0,1.0,1.0,1.0) geom.setColorArray(colors, osg.Array.BIND_OVERALL) geom.addPrimitiveSet(osg.DrawArrays(GL_QUADS, 0, 4)) # disable display list so our modified tex coordinates show up geom.setUseDisplayList(False) # load image img = osgDB.readImageFile(filename) # setup texture texture = osg.TextureRectangle(img) texmat = osg.TexMat() texmat.setScaleByTextureRectangleSize(True) # setup state state = geom.getOrCreateStateSet() state.setTextureAttributeAndModes(0, texture, osg.StateAttribute.ON) state.setTextureAttributeAndModes(0, texmat, osg.StateAttribute.ON) # turn off lighting state.setMode(GL_LIGHTING, osg.StateAttribute.OFF) # install 'update' callback geode = osg.Geode() geode.addDrawable(geom) geode.setUpdateCallback(TexturePanCallback(texmat)) return geode