本文整理汇总了Python中panda3d.core.GeomTriangles.modifyVertices方法的典型用法代码示例。如果您正苦于以下问题:Python GeomTriangles.modifyVertices方法的具体用法?Python GeomTriangles.modifyVertices怎么用?Python GeomTriangles.modifyVertices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.GeomTriangles
的用法示例。
在下文中一共展示了GeomTriangles.modifyVertices方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MeshGenerator
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import modifyVertices [as 别名]
class MeshGenerator():
def __init__(self, name = 'Mesh'):
self.name = name
self.finished = False
self.format = GeomVertexFormat.getV3c4t2()
#print self.format
self.vertexData = GeomVertexData(name, self.format, Geom.UHStatic)
self.vertexData.setNumRows(26136)
self.mesh = Geom(self.vertexData)
self.triangles = GeomTriangles(Geom.UHStatic)
self.triangleData = self.triangles.modifyVertices()
self.triangleData.setNumRows(26136)
self.vertex = GeomVertexWriter(self.vertexData, 'vertex')
self.normal = GeomVertexWriter(self.vertexData, 'normal')
self.color = GeomVertexWriter(self.vertexData, 'color')
self.texcoord = GeomVertexWriter(self.vertexData, 'texcoord')
self.faceCount = 0
def makeFace(self, x1, y1, z1, x2, y2, z2, id, color):
if x1 != x2:
self.vertex.addData3f(x1, y1, z1)
self.vertex.addData3f(x2, y1, z1)
self.vertex.addData3f(x2, y2, z2)
self.vertex.addData3f(x1, y2, z2)
else:
self.vertex.addData3f(x1, y1, z1)
self.vertex.addData3f(x2, y2, z1)
self.vertex.addData3f(x2, y2, z2)
self.vertex.addData3f(x1, y1, z2)
self.color.addData4f(color, color, color, 1.0)
self.color.addData4f(color, color, color, 1.0)
self.color.addData4f(color, color, color, 1.0)
self.color.addData4f(color, color, color, 1.0)
if id == 1:
self.texcoord.addData2f(0.0, 0.5)
self.texcoord.addData2f(0.0, 0.0)
self.texcoord.addData2f(0.25, 0.0)
self.texcoord.addData2f(0.25, 0.5)
elif id == 2:
self.texcoord.addData2f(0.25, 0.5)
self.texcoord.addData2f(0.25, 0.0)
self.texcoord.addData2f(0.5, 0.0)
self.texcoord.addData2f(0.5, 0.5)
elif id == 3:
self.texcoord.addData2f(0.5, 0.5)
self.texcoord.addData2f(0.5, 0.0)
self.texcoord.addData2f(0.75, 0.0)
self.texcoord.addData2f(0.75, 0.5)
elif id == 4:
self.texcoord.addData2f(0.75, 0.5)
self.texcoord.addData2f(0.75, 0.0)
self.texcoord.addData2f(1.0, 0.0)
self.texcoord.addData2f(1.0, 0.5)
elif id == 5:
self.texcoord.addData2f(0.0, 1.0)
self.texcoord.addData2f(0.0, 0.5)
self.texcoord.addData2f(0.25, 0.5)
self.texcoord.addData2f(0.25, 1.0)
elif id == 6:
self.texcoord.addData2f(0.25, 1.0)
self.texcoord.addData2f(0.25, 0.5)
self.texcoord.addData2f(0.5, 0.5)
self.texcoord.addData2f(0.5, 1.0)
vertexId = self.faceCount * 4
self.triangles.addVertices(vertexId, vertexId + 1, vertexId + 3)
self.triangles.addVertices(vertexId + 1, vertexId + 2, vertexId + 3)
self.faceCount += 1
def makeFrontFace(self, x, y, z, id):
self.makeFace(x + 1, y + 1, z - 1, x, y + 1, z, id, 0.6)
def makeBackFace(self, x, y, z, id):
self.makeFace(x, y, z - 1, x + 1, y, z, id, 0.85)
def makeRightFace(self, x, y, z, id):
self.makeFace(x + 1, y, z - 1, x + 1, y + 1, z, id, 1.0)
def makeLeftFace(self, x, y, z, id):
self.makeFace(x, y + 1, z - 1, x, y, z, id, 0.9)
def makeTopFace(self, x, y, z, id):
self.makeFace(x + 1, y + 1, z, x, y, z, id, 1.0)
def makeBottomFace(self, x, y, z, id):
#.........这里部分代码省略.........
示例2: MeshGenerator
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import modifyVertices [as 别名]
class MeshGenerator(object):
'''
Generates a cube mesh
'''
def __init__(self, name = 'Mesh'):
'''
Constructor
'''
self.name = name
self.finished = False
self.format = GeomVertexFormat.getV3n3c4()
self.vertexData = GeomVertexData(name, self.format, Geom.UHStream)
self.mesh = Geom(self.vertexData)
self.triangles = GeomTriangles(Geom.UHStream)
self.triangleData = self.triangles.modifyVertices()
self.vertex = GeomVertexWriter(self.vertexData, 'vertex')
self.normal = GeomVertexWriter(self.vertexData, 'normal')
self.color = GeomVertexWriter(self.vertexData, 'color')
#self.texcoord = GeomVertexWriter(self.vertexData, 'texcoord')
self.faceCount = 0
def makeFace(self, x1, y1, z1, x2, y2, z2, color):
if x1 != x2:
self.vertex.addData3f(x1, y1, z1)
self.vertex.addData3f(x2, y1, z1)
self.vertex.addData3f(x2, y2, z2)
self.vertex.addData3f(x1, y2, z2)
vector1 = Vec3(x1, y1, z1)
vector2 = Vec3(x2, y1, z1)
vector3 = Vec3(x2, y2, z2)
normalVector1 = vector3-vector1
normalVector2 = vector2-vector1
normalVector2.cross(normalVector1)
self.normal.addData3f(CalcSufaceNormal(normalVector2))
self.normal.addData3f(CalcSufaceNormal(normalVector2))
self.normal.addData3f(CalcSufaceNormal(normalVector2))
self.normal.addData3f(CalcSufaceNormal(normalVector2))
else:
self.vertex.addData3f(x1, y1, z1)
self.vertex.addData3f(x2, y2, z1)
self.vertex.addData3f(x2, y2, z2)
self.vertex.addData3f(x1, y1, z2)
vector1 = Vec3(x1, y1, z1)
vector2 = Vec3(x2, y2, z1)
vector3 = Vec3(x2, y2, z2)
normalVector1 = vector3-vector1
normalVector2 = vector2-vector1
normalVector2.cross(normalVector1)
self.normal.addData3f(CalcSufaceNormal(normalVector2))
self.normal.addData3f(CalcSufaceNormal(normalVector2))
self.normal.addData3f(CalcSufaceNormal(normalVector2))
self.normal.addData3f(CalcSufaceNormal(normalVector2))
RGBAVal = convertToRGBA(color[0], color[1], color[2], color[3])
self.color.addData4f(RGBAVal[0], RGBAVal[1], RGBAVal[2], RGBAVal[3])
self.color.addData4f(RGBAVal[0], RGBAVal[1], RGBAVal[2], RGBAVal[3])
self.color.addData4f(RGBAVal[0], RGBAVal[1], RGBAVal[2], RGBAVal[3])
self.color.addData4f(RGBAVal[0], RGBAVal[1], RGBAVal[2], RGBAVal[3])
vertexId = self.faceCount * 4
self.triangles.addVertices(vertexId, vertexId + 1, vertexId + 3)
self.triangles.addVertices(vertexId + 1, vertexId + 2, vertexId + 3)
self.faceCount += 1
def makeFrontFace(self, x, y, z, color):
self.makeFace(x + 1, y + 1, z - 1, x, y + 1, z, color)
def makeBackFace(self, x, y, z, color):
self.makeFace(x, y, z - 1, x + 1, y, z, color)
def makeRightFace(self, x, y, z, color):
self.makeFace(x + 1, y, z - 1, x + 1, y + 1, z, color)
def makeLeftFace(self, x, y, z, color):
self.makeFace(x, y + 1, z - 1, x, y, z, color)
def makeTopFace(self, x, y, z, color):
self.makeFace(x + 1, y + 1, z, x, y, z, color)
def makeBottomFace(self, x, y, z, color):
self.makeFace(x, y + 1, z - 1, x + 1, y, z - 1, color)
#.........这里部分代码省略.........