Simple Mesh creation ?

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
gastar
Posts: 9
Joined: Wed Sep 24, 2003 7:52 am

Simple Mesh creation ?

Post by gastar »

Hi,

first impressive Engine Niko.

I would like to create a small test Mesh without a external Programm.
So how can i build my own Mesch out of Vetrices and add it to the Scene ?

tnx

Gastar
puh
Posts: 356
Joined: Tue Aug 26, 2003 3:53 pm

Post by puh »

Please see Tutorial 3.CustomSceneNode: http://irrlicht.sourceforge.net/tut003.html
gastar
Posts: 9
Joined: Wed Sep 24, 2003 7:52 am

Post by gastar »

I know this Tutorial, but its a whole Custom Scene Node!

There must be a way to create a Mesh and stuff it in a normal MeshSceneNode.
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

You could just implement your own IMesh, or IAnimatedMesh. Or easier: Just use a SMesh and fill it with vertices. :) (http://irrlicht.sourceforge.net/docu/st ... SMesh.html) There are also some IMeshBuffer implementations like SMeshBuffer.

Or if you want to create a mesh loader for your own mesh format, simply implement the IMeshLoader interface as described at http://irrlicht.sourceforge.net/docu/cl ... oader.html
gastar
Posts: 9
Joined: Wed Sep 24, 2003 7:52 am

Post by gastar »

Ah thank you!

And there is the next Question ;)

I created my Mesh and pass it to the SceneNode (addMeshSceneNode)...

Code: Select all

 video::S3DVertex Vertices[4];
        scene::SMesh* myMesh = new scene::SMesh();
        scene::SMeshBuffer* myMeshBuffer = new scene::SMeshBuffer();

        Vertices[0] = video::S3DVertex(0,0,10,1,1,0,video::SColor(255,0,255,255),0,1);
        Vertices[1] = video::S3DVertex(10,0,-10,1,0,0,video::SColor(255,255,0,255),1,1);
        Vertices[2] = video::S3DVertex(0,20,0, 0,1,1,video::SColor(255,255,255,0),1,0);
        Vertices[3] = video::S3DVertex(-10,0,-10, 0,0,1,video::SColor(255,0,255,0),0,0);

        core::aabbox3d<f32> Box;
        Box.reset(Vertices[0].Pos);
        for (s32 i=1; i<4; ++i) {
            Box.addInternalPoint(Vertices[i].Pos);
        }


        myMeshBuffer->Vertices.push_back(Vertices[0]);
        myMeshBuffer->Vertices.push_back(Vertices[1]);
        myMeshBuffer->Vertices.push_back(Vertices[2]);
        myMeshBuffer->Vertices.push_back(Vertices[3]);

        myMeshBuffer->Indices.push_back(0);
        myMeshBuffer->Indices.push_back(2);
        myMeshBuffer->Indices.push_back(3);

        myMeshBuffer->Indices.push_back(2);
        myMeshBuffer->Indices.push_back(1);
        myMeshBuffer->Indices.push_back(3);

        myMeshBuffer->Indices.push_back(1);
        myMeshBuffer->Indices.push_back(0);
        myMeshBuffer->Indices.push_back(3);

        myMeshBuffer->Indices.push_back(2);
        myMeshBuffer->Indices.push_back(0);
        myMeshBuffer->Indices.push_back(1);


        myMeshBuffer->BoundingBox = Box;
        myMesh->MeshBuffers.push_back(myMeshBuffer);

        mSNode = scenemgr->addMeshSceneNode (myMesh, iParent->getNode());
When i build this into a class who will be responsible for deleting the Mesh and the MeshBuffer?
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

Forget 'delete' in Irrlicht. Just use ->drop(). After you have given your mesh to the scene node, and you do not need your mesh any more, just drop() it. It will be deleted automaticly, if no one needs it anymore.

Code: Select all

IMesh* mesh = new YourMesh();
doSomethingWithYourMesh(mesh);
mesh->drop();
If doSomethingWithYourMesh() needs your mesh longer than yourself, that's no problem, because it did a grab() and will drop() it, until it doesn't need it.
Post Reply