[Fixed]How to draw a mesh from a file without the file..

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

[Fixed]How to draw a mesh from a file without the file..

Post by MasterGod »

Yes this sound a bit weird but I couldn't describe better.
I have a text mesh I made with Blender.
I want to make a custom scene node with that text but I don't want to have the mesh file. I understand that if I convert it to irrmesh it becomes a simple xml file or something like that, that if I'll open it with notepad it would be readable.
I want to copy that mesh info so I'll be able to draw manually the mesh..

How can I do that if you understand what I mean?

P.S
I know how to make a custom scene node (well, it would be my first one). I guess it would be similar to the tutorial because there the triangle is drawn without a mesh file.
Last edited by MasterGod on Tue Feb 05, 2008 2:37 pm, edited 1 time in total.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

Uhm, if I am hearing this correctly, you want to take the data out of the file, and put it into your program so that you no longer need the file? Well then, all you have to do is copy the xml to a string, and then parse it as if it was in a file. (That's if I am understanding you correctly.)
TheQuestion = 2B || !2B
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Halifax wrote:Uhm, if I am hearing this correctly, you want to take the data out of the file, and put it into your program so that you no longer need the file? Well then, all you have to do is copy the xml to a string, and then parse it as if it was in a file. (That's if I am understanding you correctly.)
That's exactly what I want and I've checked and the irrmesh is a xml file.
So, there must be an easy way to use a built-in method to read the code - string, instead of the file.. Just how can I do that?
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Open the file, read it, close it. There's the IReadFile Interface which allows to do such things.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

I'll look on the IReadFile now but I don't want to read from a file, that's that whole idea, I want to copy the file's data into a string and read everything from that string and then draw the mesh (which's data is in a single string).
I think it kinda like the built-in font if I remember right its implementation.

Edit:
Should I pass read() method the string and the sizeof(st)?

P.S
The docs for the buffer are a bit confusing:
virtual s32 irr::io::IReadFile::read ( void * buffer,
u32 sizeToRead
) [pure virtual]

Reads an amount of bytes from the file.

Parameters:
buffer,: Pointer to buffer where to read bytes will be written to.
sizeToRead,: Amount of bytes to read from the file.

Returns:
Returns how much bytes were read.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Which of these I need?
virtual IReadFile * createMemoryReadFile (void *memory, s32 len, const c8 *fileName, bool deleteMemoryWhenDropped=false)=0
Creates an IReadFile interface for accessing memory like a file.

virtual IXMLReader * createXMLReader (IReadFile *file)=0
Creates a XML Reader from a file which returns all parsed strings as wide characters (wchar_t*).

virtual IXMLReaderUTF8 * createXMLReaderUTF8 (IReadFile *file)=0
Creates a XML Reader from a file which returns all parsed strings as ASCII/UTF-8 characters (char*).
And then again getMesh() wants a file not a IReadFile*..
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Looks like the first one that you need, passing it a pointer to the place in memory you have the file stored (as a string).

Personally i use a funky command line program called dattoh which turns a data file into a C header containing a char array of the data. So then you just have to include that file into your project and pass the array to a function that will accept a memory pointer to read from.
Image Image Image
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

JP wrote:Looks like the first one that you need, passing it a pointer to the place in memory you have the file stored (as a string).
You mean IReadFile::read() or createMemoryReadFile()?
JP wrote:Personally i use a funky command line program called dattoh which turns a data file into a C header containing a char array of the data. So then you just have to include that file into your project and pass the array to a function that will accept a memory pointer to read from.
I think Anim8tor can do that too but I'm not sure I want such solution..

P.S
The irrmesh is a XML file, can't it help in some way?
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

i don't know anything about irrmesh but being xml doesn't help loading it from memory in anyway (doesn't make it harder i'm sure but doesn't make it easier).

What you want is to have the file stored in memory some way, a header is the best way to do this and storing it as a string/char-array is the way to do it, there's not really another way.
Image Image Image
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

MasterGod,

What exactly are you trying to do? Your first post made it sound like you were trying to prevent people from looking at your mesh data [which won't work]. Now it looks like you are trying to load mesh data directly into memory, and that isn't going to be very useful either because you would need to get direct access to the mesh loader, which you don't have.

So please, go back a step and tell us exactly what you are trying to do, e.g. what is the problem that you are trying to solve and why.

Travis
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Lets say I have this string as the mesh's data:

Code: Select all

// Copyright (C) 2002-2007 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h

#ifndef __BUILD_IN_FONT_H_INCLUDED__
#define __BUILD_IN_FONT_H_INCLUDED__

#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_GUI_

// header file generated by Bin2H, copyright 2002 by N.Gebhardt.
// Bin2H is Freeware. Download it freely from www.code3d.com.
// for the source bitmap, see builtInFont.bmp

namespace irr
{
namespace gui
{

u8 BuiltInFontData[] =
{
	0x42, 0x4d, 0x4a, 0x20, ...
	0x23, 0x22
};

	u32 BuiltInFontDataSize = sizeof(BuiltInFontData);
} // end namespace gui
} // end namespace irr

#endif // _IRR_COMPILE_WITH_GUI_

#endif
How can I render it assuming its a static mesh? (example code maybe?)[/code]

P.S
I think maybe I'll use Bin2hfor the conversion though..
Edit: Not maybe, I am gonna use it :)
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

vitek wrote:MasterGod,

What exactly are you trying to do? Your first post made it sound like you were trying to prevent people from looking at your mesh data [which won't work]. Now it looks like you are trying to load mesh data directly into memory, and that isn't going to be very useful either because you would need to get direct access to the mesh loader, which you don't have.

So please, go back a step and tell us exactly what you are trying to do, e.g. what is the problem that you are trying to solve and why.

Travis
I don't try to hide my mesh data, I just don't want it to be an external file but part of the exe file.
Yes, I do try to load it to memory and pass that data to the mesh loaders..
Is that impossible? (without modifying irrlicht?)

P.S
It seems we were posting at the same time :wink:
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

You would need to get a pointer to the mesh loader used to parse the given mesh file format. I don't see any way to do that yet, so this would require a change to the Irrlicht sources [add getMeshLoaderCount() and getMeshLoader(u32) to the scene manager interface and implementation]. This would be a useful addition to the Irrlicht core, so if you decide to do it, you might post a patch.

If you have ascii XML data, you don't need to use any utility, you just paste the xml content into your source and escape some characters [quotes and such]...

Code: Select all

const char dwarfMeshData[] =
"<?xml version=\"1.0\"?>"
"<mesh xmlns=\"http://irrlicht.sourceforge.net/IRRMESH_09_2007\" version=\"1.0\">"
"<!-- This file contains a static mesh in the Irrlicht Engine format with 3 materials.-->"
"	<boundingBox minEdge=\"-34.120579 -3.543222 -49.155174\" maxEdge=\"38.802605 74.407661 19.682945\" />"
"	<buffer>"
"		<boundingBox minEdge=\"24.496161 15.668485 -46.026169\" maxEdge=\"35.487915 33.405987 16.553940\" />"
"		<material>"
"			<enum name=\"Type\" value=\"solid\" />"
"			<color name=\"Ambient\" value=\"ffffffff\" />"
"			<color name=\"Diffuse\" value=\"ffcccccc\" />"
"			<enum name=\"TextureWrap4\" value=\"texture_clamp_repeat\" />"

// snip

"		</material>"
"		<vertices type=\"standard\" vertexCount=\"0\">\n"
"		</vertices>"
"		<indices indexCount=\"0\">"
"		</indices>"
"	</buffer>"
"</mesh>";
Then just write code to create a read file from that data...

Code: Select all

io::IReadFile* file = fileSystem->createMemoryReadFile(dwarfMeshData, sizeof(dwarfMeshData), "dwarf.irrmesh");
The thing that really sucks about this idea is that you need to recompile and relink your application to change the mesh data. You must also remember to keep the source mesh around so you can regenerate the data if it is ever updated.

Travis
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

1. I've added the methods you said, now which IMeshLoader should I use? (at index 0?)
2. I still prefer to use bin2h :wink:
3. "The thing that really sucks about this idea is that you need to recompile and relink your application to change the mesh data. You must also remember to keep the source mesh around so you can regenerate the data if it is ever updated. " That's really ain't a problem for me :)

Thanks.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Can't you put your data into a zip file, bin2h that one and mount the zip file from memory? Then all the usual methods would again apply.
Post Reply