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


Python GeomVertexWriter.addData4f方法代码示例

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


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

示例1: draw

# 需要导入模块: from pandac.PandaModules import GeomVertexWriter [as 别名]
# 或者: from pandac.PandaModules.GeomVertexWriter import addData4f [as 别名]
 def draw(self):
     format=GeomVertexFormat.getV3n3cpt2()
     vdata=GeomVertexData('square', format, Geom.UHDynamic)
     vertex=GeomVertexWriter(vdata, 'vertex')
     normal=GeomVertexWriter(vdata, 'normal')
     color=GeomVertexWriter(vdata, 'color')
     circle=Geom(vdata)
     # Create vertices
     vertex.addData3f(self.pos)
     color.addData4f(self.color)
     for v in range(self._EDGES):
         x = self.pos.getX() + (self.size * math.cos((2*math.pi/self._EDGES)*v))
         y = self.pos.getY() + (self.size * math.sin((2*math.pi/self._EDGES)*v))
         z = self.pos.getZ()
         vertex.addData3f(x, y, z)
         color.addData4f(self.color)
     
     # Create triangles
     for t in range(self._EDGES):
         tri = GeomTriangles(Geom.UHDynamic)
         tri.addVertex(0)
         tri.addVertex(t+1)
         if (t+2) > self._EDGES:
             tri.addVertex(1)
         else:
             tri.addVertex(t+2)
         tri.closePrimitive()
         circle.addPrimitive(tri)
     
     gn = GeomNode('Circle')
     gn.addGeom(circle)
     np = NodePath(gn)
     np.setHpr(0, 90, 0)
     return np
开发者ID:crempp,项目名称:Fire-Water,代码行数:36,代码来源:GeomObjects.py

示例2: drawSquare

# 需要导入模块: from pandac.PandaModules import GeomVertexWriter [as 别名]
# 或者: from pandac.PandaModules.GeomVertexWriter import addData4f [as 别名]
	def drawSquare(self, x1,y1,z1, x2,y2,z2):
		format=GeomVertexFormat.getV3n3cpt2()
		vdata=GeomVertexData('square', format, Geom.UHStatic)
		
		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.addData3f(x1, y1, z1)
		vertex.addData3f(x2, y1, z1)
		vertex.addData3f(x2, y2, z2)
		vertex.addData3f(x1, y2, z2)

		normal.addData3f(self.myNormalize(Vec3(2*x1-1, 2*y1-1, 2*z1-1)))
		normal.addData3f(self.myNormalize(Vec3(2*x2-1, 2*y1-1, 2*z1-1)))
		normal.addData3f(self.myNormalize(Vec3(2*x2-1, 2*y2-1, 2*z2-1)))
		normal.addData3f(self.myNormalize(Vec3(2*x1-1, 2*y2-1, 2*z2-1)))
		
		#adding different colors to the vertex for visibility
		color.addData4f(0.0,0.5,0.0,0.5)
		color.addData4f(0.0,0.5,0.0,0.5)
		color.addData4f(0.0,0.5,0.0,0.5)
		color.addData4f(0.0,0.5,0.0,0.5)
		
		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 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)
		#square.setIntoCollideMask(BitMask32.bit(1))
		
		squareNP = NodePath(GeomNode('square gnode')) 
		squareNP.node().addGeom(square)
		squareNP.setTransparency(1) 
		squareNP.setAlphaScale(.5) 
		squareNP.setTwoSided(True)
		squareNP.setCollideMask(BitMask32.bit(1))
		return squareNP
开发者ID:crempp,项目名称:psg,代码行数:61,代码来源:Grid.py

示例3: _create_vertex_data

# 需要导入模块: from pandac.PandaModules import GeomVertexWriter [as 别名]
# 或者: from pandac.PandaModules.GeomVertexWriter import addData4f [as 别名]
    def _create_vertex_data(self):
        """Creates and fills the vertex data store."""
        format = GeomVertexFormat.getV3c4()
        vdata = GeomVertexData('cloud', format, Geom.UHDynamic)

        vertex = GeomVertexWriter(vdata, 'vertex')
        color = GeomVertexWriter(vdata, 'color')

        for point, value in self._points.iteritems():
            vertex.addData3f(point[0], point[1], value)
            color.addData4f(*self._color)

        self._vdata = vdata
开发者ID:weltenwort,项目名称:uni_cg2,代码行数:15,代码来源:surface.py

示例4: makeCircle

# 需要导入模块: from pandac.PandaModules import GeomVertexWriter [as 别名]
# 或者: from pandac.PandaModules.GeomVertexWriter import addData4f [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:juancq,项目名称:character-evolver,代码行数:44,代码来源:Tut-Fractal-Plants.py

示例5: _create_vertex_data

# 需要导入模块: from pandac.PandaModules import GeomVertexWriter [as 别名]
# 或者: from pandac.PandaModules.GeomVertexWriter import addData4f [as 别名]
    def _create_vertex_data(self):
        """Creates and fills the vertex data store."""
        format = GeomVertexFormat.getV3n3cp()
        vdata = GeomVertexData("surface", format, Geom.UHDynamic)
        tri = GeomTriangles(Geom.UHDynamic)

        vertex = GeomVertexWriter(vdata, "vertex")
        normal = GeomVertexWriter(vdata, "normal")
        color = GeomVertexWriter(vdata, "color")

        for triangle in self._halfedge_mesh.faces:
            for v in triangle.iter_vertices():
                vertex.addData3f(*v.coordinates)
                normal.addData3f(*v.normal)
                color.addData4f(*self._color)
                tri.addNextVertices(1)

        self._vdata = vdata
        tri.closePrimitive()
        self._geom_primitives = [tri]
开发者ID:weltenwort,项目名称:uni_cg2,代码行数:22,代码来源:halfedge.py

示例6: create_table_geom

# 需要导入模块: from pandac.PandaModules import GeomVertexWriter [as 别名]
# 或者: from pandac.PandaModules.GeomVertexWriter import addData4f [as 别名]
def create_table_geom():
    format = GeomVertexFormat.getV3n3c4t2()
    # GeomVertexData. 
    vdata = GeomVertexData('table_vertex', format, Geom.UHStatic)
    
    vertex = GeomVertexWriter(vdata, 'vertex')
    normal = GeomVertexWriter(vdata, 'normal')
    color = GeomVertexWriter(vdata, 'color')
    texcoord = GeomVertexWriter(vdata, 'texcoord')

    vertex.addData3f(xmax, ymin, 0)
    normal.addData3f(0, 0, 1)
    color.addData4f(0, 0, 1, 1)
    texcoord.addData2f(1, 0)
    
    vertex.addData3f(xmax, ymax, 0)
    normal.addData3f(0, 0, 1)
    color.addData4f(0, 0, 1, 1)
    texcoord.addData2f(1, 1)
    
    vertex.addData3f(xmin, ymax, 0)
    normal.addData3f(0, 0, 1)
    color.addData4f(0, 0, 1, 1)
    texcoord.addData2f(0, 1)
    
    vertex.addData3f(xmin, ymin, 0)
    normal.addData3f(0, 0, 1)
    color.addData4f(0, 0, 1, 1)
    texcoord.addData2f(0, 0)
    
    prim = GeomTriangles(Geom.UHStatic)
    prim.addVertex(0)
    prim.addVertex(1)
    prim.addVertex(2)
    prim.closePrimitive()
    
    prim.addVertex(0)
    prim.addVertex(2)
    prim.addVertex(3)
    prim.closePrimitive()

    geom = Geom(vdata)
    geom.addPrimitive(prim)
    return geom
开发者ID:hugomatic,项目名称:Kepler,代码行数:46,代码来源:kepler_sim.py

示例7: draw_body

# 需要导入模块: from pandac.PandaModules import GeomVertexWriter [as 别名]
# 或者: from pandac.PandaModules.GeomVertexWriter import addData4f [as 别名]
  def draw_body(self, position, vector_list, radius = 1, keep_drawing = True, num_vertices = 8):
    circle_geom = Geom(self.vdata)

    vertex_writer = GeomVertexWriter(self.vdata, "vertex")
    color_writer = GeomVertexWriter(self.vdata, "color")
    normal_writer = GeomVertexWriter(self.vdata, "normal")
    draw_rewriter = GeomVertexRewriter(self.vdata, "drawFlag")
    tex_rewriter = GeomVertexRewriter(self.vdata, "texcoord")

    start_row = self.vdata.getNumRows()
    vertex_writer.setRow(start_row)
    color_writer.setRow(start_row)
    normal_writer.setRow(start_row)

    sCoord = 0

    if start_row != 0:
      tex_rewriter.setRow(start_row - num_vertices)
      sCoord = tex_rewriter.getData2f().getX() + 1

      draw_rewriter.setRow(start_row - num_vertices)
      if draw_rewriter.getData1f() == False:
        sCoord -= 1

    draw_rewriter.setRow(start_row)
    tex_rewriter.setRow(start_row)

    angle_slice = 2 * math.pi / num_vertices
    current_angle = 0

    perp1 = vector_list[1]
    perp2 = vector_list[2]

    # write vertex information
    for i in range(num_vertices):
      adjacent_circle = position + (perp1 * math.cos(current_angle) + perp2 * math.sin(current_angle)) * radius
      normal = perp1 * math.cos(current_angle) + perp2 * math.sin(current_angle)
      normal_writer.addData3f(normal)
      vertex_writer.addData3f(adjacent_circle)
      tex_rewriter.addData2f(sCoord, (i + 0.001) / (num_vertices - 1))
      color_writer.addData4f(0.5, 0.5, 0.5, 1.0)
      draw_rewriter.addData1f(keep_drawing)
      current_angle += angle_slice

    draw_reader = GeomVertexReader(self.vdata, "drawFlag")
    draw_reader.setRow(start_row - num_vertices)

    # we can't draw quads directly so use Tristrips
    if start_row != 0 and draw_reader.getData1f() != False:
      lines = GeomTristrips(Geom.UHStatic)
      half = int(num_vertices * 0.5)
      for i in range(num_vertices):
        lines.addVertex(i + start_row)
        if i < half:
          lines.addVertex(i + start_row - half)
        else:
          lines.addVertex(i + start_row - half - num_vertices)

      lines.addVertex(start_row)
      lines.addVertex(start_row - half)
      lines.closePrimitive()
      lines.decompose()
      circle_geom.addPrimitive(lines)

      circle_geom_node = GeomNode("Debug")
      circle_geom_node.addGeom(circle_geom)

      circle_geom_node.setAttrib(CullFaceAttrib.makeReverse(), 1)

      self.get_model().attachNewNode(circle_geom_node)
开发者ID:KingAbbott,项目名称:devsyn,代码行数:72,代码来源:simple.py

示例8: make_layer

# 需要导入模块: from pandac.PandaModules import GeomVertexWriter [as 别名]
# 或者: from pandac.PandaModules.GeomVertexWriter import addData4f [as 别名]
  def make_layer(self, i, a, b):
    # get data
    data = self.subdata[a][b]

    # set color + alpha of vertex texture
    def ap(n):
      alpha = 0
      if i == n:
        alpha = 1.0
      return alpha
    def tp(n):
      list = [0, 0, 0, 0]
      if i == n:
        list = [1, 1, 1, 0.75]
      return list

    # set vertex data
    vdata = GeomVertexData('plane', GeomVertexFormat.getV3n3c4t2(), Geom.UHStatic)
    vertex = GeomVertexWriter(vdata, 'vertex')
    normal = GeomVertexWriter(vdata, 'normal')
    color = GeomVertexWriter(vdata, 'color')
    uv = GeomVertexWriter(vdata, 'texcoord')

    # set vertices
    number = 0
    for x in range(0, len(data) - 1):
      for y in range(0, len(data[x]) - 1):
        # get vertex data
        v1 = Vec3(x, y, data[x][y]['h'])
        c1 = data[x][y]['c']
        t1 = data[x][y]['texnum']
        v2 = Vec3(x+1, y, data[x+1][y]['h'])
        c2 = data[x+1][y]['c']
        t2 = data[x+1][y]['texnum']
        v3 = Vec3(x+1, y+1, data[x+1][y+1]['h'])
        c3 = data[x+1][y+1]['c']
        t3 = data[x+1][y+1]['texnum']
        v4 = Vec3(x, y+1, data[x][y+1]['h'])
        c4 = data[x][y+1]['c']
        t4 = data[x][y+1]['texnum']
        n=(0, 0, 1) # normal

        # assign vertex colors + alpha
        a1, a2, a3, a4 = ap(t1), ap(t2), ap(t3), ap(t4)
        t1, t2, t3, t4 = tp(t1), tp(t2), tp(t3), tp(t4)

        if v1[2]==0:
          t1 = [data[x][y]['c'][0], data[x][y]['c'][1], data[x][y]['c'][2],
                a1]
        if v2[2]==0:
          t2 = [data[x+1][y]['c'][0], data[x+1][y]['c'][1],
                data[x+1][y]['c'][2], a2]
        if v3[2]==0:
          t3 = [data[x+1][y+1]['c'][0], data[x+1][y+1]['c'][1],
                data[x+1][y+1]['c'][2], a3]
        if v4[2]==0:
          t4 = [data[x][y+1]['c'][0], data[x][y+1]['c'][1],
                data[x][y+1]['c'][2], a4]

        if a1 == 0 and a2 == 0 and a3 == 0 and a4 == 0:
          continue

        # add vertices
        vertex.addData3f(v1)
        normal.addData3f(*n)
        color.addData4f(*t1)
        uv.addData2f(0,0)

        vertex.addData3f(v2)
        normal.addData3f(*n)
        color.addData4f(*t2)
        uv.addData2f(1,0)

        vertex.addData3f(v3)
        normal.addData3f(*n)
        color.addData4f(*t3)
        uv.addData2f(1,1)

        vertex.addData3f(v1)
        normal.addData3f(*n)
        color.addData4f(*t1)
        uv.addData2f(0,0)

        vertex.addData3f(v3)
        normal.addData3f(*n)
        color.addData4f(*t3)
        uv.addData2f(1,1)

        vertex.addData3f(v4)
        normal.addData3f(*n)
        color.addData4f(*t4)
        uv.addData2f(0,1)

        number = number + 2

    # add triangles
    prim = GeomTriangles(Geom.UHStatic)
    for n in range(number):
      prim.addVertices((n * 3) + 2, (n * 3) + 0, (n * 3) + 1)
    prim.closePrimitive()
#.........这里部分代码省略.........
开发者ID:asceth,项目名称:devsyn,代码行数:103,代码来源:terrain.py

示例9: make_base

# 需要导入模块: from pandac.PandaModules import GeomVertexWriter [as 别名]
# 或者: from pandac.PandaModules.GeomVertexWriter import addData4f [as 别名]
  def make_base(self, a, b):
    # get data
    data = self.subdata[a][b]
    # set vertex data
    vdata = GeomVertexData('plane', GeomVertexFormat.getV3n3c4t2(), Geom.UHStatic)
    vertex = GeomVertexWriter(vdata, 'vertex')
    normal = GeomVertexWriter(vdata, 'normal')
    color = GeomVertexWriter(vdata, 'color')
    uv = GeomVertexWriter(vdata, 'texcoord')

    # set vertices
    number = 0
    for x in range(0, len(data) - 1):
      for y in range(0, len(data[x]) - 1):
        # get vertex data
        v1 = Vec3(x, y, data[x][y]['h'])
        v2 = Vec3(x + 1, y, data[x+1][y]['h'])
        v3 = Vec3(x + 1, y + 1, data[x+1][y+1]['h'])
        v4 = Vec3(x, y + 1, data[x][y+1]['h'])
        n = (0, 0, 1) # normal

        # assign vertex colors + alpha
        option = 1 # black
        if option == 1:
          c = 0
          c1 = [c, c, c, 1]
          c2 = [c, c, c, 1]
          c3 = [c, c, c, 1]
          c4 = [c, c, c, 1]
        # option2: color vertices
        if option == 2:
          alpha = 1.0
          c1 = [data[x][y]['c'][0], data[x][y]['c'][1],
                data[x][y]['c'][2], alpha]
          c2 = [data[x+1][y]['c'][0], data[x+1][y]['c'][1],
                data[x+1][y]['c'][2], alpha]
          c3 = [data[x+1][y+1]['c'][0], data[x+1][y+1]['c'][1],
                data[x+1][y+1]['c'][2], alpha]
          c4 = [data[x][y+1]['c'][0], data[x][y+1]['c'][1],
                data[x][y+1]['c'][2], alpha]

        if option == 3:
          c1 = self.color_vertex(v1)
          c2 = self.color_vertex(v2)
          c3 = self.color_vertex(v3)
          c4 = self.color_vertex(v4)

        vertex.addData3f(v1)
        normal.addData3f(*n)
        color.addData4f(*c1)
        uv.addData2f(0,0)

        vertex.addData3f(v2)
        normal.addData3f(*n)
        color.addData4f(*c2)
        uv.addData2f(1,0)

        vertex.addData3f(v3)
        normal.addData3f(*n)
        color.addData4f(*c3)
        uv.addData2f(1,1)

        vertex.addData3f(v1)
        normal.addData3f(*n)
        color.addData4f(*c1)
        uv.addData2f(0,0)

        vertex.addData3f(v3)
        normal.addData3f(*n)
        color.addData4f(*c3)
        uv.addData2f(1,1)

        vertex.addData3f(v4)
        normal.addData3f(*n)
        color.addData4f(*c4)
        uv.addData2f(0,1)

#         # add vertex h
#         vertex.addData3f(v1)
#         # normal.addData3f(*n)
#         vertex.addData3f(v2)
#         # normal.addData3f(*n)
#         vertex.addData3f(v3)
#         # normal.addData3f(*n)
#         vertex.addData3f(v1)
#         # normal.addData3f(*n)
#         vertex.addData3f(v3)
#         # normal.addData3f(*n)
#         vertex.addData3f(v4)
#         # normal.addData3f(*n)
#         # add vertex color
#         color.addData4f(*c1)
#         color.addData4f(*c2)
#         color.addData4f(*c3)
#         color.addData4f(*c1)
#         color.addData4f(*c3)
#         color.addData4f(*c4)

        # iterate
        number = number + 2
#.........这里部分代码省略.........
开发者ID:asceth,项目名称:devsyn,代码行数:103,代码来源:terrain.py

示例10: _create_vertex_data

# 需要导入模块: from pandac.PandaModules import GeomVertexWriter [as 别名]
# 或者: from pandac.PandaModules.GeomVertexWriter import addData4f [as 别名]
    def _create_vertex_data(self):
        """Creates and fills the vertex data store."""
        format = GeomVertexFormat.getV3n3cp()
        vdata = GeomVertexData('surface', format, Geom.UHDynamic)
        tri = GeomTriangles(Geom.UHDynamic)

        vertex = GeomVertexWriter(vdata, 'vertex')
        normal = GeomVertexWriter(vdata, 'normal')
        color = GeomVertexWriter(vdata, 'color')

        vertmap = [(0, 1), (1, 2), (2, 3), (3, 0), (4, 5), (5, 6), (6, 7), (7, 4), (0, 4), (1, 5), (2, 6), (3, 7)]

        def generate_index(x, y, z):
            return x + \
                   y * (self._surface.mls_subdivisions+2) + \
                   z * (self._surface.mls_subdivisions+2)**2

        numbering_scheme = [
                (0, 0, 1),
                (1, 0, 1),
                (1, 0, 0),
                (0, 0, 0),
                (0, 1, 1),
                (1, 1, 1),
                (1, 1, 0),
                (0, 1, 0)]

        vertices = zeros((12,), dtype='3f')
        vertex_normals = zeros((12,), dtype='3f')
        # walk the cubes
        for x_index in range(self._surface.mls_subdivisions+1):
            for y_index in range(self._surface.mls_subdivisions+1):
                for z_index in range(self._surface.mls_subdivisions+1):
                    #points = map(lambda offsets: self._surface.mls_points[generate_index(array([x_index, y_index, z_index]) + offsets)], numbering_scheme)
                    points = [
                            self._surface.mls_points[generate_index(x_index + 0, y_index + 0, z_index + 1)],
                            self._surface.mls_points[generate_index(x_index + 1, y_index + 0, z_index + 1)],
                            self._surface.mls_points[generate_index(x_index + 1, y_index + 0, z_index + 0)],
                            self._surface.mls_points[generate_index(x_index + 0, y_index + 0, z_index + 0)],
                            self._surface.mls_points[generate_index(x_index + 0, y_index + 1, z_index + 1)],
                            self._surface.mls_points[generate_index(x_index + 1, y_index + 1, z_index + 1)],
                            self._surface.mls_points[generate_index(x_index + 1, y_index + 1, z_index + 0)],
                            self._surface.mls_points[generate_index(x_index + 0, y_index + 1, z_index + 0)],
                            ]
                    values = [
                            self._surface.mls_distances[generate_index(x_index + 0, y_index + 0, z_index + 1)],
                            self._surface.mls_distances[generate_index(x_index + 1, y_index + 0, z_index + 1)],
                            self._surface.mls_distances[generate_index(x_index + 1, y_index + 0, z_index + 0)],
                            self._surface.mls_distances[generate_index(x_index + 0, y_index + 0, z_index + 0)],
                            self._surface.mls_distances[generate_index(x_index + 0, y_index + 1, z_index + 1)],
                            self._surface.mls_distances[generate_index(x_index + 1, y_index + 1, z_index + 1)],
                            self._surface.mls_distances[generate_index(x_index + 1, y_index + 1, z_index + 0)],
                            self._surface.mls_distances[generate_index(x_index + 0, y_index + 1, z_index + 0)],
                            ]
                    #values = map(lambda offsets: self._surface.mls_distances[generate_index(array([x_index, y_index, z_index]) + offsets)], numbering_scheme)
                    cubeindex = self._get_cubeindex(values)
                    for n in range(12):
                        if self.edge_table[cubeindex] & (2**n):
                            t_v, t_n = self._interpolate(points[vertmap[n][0]], points[vertmap[n][1]], values[vertmap[n][0]], values[vertmap[n][1]])
                            vertices[n] = t_v
                            vertex_normals[n] = t_n/norm(t_n)
                        else:
                            vertices[n] = 0
                            vertex_normals[n] = 0

                    triangles = []
                    i = 0
                    while self.triangle_table[cubeindex][i] != -1:
                        triangles.append([self.triangle_table[cubeindex][i],
                                         self.triangle_table[cubeindex][i+1],
                                         self.triangle_table[cubeindex][i+2]])
                        i += 3

                    for triangle in triangles:
                        vertex.addData3f(*vertices[triangle[0]])
                        vertex.addData3f(*vertices[triangle[1]])
                        vertex.addData3f(*vertices[triangle[2]])
                        normal.addData3f(*vertex_normals[triangle[0]])
                        normal.addData3f(*vertex_normals[triangle[1]])
                        normal.addData3f(*vertex_normals[triangle[2]])
                        #color.addData4f(self._color[0], self._color[1], self._color[2], self._color[3])
                        #color.addData4f(self._color[0], self._color[1], self._color[2], self._color[3])
                        #color.addData4f(self._color[0], self._color[1], self._color[2], self._color[3])
                        color.addData4f(*self._color)
                        color.addData4f(*self._color)
                        color.addData4f(*self._color)
                        tri.addNextVertices(3)

        self._vdata = vdata
        tri.closePrimitive()
        self._geom_primitives = [tri, ]
开发者ID:weltenwort,项目名称:uni_cg2,代码行数:93,代码来源:marching_cube.py

示例11: generate_sphere

# 需要导入模块: from pandac.PandaModules import GeomVertexWriter [as 别名]
# 或者: from pandac.PandaModules.GeomVertexWriter import addData4f [as 别名]
def generate_sphere(name, radius, resolution):
    """
    Generates a sphere with the provided resolution.

    @type name: string
    @param name: Name of this sphere.

    @type radius: number
    @param radius: Radius of sphere in kilometers.

    @type resolution: number
    @param resolution: Resolution of sphere (minimum 2)

    @rtype: GeomNode
    @return: A GeomNode with the given sphere.
    """

    if resolution < 2:
        raise ValueError, "resolution must be >= 2"

    horizBands = resolution*2
    vertBands = horizBands*2

    vertexFormat = GeomVertexFormat.getV3n3c4t2()
    vdata = GeomVertexData('%s_vdata' % name, vertexFormat, Geom.UHDynamic)

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

    vertDelta = omath.TWOPI / vertBands
    horizDelta = omath.TWOPI / horizBands

    numVertices = 0

    for i in range(vertBands+1):
        lowTheta = i * vertDelta
        highTheta = (i+1) * vertDelta

        cosLowTheta = math.cos(lowTheta)
        sinLowTheta = math.sin(lowTheta)
        cosHighTheta = math.cos(highTheta)
        sinHighTheta = math.sin(highTheta)

        for j in range(horizBands):
            horizTheta = j * horizDelta

            cosHorizTheta = math.cos(horizTheta)
            sinHorizTheta = math.sin(horizTheta)

            ex = cosLowTheta*cosHorizTheta
            ey = sinLowTheta
            ez = cosLowTheta*sinHorizTheta

            vertex.addData3f(ex*radius, ey*radius, ez*radius)
            normal.addData3f(ex, ey, ez)
            color.addData4f(.75, .75, .75, 1)
            texcoord.addData2f(i / vertBands, j / horizBands)

            ex = cosHighTheta*cosHorizTheta
            ey = sinHighTheta
            ez = cosHighTheta*sinHorizTheta

            vertex.addData3f(ex*radius, ey*radius, ez*radius)
            normal.addData3f(ex, ey, ez)
            color.addData4f(.75, .75, .75, 1)
            texcoord.addData2f(i / vertBands, j / horizBands)

            numVertices += 2

    prim = GeomTristrips(Geom.UHStatic)
    prim.addConsecutiveVertices(0, numVertices)
    prim.closePrimitive()

    geom = Geom(vdata)
    geom.addPrimitive(prim)

    geomNode = GeomNode(name)
    geomNode.addGeom(geom)

    return GeomScaler(geomNode)
开发者ID:smoluf,项目名称:orbitalindustry,代码行数:84,代码来源:mesh.py

示例12: drawBody

# 需要导入模块: from pandac.PandaModules import GeomVertexWriter [as 别名]
# 或者: from pandac.PandaModules.GeomVertexWriter import addData4f [as 别名]
def drawBody(nodePath, vdata, pos, vecList, radius=1, keepDrawing=True,numVertices=8):

	circleGeom=Geom(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)
	
	sCoord=0

	if (startRow!=0):
		texReWriter.setRow(startRow-numVertices)
		sCoord=texReWriter.getData2f().getX()+1
		
		drawReWriter.setRow(startRow-numVertices)
		if(drawReWriter.getData1f()==False):
			sCoord-=1
	
	drawReWriter.setRow(startRow)
	texReWriter.setRow(startRow)	
	
	angleSlice=2*math.pi/numVertices
	currAngle=0
			
	#axisAdj=Mat4.rotateMat(45, axis)*Mat4.scaleMat(radius)*Mat4.translateMat(pos)

	perp1=vecList[1]
	perp2=vecList[2]	

	#vertex information is written here
	for i in range(numVertices):
		adjCircle=pos+(perp1*math.cos(currAngle)+perp2*math.sin(currAngle))*radius
		normal=perp1*math.cos(currAngle)+perp2*math.sin(currAngle)		
		normalWriter.addData3f(normal)
		vertWriter.addData3f(adjCircle)
		texReWriter.addData2f(sCoord,(i+0.001)/(numVertices-1))
		colorWriter.addData4f(0.5,0.5,0.5,1)
		drawReWriter.addData1f(keepDrawing)
		currAngle+=angleSlice

	
	drawReader=GeomVertexReader(vdata, "drawFlag")
	drawReader.setRow(startRow-numVertices)

	#we cant draw quads directly so we use Tristrips
	if (startRow!=0) & (drawReader.getData1f()!=False):
		lines=GeomTristrips(Geom.UHStatic)
		half=int(numVertices*0.5)
		for i in range(numVertices):
			lines.addVertex(i+startRow)
			if i< half:
				lines.addVertex(i+startRow-half)
			else:
				lines.addVertex(i+startRow-half-numVertices)

		lines.addVertex(startRow)
		lines.addVertex(startRow-half)
		lines.closePrimitive()
		lines.decompose()
		circleGeom.addPrimitive(lines)
		

		circleGeomNode=GeomNode("Debug")
		circleGeomNode.addGeom(circleGeom)

		#I accidentally made the front-face face inwards. Make reverse makes the tree render properly and
			#should cause any surprises to any poor programmer that tries to use this code
		circleGeomNode.setAttrib(CullFaceAttrib.makeReverse(),1)
		global numPrimitives
		numPrimitives+=numVertices*2
	
		nodePath.attachNewNode(circleGeomNode)
开发者ID:juancq,项目名称:character-evolver,代码行数:82,代码来源:Tut-Fractal-Plants.py


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