Page 1 of 1

Simple Mesh creation ?

Posted: Wed Sep 24, 2003 8:01 am
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

Posted: Wed Sep 24, 2003 8:06 am
by puh
Please see Tutorial 3.CustomSceneNode: http://irrlicht.sourceforge.net/tut003.html

Posted: Wed Sep 24, 2003 8:19 am
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.

Posted: Wed Sep 24, 2003 8:48 am
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

Posted: Wed Sep 24, 2003 9:26 am
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?

Posted: Wed Sep 24, 2003 9:48 am
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.