Adding/Updating Model meshes at runtime

Anything about development not directly related to libgdx, e.g. OpenGL, Android APIs etc.

Adding/Updating Model meshes at runtime

Postby ThomasOBVI » Mon Jun 12, 2017 4:14 pm

Hello,
I'm new to LibGDX, I must say that I don't really get it with the ModelBuilder, MeshBuilder and the MeshPartBuilder.
What I'm trying to achieve is simple, I'm receiving data from an ordoned point cloud (with everything I need, vertices, faces, normal, colors) and I want to display it with OpenGL. I did that before with Rajawali OpenGL Library. But I decided to switch to LibGDX, because it's more complete.

So before starting, All the values of the vertices are good !

The thing is, when Google Tango have a valid "mesh", it register it, and after I send it to LibGDX. So in my application I have an array (an HashMap to be more precise) of point clouds data. What I want to achieve is, each time I get a new "tangoMesh" -> IF it's a new one : I add it into a TangoModel / ELSE -> I find the good mesh into my model, and I update it with the new data.
I want to have only one model, but with multiple meshes into.

My problems : when I try to add the new mesh into my model, it doesn't work at all, I have to recreate a brand new model each time (with ModelBuilder) if I want my model updated. Which is really heavy on performance.

Here is some code :
Code: Select all
//The create() function of my app
//TANGO
        modelBuilder.begin();
        Node mainTangoNode = modelBuilder.node();
        mainTangoNode.id = MAIN_NODE_ID;
        //Create the tangoMeshPart
        MeshPartBuilder meshBuilder;
        meshBuilder = modelBuilder.part("mainPart", GL20.GL_TRIANGLES, VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal, new Material());

        mTangoModel = modelBuilder.end();
        mTangoModelInstance = new ModelInstance(mTangoModel);
        //Add the renderable objects into the array

        mInstanceToRender = new Array<ModelInstance>();
        mInstanceToRender.add(mFPCameraHelper);
        mInstanceToRender.add(mTangoModelInstance);

        mModelsBatch = new ModelBatch();


Code: Select all
//The function where I update the model (vertices and faces was float[] and short[] created before)

MeshBuilder meshBuilder = new MeshBuilder();
        meshBuilder.begin(VertexAttributes.Usage.Position | VertexAttributes.Usage.ColorPacked);
        mTangoModel.meshParts.set(0, meshBuilder.part("part1", GL20.GL_TRIANGLES));
        meshBuilder.addMesh(vertices, faces);
        Mesh mesh = meshBuilder.end();
        mTangoModel.meshes.add(mesh);

        //If the hash already exist (look at mesh index)
        //mTangoModel.meshes.add(meshBuilder.end());


        mInstanceToRender.removeValue(mTangoModelInstance, false);
        mTangoModelInstance = new ModelInstance(mTangoModel);
        mInstanceToRender.add(mTangoModelInstance);


If anybody have an idea to do this without recreating the Model with the ModelBuilder ?
Thanks in advance !
ThomasOBVI
 
Posts: 1
Joined: Mon Jun 12, 2017 12:29 pm

Return to General Development

Who is online

Users browsing this forum: No registered users and 4 guests