@hybrid:
Ok, lets say I've put that static mesh into a zip, bin2h-ed it, made it like the built in font.
Now, how can I load that zip file?
[Fixed]How to draw a mesh from a file without the file..
You use the one that matches the format of the data you've provided. You need to iterate over the list of mesh loaders and see which one it is. Don't hardcode the index, because the index can change depending on how the Irrlicht library is compiled.MasterGod wrote:1. I've added the methods you said, now which IMeshLoader should I use? (at index 0?)
I don't understand why. I still get the feeling that you're trying to 'hide' your meshes in the binary. It may seem less readable in source form, but I can guarantee you that opening the binary in a hex editor will show ascii data. i.e. const c8* msg = "hello world!" is exactly the same as const c8 msg[] = { 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21 } in a hex editor.MasterGod wrote:2. I still prefer to use bin2h :wink:
Is that because you never make mistakes, or the meshes are so primitive that they'd never need to be updated?MasterGod wrote:3. That's really ain't a problem for me :)
Travis
I'm sure he's not trying to hide anything from anyone, not for security reasons.
He probably wants a basic mesh type of some sort, say a quad for use in his game engine and instead of making that file necessary for the person using his engine to actually have in their folder structure he wants to include it as part of his .exe or .lib so that it's just a bit easier to use.
It's something i've been doing in my basic engine i've been using. For example i have some basic shaders that my engine uses to render anything and everything and instead of the application using the engine having to have those files in their folder i just include them in the actual library.
He probably wants a basic mesh type of some sort, say a quad for use in his game engine and instead of making that file necessary for the person using his engine to actually have in their folder structure he wants to include it as part of his .exe or .lib so that it's just a bit easier to use.
It's something i've been doing in my basic engine i've been using. For example i have some basic shaders that my engine uses to render anything and everything and instead of the application using the engine having to have those files in their folder i just include them in the actual library.
Thanks I'll do that. While writing my post I've tried and it doesn't work:vitek wrote:You use the one that matches the format of the data you've provided. You need to iterate over the list of mesh loaders and see which one it is. Don't hardcode the index, because the index can change depending on how the Irrlicht library is compiled.MasterGod wrote:1. I've added the methods you said, now which IMeshLoader should I use? (at index 0?)
Code: Select all
// Getting the right mesh loader from irrlicht
IAnimatedMesh* mesh = 0;
for(u32 meshLoader = 0; meshLoader < smgr->getMeshLoaderCount(); meshLoader++)
{
if(mesh = smgr->getMeshLoader(meshLoader)->createMesh(memData))
break;
}
Code: Select all
if(mesh = smgr->getMeshLoader(4)->createMesh(memData))
break;
EDIT2: The exception is thrown because one of the mesh loaders (6th I think) throws it, still, only the second time and only when I run it with VC..
EDIT3:To be more exact when the meshLoader == 6, I'm not sure it actually tries the 6th loader cause I guess I would have seen something on the console, like the MD2's loader did and the 4th (3ds) should have already load it right..
Exactly what JP said, I also provide the actual mesh as .3ds file in the media directory and I note that in the generated .h file so I really don't try to hide anything..vitek wrote:I don't understand why. I still get the feeling that you're trying to 'hide' your meshes in the binary. It may seem less readable in source form, but I can guarantee you that opening the binary in a hex editor will show ascii data. i.e. const c8* msg = "hello world!" is exactly the same as const c8 msg[] = { 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21 } in a hex editor.MasterGod wrote:2. I still prefer to use bin2h
Kinda, yes (being so primitive)vitek wrote:Is that because you never make mistakes, or the meshes are so primitive that they'd never need to be updated?MasterGod wrote:3. That's really ain't a problem for me
Travis
I don't understand why this is so complicated...
Travis
Code: Select all
// this function creates an animated mesh from an IReadFile. requires
// access to the mesh loaders shown above
scene::IAnimatedMesh*
ISceneManager_createMeshFromFile(scene::ISceneManager* smgr, io::IReadFile* file)
{
const c8* fileName = file->getFileName();
for (u32 n = 0; n < smgr->getMeshLoaderCount(); ++n)
{
scene::IMeshLoader* loader = smgr->getMeshLoader(n);
if (loader && loader->isALoadableFileExtension(fileName))
{
scene::IAnimatedMesh* mesh = loader->createMesh(file);
if (mesh) {
//// you could put the mesh into the mesh cache...
//// this would allow a call to smgr->getMesh() to find the mesh
//scene::IMeshCache* cache = smgr->getMeshCache();
//if (cache)
// cache->addMesh (fileName, mesh);
return mesh;
}
}
}
return 0;
}
// this is a 3ds mesh as binary data
u8 myMeshData[] = {
// mesh data as constructed with bin2h
// if you don't have access to bin2h source, you can write it pretty easily.
};
// load a bunch of data into a memory read file. this would go in your main or whatever
int main ()
{
// do regular irrlicht stuff
io::IReadFile* memoryFile = fileSystem->createMemoryReadFile(myMeshData, sizeof(myMeshData), "myMesh.3ds");
scene::IAnimatedMesh* mesh = ISceneManager_createMeshFromFile(smgr, memoryFile);
memoryFile->drop();
scene::IMeshSceneNode* node = 0;
if (mesh)
node = smgr->addMeshSceneNode(mesh->getMesh(0));
// do more irrlicht stuff...
return 0;
}