Manually create a mesh
Manually create a mesh
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?
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
Please check 23.SMeshHandling example.
Re: Manually create a mesh
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.
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
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
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Re: Manually create a mesh
can you explain more? i didnt understand that where is problem exactly.
Re: Manually create a mesh
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.
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.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Re: Manually create a mesh
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?
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
there are many ways, you can manually animate the vertices, attach them to bones, it is up to you what to do
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Re: Manually create a mesh
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.
-
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
Re: Manually create a mesh
Basically because it's a beginner C++ problem, nothing related to Irrlicht.khatarat wrote:thanks.
my problem has solved.
but why this explanations does not exist in document?
Re: Manually create a mesh
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
You can always open up the sources and look what's going inside for yourself
Working on game: Marrbles (Currently stopped).
-
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
Re: Manually create a mesh
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
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.