Exemple #1
0
def createLights(bb, rootStateSet):


    
    lightGroup = osg.Group()

    modelSize = bb.radius()

    # create a spot light.
    myLight1 = osg.Light()
    myLight1.setLightNum(0)
    myLight1.setPosition(osg.Vec4(bb.corner(4),1.0))
    myLight1.setAmbient(osg.Vec4(1.0,0.0,0.0,1.0))
    myLight1.setDiffuse(osg.Vec4(1.0,0.0,0.0,1.0))
    myLight1.setSpotCutoff(20.0)
    myLight1.setSpotExponent(50.0)
    myLight1.setDirection(osg.Vec3(1.0,1.0,-1.0))

    lightS1 = osg.LightSource()
    lightS1.setLight(myLight1)
    lightS1.setLocalStateSetModes(osg.StateAttribute.ON)

    lightS1.setStateSetModes(*rootStateSet,osg.StateAttribute.ON)
    lightGroup.addChild(lightS1)


    # create a local light.
    myLight2 = osg.Light()
    myLight2.setLightNum(1)
    myLight2.setPosition(osg.Vec4(0.0,0.0,0.0,1.0))
    myLight2.setAmbient(osg.Vec4(0.0,1.0,1.0,1.0))
    myLight2.setDiffuse(osg.Vec4(0.0,1.0,1.0,1.0))
    myLight2.setConstantAttenuation(1.0)
    myLight2.setLinearAttenuation(2.0/modelSize)
    myLight2.setQuadraticAttenuation(2.0/osg.square(modelSize))

    lightS2 = osg.LightSource()
    lightS2.setLight(myLight2)
    lightS2.setLocalStateSetModes(osg.StateAttribute.ON)

    lightS2.setStateSetModes(*rootStateSet,osg.StateAttribute.ON)

    mt = osg.MatrixTransform()
        # set up the animation path
        animationPath = osg.AnimationPath()
        animationPath.insert(0.0,osg.AnimationPath.ControlPoint(bb.corner(0)))
        animationPath.insert(1.0,osg.AnimationPath.ControlPoint(bb.corner(1)))
        animationPath.insert(2.0,osg.AnimationPath.ControlPoint(bb.corner(2)))
        animationPath.insert(3.0,osg.AnimationPath.ControlPoint(bb.corner(3)))
        animationPath.insert(4.0,osg.AnimationPath.ControlPoint(bb.corner(4)))
        animationPath.insert(5.0,osg.AnimationPath.ControlPoint(bb.corner(5)))
        animationPath.insert(6.0,osg.AnimationPath.ControlPoint(bb.corner(6)))
        animationPath.insert(7.0,osg.AnimationPath.ControlPoint(bb.corner(7)))
        animationPath.insert(8.0,osg.AnimationPath.ControlPoint(bb.corner(0)))
        animationPath.setLoopMode(osg.AnimationPath.SWING)

        mt.setUpdateCallback(osg.AnimationPathCallback(animationPath))
def createSpotLightNode(position, direction, angle, lightNum, textureUnit):


    
    group = osg.Group()
    
    # create light source.
    lightsource = osg.LightSource()
    light = lightsource.getLight()
    light.setLightNum(lightNum)
    light.setPosition(osg.Vec4(position,1.0))
    light.setAmbient(osg.Vec4(0.00,0.00,0.05,1.0))
    light.setDiffuse(osg.Vec4(1.0,1.0,1.0,1.0))
    group.addChild(lightsource)
    
    # create tex gen.
    
    up = osg.Vec3(0.0,0.0,1.0)
    up = (direction ^ up) ^ direction
    up.normalize()
    
    texgenNode = osg.TexGenNode()
    texgenNode.setTextureUnit(textureUnit)
    texgen = texgenNode.getTexGen()
    texgen.setMode(osg.TexGen.EYE_LINEAR)
    texgen.setPlanesFromMatrix(osg.Matrixd.lookAt(position, position+direction, up)*
                                osg.Matrixd.perspective(angle,1.0,0.1,100)*
                                osg.Matrixd.translate(1.0,1.0,1.0)*
                                osg.Matrixd.scale(0.5,0.5,0.5))

    
    group.addChild(texgenNode)
    
    return group
Exemple #3
0
            texenv.setSource2_RGB(osg.TexEnvCombine.PRIMARY_COLOR)
            texenv.setOperand2_RGB(osg.TexEnvCombine.SRC_COLOR)

            stateset.setTextureAttribute( 1, texenv )
            tex2d = osg.Texture2D( image )
            tex2d.setWrap( osg.Texture.WRAP_S, osg.Texture.REPEAT )
            tex2d.setWrap( osg.Texture.WRAP_T, osg.Texture.REPEAT )
            stateset.setTextureAttributeAndModes( 1, tex2d, osg.StateAttribute.ON )

    return( geodePlanet )

# end SolarSystem.createPlanet

osg.Group* SolarSystem.createSunLight()

    sunLightSource = osg.LightSource()

    sunLight = sunLightSource.getLight()
    sunLight.setPosition( osg.Vec4( 0.0, 0.0, 0.0, 1.0 ) )
    sunLight.setAmbient( osg.Vec4( 0.0, 0.0, 0.0, 1.0 ) )

    sunLightSource.setLight( sunLight )
    sunLightSource.setLocalStateSetModes( osg.StateAttribute.ON )
    sunLightSource.getOrCreateStateSet().setMode(GL_LIGHTING, osg.StateAttribute.ON)

    lightModel = osg.LightModel()
    lightModel.setAmbientIntensity(osg.Vec4(0.0,0.0,0.0,1.0))
    sunLightSource.getOrCreateStateSet().setAttribute(lightModel)


    return sunLightSource