本文整理汇总了Python中panda3d.core.GeomNode.addGeom方法的典型用法代码示例。如果您正苦于以下问题:Python GeomNode.addGeom方法的具体用法?Python GeomNode.addGeom怎么用?Python GeomNode.addGeom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.GeomNode
的用法示例。
在下文中一共展示了GeomNode.addGeom方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _makeGeom
# 需要导入模块: from panda3d.core import GeomNode [as 别名]
# 或者: from panda3d.core.GeomNode import addGeom [as 别名]
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
# 需要导入模块: from panda3d.core import GeomNode [as 别名]
# 或者: from panda3d.core.GeomNode import addGeom [as 别名]
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
# 需要导入模块: from panda3d.core import GeomNode [as 别名]
# 或者: from panda3d.core.GeomNode import addGeom [as 别名]
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
# 需要导入模块: from panda3d.core import GeomNode [as 别名]
# 或者: from panda3d.core.GeomNode import addGeom [as 别名]
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
# 需要导入模块: from panda3d.core import GeomNode [as 别名]
# 或者: from panda3d.core.GeomNode import addGeom [as 别名]
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
# 需要导入模块: from panda3d.core import GeomNode [as 别名]
# 或者: from panda3d.core.GeomNode import addGeom [as 别名]
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
# 需要导入模块: from panda3d.core import GeomNode [as 别名]
# 或者: from panda3d.core.GeomNode import addGeom [as 别名]
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: __build_Patches
# 需要导入模块: from panda3d.core import GeomNode [as 别名]
# 或者: from panda3d.core.GeomNode import addGeom [as 别名]
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
示例9: setup
# 需要导入模块: from panda3d.core import GeomNode [as 别名]
# 或者: from panda3d.core.GeomNode import addGeom [as 别名]
def setup(self):
self.worldNP = render.attachNewNode('World')
# World
self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
self.debugNP.show()
self.world = BulletWorld()
self.world.setGravity(Vec3(0, 0, -9.81))
self.world.setDebugNode(self.debugNP.node())
# Ground
p0 = Point3(-20, -20, 0)
p1 = Point3(-20, 20, 0)
p2 = Point3(20, -20, 0)
p3 = Point3(20, 20, 0)
mesh = BulletTriangleMesh()
mesh.addTriangle(p0, p1, p2)
mesh.addTriangle(p1, p2, p3)
shape = BulletTriangleMeshShape(mesh, dynamic=False)
np = self.worldNP.attachNewNode(BulletRigidBodyNode('Mesh'))
np.node().addShape(shape)
np.setPos(0, 0, -2)
np.setCollideMask(BitMask32.allOn())
self.world.attachRigidBody(np.node())
# Soft body world information
info = self.world.getWorldInfo()
info.setAirDensity(1.2)
info.setWaterDensity(0)
info.setWaterOffset(0)
info.setWaterNormal(Vec3(0, 0, 0))
# Softbody
for i in range(50):
p00 = Point3(-2, -2, 0)
p10 = Point3( 2, -2, 0)
p01 = Point3(-2, 2, 0)
p11 = Point3( 2, 2, 0)
node = BulletSoftBodyNode.makePatch(info, p00, p10, p01, p11, 6, 6, 0, True)
node.generateBendingConstraints(2)
node.getCfg().setLiftCoefficient(0.004)
node.getCfg().setDynamicFrictionCoefficient(0.0003)
node.getCfg().setAeroModel(BulletSoftBodyConfig.AMVertexTwoSided)
node.setTotalMass(0.1)
node.addForce(Vec3(0, 2, 0), 0)
np = self.worldNP.attachNewNode(node)
np.setPos(self.Vec3Rand() * 10 + Vec3(0, 0, 20))
np.setHpr(self.Vec3Rand() * 16)
self.world.attachSoftBody(node)
fmt = GeomVertexFormat.getV3n3t2()
geom = BulletHelper.makeGeomFromFaces(node, fmt, True)
node.linkGeom(geom)
nodeV = GeomNode('')
nodeV.addGeom(geom)
npV = np.attachNewNode(nodeV)
示例10: __build_Tris
# 需要导入模块: from panda3d.core import GeomNode [as 别名]
# 或者: from panda3d.core.GeomNode import addGeom [as 别名]
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
示例11: load
# 需要导入模块: from panda3d.core import GeomNode [as 别名]
# 或者: from panda3d.core.GeomNode import addGeom [as 别名]
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
示例12: buildGeom
# 需要导入模块: from panda3d.core import GeomNode [as 别名]
# 或者: from panda3d.core.GeomNode import addGeom [as 别名]
def buildGeom(self, meshData):
prims = meshData["prims"]
vertices = meshData["vertices"]
normals = meshData["normals"]
texcoords = meshData["texcoords"]
vdata = GeomVertexData('mesh', GeomVertexFormat.getV3n3t2(), Geom.UHStatic)
vwriter = GeomVertexWriter(vdata, 'vertex')
nvwriter = GeomVertexWriter(vdata, 'normal')
tvwriter = GeomVertexWriter(vdata, 'texcoord')
for i in range(len(vertices)):
v = vertices[i]
n = normals[i]
t = texcoords[i]
vwriter.addData3f(v)
nvwriter.addData3f(n)
tvwriter.addData2f(t)
prim = GeomTriangles(Geom.UHStatic)
for i in range(len(prims)):
A, B, C = prims[i]
prim.addVertices(A, B, C)
prim.closePrimitive()
geom = Geom(vdata)
geom.addPrimitive(prim)
geomNode = GeomNode('trig')
geomNode.addGeom(geom)
geomNode.unify(1, True)
return geomNode
示例13: makeSimpleGeom
# 需要导入模块: from panda3d.core import GeomNode [as 别名]
# 或者: from panda3d.core.GeomNode import addGeom [as 别名]
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
示例14: __build_Star_Sphere
# 需要导入模块: from panda3d.core import GeomNode [as 别名]
# 或者: from panda3d.core.GeomNode import addGeom [as 别名]
def __build_Star_Sphere(self, bg_stars):
from panda3d.core import GeomVertexWriter, GeomVertexFormat, GeomVertexData
from panda3d.core import Geom, GeomNode, GeomPoints, AmbientLight
self.star_sphere_np.removeNode()
# Fill GeomVertexData.
vformat = GeomVertexFormat.getV3c4()
vdata = GeomVertexData("Data", vformat, Geom.UHStatic)
vertices = GeomVertexWriter(vdata, "vertex")
colours = GeomVertexWriter(vdata, "color")
for coords in bg_stars:
x, y, z = coords
vertices.addData3f(x, y, z)
colours.addData4f(1, 1, 1, 1)
# Render bg stars.
bg_stars = GeomPoints(Geom.UHStatic)
bg_stars.addNextVertices(_env.STAR_COUNT)
bg_stars_geom = Geom(vdata)
bg_stars_geom.addPrimitive(bg_stars)
star_sphere = GeomNode("star_sphere")
star_sphere.addGeom(bg_stars_geom)
star_sphere_np = NodePath(star_sphere)
star_sphere_np.reparentTo(self.NP)
return star_sphere_np
示例15: __build_Geom
# 需要导入模块: from panda3d.core import GeomNode [as 别名]
# 或者: from panda3d.core.GeomNode import addGeom [as 别名]
def __build_Geom(self, data_dict, tris, prim_type=GeomTriangles):
data_list = list(data_dict.items())
_num_rows = 0
for field, data in data_list:
if not _num_rows: _num_rows = len(data)
writer = self.__writers[field]
writer.reserveNumRows(_num_rows)
set_data = self._data_types[self.field_types[field]][-1]
for datum in data:
set_data(writer, *datum)
# Tris
prim = prim_type(Geom.UHStatic)
prim.reserveNumVertices(len(tris))
for tri in tris:
prim.addVertices(*tri)
prim.closePrimitive()
# Geom.
geom = Geom(self.__vdata)
geom.addPrimitive(prim)
geom_node = GeomNode("geom")
geom_node.addGeom(geom)
geom_np = NodePath(geom_node)
return geom_np