How to get node visible when adding points and geoms later.

Hello,
I’m in a situation where I add an empty GeomNode to the ‘render-tree’ with addChild.
When I add points and geoms afterwards, it is not shown.

When I add just 3 points and 1 geom before I add it to the ‘render-tree’. And then add points afterwards, it works fine.

I’d prefer to have the situation where I add points and geoms later. Are there some steps I can do to get that working properly?

Hope I was clear enough in my questioning.

Additional information:
I’m using Panda3d V1.7.0

Sequences of imports and calls:

from direct.showbase.ShowBase import ShowBase
from direct.showbase.DirectObject import DirectObject

pNode=GeomNode(‘Geom’)
format=GeomVertexFormat.getV3n3cpt2()
vdata=GeomVertexData(‘form’, self.format, Geom.UHDynamic)
geom=Geom(self.vdata)
pNode.addGeom(self.geom)
vertex=GeomVertexRewriter(self.vdata, ‘vertex’)
normal=GeomVertexRewriter(self.vdata, ‘normal’)
color=GeomVertexRewriter(self.vdata, ‘color’)
texcoord=GeomVertexRewriter(self.vdata, ‘texcoord’)
nPath=NodePath(self.pNode)

optionally load texture

nPath.reparentTo(render)

create an instance of “class MyTapper(DirectObject)”

then add several vertex

self.vertex.addData3f(vec)
self.normal.addData3f(vecn)
self.color.addData4f(1.0,1.0,1.0,1.0)
self.texcoord.addData2f(tc[0],tc[1])

then add some geoms

prim = GeomTriangles(Geom.UHDynamic)
prim.addVertex(idx[i]) x 3
prim.closePrimitive()
geom.addPrimitive(prim)

When there is just 1 geom (with needed points) already there before the “reparentTo()”, then it works.
It should work without too shouldn’t it?

Greetings,
J.E.H.

The problem is that you have to get a fresh Geom object, instead of holding onto the one you created before. Once you add a Geom into the tree, Panda is free to duplicate is as necessary, making your future changes to the one you are holding onto irrelevant. Also, Panda relies on the modifyGeom() call to tell it to invalidate its internal caches.

So use:

geom = pNode.modifyGeom(0)
vdata = geom.modifyVertexData()
vertex=GeomVertexRewriter(vdata, 'vertex')
normal=GeomVertexRewriter(vdata, 'normal')
color=GeomVertexRewriter(vdata, 'color')
texcoord=GeomVertexRewriter(vdata, 'texcoord') 

to get a modifiable pointer to your Geom from the scene graph. And again, you shouldn’t keep these things around across frames. If you decide to modify the Geom again in a future frame, get a fresh Geom again.

David

Ahhhh,
thank you for explaining that bit.
Have modified the code, and it’s working fine now :slight_smile:

Thanks,
J.E.H.