本文整理汇总了Python中panda3d.core.GeomVertexFormat类的典型用法代码示例。如果您正苦于以下问题:Python GeomVertexFormat类的具体用法?Python GeomVertexFormat怎么用?Python GeomVertexFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GeomVertexFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: regesterGeomRequirements
def regesterGeomRequirements(self, LOD, collection):
n = NodePath("tmp")
if self.barkTexture is not None:
n.setTexture(self.barkTexture)
n.setShaderInput("diffTex", self.barkTexture)
format = GeomVertexFormat.getV3n3t2()
else:
format = GeomVertexFormat.getV3n3()
n.setColor(0.4, 0.3, 0.3, 1)
# n.setShader(customLoader.makeShader(n))
trunkRequirements = meshManager.GeomRequirements(geomVertexFormat=format, renderState=n.getState())
n = NodePath("tmp")
if self.leafTexture is not None:
# n.setTag("alpha","")
n.setShaderInput("alpha", 0, 0, 0) # marker we need cutout alpha
n.setTexture(self.leafTexture)
n.setShaderInput("diffTex", self.leafTexture)
format = GeomVertexFormat.getV3n3t2()
else:
format = GeomVertexFormat.getV3n3c4()
# n.setShader(customLoader.makeShader(n,debugCodePrefix="tree",debugGraphPrefix="tree"))
leafRequirements = meshManager.GeomRequirements(geomVertexFormat=format, renderState=n.getState())
self.trunkDataIndex[LOD] = collection.add(trunkRequirements)
self.leafDataIndex[LOD] = collection.add(leafRequirements)
示例2: __init__
def __init__(self, __occupying_unit = None, __occupiable = True,
x = 0, z = 0, r = 5, tag = 0):
self.__occupying_unit = __occupying_unit
self.__occupiable = __occupiable
self.__r = r
self.__x = x
self.__z = z
self.__tag = tag
#Procedurally creating a hex!
geometry_array = GeomVertexArrayFormat()
geometry_array.addColumn(InternalName.make('vertex'), 3, Geom.NTFloat32, Geom.CPoint)
geometry_array.addColumn(InternalName.make('normal'), 3, Geom.NTFloat32, Geom.CPoint)
format = GeomVertexFormat()
format.addArray(geometry_array)
format = GeomVertexFormat.registerFormat(format)
self.__vdata = GeomVertexData('Hex', format, Geom.UHStatic)
self.__vertex = GeomVertexWriter(self.__vdata, 'vertex')
self.__normal = GeomVertexWriter(self.__vdata, 'normal')
#Vertex 1
self.__vertex.addData3f(self.__x, self.__z+self.__r, 0)
self.__normal.addData3f(1, 0, 0)
#Vertex 2
self.__vertex.addData3f(self.__x+self.__r*sin(pi/3), self.__z+self.__r*cos(pi/3), 0)
self.__normal.addData3f(1, 0, 0)
#Vertex 3
self.__vertex.addData3f(self.__x+self.__r*sin(pi/3), self.__z-self.__r*cos(pi/3), 0)
self.__normal.addData3f(1, 0, 0)
#Vertex 4
self.__vertex.addData3f(self.__x, self.__z-self.__r, 0)
self.__normal.addData3f(1, 0, 0)
#Vertex 5
self.__vertex.addData3f(self.__x-self.__r*sin(pi/3), self.__z-self.__r*cos(pi/3), 0)
self.__normal.addData3f(1, 0, 0)
#Vertex 6
self.__vertex.addData3f(self.__x-self.__r*sin(pi/3), self.__z+self.__r*cos(pi/3), 0)
self.__normal.addData3f(1, 0, 0)
self.__hex_primitive = GeomTrifans(Geom.UHStatic)
self.__hex_primitive.addVertices(5, 4)
self.__hex_primitive.addVertices(3, 2)
self.__hex_primitive.addVertices(1, 0)
self.__hex_primitive.closePrimitive()
self.__hex_geometry = Geom(self.__vdata)
self.__hex_geometry.addPrimitive(self.__hex_primitive)
self.__hex_node = GeomNode('HexNode')
self.__hex_node.addGeom(self.__hex_geometry)
nodePath = render.attachNewNode(self.__hex_node)
nodePath.setTag( "hex", str(tag) )
nodePath.node().setIntoCollideMask(BitMask32.bit(1))
nodePath.hide()
示例3: create_model
def create_model(self):
# Set up the vertex arrays
vformatArray = GeomVertexArrayFormat()
# Panda3D implicitly generates a bounding volume from a
# column named "vertex", so you either
# * have a column of that name, or
# * add a bounding volume yourself.
vformatArray.addColumn(InternalName.make("vertex"), 3, Geom.NTFloat32, Geom.CPoint)
vformatArray.addColumn(InternalName.make("color"), 4, Geom.NTFloat32, Geom.CColor)
vformat = GeomVertexFormat()
vformat.addArray(vformatArray)
vformat = GeomVertexFormat.registerFormat(vformat)
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 = GeomPatches(3, 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, initial shader vars, number of instances
np.set_shader(Shader.load(Shader.SL_GLSL,
vertex = "shader.vert",
tess_control = "shader.tesc",
tess_evaluation = "shader.tese",
geometry = "shader.geom",
fragment = "shader.frag"))
np.set_shader_input("time", 0.0)
np.set_shader_input("tess_level", 32.0)
np.set_instance_count(num_instances)
np.set_shader_input("numInstances", num_instances)
return np
示例4: _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
示例5: 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
示例6: 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
示例7: 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
示例8: makePoints
def makePoints(n=1000):
""" make a cloud of points that are a single node VS branching and making subnodes to control display """
#points = np.random.uniform(-10,10,(n,4))
points = np.random.randn(n,3)
colors = np.random.rand(n,4)
fmt = GeomVertexFormat.getV3c4() #3 component vertex, w/ 4 comp color
vertexData = GeomVertexData('points', fmt, Geom.UHStatic)
verts = GeomVertexWriter(vertexData, 'vertex')
color = GeomVertexWriter(vertexData, 'color')
for point,clr4 in zip(points,colors):
#for point in points:
verts.addData3f(*point)
#color.addData4f(*point)
color.addData4f(*clr4)
#color.addData4f(.1,.1,.1,1)
#pointCloud = GeomLinestrips(Geom.UHStatic) #this is fucking cool!
pointCloud = GeomTristrips(Geom.UHStatic) #this is fucking cool!
#pointCloud = GeomPoints(Geom.UHStatic)
#pointCloud.addVerticies(*range(n))
pointCloud.addConsecutiveVertices(0,n) #warning may error since n-1?
pointCloud.closePrimitive()
cloud = Geom(vertexData)
cloud.addPrimitive(pointCloud)
return cloud
示例9: 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
示例10: makeSelectRect
def makeSelectRect():
ctup = (1,1,1,1)
fmt = GeomVertexFormat.getV3c4()
vertexData = GeomVertexData('points', fmt, Geom.UHDynamic)
points = ( #makes nice for Tristrips
(0,0,0),
(0,0,1),
(1,0,0),
(1,0,1),
)
verts = GeomVertexWriter(vertexData, 'vertex')
color = GeomVertexWriter(vertexData, 'color')
for point in points:
verts.addData3f(*point)
color.addData4f(*ctup)
boxLines = GeomLinestrips(Geom.UHDynamic)
boxLines.addVertices(0,1,3,2)
boxLines.addVertex(0)
boxLines.closePrimitive()
boxTris = GeomTristrips(Geom.UHDynamic)
boxTris.addConsecutiveVertices(0,3)
boxTris.closePrimitive()
box = Geom(vertexData)
box.addPrimitive(boxLines)
#box.addPrimitive(boxTris)
return box
示例11: setup
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)
示例12: 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)
示例13: _make_fullscreen_tri
def _make_fullscreen_tri(self):
""" Creates the oversized triangle used for rendering """
vformat = GeomVertexFormat.get_v3()
vdata = GeomVertexData("vertices", vformat, Geom.UH_static)
vdata.set_num_rows(3)
vwriter = GeomVertexWriter(vdata, "vertex")
vwriter.add_data3f(-1, 0, -1)
vwriter.add_data3f(3, 0, -1)
vwriter.add_data3f(-1, 0, 3)
gtris = GeomTriangles(Geom.UH_static)
gtris.add_next_vertices(3)
geom = Geom(vdata)
geom.add_primitive(gtris)
geom_node = GeomNode("gn")
geom_node.add_geom(geom)
geom_node.set_final(True)
geom_node.set_bounds(OmniBoundingVolume())
tri = NodePath(geom_node)
tri.set_depth_test(False)
tri.set_depth_write(False)
tri.set_attrib(TransparencyAttrib.make(TransparencyAttrib.M_none), 10000)
tri.set_color(Vec4(1))
tri.set_bin("unsorted", 10)
tri.reparent_to(self._node)
self._tri = tri
示例14: makeGeom
def makeGeom():
# Vertex data
fmt = GeomVertexFormat.getV3n3t2()
vdata = GeomVertexData('', fmt, Geom.UHStatic)
vertex = GeomVertexWriter(vdata, InternalName.getVertex())
normal = GeomVertexWriter(vdata, InternalName.getNormal())
texcoord = GeomVertexWriter(vdata, InternalName.getTexcoord())
for (x, y, z) in vertices:
vertex.addData3f(x, y, z)
normal.addData3f(0, 0, 0)
# Privitive
prim = GeomTriangles(Geom.UHStatic)
for (i1, i2, i3) in indices:
prim.addVertices(i1, i2, i3)
prim.closePrimitive()
# Geom
geom = Geom(vdata)
geom.addPrimitive(prim)
return geom
示例15: __build_Writers
def __build_Writers(self):
# Build Vdata.
array = GeomVertexArrayFormat()
for field_name, field_spec_name in list(self.field_types.items()):
field_specs = self._data_types[field_spec_name][:-1]
array.addColumn(InternalName.make(field_name), *field_specs)
vformat = GeomVertexFormat()
vformat.addArray(array)
vformat = GeomVertexFormat.registerFormat(vformat)
vdata = GeomVertexData("data", vformat, Geom.UHStatic)
# Build GeomVertexWriters.
writers = {}
for field_name in list(self.field_types.keys()):
writers[field_name] = GeomVertexWriter(vdata, field_name)
return vdata, writers