-
Notifications
You must be signed in to change notification settings - Fork 2
/
CreepyDuckDevExample.py
74 lines (59 loc) · 2.6 KB
/
CreepyDuckDevExample.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/python
from direct.showbase.ShowBase import ShowBase
from panda3d.core import Geom, GeomNode, GeomVertexData, GeomTriangles, GeomPoints, GeomVertexFormat, GeomVertexRewriter
from panda3d.core import Vec3, Vec4
from utilities.pandaHelperFuncs import PanditorEnableMouseFunc, PanditorDisableMouseFunc
class DevTest(ShowBase):
def __init__(self):
ShowBase.__init__(self)
PanditorDisableMouseFunc()
camera.setPos(0.0, 0.0, 50.0)
camera.lookAt(0.0)
PanditorEnableMouseFunc()
# 1) create GeomVertexData
frmt = GeomVertexFormat.getV3n3cp()
vdata = GeomVertexData('triangle', frmt, Geom.UHDynamic)
# 2) create Writers/Rewriters (must all be created before any readers and readers are one-pass-temporary)
vertex = GeomVertexRewriter(vdata, 'vertex')
normal = GeomVertexRewriter(vdata, 'normal')
color = GeomVertexRewriter(vdata, 'color')
zUp = Vec3(0, 0, 1)
wt = Vec4(1.0, 1.0, 1.0, 1.0)
gr = Vec4(0.5, 0.5, 0.5, 1.0)
# 3) write each column on the vertex data object (for speed, have a different writer for each column)
def addPoint(x, y, z):
vertex.addData3f(x, y, z)
normal.addData3f(zUp)
color.addData4f(wt)
addPoint(0.0, 0.0, 0.0)
addPoint(5.0, 0.0, 0.0)
addPoint(0.0, 5.0, 0.0)
addPoint(5.0, 5.0, 0.0)
# 4) create a primitive and add the vertices via index (not truely associated with the actual vertex table, yet)
tris = GeomTriangles(Geom.UHDynamic)
tris.addVertices(0, 1, 2)
tris.closePrimitive() # exception thrown if verts added != 3, other types inform Panda how many verts/primitive
tris.addVertices(2, 1, 3)
print "vdataPoints", vdata.getArrays()[0]
# 5.1) (adding to scene) create a Geom and add primitives of like base-type i.e. triangles and triangle strips
geom = Geom(vdata)
geom.addPrimitive(tris)
# 5.2) create a GeomNode to hold the Geom(s) and add the Geom(s)
gn = GeomNode('gnode')
gn.addGeom(geom)
# 5.3) attache the node to the scene
gnNodePath = render.attachNewNode(gn)
geomPts = Geom(vdata)
pts = GeomPoints(Geom.UHStatic)
pts.addVertices(0, 1, 2)
pts.closePrimitive()
geomPts.addPrimitive(pts)
pointsNode = GeomNode('points_node')
pointsNode.addGeom(geomPts)
pointsNP = render.attachNewNode(pointsNode)
pointsNP.setZ(0.5)
render.ls()
if __name__ == '__main__':
print "Yep main"
app = DevTest()
app.run()