panda3d画出vertices = Point3-1 -1 0 Point31 -1 0 Point31 1 0 Point3-1 1 0 Point3-1 -1 1 Point31 -1 1 Point31 1 1 Point3-1 1 1以这8个点所组成的立体图形
代码如下:
from direct.showbase.ShowBase import ShowBase from panda3d.core import Point3 from panda3d.core import GeomVertexFormat, GeomVertexData, GeomVertexWriter from panda3d.core import GeomTriangles, Geom, GeomNode
class MyDemo(ShowBase): def init(self): ShowBase.init(self)
# Set up vertices
vertices = [
Point3(-1, -1, 0),
Point3(1, -1, 0),
Point3(1, 1, 0),
Point3(-1, 1, 0),
Point3(-1, -1, 1),
Point3(1, -1, 1),
Point3(1, 1, 1),
Point3(-1, 1, 1),
]
# Set up vertex format and data
format = GeomVertexFormat.getV3()
vdata = GeomVertexData('vertices', format, Geom.UHStatic)
vertex = GeomVertexWriter(vdata, 'vertex')
for v in vertices:
vertex.addData3f(v)
# Set up indices for triangles
indices = [
0, 1, 2,
2, 3, 0,
4, 5, 6,
6, 7, 4,
0, 4, 7,
7, 3, 0,
1, 5, 6,
6, 2, 1,
0, 4, 5,
5, 1, 0,
3, 7, 6,
6, 2, 3,
]
# Set up triangles
tris = GeomTriangles(Geom.UHStatic)
for i in range(0, len(indices), 3):
tris.addVertices(indices[i], indices[i+1], indices[i+2])
tris.closePrimitive()
# Set up geometry and node
geom = Geom(vdata)
geom.addPrimitive(tris)
node = GeomNode('cube')
node.addGeom(geom)
# Attach node to render
self.render.attachNewNode(node)
demo = MyDemo() demo.run(
原文地址: https://www.cveoy.top/t/topic/g9dL 著作权归作者所有。请勿转载和采集!