Manually creating meshes (from vertexes)
-
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
Re: Manually creating meshes (from vertexes)
Note, though, that you might need more vertices per cube in the case of textured meshes. Or a very sophisticated texture algorithm.
-
- Posts: 11
- Joined: Sun Jul 08, 2012 11:49 am
Re: Manually creating meshes (from vertexes)
I simply cannot get it to work.
This code yeids a single, black triangle, where one vertex seems to move as I pitch the camera away from it (camera is stationary) before the whole object suddenly disappears. Im confuzzled.
NOTE: I didnt use "buf->Vertices[0] = ..." because whenever I did things that way, it crashed.
Code: Select all
irr::scene::SMesh* mymesh;
mymesh = new irr::scene::SMesh();
irr::scene::SMeshBuffer *buf = 0;
buf = new irr::scene::SMeshBuffer();
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* ver[] = {a,b,c,d};
u16 indices[] = { 0,2,3, 2,1,3, 1,0,3, 2,0,1 };
mymesh->addMeshBuffer(buf);
buf->drop();
buf->append((const void*)&ver, 4, (u16*)&indices, 12);
buf->recalculateBoundingBox();
irr::scene::IMeshSceneNode* node = scenemgr->addMeshSceneNode( mymesh );
NOTE: I didnt use "buf->Vertices[0] = ..." because whenever I did things that way, it crashed.
Re: Manually creating meshes (from vertexes)
thats because you didnt allocate space for the array, so accessing [0] leads to a crash, since index must be < array.size()NOTE: I didnt use "buf->Vertices[0] = ..." because whenever I did things that way, it crashed.
scene::SMeshBuffer buffer;
buffer.Vertices.reallocate(4); --> now you can have 4 vertices without allocation spaces again (push_back works 4 times without allocating anything)
1st variant:
buffer.Vertices.set_used(4); --> now you can access indices 0..3
buffer.Vertices[0] = video::S3DVertex();
buffer.Vertices[1] = video::S3DVertex();
buffer.Vertices[2] = video::S3DVertex();
buffer.Vertices[3] = video::S3DVertex();
2nd variant
buffer.Vertices.set_used(0); --> now you cant access by index, you would use push_back
buffer.Vertices.push_back( video::S3DVertex() );
buffer.Vertices.push_back( video::S3DVertex() );
buffer.Vertices.push_back( video::S3DVertex() );
buffer.Vertices.push_back( video::S3DVertex() );