Uhm, it’s a special kind of ModelNode that is added at the top of every model loaded with loader.loadModel. By default, it tells the scene graph reducer not to flatten this node. If you want to merge multiple models together into one, you first need to tell Panda to clear the model nodes, or configure them to allow flattening.
This is offtopic, but if I procedurally generate an Actor with multiple geoms, I should create a parent node for them named “ModelRoot” so they wont get flattened?
for batch in self.batches:
for ch in batch.getChildren():
ch.find('**/ModelRoot').removeNode()
batch.flattenStrong()
Assertion failed: _error_type != ET_not_found at line 914 of panda/src/pgraph/no
dePath.cxx
Traceback (most recent call last):
File "main.py", line 18, in <module>
trees = Trees()
File "C:\Users\Me\Desktop\pandajungle\trees.py", line 87, in __init__
ch.find('**/ModelRoot').removeNode()
AssertionError: _error_type != ET_not_found at line 914 of panda/src/pgraph/node
Path.cxx
Press any key to continue . . .
You should notice the small tree in the middle of the screen though. The thing is, it stays small and not prespective untill you rotate the camera around it for some time. Bug?
from direct.directbase.DirectStart import *
from pandac.PandaModules import *
# render the tree in another buffer and use it as a texture for the point sprites
spritebuffer = base.win.makeTextureBuffer("sprite buffer", 512, 512)
spriterender = NodePath("sprite render")
spritecam = base.makeCamera(spritebuffer)
spritecam.reparentTo(spriterender)
spritecam.setPos(0, -12, 0)
tree = loader.loadModel('media/trees2/fir06_30.mesh.xml.egg')
tree.reparentTo(spriterender)
tree.setScale(0.02)
tree.setR(180)
# make a point sprite nodepath and assign the above texture to it
array = GeomVertexArrayFormat()
array.addColumn(InternalName.make('vertex'), 3, Geom.NTFloat32, Geom.CPoint)
format = GeomVertexFormat()
format.addArray(array)
format = GeomVertexFormat.registerFormat(format)
vertexdata = GeomVertexData('sprite', format, Geom.UHStatic)
vertexwriter = GeomVertexWriter(vertexdata, 'vertex')
vertexwriter.addData3f(0,0,0)
prim = GeomPoints(Geom.UHStatic)
prim.addVertex(0)
prim.closePrimitive()
geom = Geom(vertexdata)
geom.addPrimitive(prim)
node = GeomNode('gnode')
node.addGeom(geom)
sprite = render.attachNewNode(node)
sprite.setTransparency(TransparencyAttrib.MDual)
sprite.setY(12)
sprite.setTexGen(TextureStage.getDefault(), TexGenAttrib.MPointSprite)
sprite.setTexture(spritebuffer.getTexture())
sprite.setRenderModeThickness(128)
sprite.setRenderModePerspective(True)
# environment
env = loader.loadModel('environment')
env.reparentTo(render)
env.setScale(50)
env.setZ(-20)
env.setColor(0.7,0.2,0.2,1)
run()
There are occasionally driver bugs with perspective sprites. If you’re seeing a driver bug, you have to set:
hardware-point-sprites 0
but then you’re more limited in the number of sprites you can have before your performance degrades. But if this solves your rendering problem, it proves you have a driver bug and not a Panda bug.
Honestly, I’ve long since given up on asking “why” a driver bug behaves in a particular way. I’ve seen everything, and only about half of it makes sense.
If you are seeing a driver bug, and it happens in some cases and not in others, I really can’t tell you why. But you’re more than welcome to research it further and see if you can determine what the difference is.
By my knowledge sprite particles work the same way, so i thought theres a small possibilty that panda itself doesnt do everything ‘right’ (maybe theres a workaround code for such bug in the particles sourcecode).
Pshaw. You just successfully constructed an animated character based on little to no documentation and a handful of sample code. You can’t tell me that C++ is beyond you.
But even still, there might be no reason you need to delve into C++ to research this. The particle system doesn’t do anything other than create GeomPoints with the RenderModeAttrib set on them. If the particle system is rendering correctly, but your own points aren’t, then either something is different with the scene graph between these two cases, or the difference has nothing to do with Panda.
Well I asked tons of questions and I still dont have everything working correctly in that thread, and C++ isnt something you can learn in a weekend, so…
I can just make this assumption: the main difference is that particles are a single geom, but in another thread i also had everything as a single geom, so the only difference would be that the vertices in the particle system’s geom are “dynamic”. Ive already mentioned that the perspective mode is applied only after you view the sprite from different positions (move your camera around it). It is possible that as particle points are moving, they are rendered from different camera distances right after they are created, so we dont have time to notice how the perspective mode is applied a bit late.
Thats the only thing I can think of.
OK, since it seems like a driver bug, I moved along.
So how to make a sprite ,how to texture it properly and how to set the size properly?
From the above code I make a single sprite, then I use tree.copyTo(parent) to make corresponding sprites. It seems to work, but how would you measure the distance of the camera from the tree in the tree buffer? I would need to fit the tree model perfectly on the buffer texture. I could use the tree’s bounding box, but I dont know how exactly.
I then would need to scale the sprite to be the same size as the tree model. How? The size of a point sprite is set with setRenderModeThickness(), how does that relate with panda units used in 3d geometry?