Can't get External Mesh Loader to work in irrBMAX

BlitzMax Forums/BlitzMax Programming/Can't get External Mesh Loader to work in irrBMAX

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

teaches me to go from memory :) my apologies. i misguided you on a few steps. my changes are denoted with "GG":

Strict

Import gg.irrBMAX

Type T_chunk_header
 Field id:Byte[4]
 Field length:Long
End Type

' GG - based on BMXIMeshLoader instead
Type B3DLoader Extends BMXIMeshLoader
 Field ChunkHeader:T_chunk_header

 Method IsALoadableFileExtension:Int(Filename:String)
DebugLog("IsALoadableFileExtension")
  Return (Lower(Right(Filename,4)) = ".b3d")
 End Method

 
 Method createMesh:T_irrIAnimatedMesh(file:T_irrIReadFile)
DebugLog("createMesh")
  ChunkHeader = New T_chunk_header
  file.seek(0) 'seek to start of file
  ReadChunkHeader(file)

  If TestByteStringArray(ChunkHeader.id,"BB3D")
   Print "BB3D header found"
  Else
   Print "BB3D header not found"
  End If

 End Method

 Method TestByteStringArray:Int(test1:Byte Ptr,test2:String)
  Local t:Int
   
  For t = 1 To Len(test2)
   If Chr(test1[t-1]) <> Mid(test2,t,1) Then Return False
  Next
  Return True
 End Method

 Method ReadChunkHeader(file:T_irrIReadFile)
  file.read(String Ptr(Varptr ChunkHeader),8)
 End Method
 ' GG - changed to return BMXIMeshLoader
 Function generate:BMXIMeshLoader()
  Return BMXIMeshLoader(New B3DLoader)
 End Function
  
End Type


Local device:T_irrIrrlichtDevice=T_irrIrrlichtDevice.create(EDT_OPENGL,T_irrDimension2d_s32.create(640,480),32,False,False,False,0)

device.setWindowCaption("Hello World! - Irrlicht Engine Demo")

Local driver:T_irrIVideoDriver=device.getVideoDriver()
Local smgr:T_irrISceneManager=device.getSceneManager()
Local guienv:T_irrIGUIEnvironment=device.getGUIEnvironment()

' GG - create the loader, convert it to a T_irrIMeshLoader and pass to addexternalmeshloader
Local loader:B3DLoader = B3DLoader(B3DLoader.create(B3DLoader.generate))
smgr.AddExternalMeshLoader(T_irrIMeshLoader.createFromHandle(loader.handle))

guienv.addStaticText("Hello World! This is the Irrlicht Software renderer!",T_irrRect_s32.createFromVals(10,10,200,22),True)

Local mesh:T_irrIAnimatedMesh=smgr.getMesh("bridge.b3d")
Local node:T_irrIAnimatedMeshSceneNode=smgr.addAnimatedMeshSceneNode(mesh)
Local anim:T_irrISceneNodeAnimator
If node.handle<>0
    node.setScale(T_irrVector3df.createFromVals(100,100,100))
	node.setMaterialFlag(EMF_LIGHTING,False)
	node.setFrameLoop(0,310)
	node.setMaterialTexture(0,driver.getTexture("pebble2.jpg"))
	anim = smgr.createRotationAnimator(T_irrVector3df.createFromVals(.1,1,.5))
	node.addAnimator(anim)

EndIf

smgr.addCameraSceneNode(0,T_irrVector3df.createFromVals(0,30,-40),T_irrVector3df.createFromVals(0,5,0))

While (device.run())

	driver.beginScene(True,True,T_irrSColor.createFromVals(0,200,200,200))
	smgr.drawAll()
	guienv.drawAll()
	driver.endScene()

Wend

device.drop()