Hi,
I found what I think is a bug when adding a model and a LineSegs to a nodepath and using clearModelNodes and flattenStrong, both. If you do not use both or use just one of them, the result is good.
Here is the code to reproduce it:
from direct.showbase.ShowBase import ShowBase,LineSegs, PandaNode
from math import pi, sin, cos
class MyApp(ShowBase):
def __init__(self):
# Open Panda3D
ShowBase.__init__(self)
nodepath = self.render.attachNewNode("Nodepath")
# camera model
model = self.loader.loadModel("cone.bam")
model.setScale(0.2, 0.2, 0.2)
model.setColor(0,0,0,1)
model.reparentTo(nodepath)
# Create Segs
segs = LineSegs()
segs.setThickness(3.0)
segs.setColor(0.0,0.0,0.0,1.0)
fov = 40
fovr = fov * (pi / 180.0)
ratio = 1.2
xmin = 1
xmax = 2
ymin = cos(fovr) * xmin * ratio
ymax = cos(fovr) * xmax * ratio
zmin = cos(fovr) * xmin
zmax = cos(fovr) * xmax
# Lens min plane
segs.moveTo(xmin, ymin, -zmin)
segs.drawTo(xmin, ymin, zmin)
segs.drawTo(xmax, ymax, zmax)
segs.moveTo(xmin, ymin, zmin)
segs.drawTo(xmin, -ymin, zmin)
segs.drawTo(xmax, -ymax, zmax)
segs.moveTo(xmin, -ymin, zmin)
segs.drawTo(xmin, -ymin, -zmin)
segs.drawTo(xmax, -ymax, -zmax)
segs.moveTo(xmin, -ymin, -zmin)
segs.drawTo(xmin, ymin, -zmin)
segs.drawTo(xmax, ymax, -zmax)
# Lens max plane
segs.moveTo(xmax, ymax, zmax)
segs.drawTo(xmax, -ymax, zmax)
segs.drawTo(xmax, -ymax, -zmax)
segs.drawTo(xmax, ymax, -zmax)
segs.drawTo(xmax, ymax, zmax)
# Create segs
gridnode = nodepath.attachNewNode(PandaNode("Lens"))
gridnode.attachNewNode(segs.create())
# Flatten Node
nodepath.clearModelNodes()
nodepath.flattenStrong()
# Add the spinCameraTask procedure to the task manager.
self.setFrameRateMeter(True)
self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")
# Define a procedure to move the camera.
def spinCameraTask(self, task):
angleDegrees = task.time * 6.0
angleRadians = angleDegrees * (pi / 180.0)
self.camera.setPos(10 * sin(angleRadians), -10.0 * cos(angleRadians), 1)
self.camera.setHpr(angleDegrees, 0, 0)
return task.cont
if __name__ == '__main__':
App = MyApp()
App.run()