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


Python GeomVertexWriter.addData2f方法代码示例

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


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

示例1: buildGeom

# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData2f [as 别名]
	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,代码行数:36,代码来源:meshHandler.py

示例2: make_geom

# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData2f [as 别名]
def make_geom(vertices, normals, colors, texcoords):
    if panda3d is None: raise ImportError("Cannot locate Panda3D")
    format = "V3"
    if normals is not None:
        assert len(normals) == len(vertices)
        format += "n3"

    if colors is not None:
        assert len(colors) == len(vertices)
        format += "cp"

    if texcoords is not None:
        assert len(texcoords) == len(vertices)
        format += "t2"
    format = getattr(GeomVertexFormat, "get" + format)()
    vdata = GeomVertexData("", format, Geom.UHStatic)

    v_vertex = GeomVertexWriter(vdata, 'vertex')
    if normals is not None: v_normals = GeomVertexWriter(vdata, 'normal')
    if colors is not None: v_colors = GeomVertexWriter(vdata, 'color')
    if texcoords is not None: v_texcoords = GeomVertexWriter(vdata, 'texcoord')

    for n in range(len(vertices)):
        v_vertex.addData3f(*vertices[n])
        if normals is not None: v_normals.addData3f(*normals[n])
        if colors is not None: v_colors.addData4f(*colors[n])
        if texcoords is not None: v_texcoords.addData2f(*texcoords[n])

    return Geom(vdata)
开发者ID:agoose77,项目名称:hivesystem,代码行数:31,代码来源:pandascene.py

示例3: __build_Patches

# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData2f [as 别名]
 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,代码行数:33,代码来源:model.py

示例4: __build_Tris

# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData2f [as 别名]
 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,代码行数:34,代码来源:model.py

示例5: make_square

# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData2f [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
开发者ID:viatoriche,项目名称:suber,代码行数:57,代码来源:support.py

示例6: makeSquare

# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData2f [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.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
开发者ID:zjusky,项目名称:python-gems,代码行数:55,代码来源:pycraft.py

示例7: make_square4v

# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData2f [as 别名]
def make_square4v(coord1, coord2, coord3, coord4, 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
    vertex.addData3f(coord1)
    vertex.addData3f(coord2)
    vertex.addData3f(coord3)
    vertex.addData3f(coord4)

    side1 = coord1 - coord2
    side2 = coord1 - coord4
    norm1 = side1.cross(side2)
    side1 = coord2 - coord3
    side2 = coord2 - coord4
    norm2 = side1.cross(side2)

    normal.addData3f(norm1)
    normal.addData3f(norm1)
    normal.addData3f(norm1)
    normal.addData3f(norm2)

    # 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.addVertex(0)
    tri1.addVertex(1)
    tri1.addVertex(3)

    tri1.addConsecutiveVertices(1, 3)

    tri1.closePrimitive()

    square = Geom(vdata)
    square.addPrimitive(tri1)

    return square
开发者ID:viatoriche,项目名称:suber,代码行数:53,代码来源:support.py

示例8: makeCircle

# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData2f [as 别名]
def makeCircle(vdata, numVertices=40,offset=Vec3(0,0,0), direction=1):
	circleGeom=Geom(vdata)

	vertWriter=GeomVertexWriter(vdata, "vertex")
	normalWriter=GeomVertexWriter(vdata, "normal")
	colorWriter=GeomVertexWriter(vdata, "color")
	uvWriter=GeomVertexWriter(vdata, "texcoord")
	drawWriter=GeomVertexWriter(vdata, "drawFlag")

	#make sure we start at the end of the GeomVertexData so we dont overwrite anything
	#that might be there already
	startRow=vdata.getNumRows()

	vertWriter.setRow(startRow)
	colorWriter.setRow(startRow)
	uvWriter.setRow(startRow)
	normalWriter.setRow(startRow)
	drawWriter.setRow(startRow)

	angle=2*math.pi/numVertices
	currAngle=angle

	for i in range(numVertices):
		position=Vec3(math.cos(currAngle)+offset.getX(), math.sin(currAngle)+offset.getY(),offset.getZ())
		vertWriter.addData3f(position)
		uvWriter.addData2f(position.getX()/2.0+0.5,position.getY()/2.0+0.5)
		colorWriter.addData4f(1.0, 1.0, 1.0, 1.0)
		position.setZ(position.getZ()*direction)
		position.normalize()
		normalWriter.addData3f(position)
		
		#at default Opengl only draws "front faces" (all shapes whose vertices are arranged CCW). We
		#need direction so we can specify which side we want to be the front face
		currAngle+=angle*direction

	circle=GeomTrifans(Geom.UHStatic)
	circle.addConsecutiveVertices(startRow, numVertices)
	circle.closePrimitive()

	circleGeom.addPrimitive(circle)
	
	return circleGeom
开发者ID:FelixBucket,项目名称:ToontownFritzServer,代码行数:44,代码来源:Tut-Fractal-Plants.py

示例9: makeSquare

# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData2f [as 别名]
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
开发者ID:btdevel,项目名称:bt,代码行数:41,代码来源:pd.py

示例10: reconstruct

# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData2f [as 别名]
	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)
开发者ID:aggronerd,项目名称:Crowd-Control,代码行数:41,代码来源:environment.py

示例11: update_nodepath

# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData2f [as 别名]
def update_nodepath(pandaNode, refinements):
    geom = pandaNode.modifyGeom(0)
    
    vertdata = geom.modifyVertexData()
    prim = geom.modifyPrimitive(0)
    indexdata = prim.modifyVertices()
    
    indexwriter = GeomVertexWriter(indexdata)
    indexwriter.setColumn(0)
    nextTriangleIndex = indexdata.getNumRows()
    
    vertwriter = GeomVertexWriter(vertdata, 'vertex')
    numverts = vertdata.getNumRows()
    vertwriter.setRow(numverts)
    normalwriter = GeomVertexWriter(vertdata, 'normal')
    normalwriter.setRow(numverts)
    uvwriter = GeomVertexWriter(vertdata, 'texcoord')
    uvwriter.setRow(numverts)
    
    for refinement in refinements:
        for op_index in range(len(refinement)):
            vals = refinement[op_index]
            op = vals[0]
            if op == PM_OP.TRIANGLE_ADDITION:
                indexwriter.setRow(nextTriangleIndex)
                nextTriangleIndex += 3
                indexwriter.addData1i(vals[1])
                indexwriter.addData1i(vals[2])
                indexwriter.addData1i(vals[3])
            elif op == PM_OP.INDEX_UPDATE:
                indexwriter.setRow(vals[1])
                indexwriter.setData1i(vals[2])
            elif op == PM_OP.VERTEX_ADDITION:
                numverts += 1
                vertwriter.addData3f(vals[1], vals[2], vals[3])
                normalwriter.addData3f(vals[4], vals[5], vals[6])
                uvwriter.addData2f(vals[7], vals[8])
开发者ID:jterrace,项目名称:open3dhub-panda3d-tests,代码行数:39,代码来源:python_impl.py

示例12: createBox

# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData2f [as 别名]
    def createBox(self):
        """
        Create the skybox GeomNode
        :return:
        """

        obj = ''
        obj += "# Skybox\n"
        obj += 'mtllib skybox.mtl\n'


        mtl = '# material for skybox\n'

        fmt = GeomVertexFormat.getV3n3t2()
        vdata = GeomVertexData('skybox', fmt, Geom.UHStatic)
        vdata.setNumRows(24)

        vertex = GeomVertexWriter(vdata, 'vertex')
        normals = GeomVertexWriter(vdata, 'normal')
        texcoord = GeomVertexWriter(vdata, 'texcoord')

        node = GeomNode('skybox')

        for normal in self.normals:
            geom = Geom(vdata)
            prim = GeomTriangles(Geom.UHStatic)

            idx = vertex.getWriteRow()

            verts = self.vertMappings[normal]
            tcs = self.getFaceMapping(normal)

            for v, t in zip(verts, tcs):
                vertex.addData3f(v[0]*2, v[1]*2, v[2]*2)
                normals.addData3f(normal)
                texcoord.addData2f(t)

                obj += 'v {0} {1} {2}\n'.format(v[0]*2, v[1]*2, v[2]*2)
                obj += 'vn {0} {1} {2}\n'.format(*normal)
                obj += 'vt {0} {1}\n'.format(*t)


            tex = self.getFaceTexture(normal)

            prim.addVertices(idx, idx + 1, idx + 3)
            prim.closePrimitive()

            obj += "usemtl {0}\n".format(tex.getName())
            obj += 'f {0}/{0} {1}/{1} {2}/{2}\n'.format(1+idx, 1+idx+1, 1+idx+3)

            prim.addVertices(idx + 1, idx + 2, idx + 3)
            prim.closePrimitive()

            obj += "usemtl {0}\n".format(tex.getName())
            obj += 'f {0}/{0} {1}/{1} {2}/{2}\n'.format(1+idx+1, 1+idx+2, 1+idx+3)

            geom.addPrimitive(prim)

            tex.setWrapU(Texture.WMMirror)
            tex.setWrapV(Texture.WMMirror)

            node.addGeom(geom, RenderState.make(TextureAttrib.make(tex)))


            mtl += "newmtl {0}\n".format(tex.getName())
            mtl += "Ka 1 1 1\n"
            mtl += "Kd 1 1 1\n"
            mtl += "map_Kd {0}\n".format(tex.getFilename().toOsSpecific())

        return node
开发者ID:eswartz,项目名称:panda3d-stuff,代码行数:72,代码来源:skybox.py

示例13: MeshGenerator

# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData2f [as 别名]
class MeshGenerator():
   
    def __init__(self, name = 'Mesh'):
       
        self.name = name
        self.finished = False
 
        self.format = GeomVertexFormat.getV3c4t2()
        #print self.format
        self.vertexData = GeomVertexData(name, self.format, Geom.UHStatic)
        self.vertexData.setNumRows(26136)
       
        self.mesh = Geom(self.vertexData)
        self.triangles = GeomTriangles(Geom.UHStatic)
        self.triangleData = self.triangles.modifyVertices()
        self.triangleData.setNumRows(26136)
       
        self.vertex = GeomVertexWriter(self.vertexData, 'vertex')
        self.normal = GeomVertexWriter(self.vertexData, 'normal')
        self.color = GeomVertexWriter(self.vertexData, 'color')
        self.texcoord = GeomVertexWriter(self.vertexData, 'texcoord')
       
        self.faceCount = 0
   
    def makeFace(self, x1, y1, z1, x2, y2, z2, id, color):
       
        if x1 != x2:
       
            self.vertex.addData3f(x1, y1, z1)
            self.vertex.addData3f(x2, y1, z1)
            self.vertex.addData3f(x2, y2, z2)
            self.vertex.addData3f(x1, y2, z2)
           
        else:
       
            self.vertex.addData3f(x1, y1, z1)
            self.vertex.addData3f(x2, y2, z1)
            self.vertex.addData3f(x2, y2, z2)
            self.vertex.addData3f(x1, y1, z2)
 
 
        self.color.addData4f(color, color, color, 1.0)
        self.color.addData4f(color, color, color, 1.0)
        self.color.addData4f(color, color, color, 1.0)
        self.color.addData4f(color, color, color, 1.0)
       
        if id == 1:
            self.texcoord.addData2f(0.0, 0.5)
            self.texcoord.addData2f(0.0, 0.0)
            self.texcoord.addData2f(0.25, 0.0)
            self.texcoord.addData2f(0.25, 0.5)
        elif id == 2:
            self.texcoord.addData2f(0.25, 0.5)
            self.texcoord.addData2f(0.25, 0.0)
            self.texcoord.addData2f(0.5, 0.0)
            self.texcoord.addData2f(0.5, 0.5)
        elif id == 3:
            self.texcoord.addData2f(0.5, 0.5)
            self.texcoord.addData2f(0.5, 0.0)
            self.texcoord.addData2f(0.75, 0.0)
            self.texcoord.addData2f(0.75, 0.5)
        elif id == 4:
            self.texcoord.addData2f(0.75, 0.5)
            self.texcoord.addData2f(0.75, 0.0)
            self.texcoord.addData2f(1.0, 0.0)
            self.texcoord.addData2f(1.0, 0.5)
        elif id == 5:
            self.texcoord.addData2f(0.0, 1.0)
            self.texcoord.addData2f(0.0, 0.5)
            self.texcoord.addData2f(0.25, 0.5)
            self.texcoord.addData2f(0.25, 1.0)
        elif id == 6:
            self.texcoord.addData2f(0.25, 1.0)
            self.texcoord.addData2f(0.25, 0.5)
            self.texcoord.addData2f(0.5, 0.5)
            self.texcoord.addData2f(0.5, 1.0)
       
        vertexId = self.faceCount * 4
       
        self.triangles.addVertices(vertexId, vertexId + 1, vertexId + 3)
        self.triangles.addVertices(vertexId + 1, vertexId + 2, vertexId + 3)
       
        self.faceCount += 1
   
    def makeFrontFace(self, x, y, z, id):
        self.makeFace(x + 1, y + 1, z - 1, x, y + 1, z, id, 0.6)
   
    def makeBackFace(self, x, y, z, id):
        self.makeFace(x, y, z - 1, x + 1, y, z, id, 0.85)
   
    def makeRightFace(self, x, y, z, id):
        self.makeFace(x + 1, y, z - 1, x + 1, y + 1, z, id, 1.0)
   
    def makeLeftFace(self, x, y, z, id):
        self.makeFace(x, y + 1, z - 1, x, y, z, id, 0.9)
   
    def makeTopFace(self, x, y, z, id):
        self.makeFace(x + 1, y + 1, z, x, y, z, id, 1.0)
   
    def makeBottomFace(self, x, y, z, id):
#.........这里部分代码省略.........
开发者ID:nano13,项目名称:simulacron,代码行数:103,代码来源:meshgenerator.py

示例14: __init__

# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData2f [as 别名]
 def __init__(self):
 
     self.textures={}
     for k in texMap:
         v=texMap[k]
         tex=loader.loadTexture("gfx/%s"%v)
         tex.setWrapU(Texture.WM_clamp)
         tex.setWrapV(Texture.WM_clamp)
         self.textures[k]=tex
     
     self.viewPoint=(0,0,0)
     self.cubeVtxSrc=[
         # 14 vertices per cube mapped
         # so that UV coords utilize
         # the typical cube unwrap:
         #
         #   ####  <-- square texture
         #   ##U#
         #   BLFR
         #   ##D#    #=unused
         #
         # This form uses 14 vertices per cube since
         # the extra (worldspace overlapped) vertices
         # map different U,V coordinates at the same
         # worldspace coordinates, depending on face
         #   
         # x    y    z    u    v
         (1.00,1.00,1.00,0.00,0.50), # A
         (1.00,1.00,0.00,0.00,0.25), # B
         (0.00,1.00,1.00,0.25,0.50), # C
         (0.00,1.00,0.00,0.25,0.25), # D
         (0.00,0.00,1.00,0.50,0.50), # E
         (0.00,0.00,0.00,0.50,0.25), # F
         (1.00,0.00,1.00,0.75,0.50), # G
         (1.00,0.00,0.00,0.75,0.25), # H
         (1.00,1.00,1.00,1.00,0.50), # I
         (1.00,1.00,0.00,1.00,0.25), # J
         (0.00,1.00,1.00,0.50,0.75), # K
         (1.00,1.00,1.00,0.75,0.75), # L
         (0.00,1.00,0.00,0.50,0.00), # M
         (1.00,1.00,0.00,0.75,0.00)  # N
         ]
     self.triSrc=[
         #
         #  Faces (QUAD/TRIPAIR)
         #  using RHR vertex ordering for
         #  correct face surface normals
         #
         #    front: EFHG/EFH+HGE
         #     rear: CABD/CAB+BDC
         #     left: CDFE/CDF+FEC
         #    right: GHJI/GHJ+JIG
         #    upper: KEGL/KEG+GLK
         #    lower: FMNH/FMN+NHF
         #
         "EFH","HGE",
         "CAB","BDC",
         "CDF","FEC",
         "GHJ","JIG",
         "KEG","GLK",
         "FMN","NHF"
         ]
     #
     # setup cube
     #
     # one cube node will be generated per non-air block
     # since different block id's potentially refer to
     # different textures and thus must be separate nodes
     # of the scene graph.
     #
     #   1. vertices
     self.cubeVtx=GeomVertexData('blockCube',GeomVertexFormat.getV3t2(),Geom.UHStatic)
     self.cubeVtx.setNumRows(len(self.cubeVtxSrc))
     vtxW=GeomVertexWriter(self.cubeVtx,'vertex')
     txcW=GeomVertexWriter(self.cubeVtx,'texcoord')
     for vertex in self.cubeVtxSrc:
         vtxW.addData3f(*vertex[0:3])
         txcW.addData2f(*vertex[3:5])
     #   2. mesh
     self.cubeMesh=GeomTriangles(Geom.UHStatic)
     for tri in self.triSrc:
         for triV in tri:
             triVtxId=ord(triV)-65 # changea 'A'-'N' to 0-13
             self.cubeMesh.addVertex(triVtxId)
         self.cubeMesh.close_primitive()
     #   3. geometry (primitive+vertex pair)
     self.cubeGeom=Geom(self.cubeVtx)
     self.cubeGeom.addPrimitive(self.cubeMesh)
开发者ID:gau-veldt,项目名称:Blockiverse,代码行数:90,代码来源:__init__.py

示例15: make_square

# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import addData2f [as 别名]
def make_square(sq_color):
    # sq_color is a list of tuples, describing each vertex:
    # (r, g, b, a) for [bl, br, tr, tl]
    x1 = -1
    y1 = -1
    z1 = -1
    x2 = 1
    y2 = -1
    z2 = 1
    v_format = GeomVertexFormat.getV3n3cpt2()
    v_data = GeomVertexData('square', v_format, Geom.UHDynamic)

    vertex = GeomVertexWriter(v_data, 'vertex')
    normal = GeomVertexWriter(v_data, 'normal')
    color = GeomVertexWriter(v_data, 'color')
    tex_coord = GeomVertexWriter(v_data, '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)
    color.addData4f(sq_color[0])  # (0, 0) bottom left
    color.addData4f(sq_color[1])  # (0.5, 0) bottom right
    color.addData4f(sq_color[2])  # (0.5, 0.5) top right
    color.addData4f(sq_color[3])  # (0, 0.5) top left

    tex_coord.addData2f(0.0, 1.0)
    tex_coord.addData2f(0.0, 0.0)
    tex_coord.addData2f(1.0, 0.0)
    tex_coord.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(v_data)
    square.addPrimitive(tris)
    return square
开发者ID:codedragon,项目名称:color_world,代码行数:67,代码来源:square.py


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