Lights are encapsulated by the FBLight
class. An FBLight
is created using the FBLight()
constructor. The light's diffuse color FBLight.Diffuse
property controls the color of the light being emitted into the scene. A light's behavior (FBLight.LightType
) can be assigned to a value of FBLightType
. The enumeration values of FBLightType
are described in the following table.
Light Type | Description |
---|---|
FBLightType.kFBLightTypePoint | Point Light. Light radiates from the center of the light, illuminating models in the scene. The FBLight.ConeAngle and FBLight.FogIntensity properties do not apply to point lights. |
FBLightType.kFBLightTypeInfinite | Infinite Light. Light shines uniformly onto the scene, based on its rotation vector. The light's direction is not affected by its translation vector. The FBLight.ConeAngle and FBLight.FogIntensity properties do not apply to infinite lights. |
FBLightType.kFBLightTypeSpot | Spot Light. Light shines from a position in the scene. The FBLight.ConeAngle affects the size of the cone, while the FBLight.FogIntensity property affects the opacity of the fog emitted from the light source. |
FBLight.AttenuationType
) can be set to no attenuation (FBAttenuationType.kFBAttenuationNone
), linear (FBAttenuationType.kFBAttenuationLinear
), or quadratic (FBAttenuationType.kFBAttenuationQuadratic
). However, the attenuation is only visible if a dynamic lighting shader has been applied to the models in the scene. For more information, consult the!!CONVERSION WARNING!! broken xref detectd, likely a cross-book reference. The target GUID file is GUID-286414C1-4969-4BC5-9506-CB5FE8AED544.htm#SECTION_4DA37F7224984044A6C507CC4F5BE52B and the target link text is Example: Dynamic Lighting
section below.
In the following program, an infinite light (red), a point light (green), and a spot light (blue) project their light onto a sphere in the scene.
from pyfbsdk import *
###############################################################
# Helper Function(s). #
###############################################################
# Create an infinite light.
def createInfiniteLight():
infLight = FBLight('myInfiniteLight')
infLight.LightType = FBLightType.kFBLightTypeInfinite
infLight.Translation = FBVector3d(-100, 75, 0)
infLight.Rotation = FBVector3d(0, 0, 145)
infLight.DiffuseColor = FBColor(1, 0, 0)
infLight.Show = True
# Create a point light.
def createPointLight():
pointLight = FBLight('myPointLight')
pointLight.LightType = FBLightType.kFBLightTypePoint
pointLight.Translation = FBVector3d(100, 75, 0)
pointLight.DiffuseColor = FBColor(0, 1, 0)
pointLight.Show = True
# Create a spotlight.
def createSpotLight():
spotLight = FBLight('mySpotLight')
spotLight.LightType = FBLightType.kFBLightTypeSpot
spotLight.Translation = FBVector3d(0, 150, 0)
spotLight.DiffuseColor = FBColor(0, 0, 1)
spotLight.Intensity = 200
spotLight.ConeAngle = 90
spotLight.Show = True
# Create a sphere.
def createSphere():
sphere = FBCreateObject( 'Browsing/Templates/Elements/Primitives', 'Sphere', 'Sphere' )
sphere.Name = 'mySphere'
sphere.Translation = FBVector3d(0, 50, 0)
sphere.Scaling = FBVector3d(4, 4, 4)
sphere.Show = True
###############################################################
# Main. #
###############################################################
# Clear the scene.
FBApplication().FileNew()
# Create a sphere and the various light types.
createSphere()
createInfiniteLight()
createPointLight()
createSpotLight()
The FBGlobalLight
object represents the ambient light in the scene. A reference to the ambient light can be obtained via FBGlobalLight()
. The ambient light color (FBGlobalLight.AmbientColor
), and fog properties (FBGlobalLight.FogEnable
, FBGlobalLight.FogColor
, FBGlobalLight.FogDensity
) can be accessed through this object.
In the following program, we set the ambient light's color, and enable the fog. The white fog is visible as the depth increases along the plane.
from pyfbsdk import *
# Clear the scene.
FBApplication().FileNew()
# Get a reference to the global light.
globalLight = FBGlobalLight()
globalLight.AmbientColor = FBColor(0, 1, 1) # Turquoise
globalLight.FogEnable = True
# Create a plane.
plane = FBModelPlane('myPlane')
plane.Translation = FBVector3d(0, 1, 0)
plane.Scaling = FBVector3d(10, 10, 10)
plane.Show = True
# Create a cone.
model = FBCreateObject( 'Browsing/Templates/Elements/Primitives', 'Cone', 'Cone' )
model.Scaling = FBVector3d(10, 5, 10)
model.Translation = FBVector3d(0, 50, 0)
model.Show = True
Sample Viewport Output:
Program Summary: The program below creates a plane (FBModelPlane
), a blue cylinder (FBModel
), and a spotlight (FBLight
) pointing at the cylinder. The Dynamic Lighting
shader is bound to the plane and the cylinder to allow the light to project onto their surfaces. The Live Shadow
shader is bound to the plane to allow the cylinder's shadow to project onto the plane's surface.
from pyfbsdk import *
###############################################################
# Helper Function(s). #
###############################################################
# Create a spotlight positioned at pTranslation, which will
# shine light on pModel.
def createSpotlight(pTranslation, pModel):
light = FBLight('myLight')
light.LightType = FBLightType.kFBLightTypeSpot
light.Intensity = 200
light.ConeAngle = 70
light.FogIntensity = 20
light.Show = True
light.Translation = pTranslation
light.LookAt = pModel
return light
# Create a large plane.
def createPlane():
plane = FBModelPlane('myPlane')
plane.Translation = FBVector3d(0, 1, 0)
plane.Scaling = FBVector3d(5, 0, 5)
plane.Show = True
return plane
# Create a cylinder.
def createCylinder():
cylinder = FBCreateObject( 'Browsing/Templates/Elements/Primitives', 'Cylinder', 'Cylinder' )
cylinder.Scaling = FBVector3d(5, 3, 5)
cylinder.Translation = FBVector3d(0, 30, 0)
cylinder.Show = True
return cylinder
# Create a blue material.
def createMaterial():
material = FBMaterial('myMaterial')
material.Diffuse = FBColor(0.25, 0.56, 0.8)
return material
# Create a live shadow shader. This shader projects the shadow of an occluding
# object onto a surface.
def createLiveShadowShader():
shader = FBCreateObject('Browsing/Templates/Shading Elements/Shaders', 'Live Shadow', 'myLiveShadowShader')
return shader
# Create a dynamic lighting shader. This shader projects light dynamically
# onto surfaces.
def createDynamicLightingShader():
shader = FBCreateObject('Browsing/Templates/Shading Elements/Shaders', 'Dynamic Lighting', 'myDynamicLightingShader')
return shader
###############################################################
# Main. #
###############################################################
# Clear the scene.
FBApplication().FileNew()
# Create a plane and a cylinder.
plane = createPlane()
cylinder = createCylinder()
# Create a material to apply to the cylinder.
material = createMaterial()
cylinder.Materials.append(material)
# Create a spotlight looking at the cylinder.
light = createSpotlight(FBVector3d(-150, 150, -20), cylinder)
# Create the live shadow and dynamic lighting shaders.
liveShadow = createLiveShadowShader()
dynamicLighting = createDynamicLightingShader()
# Apply the shaders to the plane.
plane.Shaders.append(liveShadow)
plane.Shaders.append(dynamicLighting)
plane.ShadingMode = FBModelShadingMode.kFBModelShadingDefault
# Apply the dynamic lighting shader to the cylinder.
cylinder.Shaders.append(dynamicLighting)
cylinder.ShadingMode = FBModelShadingMode.kFBModelShadingDefault