示例#1
0
def generateLight(_lsType, _scene, _goboTex):
    """docstring for generateLight"""
    lh = createNewLightHandle()
    lookAt = Vec3(0.0, -2.0, 0.0)
    if _lsType == 0:
        apiCall( ILBCreateDirectionalLight(_scene, 
                                           "Light", 
                                           vecmath.directionalLightOrientation(Vec3(1.0, -1.0, -1.0)),
                                           ColorRGB(1.0, 1.0, 0.8),
                                           lh))
        apiCall( ILBSetCastShadows(lh, True) )
        apiCall( ILBSetShadowSamples(lh, 32) )
        apiCall( ILBSetShadowAngle(lh, 0.1) )

    elif _lsType == 1:
        # point light
        apiCall( ILBCreatePointLight(_scene,
                                     "Light",
                                     vecmath.translation(Vec3(-1.0, 1.0, 1.0)),
                                     ColorRGB(3.0, 3.0, 2.0),
                                     lh))

        apiCall( ILBSetCastShadows(lh, True) )
        apiCall( ILBSetShadowSamples(lh, 32) )
        apiCall( ILBSetShadowRadius(lh, 1.0) )

        # set a quadratic falloff
        apiCall( ILBSetFalloff(lh, ILB_FO_EXPONENT, 2.0, 20.0, True))
    elif _lsType == 2:
        # spot light
        pos = Vec3(-1.0, 1.0, 1.0)
        spotMatrix = vecmath.setSpotlightMatrix(pos, lookAt-pos)
        apiCall( ILBCreateSpotLight(_scene,
                                     "Light",
                                     spotMatrix,
                                     ColorRGB(3.0, 3.0, 2.0),
                                     lh))

        apiCall( ILBSetCastShadows(lh, True) )
        apiCall( ILBSetShadowSamples(lh, 32) )
        apiCall( ILBSetShadowRadius(lh, 1.0) )

        coneAngle = M_PI/3.0
        apiCall(ILBSetSpotlightCone(lh, coneAngle, 0.1, 2.0))

    elif _lsType == 3:
        # window light
        pos = Vec3(-1.0, 1.0, 1.0)
        matrix = vecmath.setAreaLightMatrix(pos, 
                                            lookAt-pos,
                                            Vec3(0.0, 1.0, 0.0),
                                            Vec2(2.0, 5.0))
        apiCall( ILBCreateWindowLight(_scene,
                                     "Light",
                                     matrix,
                                     ColorRGB(3.0, 3.0, 2.0),
                                     lh))

        apiCall( ILBSetCastShadows(lh, True) )
        apiCall( ILBSetShadowSamples(lh, 32) )
        apiCall( ILBSetShadowAngle(lh, 0.1) )

    elif _lsType == 4:
        #area light
        pos = Vec3(-1.0, 1.0, 1.0)
        matrix = vecmath.setAreaLightMatrix(pos, 
                                            lookAt-pos,
                                            Vec3(0.0, 1.0, 0.0),
                                            Vec2(3.0, 1.0))
        apiCall( ILBCreateAreaLight(_scene,
                                     "Light",
                                     matrix,
                                     ColorRGB(0.4, 0.4, 0.3),
                                     lh))

        apiCall( ILBSetCastShadows(lh, True) )
        apiCall( ILBSetShadowSamples(lh, 32) )

    elif _lsType == 5:
        # Point light wit ramp
        transform = vecmath.scaleTranslation(Vec3(17.0, 17.0, 17.0), Vec3(-1.0, 1.0, 1.0))
        apiCall( ILBCreatePointLight(_scene,
                                     "Light",
                                     transform,
                                     ColorRGB(1.0, 1.0, 1.0),
                                     lh))

        apiCall( ILBSetCastShadows(lh, True) )
        apiCall( ILBSetShadowSamples(lh, 32) )
        apiCall( ILBSetShadowRadius(lh, 1.0) )
        apiCall( ILBSetFalloff(lh, ILB_FO_EXPONENT, 0.0, 20.0, True) )

        # set some random colors in a ramp
        rampColors = 10
        for i in range(rampColors):
            randCol = vecmath.randomRGBA(3.0)
            apiCall( ILBSetLightRampEntry(lh, i/(rampColors-1.0), randCol.toColorRGB()))

    elif _lsType == 6:
        # spot light
        pos = Vec3(-1.0, 1.0, 1.0)
        spotMatrix = vecmath.setSpotlightMatrix(pos, lookAt - pos)
        apiCall( ILBCreateSpotLight(_scene,
                                     "Light",
                                     spotMatrix,
                                     ColorRGB(3.0, 3.0, 2.0),
                                     lh))

        apiCall( ILBSetCastShadows(lh, True) )
        apiCall( ILBSetShadowSamples(lh, 32) )
        apiCall( ILBSetShadowRadius(lh, 1.0) )
        apiCall( ILBSetLightProjectedTexture(lh, goboTex) )

        coneAngle = M_PI/3.0
        apiCall( ILBSetSpotlightCone(lh, coneAngle, 0.1, 2.0) )

    return lh