still having problems with my city generator script:
#Cityscape v.01
#based extensively on the Demo Script in the Blender 2.3x Manual
##########################################
import Blender
from Blender import NMesh
from Blender.BGL import *
from Blender.Draw import *
import math
from math import *
import whrandom
#building parameters
T_height = Create(10)
T_width = Create(1)
T_depth = Create(1)
T_buildnum = Create(10)
#Events
EVENT_NOEVENT = 1
EVENT_DRAW = 2
EVENT_EXIT = 3
EVENT_CITY = 4
############################################
#Drawing GUI
############################################
def draw() :
global T_height
global T_width
global T_depth
global T_buildnum
global EVENT_NOEVENT, EVENT_DRAW, EVENT_EXIT
##############title
glClear(GL_COLOR_BUFFER_BIT)
glRasterPos2d(8, 173)
Text("Cityscape")
############# GUI buttons
glRasterPos2d(8, 153)
Text("Settings")
T_height = Number("Height: ", EVENT_NOEVENT,
10, 125, 210, 18,
T_height.val, 1, 60, "Height of building") ;
T_width = Number("Width: ", EVENT_NOEVENT,
10, 105, 210, 18,
T_width.val, 1, 10, "Width of building") ;
T_depth = Number("Depth: ", EVENT_NOEVENT,
10, 85, 210, 18,
T_depth.val, 1, 10, "Depth of building") ;
T_buildnum = Number("Number of buildings: ", EVENT_NOEVENT,
250, 125, 210, 18,
T_buildnum.val, 2, 1000, "Number of buildings") ;
T_citygen = Button("Generate City", EVENT_CITY,
250, 100,
100, 25, "generate city") ;
############Draw and Exit Buttons
Button("Draw", EVENT_DRAW, 10, 20, 80, 18)
Button("Exit", EVENT_EXIT, 140, 20, 80, 18)
##################################################
#Handling Events
###################################################
def event(evt, val):
if (evt == QKEY and not val):
Exit()
def bevent(evt):
global T_height
global T_width
global T_depth
global T_citygen
global T_buildnum
global EVENT_NOEVENT,EVENT_DRAW,EVENT_EXIT
######### Manages GUI events
if (evt == EVENT_EXIT):
Exit()
elif (evt== EVENT_DRAW):
Building(T_height.val, T_width.val, T_depth.val)
if (evt == EVENT_CITY):
city()
Blender.Redraw()
Register(draw, event, bevent)
########################################
#Creating the building
########################################
def Building(height, width, depth):
##############Create the mesh
poly = NMesh.GetRaw()
############## Add vertices
v = NMesh.Vert(0.0,0.0,0.0)
poly.verts.append(v)
v = NMesh.Vert(width,0.0,0.0)
poly.verts.append(v)
v = NMesh.Vert(0.0,depth,0.0)
poly.verts.append(v)
v = NMesh.Vert(width,depth,0.0)
poly.verts.append(v)
v = NMesh.Vert(0.0,0.0,height)
poly.verts.append(v)
v = NMesh.Vert(width,0.0,height)
poly.verts.append(v)
v = NMesh.Vert(width,depth,height)
poly.verts.append(v)
v = NMesh.Vert(0.0,depth,height)
poly.verts.append(v)
f = NMesh.Face()
f.v.append(poly.verts[0 ])
f.v.append(poly.verts[1 ])
f.v.append(poly.verts[3 ])
f.v.append(poly.verts[2 ])
poly.faces.append(f)
g = NMesh.Face()
g.v.append(poly.verts[4])
g.v.append(poly.verts[5])
g.v.append(poly.verts[6])
g.v.append(poly.verts[7])
poly.faces.append(g)
h = NMesh.Face()
h.v.append(poly.verts[0])
h.v.append(poly.verts[2])
h.v.append(poly.verts[7])
h.v.append(poly.verts[4])
poly.faces.append(h)
i = NMesh.Face()
i.v.append(poly.verts[7])
i.v.append(poly.verts[6])
i.v.append(poly.verts[3])
i.v.append(poly.verts[2])
poly.faces.append(i)
j = NMesh.Face()
j.v.append(poly.verts[0])
j.v.append(poly.verts[1])
j.v.append(poly.verts[5])
j.v.append(poly.verts[4])
poly.faces.append(j)
k = NMesh.Face()
k.v.append(poly.verts[5])
k.v.append(poly.verts[6])
k.v.append(poly.verts[3])
k.v.append(poly.verts[1])
poly.faces.append(k)
############## Creates new object
polyObj = NMesh.PutRaw(poly)
############################################
#CITY STUFF
############################################
###########city
#generates buildings along x axis
def city():
global height
global T_width
global depth
global T_buildnum
global EVENT_NOEVENT,EVENT_DRAW,EVENT_EXIT, EVENT_CITY
for n in range(T_buildnum.val):
Building(T_height.val, T_width.val, T_depth.val)
sel = Blender.Object.GetSelected()
for obj in sel:
objlocx = obj.LocX
objlocx = (n * T_width.val) + (T_width.val * n)
obj.LocX = objlocx
City2()
#adds randomness
r = whrandom.random()
if r < 0.7:
r = r + 1
objsizex = obj.SizeX
objsizex = objsizex * r
obj.SizeX = objsizex
#adds randomness
r_2 = whrandom.random()
if r_2 < 0.7:
r_2 = r_2 + 1
objsizez = obj.SizeZ
objsizez = objsizez * r_2
obj.SizeZ = objsizez
#adds randomness
r_3 = whrandom.random()
if r_3 < 0.7:
r_3 = r_3 + 1
objsizey = obj.SizeY
objsizey = objsizey * r_3
obj.SizeY = objsizey
City2()
###############################################################
def City2():
global height
global T_width
global depth
global T_buildnum
global EVENT_NOEVENT,EVENT_DRAW,EVENT_EXIT, EVENT_CITY
global objlocx
for n in range(T_buildnum.val):
Building(T_height.val, T_width.val, T_depth.val)
#adds randomness
r = whrandom.random()
if r < 0.7:
r = r + 1
sel = Blender.Object.GetSelected()
print(sel)
for obj in sel:
objlocy = obj.LocY
objlocy = (n * T_depth.val) + (T_depth.val * n)
obj.LocY = objlocy
objsizex = obj.SizeX
objsizex = objsizex * r
obj.SizeX = objsizex
print(r)
#adds randomness
r_2 = whrandom.random()
if r_2 < 0.7:
r_2 = r_2 + 1
objsizez = obj.SizeZ
objsizez = objsizez * r_2
obj.SizeZ = objsizez
print(r_2)
#adds randomness
r_3 = whrandom.random()
if r_3 < 0.7:
r_3 = r_3 + 1
objsizey = obj.SizeY
objsizey = objsizey * r_3
obj.SizeY = objsizey
its supposed to generate 1 building along y axis, then n on x axis, then one more on y axis, then n more on x axis, but i dont think that the y axis function is calling the x axis function properly.
anyone see the problem?