Rendering geoms

Discussion in 'Simulation' started by Alexander, Jul 4, 2017.

  1. I'm posting this in a separate thread as it's a different topic.

    Emo in another thread you stated that
    I had a look at mjvive.cpp, unfortunately I can't see the key steps in creating and rendering a new geom. I'm currently using simulation.cpp as a template, and simply extracting a few of the function calls used in mjvive.cpp gives me this:

    mjvGeom * g;
    g = scn.geoms + scn.ngeom;
    v_defaultGeom(g); // as defined in mjvive.cpp
    g->size[0] = 3;
    g->size[1] = 3;
    g->size[2] = 3;
    g->rgba[0] = 0.5;
    g->rgba[1] = 0.5;
    g->rgba[2] = 0.5;
    g->rgba[3] = 0.5;
    g->pos[0] = 0;
    g->pos[1] = 0;
    g->pos[2] = 0;
    g->type = mjGEOM_SPHERE;
    mjv_addGeoms(m, d, &vopt, &pert, mjCAT_ALL, &scn); // is this useful?
    mjv_updateScene(m, d, &vopt, &pert, &cam, mjCAT_ALL, &scn);
    scn.ngeom++;


    I put this code inside void loadmodel(...), however I can't get the geom to render on the screen together with the model I'm loading - what am I missing?
     
    Last edited: Jul 4, 2017
  2. Emo Todorov

    Emo Todorov Administrator Staff Member

    First call mjv_updateScene. This will populate the list of geoms from the model. Then add your custom geom at the end of the geom list, and then render with mjr_render:

    mjv_updateScene(...);
    mjvGeom* g = scn.geoms + scn.ngeom++;
    // set the properties of g
    mjr_render(...);
     
  3. I moved mjv_updateScene as you said, however it still doesn't work. It appears that the value of scn.ngeoms is reset the next time mjv_updateScene is called inside render(...), and the value of m->ngeom never increases by 1, which is perhaps why mjv_updateScene "resets" the value of scn.ngeoms? But still, if I render the single initial frame (i.e. don't call mjv_updateScene(...) in render(...), only called in loadmodel(...)), the geom I created is still not visible. The value of scn.ngeoms has increased by 1, but m->ngeom is still the same, i.e. the model doesn't update?

    Lastly, is there some property making the geom invisible, or is it simply not rendering at all.

    Perhaps you could provide just a few lines of code, that when run in simulation.cpp (and where to run it) would create a new geom?
     
    Last edited: Jul 5, 2017
  4. Emo Todorov

    Emo Todorov Administrator Staff Member

    mjModel.ngeom is the number of geoms in the physics model. mjvScene.ngeom is the number of geoms in the list of abstract geoms to be rendered. The two are not the same. In paritcular, the abstract renderer (mjv_updateScene) may create various decor geoms (contact forces etc) that do not correspond to a model geom, and the user (you) may add custom geoms.

    mjvScene.ngeom is updated every time you call mjv_updateScene. So you have to add your custom geom after every update (i.e. once per frame).

    Not sure why your custom geom is not being rendered. The custom geoms being added in mjvive.cpp are definitely rendered, so maybe copy that code carefully in your project, and go from there.

    To make a geom invisible, set its alpha value (in rgba) to 0.