Attempting to load a b3d entity from a bank

Community Forums/General Help/Attempting to load a b3d entity from a bank

Blitzplotter(Posted 2015) [#1]
This is my attempt so far, which results in a MAV:


Local b3dentityone = LoadAnimMesh(FiLoadFromBank(bank[6]))



Any assistance with where I'm going wrong appreciated.


Matty(Posted 2015) [#2]
Well...if I was debugging that I'd take everything out of the nested brackets first and make sure all the return values were valid....as a start.


Blitzplotter(Posted 2015) [#3]
Hmmm after digging around I'm beginning to think I've finally bitten of more that I can chew: Managed to extract jpgs from the end of an exe - however extracting b3d(s) that are plastered onto the end of an exe as well as images is eluding me.

Time to hang up the coding boots and read a book I think, for tonight anyway.

http://www.blitzbasic.com/Community/posts.php?topic=20336#207774


virtlands(Posted 2015) [#4]
Oh, hello BlitzPlotter,

The FiLoadFromBank is a custom function to be used with images only,
it cannot be interfaced to any other file type (including meshes).

Here is the FiLoadFromBank in its original form (located in FreeImage.bb)::

Function FiLoadFromBank(bank)
;Loads a FreeImage bitmap from a bank
;Returns a FreeImage bitmap or False if fails

Local stream, fif, dib
If bank = 0 Then Return 0 ;No bank
stream = FreeImage_OpenMemory(bank, BankSize(bank)) ;Attach to memory
fif = FreeImage_GetFileTypeFromMemory(stream, 0) ;Format from filetype
If fif >= 0 ;Format is valid
dib = FreeImage_LoadFromMemory(fif, stream, 0) ;Load from memory
EndIf
FreeImage_CloseMemory(stream) ;Close memory
Return dib
End Function

===========================================================================

In order to accomplish what you're trying to do, then perhaps try this different simpler strategy ::

(a) Extract the B3D directly out of the EXE and save into a file on disc.
(b) Read the B3D file normally, using LoadAnimesh ...

LoadAnimMesh( Filename$, [Parent] )

I don't believe there is any shortcut strategy of loading it into a bank first.
Good Luck.


*(Posted 2015) [#5]
If its a static b3d (no animation) you could just convert the vertex, triangle and uv data to simple DefData statements and read it in creating it as you go. This way would give you no model files at all but doesn't exactly work for animated meshes.


Blitzplotter(Posted 2015) [#6]
@Virtlands and Edzup, thanks for the feedback. I believe I need to read and consequently write byte by byte from the start 'offset' to the end 'offset' and read in the animated mesh using the LoadAnimMesh as you've suggested.

Seeing as they are animated meshes I think this'll be my way forward. I like a challenge, this one has almost proven too much though ;) Thanks for confirming the way forward, its appreciated.