AppearanceError$ ( )

Parameters

None.

Description

Returns why ApplyWorldEnvironment, ApplyCameraPostFX or ApplyEnvironmentMap last failed.

Each of those commands clears it before it starts, so read it straight after one returns False - for example when a preset of the wrong kind is used, or an environment has no reflection map.

Returns "" after a success.

For the full story, see the Environment and camera presets guide and its complete 01_Appearance_Presets.bb sample.


See also: ApplyWorldEnvironment, ApplyCameraPostFX, ApplyEnvironmentMap.

Example

; ApplyWorldEnvironment Example
; -----------------------------

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

; The soft camera preset needs HDR and tone map 2; those belong to the program
HDRRendering True
ToneMapMode 2

camera=CreateCamera()
PositionEntity camera,0,2,-6

light=CreateLight()
RotateEntity light,45,45,0

; A courtyard of simple shapes to light
ground=CreatePlane()
EntityColor ground,120,130,110
pillar=CreateCylinder(16)
ScaleEntity pillar,0.5,1.5,0.5
PositionEntity pillar,-1.5,1.5,1
ball=CreateSphere(16)
PositionEntity ball,1.5,1,0

; Mountain daylight: sky, ambient light and shadows; soft and plain: camera effects
daylight=LoadPreset(LoadResourceDocument("../../../samples/appearance/daylight.environment"))
soft=LoadPreset(LoadResourceDocument("../../../samples/appearance/soft.postfx"))
plain=LoadPreset(CreateResourceDocument("postfx"))
softened=False
message$="Nothing applied yet"

While Not KeyDown(1)

    ; 1 applies the environment to the world we are drawing
    If KeyHit(2) Then
        If ApplyWorldEnvironment(GetWorld(),FindWorldAsset(daylight,"resource")) Then message="ApplyWorldEnvironment returned True"
    EndIf

    ; 2 swaps the camera's whole effect chain: soft, or plain (no effects)
    If KeyHit(3) Then
        softened=Not softened
        effects=FindWorldAsset(plain,"resource")
        If softened Then effects=FindWorldAsset(soft,"resource")
        If ApplyCameraPostFX(camera,effects) Then message="ApplyCameraPostFX returned True"
    EndIf

    ; 3 makes a mistake: an environment is not a camera preset
    If KeyHit(4) Then
        If Not ApplyCameraPostFX(camera,FindWorldAsset(daylight,"resource")) Then message="ApplyCameraPostFX returned False"
    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

    TurnEntity ball,0,1,0
    RenderWorld

    Text 0,0,"Arrow keys: move camera   1: environment   2: effects   3: a mistake   Esc: exit"
    Text 0,20,message
    Text 0,40,"AppearanceError: "+AppearanceError()

    Flip

Wend

; Applied presets keep what they need, so their worlds can go any time
FreeWorld plain
FreeWorld soft
FreeWorld daylight

End

; Load a preset document into a world of its own, and wait for it
Function LoadPreset(document)
    If document=0 Then RuntimeError ResourceDocumentError()
    preset=LoadResourceDocumentAsync(document)
    FreeResourceDocument document
    While Not WorldReady(preset)
        If WorldLoadState(preset)=WORLD_LOAD_FAILED Then RuntimeError WorldLoadError(preset)
        UpdateAsyncLoads 2
    Wend
    Return preset
End Function

Index