LightBakeError$ ( bake )

Parameters

bake - bake handle from BakeLighting

Description

Returns why a bake failed, or why SaveLightBake could not save it.

It is empty while the bake runs and after it succeeds. Check it when LightBakeState says LIGHT_BAKE_FAILED, or when SaveLightBake returns False, and show it to whoever is making the level.

See also: LightBakeState, SaveLightBake, BakeLighting.

Example

; BakeLighting Example
; --------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,1,-3.5

; A dark room: everything you see comes from the lamp and the light it bounces
AmbientLight 8,8,12

; One wall, floor or ceiling of the room: a flat box of its own colour
Function Wall(x#,y#,z#,width#,height#,depth#,red,green,blue)
    wall=CreateCube()
    ScaleEntity wall,width/2,height/2,depth/2
    PositionEntity wall,x,y,z
    EntityColor wall,red,green,blue
    Return wall
End Function

Wall 0,-0.1,0,4,0.2,4,230,230,225
Wall 0,2.1,0,4,0.2,4,230,230,225
Wall 0,1,2.1,4,2.4,0.2,230,230,225
Wall -2.1,1,0,0.2,2.4,4,220,40,30
Wall 2.1,1,0,0.2,2.4,4,50,200,60
crate=Wall(0.5,0.4,0.6,0.8,0.8,0.8,200,180,140)
TurnEntity crate,0,25,0

; The lamp, fully baked: its light and soft shadows go into the lightmaps
lamp=CreateLight(2)
PositionEntity lamp,0,1.8,-0.3
LightRange lamp,2
LightBakeMode lamp,LIGHT_BAKED
LightBakeRadius lamp,0.2

; Bake at Preview quality, which takes moments
LightBakeQuality 0
bake=BakeLighting()
view=0

While Not KeyDown(1)

    ; Space bakes again, C cancels a bake, R clears the baked lighting
    If KeyHit(57) And bake=0 Then bake=BakeLighting()
    If KeyHit(46) And bake<>0 Then CancelLightBake bake
    If KeyHit(19) Then ClearBakedLighting

    ; V cycles the view: finished look, lighting only, lightmap texels
    If KeyHit(47) Then
        view=(view+1) Mod 3
        LightBakeView view
    EndIf

    ; A finished bake has applied itself: keep its stats, then free it
    If bake<>0 Then
        If LightBakeState(bake)<>LIGHT_BAKE_RUNNING Then
            If LightBakeState(bake)=LIGHT_BAKE_FAILED Then stats$="Failed: "+LightBakeError(bake) Else stats$=LightBakeStats(bake)
            FreeLightBake bake
            bake=0
        EndIf
    EndIf

    ; Arrow keys move the camera
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,0,-0.1
    If KeyDown(203) Then TurnEntity camera,0,1,0
    If KeyDown(205) Then TurnEntity camera,0,-1,0

    RenderWorld

    Text 0,0,"Arrow keys: move camera   Space: bake   C: cancel   R: clear   V: view   Esc: exit"
    If bake<>0 Then
        Text 0,20,"Baking: "+LightBakeStage(bake)+" "+(LightBakeProgress(bake)/10)+"%"
    Else
        Text 0,20,"BakedLightingStatus: "+BakedLightingStatus()
    EndIf
    Text 0,440,Left(stats,90)

    Flip

Wend

End

Index