I’m just getting started with Panda3D (and with 3D in general, in fact) and have hit a wall generating a cube Geom. When running my script, nothing at all appears in the render window (blank grey, as if the scene graph were empty) and no errors appear in the console.
I’m using spinCameraTask from the tutorial and the Geom code is based on that section of the manual. I’ve triple-checked that I’m defining the vertices in the correct (counter-clockwise) order, but have tried reversing them as well to no effect. Any ideas what I’m doing wrong? For future reference, how can I best troubleshoot this kind of “no feedback” problem in Panda3D?
import math
from direct.showbase.ShowBase import ShowBase
from direct.task import Task
from panda3d.core import Geom, GeomNode, GeomTristrips, GeomVertexData, GeomVertexFormat, GeomVertexWriter
def cube(coords, color, size=1):
x = coords[0]
y = coords[1]
z = coords[2]
xx = x + size
yy = y + size
zz = z + size
r = color[0]
g = color[1]
b = color[2]
a = color[3]
data = GeomVertexData("cube", GeomVertexFormat.getV3c4(), Geom.UHStatic)
vertices = vertices = GeomVertexWriter(data, "vertex")
colors = vertices = GeomVertexWriter(data, "color")
# bottom, left, top
vertices.addData3f(x, y, z)
vertices.addData3f(x, yy, z)
vertices.addData3f(xx, y, z)
vertices.addData3f(xx, yy, z)
vertices.addData3f(xx, y, zz)
vertices.addData3f(xx, yy, zz)
vertices.addData3f(x, y, zz)
vertices.addData3f(x, yy, zz)
# front, right, back
vertices.addData3f(xx, y, zz)
vertices.addData3f(xx, y, z)
vertices.addData3f(x, y, zz)
vertices.addData3f(x, y, z)
vertices.addData3f(x, yy, zz)
vertices.addData3f(x, yy, z)
vertices.addData3f(xx, yy, zz)
vertices.addData3f(xx, yy, z)
# all vertices are the same color
for i in xrange(16):
colors.addData4f(r, g, b, a)
primitive = GeomTristrips(Geom.UHStatic)
primitive.addNextVertices(8)
primitive.closePrimitive()
primitive.addNextVertices(8)
primitive.closePrimitive()
geometry = Geom(data)
geometry.addPrimitive(primitive)
node = GeomNode("cube")
node.addGeom(geometry)
return node
class CubeDemo(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.setFrameRateMeter(True)
self.render.attachNewNode(cube((0, 0, 0), (.5, 1, 1, 1)))
self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")
def spinCameraTask(self, task):
angleDegrees = task.time * 6
angleRadians = angleDegrees * math.pi / 180
self.camera.setPos(20 * math.sin(angleRadians), -20 * math.cos(angleRadians), 3)
self.camera.setHpr(angleDegrees, 0, 0)
return Task.cont
cubedemo = CubeDemo()
cubedemo.run()