Page 1 of 1
Manually create a mesh
Posted: Tue Jan 01, 2013 8:10 am
by khatarat
i want to create a mesh manually
irrlicht document is very poor and cant find anything about using classes of Engine.
after very searches i found that i should write something like this:
SMesh *m=new SMesh();
SMeshBuffer * meshbuf=new SMeshBuffer();
IMeshSceneNode *node;
video::S3DVertex* a = new video::S3DVertex(0,0,10, 1,1,0, video::SColor(255,0,255,255), 0, 1);
video::S3DVertex* b = new video::S3DVertex(10,0,-10, 1,0,0, video::SColor(255,255,0,255), 1, 1);
video::S3DVertex* c = new video::S3DVertex(0,20,0, 0,1,1, video::SColor(255,255,255,0), 1, 0);
video::S3DVertex* d = new video::S3DVertex(-10,0,-10, 0,0,1, video::SColor(255,0,255,0), 0, 0);
void* ver2[] = {a,b,c,d};
u16 indices[] = { 0,2,3, 2,1,3, 1,0,3, 2,0,1 };
m->addMeshBuffer(meshbuf);
meshbuf->drop();
meshbuf->append((const void*)&ver2, 4, (u16*)&indices, 12);
meshbuf->Vertices.reallocate(4);
meshbuf->Vertices.set_used(4);
meshbuf->Indices.set_used(12);
meshbuf->recalculateBoundingBox();
}
but it doesnt work.
when i call m_Scene->drawAll(); its never go to next line.
what is problem?
Re: Manually create a mesh
Posted: Tue Jan 01, 2013 9:08 am
by greenya
Please check 23.SMeshHandling example.
Re: Manually create a mesh
Posted: Tue Jan 01, 2013 9:57 am
by khatarat
i road that example but its very complicated and not what i want.
i want to user CMeshBuffer.append to add several vertices at once . but when i use it the value of vertices and indices of buffer isnt what i add to beffer.
Re: Manually create a mesh
Posted: Tue Jan 01, 2013 12:35 pm
by Mel
Irrlicht uses a void* pointer so it doesn't have to rewrite each method for diferent vertex types and have diferent signatures, but what you are passing to the append method is a vector of pointers to vertices, not a vector of vertices, which is what is expected, the indices seem fine, though
Re: Manually create a mesh
Posted: Tue Jan 01, 2013 6:59 pm
by khatarat
can you explain more? i didnt understand that where is problem exactly.
Re: Manually create a mesh
Posted: Tue Jan 01, 2013 11:24 pm
by Mel
The SMeshBuffer class inherits from the IMeshBuffer interface, which specifies an append method that uses a void* pointer so it doesn't have to specify a type of vertex.
This IMeshBuffer interface is then implemented in 3 subclasses: SMeshBuffer, for normal vertices, SMeshBufferLightMap for vertices with 2 sets of mapping coordinates and SMeshBufferTangents for meshes with tangents and binormal/bitangent vectors, which have 3 diferent vertex types, so the append method works a little bit diferent for them. One expects vertices of S3DVertex size, other expects the size of vertex of a S3DVertex2TCoords and the other, the size of a S3DVertexTangents, using a void* pointer unifies the whole interface, and makes it posible for all of them to work under the same scheme.
The problem is that you are passing a vector of pointers to vertices, not a vector of vertices to the append method. The engine can't force you to use a type of vertex with the void * pointer, but what you should pass to the append method is a S3DVertex*, The program crashes because you are reading out of the bounds of the vector you have defined for the vertices.
To solve that, instead of a void* pointer, use an array class, and get its pointer when passing the vertices to your mesh.
Re: Manually create a mesh
Posted: Wed Jan 02, 2013 6:21 am
by khatarat
thanks.
my problem has solved.
but why this explanations does not exist in document?
i have another question.
i have a mesh in each frame. how can i create an animation with this meshes?
Re: Manually create a mesh
Posted: Wed Jan 02, 2013 9:03 am
by Mel
there are many ways, you can manually animate the vertices, attach them to bones, it is up to you what to do
Re: Manually create a mesh
Posted: Wed Jan 02, 2013 11:00 am
by Klunk
http://irrlicht.sourceforge.net/forum/v ... =9&t=45093 is an example of animated verts (which coincidentally are "manually" created) theres a link to a release build for window further down too.
Re: Manually create a mesh
Posted: Wed Jan 02, 2013 11:49 am
by hybrid
khatarat wrote:thanks.
my problem has solved.
but why this explanations does not exist in document?
Basically because it's a beginner C++ problem, nothing related to Irrlicht.
Re: Manually create a mesh
Posted: Thu Jan 03, 2013 11:00 am
by khatarat
i know that this void* is a way to create several functions with one signature but from where should i know that what is implimentations of each function in irrlicht library? i think the best way is to read all source codes so could use this library.
Re: Manually create a mesh
Posted: Thu Jan 03, 2013 11:30 am
by serengeor
You can always open up the sources and look what's going inside for yourself
![Smile :)](./images/smilies/icon_smile.gif)
Re: Manually create a mesh
Posted: Thu Jan 03, 2013 2:26 pm
by hybrid
Not sure which problem your void* question is related to. But here, there's absolutely no problem with the void interface, it's basically your Java-style of vertex creation which makes a problem. For C++, an array of vertices is simply not an array of dynamically allocated vertices, otherwise it would be explicitely mentioned.
Re: Manually create a mesh
Posted: Thu Jan 03, 2013 3:55 pm
by khatarat
just after i change S3DVertex * to S3DVertex my problem solved. because no where wrote that should not sent pointer and i just saw one sample code in internet that used pointers.so i sent pointer.