本文整理汇总了Python中panda3d.core.GeomVertexWriter.addData3方法的典型用法代码示例。如果您正苦于以下问题:Python GeomVertexWriter.addData3方法的具体用法?Python GeomVertexWriter.addData3怎么用?Python GeomVertexWriter.addData3使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.GeomVertexWriter
的用法示例。
在下文中一共展示了GeomVertexWriter.addData3方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makeSquare
# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData3 [as 别名]
def makeSquare(x1, y1, z1, x2, y2, z2):
format = GeomVertexFormat.getV3n3cpt2()
vdata = GeomVertexData('square', format, Geom.UHDynamic)
vertex = GeomVertexWriter(vdata, 'vertex')
normal = GeomVertexWriter(vdata, 'normal')
# color = GeomVertexWriter(vdata, 'color')
texcoord = GeomVertexWriter(vdata, 'texcoord')
# make sure we draw the sqaure in the right plane
if x1 != x2:
vertex.addData3(x1, y1, z1)
vertex.addData3(x2, y1, z1)
vertex.addData3(x2, y2, z2)
vertex.addData3(x1, y2, z2)
normal.addData3(normalized(2 * x1 - 1, 2 * y1 - 1, 2 * z1 - 1))
normal.addData3(normalized(2 * x2 - 1, 2 * y1 - 1, 2 * z1 - 1))
normal.addData3(normalized(2 * x2 - 1, 2 * y2 - 1, 2 * z2 - 1))
normal.addData3(normalized(2 * x1 - 1, 2 * y2 - 1, 2 * z2 - 1))
else:
vertex.addData3(x1, y1, z1)
vertex.addData3(x2, y2, z1)
vertex.addData3(x2, y2, z2)
vertex.addData3(x1, y1, z2)
normal.addData3(normalized(2 * x1 - 1, 2 * y1 - 1, 2 * z1 - 1))
normal.addData3(normalized(2 * x2 - 1, 2 * y2 - 1, 2 * z1 - 1))
normal.addData3(normalized(2 * x2 - 1, 2 * y2 - 1, 2 * z2 - 1))
normal.addData3(normalized(2 * x1 - 1, 2 * y1 - 1, 2 * z2 - 1))
# adding different colors to the vertex for visibility
# color.addData4f(1.0, 0.0, 0.0, 1.0)
# color.addData4f(0.0, 1.0, 0.0, 1.0)
# color.addData4f(0.0, 0.0, 1.0, 1.0)
# color.addData4f(1.0, 0.0, 1.0, 1.0)
texcoord.addData2f(0.0, 1.0)
texcoord.addData2f(0.0, 0.0)
texcoord.addData2f(1.0, 0.0)
texcoord.addData2f(1.0, 1.0)
# Quads aren't directly supported by the Geom interface
# you might be interested in the CardMaker class if you are
# interested in rectangle though
tris = GeomTriangles(Geom.UHDynamic)
tris.addVertices(0, 1, 3)
tris.addVertices(1, 2, 3)
square = Geom(vdata)
square.addPrimitive(tris)
return square
示例2: make_square
# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData3 [as 别名]
def make_square(sq_color):
# sq_color is a list of tuples, describing each vertex:
# (r, g, b, a) for [bl, br, tr, tl]
x1 = -1
y1 = -1
z1 = -1
x2 = 1
y2 = -1
z2 = 1
v_format = GeomVertexFormat.getV3n3cpt2()
v_data = GeomVertexData('square', v_format, Geom.UHDynamic)
vertex = GeomVertexWriter(v_data, 'vertex')
normal = GeomVertexWriter(v_data, 'normal')
color = GeomVertexWriter(v_data, 'color')
tex_coord = GeomVertexWriter(v_data, 'texcoord')
# make sure we draw the sqaure in the right plane
if x1 != x2:
vertex.addData3(x1, y1, z1)
vertex.addData3(x2, y1, z1)
vertex.addData3(x2, y2, z2)
vertex.addData3(x1, y2, z2)
normal.addData3(normalized(2 * x1 - 1, 2 * y1 - 1, 2 * z1 - 1))
normal.addData3(normalized(2 * x2 - 1, 2 * y1 - 1, 2 * z1 - 1))
normal.addData3(normalized(2 * x2 - 1, 2 * y2 - 1, 2 * z2 - 1))
normal.addData3(normalized(2 * x1 - 1, 2 * y2 - 1, 2 * z2 - 1))
else:
vertex.addData3(x1, y1, z1)
vertex.addData3(x2, y2, z1)
vertex.addData3(x2, y2, z2)
vertex.addData3(x1, y1, z2)
normal.addData3(normalized(2 * x1 - 1, 2 * y1 - 1, 2 * z1 - 1))
normal.addData3(normalized(2 * x2 - 1, 2 * y2 - 1, 2 * z1 - 1))
normal.addData3(normalized(2 * x2 - 1, 2 * y2 - 1, 2 * z2 - 1))
normal.addData3(normalized(2 * x1 - 1, 2 * y1 - 1, 2 * z2 - 1))
# adding different colors to the vertex for visibility
# color.addData4f(1.0, 0.0, 0.0, 1.0)
# color.addData4f(0.0, 1.0, 0.0, 1.0)
# color.addData4f(0.0, 0.0, 1.0, 1.0)
# color.addData4f(1.0, 0.0, 1.0, 1.0)
color.addData4f(sq_color[0]) # (0, 0) bottom left
color.addData4f(sq_color[1]) # (0.5, 0) bottom right
color.addData4f(sq_color[2]) # (0.5, 0.5) top right
color.addData4f(sq_color[3]) # (0, 0.5) top left
tex_coord.addData2f(0.0, 1.0)
tex_coord.addData2f(0.0, 0.0)
tex_coord.addData2f(1.0, 0.0)
tex_coord.addData2f(1.0, 1.0)
# Quads aren't directly supported by the Geom interface
# you might be interested in the CardMaker class if you are
# interested in rectangle though
tris = GeomTriangles(Geom.UHDynamic)
tris.addVertices(0, 1, 3)
tris.addVertices(1, 2, 3)
square = Geom(v_data)
square.addPrimitive(tris)
return square