本文整理汇总了Python中panda3d.core.GeomNode类的典型用法代码示例。如果您正苦于以下问题:Python GeomNode类的具体用法?Python GeomNode怎么用?Python GeomNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GeomNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _makeGeom
def _makeGeom(array,ctup,i,pipe, geomType=GeomPoints): #XXX testing multiple Geom version ... for perf seems like it will be super slow
#SUUUPER slow TONS of draw calls
#wwwayyy better to make a bunch of geoms ahead of time...
""" multiprocessing capable geometery maker """
fmt = GeomVertexFormat.getV3c4()
cloudNode = GeomNode('bin %s selectable'%(i))
for point in array:
vertexData = GeomVertexData('poitn', fmt, Geom.UHStatic)
GeomVertexWriter(vertexData, 'vertex').addData3f(*point)
GeomVertexWriter(vertexData, 'color').addData4f(*ctup)
#verts.addData3f(*point)
#color.addData4f(*ctup)
points = geomType(Geom.UHStatic)
points.addVertex(0)
points.closePrimitive()
cloudGeom = Geom(vertexData)
cloudGeom.addPrimitive(points)
cloudNode.addGeom(cloudGeom) #TODO figure out if it is faster to add and subtract Geoms from geom nodes...
#output[i] = cloudNode
#print('ping',{i:cloudNode})
#pipe.send((i,))
#out = q.get()
#print('pong',out)
#q.put(out)
if pipe == None:
return (cloudNode)
pipe.send(cloudNode.encodeToBamStream()) #FIXME make this return a pointer NOPE
示例2: makeRotationGeomNode
def makeRotationGeomNode():
vdata = GeomVertexData('rotHandleData', GeomVertexFormat.getV3(),
Geom.UHStatic)
v = GeomVertexWriter(vdata, 'vertex')
radius = 0.7
width = 0.08
res = 30
innerRad = radius - width
for i in xrange(res):
theta = i*(2*pi/res)
v.addData3f(innerRad*sin(theta), innerRad*cos(theta), width/2.0)
v.addData3f(innerRad*sin(theta), innerRad*cos(theta), -width/2.0)
v.addData3f(radius*sin(theta), radius*cos(theta), width/2.0)
v.addData3f(radius*sin(theta), radius*cos(theta), -width/2.0)
circle = Geom(vdata)
# Make prims for the faces of the torus
faces = [GeomTristrips(Geom.UHStatic) for i in xrange(4)]
for i in xrange(res):
i = i*4
faces[0].addVertices(i + 1, i)
faces[1].addVertices(i + 2, i + 1)
faces[2].addVertices(i + 3, i + 2)
faces[3].addVertices(i, i + 3)
for i in xrange(4):
faces[i].addVertices((i + 1) % 4, i)
faces[i].closePrimitive()
circle.addPrimitive(faces[i])
node = GeomNode('geomnode')
node.addGeom(circle)
return node
示例3: makeSimpleGeomBuffer
def makeSimpleGeomBuffer(array, color, geomType=GeomPoints):
""" massively faster than the nonbuffer version """
full = [tuple(d) for d in np.hstack((array,color))]
fmt = GeomVertexFormat.getV3c4()
vertexData = GeomVertexData('points', fmt, Geom.UHDynamic) #FIXME use the index for these too? with setPythonTag, will have to 'reserve' some
cloudGeom = Geom(vertexData)
cloudNode = GeomNode('just some points')
vertexData.setNumRows(len(array))
mem_array = vertexData.modifyArray(0)
view = memoryview(mem_array)
arr = np.asarray(view)
arr[:] = full
points = geomType(Geom.UHDynamic)
points.addConsecutiveVertices(0,len(array))
points.closePrimitive()
cloudGeom.addPrimitive(points)
cloudNode.addGeom(cloudGeom)
return cloudNode
示例4: make_cube
def make_cube(x, y, z, size):
squares = []
squares.append(
make_square(x - (size / 2), y - (size / 2), z - (size / 2), x + (size / 2), y - (size / 2), z + (size / 2))
)
squares.append(
make_square(x - (size / 2), y + (size / 2), z - (size / 2), x + (size / 2), y + (size / 2), z + (size / 2))
)
squares.append(
make_square(x - (size / 2), y + (size / 2), z + (size / 2), x + (size / 2), y - (size / 2), z + (size / 2))
)
squares.append(
make_square(x - (size / 2), y + (size / 2), z - (size / 2), x + (size / 2), y - (size / 2), z - (size / 2))
)
squares.append(
make_square(x - (size / 2), y - (size / 2), z - (size / 2), x - (size / 2), y + (size / 2), z + (size / 2))
)
squares.append(
make_square(x + (size / 2), y - (size / 2), z - (size / 2), x + (size / 2), y + (size / 2), z + (size / 2))
)
snode = GeomNode("square")
for s in squares:
snode.addGeom(s)
cube = render.attachNewNode(snode)
cube.setTwoSided(True)
示例5: draw_face
def draw_face(self,f,f_color):
#add normal
format = GeomVertexFormat.getV3n3cp()
vdata=GeomVertexData('vert', format, Geom.UHDynamic)
vertex=GeomVertexWriter(vdata, 'vertex')
color=GeomVertexWriter(vdata, 'color')
normal=GeomVertexWriter(vdata, 'normal')
vertex.addData3f(f.v1.pos)
normal.addData3f(f.v1.norm.x, f.v1.norm.y, f.v1.norm.z)
color.addData4f(f_color)
vertex.addData3f(f.v2.pos)
normal.addData3f(f.v2.norm.x, f.v2.norm.y, f.v2.norm.z)
color.addData4f(f_color)
vertex.addData3f(f.v3.pos)
normal.addData3f(f.v3.norm.x, f.v3.norm.y, f.v3.norm.z)
color.addData4f(f_color)
mesh = Geom(vdata)
tri = GeomTriangles(Geom.UHDynamic)
tri.addVertex(0)
tri.addVertex(1)
tri.addVertex(2)
tri.closePrimitive()
mesh.addPrimitive(tri)
face_node = GeomNode(self.mesh.name+'_face_'+str(f.ID))
face_node.addGeom(mesh)
face_node.setTag('ID',str(f.ID))
rendered_face = self.render_root.attachNewNode(face_node)
rendered_face.setTwoSided(True)
self.render_nodes['face_'+str(f.ID)] = rendered_face
示例6: makeSB
def makeSB(pos, hpr):
import torus
geom = torus.makeGeom()
#geom = loader.loadModel('models/torus.egg') \
# .findAllMatches('**/+GeomNode').getPath(0).node() \
# .modifyGeom(0)
geomNode = GeomNode('')
geomNode.addGeom(geom)
node = BulletSoftBodyNode.makeTriMesh(info, geom)
node.linkGeom(geomNode.modifyGeom(0))
node.generateBendingConstraints(2)
node.getCfg().setPositionsSolverIterations(2)
node.getCfg().setCollisionFlag(BulletSoftBodyConfig.CFVertexFaceSoftSoft, True)
node.randomizeConstraints()
node.setTotalMass(50, True)
softNP = self.worldNP.attachNewNode(node)
softNP.setPos(pos)
softNP.setHpr(hpr)
self.world.attachSoftBody(node)
geomNP = softNP.attachNewNode(geomNode)
示例7: create_model
def create_model(self):
# Set up the vertex arrays
vformat = GeomVertexFormat.get_v3c4()
vdata = GeomVertexData("Data", vformat, Geom.UHStatic)
vertex = GeomVertexWriter(vdata, 'vertex')
color = GeomVertexWriter(vdata, 'color')
geom = Geom(vdata)
# Vertex data
vertex.addData3f(1.5, 0, -1)
color.addData4f(1, 0, 0, 1)
vertex.addData3f(-1.5, 0, -1)
color.addData4f(0, 1, 0, 1)
vertex.addData3f(0, 0, 1)
color.addData4f(0, 0, 1, 1)
# Primitive
tri = GeomTriangles(Geom.UHStatic)
tri.add_vertex(2)
tri.add_vertex(1)
tri.add_vertex(0)
tri.close_primitive()
geom.addPrimitive(tri)
# Create the actual node
node = GeomNode('geom_node')
node.addGeom(geom)
np = NodePath(node)
# Shader and initial shader vars
np.set_shader(Shader.load(Shader.SL_GLSL, "shader/shader.vert", "shader/shader.frag"))
np.set_shader_input("time", 0.0)
# No instancing necessary
#np.set_instance_count(27)
# return np
np.reparent_to(base.render)
self.model = np
示例8: Sky
class Sky(object):
def __init__(self, mp):
vdata = GeomVertexData("name_me", GeomVertexFormat.getV3c4(), Geom.UHStatic)
vertex = GeomVertexWriter(vdata, "vertex")
color = GeomVertexWriter(vdata, "color")
primitive = GeomTristrips(Geom.UHStatic)
film_size = base.cam.node().getLens().getFilmSize()
x = film_size.getX() / 2.0
z = x * 256.0 / 240.0
vertex.addData3f(x, 90, z)
vertex.addData3f(-x, 90, z)
vertex.addData3f(x, 90, -z)
vertex.addData3f(-x, 90, -z)
color.addData4f(VBase4(*mp["backgroundcolor1"]))
color.addData4f(VBase4(*mp["backgroundcolor1"]))
color.addData4f(VBase4(*mp["backgroundcolor2"]))
color.addData4f(VBase4(*mp["backgroundcolor2"]))
primitive.addNextVertices(4)
primitive.closePrimitive()
geom = Geom(vdata)
geom.addPrimitive(primitive)
self.node = GeomNode("sky")
self.node.addGeom(geom)
base.camera.attachNewNode(self.node)
def remove(self):
NodePath(self.node).removeNode()
示例9: makeSimpleGeom
def makeSimpleGeom(array, ctup, geomType = GeomPoints, fix = False):
fmt = GeomVertexFormat.getV3c4()
vertexData = GeomVertexData('points', fmt, Geom.UHDynamic) #FIXME use the index for these too? with setPythonTag, will have to 'reserve' some
cloudGeom = Geom(vertexData)
cloudNode = GeomNode('just some points')
verts = GeomVertexWriter(vertexData, 'vertex')
color = GeomVertexWriter(vertexData, 'color')
if fix:
if len(ctup) == len(array):
for point,c in zip(array, ctup):
verts.addData3f(*point)
color.addData4f(*c)
else:
for point in array:
verts.addData3f(*point)
color.addData4f(*ctup)
else:
for point in array:
verts.addData3f(*point)
color.addData4f(*ctup)
points = geomType(Geom.UHDynamic)
points.addConsecutiveVertices(0,len(array))
points.closePrimitive()
cloudGeom.addPrimitive(points)
cloudNode.addGeom(cloudGeom) #TODO figure out if it is faster to add and subtract Geoms from geom nodes...
if fix:
return cloudNode.__reduce__()
else:
return cloudNode # decoding fails becuase ForkingPickler is called for reasons beyond comprehension
示例10: __init__
def __init__(self, scale=10):
axisNode = GeomNode('axis')
axisGeom = makeAxis()
axisNode.addGeom(axisGeom)
axis = render.attachNewNode(axisNode)
axis.setScale(scale,scale,scale)
axis.setRenderModeThickness(2)
示例11: __build_Tris
def __build_Tris(self, sphere, mode):
vdata = GeomVertexData("Data", self.__vformat[mode], Geom.UHStatic)
_num_rows = len(sphere.pts)
# Vertices.
vertices = GeomVertexWriter(vdata, "vertex")
vertices.reserveNumRows(_num_rows)
for pt in sphere.pts:
vertices.addData3f(*pt)
# Map coords.
if mode == "mid":
mapcoords = GeomVertexWriter(vdata, "mapcoord")
mapcoords.reserveNumRows(_num_rows)
for mc in sphere.coords:
u, v = mc[:2]
mapcoords.addData2f(u,v)
# Tris.
prim = GeomTriangles(Geom.UHStatic)
prim.reserveNumVertices(len(sphere.tris))
for tri in sphere.tris:
prim.addVertices(*tri)
prim.closePrimitive()
# Geom.
geom = Geom(vdata)
geom.addPrimitive(prim)
geom_node = GeomNode("geom")
geom_node.addGeom(geom)
geom_np = NodePath(geom_node)
return geom_np
示例12: add_plane
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)
示例13: __build_Patches
def __build_Patches(self, sphere):
vdata = GeomVertexData("Data", self.__vformat['high'], Geom.UHStatic)
vertices = GeomVertexWriter(vdata, "vertex")
mapcoords = GeomVertexWriter(vdata, "mapcoord")
texcoords = GeomVertexWriter(vdata, "texcoord")
_num_rows = len(sphere.pts)
vertices.reserveNumRows(_num_rows)
mapcoords.reserveNumRows(_num_rows)
texcoords.reserveNumRows(_num_rows)
# Pts.
for pt, uv, coords, in zip(sphere.pts, sphere.uvs, sphere.coords):
vertices.addData3f(*pt)
mapcoords.addData2f(*coords)
texcoords.addData2f(*uv) ## *.99+.01)
# Patches.
prim = GeomPatches(3, Geom.UHStatic)
prim.reserveNumVertices(len(sphere.tris))
for tri in sphere.tris:
prim.addVertices(*tri)
prim.closePrimitive()
# Geom.
geom = Geom(vdata)
geom.addPrimitive(prim)
geom_node = GeomNode("geom")
geom_node.addGeom(geom)
geom_np = NodePath(geom_node)
return geom_np
示例14: load
def load(self):
if panda3d is None: raise ImportError("Cannot locate Panda3D")
#KLUDGE
if self.material is not None and self.colors is None:
col = self.material.getAmbient()
col = (col[0] / col[3], col[1] / col[3], col[2] / col[3], 1.0)
self.colors = (col,) * len(self.vertices)
#/KLUDGE
geom = make_geom(self.vertices, self.normals, self.colors, self.texcoords)
prim = GeomTriangles(Geom.UHStatic)
for face in self.faces:
#TODO: proper tesselation! the current one only works for convex faces
first = face[0]
curr = face[1]
for v in face[2:]:
prim.addVertex(curr)
prim.addVertex(v)
prim.addVertex(first)
curr = v
prim.closePrimitive()
geom.addPrimitive(prim)
node = GeomNode(self.name)
node.addGeom(geom)
self.node = NodePath(node)
self.node.setTwoSided(True)
if self.material is not None: self.node.setMaterial(self.material, priority=1)
self.loaded = True
示例15: draw
def draw(self):
if self.rendered_mesh != None:
self.reset_draw()
format=GeomVertexFormat.getV3n3cp()
vdata=GeomVertexData('tri', format, Geom.UHDynamic)
vertex=GeomVertexWriter(vdata, 'vertex')
normal=GeomVertexWriter(vdata, 'normal')
color=GeomVertexWriter(vdata, 'color')
v_mapping = {}
i=0
for v in self.verts.values():
vertex.addData3f(v.pos.x,v.pos.y,v.pos.z)
normal.addData3f(v.norm.x, v.norm.y, v.norm.z)
color.addData4f(v.color[0],v.color[1],v.color[2],v.color[3])
v_mapping[v.ID] = i
i += 1
mesh = Geom(vdata)
for f in self.faces.values():
tri = GeomTriangles(Geom.UHDynamic)
tri.addVertex(v_mapping[f.v1.ID])
tri.addVertex(v_mapping[f.v2.ID])
tri.addVertex(v_mapping[f.v3.ID])
tri.closePrimitive()
mesh.addPrimitive(tri)
snode = GeomNode(self.name)
snode.addGeom(mesh)
self.rendered_mesh = render.attachNewNode(snode)
self.rendered_mesh.setTwoSided(True)