当前位置: 首页>>代码示例>>Python>>正文


Python Batch.add_indexed方法代码示例

本文整理汇总了Python中pyglet.graphics.Batch.add_indexed方法的典型用法代码示例。如果您正苦于以下问题:Python Batch.add_indexed方法的具体用法?Python Batch.add_indexed怎么用?Python Batch.add_indexed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyglet.graphics.Batch的用法示例。


在下文中一共展示了Batch.add_indexed方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from pyglet.graphics import Batch [as 别名]
# 或者: from pyglet.graphics.Batch import add_indexed [as 别名]
class World:
    def __init__(self):
        self.current_lists = {}
        self.old_lists = {}
        self.zone_size = 30.0
        self.patch_size = 0.5
        self.zone_x = None
        self.zone_z = None
        self.terrain_batch = Batch()
        self.sea_batch = Batch()
        self.tree_batch = Batch()

    def gen_terrain(self, mutex, x, z):
        zone_size = self.zone_size
        patch_size = self.patch_size
        w = zone_size / patch_size + 1
        assert w == int(w)
        w = int(w)
        xmin = (x - 0.5) * zone_size
        xmax = (x + 0.5) * zone_size
        zmin = (z - 0.5) * zone_size
        zmax = (z + 0.5) * zone_size
        v = []
        v_sea = []
        n = []
        c = []
        t = []
        for i in np.linspace(xmin, xmax, w):
            time.sleep(0.2)
            for j in np.linspace(zmin, zmax, w):
                y = self.get_v(i, j)
                vv = [i, y, j]
                vv_sea = [i, 0.0, j]
                nn = self.get_n(i, j)
                v += vv
                v_sea += vv_sea
                n += nn
                if y > 10.0:
                    c += [255, 255, 255]
                elif y > 7.0:
                    c += [255, 120, 0]
                elif y > 1.0:
                    c += [0, 255, 0]
                    if random.random() > 0.5:
                        t.append([i, y, j])
                elif y > 0.0:
                    c += [255, 255, 150]
                else:
                    c += [0, 0, 255]
        index = []
        for i in range(0, w-1):
            for j in range(0, w-1):
                index += [
                    i + j * w,
                    i + j * w + 1,
                    i + j * w + 1 + w,
                    i + j * w + w]
        data = [index, v, n, c, v_sea, t]
        mutex.acquire()
        self.current_lists[(x, z)] = data
        mutex.release()
        #np.savez('save/{0}_{1}.npz'.format(x,z), data)

    def draw(self):
        self.terrain_batch.draw()
        self.sea_batch.draw()
        self.tree_batch.draw()

    def zone_lists_changed(self):
        tmp_lists = self.current_lists.copy()
        if tmp_lists != self.old_lists:
            self.old_lists = self.current_lists.copy()
            return True
        return False

    def zone_changed(self):
        size = self.zone_size
        player_x = int(np.floor(self.player.position[0] / size + 0.5))
        player_z = int(np.floor(self.player.position[2] / size + 0.5))
        return (player_x != self.zone_x or player_z != self.zone_z)

    def draw_terrain(self, l, w2):
        vlist = self.terrain_batch.add_indexed(
            w2, GL_QUADS, None, l[0],
            ('v3f/static', l[1]), ('n3f/static', l[2]),
            ('c3B/static', l[3]))

    def draw_sea(self, l, w2):
        n = [0, 0, 255] * w2
        vlist = self.sea_batch.add_indexed(
            w2, GL_QUADS, None, l[0],
            ('v3f/static', l[4]), ('n3f/static', n),
            ('c3B/static', l[3]))

    def draw_tree(self, l, w2):
        for [x, y, z] in l[5]:
            self.add_tree(self.tree_batch, x, y, z)

    def draw_sea_simple(self):
        tmp_lists = self.current_lists.copy()
#.........这里部分代码省略.........
开发者ID:NixSilva,项目名称:lonely_islands_unlimited,代码行数:103,代码来源:world.py


注:本文中的pyglet.graphics.Batch.add_indexed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。