本文整理汇总了Python中panda3d.core.GeomTriangles.addConsecutiveVertices方法的典型用法代码示例。如果您正苦于以下问题:Python GeomTriangles.addConsecutiveVertices方法的具体用法?Python GeomTriangles.addConsecutiveVertices怎么用?Python GeomTriangles.addConsecutiveVertices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.GeomTriangles
的用法示例。
在下文中一共展示了GeomTriangles.addConsecutiveVertices方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_square
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addConsecutiveVertices [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
示例2: createPlane
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addConsecutiveVertices [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)
示例3: renderCharts
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addConsecutiveVertices [as 别名]
def renderCharts(facegraph, verts, vert_indices, lineset=None):
from meshtool.filters.panda_filters.pandacore import getVertexData, attachLights, ensureCameraAt
from meshtool.filters.panda_filters.pandacontrols import KeyboardMovement, MouseDrag, MouseScaleZoom, ButtonUtils
from panda3d.core import GeomTriangles, Geom, GeomNode, GeomVertexFormat, GeomVertexData, GeomVertexWriter, LineSegs
from direct.showbase.ShowBase import ShowBase
vformat = GeomVertexFormat.getV3c4()
vdata=GeomVertexData('tris', vformat, Geom.UHDynamic)
vertex=GeomVertexWriter(vdata, 'vertex')
color=GeomVertexWriter(vdata, 'color')
colors = gen_color3(len(facegraph))
numtris = 0
for chart, data in facegraph.nodes_iter(data=True):
curcolor = next(colors)
for tri in data['tris']:
triv = verts[vert_indices[tri]]
vertex.addData3f(triv[0][0], triv[0][1], triv[0][2])
vertex.addData3f(triv[1][0], triv[1][1], triv[1][2])
vertex.addData3f(triv[2][0], triv[2][1], triv[2][2])
color.addData4f(curcolor[0],curcolor[1], curcolor[2], 1)
color.addData4f(curcolor[0],curcolor[1], curcolor[2], 1)
color.addData4f(curcolor[0],curcolor[1], curcolor[2], 1)
numtris += 1
tris=GeomTriangles(Geom.UHDynamic)
tris.addConsecutiveVertices(0, 3*numtris)
tris.closePrimitive()
linenodes = []
if lineset:
for lines in lineset:
ls = LineSegs()
ls.setThickness(4)
curcolor = next(colors)
ls.setColor(curcolor[0]/256.0, curcolor[1]/256.0, curcolor[2]/256.0, 1)
tuples = False
for blah in lines:
if isinstance(blah, tuple):
tuples = True
break
if tuples:
for i, j in lines:
frompt = verts[i]
topt = verts[j]
ls.moveTo(frompt[0], frompt[1], frompt[2])
ls.drawTo(topt[0], topt[1], topt[2])
else:
for i in range(len(lines)-1):
frompt = verts[lines[i]]
topt = verts[lines[i+1]]
ls.moveTo(frompt[0], frompt[1], frompt[2])
ls.drawTo(topt[0], topt[1], topt[2])
linenodes.append(ls.create())
pgeom = Geom(vdata)
pgeom.addPrimitive(tris)
node = GeomNode("primitive")
node.addGeom(pgeom)
p3dApp = ShowBase()
#attachLights(render)
geomPath = render.attachNewNode(node)
for linenode in linenodes:
geomPath.attachNewNode(linenode)
#geomPath.setRenderModeWireframe()
ensureCameraAt(geomPath, base.cam)
boundingSphere = geomPath.getBounds()
base.cam.setPos(boundingSphere.getCenter() + boundingSphere.getRadius())
base.cam.lookAt(boundingSphere.getCenter())
KeyboardMovement()
ButtonUtils(geomPath)
MouseDrag(geomPath)
MouseScaleZoom(geomPath)
#render.setShaderAuto()
p3dApp.run()
示例4: len
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addConsecutiveVertices [as 别名]
um.polygonize()
format=GeomVertexFormat.getV3n3()
vdata=GeomVertexData("vertices", format, Geom.UHStatic)
vertexWriter=GeomVertexWriter(vdata, "vertex")
normalWriter=GeomVertexWriter(vdata, "normal")
print len(um.tri_list), "vertices"
print len(um.tri_list) / 3.0, "tris"
for p in um.tri_list:
vertexWriter.addData3f(p[0],p[1],p[2])
for p in um.normal_list:
normalWriter.addData3f(p[0],p[1],p[2])
for p in reversed(um.tri_list):
vertexWriter.addData3f(p[0],p[1],p[2])
for p in reversed(um.normal_list):
normalWriter.addData3f(-1 * p[0], -1 * p[1], -1 *p[2])
tris = GeomTriangles(Geom.UHStatic)
tris.addConsecutiveVertices(0, len(um.tri_list))
tris.closePrimitive()
um_geom = Geom(vdata)
um_geom.addPrimitive(tris)
um_GN = GeomNode(shp)
um_GN.addGeom(um_geom)
app = MyApp()
app.run()
示例5: makeSquare
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addConsecutiveVertices [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