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


Python GeomVertexFormat.getV3n3c4方法代码示例

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


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

示例1: regesterGeomRequirements

# 需要导入模块: from panda3d.core import GeomVertexFormat [as 别名]
# 或者: from panda3d.core.GeomVertexFormat import getV3n3c4 [as 别名]
    def regesterGeomRequirements(self, LOD, collection):

        n = NodePath("tmp")

        if self.barkTexture is not None:
            n.setTexture(self.barkTexture)
            n.setShaderInput("diffTex", self.barkTexture)
            format = GeomVertexFormat.getV3n3t2()
        else:
            format = GeomVertexFormat.getV3n3()
            n.setColor(0.4, 0.3, 0.3, 1)

        # n.setShader(customLoader.makeShader(n))

        trunkRequirements = meshManager.GeomRequirements(geomVertexFormat=format, renderState=n.getState())

        n = NodePath("tmp")

        if self.leafTexture is not None:
            # n.setTag("alpha","")
            n.setShaderInput("alpha", 0, 0, 0)  # marker we need cutout alpha
            n.setTexture(self.leafTexture)
            n.setShaderInput("diffTex", self.leafTexture)
            format = GeomVertexFormat.getV3n3t2()
        else:
            format = GeomVertexFormat.getV3n3c4()

        # n.setShader(customLoader.makeShader(n,debugCodePrefix="tree",debugGraphPrefix="tree"))

        leafRequirements = meshManager.GeomRequirements(geomVertexFormat=format, renderState=n.getState())

        self.trunkDataIndex[LOD] = collection.add(trunkRequirements)
        self.leafDataIndex[LOD] = collection.add(leafRequirements)
开发者ID:rasrenato,项目名称:Panda3D-Terrain-System,代码行数:35,代码来源:treeFactory.py

示例2: add_plane

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

示例3: create_geom

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

示例4: __init__

# 需要导入模块: from panda3d.core import GeomVertexFormat [as 别名]
# 或者: from panda3d.core.GeomVertexFormat import getV3n3c4 [as 别名]
    def __init__(self, name = 'Mesh'):
        '''
        Constructor
        '''
        self.name = name
        self.finished = False

        self.format = GeomVertexFormat.getV3n3c4()
        self.vertexData = GeomVertexData(name, self.format, Geom.UHStream)

        self.mesh = Geom(self.vertexData)
        self.triangles = GeomTriangles(Geom.UHStream)
        self.triangleData = self.triangles.modifyVertices()

        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
开发者ID:deltasquad451,项目名称:Brickfield,代码行数:22,代码来源:CubeModelGenerator.py

示例5: __init__

# 需要导入模块: from panda3d.core import GeomVertexFormat [as 别名]
# 或者: from panda3d.core.GeomVertexFormat import getV3n3c4 [as 别名]
    def __init__(self, point, vertices, map_width=1024, map_height=1024, base=0.0):
        self.point = point
        # TODO: Sort these clockwise (they still are 2D points)
# http://stackoverflow.com/questions/6989100/sort-points-in-clockwise-order
        # Might just need to reverse if the wrong way. I think they're already
        # ordered. Should be able to tell by checking the normal calculation.
        self.vertices = vertices

        # Ensure that stuff is working correctly
        if [-10.101, -10.101] in vertices:
            raise ValueError("Can't create this region.")

        # TODO: Constrain the bounds like this... though it's somewhat busted.
        # for i, v in enumerate(vertices):
        #     x, y = v
        #     x = max(min(x, map_width/2), -map_width/2)
        #     y = max(min(y, map_height/2), -map_height/2)
        #     vertices[i] = (x, y)

        for v in vertices:
            if not (-map_width/2 <= v[0] <= map_width/2 and
                    -map_height/2 <= v[1] <= map_height/2):
                raise ValueError("Can't create this region.")

        # 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
        # TODO: Migrate to Tristrips.
        # TODO: Make walls, floors (and ceilings?)
        prim = GeomTrifans(Geom.UHStatic)

        DETAIL = 128
        HEIGHT_SCALE = 20
        vertices = [
            (v[0], v[1], snoise2(
                v[0]/DETAIL, v[1]/DETAIL, base=base,
                persistence=0.5, lacunarity=2.0,
                repeatx=map_width/4, repeaty=map_height/4,
                octaves=5) * HEIGHT_SCALE)
            for v in vertices]

        num_high = len(list(filter(lambda x: x[2] > HEIGHT_SCALE * 0.4, vertices)))
        num_above = len(list(filter(lambda x: HEIGHT_SCALE * 0.4 > x[2] > 0, vertices)))
        num_below = len(list(filter(lambda x: x[2] <= 0, vertices)))
        num_deep = len(list(filter(lambda x: x[2] < -HEIGHT_SCALE * 0.2, vertices)))

        # Calculate the color:
        #  * White if high altitude
        #  * Green if land
        #  * Tan if coast
        #  * Blue if water
        #  * Dark Blue if deep water
        # poly_color = (uniform(0, 1), uniform(0, 1), uniform(0, 1), 1, )
        if num_high:
            white = uniform(0.7, 1.0)
            poly_color = (white, white, white, 1.0)
        elif num_below and num_above:
            yellow = uniform(0.5, 1.0)
            poly_color = (yellow, yellow, 0.0, 1.0)
        elif num_deep:
            poly_color = (0.0, 0.0, uniform(0.5, 1.0), 1.0)
        elif num_below:
            poly_color = (0.3, 0.3, uniform(0.5, 1.0), 1.0)
        else:
            poly_color = (0.0, uniform(0.5, 1.0), 0.0, 1.0)

        for i, point in enumerate(vertices):
            vertex.addData3f(point[0], point[1], max(point[2], 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)
开发者ID:pennomi,项目名称:voronoi-terrain,代码行数:90,代码来源:terrain.py

示例6: generate

# 需要导入模块: from panda3d.core import GeomVertexFormat [as 别名]
# 或者: from panda3d.core.GeomVertexFormat import getV3n3c4 [as 别名]
    def generate(self, terrain, size, lod=1.0):
        if self.meshgentype == "marching":
            mesher = MarchingCubes()
        elif self.meshgentype == "dual":
            mesher = DualContour(noise=manager.get('noise'))
        else:
            mesher = Voxel()

        triangles = mesher.generateMesh(terrain, size, lod)

        #format = GeomVertexFormat.registerFormat(GeomVertexFormat.getV3n3c4t2())
        format = GeomVertexFormat.registerFormat(GeomVertexFormat.getV3n3c4())
        vdata = GeomVertexData('chunk_mesh', format, Geom.UHStatic)

        vertex = GeomVertexWriter(vdata, 'vertex')
        normal = GeomVertexWriter(vdata, 'normal')
        color = GeomVertexWriter(vdata, 'color')
        texcoord = GeomVertexWriter(vdata, 'texcoord')
        prim = GeomTriangles(Geom.UHStatic)

        vertexcount = 0
        for triangle in triangles:
            for avertex in triangle:
                #print triangle
                #make vertices here
                shade = 0.5
                vertex.addData3f(avertex[0], avertex[1], avertex[2])
                #fix normals
                x1, y1, z1 = triangle[0][0], triangle[0][1], triangle[0][2]
                x2, y2, z2 = triangle[1][0], triangle[1][1], triangle[1][2]
                x3, y3, z3 = triangle[2][0], triangle[2][1], triangle[2][2]
                normx = (z1 - z2) * (y3 - y2) - (y1 - y2) * (z3 - z2)
                normy = (x1 - x2) * (z3 - z2) - (z1 - z2) * (x3 - x2)
                normz = (y1 - y2) * (x3 - x2) - (x1 - x2) * (y3 - y2)
                normlength = math.sqrt(normx ** 2 + normy ** 2 + normz ** 2)
                if normlength != 0:
                    normx /= normlength
                    normy /= normlength
                    normz /= normlength
                normal.addData3f(normx, normy, normz)
                color.addData4f(shade, shade, shade, 1)
                #color.addData4f(random.randrange(0,255), random.randrange(0,255), random.randrange(0,255), 1)
                #texcoord.addData2f(triangle[0][0] / 16, triangle[0][1] / 16)
                #texcoord.addData2f(0, 1)

            #make triangles
            prim.addVertices(vertexcount, vertexcount + 1, vertexcount + 2)
            prim.closePrimitive()
            vertexcount += 3

        #print prim
        #attach primitives and render
        geom = Geom(vdata)
        geom.addPrimitive(prim)

        """try:
            self.node.removeNode()
            self.bulletnode.removeShape(self.bulletshape)
            self.root.bulletworld.removeRigidBody(self.bulletnode)
            self.bulletnp.removeNode()
        except AttributeError:
            pass"""

        node = GeomNode("terrainmesh")
        node.addGeom(geom)
        return node

        #self.meshed = True

        """#do bullet meshing
开发者ID:gamingrobot,项目名称:second-sunrise,代码行数:72,代码来源:meshgeneration.py

示例7: GeomTriangles

# 需要导入模块: from panda3d.core import GeomVertexFormat [as 别名]
# 或者: from panda3d.core.GeomVertexFormat import getV3n3c4 [as 别名]

from direct.showbase.ShowBase import ShowBase
from direct.task import Task
from direct.actor.Actor import Actor
from direct.interval.IntervalGlobal import Sequence
from panda3d.core import Point3
from panda3d.core import Geom, GeomVertexFormat, GeomVertexData, GeomVertexWriter, GeomNode, GeomTriangles
from math import pi, sin, cos


um = pymetasurf.UnitMetaball()
um.set_resolution(40,40,40)
um.set_bounds(-3, -3, -3, 3, 3, 3)
um.polygonize()
format=GeomVertexFormat.getV3n3c4()
vdata=GeomVertexData("vertices", format, Geom.UHStatic)
vertexWriter=GeomVertexWriter(vdata, "vertex")
for p in um.tri_list:
    vertexWriter.addData3f(p[0],p[1],p[2])
normalWriter=GeomVertexWriter(vdata, "normal")
for p in um.normal_list:
    normalWriter.addData3f(p[0],p[1],p[2])

colorWriter=GeomVertexWriter(vdata, "color")
for p in um.tri_list:
    colorWriter.addData4f(1.0 - (p[0] * 0.1),1.0 - (p[1] * 0.1), 1.0 - (p[2] * 0.1),1.0)

tris = GeomTriangles(Geom.UHStatic)
tris.addConsecutiveVertices(0, len(um.tri_list))
tris.closePrimitive()
开发者ID:chaomodus,项目名称:pymetasurf,代码行数:32,代码来源:unitmetaball.py


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