本文整理汇总了Python中panda3d.core.GeomTriangles.addVertices方法的典型用法代码示例。如果您正苦于以下问题:Python GeomTriangles.addVertices方法的具体用法?Python GeomTriangles.addVertices怎么用?Python GeomTriangles.addVertices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.GeomTriangles
的用法示例。
在下文中一共展示了GeomTriangles.addVertices方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: buildGeom
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addVertices [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
示例2: __build_Tris
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addVertices [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
示例3: makeGeom
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addVertices [as 别名]
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
示例4: __init__
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addVertices [as 别名]
def __init__(self):
ShowBase.__init__(self)
PanditorDisableMouseFunc()
camera.setPos(0.0, 0.0, 50.0)
camera.lookAt(0.0)
PanditorEnableMouseFunc()
# 1) create GeomVertexData
frmt = GeomVertexFormat.getV3n3cp()
vdata = GeomVertexData('triangle', frmt, Geom.UHDynamic)
# 2) create Writers/Rewriters (must all be created before any readers and readers are one-pass-temporary)
vertex = GeomVertexRewriter(vdata, 'vertex')
normal = GeomVertexRewriter(vdata, 'normal')
color = GeomVertexRewriter(vdata, 'color')
zUp = Vec3(0, 0, 1)
wt = Vec4(1.0, 1.0, 1.0, 1.0)
gr = Vec4(0.5, 0.5, 0.5, 1.0)
# 3) write each column on the vertex data object (for speed, have a different writer for each column)
def addPoint(x, y, z):
vertex.addData3f(x, y, z)
normal.addData3f(zUp)
color.addData4f(wt)
addPoint(0.0, 0.0, 0.0)
addPoint(5.0, 0.0, 0.0)
addPoint(0.0, 5.0, 0.0)
addPoint(5.0, 5.0, 0.0)
# 4) create a primitive and add the vertices via index (not truely associated with the actual vertex table, yet)
tris = GeomTriangles(Geom.UHDynamic)
tris.addVertices(0, 1, 2)
tris.closePrimitive() # exception thrown if verts added != 3, other types inform Panda how many verts/primitive
tris.addVertices(2, 1, 3)
print "vdataPoints", vdata.getArrays()[0]
# 5.1) (adding to scene) create a Geom and add primitives of like base-type i.e. triangles and triangle strips
geom = Geom(vdata)
geom.addPrimitive(tris)
# 5.2) create a GeomNode to hold the Geom(s) and add the Geom(s)
gn = GeomNode('gnode')
gn.addGeom(geom)
# 5.3) attache the node to the scene
gnNodePath = render.attachNewNode(gn)
geomPts = Geom(vdata)
pts = GeomPoints(Geom.UHStatic)
pts.addVertices(0, 1, 2)
pts.closePrimitive()
geomPts.addPrimitive(pts)
pointsNode = GeomNode('points_node')
pointsNode.addGeom(geomPts)
pointsNP = render.attachNewNode(pointsNode)
pointsNP.setZ(0.5)
render.ls()
示例5: makeSquare
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addVertices [as 别名]
def makeSquare(x1, y1, z1, x2, y2, z2):
format = GeomVertexFormat.getV3n3cpt2()
vdata = GeomVertexData('square', format, Geom.UHDynamic)
vertex = GeomVertexWriter(vdata, 'vertex')
normal = GeomVertexWriter(vdata, 'normal')
# color = GeomVertexWriter(vdata, 'color')
texcoord = GeomVertexWriter(vdata, 'texcoord')
# make sure we draw the sqaure in the right plane
if x1 != x2:
vertex.addData3(x1, y1, z1)
vertex.addData3(x2, y1, z1)
vertex.addData3(x2, y2, z2)
vertex.addData3(x1, y2, z2)
normal.addData3(normalized(2 * x1 - 1, 2 * y1 - 1, 2 * z1 - 1))
normal.addData3(normalized(2 * x2 - 1, 2 * y1 - 1, 2 * z1 - 1))
normal.addData3(normalized(2 * x2 - 1, 2 * y2 - 1, 2 * z2 - 1))
normal.addData3(normalized(2 * x1 - 1, 2 * y2 - 1, 2 * z2 - 1))
else:
vertex.addData3(x1, y1, z1)
vertex.addData3(x2, y2, z1)
vertex.addData3(x2, y2, z2)
vertex.addData3(x1, y1, z2)
normal.addData3(normalized(2 * x1 - 1, 2 * y1 - 1, 2 * z1 - 1))
normal.addData3(normalized(2 * x2 - 1, 2 * y2 - 1, 2 * z1 - 1))
normal.addData3(normalized(2 * x2 - 1, 2 * y2 - 1, 2 * z2 - 1))
normal.addData3(normalized(2 * x1 - 1, 2 * y1 - 1, 2 * z2 - 1))
# adding different colors to the vertex for visibility
# color.addData4f(1.0, 0.0, 0.0, 1.0)
# color.addData4f(0.0, 1.0, 0.0, 1.0)
# color.addData4f(0.0, 0.0, 1.0, 1.0)
# color.addData4f(1.0, 0.0, 1.0, 1.0)
texcoord.addData2f(0.0, 1.0)
texcoord.addData2f(0.0, 0.0)
texcoord.addData2f(1.0, 0.0)
texcoord.addData2f(1.0, 1.0)
# Quads aren't directly supported by the Geom interface
# you might be interested in the CardMaker class if you are
# interested in rectangle though
tris = GeomTriangles(Geom.UHDynamic)
tris.addVertices(0, 1, 3)
tris.addVertices(1, 2, 3)
square = Geom(vdata)
square.addPrimitive(tris)
return square
示例6: create_geom
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addVertices [as 别名]
def create_geom(self, sidelength):
# Set up the vertex arrays
vformat = GeomVertexFormat.getV3n3c4()
vdata = GeomVertexData("Data", vformat, Geom.UHDynamic)
vertex = GeomVertexWriter(vdata, 'vertex')
normal = GeomVertexWriter(vdata, 'normal')
color = GeomVertexWriter(vdata, 'color')
geom = Geom(vdata)
# Write vertex data
for x in range(0, sidelength):
for y in range(0, sidelength):
# vertex_number = x * sidelength + y
v_x, v_y, v_z = self.map_b[(x, y)]
n_x, n_y, n_z = 0.0, 0.0, 1.0
c_r, c_g, c_b, c_a = 0.5, 0.5, 0.5, 0.5
vertex.addData3f(v_x, v_y, v_z)
normal.addData3f(n_x, n_y, n_z)
color.addData4f(c_r, c_g, c_b, c_a)
# Add triangles
for x in range(0, sidelength - 1):
for y in range(0, sidelength - 1):
# The vertex arrangement (y up, x right)
# 2 3
# 0 1
v_0 = x * sidelength + y
v_1 = x * sidelength + (y + 1)
v_2 = (x + 1) * sidelength + y
v_3 = (x + 1) * sidelength + (y + 1)
if (x+y)%1 == 0: # An even square
tris = GeomTriangles(Geom.UHStatic)
tris.addVertices(v_0, v_2, v_3)
tris.closePrimitive()
geom.addPrimitive(tris)
tris = GeomTriangles(Geom.UHStatic)
tris.addVertices(v_3, v_1, v_0)
tris.closePrimitive()
geom.addPrimitive(tris)
else: # An odd square
tris = GeomTriangles(Geom.UHStatic)
tris.addVertices(v_1, v_0, v_2)
tris.closePrimitive()
geom.addPrimitive(tris)
tris = GeomTriangles(Geom.UHStatic)
tris.addVertices(v_2, v_3, v_1)
tris.closePrimitive()
geom.addPrimitive(tris)
# Create the actual node
node = GeomNode('geom_node')
node.addGeom(geom)
# Remember GeomVertexWriters to adjust vertex data later
#self.vertex_writer = vertex
#self.color_writer = color
self.vdata = vdata
return node
示例7: createTetraeder
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addVertices [as 别名]
def createTetraeder(self, iterations):
'''
Note that the first and the last node of the Thetha_Range should be 0 and 180 Degrees
because this will be just one time added to verticies
'''
#Format
format = GeomVertexFormat.getV3n3cpt2()
#VertexData
vdata = GeomVertexData('name', format, Geom.UHDynamic)
##VertexWriter
vertex = GeomVertexWriter(vdata, 'vertex')
normal = GeomVertexWriter(vdata, 'normal')
color = GeomVertexWriter(vdata, 'color')
texcoord = GeomVertexWriter(vdata, 'texcoord')
vertex.addData3f(0,1.434,-0.507)
vertex.addData3f(-1.242,-0.717,-0.507)
vertex.addData3f(1.242,-0.717,-0.507)
vertex.addData3f(0,0,1.521)
color.addData4f(1,1,1,1)
color.addData4f(1,1,1,1)
color.addData4f(1,1,1,1)
color.addData4f(1,1,1,1)
normal.addData3f(0,1.434,-0.507)
normal.addData3f(-1.242,-0.717,-0.507)
normal.addData3f(1.242,-0.717,-0.507)
normal.addData3f(0,0,1.521)
### Create Geom
geom = Geom(vdata)
### Create Primitives
prim = GeomTriangles(Geom.UHStatic)
prim.addVertices(0, 1, 2)
prim.addVertices(0, 1, 3)
prim.addVertices(1, 2, 3)
prim.addVertices(2, 0, 3)
prim.closePrimitive()
geom.addPrimitive(prim)
node = GeomNode('gnode')
node.addGeom(geom)
return node
示例8: makeNode
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addVertices [as 别名]
def makeNode(self, pointmap=(lambda x, y: (x, y, 0))):
vt = tuple(self.vertices)
t = Triangulator()
fmt = GeomVertexFormat.getV3()
vdata = GeomVertexData('name', fmt, Geom.UHStatic)
vertex = GeomVertexWriter(vdata, 'vertex')
for x, y in vt:
t.addPolygonVertex(t.addVertex(x, y))
vertex.addData3f(pointmap(x, y))
t.triangulate()
prim = GeomTriangles(Geom.UHStatic)
for n in xrange(t.getNumTriangles()):
prim.addVertices(t.getTriangleV0(n),t.getTriangleV1(n),t.getTriangleV2(n))
prim.closePrimitive()
geom = Geom(vdata)
geom.addPrimitive(prim)
node = GeomNode('gnode')
node.addGeom(geom)
return node
示例9: makeSquare
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addVertices [as 别名]
def makeSquare(face, rhs=True):
format=GeomVertexFormat.getV3n3cpt2()
format=GeomVertexFormat.getV3n3t2()
vdata=GeomVertexData('square', format, Geom.UHStatic)
vertex=GeomVertexWriter(vdata, 'vertex')
normal=GeomVertexWriter(vdata, 'normal')
#color=GeomVertexWriter(vdata, 'color')
texcoord=GeomVertexWriter(vdata, 'texcoord')
if not rhs:
face = list(reversed(face))
normalvec = (face[1]-face[0]).cross(face[2]-face[0])
normalvec.normalize()
f = 0.9 if rhs else 0.8
f = 1.0
for ver in face:
vertex.addData3f(ver*f)
normal.addData3f(normalvec)
#color.addData3f((ver+1.0+2.0)*0.25)
#color.addData3f(ver*0.0+1.0)
if not normalvec.z:
texcoord.addData2f(0.0, 0.0)
texcoord.addData2f(1.0, 0.0)
texcoord.addData2f(1.0, 1.0)
texcoord.addData2f(0.0, 1.0)
tri=GeomTriangles(Geom.UHStatic)
tri.addVertices(0, 1, 2)
tri.addVertices(2, 3, 0)
tri.closePrimitive()
square=Geom(vdata)
square.addPrimitive(tri)
return square
示例10: makeGeomNode
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addVertices [as 别名]
def makeGeomNode():
vdata = GeomVertexData('handleData', GeomVertexFormat.getV3(),
Geom.UHStatic)
v = GeomVertexWriter(vdata, 'vertex')
length = 1.0
gapLen = 0.2
coneLen = 0.18
coneRad = 0.06
circRes = 10
v.addData3f(0, 0, -length/2.0) # back cone butt
v.addData3f(0, 0, -length/2.0 + coneLen) # back cone point
v.addData3f(0, 0, -gapLen/2.0)
v.addData3f(0, 0, gapLen/2.0)
v.addData3f(0, 0, length/2.0 - coneLen) # front cone butt
v.addData3f(0, 0, length/2.0) # font cone point
# Add vertices for the cone's circles.
for z in [-length/2.0, length/2.0 - coneLen]:
for i in xrange(circRes):
theta = i*(2*pi/circRes)
v.addData3f(coneRad*sin(theta), coneRad*cos(theta), z)
lines = Geom(vdata)
# Make prims for the two lines.
for vertices in [(0, 2), (3, 5)]:
line = GeomLines(Geom.UHStatic)
line.addVertices(*vertices)
line.closePrimitive()
lines.addPrimitive(line)
cones = Geom(vdata)
# Make prims for the cones.
for back, circ in [(0, 6), (4, 6 + circRes)]:
point = back + 1
cone = GeomTriangles(Geom.UHStatic)
for i in xrange(circRes):
if i + 1 == circRes:
cone.addVertices(back, circ, circ + i)
cone.addVertices(point, circ + i, circ)
else:
cone.addVertices(back, circ + i + 1, circ + i)
cone.addVertices(point, circ + i, circ + i + 1)
cone.closePrimitive()
cones.addPrimitive(cone)
node = GeomNode('geomnode')
node.addGeom(lines)
node.addGeom(cones)
return node
示例11: reconstruct
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addVertices [as 别名]
def reconstruct(self):
trianglator = Triangulator()
#Add vertices to the trianglator
for vertex in self.vertices:
trianglator.addPolygonVertex(trianglator.addVertex(vertex))
trianglator.triangulate()
#Prepare to create the primative
self.vdata = GeomVertexData('floor', GeomVertexFormat.getV3n3cpt2(), Geom.UHStatic)
vertexW = GeomVertexWriter(self.vdata, 'vertex')
normalW = GeomVertexWriter(self.vdata, 'normal')
colorW = GeomVertexWriter(self.vdata, 'color')
texcoordW = GeomVertexWriter(self.vdata, 'texcoord')
#Add vertices to the primative
i = 0
while i < trianglator.getNumVertices():
vertex = trianglator.getVertex(i)
vertexW.addData3f(vertex.x,vertex.y,0.0)
normalW.addData3f(0,0,1)
colorW.addData4f(0.1,0.1,0.1,0.5)
texcoordW.addData2f(0.0, 1.0)
i+=1
self.geom = Geom(self.vdata)
#Add triangles to the primative
i = 0
print(trianglator.getNumTriangles())
while i < trianglator.getNumTriangles():
tri = GeomTriangles(Geom.UHStatic)
tri.addVertices(trianglator.getTriangleV0(i),trianglator.getTriangleV1(i),trianglator.getTriangleV2(i))
tri.closePrimitive()
self.geom.addPrimitive(tri)
i+=1
self.addGeom(self.geom)
示例12: PolyGroup
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addVertices [as 别名]
class PolyGroup():
# vdata is the Panda3D vertex data object created by the main Mesh
def __init__(self, vdata, tex_idx):
self.vdata = vdata # vertex data, passed in from parent mesh
self.name = 'PolyGroup_'+str(tex_idx)
self.geom = Geom(self.vdata)
self.primitives = GeomTriangles(Geom.UHStatic)
self.geom.addPrimitive(self.primitives)
self.sprite_list_index = 0
self.nodePath = None
# Parameters:
# wld_container - WldContainer parent object
# f - the f36 fragment we are based on
# start_index - index of our first poly in the fragment's polyList polygon list
# n_polys - numer of polys to build
# tex_idx - index of the texture that all our polys share
def build(self, wld_container, f, start_index, n_polys, tex_idx,debug=False):
# f.dump()
self.sprite_list_index = f.fragment1-1 # the fragment1 ref is used as sprite list index
sprite = wld_container.getSprite(tex_idx, self.sprite_list_index)
polyList = f.polyList
poly_idx = start_index
for poly in range(0, n_polys):
p = polyList[poly_idx]
poly_idx += 1
self.primitives.addVertices(p[0], p[1], p[2])
self.node = GeomNode(self.name)
self.node.addGeom(self.geom)
# make a node path for our GEOM, these will be attached under our parent mesh's root
self.nodePath = NodePath(self.node)
# self.nodePath.setRenderModeWireframe()
# self.nodePath.setRenderModeFilled()
# self.nodePath.showBounds()
self.nodePath.setPos(f.centerX, f.centerY,f.centerZ) # translate to correct position
self.nodePath.setAttrib(CullFaceAttrib.make(CullFaceAttrib.MCullCounterClockwise))
# self.nodePath.setAttrib(CullFaceAttrib.make(CullFaceAttrib.MCullClockwise))
# Texture setup
if sprite != None:
# sprite.dump()
if sprite.numtex > 0:
t = sprite.textures[0]
self.nodePath.setTexture(t)
if debug:
print(" polygroup build had texture count: " + str(sprite.numtex) + " AnimDelay: " + str(sprite.anim_delay))
patchInvertDDSV(self.nodePath,t,debug)
if sprite.anim_delay > 0:
geom_num = self.node.getNumGeoms()-1
if debug:
print("Adding geom render state for " + self.name)
from panda3d.core import ColorBlendAttrib
# seems animated "masked" textrue need this in order to function
# dont want to have it on the main zone geoms though cause it breaks
# semi trasparent surfaces (water etc). Probably should move away from making those
# transparent through color blending and simply patch up their alpha channels as needed?
if sprite.masked == 1:
self.node.setAttrib(ColorBlendAttrib.make(ColorBlendAttrib.MAdd,ColorBlendAttrib.OAlphaScale,ColorBlendAttrib.OOne))
sprite.addAnimGeomRenderState( (self.node,geom_num,self.node.getGeomState(geom_num),self.name) )
else:
print 'Error: texture (idx=%i) not found. PolyGroup will be rendered untextured' % (tex_idx)
return 1
示例13: visualize
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addVertices [as 别名]
def visualize(centers, corners, edges):
from meshtool.filters.panda_filters.pandacore import getVertexData, attachLights, ensureCameraAt
from meshtool.filters.panda_filters.pandacontrols import KeyboardMovement, MouseDrag, MouseScaleZoom, MouseCamera
from panda3d.core import GeomPoints, GeomTriangles, Geom, GeomNode, GeomVertexFormat, GeomVertexData, GeomVertexWriter, LineSegs, VBase3
from direct.showbase.ShowBase import ShowBase
format = GeomVertexFormat.getV3c4()
vdata = GeomVertexData('pts', format, Geom.UHDynamic)
vertex = GeomVertexWriter(vdata, 'vertex')
color = GeomVertexWriter(vdata, 'color')
vertex_index = 0
center_vertex_indices = {}
corner_vertex_indices = {}
for key, center in centers.iteritems():
vertex.addData3f(center.x * X_SCALE, center.y * Y_SCALE, center.elevation * Z_SCALE)
curcolor = hex2rgb(COLORS[center.biome])
color.addData4f(curcolor[0], curcolor[1], curcolor[2], 1)
center_vertex_indices[key] = vertex_index
vertex_index += 1
for corner in center.corners:
vertex.addData3f(corner.x * X_SCALE, corner.y * Y_SCALE, corner.elevation * Z_SCALE)
color.addData4f(curcolor[0], curcolor[1], curcolor[2], 1)
corner_vertex_indices[corner.id] = vertex_index
vertex_index += 1
tris = GeomTriangles(Geom.UHDynamic)
for edge in edges.itervalues():
corner0 = edge.corner0
corner1 = edge.corner1
center0 = edge.center0
center1 = edge.center1
if corner0 is None or corner1 is None:
continue
tris.addVertices(corner_vertex_indices[corner1.id],
corner_vertex_indices[corner0.id],
center_vertex_indices[center0.id])
tris.addVertices(center_vertex_indices[center1.id],
corner_vertex_indices[corner0.id],
corner_vertex_indices[corner1.id])
tris.closePrimitive()
pgeom = Geom(vdata)
pgeom.addPrimitive(tris)
node = GeomNode("primitive")
node.addGeom(pgeom)
p3dApp = ShowBase()
attachLights(render)
geomPath = render.attachNewNode(node)
#geomPath.setRenderModeThickness(6.0)
#geomPath.setRenderModeWireframe()
ensureCameraAt(geomPath, base.cam)
boundingSphere = geomPath.getBounds()
base.cam.setPos(boundingSphere.getCenter() + boundingSphere.getRadius())
base.cam.lookAt(boundingSphere.getCenter())
geomPath.setScale(VBase3(50,50,50))
KeyboardMovement()
#MouseDrag(geomPath)
MouseCamera()
MouseScaleZoom(geomPath)
#render.setShaderAuto()
p3dApp.run()
示例14: create_node
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addVertices [as 别名]
def create_node(self):
# Set up the vertex arrays
vformat = GeomVertexFormat.get_v3n3c4t2()
vdata = GeomVertexData("Data", vformat, Geom.UHDynamic)
vertex = GeomVertexWriter(vdata, 'vertex')
normal = GeomVertexWriter(vdata, 'normal')
color = GeomVertexWriter(vdata, 'color')
texcoord = GeomVertexWriter(vdata, 'texcoord')
geom = Geom(vdata)
# Write vertex data
for v in range(0, self.res[1] + 1):
for u in range(0, self.res[0] + 1):
# vertex_number = u * (self.res[0] + 1) + v
t_u, t_v = float(u)/float(self.res[0]), float(v)/float(self.res[1])
# Vertex positions and normals will be overwritten before the first displaying anyways.
vertex.addData3f(0, 0, 0)
normal.addData3f(0, 0, 0)
# Color is actually not an issue and should probably be kicked out of here.
color.addData4f(1, 1, 1, 1)
# Texcoords are constant, so this should be moved into its own array.
texcoord.addData2f(t_u, t_v)
# Add triangles
for u in range(0, self.res[0]):
for v in range(0, self.res[1]):
# The vertex arrangement (y up, x right)
# 2 3
# 0 1
u_verts = self.res[0] + 1
v_0 = u + v * u_verts
v_1 = (u + 1) + v * u_verts
v_2 = u + (v + 1) * u_verts
v_3 = (u + 1) + (v + 1) * u_verts
tris = GeomTriangles(Geom.UHDynamic)
tris.addVertices(v_2, v_0, v_1)
tris.closePrimitive()
geom.addPrimitive(tris)
tris = GeomTriangles(Geom.UHDynamic)
tris.addVertices(v_1, v_3, v_2)
tris.closePrimitive()
geom.addPrimitive(tris)
# Create the actual node
sphere = GeomNode('geom_node')
sphere.addGeom(geom)
sphere_np = NodePath(sphere)
tex = base.loader.loadTexture("assets/geosphere/geosphere_day.jpg")
sphere_np.setTexture(tex)
self.sphere_np = sphere_np
self.sphere_vdata = vdata
# -----
vformat = GeomVertexFormat.get_v3n3c4()
vdata = GeomVertexData("Data", vformat, Geom.UHDynamic)
vertex = GeomVertexWriter(vdata, 'vertex')
color = GeomVertexWriter(vdata, 'color')
geom = Geom(vdata)
vertex.addData3f(-1, -1, 0)
color.addData4f(1, 1, 1, 1)
vertex.addData3f(1, -1, 0)
color.addData4f(1, 1, 1, 1)
tris = GeomLines(Geom.UHDynamic)
tris.addVertices(0, 1)
tris.closePrimitive()
geom.addPrimitive(tris)
connections = GeomNode('geom_node')
connections.addGeom(geom)
connections_np = NodePath(connections)
connections_np.setRenderModeThickness(3)
self.connections_np = connections_np
self.connections_vdata = vdata
self.connections_geom = geom
self.connections_np.reparent_to(sphere_np)
return sphere_np
示例15: build
# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import addVertices [as 别名]
def build(self):
# http://www.panda3d.org/forums/viewtopic.php?t=11528
"""Create the geometry from the submitted arrays"""
verts = self.verts
polys = self.polys
self.geomnode = GeomNode('geometry')
self.color_lookup = []
if not self.vnorms:
self.getNormals()
if not self.uvs:
self.getUVMapping()
if self.use_tangents:
self.getTangents()
# Build array for new format.
array = GeomVertexArrayFormat()
array.addColumn(InternalName.make(b'vertex'), 3, Geom.NTFloat32, Geom.CPoint)
array.addColumn(InternalName.make(b'texcoord'), 2, Geom.NTFloat32, Geom.CTexcoord)
array.addColumn(InternalName.make(b'normal'), 3, Geom.NTFloat32, Geom.CVector)
if self.use_tangents:
array.addColumn(InternalName.make(b'binormal'), 3, Geom.NTFloat32, Geom.CVector)
array.addColumn(InternalName.make(b'tangent'), 3, Geom.NTFloat32, Geom.CVector)
# Create and register format.
format = GeomVertexFormat()
format.addArray(array)
format = GeomVertexFormat.registerFormat(format)
geoms = []
for i in range(len(self.colors)):
vdata = GeomVertexData('ngon', format, Geom.UHStatic)
geom = Geom(vdata)
tri = GeomTriangles(Geom.UHStatic)
vertex = GeomVertexWriter(vdata, b'vertex')
normal = GeomVertexWriter(vdata, b'normal')
texcoord = GeomVertexWriter(vdata, b'texcoord')
geoms.append({'geom':geom,
'tri':tri,
'vertex':vertex,
'texcoord':texcoord,
'normal':normal,
'index':0,
'vdata':vdata,
'color':i})
if self.use_tangents:
tangent = GeomVertexWriter(vdata, b'tangent')
binormal = GeomVertexWriter(vdata, b'binormal')
geoms[i]['tangent'] = tangent
geoms[i]['binormal'] = binormal
for poly_index in range(len(polys)):
color_index = self.colors.index(self.mats[poly_index])
vertcount = geoms[color_index]['index']
p = polys[poly_index]
poly = [verts[i] for i in p]
uvs = self.uvs[poly_index]
norm = [self.vnorms[i] for i in p]
if self.use_tangents:
binorm = [self.binorms[i] for i in p]
tan = [self.tans[i] for i in p]
reindexed = [] # New vertex indices per-poly
for v in poly:
geoms[color_index]['vertex'].addData3f(v[0], v[1], v[2])
reindexed.append(vertcount)
vertcount += 1
geoms[color_index]['index'] = vertcount
for i in range(len(poly)):
geoms[color_index]['normal'].addData3f(Vec3(norm[i][0], norm[i][1], norm[i][2]))
if self.use_tangents:
geoms[color_index]['binormal'].addData3f(Vec3(binorm[i][0], binorm[i][1], binorm[i][2]))
geoms[color_index]['tangent'].addData3f(Vec3(tan[i][0], tan[i][1], tan[i][2]))
for tvert in uvs:
geoms[color_index]['texcoord'].addData2f(tvert[0], tvert[1])
triangulated = self.getFanning(reindexed) # Use new vertex indices
for tri_index in range(len(triangulated)):
t = triangulated[tri_index]
tri = geoms[color_index]['tri']
tri.addVertices(t[0], t[1], t[2])
for color_index in range(len(self.colors)):
geom = geoms[color_index]['geom']
tri = geoms[color_index]['tri']
tri.closePrimitive()
geom.addPrimitive(tri)
self.geomnode.addGeom(geom)
self.color_lookup.append(color_index)