本文整理汇总了Python中panda3d.core.GeomVertexWriter.setData2f方法的典型用法代码示例。如果您正苦于以下问题:Python GeomVertexWriter.setData2f方法的具体用法?Python GeomVertexWriter.setData2f怎么用?Python GeomVertexWriter.setData2f使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.GeomVertexWriter
的用法示例。
在下文中一共展示了GeomVertexWriter.setData2f方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate
# 需要导入模块: from panda3d.core import GeomVertexWriter [as 别名]
# 或者: from panda3d.core.GeomVertexWriter import setData2f [as 别名]
def generate(self):
'''(Re)generate the entire terrain erasing any current changes'''
factor = self.blockSize*self.chunkSize
#print "Factor:", factor
for terrain in self.terrains:
terrain.getRoot().removeNode()
self.terrains = []
# Breaking master heightmap into subimages
heightmaps = []
self.xchunks = (self.heightfield.getXSize()-1)/factor
self.ychunks = (self.heightfield.getYSize()-1)/factor
#print "X,Y chunks:", self.xchunks, self.ychunks
n = 0
for y in range(0, self.ychunks):
for x in range(0, self.xchunks):
heightmap = PNMImage(factor+1, factor+1)
heightmap.copySubImage(self.heightfield, 0, 0, xfrom = x*factor, yfrom = y*factor)
heightmaps.append(heightmap)
n += 1
# Generate GeoMipTerrains
n = 0
y = self.ychunks-1
x = 0
for heightmap in heightmaps:
terrain = GeoMipTerrain(str(n))
terrain.setHeightfield(heightmap)
terrain.setBruteforce(self.bruteForce)
terrain.setBlockSize(self.blockSize)
terrain.generate()
self.terrains.append(terrain)
root = terrain.getRoot()
root.reparentTo(self.root)
root.setPos(n%self.xchunks*factor, (y)*factor, 0)
# In order to texture span properly we need to reiterate through every vertex
# and redefine the uv coordinates based on our size, not the subGeoMipTerrain's
root = terrain.getRoot()
children = root.getChildren()
for child in children:
geomNode = child.node()
for i in range(geomNode.getNumGeoms()):
geom = geomNode.modifyGeom(i)
vdata = geom.modifyVertexData()
texcoord = GeomVertexWriter(vdata, 'texcoord')
vertex = GeomVertexReader(vdata, 'vertex')
while not vertex.isAtEnd():
v = vertex.getData3f()
t = texcoord.setData2f((v[0]+ self.blockSize/2 + self.blockSize*x)/(self.xsize - 1),
(v[1] + self.blockSize/2 + self.blockSize*y)/(self.ysize - 1))
x += 1
if x >= self.xchunks:
x = 0
y -= 1
n += 1