[solved] Minimum needs to display Mesh (Writing FileLoader)
[solved] Minimum needs to display Mesh (Writing FileLoader)
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
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.
Re: Minimum needs to display Mesh (Writing FileLoader)
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) !!!L o wrote:I would need 4 verts and one face with the indices 0,1,2,3.
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
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?
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;
}
I see nothing.
I just dumped the mesh calling
The result:
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.
I just dumped the mesh calling
Code: Select all
smgr->saveScene("scene.out");
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>
OK, but it seems no need a FileSystem, and I do not know where to get that
from CIrrMeshWriter.h:
from CIrrMeshWriter.h:
Code: Select all
CIrrMeshWriter(video::IVideoDriver* driver, io::IFileSystem* fs);
-
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
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
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
oh sorry I was only reading the doxygen files.
ok I got the file:
Looks like the mesh has no buffer?! But I think I inserted the buffer correctly.
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).
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>
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();