Want more features on Pastebin? Sign Up, it's FREE!
Guest

cubes.py

By: a guest on Oct 28th, 2011  |  syntax: Python  |  size: 1.57 KB  |  views: 667  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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())
  50. cube.setTexture(loader.loadTexture("tex.png"))
  51.  
  52. print time() - ftime
  53.  
  54. #filters = CommonFilters(base.win, base.cam)
  55. #filters.setBloom()
  56. #render.setShaderAuto()
  57. run()
  58.  
clone this paste RAW Paste Data