[solved] Minimum needs to display Mesh (Writing FileLoader)

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
L o
Posts: 44
Joined: Sun Mar 29, 2009 2:53 pm

[solved] Minimum needs to display Mesh (Writing FileLoader)

Post by L o »

Hi,

I am a total n00b in 3D Graphics. Sorry if question is too silly ;)

I have an easy level format which first gives all verts (3 floats per vert) and then all faces as polygons (firs the number of verts of polygon, then the vertex indices). E.g. to display a simple rectangle, I would need 4 verts and one face with the indices 0,1,2,3.

Now everything my engine does is creating the mesh and filling it with a meshbuffer. All I do with the MeshBuffer is:

SMeshBuffer* buffer = new SMeshBuffer;

for each vertex:
{
read v.Pos from file

// I have no clue what a normal to a vert is. I thought normals can only be computed to faces. Is it wrong what I do here?
v.Normal = v.Pos;

// Set Color to White, should not be a problem?
v.Color.set(255,255,255,255);

// What is that? What shall I write here? Is this the reason nothing is displayed?
v.TCoords.X = 1.0;
v.TCoords.Y = 1.0;

// ADD TO MESH BUFFER
vertbuf->Vertices.push_back(v);
}

for each face:
{
// split face into triangles (easy, since faces are all convex)
// ...
vertbuf->Indices.reallocate(...)
insert for each triangle thre shorts, where each is the index of a vert of the triangle
}

That's all. But the loader displays nothing (camera looks ok). What have I forgotten?

Thanks for help in advance!
Lo
Last edited by L o on Sat Apr 18, 2009 6:07 pm, edited 3 times in total.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You should (for a start) enable all debugging render elements (see ISceneNode interface) and you *must* recalculate all bounding boxes, i.e. those of the meshbuffer, the mesh, and the animated mesh (if you need one). Otherwise the mesh will be culled always.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Re: Minimum needs to display Mesh (Writing FileLoader)

Post by Acki »

L o wrote:I would need 4 verts and one face with the indices 0,1,2,3.
no, 4 vetices and 2 faces (triangles), so the indices should be 0,1,2 and 1,2,3 (depending on the order of the vertices) !!! :lol:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
L o
Posts: 44
Joined: Sun Mar 29, 2009 2:53 pm

Post by L o »

Thanks for fast response. I set all debugging stuff, nothing changed. The bounding box calculation etc. was copied from another Loader, it was ok. Below is my main.cpp, but I think that file is ok (most parts also copied).

What still bothers me: Did I do all necessary for the MeshBuffer? Did I fill the vertex correctly?

Code: Select all

int main()
{
	IrrlichtDevice *device =
#ifdef _IRR_OSX_PLATFORM_
		createDevice( video::EDT_OPENGL, dimension2d<s32>(640, 480), 16,
			false, false, false, 0);
#else
		createDevice( video::EDT_SOFTWARE, dimension2d<s32>(640, 480), 16,
			false, false, false, 0);
#endif
	if (!device)
		return 1;

	device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");

	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	IGUIEnvironment* guienv = device->getGUIEnvironment();

	guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
		rect<s32>(10,10,260,22), true);

	IAnimatedMesh* mesh = smgr->getMesh("./testlevel.odfl");

	if (!mesh)
		return 1;
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
	
	
	if (node)
	{
		node->setDebugDataVisible(EDS_FULL);
		node->setMaterialFlag(EMF_LIGHTING, false);
		node->setMD2Animation(scene::EMAT_STAND);
		node->setMaterialTexture( 0, driver->getTexture("../../irrlicht-1.5/media/sydney.bmp") );
	}
	else
	 puts("Node could not be loaded!");
// 2000 -120 2000
	smgr->addCameraSceneNode(0, vector3df(0,0,0), vector3df(2000,-120,2000));
//	smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));

	while(device->run())
	{
		driver->beginScene(true, true, SColor(255,100,101,140));

		smgr->drawAll();
		guienv->drawAll();

		driver->endScene();
	}

	device->drop();

	return 0;
}
L o
Posts: 44
Joined: Sun Mar 29, 2009 2:53 pm

Post by L o »

@Acki: Yes, right, I just meant how it looks in the file. Of course, I split into triangles later. :)
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Even if you cannot see the polygons (e.g. due to wrong orientation, maybe disable backface culling) you should see the bounding boxes. Moreover, the rendered poly count should tell you that at least some meshes are sent to the gfx card. Also make sure your loader returns a proper mesh structure.
L o
Posts: 44
Joined: Sun Mar 29, 2009 2:53 pm

Post by L o »

I see nothing.

I just dumped the mesh calling

Code: Select all

smgr->saveScene("scene.out");
The result:

Code: Select all

<?xml version="1.0"?>
<irr_scene>

        <attributes>
          ...
        </attributes>

        <node type="animatedMesh">

                <attributes>
                        <string name="Name" value="" />
                        <int name="Id" value="-1" />
                        <vector3d name="Position" value="0.000000, 0.000000, 0.000000" />
                        <vector3d name="Rotation" value="0.000000, 0.000000, 0.000000" />
                        <vector3d name="Scale" value="1.000000, 1.000000, 1.000000" />
                        <bool name="Visible" value="true" />
                        <enum name="AutomaticCulling" value="box" />
                        <int name="DebugDataVisible" value="-1" />
                        <bool name="IsDebugObject" value="false" />
                        <string name="Mesh" value="./testlevel.odfl" />
                        <bool name="Looping" value="true" />
                        <bool name="ReadOnlyMaterials" value="false" />
                        <float name="FramesPerSecond" value="0.250000" />
                </attributes>

        </node>
        <node type="camera">

                <attributes>
                        ....
                </attributes>

        </node>
</irr_scene>
Now where is the mesh? oO I see only <string name="Mesh" value="./testlevel.odfl" />, but that file has nothing to do with the mesh buffer.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The scene does not save geometry. You have to use the MeshWriter interface instead to see the vertices and faces.
L o
Posts: 44
Joined: Sun Mar 29, 2009 2:53 pm

Post by L o »

OK, but it seems no need a FileSystem, and I do not know where to get that :-(

from CIrrMeshWriter.h:

Code: Select all

CIrrMeshWriter(video::IVideoDriver* driver, io::IFileSystem* fs);
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You get it from your device (device->getFileSystem())
L o
Posts: 44
Joined: Sun Mar 29, 2009 2:53 pm

Post by L o »

Ook, but should I really use that CIrrMeshWriter? I needed to include it seperately!
Oh and how do I get an IWriteFile? Would be good if you could document such things.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, no, you don't use that one. Did you search the API docs?
Here's what you should do:
ISceneManager::createMeshWriter(EMESH_WRITER_TYPE type)
IMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32 flags=EMWF_NONE)
The writefile is from IFileSystem::createAndWriteFile(const core::string<c16>& filename, bool append=false)
It's all linked and documented :D
L o
Posts: 44
Joined: Sun Mar 29, 2009 2:53 pm

Post by L o »

oh sorry I was only reading the doxygen files.

ok I got the file: :)

Code: Select all

<?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 0 materials.-->
        <boundingBox minEdge="0.000000 0.000000 0.000000" maxEdge="0.000000 0.000000 0.000000" />
</mesh>
Looks like the mesh has no buffer?! But I think I inserted the buffer correctly.

Code: Select all

SMesh* mesh = new SMesh();
animatedmesh->addMesh(mesh);
mesh->drop();

SMeshBuffer* buffer = new SMeshBuffer;
	
if( loadMesh(buffer) ) // call file loader
{
    mesh->addMeshBuffer(buffer);
    buffer->drop();
    return true;
}
mesh->recalculateBoundingBox();
Maybe, the problem is, that I wrote the iAnimatedMesh into the file, but my file loader loaded all into an iMesh which I added to the iAnimatedMesh (in the code, line 2).
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The code is quite confuse - Creating the animated mesh before the mesh, etc. then returning before recalculating the bounding box...
Just check the buffer manually. Create the Meshbuffer, check its size, when ok add it to the mesh and recalculate the bboxes. Then write out the mesh file.
L o
Posts: 44
Joined: Sun Mar 29, 2009 2:53 pm

Post by L o »

ahhh yes I returned BEFORE the recalculating :) Now it works and I see all! Thank you very much 8)

The support was great here!
Post Reply