disapearing mesh issue

Hi, so, here is the issue:
I’m building meshes “from scratch” in panda, that are changed during the execution. The issue is that when adding new vertices they sometimes don’t appear.

One concrete example:
-I create a circle in the center of the screen. ok
-During the execution of the program, I decide to change the mesh, and add vertices so that 4 more circles appears on the screen, forming the corners of a square and having the first one in the center of the square.

Everything still seems to be okay.
Then…I move the camera so that the circle in the center(the first one) leave the screen, and all the circles disapear!
I then move so that the center circle reappears, and then the other ones appears too.

So, I guess when rendering a node panda compute some stuff to decide whereas it should display or not a node, and when I modify the vertex buffer/index buffer, this stuff is not recomputed.
Am I right?
Is there a solution to solve this issue?

By the way, here is the code with which I realized the small test described above.
The four additional circle are drawn one second after the first one.

from math                import cos, sin, radians
from functools           import partial
from direct.task.Task    import Task
from pandac.PandaModules import *
import direct.directbase.DirectStart
import time

def init_vertex_and_index_data():
    geomNode      = GeomNode('line')
    node          = NodePath(geomNode)
    vertex_format = GeomVertexFormat.getV3c4()
    vertex_buffer = GeomVertexData('hf_vertices', vertex_format, Geom.UHDynamic)
    geom          = Geom(vertex_buffer)
    index_buffer  = GeomLines(Geom.UHDynamic)
    return node, vertex_buffer, index_buffer
def add_circle(vertex_buffer, index_buffer, pos, radius):
    lines = []
    for a in xrange(36):
        lines.append(((pos[0]+cos(radians(a*10.))*radius,  pos[1]+sin(radians(a*10.))*radius,0.), 
                      (pos[0]+cos(radians((a-1.)*10.))*radius,  pos[1]+sin(radians((a-1.)*10.))*radius,0.))
    vertex_writer = GeomVertexWriter(vertex_buffer, 'vertex')
    color_writer  = GeomVertexWriter(vertex_buffer, 'color')
    color =(1.,1.,1.,1.)
    index = vertex_buffer.getNumRows()
    print index
    for p1, p2 in lines:
        index = index+2

def add_other_circles(initial_time, vertex_buffer, index_buffer, *args, **kw):
    if time.clock()-initial_time<1.:
        return Task.cont
    add_circle(vertex_buffer, index_buffer, (-200,-200), 5.)
    add_circle(vertex_buffer, index_buffer, (200,200), 5.)
    add_circle(vertex_buffer, index_buffer, (-200,200), 5.)
    add_circle(vertex_buffer, index_buffer, (200,-200), 5.)
    return Task.done

def test():
    node, vertex_buffer, index_buffer = init_vertex_and_index_data()
    # ==
    # firt I create a circle in the midle of the screen
    # ==
    add_circle(vertex_buffer, index_buffer, (0,0), 5.)
    # ==
    # ==
    # then I launch a task that will one second later draw four more circles so that they form a 'square", and the firt one is at the center
    # ==
    taskMgr.add(partial(add_other_circles, time.clock(), vertex_buffer, index_buffer), "pick")
    # ==
    # once everything is displayed if I move the camera so that the original circle leave the screen, all the circle disapears.
    # ==



have you tried to tell panda to recompute the bounding volume after you changed the mesh? if not, that might very well solve the problem.

Right, your analysis is correct; the bounding volume is computed automatically when the node is first rendered. It is not recomputed unless Panda knows that you have modified the node, which it will know if you re-extract the GeomVertexData from the node, instead of storing the pointer and modifying it in-place.

That is, if you use something like:

geom = node.node().modifyGeom(0)
vertex_buffer = geom.modifyVertexData()
index_buffer = geom.modifyPrimitive(0)

to get a new handle to the vertex data and primitive object, then Panda will automatically know it will need to recompute the bounding volume.

You can also tell Panda to recompute the bounding volume explicitly. You have to recompute the bounding volume on both the GeomNode and the Geom:

geom = node.node().modifyGeom(0)

Though the first line implicitly marks the GeomNode’s bounding volume stale. If you had saved a pointer to the geom instead of re-extracting it, then you would have to do:


In general, though, I recommend re-extracting the components when modifying them like this, rather than saving the pointers and clearing bounding volumes explicitly. This gives Panda the most information about what you are doing, and requires you to have the least a priori knowledge about Panda’s internal caching mechanisms.


Thank you, this seems to work better.