Blitz3D+ Command Reference

WorldAssetKind ( asset )

Parameters

asset - an asset handle returned by FindWorldAsset

Description

Returns what kind of asset a world asset handle refers to, as a WORLD_ASSET_KIND_* constant.

The possible kinds are:
WORLD_ASSET_KIND_MODEL (1): geometry for CreateWorldAsset
WORLD_ASSET_KIND_TEXTURE (2): an image for WorldAssetTexture
WORLD_ASSET_KIND_HEIGHTMAP (3): terrain height samples consumed by terrain components
WORLD_ASSET_KIND_SOUND (4): audio for WorldAssetSound
WORLD_ASSET_KIND_SHADER (5): a shader for WorldAssetShader

Use the named constants in your code; the numbers are documented for logs and tools. Each typed accessor only accepts its own kind - asking WorldAssetTexture for a sound is a runtime error - so this query lets generic code (an asset browser, a preload progress list) route handles to the right accessor.

For the full story, see the Async World Loading guide.

Requires Extended mode.

See also: FindWorldAsset, WorldAssetID, WorldAssetTexture, WorldAssetSound, WorldAssetShader, CreateWorldAsset.

Example

; WorldAssetKind Example
; ----------------------
; Requires Extended mode.

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

camera=CreateCamera()
PositionEntity camera,0,1,-5
light=CreateLight()
RotateEntity light,45,45,0

; Load the asset manifest world in the background
manifest=LoadWorldAsync("../../../samples/worlds/asset-preload.world")
While Not WorldReady(manifest)
    If WorldLoadState(manifest)=WORLD_LOAD_FAILED Then RuntimeError WorldLoadError(manifest)
    Cls
    Text 0,0,"Loading the asset manifest..."
    Flip
Wend

; Resolve three of the manifest's assets to opaque handles
model_asset=FindWorldAsset(manifest,"display-model")
texture_asset=FindWorldAsset(manifest,"display-texture")
sound_asset=FindWorldAsset(manifest,"ready-sound")

; WorldAssetKind reports what type of asset a handle refers to
model_kind$=kind_name(WorldAssetKind(model_asset))
texture_kind$=kind_name(WorldAssetKind(texture_asset))
sound_kind$=kind_name(WorldAssetKind(sound_asset))

; A spinning crate wearing the texture asset keeps the scene alive
tex=WorldAssetTexture(texture_asset)
crate=CreateCube()
PositionEntity crate,0,1,0
EntityTexture crate,tex

While Not KeyDown(1)

    TurnEntity crate,0,1,0

    ; 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   Esc: exit"
    Text 0,20,"WorldAssetKind('display-model') = "+model_kind
    Text 0,40,"WorldAssetKind('display-texture') = "+texture_kind
    Text 0,60,"WorldAssetKind('ready-sound') = "+sound_kind

    Flip

Wend

FreeTexture tex
FreeWorld manifest
End

; Turn a WorldAssetKind value into a readable name
Function kind_name$(kind)
    Select kind
        Case WORLD_ASSET_KIND_MODEL
            Return "WORLD_ASSET_KIND_MODEL"
        Case WORLD_ASSET_KIND_TEXTURE
            Return "WORLD_ASSET_KIND_TEXTURE"
        Case WORLD_ASSET_KIND_HEIGHTMAP
            Return "WORLD_ASSET_KIND_HEIGHTMAP"
        Case WORLD_ASSET_KIND_SOUND
            Return "WORLD_ASSET_KIND_SOUND"
        Case WORLD_ASSET_KIND_SHADER
            Return "WORLD_ASSET_KIND_SHADER"
    End Select
    Return "unknown"
End Function

Index