pforbinesque on DeviantArthttp://creativecommons.org/licenses/by-nc-nd/3.0/https://www.deviantart.com/pforbinesque/art/32x32-44931922pforbinesque

Deviation Actions

pforbinesque's avatar

32x32

By
Published:
367 Views

Description

from random import *
from math import *

import polytope
import solid
import valve220
import wavefront

streetwidth = 3.5 * 4.0
streetthickness = 2.0
sidewalkwidth = 2.5
sidewalkthickness = 0.25

blockwidth = 128.0
blockdepth = 128.0
blockheight= 128.0

def makestreets(minx, miny, minz, maxx, maxy, maxz):
w = maxx - minx
d = maxy - miny
h = maxz - minz
box = solid.Box(width=w, depth=d, height=h)
cx = minx + (w / 2.0)
cy = miny + (d / 2.0)
cz = minz + (h / 2.0)
return box.translate(cx, cy, cz)


def makesidewalks(minx, miny, minz, maxx, maxy, maxz):
w = maxx - minx
d = maxy - miny
h = maxz - minz
box = solid.Box(width=w, depth=d, height=h)
cx = minx + (w / 2.0)
cy = miny + (d / 2.0)
cz = minz + (h / 2.0)
return box.translate(cx, cy, cz)


def makelot(minx, miny, minz, maxx, maxy, maxz):
res = polytope.Polytope()
n = randint(6, 12)
for i in xrange(0, n):
bx = maxx - minx
by = maxy - miny
bz = maxz - minz
w = (random() * (0.80 * bx))
while w < 5.0:
w = (random() * (0.80 * bx))
d = (random() * (0.80 * by))
while d < 5.0:
d = (random() * (0.80 * by))
h = (random() * bz)
while h < 1.0:
# h = (random() * bz)
h = normalvariate(bz, 1.2)
px = (random() * bx)
while (minx + px + w) > maxx:
px = (random() * bx)
py = (random() * by)
while (miny + py + d) > maxy:
py = (random() * by)
tx = minx + px + (w / 2.0)
ty = miny + py + (d / 2.0)
tz = minz + (h / 2.0)
if randint(0, 10) < 3:
item = solid.Cylinder(radius=0.5, height=1.0, sides=randint(3, 12))
item.scale(w, d, h)
item.translate(tx, ty, tz)
else:
item = solid.Box(width=w, depth=d, height=h)
item.translate(tx, ty, tz)
# res = polytope.Union(res, item)
res.add(item)
return res.merge()


def makecityblock(minx, miny, minz, maxx, maxy, maxz):
# single block that goes from the ground up to the streetthickness
bottomofstreet = minz
topofstreet = minz + streetthickness

# single block on top of the street and inset
bottomofsidewalk = topofstreet
topofsidewalk = bottomofsidewalk + sidewalkthickness

# fillable volume
lotminx = minx + streetwidth + sidewalkwidth + 0.5
lotminy = miny + streetwidth + sidewalkwidth + 0.5
lotminz = topofsidewalk
lotmaxx = maxx - streetwidth - sidewalkwidth - 0.5
lotmaxy = maxy - streetwidth - sidewalkwidth - 0.5
lotmaxz = maxz

A = makelot(lotminx, lotminy, lotminz, lotmaxx, lotmaxy, lotmaxz)
B = makestreets(minx, miny, minz, maxx, maxy, topofstreet)
C = makesidewalks(minx + streetwidth, miny + streetwidth, bottomofsidewalk, maxx - streetwidth, maxy - streetwidth, topofsidewalk)
return polytope.Polytope(A, B, C).merge()


def makecity(blockswide, blocksdeep):
nth = 0
res = polytope.Polytope()
for blocky in xrange(0, blocksdeep):
for blockx in xrange(0, blockswide):
cx = (blockx * blockwidth)
cy = (blocky * blockdepth)
cz = 0.0
minx = cx - (blockwidth / 2.0)
maxx = cx + (blockwidth / 2.0)
miny = cy - (blockdepth / 2.0)
maxy = cy + (blockdepth / 2.0)
minz = 0.0
# maxz = blockheight
maxz = 8.0 * normalvariate((blockheight * 1.5) / 8.0, 4.0)
print "MAKING BLOCK:", nth
b = makecityblock(minx, miny, minz, maxx, maxy, maxz)

e.export("testcityblock03-%02d-%02d.obj" % (blocky, blockx))
#;
res.add(b)
nth = nth + 1
#;
#;
return res.merge()


C = makecity(32, 32)

if 1: C.scale(2.0, 2.0, 2.0)
if 1: print "Preparing to export: snap to 1.0e-5 ... "
if 1: C.snap(1.0e-5)
print "Preparing to export: final merge... "
C.merge()


if 1:
print "Exporting .obj ..."
exp = wavefront.Exporter()
exp.setpolytope(C)
exp.export("testcityblock03.obj")
print ".obj export complete."
#;

if 1:
print "Exporting .map ..."
exp = valve220.Exporter()
worldspawn = valve220.Worldspawn(C)
worldspawn.putprop("geometry_scale", 128.0)
#worldspawn.putprop("light_geometry_scale", 128.0)
worldspawn.putprop("light_geometry_scale", 256.0)
exp.add(worldspawn)
exp.export("testcityblock03.map")
print "Done."
#;
Image size
960x544px 362.29 KB
Comments2
Join the community to add your comment. Already a deviant? Log In
tbob's avatar
I sure dont understand all those number and letters in the comments but I sure like waht I see in the image.