Blitz3D+ Command Reference

LoadMesh ( file$[,parent] )

Parameters

file$ - filename of the model to load (.b3d, .x, .3ds, .gltf or .glb)

parent (optional) - parent entity for the loaded mesh; 0 for no parent (default)

Description

Loads a model file as a single static mesh and returns the mesh handle.

Supported formats are B3D, X, 3DS and glTF (.gltf/.glb). The whole file is collapsed into one mesh: any hierarchy and animation information is thrown away. If you want to keep child entities and play the model's animation, use LoadAnimMesh instead.

If the file cannot be loaded, 0 is returned - check for that before using the handle, and see ModelLoadError for the reason.

Each format is converted into Blitz3D's coordinate system as it loads; you can change or disable that conversion per file extension with LoaderMatrix.

The optional parent parameter attaches the loaded mesh to another entity so it moves with it. The relationship is one-way, and the loaded mesh starts exactly at the parent's position (its local coordinates are 0,0,0 relative to the parent).

See also: LoadAnimMesh, LoadGLTFScene, ModelLoadError, LoaderMatrix, FitMesh, CopyEntity.

Example

; LoadMesh Example
; ----------------

; LoadMesh loads a model file (.3ds, .x, .b3d ...) and returns it as
; a single rigid mesh, ready to place in the scene like any other
; entity.

Graphics3D 640,480
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,0,-4

light=CreateLight()
RotateEntity light,30,40,0

; The documented command: load an oil drum model (with its texture)
drum=LoadMesh("media/oil-drum/oildrum.3ds")

; Models come in all sizes - scale the ENTITY so the drum is about
; 2 units wide on screen (the mesh data itself is untouched)
scale#=2.0/MeshWidth(drum)
ScaleEntity drum,scale,scale,scale

While Not KeyDown(1)

    TurnEntity drum,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,"LoadMesh returned handle "+drum
    Text 0,40,"Model has "+CountSurfaces(drum)+" surface(s), original width "+MeshWidth(drum)

    Flip

Wend

End

Index