本文整理汇总了Python中panda3d.core.GeomVertexFormat.getV3n3cp方法的典型用法代码示例。如果您正苦于以下问题:Python GeomVertexFormat.getV3n3cp方法的具体用法?Python GeomVertexFormat.getV3n3cp怎么用?Python GeomVertexFormat.getV3n3cp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.GeomVertexFormat
的用法示例。
在下文中一共展示了GeomVertexFormat.getV3n3cp方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_face
# 需要导入模块: from panda3d.core import GeomVertexFormat [as 别名]
# 或者: from panda3d.core.GeomVertexFormat import getV3n3cp [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
示例2: draw
# 需要导入模块: from panda3d.core import GeomVertexFormat [as 别名]
# 或者: from panda3d.core.GeomVertexFormat import getV3n3cp [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)
示例3: __init__
# 需要导入模块: from panda3d.core import GeomVertexFormat [as 别名]
# 或者: from panda3d.core.GeomVertexFormat import getV3n3cp [as 别名]
def __init__(self):
ShowBase.__init__(self)
PanditorDisableMouseFunc()
camera.setPos(0.0, 0.0, 50.0)
camera.lookAt(0.0)
PanditorEnableMouseFunc()
# 1) create GeomVertexData
frmt = GeomVertexFormat.getV3n3cp()
vdata = GeomVertexData('triangle', frmt, Geom.UHDynamic)
# 2) create Writers/Rewriters (must all be created before any readers and readers are one-pass-temporary)
vertex = GeomVertexRewriter(vdata, 'vertex')
normal = GeomVertexRewriter(vdata, 'normal')
color = GeomVertexRewriter(vdata, 'color')
zUp = Vec3(0, 0, 1)
wt = Vec4(1.0, 1.0, 1.0, 1.0)
gr = Vec4(0.5, 0.5, 0.5, 1.0)
# 3) write each column on the vertex data object (for speed, have a different writer for each column)
def addPoint(x, y, z):
vertex.addData3f(x, y, z)
normal.addData3f(zUp)
color.addData4f(wt)
addPoint(0.0, 0.0, 0.0)
addPoint(5.0, 0.0, 0.0)
addPoint(0.0, 5.0, 0.0)
addPoint(5.0, 5.0, 0.0)
# 4) create a primitive and add the vertices via index (not truely associated with the actual vertex table, yet)
tris = GeomTriangles(Geom.UHDynamic)
tris.addVertices(0, 1, 2)
tris.closePrimitive() # exception thrown if verts added != 3, other types inform Panda how many verts/primitive
tris.addVertices(2, 1, 3)
print "vdataPoints", vdata.getArrays()[0]
# 5.1) (adding to scene) create a Geom and add primitives of like base-type i.e. triangles and triangle strips
geom = Geom(vdata)
geom.addPrimitive(tris)
# 5.2) create a GeomNode to hold the Geom(s) and add the Geom(s)
gn = GeomNode('gnode')
gn.addGeom(geom)
# 5.3) attache the node to the scene
gnNodePath = render.attachNewNode(gn)
geomPts = Geom(vdata)
pts = GeomPoints(Geom.UHStatic)
pts.addVertices(0, 1, 2)
pts.closePrimitive()
geomPts.addPrimitive(pts)
pointsNode = GeomNode('points_node')
pointsNode.addGeom(geomPts)
pointsNP = render.attachNewNode(pointsNode)
pointsNP.setZ(0.5)
render.ls()
示例4: createTriangle
# 需要导入模块: from panda3d.core import GeomVertexFormat [as 别名]
# 或者: from panda3d.core.GeomVertexFormat import getV3n3cp [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
示例5: makeTriMesh
# 需要导入模块: from panda3d.core import GeomVertexFormat [as 别名]
# 或者: from panda3d.core.GeomVertexFormat import getV3n3cp [as 别名]
def makeTriMesh( verts, holeVerts=[[]]):
pointmap = (lambda x, y: (x, y, 0))
if not hasattr(holeVerts[0], '__iter__'):
holeVerts = [holeVerts]
frmt = GeomVertexFormat.getV3n3cp()
vdata = GeomVertexData('triangle', frmt, Geom.UHDynamic)
vertex = GeomVertexWriter(vdata, 'vertex')
normal = GeomVertexWriter(vdata, 'normal')
color = GeomVertexWriter(vdata, 'color')
bl = Vec4(50, 50, 50, 255)
gr = Vec4(256/2 - 1, 256/2 - 1, 256/2 - 1, 255)
trilator = Triangulator()
zUp = Vec3(0, 0, 1)
for i in verts:
#print "verts", verts
trilator.addPolygonVertex(trilator.addVertex(i.x, i.y))
vertex.addData3f(pointmap(i.x, i.y))
normal.addData3f(zUp)
color.addData4f(bl)
#if len(holeVerts) != 1 and holeVerts[0] != []:
for w in holeVerts:
trilator.beginHole()
print "new hole"
for j in w:
# print(j) # ###################### PRINT #######################
trilator.addHoleVertex(trilator.addVertex(j.x, j.y))
vertex.addData3f(pointmap(j.x, j.y))
normal.addData3f(zUp)
color.addData4f(gr)
# try:
trilator.triangulate()
triVerts = trilator.getVertices()
p = trilator.getTriangleV0(0)
print "trilator return", p
# except AssertionError:
# pass
# TODO:re-triangulate here and change AdjacencyList to expect a list of triangles rather than call Triangulator funcs
trilator = makeDelaunayTriangulation(trilator)
prim = GeomTriangles(Geom.UHStatic)
if isinstance(trilator, Triangulator):
# HACK just to switch back and forth from the non-Delaunay to the Delaunay for school
for n in xrange(trilator.getNumTriangles()):
prim.addVertices(trilator.getTriangleV0(n),
trilator.getTriangleV1(n),
trilator.getTriangleV2(n))
else: # it's an adjacency list
for n in xrange(len(trilator.adjLst)):
for v in range(0, len(triVerts)):
print "\ncurr", triVerts[v], "\nv0", Point2D(trilator.adjLst[n].tri[0].x, trilator.adjLst[n].tri[0].y),\
"\nv1", Point2D(trilator.adjLst[n].tri[1].x, trilator.adjLst[n].tri[1].y),\
"\nv2", Point2D(trilator.adjLst[n].tri[2].x, trilator.adjLst[n].tri[2].y)
# trilator.adjLst[n].tri[0].getXy(),\
# "\nv1", trilator.adjLst[n].tri[1].getXy(),\
# "\nv2", trilator.adjLst[n].tri[2].getXy()
# v0 = v1 = v2 = -1
if Point2D(trilator.adjLst[n].tri[0].x, trilator.adjLst[n].tri[0].y) == triVerts[v]:
v0 = v # we need indices into the vertex pool
print "found v0", v0
if Point2D(trilator.adjLst[n].tri[1].x, trilator.adjLst[n].tri[1].y) == triVerts[v]:
v1 = v
print "found v1", v1
if Point2D(trilator.adjLst[n].tri[2].x, trilator.adjLst[n].tri[2].y) == triVerts[v]:
v2 = v
print "found v2", v2
# if v0 == -1 or v1 == -1 or v2 == -1:
# print "pass", v0, v1, v2
# pass
# else:
# print "add"
# i = triVerts[v0]
# vertex.addData3f(pointmap(i.x, i.y))
# normal.addData3f(zUp)
# color.addData4f(bl)
# i = triVerts[v1]
# vertex.addData3f(pointmap(i.x, i.y))
# normal.addData3f(zUp)
# color.addData4f(bl)
# i = triVerts[v2]
# vertex.addData3f(pointmap(i.x, i.y))
# normal.addData3f(zUp)
# color.addData4f(bl)
print "v 1 2 3", v0, v1, v2
prim.addVertices(v0, v1, v2)
prim.closePrimitive()
geom = Geom(vdata)
geom.addPrimitive(prim)
node = GeomNode('gnode')
#.........这里部分代码省略.........