def loadImage(self, imagePath): """ Load the texture data from the image file at the specified path. Returns True if the texture was loaded successfully. """ try: image = osgDB.readImageFile(str(imagePath)) except: image = None return self.setImage(image)
def createMirrorTexturedState(filename): dstate = osg.StateSet(); dstate.setMode(osg.GL_CULL_FACE,osg.StateAttribute.OFF|osg.StateAttribute.PROTECTED); #// set up the texture. image = osgDB.readImageFile(filename); if (image): texture = osg.Texture2D(); texture.setImage(image); dstate.setTextureAttributeAndModes(0,texture,osg.StateAttribute.ON|osg.StateAttribute.PROTECTED); return dstate;
def loadImageCube(self, imagePaths): """ Load the texture data from the six image files at the specified paths. The imagePaths parameter should be a list of six paths to image files. The order of images is: +X, -X, +Y, -Y, +Z, -Z. Returns True if the texture was loaded successfully. """ images = [] for imagePath in imagePaths: try: images += [osgDB.readImageFile(str(imagePath))] except: pass return self.setImageCube(images)
def createObjectFromImageList(pNode, pImageList, pBaseUrl=""): """ uses the image list to create a set of objects """ box_geometry = osg.Box() box_drawable = osg.ShapeDrawable(box_geometry) # create a random function for floating points frandom = lambda x, y: random.randrange(x, y, int=types.FloatType) print "Opening %d from %d images" % (maxphotos, len(pImageList)) for imgfile in [str(x) for x in pImageList[:maxphotos]]: print "osgDB.readImageFile loading:", imgfile image = osgDB.readImageFile(imgfile) #check if the image is there, and not too small (icons and such) if image and image.s() > 100.0 and image.t() > 100.0: t = osg.TextureRectangle() texmat = osg.TexMat() texmat.setScaleByTextureRectangleSize(True) t.setImage(image) stateset = osg.StateSet() stateset.setTextureAttributeAndModes(0, t, 1) stateset.setTextureAttributeAndModes(0, texmat, osg.StateAttribute.ON) lbox_geode = osg.Geode() lbox_geode.addDrawable(box_drawable) lbox_geode.setStateSet(stateset) lbox_node = osg.PositionAttitudeTransform() lbox_node.addChild(lbox_geode) rscale = frandom(5, 10) lbox_node.setScale( osg.Vec3d(image.s() / rscale, 0.5, image.t() / rscale)) #set vertical q = osg.Quat() q.makeRotate(frandom(0, 2 * math.pi), 0, 0, 1) lbox_node.setAttitude(q) lbox_node.setPosition( osg.Vec3d(frandom(-50, 50), frandom(-50, 50), frandom(-100, 100))) pNode.addChild(lbox_node)
def write_top_group_texture(tex_file,root_file,outfile) : g = osg.Group() s = osg.StateSet() tex = osg.Texture2D() tex.setWrap(osg.Texture2D.WRAP_S,osg.Texture2D.CLAMP) tex.setWrap(osg.Texture2D.WRAP_T,osg.Texture2D.CLAMP) image = osgDB.readImageFile(tex_file) tex.setImage(image) s.setTextureAttributeAndModes(0,tex,osg.StateAttribute.ON) tenv = osg.TexEnv() s.setTextureAttribute(0,tenv) g.setStateSet(s) p = osg.ProxyNode() p.setFileName(0,root_file) print "scrivo -->",outfile g.addChild(p) for pointer in [g,s,tex,image,tenv,p]: pointer.thisown = False osgDB.writeNodeFile(g,outfile)
def osgViewerAndGeometry(self, testStateSet): print "-"*40 print "Testing osgViewer with osg::Geometry" g = osg.createTexturedQuadGeometry(osg.Vec3f(0,0,0), osg.Vec3f(1,0,0), osg.Vec3f(0,0,1), 0, 0, 1, 1) g.getColorArray()[0] = osg.Vec4f(1,1,1,0.5) geode = osg.Geode() geode.addDrawable(g) if (testStateSet): print "Will add a texture" i = osgDB.readImageFile("Images/osg256.png") t = osg.Texture2D(i) s = geode.stateSet s.setTextureAttributeAndModes(0, t, osg.StateAttribute.ON) s.setRenderingHint(osg.StateSet.TRANSPARENT_BIN) s.setMode(osg.GL_BLEND, osg.StateAttribute.ON) runViewer(geode) self.failUnless(True)
def createObjectFromImageList(pNode, pImageList, pBaseUrl=""): """ uses the image list to create a set of objects """ box_geometry = osg.Box() box_drawable = osg.ShapeDrawable(box_geometry) # create a random function for floating points frandom = lambda x,y : random.randrange(x,y,int=types.FloatType) print "Opening %d from %d images"%(maxphotos, len(pImageList)) for imgfile in [str(x) for x in pImageList[:maxphotos]]: print "osgDB.readImageFile loading:", imgfile image = osgDB.readImageFile(imgfile) #check if the image is there, and not too small (icons and such) if image and image.s()>100.0 and image.t()>100.0: t = osg.TextureRectangle() texmat = osg.TexMat() texmat.setScaleByTextureRectangleSize(True) t.setImage(image) stateset = osg.StateSet() stateset.setTextureAttributeAndModes(0,t,1) stateset.setTextureAttributeAndModes(0, texmat, osg.StateAttribute.ON) lbox_geode = osg.Geode() lbox_geode.addDrawable(box_drawable) lbox_geode.setStateSet(stateset) lbox_node = osg.PositionAttitudeTransform() lbox_node.addChild(lbox_geode) rscale = frandom(5,10) lbox_node.setScale(osg.Vec3d(image.s()/rscale,0.5,image.t()/rscale)) #set vertical q = osg.Quat() q.makeRotate(frandom(0,2*math.pi),0,0,1) lbox_node.setAttitude(q) lbox_node.setPosition (osg.Vec3d (frandom(-50,50), frandom(-50,50), frandom(-100,100))) pNode.addChild(lbox_node)
import ctypes import osgDB, osgViewer, osg group = osg.Group() image = osgDB.readImageFile("/home/trigrou/Pictures/backgrounds/games/Another_World_by_Orioto.jpg") loadedModel = osg.Group() corner = osg.Vec3(0,0,0); width = osg.Vec3(1,0,0); height = osg.Vec3(0,1,0); geom = osg.createTexturedQuadGeometry(corner, width, height, 0.0, 0.0, 1.0, 1.0); geom.getOrCreateStateSet().setTextureAttributeAndModes(0, osg.Texture2D(image)) geom.getOrCreateStateSet().setTextureAttributeAndModes(1, osg.Texture2D(osgDB.readImageFile("/home/trigrou/Pictures/backgrounds/games/Big_Blue_by_Orioto.jpg"))) vertProg = """ void main() { gl_Position = ftransform(); gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; } """ fragProg = """ uniform float test; uniform int index; uniform sampler2D tex0; uniform sampler2D tex1; void main() { vec4 color; if (index == 0.0) color = texture2D(tex0,gl_TexCoord[0].st); if (index != 0.0)
import ctypes import osgDB, osgViewer, osg group = osg.Group() image = osgDB.readImageFile( "/home/trigrou/Pictures/backgrounds/games/Another_World_by_Orioto.jpg") loadedModel = osg.Group() corner = osg.Vec3(0, 0, 0) width = osg.Vec3(1, 0, 0) height = osg.Vec3(0, 1, 0) geom = osg.createTexturedQuadGeometry(corner, width, height, 0.0, 0.0, 1.0, 1.0) geom.getOrCreateStateSet().setTextureAttributeAndModes(0, osg.Texture2D(image)) geom.getOrCreateStateSet().setTextureAttributeAndModes( 1, osg.Texture2D( osgDB.readImageFile( "/home/trigrou/Pictures/backgrounds/games/Big_Blue_by_Orioto.jpg")) ) vertProg = """ void main() { gl_Position = ftransform(); gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; } """ fragProg = """ uniform float test; uniform int index; uniform sampler2D tex0;