Mesh from PLY

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.

Mesh from PLY

Postby Jarin » Mon Apr 02, 2012 7:39 pm

Hello,
im trying to build a simple irrlicht program that will load a ply file a draws the mesh from it. Im using ply just as a sample. In the future i will be providing the verticies an faces information from a different source, but for now i would like to get it work with ply as it is the format i need.

Im using CDynamicMeshBuffer( to store vertecies and faces, but i cant get the program to show the mesh. Before this, i tried using sample program (tutorial 3) to show a custum node but it didnt work with larger number of faces (50 or more).

I think there is a small problem with drawing the mesh, because the mesh is stored ok, but i cant figure out what it is.

Got the code basics from the irrlicht source files.

cpp Code: Select all
 
int main()
{
        // ask user for driver
        video::E_DRIVER_TYPE driverType=driverChoiceConsole();
        if (driverType==video::EDT_COUNT)
                return 1;
 
        // create device
        IrrlichtDevice *device = createDevice(driverType,
                core::dimension2d<u32>(640, 480), 16, false);
 
        if (device == 0)
                return 1; // could not create selected driver.
 
        // create engine and camera
 
        device->setWindowCaption(L"Custom Scene Node - Irrlicht Engine Demo");
 
        video::IVideoDriver* driver = device->getVideoDriver();
        scene::ISceneManager* smgr = device->getSceneManager();
 
        smgr->addCameraSceneNode(0, core::vector3df(0,-40,0), core::vector3df(0,0,0));
 
        std::vector<video::S3DVertex> m_verticies;
        std::vector<irr::core::vector3df> m_faces;
 
        irr::scene::CDynamicMeshBuffer *mb;
        irr::scene::SAnimatedMesh* animMesh;
 
        // loads a ply and saves to the std vectors
        LoadPLY("balonek.ply", m_verticies, m_faces);
 
        int vertCount = m_verticies.size();
        mb = new irr::scene::CDynamicMeshBuffer(video::EVT_STANDARD, vertCount > 65565 ? video::EIT_32BIT : video::EIT_16BIT);
        mb->getVertexBuffer().reallocate(vertCount);
        mb->getIndexBuffer().reallocate(m_faces.size()*3);
        mb->setHardwareMappingHint(irr::scene::EHM_STATIC);
 
        // fills the vertex buffer
        for (long i = 0; i < m_verticies.size(); i++){
                mb->getVertexBuffer().push_back(m_verticies.at(0));
        }
 
        // fills the index buffer
        for (long i = 0; i < m_faces.size(); i++){
                mb->getIndexBuffer().push_back(m_faces.at(i).X);
                mb->getIndexBuffer().push_back(m_faces.at(i).Y);
                mb->getIndexBuffer().push_back(m_faces.at(i).Z);
        }
 
        mb->recalculateBoundingBox();
 
        irr::scene::SMesh* m = new irr::scene::SMesh();
        m->addMeshBuffer(mb);
        m->recalculateBoundingBox();
        mb->drop();
        animMesh = 0;
        animMesh = new irr::scene::SAnimatedMesh();
        animMesh->addMesh(m);
        animMesh->recalculateBoundingBox();
        m->drop();
 
        irr::scene::IAnimatedMeshSceneNode* anms = smgr->addAnimatedMeshSceneNode(animMesh);
        anms->setMaterialFlag(video::EMF_LIGHTING, false);
        anms->setVisible(true);
 
        while(device->run())
        {
                driver->beginScene(true, true, video::SColor(0,100,100,100));
                smgr->drawAll();
                driver->endScene();
        }
        device->drop();
        return 0;
}
 


Thanks for any help.
Jarek
Jarin
 
Posts: 2
Joined: Mon Apr 02, 2012 10:17 am

Re: Mesh from PLY

Postby CuteAlien » Mon Apr 02, 2012 8:19 pm

You seem to push coordinates into the index-buffer. An index-buffer contains indices (to the vertices).

edit: Also Irrlicht has already PLY loader in case that's all you need. So you should be able to just load the file (you can test if it works in the meshviewer).
IRC: #irrlicht on irc.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5364
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Mesh from PLY

Postby smso » Mon Apr 02, 2012 8:22 pm

??
cpp Code: Select all
mb->getVertexBuffer().push_back(m_verticies.at(0));


Regards
smso
smso
 
Posts: 218
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: Mesh from PLY

Postby Jarin » Tue Apr 03, 2012 5:39 am

smso wrote:??
cpp Code: Select all
mb->getVertexBuffer().push_back(m_verticies.at(0));


Regards
smso


What a beginners mistake. Cant believe i didnt see it. It works perfectly now. Thank you so much.

CuteAlien wrote:You seem to push coordinates into the index-buffer. An index-buffer contains indices (to the vertices).

edit: Also Irrlicht has already PLY loader in case that's all you need. So you should be able to just load the file (you can test if it works in the meshviewer).


I didnt use the build in because in a future (hopefully next week :D ) i will be visualising meshes created from Kinect point clouds.

Now i knouw it works and i can move to connectiong kinect with irrlicht.
Jarin
 
Posts: 2
Joined: Mon Apr 02, 2012 10:17 am

Re: Mesh from PLY

Postby RdR » Tue Apr 03, 2012 11:21 am

Jarin wrote:I didnt use the build in because in a future (hopefully next week :D ) i will be visualising meshes created from Kinect point clouds.

Now i knouw it works and i can move to connectiong kinect with irrlicht.


Take a look here:
viewtopic.php?f=9&t=45730
User avatar
RdR
Competition winner
 
Posts: 259
Joined: Tue Mar 29, 2011 2:58 pm


Return to Beginners Help

Who is online

Users browsing this forum: No registered users and 1 guest