本文整理汇总了Python中panda3d.core.GeomTriangles.addVertex方法的典型用法代码示例。如果您正苦于以下问题:Python GeomTriangles.addVertex方法的具体用法?Python GeomTriangles.addVertex怎么用?Python GeomTriangles.addVertex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.GeomTriangles
的用法示例。
在下文中一共展示了GeomTriangles.addVertex方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addVertex [as 别名]
def draw(self):
if self.rendered_mesh != None:
self.reset_draw()
format=GeomVertexFormat.getV3n3cp()
vdata=GeomVertexData('tri', format, Geom.UHDynamic)
vertex=GeomVertexWriter(vdata, 'vertex')
normal=GeomVertexWriter(vdata, 'normal')
color=GeomVertexWriter(vdata, 'color')
v_mapping = {}
i=0
for v in self.verts.values():
vertex.addData3f(v.pos.x,v.pos.y,v.pos.z)
normal.addData3f(v.norm.x, v.norm.y, v.norm.z)
color.addData4f(v.color[0],v.color[1],v.color[2],v.color[3])
v_mapping[v.ID] = i
i += 1
mesh = Geom(vdata)
for f in self.faces.values():
tri = GeomTriangles(Geom.UHDynamic)
tri.addVertex(v_mapping[f.v1.ID])
tri.addVertex(v_mapping[f.v2.ID])
tri.addVertex(v_mapping[f.v3.ID])
tri.closePrimitive()
mesh.addPrimitive(tri)
snode = GeomNode(self.name)
snode.addGeom(mesh)
self.rendered_mesh = render.attachNewNode(snode)
self.rendered_mesh.setTwoSided(True)
示例2: draw_face
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addVertex [as 别名]
def draw_face(self,f,f_color):
#add normal
format = GeomVertexFormat.getV3n3cp()
vdata=GeomVertexData('vert', format, Geom.UHDynamic)
vertex=GeomVertexWriter(vdata, 'vertex')
color=GeomVertexWriter(vdata, 'color')
normal=GeomVertexWriter(vdata, 'normal')
vertex.addData3f(f.v1.pos)
normal.addData3f(f.v1.norm.x, f.v1.norm.y, f.v1.norm.z)
color.addData4f(f_color)
vertex.addData3f(f.v2.pos)
normal.addData3f(f.v2.norm.x, f.v2.norm.y, f.v2.norm.z)
color.addData4f(f_color)
vertex.addData3f(f.v3.pos)
normal.addData3f(f.v3.norm.x, f.v3.norm.y, f.v3.norm.z)
color.addData4f(f_color)
mesh = Geom(vdata)
tri = GeomTriangles(Geom.UHDynamic)
tri.addVertex(0)
tri.addVertex(1)
tri.addVertex(2)
tri.closePrimitive()
mesh.addPrimitive(tri)
face_node = GeomNode(self.mesh.name+'_face_'+str(f.ID))
face_node.addGeom(mesh)
face_node.setTag('ID',str(f.ID))
rendered_face = self.render_root.attachNewNode(face_node)
rendered_face.setTwoSided(True)
self.render_nodes['face_'+str(f.ID)] = rendered_face
示例3: create_mesh
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addVertex [as 别名]
def create_mesh(parentnp, debug=False, invert=False):
"""This creates a simple 17x17 grid mesh for the sides of our cube.
The ultimate goal is to use a LOD system, probably based on quadtrees.
If debug is true then we get a color gradiant on our vertexes."""
x = -1.0
y = -1.0
vertex_count = 0
u = 0.0
v = 0.0
WIDTH_STEP = 2 / 16.0
while y <= 1.0:
while x <= 1.0:
vertex.addData3f(x, y, 0)
if invert:
normal.addData3f(myNormalize((Vec3(2 * x + 1, 2 * y + 1, 2 * 0 - 1))))
else:
normal.addData3f(myNormalize((Vec3(2 * x - 1, 2 * y - 1, 2 * 0 - 1))))
if debug:
color.addData4f(1.0, u, v, 1.0)
texcoord.addData2f(u, v)
vertex_count += 1
x += WIDTH_STEP
u += WIDTH_STEP / 2.0
x = -1.0
u = 0
y += WIDTH_STEP
v += WIDTH_STEP / 2.0
print vertex_count
triangles = []
for y in range(0, 16):
for x in range(0, 16):
v = 17 * y + x
tri = GeomTriangles(Geom.UHDynamic)
tri.addVertex(v)
tri.addVertex(v + 1)
tri.addVertex(v + 17)
tri.closePrimitive()
triangles.append(tri)
tri = GeomTriangles(Geom.UHDynamic)
tri.addVertex(v + 1)
tri.addVertex(v + 18)
tri.addVertex(v + 17)
tri.closePrimitive()
triangles.append(tri)
mesh = Geom(vdata)
for t in triangles:
mesh.addPrimitive(t)
mnode = GeomNode("quadface")
mnode.addGeom(mesh)
nodePath = parentnp.attachNewNode(mnode)
return nodePath
示例4: make_square
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addVertex [as 别名]
def make_square(x1, y1, z1, x2, y2, z2, tex_coord):
format = GeomVertexFormat.getV3n3t2()
vdata = GeomVertexData("square", format, Geom.UHStatic)
vertex = GeomVertexWriter(vdata, "vertex")
normal = GeomVertexWriter(vdata, "normal")
texcoord = GeomVertexWriter(vdata, "texcoord")
# make sure we draw the sqaure in the right plane
if x1 != x2:
vertex.addData3f(x1, y1, z1)
vertex.addData3f(x2, y1, z1)
vertex.addData3f(x2, y2, z2)
vertex.addData3f(x1, y2, z2)
else:
vertex.addData3f(x1, y1, z1)
vertex.addData3f(x2, y2, z1)
vertex.addData3f(x2, y2, z2)
vertex.addData3f(x1, y1, z2)
normal.addData3f(my_normalize(Vec3(2 * x1 - 1, 2 * y1 - 1, 2 * z1 - 1)))
normal.addData3f(my_normalize(Vec3(2 * x2 - 1, 2 * y2 - 1, 2 * z1 - 1)))
normal.addData3f(my_normalize(Vec3(2 * x2 - 1, 2 * y2 - 1, 2 * z2 - 1)))
normal.addData3f(my_normalize(Vec3(2 * x1 - 1, 2 * y1 - 1, 2 * z2 - 1)))
# adding different colors to the vertex for visibility
u1, v1, u2, v2 = tex_coord
texcoord.addData2f(u1, v2)
texcoord.addData2f(u1, v1)
texcoord.addData2f(u2, v1)
texcoord.addData2f(u2, v2)
# quads arent directly supported by the Geom interface
# you might be interested in the CardMaker class if you are
# interested in rectangle though
tri1 = GeomTriangles(Geom.UHStatic)
tri2 = GeomTriangles(Geom.UHStatic)
tri1.addVertex(0)
tri1.addVertex(1)
tri1.addVertex(3)
tri2.addConsecutiveVertices(1, 3)
tri1.closePrimitive()
tri2.closePrimitive()
square = Geom(vdata)
square.addPrimitive(tri1)
square.addPrimitive(tri2)
return square
示例5: createTriangle
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addVertex [as 别名]
def createTriangle(v1, v2, v3, is_flat=False):
x1 = v1.x
y1 = v1.y
z1 = v1.z
x2 = v2.x
y2 = v2.y
z2 = v2.z
x3 = v3.x
y3 = v3.y
z3 = v3.z
format=GeomVertexFormat.getV3n3cp()
vdata=GeomVertexData('tri', format, Geom.UHDynamic)
vertex=GeomVertexWriter(vdata, 'vertex')
normal=GeomVertexWriter(vdata, 'normal')
color=GeomVertexWriter(vdata, 'color')
vertex.addData3f(x1, y1, z1)
vertex.addData3f(x2, y2, z2)
vertex.addData3f(x3, y3, z3)
if is_flat:
normVector = norm(Vec3( (x1 + x2 + x3)/3.0, (y1 + y2 + y3)/3.0, (z1+ z2+ z3)/3.0))
normal.addData3f(normVector)
normal.addData3f(normVector)
normal.addData3f(normVector)
else:
normal.addData3f(norm(Vec3(x1,y1,z1)))
normal.addData3f(norm(Vec3(x2,y2,z2)))
normal.addData3f(norm(Vec3(x3,y3,z3)))
#adding different colors to the vertex for visibility
color.addData4f(0.5,0.5,0.5,1.0)
color.addData4f(0.5,0.5,0.5,1.0)
color.addData4f(0.5,0.5,0.5,1.0)
tri = GeomTriangles(Geom.UHDynamic)
tri.addVertex(0)
tri.addVertex(1)
tri.addVertex(2)
tri.closePrimitive()
output_tri = Geom(vdata)
output_tri.addPrimitive(tri)
return output_tri
示例6: load
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addVertex [as 别名]
def load(self):
if panda3d is None: raise ImportError("Cannot locate Panda3D")
node = GeomNode(self.name)
for n in range(len(self.faces)):
facevertices = self.faces[n]
vertices = [self.vertices[v] for v in facevertices]
normals = None
if self.normals is not None:
normals = (self.normals[n],) * len(facevertices)
colors = None
if self.facecolors is not None:
colors = (self.facecolors[n],) * len(facevertices)
elif self.fvcolors is not None:
colors = self.fvcolors[n]
texcoords = None
if self.texcoords is not None:
texcoords = self.texcoords[n]
#KLUDGE
if self.material is not None and colors is None:
col = self.material.getAmbient()
col = (col[0] / col[3], col[1] / col[3], col[2] / col[3], 1.0)
colors = (col,) * len(vertices)
#/KLUDGE
geom = make_geom(vertices, normals, colors, texcoords)
prim = GeomTriangles(Geom.UHStatic)
#TODO: proper tesselation! the current one only works for convex faces
curr = 1
for v in range(2, len(facevertices)):
prim.addVertex(curr)
prim.addVertex(v)
prim.addVertex(0)
curr = v
prim.closePrimitive()
geom.addPrimitive(prim)
node.addGeom(geom)
self.node = NodePath(node)
self.node.setTwoSided(True)
if self.material is not None:
self.node.setMaterial(self.material, priority=1)
self.loaded = True
示例7: createPlane
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addVertex [as 别名]
def createPlane(width,height):
format=GeomVertexFormat.getV3()
vdata=GeomVertexData("vertices", format, Geom.UHStatic)
vertexWriter=GeomVertexWriter(vdata, "vertex")
vertexWriter.addData3f(0,0,0)
vertexWriter.addData3f(width,0,0)
vertexWriter.addData3f(width,height,0)
vertexWriter.addData3f(0,height,0)
#step 2) make primitives and assign vertices to them
tris=GeomTriangles(Geom.UHStatic)
#have to add vertices one by one since they are not in order
tris.addVertex(0)
tris.addVertex(1)
tris.addVertex(3)
#indicates that we have finished adding vertices for the first triangle.
tris.closePrimitive()
#since the coordinates are in order we can use this convenience function.
tris.addConsecutiveVertices(1,3) #add vertex 1, 2 and 3
tris.closePrimitive()
#step 3) make a Geom object to hold the primitives
squareGeom=Geom(vdata)
squareGeom.addPrimitive(tris)
#now put squareGeom in a GeomNode. You can now position your geometry in the scene graph.
squareGN=GeomNode("square")
squareGN.addGeom(squareGeom)
terrainNode = NodePath("terrNode")
terrainNode.reparentTo(render)
terrainNode.attachNewNode(squareGN)
terrainNode.setX(-width/2)
texGrass = loader.loadTexture("textures/envir-ground.jpg")
terrainNode.setTexture(texGrass)
示例8: createModelClone
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addVertex [as 别名]
def createModelClone(self,modelFilename):
newVisualCar = loader.loadModel(modelFilename)
geomNodeCollection = newVisualCar.findAllMatches('**/+GeomNode')
simpleTris=[]
self.unmodifiedVertexData=[]
for nodePath in geomNodeCollection:
geomNode = nodePath.node()
for i in range(geomNode.getNumGeoms()):
geom = geomNode.getGeom(i)
vdata = geom.getVertexData()
vertex = GeomVertexReader(vdata, 'vertex')
while not vertex.isAtEnd():
v=vertex.getData3f()
vertexModelX,vertexModelY,vertexModelZ=v
self.unmodifiedVertexData.append([vertexModelX,vertexModelY,vertexModelZ])
for primitiveIndex in range(geom.getNumPrimitives()):
prim=geom.getPrimitive(primitiveIndex)
prim=prim.decompose()
for p in range(prim.getNumPrimitives()):
s = prim.getPrimitiveStart(p)
e = prim.getPrimitiveEnd(p)
singleTriData=[]
for i in range(s, e):
vertex.setRow(prim.getVertex(s))
vi = prim.getVertex(i)
singleTriData.append(vi)
simpleTris.append(singleTriData)
simpleVertices=self.unmodifiedVertexData
format=GeomVertexFormat.getV3()
vdata=GeomVertexData('shadow', format, Geom.UHDynamic)
self.pandaVertexData=vdata
vertex=GeomVertexWriter(vdata, 'vertex')
for vertexIndex in range(len(simpleVertices)):
simpleVertex=simpleVertices[vertexIndex]
vertex.addData3f(0,0,0)
tris=GeomTriangles(Geom.UHStatic)
for index in range(len(simpleTris)):
simpleTri=simpleTris[index]
tris.addVertex(simpleTri[0])
tris.addVertex(simpleTri[1])
tris.addVertex(simpleTri[2])
tris.closePrimitive()
shadow=Geom(vdata)
shadow.addPrimitive(tris)
snode=GeomNode('shadow')
snode.addGeom(shadow)
self.snode=snode
示例9: __init__
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addVertex [as 别名]
class Chunk2GeomDecoder:
"""
Chunk decoder that decodes chunks to Panda3D Geoms/Nodes
"""
def __init__(self):
self.textures={}
for k in texMap:
v=texMap[k]
tex=loader.loadTexture("gfx/%s"%v)
tex.setWrapU(Texture.WM_clamp)
tex.setWrapV(Texture.WM_clamp)
self.textures[k]=tex
self.viewPoint=(0,0,0)
self.cubeVtxSrc=[
# 14 vertices per cube mapped
# so that UV coords utilize
# the typical cube unwrap:
#
# #### <-- square texture
# ##U#
# BLFR
# ##D# #=unused
#
# This form uses 14 vertices per cube since
# the extra (worldspace overlapped) vertices
# map different U,V coordinates at the same
# worldspace coordinates, depending on face
#
# x y z u v
(1.00,1.00,1.00,0.00,0.50), # A
(1.00,1.00,0.00,0.00,0.25), # B
(0.00,1.00,1.00,0.25,0.50), # C
(0.00,1.00,0.00,0.25,0.25), # D
(0.00,0.00,1.00,0.50,0.50), # E
(0.00,0.00,0.00,0.50,0.25), # F
(1.00,0.00,1.00,0.75,0.50), # G
(1.00,0.00,0.00,0.75,0.25), # H
(1.00,1.00,1.00,1.00,0.50), # I
(1.00,1.00,0.00,1.00,0.25), # J
(0.00,1.00,1.00,0.50,0.75), # K
(1.00,1.00,1.00,0.75,0.75), # L
(0.00,1.00,0.00,0.50,0.00), # M
(1.00,1.00,0.00,0.75,0.00) # N
]
self.triSrc=[
#
# Faces (QUAD/TRIPAIR)
# using RHR vertex ordering for
# correct face surface normals
#
# front: EFHG/EFH+HGE
# rear: CABD/CAB+BDC
# left: CDFE/CDF+FEC
# right: GHJI/GHJ+JIG
# upper: KEGL/KEG+GLK
# lower: FMNH/FMN+NHF
#
"EFH","HGE",
"CAB","BDC",
"CDF","FEC",
"GHJ","JIG",
"KEG","GLK",
"FMN","NHF"
]
#
# setup cube
#
# one cube node will be generated per non-air block
# since different block id's potentially refer to
# different textures and thus must be separate nodes
# of the scene graph.
#
# 1. vertices
self.cubeVtx=GeomVertexData('blockCube',GeomVertexFormat.getV3t2(),Geom.UHStatic)
self.cubeVtx.setNumRows(len(self.cubeVtxSrc))
vtxW=GeomVertexWriter(self.cubeVtx,'vertex')
txcW=GeomVertexWriter(self.cubeVtx,'texcoord')
for vertex in self.cubeVtxSrc:
vtxW.addData3f(*vertex[0:3])
txcW.addData2f(*vertex[3:5])
# 2. mesh
self.cubeMesh=GeomTriangles(Geom.UHStatic)
for tri in self.triSrc:
for triV in tri:
triVtxId=ord(triV)-65 # changea 'A'-'N' to 0-13
self.cubeMesh.addVertex(triVtxId)
self.cubeMesh.close_primitive()
# 3. geometry (primitive+vertex pair)
self.cubeGeom=Geom(self.cubeVtx)
self.cubeGeom.addPrimitive(self.cubeMesh)
def setViewpoint(x,y,z):
self.viewPoint=(x,y,z)
@decompress
def Chunk2Geom(self,sChunk,origin):
"""
Decodes chunk into Panda3D geometry format
#.........这里部分代码省略.........
示例10: makeTrack
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addVertex [as 别名]
def makeTrack(segments):
format=GeomVertexFormat.getV3t2()
vdata=GeomVertexData('track', format, Geom.UHStatic)
vertex=GeomVertexWriter(vdata, 'vertex')
texcoord=GeomVertexWriter(vdata, 'texcoord')
vdata2=GeomVertexData('startline', format, Geom.UHStatic)
vertex2=GeomVertexWriter(vdata2, 'vertex')
texcoord2=GeomVertexWriter(vdata2, 'texcoord')
numVertices=0
twat=0
for segmentIndex in range(len(segments)):
currentSegment=segments[segmentIndex]
if segmentIndex==0:
nextSegment=segments[segmentIndex+1]
currentStartLineLeftPoint=Geometry.Point.CreateByInterpolation(currentSegment.getMidPoint(),currentSegment.getLeftPoint(),100,77.5);
currentStartLineRightPoint=Geometry.Point.CreateByInterpolation(currentSegment.getMidPoint(),currentSegment.getRightPoint(),100,77.5);
nextStartLineLeftPoint=Geometry.Point.CreateByInterpolation(nextSegment.getMidPoint(),nextSegment.getLeftPoint(),100,77.5);
nextStartLineRightPoint=Geometry.Point.CreateByInterpolation(nextSegment.getMidPoint(),nextSegment.getRightPoint(),100,77.5);
vertex2.addData3f(nextStartLineLeftPoint.getX(),nextStartLineLeftPoint.getY(),0)
vertex2.addData3f(nextStartLineRightPoint.getX(),nextStartLineRightPoint.getY(),0)
vertex2.addData3f(currentStartLineLeftPoint.getX(),currentStartLineLeftPoint.getY(),0)
vertex2.addData3f(currentStartLineRightPoint.getX(),currentStartLineRightPoint.getY(),0)
texcoord2.addData2f(0.0, 0.0)
texcoord2.addData2f(12.0, 0.0)
texcoord2.addData2f(0.0, 2.0)
texcoord2.addData2f(12.0, 2.0)
vertex.addData3f(currentSegment.leftPoint.getX(),currentSegment.leftPoint.getY(),0)
vertex.addData3f(currentSegment.rightPoint.getX(),currentSegment.rightPoint.getY(),0)
texcoord.addData2f(0.0, 1.0/8*float(twat))
texcoord.addData2f(1.0, 1.0/8*float(twat))
#print('vertex at '+str(segmentIndex)+' with v='+str(1.0/8*float(twat)))
numVertices+=2
twat=twat+1
if twat==9:
#print('surplus at '+str(segmentIndex)+' with v=0.0')
vertex.addData3f(currentSegment.leftPoint.getX(),currentSegment.leftPoint.getY(),0)
vertex.addData3f(currentSegment.rightPoint.getX(),currentSegment.rightPoint.getY(),0)
texcoord.addData2f(0.0, 0.0)
texcoord.addData2f(1.0, 0.0)
numVertices+=2
twat=1
#print('vertices created: '+str(numVertices))
tris=GeomTriangles(Geom.UHDynamic)
bob=0
vertexOffset=0
for index in range(len(segments)):
vertexOffsets=[]
for innerIndex in range(4):
offset=vertexOffset+innerIndex
if offset>numVertices-1:
offset=offset-numVertices
vertexOffsets.append(offset)
tris.addVertex(vertexOffsets[0])
tris.addVertex(vertexOffsets[1])
tris.addVertex(vertexOffsets[3])
tris.closePrimitive()
tris.addVertex(vertexOffsets[0])
tris.addVertex(vertexOffsets[3])
tris.addVertex(vertexOffsets[2])
tris.closePrimitive()
vertexOffset+=2
bob+=1
if bob==8:
vertexOffset+=2
bob=0
tris2=GeomTriangles(Geom.UHDynamic)
tris2.addVertex(0)
tris2.addVertex(3)
tris2.addVertex(1)
tris2.closePrimitive()
tris2.addVertex(0)
tris2.addVertex(2)
tris2.addVertex(3)
tris2.closePrimitive()
track=Geom(vdata)
track.addPrimitive(tris)
startLine=Geom(vdata2)
startLine.addPrimitive(tris2)
snode=GeomNode('tarmac')
#.........这里部分代码省略.........
示例11: makeSquare
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addVertex [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.addData3f(x1, y1, z1)
vertex.addData3f(x2, y1, z1)
vertex.addData3f(x2, y2, z2)
vertex.addData3f(x1, y2, z2)
normal.addData3f(myNormalize(Vec3(2*x1-1, 2*y1-1, 2*z1-1)))
normal.addData3f(myNormalize(Vec3(2*x2-1, 2*y1-1, 2*z1-1)))
normal.addData3f(myNormalize(Vec3(2*x2-1, 2*y2-1, 2*z2-1)))
normal.addData3f(myNormalize(Vec3(2*x1-1, 2*y2-1, 2*z2-1)))
else:
vertex.addData3f(x1, y1, z1)
vertex.addData3f(x2, y2, z1)
vertex.addData3f(x2, y2, z2)
vertex.addData3f(x1, y1, z2)
normal.addData3f(myNormalize(Vec3(2*x1-1, 2*y1-1, 2*z1-1)))
normal.addData3f(myNormalize(Vec3(2*x2-1, 2*y2-1, 2*z1-1)))
normal.addData3f(myNormalize(Vec3(2*x2-1, 2*y2-1, 2*z2-1)))
normal.addData3f(myNormalize(Vec3(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 arent directly supported by the Geom interface
#you might be interested in the CardMaker class if you are
#interested in rectangle though
tri1=GeomTriangles(Geom.UHDynamic)
tri2=GeomTriangles(Geom.UHDynamic)
tri1.addVertex(0)
tri1.addVertex(1)
tri1.addVertex(3)
tri2.addConsecutiveVertices(1,3)
tri1.closePrimitive()
tri2.closePrimitive()
square=Geom(vdata)
square.addPrimitive(tri1)
square.addPrimitive(tri2)
return square
示例12: makeMountains
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addVertex [as 别名]
def makeMountains():
format=GeomVertexFormat.getV3t2()
vdata=GeomVertexData('mountains', format, Geom.UHStatic)
vertex=GeomVertexWriter(vdata, 'vertex')
texcoord=GeomVertexWriter(vdata, 'texcoord')
format2=GeomVertexFormat.getV3c4()
vdata2=GeomVertexData('sky', format2, Geom.UHStatic)
vertex2=GeomVertexWriter(vdata2, 'vertex')
color2=GeomVertexWriter(vdata2, 'color')
numQuads=32
angle=0
textureX=0
angleAdd=math.pi*2/numQuads
textureXAdd=1.0/numQuads
currentQuad=0
numVertices=0
while currentQuad<numQuads:
if currentQuad==0:
vertexX=math.sin(angle)*3000
vertexY=math.cos(angle)*3000
vertex.addData3f(vertexX,vertexY,0.0)
vertex.addData3f(vertexX,vertexY,360.0)
texcoord.addData2f(1.0, 0.0)
texcoord.addData2f(1.0, 1.0)
numVertices=numVertices+2
vertexX=math.sin(angle)*3000
vertexY=math.cos(angle)*3000
vertex.addData3f(vertexX,vertexY,0.0)
vertex.addData3f(vertexX,vertexY,360.0)
vertex2.addData3f(vertexX,vertexY,360.0)
color2.addData4f(45.0/255.0,112.0/255.0,255.0/255.0,1.0)
#color2.addData4f(1.0,1.0,1.0,1.0)
#print('created vertex at '+str(vertexX)+','+str(vertexY)+',2')
#print('created vertex at '+str(vertexX)+','+str(vertexY)+',0')
texcoord.addData2f(textureX, 0.0)
texcoord.addData2f(textureX, 1.0)
#print('texturex is '+str(textureX))
#print('creating vertices v'+str(numVertices)+' and v'+str(numVertices+1))
numVertices=numVertices+2
currentQuad=currentQuad+1
textureX=textureX+textureXAdd
angle=angle+angleAdd
vertex2.addData3f(0.0,0.0,360.0)
#color2.addData4f(1.0,1.0,1.0,1.0)
color2.addData4f(45.0/255.0,112.0/255.0,255.0/255.0,1.0)
currentQuad=0
currentOffset=2
tris=GeomTriangles(Geom.UHDynamic)
#print('creating tris - numVertices is '+str(numVertices))
while currentQuad<numQuads:
vertexOffsets=[]
for innerIndex in range(4):
offset=currentOffset+innerIndex
#print('comparing '+str(offset)+' with '+str(numVertices-1))
if offset>numVertices-1:
offset=offset-numVertices
vertexOffsets.append(offset)
#print('adding tri connecting v'+str(vertexOffsets[0])+', v'+str(vertexOffsets[1])+', v'+str(vertexOffsets[3]))
#print('adding tri connecting v'+str(vertexOffsets[1])+', v'+str(vertexOffsets[3])+', v'+str(vertexOffsets[2]))
tris.addVertex(vertexOffsets[0])
tris.addVertex(vertexOffsets[2])
tris.addVertex(vertexOffsets[1])
tris.closePrimitive()
tris.addVertex(vertexOffsets[1])
tris.addVertex(vertexOffsets[2])
tris.addVertex(vertexOffsets[3])
tris.closePrimitive()
currentOffset=currentOffset+2
currentQuad=currentQuad+1
tris2=GeomTriangles(Geom.UHDynamic)
currentOffset=1
numTris=numQuads
currentTri=0
while currentTri<numTris:
#.........这里部分代码省略.........