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)
geomNode.addGeom(geom)
index_buffer = GeomLines(Geom.UHDynamic)
geom.addPrimitive(index_buffer)
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()
vertex_writer.setRow(index)
color_writer.setRow(index)
print index
for p1, p2 in lines:
vertex_writer.addData3f(p1)
vertex_writer.addData3f(p2)
color_writer.addData4f(color)
color_writer.addData4f(color)
index_buffer.addVertex(index)
index_buffer.addVertex(index+1)
index = index+2
index_buffer.closePrimitive()
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()
node.reparentTo(render)
# ==
# firt I create a circle in the midle of the screen
# ==
add_circle(vertex_buffer, index_buffer, (0,0), 5.)
base.cam.setPos(0,0,1000)
base.cam.lookAt((0,0,0))
# ==
# ==
# 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")
run()
# ==
# once everything is displayed if I move the camera so that the original circle leave the screen, all the circle disapears.
# ==
test()
[/code]