本文整理汇总了Python中panda3d.core.GeomVertexWriter.addData1f方法的典型用法代码示例。如果您正苦于以下问题:Python GeomVertexWriter.addData1f方法的具体用法?Python GeomVertexWriter.addData1f怎么用?Python GeomVertexWriter.addData1f使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.GeomVertexWriter
的用法示例。
在下文中一共展示了GeomVertexWriter.addData1f方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Mesh
# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData1f [as 别名]
class Mesh():
def __init__(self, name):
self.name = name
self.poly_groups = []
# GeomVertexFormats
#
# GeomVertexFormat.getV3cpt2() - vertex, color, uv
# GeomVertexFormat.getV3t2() - vertex, uv
# GeomVertexFormat.getV3cp() - vertex, color
# GeomVertexFormat.getV3n3t2() - vertex, normal, uv
# GeomVertexFormat.getV3n3cpt2()- vertex, normal, rgba, uv
# textured
self.vdata = GeomVertexData(name, GeomVertexFormat.getV3n3cpt2(), Geom.UHStatic)
# plain color filled polys
# self.vdata = GeomVertexData(name, GeomVertexFormat.getV3cp(), Geom.UHStatic)
self.vertex = GeomVertexWriter(self.vdata, 'vertex')
self.vnormal = GeomVertexWriter(self.vdata, 'normal')
self.color = GeomVertexWriter(self.vdata, 'color')
self.texcoord = GeomVertexWriter(self.vdata, 'texcoord')
self.root = NodePath(PandaNode(name+'_mesh'))
# f is a 0x36 mesh fragment (see fragment.py for reference)
def buildFromFragment(self, f, wld_container,debug=False):
# write vertex coordinates
for v in f.vertexList:
self.vertex.addData3f(v[0], v[1], v[2])
# write vertex colors
for rgba in f.vertexColorsList:
'''
r = (rgba & 0xff000000) >> 24
g = (rgba & 0x00ff0000) >> 16
b = (rgba & 0x0000ff00) >> 8
a = (rgba & 0x000000ff)
if a != 0:
print 'vertex color has alpha component, r:0x%x g:0x%x b:0x%x a:0x%x ' % (r, g, b, a)
'''
self.color.addData1f(rgba)
# write vertex normals
for v in f.vertexNormalsList:
self.vnormal.addData3f(v[0], v[1], v[2])
# write texture uv
for uv in f.uvList:
self.texcoord.addData2f(uv[0], uv[1])
# Build PolyGroups
# each polyTexList is a tuple containing a polygon count and the texture index for those polys
# we create a PolyGroup for each of these
# the PolyGroup creates all Polygons sharing a texture and adds them under a NodePath
poly_idx = 0
for pt in f.polyTexList:
n_polys = pt[0]
tex_idx = pt[1]
if debug:
print(" Bulding a poly group with tex_id " + str(tex_idx))
pg = PolyGroup(self.vdata, tex_idx)
# pass fragment so that it can access the SPRITES
if pg.build(wld_container, f, poly_idx, n_polys, tex_idx, debug) == 1:
self.poly_groups.append(pg)
pg.nodePath.reparentTo(self.root)
poly_idx += n_polys
if poly_idx != f.polyCount or poly_idx != len(f.polyList):
print 'ERROR: polycount mismatch'