本文整理汇总了Python中pandac.PandaModules.GeomVertexWriter.addData3f方法的典型用法代码示例。如果您正苦于以下问题:Python GeomVertexWriter.addData3f方法的具体用法?Python GeomVertexWriter.addData3f怎么用?Python GeomVertexWriter.addData3f使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandac.PandaModules.GeomVertexWriter
的用法示例。
在下文中一共展示了GeomVertexWriter.addData3f方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pandac.PandaModules import GeomVertexWriter [as 别名]
# 或者: from pandac.PandaModules.GeomVertexWriter import addData3f [as 别名]
def __init__(self, width=1, depth=1, height=1, origin=Point3(0, 0, 0)):
# Create vetex data format
gvf = GeomVertexFormat.getV3n3()
gvd = GeomVertexData("vertexData", gvf, Geom.UHStatic)
# Create vetex writers for each type of data we are going to store
gvwV = GeomVertexWriter(gvd, "vertex")
gvwN = GeomVertexWriter(gvd, "normal")
# Write out all points
for p in GetPointsForBox(width, depth, height):
gvwV.addData3f(Point3(p) - origin)
# Write out all the normals
for n in ((-1, 0, 0), (1, 0, 0), (0, -1, 0), (0, 1, 0), (0, 0, -1), (0, 0, 1)):
for i in range(4):
gvwN.addData3f(n)
geom = Geom(gvd)
for i in range(0, gvwV.getWriteRow(), 4):
# Create and add both triangles
geom.addPrimitive(GetGeomTriangle(i, i + 1, i + 2))
geom.addPrimitive(GetGeomTriangle(i, i + 2, i + 3))
# Init the node path, wrapping the box
geomNode = GeomNode("box")
geomNode.addGeom(geom)
NodePath.__init__(self, geomNode)
示例2: draw
# 需要导入模块: from pandac.PandaModules import GeomVertexWriter [as 别名]
# 或者: from pandac.PandaModules.GeomVertexWriter import addData3f [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
示例3: createPitchLineOld
# 需要导入模块: from pandac.PandaModules import GeomVertexWriter [as 别名]
# 或者: from pandac.PandaModules.GeomVertexWriter import addData3f [as 别名]
def createPitchLineOld(self,points=[0.5,0.25,-0.25,-0.5],
tick=0.00,colour=None):
""" create a line to hint at the pitch of the aircraft on the hud """
if colour is None:
colour = self.colour
l = LineNodePath(aspect2d,'pitchline',4,Vec4(colour[0],colour[1],
colour[2],colour[3]))
plist = []
for p in points:
plist.append((p,0.0,0.0))
plist.insert(0,(points[0],0.0,tick))
plist.append((points[3],0.0,tick))
linelist = []
linelist = [[plist[p],plist[p+1]] for p in range(len(plist)-1)]
linelist.pop(2)
l.drawLines(linelist)
l.create()
# These lines are drawn from scratch rather than using a graphic file
format = GeomVertexFormat.getV3()
vdata = GeomVertexData("vertices",format,Geom.UHStatic)
# create vertices to add to use in creating lines
vertexWriter=GeomVertexWriter(vdata,"vertex")
# here we define enough positions to create two separated lines
for p in points:
vertexWriter.addData3f(p,0.0,0.0)
# and another two positions for the 'ticks' at the line ends
vertexWriter.addData3f(points[0],0.0,tick)
vertexWriter.addData3f(points[3],0.0,tick)
# create the primitives
line = GeomLines(Geom.UHStatic)
line.addVertices(4,0) # the tick part
line.addVertices(0,1) # part of the horizontal line
line.closePrimitive()
line2 = GeomLines(Geom.UHStatic)
line2.addVertices(2,3) # other part of the horizontal line
line2.addVertices(3,5) # second tick
line2.closePrimitive()
# add the lines to a geom object
lineGeom = Geom(vdata)
lineGeom.addPrimitive(line)
lineGeom.addPrimitive(line2)
# create the node..
lineGN=GeomNode("splitline")
lineGN.addGeom(lineGeom)
# and parent the node to aspect2d
lineNP = aspect2d.attachNewNode(lineGN)
return lineNP
示例4: _create_vertex_data
# 需要导入模块: from pandac.PandaModules import GeomVertexWriter [as 别名]
# 或者: from pandac.PandaModules.GeomVertexWriter import addData3f [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
示例5: create_hexagon
# 需要导入模块: from pandac.PandaModules import GeomVertexWriter [as 别名]
# 或者: from pandac.PandaModules.GeomVertexWriter import addData3f [as 别名]
def create_hexagon(radius):
""" Creates a hexagon shape that is centered at (0,0,0) with the corners having a distance of radius to the center and
the normals pointing in direction (0,-1,0).
Returns the tuple (PandaNode, GeomVertexData). """
format = GeomVertexFormat.getV3n3c4t2()
vdata=GeomVertexData('hexagon', format, Geom.UHStatic)
vertex=GeomVertexWriter(vdata, 'vertex')
normal=GeomVertexWriter(vdata, 'normal')
# create the vertices
vertex.addData3f(0,0,0)
normal.addData3f(0,-1,0)
# add the other vertices
for phi in range(0,360,60):
# right-hand-rule (with middle finger pointing upwards): the y-axis points towards the screen,
# therefore the hexagon will be created in the x,z plane, with x-axis pointing to the right
# and the z-axis pointing up
# get the next vertex coordinates by rotating the point (0,0,radius) in the x,z plane
x,z = rotate_phi_degrees_counter_clockwise(phi, (0,radius))
#print (x,z)
vertex.addData3f(x,0,z)
normal.addData3f(0,-1,0) # the normal vector points away from the screen
# add the vertices to a geometry primitives
prim = GeomTrifans(Geom.UHStatic)
for i in range(7):
prim.addVertex(i)
prim.addVertex(1)
prim.closePrimitive()
geom = Geom(vdata)
geom.addPrimitive(prim)
hex_node = GeomNode('')
hex_node.addGeom(geom)
return hex_node, vdata
示例6: drawSquare
# 需要导入模块: from pandac.PandaModules import GeomVertexWriter [as 别名]
# 或者: from pandac.PandaModules.GeomVertexWriter import addData3f [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
示例7: createCentreMarkOld
# 需要导入模块: from pandac.PandaModules import GeomVertexWriter [as 别名]
# 或者: from pandac.PandaModules.GeomVertexWriter import addData3f [as 别名]
def createCentreMarkOld(self,colour=None):
""" create a line to hint at the pitch of the aircraft on the hud """
if colour is None:
colour = self.colour
# These lines are drawn from scratch rather than using a graphic file
format = GeomVertexFormat.getV3()
vdata = GeomVertexData("vertices",format,Geom.UHStatic)
# create vertices to add to use in creating lines
vertexWriter=GeomVertexWriter(vdata,"vertex")
# essentially I am trying to create a line that gives an idea of
# where the forward vector of the plane is pointing which
# helps indicate the pitch
# the bends in the line could be used to indicate a few angles but
# I am not sure how useful this really is.
vertexWriter.addData3f(0.15,0.0,0.0)
vertexWriter.addData3f(0.10,0.0,0.0)
vertexWriter.addData3f(0.05,0.0,-0.025)
vertexWriter.addData3f(0.00,0.0,0.025)
vertexWriter.addData3f(-0.05,0.0,-0.025)
vertexWriter.addData3f(-0.10,0.0,0.0)
vertexWriter.addData3f(-0.15,0.0,0.0)
# create the primitives
line = GeomLines(Geom.UHStatic)
line.addVertices(0,1)
line.addVertices(1,2)
line.addVertices(2,3)
line.addVertices(3,4)
line.addVertices(4,5)
line.addVertices(5,6)
line.closePrimitive()
# add the lines to a geom object
lineGeom = Geom(vdata)
lineGeom.addPrimitive(line)
# create the node..
lineGN=GeomNode("centremark")
lineGN.addGeom(lineGeom)
# and parent the node to aspect2d
lineNP = aspect2d.attachNewNode(lineGN)
return lineNP
示例8: create_line
# 需要导入模块: from pandac.PandaModules import GeomVertexWriter [as 别名]
# 或者: from pandac.PandaModules.GeomVertexWriter import addData3f [as 别名]
def create_line(x1, z1, x2, z2):
format = GeomVertexFormat.getV3n3c4t2()
vdata = GeomVertexData('', format, Geom.UHStatic)
vertex = GeomVertexWriter(vdata, 'vertex')
normal = GeomVertexWriter(vdata, 'normal')
vertex.addData3f(x1, 0, z1)
vertex.addData3f(x2, 0, z2)
for _i in range(2):
normal.addData3f(0, - 1, 0)
prim_hint = Geom.UHStatic
prim = GeomLines(prim_hint)
prim.addVertices(0, 1)
prim.closePrimitive()
geom = Geom(vdata)
geom.addPrimitive(prim)
node = GeomNode('')
node.addGeom(geom)
return (node, vdata)
示例9: makeCircle
# 需要导入模块: from pandac.PandaModules import GeomVertexWriter [as 别名]
# 或者: from pandac.PandaModules.GeomVertexWriter import addData3f [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
示例10: _create_vertex_data
# 需要导入模块: from pandac.PandaModules import GeomVertexWriter [as 别名]
# 或者: from pandac.PandaModules.GeomVertexWriter import addData3f [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]
示例11: circle
# 需要导入模块: from pandac.PandaModules import GeomVertexWriter [as 别名]
# 或者: from pandac.PandaModules.GeomVertexWriter import addData3f [as 别名]
def circle (self, radius, axis, offset):
# since we're doing line segments, just vertices in our geom
format = GeomVertexFormat.getV3()
# build our data structure and get a handle to the vertex column
vdata = GeomVertexData ('', format, Geom.UHStatic)
vertices = GeomVertexWriter (vdata, 'vertex')
# build a linestrip vertex buffer
lines = GeomLinestrips (Geom.UHStatic)
for i in range (0, self.subdiv):
angle = i / float(self.subdiv) * 2.0 * math.pi
ca = math.cos (angle)
sa = math.sin (angle)
if axis == "x":
vertices.addData3f (0, radius * ca, radius * sa + offset)
if axis == "y":
vertices.addData3f (radius * ca, 0, radius * sa + offset)
if axis == "z":
vertices.addData3f (radius * ca, radius * sa, offset)
for i in range (1, self.subdiv):
lines.addVertices(i - 1, i)
lines.addVertices (self.subdiv - 1, 0)
lines.closePrimitive()
geom = Geom (vdata)
geom.addPrimitive (lines)
# Add our primitive to the geomnode
self.gnode.addGeom (geom)
示例12: create_triangle
# 需要导入模块: from pandac.PandaModules import GeomVertexWriter [as 别名]
# 或者: from pandac.PandaModules.GeomVertexWriter import addData3f [as 别名]
def create_triangle(x_z_left, x_z_top, x_z_right, static=True):
x1,z1 = x_z_left
x2,z2 = x_z_top
x3,z3 = x_z_right
format = GeomVertexFormat.getV3n3c4t2()
vdata=GeomVertexData('', format, Geom.UHStatic)
vertex=GeomVertexWriter(vdata, 'vertex')
normal=GeomVertexWriter(vdata, 'normal')
vertex.addData3f(x1, 0, z1) # left
vertex.addData3f(x2, 0, z2) # top
vertex.addData3f(x3, 0, z3) # right
for _i in range(3):
normal.addData3f(0,-1,0)
if static:
prim_hint = Geom.UHStatic
else:
prim_hint = Geom.UHDynamic
prim = GeomTriangles(prim_hint)
prim.addVertices(0,2,1)
prim.closePrimitive()
geom = Geom(vdata)
geom.addPrimitive(prim)
node = GeomNode('')
node.addGeom(geom)
return node
示例13: create_side
# 需要导入模块: from pandac.PandaModules import GeomVertexWriter [as 别名]
# 或者: from pandac.PandaModules.GeomVertexWriter import addData3f [as 别名]
def create_side(x_z_top_left, x_z_bottom_right, static=True):
x1, z1 = x_z_top_left
x2, z2 = x_z_bottom_right
format = GeomVertexFormat.getV3n3c4t2()
vdata = GeomVertexData('', format, Geom.UHStatic)
vertex = GeomVertexWriter(vdata, 'vertex')
normal = GeomVertexWriter(vdata, 'normal')
vertex.addData3f(x1, 0, z1) # top left
vertex.addData3f(x2, 0, z1) # top right
vertex.addData3f(x2, 0, z2) # bottom right
vertex.addData3f(x1, 0, z2) # bottom left
for _i in range(4):
normal.addData3f(0, - 1, 0)
if static:
prim_hint = Geom.UHStatic
else:
prim_hint = Geom.UHDynamic
prim = GeomTristrips(prim_hint)
prim.addVertices(1, 0, 2, 3)
prim.closePrimitive()
geom = Geom(vdata)
geom.addPrimitive(prim)
node = GeomNode('')
node.addGeom(geom)
return (node, vdata)
示例14: line
# 需要导入模块: from pandac.PandaModules import GeomVertexWriter [as 别名]
# 或者: from pandac.PandaModules.GeomVertexWriter import addData3f [as 别名]
def line (self, start, end):
# since we're doing line segments, just vertices in our geom
format = GeomVertexFormat.getV3()
# build our data structure and get a handle to the vertex column
vdata = GeomVertexData ('', format, Geom.UHStatic)
vertices = GeomVertexWriter (vdata, 'vertex')
# build a linestrip vertex buffer
lines = GeomLinestrips (Geom.UHStatic)
vertices.addData3f (start[0], start[1], start[2])
vertices.addData3f (end[0], end[1], end[2])
lines.addVertices (0, 1)
lines.closePrimitive()
geom = Geom (vdata)
geom.addPrimitive (lines)
# Add our primitive to the geomnode
self.gnode.addGeom (geom)
示例15: __init__
# 需要导入模块: from pandac.PandaModules import GeomVertexWriter [as 别名]
# 或者: from pandac.PandaModules.GeomVertexWriter import addData3f [as 别名]
def __init__(self,subdivides=3,scale=1.0):
super(SphereNode,self).__init__('sphere')
uniform = True
# see if scale is a tuple
try:
xs,ys,zs = scale
uniform = False
except TypeError:
# no, it's a scalar
xs,ys,zs = scale,scale,scale
north = (0.0,1.0,0.0)
g = Octahedron()
for i in range(subdivides):
g.UniformSubdivide( midpointdisplace = NormalizeVert )
#print "%d faces per sphere"%len(g.faces)
# okay, we're gonna use setShaderInput to set constants for
# surface coverages and planetary seed, so all we need per
# vertex is position and normal
# and we kind of don't need normal for a unit sphere, but
# we want to use the same shader for other thangs
format=GeomVertexFormat.getV3n3()
vdata=GeomVertexData('sphere', format, Geom.UHDynamic)
vertex=GeomVertexWriter(vdata, 'vertex')
normal=GeomVertexWriter(vdata, 'normal')
for (x,y,z) in g.verts:
vertex.addData3f( x*xs, y*ys, z*zs )
if uniform:
normal.addData3f( x, y, z )
else:
n = NormalizeVert( (x/(xs*xs),y/(ys*ys),z/(zs*zs)) )
normal.addData3f( n[0], n[1], n[2] )
trilist=GeomTriangles(Geom.UHDynamic)
for (a,b,c) in g.faces:
trilist.addVertex(a)
trilist.addVertex(b)
trilist.addVertex(c)
trilist.closePrimitive()
self.geom = Geom(vdata)
self.geom.addPrimitive( trilist )
self.addGeom( self.geom )