本文整理汇总了Python中pandac.PandaModules.GeomNode类的典型用法代码示例。如果您正苦于以下问题:Python GeomNode类的具体用法?Python GeomNode怎么用?Python GeomNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GeomNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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
示例2: __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)
示例3: 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
示例4: 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
示例5: 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)
示例6: 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
示例7: __init__
def __init__(self, name, halfedge_mesh, color, wireframe=False):
GeomNode.__init__(self, name)
self._halfedge_mesh = halfedge_mesh
self._color = color
self._wireframe = wireframe
self._create_vertex_data()
self._create_geoms()
# set visualisation parameters
if self._wireframe:
self.setAttrib(RenderModeAttrib.make(RenderModeAttrib.MWireframe, 2, 1))
self.setAttrib(CullFaceAttrib.make(CullFaceAttrib.MCullNone))
示例8: __init__
def __init__(self, name, points, color=(1.0,1.0,1.0,1.0)):
GeomNode.__init__(self, name)
self._points = points
self._color = color
self._create_vertex_data()
self._create_geom_primitives()
self._create_geoms()
# set visualisation parameters
#if self._wireframe:
# self.setAttrib(RenderModeAttrib.make(RenderModeAttrib.MWireframe, 2, 1))
#self.setAttrib(CullFaceAttrib.make(CullFaceAttrib.MCullNone))
self.setAttrib(RenderModeAttrib.make(RenderModeAttrib.MWireframe, 2, 0))
示例9: __init__
def __init__(self, render, camera):
#Since we are using collision detection to do picking, we set it up like any other collision detection system with a traverser and a handler
self.picker = CollisionTraverser() #Make a traverser
self.pq = CollisionHandlerQueue() #Make a handler
#Make a collision node for our picker ray
self.pickerNode = CollisionNode('mouseRay')
#Attach that node to the camera since the ray will need to be positioned relative to it
self.pickerNP = camera.attachNewNode(self.pickerNode)
#Everything to be picked will use bit 1. This way if we were doing other collision we could seperate it
self.pickerNode.setFromCollideMask(BitMask32.bit(1))
self.pickerRay = CollisionRay() #Make our ray
self.pickerNode.addSolid(self.pickerRay) #Add it to the collision node
#Register the ray as something that can cause collisions
self.picker.addCollider(self.pickerNP, self.pq)
#self.picker.showCollisions(render)
self.pst = CollisionTraverser() #Make a traverser
self.hqp = CollisionHandlerQueue() #Make a handler
#Make a collision node for our picker ray
self.pstNode = CollisionNode('mouseRaytoObj')
#Attach that node to the camera since the ray will need to be positioned relative to it
self.pstNode.setFromCollideMask(GeomNode.getDefaultCollideMask())
self.pstNode2 = camera.attachNewNode(self.pstNode)
self.pickerRayObj = CollisionRay()
#Everything to be picked will use bit 1. This way if we were doing other collision we could seperate it
#self.pstNode.setFromCollideMask(BitMask32.bit(1))
self.pstNode.addSolid(self.pickerRayObj) #Add it to the collision node
#Register the ray as something that can cause collisions
self.pst.addCollider(self.pstNode2, self.hqp)
#self.pst.showCollisions(render)
示例10: __init__
def __init__ (self):
# GeomNode to hold our individual geoms
self.gnode = GeomNode ('wirePrim')
# How many times to subdivide our spheres/cylinders resulting vertices. Keep low
# because this is supposed to be an approximate representation
self.subdiv = 12
示例11: __init__
def __init__(self, name, surface, color, wireframe=False):
GeomNode.__init__(self, name)
self._surface = surface
self._color = color
self._wireframe = wireframe
self._init_tables()
self._create_vertex_data()
self._create_geoms()
# set visualisation parameters
if self._wireframe:
self.setAttrib(RenderModeAttrib.make(RenderModeAttrib.MWireframe, 2, 1))
else:
self.setAttrib(RenderModeAttrib.make(RenderModeAttrib.MFilledFlat, 2, 1))
self.setAttrib(CullFaceAttrib.make(CullFaceAttrib.MCullNone))
示例12: __init__
def __init__(self,gmap,gaming_zone):
DirectObject.__init__(self)
#gaming zone (used for mouse movement), as a tools.Rectangle
self.gaming_zone=gaming_zone
#actual camera node
self.p3dcam=base.camera
#what the cam is oriented to
self._target=base.render.attachNewNode('GaminCam.target')
#range=[0,1] between min and max closeness to ground
self.level=.7
#
#keys_down acts as a pool containing keys (+mouse buttons) currently down
self.keys_down=[]
update_list.append(self.update)
#setup for mouse picking
picker_node=CollisionNode('gcam_to_mouse_ray')#general collision node
picker_node.setFromCollideMask(GeomNode.getDefaultCollideMask())
self.picker_ray=CollisionRay()#solid ray to attach to coll node
picker_node.addSolid(self.picker_ray)
self.picker_np=self.p3dcam.attachNewNode(picker_node)#attach this node to gcam
self.collision_queue=CollisionHandlerQueue()#stores collisions
self.collision_traverser=CollisionTraverser('gcam_traverser')#actual computer
self.collision_traverser.addCollider(self.picker_np,self.collision_queue)
base.cTrav=self.collision_traverser
self.gmap=gmap
#stack of states (state=pos+zoom)
self.states_stack=[]
#enable the cam to move according to keyboard and mouse
self.move_enabled=True
示例13: createCentreMarkOld
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
示例14: create_line
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)
示例15: collideWithGeom
def collideWithGeom(self):
# The into collide mask is the bit pattern colliders look at
# when deciding whether or not to test for a collision "into"
# this collision solid. Set to all Off so this collision solid
# will not be considered in any collision tests
self.collisionNode.setIntoCollideMask(BitMask32().allOff())
# The from collide mask is the bit pattern *this* collision solid
# compares against the into collide mask of candidate collision solids
# Turn this mask all off since we're not testing for collisions against
# collision solids, but we do want to test against geometry
self.collisionNode.setFromCollideMask(GeomNode.getDefaultCollideMask())