panda3d有8个点表示长方体的8个顶点所组成的列表box_points = Point3-1 -1 -1 Point3-1 -1 1 Point3-1 1 -1 Point3-1 1 1 Point31 -1 -1 Point31 -1 1 Point31 1 -1 Point31 1 1panda3d画出这个长方体
可以使用以下代码来画出这个长方体:
from direct.showbase.ShowBase import ShowBase from panda3d.core import Point3 from panda3d.core import LineSegs
class MyApp(ShowBase): def init(self): ShowBase.init(self) self.box_points = [ Point3(-1, -1, -1), Point3(-1, -1, 1), Point3(-1, 1, -1), Point3(-1, 1, 1), Point3(1, -1, -1), Point3(1, -1, 1), Point3(1, 1, -1), Point3(1, 1, 1) ] self.draw_box()
def draw_box(self):
lines = LineSegs()
lines.set_color(1, 1, 1, 1)
# draw bottom face
lines.move_to(self.box_points[0])
lines.draw_to(self.box_points[1])
lines.draw_to(self.box_points[3])
lines.draw_to(self.box_points[2])
lines.draw_to(self.box_points[0])
# draw top face
lines.move_to(self.box_points[4])
lines.draw_to(self.box_points[5])
lines.draw_to(self.box_points[7])
lines.draw_to(self.box_points[6])
lines.draw_to(self.box_points[4])
# draw vertical edges
lines.move_to(self.box_points[0])
lines.draw_to(self.box_points[4])
lines.move_to(self.box_points[1])
lines.draw_to(self.box_points[5])
lines.move_to(self.box_points[2])
lines.draw_to(self.box_points[6])
lines.move_to(self.box_points[3])
lines.draw_to(self.box_points[7])
# render lines
node = lines.create()
self.render.attach_new_node(node)
app = MyApp() app.run(
原文地址: https://www.cveoy.top/t/topic/fI2q 著作权归作者所有。请勿转载和采集!