• API
• FAQ
• Tools
• Trends
• Archive
SHARE
TWEET

# cubes.py

a guest Oct 28th, 2011 877 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #
2. #
3. #
4. #
5. #
6.
7. from direct.directbase import DirectStart
8. from direct.filter.CommonFilters import *
9. from time import time
10. from meshgenerator import MeshGenerator
11. from panda3d.core import ConfigVariableString
12. from random import randint
13.
14. cubes = {}
15.
16. for x in range(0, 25):
17.     cubes[x] = {}
18.     for y in range(0, 25):
19.         cubes[x][y] = {}
20.         for z in range(0, 25):
21.             cubes[x][y][z] = randint(0, 2)
22.
23. ftime = time()
24. mesh = MeshGenerator('world')
25.
26. for j in cubes:
27.     for i in cubes[j]:
28.         for k in cubes[j][i]:
29.
30.             id = cubes[j][i][k]
31.
32.             if id == 0:
33.                 continue
34.
35.             if j-1 not in cubes or cubes[j-1][i][k] == 0:
36.                 mesh.makeLeftFace(j, i, k, id)
37.             if j+1 not in cubes or cubes[j+1][i][k] == 0:
38.                 mesh.makeRightFace(j, i, k, id)
39.             if i-1 not in cubes[j] or cubes[j][i-1][k] == 0:
40.                 mesh.makeBackFace(j, i, k, id)
41.             if i+1 not in cubes[j] or cubes[j][i+1][k] == 0:
42.
43.                 mesh.makeFrontFace(j, i, k, id)
44.             if k-1 not in cubes[j][i] or cubes[j][i][k-1] == 0:
45.                 mesh.makeBottomFace(j, i, k, id)
46.             if k+1 not in cubes[j][i] or cubes[j][i][k+1] == 0:
47.                 mesh.makeTopFace(j, i, k, id)
48.
49. cube = render.attachNewNode(mesh.getGeomNode())