;; ----------------------------------------------------------------------------
;; Irrlicht Wrapper for Imperative Languages - Freebasic Examples
;; Frank Dodd (2006-2010)
;; ----------------------------------------------------------------------------
;; Blitz-Irrlicht 1.8.3 Interface by Ed Musolino (AquaLung 2015)
;; ----------------------------------------------------------------------------
;; Example 04 : 3D Models - Meshes and Nodes
;; This example loads an MD2 model and adds it as a node to the scene
;; ----------------------------------------------------------------------------

;; ////////////////////////////////////////////////////////////////////////////
;; Includes for extension libraries
Include "../_libs/bIrrlicht.bb"

;; ////////////////////////////////////////////////////////////////////////////
;; global variables

; irrlicht objects
Global MD2Mesh% = 0
Global MeshTexture% = 0
Global SceneNode% = 0
Global OurCamera% = 0

;; ////////////////////////////////////////////////////////////////////////////
; start the irrlicht interface
;IRR_EDT_OPENGL  OR  IRR_EDT_DIRECT3D9
iIrr3D( 800, 600, 32, False )

; set the window caption
iAppTitle( "Example 04: 3D Models - Meshes and Nodes" )

; add credits for the model as a static text GUI object on the display
iStaticText( "Zumlin model by Rowan ;Sumaleth; Crawford", 4,0,200,16, IRR_GUI_NO_BORDER, IRR_GUI_NO_WRAP, 0 )

; load a mesh this acts as a blue print for the model
SceneNode = iLoadAnimMesh( "./media/zumlin.md2", False )

; load texture resources for texturing the scene nodes
MeshTexture = iLoadTexture( "./media/zumlin.pcx" )

; apply a material to the node to give its surface color
iNodeTexture( SceneNode, MeshTexture, 0 )

; switch off lighting effects on this model, as there are no lights in this
; scene the model would otherwise render pule black
iNodeMaterialFlag( SceneNode, IRR_EMF_LIGHTING, False )

; play an animation sequence embeded in the mesh. MD2 models have a group of
; preset animations for various poses and actions. this animation sequence is
; the character standing idle
iPlayMD2Animation( SceneNode, IRR_EMAT_STAND )

; add a camera into the scene, the first co-ordinates represents the 3D
; location of our view point into the scene the second co-ordinates specify the
; target point that the camera is looking at
OurCamera = iCreateCamera( 0 )

iPositionNode( OurCamera, 50, 0, 0 )

; erase the canvas with sky-blue before rendering
iCameraCLSColor( 128, 255, 255 )

; -----------------------------------------------------------------------------
; while the irrlicht environment is still running
While iRun() And (Not iKeyHit( KEY_ESCAPE ))

	; begin the scene
    iBeginScene()

    ; draw the scene
    iDrawScene()
    
    ; draw the GUI
    iDrawGUI()

    ; end drawing the scene and render it
    iEndScene()
Wend 

; -----------------------------------------------------------------------------
; Stop the irrlicht engine and release resources
iEndIrr3D()


End