本文整理汇总了Python中panda3d.core.GeomTriangles类的典型用法代码示例。如果您正苦于以下问题:Python GeomTriangles类的具体用法?Python GeomTriangles怎么用?Python GeomTriangles使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GeomTriangles类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: buildGeom
def buildGeom(self, meshData):
prims = meshData["prims"]
vertices = meshData["vertices"]
normals = meshData["normals"]
texcoords = meshData["texcoords"]
vdata = GeomVertexData('mesh', GeomVertexFormat.getV3n3t2(), Geom.UHStatic)
vwriter = GeomVertexWriter(vdata, 'vertex')
nvwriter = GeomVertexWriter(vdata, 'normal')
tvwriter = GeomVertexWriter(vdata, 'texcoord')
for i in range(len(vertices)):
v = vertices[i]
n = normals[i]
t = texcoords[i]
vwriter.addData3f(v)
nvwriter.addData3f(n)
tvwriter.addData2f(t)
prim = GeomTriangles(Geom.UHStatic)
for i in range(len(prims)):
A, B, C = prims[i]
prim.addVertices(A, B, C)
prim.closePrimitive()
geom = Geom(vdata)
geom.addPrimitive(prim)
geomNode = GeomNode('trig')
geomNode.addGeom(geom)
geomNode.unify(1, True)
return geomNode
示例2: _make_fullscreen_tri
def _make_fullscreen_tri(self):
""" Creates the oversized triangle used for rendering """
vformat = GeomVertexFormat.get_v3()
vdata = GeomVertexData("vertices", vformat, Geom.UH_static)
vdata.set_num_rows(3)
vwriter = GeomVertexWriter(vdata, "vertex")
vwriter.add_data3f(-1, 0, -1)
vwriter.add_data3f(3, 0, -1)
vwriter.add_data3f(-1, 0, 3)
gtris = GeomTriangles(Geom.UH_static)
gtris.add_next_vertices(3)
geom = Geom(vdata)
geom.add_primitive(gtris)
geom_node = GeomNode("gn")
geom_node.add_geom(geom)
geom_node.set_final(True)
geom_node.set_bounds(OmniBoundingVolume())
tri = NodePath(geom_node)
tri.set_depth_test(False)
tri.set_depth_write(False)
tri.set_attrib(TransparencyAttrib.make(TransparencyAttrib.M_none), 10000)
tri.set_color(Vec4(1))
tri.set_bin("unsorted", 10)
tri.reparent_to(self._node)
self._tri = tri
示例3: makeGeom
def makeGeom():
# Vertex data
fmt = GeomVertexFormat.getV3n3t2()
vdata = GeomVertexData('', fmt, Geom.UHStatic)
vertex = GeomVertexWriter(vdata, InternalName.getVertex())
normal = GeomVertexWriter(vdata, InternalName.getNormal())
texcoord = GeomVertexWriter(vdata, InternalName.getTexcoord())
for (x, y, z) in vertices:
vertex.addData3f(x, y, z)
normal.addData3f(0, 0, 0)
# Privitive
prim = GeomTriangles(Geom.UHStatic)
for (i1, i2, i3) in indices:
prim.addVertices(i1, i2, i3)
prim.closePrimitive()
# Geom
geom = Geom(vdata)
geom.addPrimitive(prim)
return geom
示例4: load
def load(self):
if panda3d is None: raise ImportError("Cannot locate Panda3D")
#KLUDGE
if self.material is not None and self.colors is None:
col = self.material.getAmbient()
col = (col[0] / col[3], col[1] / col[3], col[2] / col[3], 1.0)
self.colors = (col,) * len(self.vertices)
#/KLUDGE
geom = make_geom(self.vertices, self.normals, self.colors, self.texcoords)
prim = GeomTriangles(Geom.UHStatic)
for face in self.faces:
#TODO: proper tesselation! the current one only works for convex faces
first = face[0]
curr = face[1]
for v in face[2:]:
prim.addVertex(curr)
prim.addVertex(v)
prim.addVertex(first)
curr = v
prim.closePrimitive()
geom.addPrimitive(prim)
node = GeomNode(self.name)
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
示例5: makeSquare
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.addData3(x1, y1, z1)
vertex.addData3(x2, y1, z1)
vertex.addData3(x2, y2, z2)
vertex.addData3(x1, y2, z2)
normal.addData3(normalized(2 * x1 - 1, 2 * y1 - 1, 2 * z1 - 1))
normal.addData3(normalized(2 * x2 - 1, 2 * y1 - 1, 2 * z1 - 1))
normal.addData3(normalized(2 * x2 - 1, 2 * y2 - 1, 2 * z2 - 1))
normal.addData3(normalized(2 * x1 - 1, 2 * y2 - 1, 2 * z2 - 1))
else:
vertex.addData3(x1, y1, z1)
vertex.addData3(x2, y2, z1)
vertex.addData3(x2, y2, z2)
vertex.addData3(x1, y1, z2)
normal.addData3(normalized(2 * x1 - 1, 2 * y1 - 1, 2 * z1 - 1))
normal.addData3(normalized(2 * x2 - 1, 2 * y2 - 1, 2 * z1 - 1))
normal.addData3(normalized(2 * x2 - 1, 2 * y2 - 1, 2 * z2 - 1))
normal.addData3(normalized(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 aren't directly supported by the Geom interface
# you might be interested in the CardMaker class if you are
# interested in rectangle though
tris = GeomTriangles(Geom.UHDynamic)
tris.addVertices(0, 1, 3)
tris.addVertices(1, 2, 3)
square = Geom(vdata)
square.addPrimitive(tris)
return square
示例6: draw_face
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
示例7: create_model
def create_model(self):
# Set up the vertex arrays
vformat = GeomVertexFormat.get_v3c4()
vdata = GeomVertexData("Data", vformat, Geom.UHStatic)
vertex = GeomVertexWriter(vdata, 'vertex')
color = GeomVertexWriter(vdata, 'color')
geom = Geom(vdata)
# Vertex data
vertex.addData3f(1.5, 0, -1)
color.addData4f(1, 0, 0, 1)
vertex.addData3f(-1.5, 0, -1)
color.addData4f(0, 1, 0, 1)
vertex.addData3f(0, 0, 1)
color.addData4f(0, 0, 1, 1)
# Primitive
tri = GeomTriangles(Geom.UHStatic)
tri.add_vertex(2)
tri.add_vertex(1)
tri.add_vertex(0)
tri.close_primitive()
geom.addPrimitive(tri)
# Create the actual node
node = GeomNode('geom_node')
node.addGeom(geom)
np = NodePath(node)
# Shader and initial shader vars
np.set_shader(Shader.load(Shader.SL_GLSL, "shader/shader.vert", "shader/shader.frag"))
np.set_shader_input("time", 0.0)
# No instancing necessary
#np.set_instance_count(27)
# return np
np.reparent_to(base.render)
self.model = np
示例8: getPrimAndDataFromTri
def getPrimAndDataFromTri(triset, matstate):
if triset.normal is None:
triset.generateNormals()
needsTanAndBin = False
if matstate is not None and matstate.hasAttrib(TextureAttrib):
texattr = matstate.getAttrib(TextureAttrib)
for i in range(texattr.getNumOnStages()):
if texattr.getOnStage(i).getMode() == TextureStage.MNormal:
needsTanAndBin = True
if needsTanAndBin and isinstance(triset, collada.triangleset.TriangleSet) and \
len(triset.texcoordset) > 0 and len(triset.textangentset) == 0:
triset.generateTexTangentsAndBinormals()
vdata, indexdata = getVertexData(triset.vertex, triset.vertex_index,
triset.normal, triset.normal_index,
triset.texcoordset, triset.texcoord_indexset,
triset.textangentset, triset.textangent_indexset,
triset.texbinormalset, triset.texbinormal_indexset)
gprim = GeomTriangles(Geom.UHStatic)
gprim.setIndexType(Geom.NTUint32)
gprim.setVertices(indexdata)
gprim.closePrimitive()
return (vdata, gprim)
示例9: draw
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)
示例10: __build_Tris
def __build_Tris(self, sphere, mode):
vdata = GeomVertexData("Data", self.__vformat[mode], Geom.UHStatic)
_num_rows = len(sphere.pts)
# Vertices.
vertices = GeomVertexWriter(vdata, "vertex")
vertices.reserveNumRows(_num_rows)
for pt in sphere.pts:
vertices.addData3f(*pt)
# Map coords.
if mode == "mid":
mapcoords = GeomVertexWriter(vdata, "mapcoord")
mapcoords.reserveNumRows(_num_rows)
for mc in sphere.coords:
u, v = mc[:2]
mapcoords.addData2f(u,v)
# Tris.
prim = GeomTriangles(Geom.UHStatic)
prim.reserveNumVertices(len(sphere.tris))
for tri in sphere.tris:
prim.addVertices(*tri)
prim.closePrimitive()
# Geom.
geom = Geom(vdata)
geom.addPrimitive(prim)
geom_node = GeomNode("geom")
geom_node.addGeom(geom)
geom_np = NodePath(geom_node)
return geom_np
示例11: __init__
def __init__(self, vdata, tex_idx):
self.vdata = vdata # vertex data, passed in from parent mesh
self.name = 'PolyGroup_'+str(tex_idx)
self.geom = Geom(self.vdata)
self.primitives = GeomTriangles(Geom.UHStatic)
self.geom.addPrimitive(self.primitives)
self.sprite_list_index = 0
self.nodePath = None
示例12: makeNode
def makeNode(self, pointmap=(lambda x, y: (x, y, 0))):
vt = tuple(self.vertices)
t = Triangulator()
fmt = GeomVertexFormat.getV3()
vdata = GeomVertexData('name', fmt, Geom.UHStatic)
vertex = GeomVertexWriter(vdata, 'vertex')
for x, y in vt:
t.addPolygonVertex(t.addVertex(x, y))
vertex.addData3f(pointmap(x, y))
t.triangulate()
prim = GeomTriangles(Geom.UHStatic)
for n in xrange(t.getNumTriangles()):
prim.addVertices(t.getTriangleV0(n),t.getTriangleV1(n),t.getTriangleV2(n))
prim.closePrimitive()
geom = Geom(vdata)
geom.addPrimitive(prim)
node = GeomNode('gnode')
node.addGeom(geom)
return node
示例13: __init__
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()
示例14: makeSquare
def makeSquare(face, rhs=True):
format=GeomVertexFormat.getV3n3cpt2()
format=GeomVertexFormat.getV3n3t2()
vdata=GeomVertexData('square', format, Geom.UHStatic)
vertex=GeomVertexWriter(vdata, 'vertex')
normal=GeomVertexWriter(vdata, 'normal')
#color=GeomVertexWriter(vdata, 'color')
texcoord=GeomVertexWriter(vdata, 'texcoord')
if not rhs:
face = list(reversed(face))
normalvec = (face[1]-face[0]).cross(face[2]-face[0])
normalvec.normalize()
f = 0.9 if rhs else 0.8
f = 1.0
for ver in face:
vertex.addData3f(ver*f)
normal.addData3f(normalvec)
#color.addData3f((ver+1.0+2.0)*0.25)
#color.addData3f(ver*0.0+1.0)
if not normalvec.z:
texcoord.addData2f(0.0, 0.0)
texcoord.addData2f(1.0, 0.0)
texcoord.addData2f(1.0, 1.0)
texcoord.addData2f(0.0, 1.0)
tri=GeomTriangles(Geom.UHStatic)
tri.addVertices(0, 1, 2)
tri.addVertices(2, 3, 0)
tri.closePrimitive()
square=Geom(vdata)
square.addPrimitive(tri)
return square
示例15: reconstruct
def reconstruct(self):
trianglator = Triangulator()
#Add vertices to the trianglator
for vertex in self.vertices:
trianglator.addPolygonVertex(trianglator.addVertex(vertex))
trianglator.triangulate()
#Prepare to create the primative
self.vdata = GeomVertexData('floor', GeomVertexFormat.getV3n3cpt2(), Geom.UHStatic)
vertexW = GeomVertexWriter(self.vdata, 'vertex')
normalW = GeomVertexWriter(self.vdata, 'normal')
colorW = GeomVertexWriter(self.vdata, 'color')
texcoordW = GeomVertexWriter(self.vdata, 'texcoord')
#Add vertices to the primative
i = 0
while i < trianglator.getNumVertices():
vertex = trianglator.getVertex(i)
vertexW.addData3f(vertex.x,vertex.y,0.0)
normalW.addData3f(0,0,1)
colorW.addData4f(0.1,0.1,0.1,0.5)
texcoordW.addData2f(0.0, 1.0)
i+=1
self.geom = Geom(self.vdata)
#Add triangles to the primative
i = 0
print(trianglator.getNumTriangles())
while i < trianglator.getNumTriangles():
tri = GeomTriangles(Geom.UHStatic)
tri.addVertices(trianglator.getTriangleV0(i),trianglator.getTriangleV1(i),trianglator.getTriangleV2(i))
tri.closePrimitive()
self.geom.addPrimitive(tri)
i+=1
self.addGeom(self.geom)