当前位置: 首页>>代码示例>>Python>>正文


Python core.GeomVertexWriter类代码示例

本文整理汇总了Python中panda3d.core.GeomVertexWriter的典型用法代码示例。如果您正苦于以下问题:Python GeomVertexWriter类的具体用法?Python GeomVertexWriter怎么用?Python GeomVertexWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了GeomVertexWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: addMeshConvexRB

    def addMeshConvexRB(self,vertices, faces,ghost=False,**kw):
        #step 1) create GeomVertexData and add vertex information
        format=GeomVertexFormat.getV3()
        vdata=GeomVertexData("vertices", format, Geom.UHStatic)
        
        vertexWriter=GeomVertexWriter(vdata, "vertex")
        [vertexWriter.addData3f(v[0],v[1],v[2]) for v in vertices]
        
        #step 2) make primitives and assign vertices to them
        tris=GeomTriangles(Geom.UHStatic)
        [self.setGeomFaces(tris,face) for face in faces]
        
        #step 3) make a Geom object to hold the primitives
        geom=Geom(vdata)
        geom.addPrimitive(tris)
        
        #step 4) create the bullet mesh and node
        mesh = BulletTriangleMesh()
        mesh.addGeom(geom)

        shape = BulletConvexHullShape(mesh, dynamic=not ghost)#
        if ghost :
            inodenp = self.worldNP.attachNewNode(BulletGhostNode('Mesh'))
        else :
            inodenp = self.worldNP.attachNewNode(BulletRigidBodyNode('Mesh'))
        inodenp.node().addShape(shape)
#        inodenp.setPos(0, 0, 0.1)
        self.setRB(inodenp,**kw)
        inodenp.setCollideMask(BitMask32.allOn())
   
        self.world.attachRigidBody(inodenp.node())
        return inodenp
开发者ID:brettbarbaro,项目名称:autoPACK,代码行数:32,代码来源:pandautil.py

示例2: newVertexData

 def newVertexData(self):
     fmt = GeomVertexFormat.getV3c4()
     #         fmt = GeomVertexFormat.getV3n3c4()
     self.vertexData = GeomVertexData("path", fmt, Geom.UHStatic)
     self.vertexWriter = GeomVertexWriter(self.vertexData, "vertex")
     #         self.normalWriter = GeomVertexWriter(self.vertexData, 'normal')
     self.colorWriter = GeomVertexWriter(self.vertexData, "color")
开发者ID:eswartz,项目名称:panda3d-stuff,代码行数:7,代码来源:draw_path_tris.py

示例3: _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
开发者ID:ELMERzark,项目名称:RenderPipeline,代码行数:25,代码来源:post_process_region.py

示例4: __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
开发者ID:svfgit,项目名称:solex,代码行数:32,代码来源:model.py

示例5: __modify_Model

 def __modify_Model(self, field, data):
     geom = self.node.modifyGeom(0)
     vdata = geom.modifyVertexData()
     vwriter = GeomVertexWriter(vdata, field)
     vwriter.reserveNumRows(len(data))
     set_data = self.set_dict[field]
     for datum in data:
         set_data(vwriter, *datum)
     geom.setVertexData(vdata)
开发者ID:svfgit,项目名称:solex,代码行数:9,代码来源:model.py

示例6: generate

 def generate(self):
     '''(Re)generate the entire terrain erasing any current changes'''
     factor = self.blockSize*self.chunkSize
     #print "Factor:", factor
     for terrain in self.terrains:
         terrain.getRoot().removeNode()
     self.terrains = []
     # Breaking master heightmap into subimages
     heightmaps = []
     self.xchunks = (self.heightfield.getXSize()-1)/factor
     self.ychunks = (self.heightfield.getYSize()-1)/factor
     #print "X,Y chunks:", self.xchunks, self.ychunks
     n = 0
     for y in range(0, self.ychunks):
         for x in range(0, self.xchunks):
             heightmap = PNMImage(factor+1, factor+1)
             heightmap.copySubImage(self.heightfield, 0, 0, xfrom = x*factor, yfrom = y*factor)
             heightmaps.append(heightmap)
             n += 1
     
     # Generate GeoMipTerrains
     n = 0
     y = self.ychunks-1
     x = 0
     for heightmap in heightmaps:
         terrain = GeoMipTerrain(str(n))
         terrain.setHeightfield(heightmap)
         terrain.setBruteforce(self.bruteForce)
         terrain.setBlockSize(self.blockSize)
         terrain.generate()
         self.terrains.append(terrain)
         root = terrain.getRoot()
         root.reparentTo(self.root)
         root.setPos(n%self.xchunks*factor, (y)*factor, 0)
         
         # In order to texture span properly we need to reiterate through every vertex
         # and redefine the uv coordinates based on our size, not the subGeoMipTerrain's
         root = terrain.getRoot()
         children = root.getChildren()
         for child in children:
             geomNode = child.node()
             for i in range(geomNode.getNumGeoms()):
                 geom = geomNode.modifyGeom(i)
                 vdata = geom.modifyVertexData()
                 texcoord = GeomVertexWriter(vdata, 'texcoord')
                 vertex = GeomVertexReader(vdata, 'vertex')
                 while not vertex.isAtEnd():
                     v = vertex.getData3f()
                     t = texcoord.setData2f((v[0]+ self.blockSize/2 + self.blockSize*x)/(self.xsize - 1),
                                                     (v[1] + self.blockSize/2 + self.blockSize*y)/(self.ysize - 1))
         x += 1
         if x >= self.xchunks:
             x = 0
             y -= 1
         n += 1
开发者ID:croxis,项目名称:CityMania,代码行数:55,代码来源:PagedGeoMipTerrain.py

示例7: 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)
开发者ID:nkolkin13,项目名称:ProcEdit,代码行数:34,代码来源:D_mesh.py

示例8: add_plane

def add_plane(map_width, map_height):
    # Prepare the vertex format writers
    v_fmt = GeomVertexFormat.getV3n3c4()
    v_data = GeomVertexData('TerrainData', v_fmt, Geom.UHStatic)
    vertex = GeomVertexWriter(v_data, 'vertex')
    normal = GeomVertexWriter(v_data, 'normal')
    color = GeomVertexWriter(v_data, 'color')
    #texcoord = GeomVertexWriter(v_data, 'texcoord')

    # Create a primitive
    prim = GeomTrifans(Geom.UHStatic)
    poly_color = (uniform(0, 0.05), uniform(0, 0.5), uniform(0.5, 1), 0.5, )

    for i, point in enumerate([
            (-map_width/2, -map_height/2),
            (map_width/2, -map_height/2),
            (map_width/2, map_height/2),
            (-map_width/2, map_height/2), ]):
        x, y = point
        vertex.addData3f(x, y, 0)
        normal.addData3f(0, 0, 1)
        color.addData4f(*poly_color)
        #texcoord.addData2f(1, 0)
        prim.addVertex(i)
    prim.addVertex(0)
    prim.closePrimitive()

    # Add to the scene graph
    geom = Geom(v_data)
    geom.addPrimitive(prim)
    node = GeomNode('gnode')
    node.addGeom(geom)
    nodePath = render.attachNewNode(node)
    nodePath.setTwoSided(True)
    nodePath.setAlphaScale(0.5)
开发者ID:pennomi,项目名称:voronoi-terrain,代码行数:35,代码来源:terrain.py

示例9: makeRotationGeomNode

def makeRotationGeomNode():
    vdata = GeomVertexData('rotHandleData', GeomVertexFormat.getV3(),
            Geom.UHStatic)
    v = GeomVertexWriter(vdata, 'vertex')
    radius = 0.7
    width = 0.08
    res = 30
    innerRad = radius - width

    for i in xrange(res):
        theta = i*(2*pi/res)
        v.addData3f(innerRad*sin(theta), innerRad*cos(theta), width/2.0)
        v.addData3f(innerRad*sin(theta), innerRad*cos(theta), -width/2.0)
        v.addData3f(radius*sin(theta), radius*cos(theta), width/2.0)
        v.addData3f(radius*sin(theta), radius*cos(theta), -width/2.0)

    circle = Geom(vdata)
    # Make prims for the faces of the torus
    faces = [GeomTristrips(Geom.UHStatic) for i in xrange(4)]
    for i in xrange(res):
        i = i*4
        faces[0].addVertices(i + 1, i)
        faces[1].addVertices(i + 2, i + 1)
        faces[2].addVertices(i + 3, i + 2)
        faces[3].addVertices(i, i + 3)
    for i in xrange(4):
        faces[i].addVertices((i + 1) % 4, i)
        faces[i].closePrimitive()
        circle.addPrimitive(faces[i])
    node = GeomNode('geomnode')
    node.addGeom(circle)
    return node
开发者ID:athityakumar,项目名称:software,代码行数:32,代码来源:handles.py

示例10: 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
开发者ID:arikel,项目名称:PPARPG,代码行数:34,代码来源:meshHandler.py

示例11: create_geom

    def create_geom(self, sidelength):
        # Set up the vertex arrays
        vformat = GeomVertexFormat.getV3n3c4()
        vdata = GeomVertexData("Data", vformat, Geom.UHDynamic)
        vertex = GeomVertexWriter(vdata, 'vertex')
        normal = GeomVertexWriter(vdata, 'normal')
        color = GeomVertexWriter(vdata, 'color')
        geom = Geom(vdata)

        # Write vertex data
        for x in range(0, sidelength):
            for y in range(0, sidelength):
                # vertex_number = x * sidelength + y
                v_x, v_y, v_z = self.map_b[(x, y)]
                n_x, n_y, n_z = 0.0, 0.0, 1.0
                c_r, c_g, c_b, c_a = 0.5, 0.5, 0.5, 0.5
                vertex.addData3f(v_x, v_y, v_z)
                normal.addData3f(n_x, n_y, n_z)
                color.addData4f(c_r, c_g, c_b, c_a)

        # Add triangles
        for x in range(0, sidelength - 1):
            for y in range(0, sidelength - 1):
                # The vertex arrangement (y up, x right)
                # 2 3
                # 0 1
                v_0 = x * sidelength + y
                v_1 = x * sidelength + (y + 1)
                v_2 = (x + 1) * sidelength + y
                v_3 = (x + 1) * sidelength + (y + 1)
                if (x+y)%1 == 0: # An even square
                    tris = GeomTriangles(Geom.UHStatic)
                    tris.addVertices(v_0, v_2, v_3)
                    tris.closePrimitive()
                    geom.addPrimitive(tris)
                    tris = GeomTriangles(Geom.UHStatic)
                    tris.addVertices(v_3, v_1, v_0)
                    tris.closePrimitive()
                    geom.addPrimitive(tris)
                else: # An odd square
                    tris = GeomTriangles(Geom.UHStatic)
                    tris.addVertices(v_1, v_0, v_2)
                    tris.closePrimitive()
                    geom.addPrimitive(tris)
                    tris = GeomTriangles(Geom.UHStatic)
                    tris.addVertices(v_2, v_3, v_1)
                    tris.closePrimitive()
                    geom.addPrimitive(tris)

        # Create the actual node
        node = GeomNode('geom_node')
        node.addGeom(geom)
        
        # Remember GeomVertexWriters to adjust vertex data later
        #self.vertex_writer = vertex
        #self.color_writer = color
        self.vdata = vdata
        
        return node
开发者ID:TheCheapestPixels,项目名称:panda_examples,代码行数:59,代码来源:geometry.py

示例12: __init__

    def __init__(self, __occupying_unit = None, __occupiable = True, 
	x = 0, z = 0, r = 5, tag = 0):
        self.__occupying_unit = __occupying_unit
        self.__occupiable = __occupiable
	self.__r = r
	self.__x = x
	self.__z = z
	self.__tag = tag
	
	#Procedurally creating a hex!
	geometry_array = GeomVertexArrayFormat()
	geometry_array.addColumn(InternalName.make('vertex'), 3, Geom.NTFloat32, Geom.CPoint)
	geometry_array.addColumn(InternalName.make('normal'), 3, Geom.NTFloat32, Geom.CPoint)
	format = GeomVertexFormat()
	format.addArray(geometry_array)
	format = GeomVertexFormat.registerFormat(format)
	self.__vdata = GeomVertexData('Hex', format, Geom.UHStatic)
	self.__vertex = GeomVertexWriter(self.__vdata, 'vertex')
	self.__normal = GeomVertexWriter(self.__vdata, 'normal')

	#Vertex 1
	self.__vertex.addData3f(self.__x, self.__z+self.__r, 0)
	self.__normal.addData3f(1, 0, 0)
	#Vertex 2
	self.__vertex.addData3f(self.__x+self.__r*sin(pi/3), self.__z+self.__r*cos(pi/3), 0)
	self.__normal.addData3f(1, 0, 0)
	#Vertex 3
	self.__vertex.addData3f(self.__x+self.__r*sin(pi/3), self.__z-self.__r*cos(pi/3), 0)
	self.__normal.addData3f(1, 0, 0)
	#Vertex 4
	self.__vertex.addData3f(self.__x, self.__z-self.__r, 0)
	self.__normal.addData3f(1, 0, 0)
	#Vertex 5
	self.__vertex.addData3f(self.__x-self.__r*sin(pi/3), self.__z-self.__r*cos(pi/3), 0)
	self.__normal.addData3f(1, 0, 0)
	#Vertex 6
	self.__vertex.addData3f(self.__x-self.__r*sin(pi/3), self.__z+self.__r*cos(pi/3), 0)
	self.__normal.addData3f(1, 0, 0)

	self.__hex_primitive = GeomTrifans(Geom.UHStatic)
	self.__hex_primitive.addVertices(5, 4)
	self.__hex_primitive.addVertices(3, 2)
	self.__hex_primitive.addVertices(1, 0)

	self.__hex_primitive.closePrimitive()
	self.__hex_geometry = Geom(self.__vdata)
	self.__hex_geometry.addPrimitive(self.__hex_primitive)
	self.__hex_node = GeomNode('HexNode')
	self.__hex_node.addGeom(self.__hex_geometry)

	nodePath = render.attachNewNode(self.__hex_node)
	nodePath.setTag( "hex", str(tag) )
	nodePath.node().setIntoCollideMask(BitMask32.bit(1))
	nodePath.hide()
开发者ID:tkayali,项目名称:P.I.R.A.T.E.S.,代码行数:54,代码来源:PGridspace.py

示例13: clearMesh

	def clearMesh(self):
		#if self.np:
		#	self.np.remove()
		self.node.removeAllGeoms()
		
		self.vdata = GeomVertexData ('name', self.format, Geom.UHStatic)
		self.vWriter = GeomVertexWriter (self.vdata, 'vertex')
		self.cWriter = GeomVertexWriter (self.vdata, 'color')
		
		self.geom = Geom(self.vdata)
		#self.node = GeomNode("lines")
		
		self.node.addGeom(self.geom)
开发者ID:arikel,项目名称:PPARPG,代码行数:13,代码来源:meshLine.py

示例14: drawBody

    def drawBody(self, pos, quat, radius=1,UVcoord=(1,1), numVertices=_polySize):
#        if isRoot:
#            self.bodydata = GeomVertexData("body vertices", GeomVertexFormat.getV3n3t2(), Geom.UHStatic)
        vdata = self.bodydata
        circleGeom = Geom(vdata) # this was originally a copy of all previous geom in vdata...
        vertWriter = GeomVertexWriter(vdata, "vertex")
        #colorWriter = GeomVertexWriter(vdata, "color")
        normalWriter = GeomVertexWriter(vdata, "normal")
#        drawReWriter = GeomVertexRewriter(vdata, "drawFlag")
        texReWriter = GeomVertexRewriter(vdata, "texcoord")

        startRow = vdata.getNumRows()
        vertWriter.setRow(startRow)
        #colorWriter.setRow(startRow)
        normalWriter.setRow(startRow)       
        texReWriter.setRow(startRow)   
       
        #axisAdj=Mat4.rotateMat(45, axis)*Mat4.scaleMat(radius)*Mat4.translateMat(pos)
        perp1 = quat.getRight()
        perp2 = quat.getForward()   
        
#TODO: PROPERLY IMPLEMENT RADIAL NOISE        
        #vertex information is written here
        angleSlice = 2 * pi / numVertices
        currAngle = 0
        for i in xrange(numVertices+1): 
            adjCircle = pos + (perp1 * cos(currAngle) + perp2 * sin(currAngle)) * radius * (.5+bNodeRadNoise*random.random())
            normal = perp1 * cos(currAngle) + perp2 * sin(currAngle)       

            normalWriter.addData3f(normal)
            vertWriter.addData3f(adjCircle)
            texReWriter.addData2f(float(UVcoord[0]*i) / numVertices,UVcoord[1])            # UV SCALE HERE!
            #colorWriter.addData4f(0.5, 0.5, 0.5, 1)
            currAngle += angleSlice 
        
        #we cant draw quads directly so we use Tristrips
        if (startRow != 0):
            lines = GeomTristrips(Geom.UHStatic)         
            for i in xrange(numVertices+1):
                lines.addVertex(i + startRow)
                lines.addVertex(i + startRow - numVertices-1)
            lines.addVertex(startRow)
            lines.addVertex(startRow - numVertices)
            lines.closePrimitive()
            #lines.decompose()
            circleGeom.addPrimitive(lines)           
            circleGeomNode = GeomNode("Debug")
            circleGeomNode.addGeom(circleGeom)   
            self.numPrimitives += numVertices * 2
            self.bodies.attachNewNode(circleGeomNode)
            return circleGeomNode
开发者ID:supus71,项目名称:panda3dtrees,代码行数:51,代码来源:myFracTree.py

示例15: __modify_Model

 def __modify_Model(self, field, data):
     set_dict = {
         'vertex':GeomVertexWriter.setData3f,
         'normal':GeomVertexWriter.setData3f,
         'color':GeomVertexWriter.setData4f,
         'texcoord':GeomVertexWriter.setData2f,
         'info':GeomVertexWriter.setData4f,
         'ref':GeomVertexWriter.setData3f,
         'nbr':GeomVertexWriter.setData4i}
         
     geom = self.NP.node().modifyGeom(0)
     vdata = geom.modifyVertexData()
     vwriter = GeomVertexWriter(vdata, field)
     vwriter.reserveNumRows(len(data))
     set_data = set_dict[field]
     for datum in data:
         set_data(vwriter, *datum)
     geom.setVertexData(vdata)
开发者ID:svfgit,项目名称:solex,代码行数:18,代码来源:_model.py


注:本文中的panda3d.core.GeomVertexWriter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。