本文整理汇总了Python中pandac.PandaModules.GeomVertexWriter类的典型用法代码示例。如果您正苦于以下问题:Python GeomVertexWriter类的具体用法?Python GeomVertexWriter怎么用?Python GeomVertexWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GeomVertexWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_hexagon
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
示例2: draw
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
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: set_bar_height
def set_bar_height(self, height):
""" Sets the height of the bar to the given value. The given height should be between 0 and 1. """
reader = GeomVertexReader(self.bar_vdata, 'vertex')
writer = GeomVertexWriter(self.bar_vdata, 'vertex')
while not reader.isAtEnd():
v = reader.getData3f()
if v[2] > 0:
writer.setData3f(v[0],v[1],height)
else:
writer.setData3f(v) # I have to call the writer setData method in any case
示例5: _set_z_on_shaft
def _set_z_on_shaft(self, z):
for vdata in self.shaft_vdata:
reader = GeomVertexReader(vdata, 'vertex')
writer = GeomVertexWriter(vdata, 'vertex')
while not reader.isAtEnd():
v = reader.getData3f()
if v[2] > 0:
writer.setData3f(v[0],v[1],z)
else:
writer.setData3f(v) # I have to call the writer setData method in any case
示例6: create_triangle
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
示例7: create_side
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)
示例8: circle
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)
示例9: __init__
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)
示例10: __init__
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 )
示例11: scale_vertices
def scale_vertices(self, multiplier):
"""
Scale the working vertices as the given multiplier to the original
vertices.
@type multiplier: number
@param multiplier: Coefficient to apply to original vertices.
"""
for i,geom in self.__get_geoms():
orig_vdata = self.orig_vertices[i]
working_vdata = self.working_vertices[i]
reader = GeomVertexReader(orig_vdata, 'vertex')
writer = GeomVertexWriter(working_vdata, 'vertex')
while not reader.isAtEnd():
data = reader.getData3f()
writer.setData3f(data[0] * multiplier,
data[1] * multiplier,
data[2] * multiplier)
示例12: line
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)
示例13: _create_vertex_data
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 index, point in enumerate(self._points):
vertex.addData3f(*point[0:3])
if self._colors != None:
color.addData4f(*self._colors[index])
else:
color.addData4f(*self._color)
self._vdata = vdata
示例14: _create_vertex_data
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]
示例15: generate
def generate(self):
format = GeomVertexFormat.getV3()
data = GeomVertexData("Data", format, Geom.UHStatic)
vertices = GeomVertexWriter(data, "vertex")
size = self.size
vertices.addData3f(-size, -size, -size)
vertices.addData3f(+size, -size, -size)
vertices.addData3f(-size, +size, -size)
vertices.addData3f(+size, +size, -size)
vertices.addData3f(-size, -size, +size)
vertices.addData3f(+size, -size, +size)
vertices.addData3f(-size, +size, +size)
vertices.addData3f(+size, +size, +size)
triangles = GeomTriangles(Geom.UHStatic)
def addQuad(v0, v1, v2, v3):
triangles.addVertices(v0, v1, v2)
triangles.addVertices(v0, v2, v3)
triangles.closePrimitive()
addQuad(4, 5, 7, 6) # Z+
addQuad(0, 2, 3, 1) # Z-
addQuad(3, 7, 5, 1) # X+
addQuad(4, 6, 2, 0) # X-
addQuad(2, 6, 7, 3) # Y+
addQuad(0, 1, 5, 4) # Y+
geom = Geom(data)
geom.addPrimitive(triangles)
node = GeomNode("CubeMaker")
node.addGeom(geom)
path = NodePath(node)
path.setColor(1.0, 0.0, 1.0)
return NodePath(node)