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


Python core.Geom类代码示例

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


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

示例1: _makeGeom

def _makeGeom(array,ctup,i,pipe, geomType=GeomPoints): #XXX testing multiple Geom version ... for perf seems like it will be super slow
    #SUUUPER slow TONS of draw calls
    #wwwayyy better to make a bunch of geoms ahead of time...
    """ multiprocessing capable geometery maker """
    fmt = GeomVertexFormat.getV3c4()

    cloudNode = GeomNode('bin %s selectable'%(i))
    for point in array:
        vertexData = GeomVertexData('poitn', fmt, Geom.UHStatic)
        GeomVertexWriter(vertexData, 'vertex').addData3f(*point)
        GeomVertexWriter(vertexData, 'color').addData4f(*ctup)
        #verts.addData3f(*point)
        #color.addData4f(*ctup)

        points = geomType(Geom.UHStatic)
        points.addVertex(0)
        points.closePrimitive()

        cloudGeom = Geom(vertexData)
        cloudGeom.addPrimitive(points)
        cloudNode.addGeom(cloudGeom) #TODO figure out if it is faster to add and subtract Geoms from geom nodes...
    #output[i] = cloudNode
    #print('ping',{i:cloudNode})
    #pipe.send((i,))
    #out = q.get()
    #print('pong',out)
    #q.put(out)
    if pipe == None:
        return (cloudNode)
    pipe.send(cloudNode.encodeToBamStream()) #FIXME make this return a pointer NOPE
开发者ID:tgbugs,项目名称:desc,代码行数:30,代码来源:test_objects.py

示例2: makeSimpleGeomBuffer

def makeSimpleGeomBuffer(array, color, geomType=GeomPoints):
    """ massively faster than the nonbuffer version """

    full = [tuple(d) for d in np.hstack((array,color))]

    fmt = GeomVertexFormat.getV3c4()

    vertexData = GeomVertexData('points', fmt, Geom.UHDynamic) #FIXME use the index for these too? with setPythonTag, will have to 'reserve' some
    cloudGeom = Geom(vertexData)
    cloudNode = GeomNode('just some points')

    vertexData.setNumRows(len(array))
    mem_array = vertexData.modifyArray(0)
    view = memoryview(mem_array)
    arr = np.asarray(view)
    arr[:] = full

    points = geomType(Geom.UHDynamic)
    points.addConsecutiveVertices(0,len(array))
    points.closePrimitive()

    cloudGeom.addPrimitive(points)
    cloudNode.addGeom(cloudGeom)

    return cloudNode
开发者ID:tgbugs,项目名称:desc,代码行数:25,代码来源:test_objects.py

示例3: __build_Geom

 def __build_Geom(self, data_dict, tris, prim_type=GeomTriangles):
     data_list = list(data_dict.items())
     _num_rows = 0
     for field, data in data_list:
         if not _num_rows: _num_rows = len(data)
         writer = self.__writers[field]
         writer.reserveNumRows(_num_rows)
         set_data = self._data_types[self.field_types[field]][-1]
         for datum in data:
             set_data(writer, *datum)
     
     # Tris
     prim = prim_type(Geom.UHStatic)
     prim.reserveNumVertices(len(tris))
     for tri in tris:
         prim.addVertices(*tri)
     prim.closePrimitive()
     
     # Geom.
     geom = Geom(self.__vdata)
     geom.addPrimitive(prim)
     geom_node = GeomNode("geom")
     geom_node.addGeom(geom)
     geom_np = NodePath(geom_node)
     return geom_np
开发者ID:svfgit,项目名称:solex,代码行数:25,代码来源:util.py

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

示例5: 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

示例6: 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
开发者ID:TheCheapestPixels,项目名称:panda_examples,代码行数:33,代码来源:shader.py

示例7: __build_Patches

 def __build_Patches(self, sphere):
     vdata = GeomVertexData("Data", self.__vformat['high'], Geom.UHStatic)
     vertices = GeomVertexWriter(vdata, "vertex")
     mapcoords = GeomVertexWriter(vdata, "mapcoord")
     texcoords = GeomVertexWriter(vdata, "texcoord")
     
     _num_rows = len(sphere.pts)
     vertices.reserveNumRows(_num_rows)
     mapcoords.reserveNumRows(_num_rows)
     texcoords.reserveNumRows(_num_rows)
     
     # Pts.
     for pt, uv, coords, in zip(sphere.pts, sphere.uvs, sphere.coords):
         vertices.addData3f(*pt)
         mapcoords.addData2f(*coords)
         texcoords.addData2f(*uv) ## *.99+.01)
     
     # Patches.
     prim = GeomPatches(3, 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,代码行数:31,代码来源:model.py

示例8: 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

示例9: makeSimpleGeom

def makeSimpleGeom(array, ctup, geomType = GeomPoints, fix = False):
    fmt = GeomVertexFormat.getV3c4()

    vertexData = GeomVertexData('points', fmt, Geom.UHDynamic) #FIXME use the index for these too? with setPythonTag, will have to 'reserve' some
    cloudGeom = Geom(vertexData)
    cloudNode = GeomNode('just some points')

    verts = GeomVertexWriter(vertexData, 'vertex')
    color = GeomVertexWriter(vertexData, 'color')

    if fix:
        if len(ctup) == len(array):
            for point,c in zip(array, ctup):
                verts.addData3f(*point)
                color.addData4f(*c)
        else:
            for point in array:
                verts.addData3f(*point)
                color.addData4f(*ctup)
    else:
        for point in array:
            verts.addData3f(*point)
            color.addData4f(*ctup)

    points = geomType(Geom.UHDynamic)
    points.addConsecutiveVertices(0,len(array))
    points.closePrimitive()

    cloudGeom.addPrimitive(points)
    cloudNode.addGeom(cloudGeom) #TODO figure out if it is faster to add and subtract Geoms from geom nodes...

    if fix:
        return cloudNode.__reduce__()
    else:
        return cloudNode  # decoding fails becuase ForkingPickler is called for reasons beyond comprehension
开发者ID:tgbugs,项目名称:desc,代码行数:35,代码来源:test_objects.py

示例10: 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

示例11: makePoints

def makePoints(n=1000):
    """ make a cloud of points that are a single node VS branching and making subnodes to control display """

    #points = np.random.uniform(-10,10,(n,4))
    points = np.random.randn(n,3)
    colors = np.random.rand(n,4)

    fmt = GeomVertexFormat.getV3c4() #3 component vertex, w/ 4 comp color
    vertexData = GeomVertexData('points', fmt, Geom.UHStatic)

    verts = GeomVertexWriter(vertexData, 'vertex')
    color = GeomVertexWriter(vertexData, 'color')

    for point,clr4 in zip(points,colors):
    #for point in points:
        verts.addData3f(*point)
        #color.addData4f(*point)
        color.addData4f(*clr4)
        #color.addData4f(.1,.1,.1,1)

    #pointCloud = GeomLinestrips(Geom.UHStatic) #this is fucking cool!
    pointCloud = GeomTristrips(Geom.UHStatic) #this is fucking cool!
    #pointCloud = GeomPoints(Geom.UHStatic)
    #pointCloud.addVerticies(*range(n))
    pointCloud.addConsecutiveVertices(0,n) #warning may error since n-1?
    pointCloud.closePrimitive()

    cloud = Geom(vertexData)
    cloud.addPrimitive(pointCloud)
    return cloud
开发者ID:tgbugs,项目名称:desc,代码行数:30,代码来源:points.py

示例12: __build_Star_Sphere

    def __build_Star_Sphere(self, bg_stars):
        from panda3d.core import GeomVertexWriter, GeomVertexFormat, GeomVertexData
        from panda3d.core import Geom, GeomNode, GeomPoints, AmbientLight
        self.star_sphere_np.removeNode()
        
        # Fill GeomVertexData.
        vformat = GeomVertexFormat.getV3c4()
        vdata = GeomVertexData("Data", vformat, Geom.UHStatic) 
        vertices = GeomVertexWriter(vdata, "vertex")
        colours = GeomVertexWriter(vdata, "color")
        for coords in bg_stars:
            x, y, z = coords
            vertices.addData3f(x, y, z)
            colours.addData4f(1, 1, 1, 1)
            
        # Render bg stars.
        bg_stars = GeomPoints(Geom.UHStatic)
        bg_stars.addNextVertices(_env.STAR_COUNT)
        bg_stars_geom = Geom(vdata)
        bg_stars_geom.addPrimitive(bg_stars)
        star_sphere = GeomNode("star_sphere")
        star_sphere.addGeom(bg_stars_geom)
        star_sphere_np = NodePath(star_sphere)

        star_sphere_np.reparentTo(self.NP)
        return star_sphere_np
开发者ID:svfgit,项目名称:solex,代码行数:26,代码来源:environments.py

示例13: 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
开发者ID:Changuito,项目名称:juan_example,代码行数:26,代码来源:torus.py

示例14: 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

示例15: 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


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