Creating Custom Mesh with SMeshBuffer

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.
Post Reply
Bonaducci
Posts: 11
Joined: Fri Aug 03, 2012 1:22 am
Location: Wrocław, Poland

Creating Custom Mesh with SMeshBuffer

Post by Bonaducci »

Hello,
I'm quite new in irrlicht and I'm trying to understand basic things.
I want to create simple engine with editable map, but first of all I have to learn how to manage with meshes.

I've tried method from tutorial 3 but I couldn't even put texture on it. So i decided to use SMesh and create my own mesh and I thought that tutorial 23 would be usefull. I was a bit mistaken.
There is almost no explanation of what there is done. I could spent a lot of time to understand everything there and finally get 10 lines of code needed to create simple mesh, but that is no good method.
I've choosen some parts of this code, but it still don't want to work with me.

Code: Select all

    SMesh* Mesh = new SMesh();
 
    SMeshBuffer *buf = 0;
    buf = new SMeshBuffer();
    Mesh->addMeshBuffer(buf);
    buf->drop();
 
    buf->Vertices.reallocate(3);
    buf->Vertices.set_used(3);
 
    S3DVertex& v = buf->Vertices[0];
    v.Pos.set(0,100,0);
    v.Normal.set(1,1,1);
    v.Color.set(100, 200, 200, 200);
    v.TCoords.set(0, 0);
 
    v = buf->Vertices[1];
    v.Pos.set(100,-100,0);
    v.Normal.set(1,1,1);
    v.Color.set(100, 200, 200, 200);
    v.TCoords.set(0, 0);
 
    v = buf->Vertices[2];
    v.Pos.set(-100,-100,0);
    v.Normal.set(1,1,1);
    v.Color.set(100, 200, 200, 200);
    v.TCoords.set(0, 0);
 
    buf->Indices.reallocate(3);
    buf->Indices.set_used(3);
 
    buf->Indices[0]=0;
    buf->Indices[1]=1;
    buf->Indices[2]=2;
 
    buf->recalculateBoundingBox();
 
 
    IMeshSceneNode* myNode = irrScene -> addMeshSceneNode(Mesh);
 
    myNode->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);
    myNode->setMaterialFlag(EMF_LIGHTING, false);
    myNode->setMaterialFlag(EMF_NORMALIZE_NORMALS, true);
    myNode->setMaterialTexture(0, irrDriver->getTexture("rust0.jpg"));
And this is effect:
Image

I didn't see anything about using this in documentation, so can anyone tell me what I'm doing wrong and what I should do to get simple, textured triangle (and then to add next triangles to it or edit it's shape in real-time)?

//////
I find solution. Now it works:

Code: Select all

    SMesh* Mesh = new SMesh();
 
    SMeshBuffer *buf = 0;
    buf = new SMeshBuffer();
    Mesh->addMeshBuffer(buf);
    buf->drop();
 
    buf->Vertices.reallocate(3);
    buf->Vertices.set_used(3);
 
    buf->Vertices[0] = S3DVertex(0,0,10, 1,1,0,    video::SColor(255,0,255,255), 0, 1);
    buf->Vertices[1] = S3DVertex(10,0,-10, 1,0,0,  video::SColor(255,255,0,255), 1, 1);
    buf->Vertices[2] = S3DVertex(0,20,0, 0,1,1,    video::SColor(255,255,255,0), 1, 0);
 
    buf->Indices.reallocate(3);
    buf->Indices.set_used(3);
 
    buf->Indices[0]=0;
    buf->Indices[1]=1;
    buf->Indices[2]=2;
 
    buf->recalculateBoundingBox();
 
 
    IMeshSceneNode* myNode = irrScene -> addMeshSceneNode(Mesh);
 
    myNode->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);
    myNode->setMaterialFlag(EMF_LIGHTING, false);
    myNode->setMaterialFlag(EMF_NORMALIZE_NORMALS, true);
    myNode->setMaterialTexture(0, irrDriver->getTexture("rust0.jpg"));
Thanks to:
http://irrlicht.sourceforge.net/forum/v ... sh&start=5
Post Reply