Meshbuffer vertex coords issue

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
Misan
Posts: 8
Joined: Mon Jan 30, 2012 12:16 pm

Meshbuffer vertex coords issue

Post by Misan »

Hi.

I'm trying to export my scene to my own text format and I came along the following problem:
When I do my own custom scene nodes, everything works fine, but when I try to export the meshbuffers of mesh scene nodes loaded from md2 or any other format - I get the original vertex coordinates, instead of the ones I expect after multiple calls to setRotation, setPosition or setScale on the scene node.

Here's what I do now:

Code: Select all

std::string Serializer::doNode(irr::scene::IMeshSceneNode *node){
        std::string out;
        for(u32 i = 0; i < node->getMesh()->getMeshBufferCount(); ++i){
                IMeshBuffer *buf = node->getMesh()->getMeshBuffer(i);
                u32 vcount, icount;
                vcount = buf->getVertexCount();
                icount = buf->getIndexCount();
                out += "object " + fmt(vcount) + " " + fmt(icount) + "\n";
                out += "indices ";
                for(u32 i = 0; i < icount; ++i){
                        out += fmt(buf->getIndices()[i]) + ",";
                }
                out += "\nvertices\n";
                for(u32 i = 0; i < vcount; ++i){
                        out += doVertex(((S3DVertex*)buf->getVertices())[i]) + "\n"; //convert a s3dvertex array into '\n'-separated strings
                }
        }
        return out;
}
Any help would be greatly appreciated.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Meshbuffer vertex coords issue

Post by CuteAlien »

You usually have X nodes and one single mesh. And on rendering the nodes transform that mesh each frame (that's way faster than uploading a changed mesh all the time). So you always export the same mesh - meshes don't change. And for nodes you export scaling, rotation and position (+ maybe the name of your mesh). If you really want to change the mesh itself (very rarely the case!) you would work with the transform function of IMeshManipulator.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Misan
Posts: 8
Joined: Mon Jan 30, 2012 12:16 pm

Re: Meshbuffer vertex coords issue

Post by Misan »

Thanks for the reply.

I don't necessarily need to change the meshes themselves, but I cannot export any other parameters than vertex coordinates. I'm just looking for a way to obtain a list of transformed vertices, whether by changing the mesh or not - that's not significant. Just to be clear - my goal is to export what is being rendered, not loaded, transformed etc... ie, exactly what I see on the screen.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Meshbuffer vertex coords issue

Post by CuteAlien »

You are sending the mesh + transformation matrices to the graphic card. The transformation from mesh-coordinates to something on the screen is happening on the graphic card. The vertex-coordinates are at no point changed in your main-memory. I don't think there is any easy way getting that back from the graphic card (although I guess it's probably possible with some shader programs). But unless you have a very strange format there is simply no point in working with the transformed vertices - working with the mesh + transformations is so much easier.

edit: Note - if you absolutely need this for some reason then you can do manually the same transformations which the card usually does for you by hand. Method would be as described above - you would use the transform functions of the MeshManipulator and give it the absolute transformation of the scenenode (ISceneNode::getAbsoluteTransformation will return that). But maybe describe first why you can't just put the transformations in your export instead - it makes so much more sense.

edit2: The "exactly what I see on the screen" is a 2d image - which is the end-result of applying a bunch of transformations on a given 3d mesh and doing some additional clipping (using the depth-buffer information). There's a screenshot function for that...
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Misan
Posts: 8
Joined: Mon Jan 30, 2012 12:16 pm

Re: Meshbuffer vertex coords issue

Post by Misan »

...as for your edit2 - my mistake, I obviously meant the 3D scene.

I don't think exporting transformations is the way to go, because I need co create something easily reparseable into a bunch of different open formats, such as .obj, which I don't think supports transformations. Or am I wrong here as well? :)

Anyway, MeshManipulator seems like the way to go, thanks a bunch for your help!
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Meshbuffer vertex coords issue

Post by CuteAlien »

OK, I have to admit exporting the whole scene is a single .obj file is indeed something where you will need this. Be careful - usually scenenodes do share their meshes, so you have to copy the mesh before transforming them (IMeshManipulator also has a function for that).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Misan
Posts: 8
Joined: Mon Jan 30, 2012 12:16 pm

Re: Meshbuffer vertex coords issue

Post by Misan »

Yup, the copying kind of occured to me as I was coding. Thanks for the additional tip :)
Post Reply