Hey dudes.
Well ive managed to import my changes and your changes into one script .
ive kept the basic house structure for the slider and the button , it actualy works quite well if you want to make a random building thats quite big but does not just look like a big house. i think a toggle button to switch between making a old style or new style could be cool.
any how my coding is getting better but still not the greatest you know the drill.
Here are some picutes:
please excuse the long amount of code…
#!BPY
"""
Name: 'Home Designer extreme'
Blender: 237
Group: 'Mesh'
Tip: 'Creates VERY simple house-like meshes'
"""
# basic source - url - https://blenderartists.org/forum/viewtopic.php?t=45593
import Blender
from Blender import *
from Blender.Draw import *
# Define the action buttons here
# Must start with a E_ for eliance
E_DEBUG = 1 # 1 for debug to be on.0 for off.
E_EXIT = 911 # also set to QKEY
E_RANDOM = 11
E_CUSTOM_BUTTON = 10
E_CUSTOM_SLIDER = 9
E_CUSTOM_NAME = 'Create a custom building'
E_CUSTOM_NAME2 = 'Create a custom building [sliders]'
E_RANDOM_NAME = 'Click to generate a Random sized house.'
# declare the globals
sld = lung = fls = fln = Create (0)
dist = Create(0.2)
dist1 = Create(1.2)
dist2 = Create(2.2)
dist3 = Create(3.2)
negfive = Create(-5.0)
zero = Create(0.0)
one = Create(1.0)
two = Create(2.0)
three = Create(3.0)
four = Create(4.0)
five = Create(5.0)
six = Create(6.0)
print "Home Designer Extreme 0.46"
if (E_DEBUG == 1):
print ">> Debug Mode ON" # [ you can switch this by the debug button in your GUI ]"
#size=Buffer(GL_FLOAT, 4)
# glGetFloatv(GL_SCISSOR_BOX, size)
#size= size.list
# Create the action buttons here
def buton ():
global xC, yC, hpC, hsC, wC, lC, xC2, yC2, hpC2, hsC2, wC2, lC2, Toggle, n, sld, tgl, rtt, fls, fln
# Button functions.
Button ('Generate', 1, 50, 50, 200, 25)
sld = Slider ('Grid size: ', 2, 50, 190, 200, 25, sld.val, 1.0, 10.0)
tgl = Toggle ('Remove some objects?', 3, 50, 105, 200, 25, 0)
rtt = Toggle ('Rotate objects?', 4, 50, 80, 200, 25, 0)
fls = Slider ('Max floors: ', 5, 50, 130, 200, 25, fls.val, 1.0, 4.0)
fln = Slider ('Tall houses: ', 6, 50, 155, 200, 25, fln.val, 0.0, (sld.val * sld.val))
Button ('Button House', E_CUSTOM_BUTTON, 280, 410, 150, 25, E_CUSTOM_NAME)
Button ('Slider House', E_CUSTOM_SLIDER, 280, 300, 150, 25, E_CUSTOM_NAME2)
# EV 4:Debug must toggel on or off the debug print in the consol window.
Toggle('Debug', 4, 280, 100, 100, 20, 1, 'toggle tip')
Button ('Random Generate', E_RANDOM, 280, 255, 150, 25, E_RANDOM_NAME)
# EV 7: Need to find a fix here to keep the last submitted slider house values.
xC2 = Slider("xC ",7,50,380,200,25,dist.val,negfive.val,five.val,0,"Size of value X")
yC2 = Slider("yC ",7,50,355,200,25,dist.val,negfive.val,five.val,0,"Size of value Y")
hpC2 = Slider("hpC ",7,50,330,200,25,dist1.val,zero.val,five.val,0,"Size of value HP")
hsC2 = Slider("hsC ",7,50,305,200,25,dist1.val,one.val,two.val,0,"Size of value HS")
wC2 = Slider("wC ",7,50,280,200,25,dist3.val,two.val,four.val,0,"Size of value W")
lC2 = Slider("lC ",7,50,255,200,25,dist3.val,two.val,four.val,0,"Size of value L")
# EV 8: House Values for your Custom House.
xC = Number('X', 8, 50, 490, 100, 15, 1, -5, 5, 'X Value')
yC = Number('Y', 8, 50, 475, 100, 15, 1, -5, 5, 'Y Value')
hpC = Number('HP', 8, 50, 460, 100, 15, 1, 0, 5, 'HP Value')
hsC = Number('HS', 8, 50, 445, 100, 15, 1, 1, 2, 'HS Value')
wC = Number('W', 8, 50, 430, 100, 15, 2, 2, 4, 'W Value')
lC = Number('L', 8, 50, 415, 100, 15, 2, 2, 6, 'L Value')
def exit (evt, val):
if (evt == QKEY and not val):
Exit()
##########################################################################
def event (ev):
global xC, yC, hpC, hsC, wC, lC, xC2, yC2, hpC2, hsC2, wC2, lC2, Toggle
if ev == 7:
# event called when a user selects the number values.
if (E_DEBUG == 1):
print ">> Slider selected"
print "x = ",xC2
print "y = ",yC2
print "hp = ",hpC2
print "hs = ",hsC2
print "w = ",wC2
print "l = ",lC2
if ev == 8:
# event called when a user selects the number values.
if (E_DEBUG == 1):
print ">> Button selected"
print "x = ",xC
print "y = ",yC
print "hp = ",hpC
print "hs = ",hsC
print "w = ",wC
print "l = ",lC
# Create a more detailed house woohoo
if ev == 1:
if (E_DEBUG == 1):
print ">> Create a Detailed house with chimneys ...."
make (sld.val, 1, tgl.val, rtt.val, fln.val, fls.val)
return
elif ev == 9:
# Draw a custom house selected by the user.
xC2 = eval(str(xC2))
yC2 = eval(str(yC2))
hpC2 = eval(str(hpC2))
hsC2 = eval(str(hsC2))
wC2 = eval(str(wC2))
lC2 = eval(str(lC2))
semiC2 = xC2 + (wC2/2)
if (E_DEBUG == 1):
print ">> Create a Custom house with the following cordinates.[Slider style]"
print "x = ",xC2
print "y = ",yC2
print "hp = ",hpC2
print "hs = ",hsC2
print "w = ",wC2
print "l = ",lC2
print "semi = ",semiC2
CreateHouse(xC2, yC2, hpC2, hsC2, wC2, lC2, semiC2)
return
elif ev == 10:
# Draw a custom house selected by the user.
if (E_DEBUG == 1):
print ">> Create a Custom house with the following cordinates.[button style]"
print "x = ",xC
print "y = ",yC
print "hp = ",hpC
print "hs = ",hsC
print "w = ",wC
print "l = ",lC
# could add a cheeky hack here to try get the floats correct
# select a random from the point the user chose to 1 int above it.
# TODO : figure out adding numbers to a int or make the float correctly
# if i can do this the form section will work correctly
# built-in functions int(), long(), and float() convert inputs
x = eval(str(xC))
y = eval(str(yC))
hp = eval(str(hpC))
hs = eval(str(hsC))
w = eval(str(wC))
l = eval(str(lC))
semi = x + (w/2)
if (E_DEBUG == 1):
print " >> new values"
print "x = ",x
print "y = ",y
print "hp = ",hp
print "hs = ",hs
print "w = ",w
print "l = ",l
print "semi = ",semi
CreateHouse(x, y, hp, hs, w, l, semi)
return
elif ev == 11:
# user does not know what he wants so draw a random house.
# Draw a random size house for the user.
# Returns a random number eg: 2.03430345967
x = Mathutils.Rand (-5,5)
y = Mathutils.Rand (-5,5)
hp = Mathutils.Rand (0,5)
hs = Mathutils.Rand (1,2)
w = Mathutils.Rand (2,4)
l = Mathutils.Rand (2,6)
semi = x + (w/2)
if (E_DEBUG == 1):
print ">> Random House Generated."
print "x = ",x
print "y = ",y
print "hp = ",hp
print "hs = ",hs
print "w = ",w
print "l = ",l
print "semi = ",semi
CreateHouse(x, y, hp, hs, w, l, semi)
return
Register (buton, exit, event)
############################################################################
# Main Function to use when drawing a simple block house.
# Basic house mesh - i like to keep this as a option as well as the more detailed house.
def CreateHouse(x, y, hp, hs, w, l, semi):
if (E_DEBUG == 1):
print ">> Inside CreateHouse"
print "x = ",x
print "y = ",y
print "hp = ",hp
print "hs = ",hs
print "w = ",w
print "l = ",l
print "semi = ",semi
mesh = NMesh.New()
# Method: NMesh.Vert([x, y, z])
# Returns a new NMVert object, created from the given x,y,and z coordinates. If any of the coordinates are not passed they default to 0.0.
a = NMesh.Vert (x,y,0)
b = NMesh.Vert ((x+w),y,0)
c = NMesh.Vert ((x+w),(y+l),0)
d = NMesh.Vert (x,(y+l),0)
e = NMesh.Vert (x,y,hp)
f = NMesh.Vert ((x+w),y,hp)
g = NMesh.Vert ((x+w),(y+l),hp)
h = NMesh.Vert (x,(y+l),hp)
i = NMesh.Vert (semi,y,(hp+hs))
j = NMesh.Vert (semi,(y+l),(hp+hs))
mesh.verts.append (a)
mesh.verts.append (b)
mesh.verts.append (c)
mesh.verts.append (d)
mesh.verts.append (e)
mesh.verts.append (f)
mesh.verts.append (g)
mesh.verts.append (h)
mesh.verts.append (i)
mesh.verts.append (j)
# Method: NMesh.Face()
# Face() Return a new NMCol object created from the given r,g,b, and a color components. If any of the components are not passed they default to 255.
abcd = NMesh.Face ([a,b,c,d])
abfe = NMesh.Face ([a,b,f,e])
bcgf = NMesh.Face ([b,c,g,f])
cdhg = NMesh.Face ([c,d,h,g])
daeh = NMesh.Face ([d,a,e,h])
efi = NMesh.Face ([e,f,i])
ghj = NMesh.Face ([g,h,j])
fgji = NMesh.Face ([f,g,j,i])
heij = NMesh.Face ([h,e,i,j])
# these dimensions are taken from the frount camera view.
# These are each pannel that will be placed and put together.
mesh.faces.append (abcd) # Floor
mesh.faces.append (abfe) # Frount Wall
mesh.faces.append (bcgf) # Right Wall
mesh.faces.append (cdhg) # Back Wall
mesh.faces.append (daeh) # Left Wall
mesh.faces.append (efi) # Frount Roof Triangle
mesh.faces.append (ghj) # Back Roof Triangle
mesh.faces.append (fgji) # Right Roof
mesh.faces.append (heij) # Left Roof
# New Mesh Object will be created from the values set in our mesh object.
obj = Object.New ("Mesh", "AidansHome")
obj.link (mesh)
Scene.GetCurrent().link(obj)
# Method: Blender.Redraw()
# This function forces an immediate redraw of all 3D windows in the current screen. It can be used to force display of updated information (for example when an IPO curve for an Object has been changed).
Blender.Redraw()
# New more detailed house maker function.
# on to the good stuff...
def make (lim, dim, rem, rot, tal, etj):
if (E_DEBUG == 1):
print ">> Inside Make Function."
print "x = ",xC2
print "y = ",yC2
print "hp = ",hpC2
print "hs = ",hsC2
print "w = ",wC2
print "l = ",lC2
dim = float (int(dim * 10)) / 10
lun = 0.0
lat = 0.0
# start defining the grid
for gridy in range (lim):
if (gridy != 0):
lat = (dim + lat) + 1.5
for gridx in range (lim):
# choose whether a mesh
# will be created or not
if rem:
rmv = int(Mathutils.Rand(0,20))
else:
rmv = 1
if (rmv <= 13):
# define a new mesh
mesh = NMesh.New()
if (gridx != 0):
lun = (dim + lun) + 1
# the random deviations
rdm = float(int(Mathutils.Rand (3,7)) * 10) / 100
rh = rdm + 0.1
bln = float(int(Mathutils.Rand(0,1)) * 10) / 10
if (bln < 1):
rdm = rdm * (-1)
hi = float(int(Mathutils.Rand (4,10)) * 10) / 100
hi = dim * hi
# floors:
if (tal):
randhs = int(Mathutils.Rand (0,10))
if (randhs <= 8):
# will this house have many floors?
alt = float(int (Mathutils.Rand (1,(etj + 1)))) / 2
tal -= 1
else:
alt = 0
else:
alt = 0
# start positioning the verts
wid = dim + rdm
len = (dim * 1.5) + rdm
hei = alt + dim + rh
a = NMesh.Vert (rdm,rdm,0)
b = NMesh.Vert (wid,rdm,0)
c = NMesh.Vert (wid,len,0)
d = NMesh.Vert (rdm,len,0)
e = NMesh.Vert (rdm,rdm,hei)
f = NMesh.Vert (wid,rdm,hei)
g = NMesh.Vert (wid,len,hei)
h = NMesh.Vert (rdm,len,hei)
i = NMesh.Vert ((rdm - 0.1),(rdm - 0.1),hei)
j = NMesh.Vert ((wid + 0.1),(rdm - 0.1),hei)
k = NMesh.Vert ((wid + 0.1),(len + 0.1),hei)
l = NMesh.Vert ((rdm - 0.1),(len + 0.1),hei)
m = NMesh.Vert ((rdm + (dim / 2)), (rdm + 0.15), (hei + hi))
n = NMesh.Vert ((rdm + (dim / 2)), (len - 0.15), (hei + hi))
# and append them to the mesh
mesh.verts.append (a)
mesh.verts.append (b)
mesh.verts.append (c)
mesh.verts.append (d)
mesh.verts.append (e)
mesh.verts.append (f)
mesh.verts.append (g)
mesh.verts.append (h)
mesh.verts.append (i)
mesh.verts.append (j)
mesh.verts.append (k)
mesh.verts.append (l)
mesh.verts.append (m)
mesh.verts.append (n)
# then define the faces
abcd = NMesh.Face ([d,c,b,a])
abfe = NMesh.Face ([a,b,f,e])
bcgf = NMesh.Face ([b,c,g,f])
cdhg = NMesh.Face ([c,d,h,g])
daeh = NMesh.Face ([d,a,e,h])
efji = NMesh.Face ([e,f,j,i])
fgkj = NMesh.Face ([f,g,k,j])
ghlk = NMesh.Face ([g,h,l,k])
heil = NMesh.Face ([h,e,i,l])
ijm = NMesh.Face ([i,j,m])
kln = NMesh.Face ([k,l,n])
jknm = NMesh.Face ([j,k,n,m])
limn = NMesh.Face ([l,i,m,n])
# and append them to the mesh
mesh.faces.append (abcd)
mesh.faces.append (abfe)
mesh.faces.append (bcgf)
mesh.faces.append (cdhg)
mesh.faces.append (daeh)
mesh.faces.append (efji)
mesh.faces.append (fgkj)
mesh.faces.append (ghlk)
mesh.faces.append (heil)
mesh.faces.append (ijm)
mesh.faces.append (kln)
mesh.faces.append (jknm)
mesh.faces.append (limn)
# make chimneys
number = int (Mathutils.Rand (0,3))
for contor in range (number):
ch = float (int (Mathutils.Rand (rdm,(wid - 0.1) * 100))) / 100
ich = hei + hi + (Mathutils.Rand (0,0.5))
randis = float (int (Mathutils.Rand(0,0.1) * 100)) / 100
cha = NMesh.Vert (ch,ch,hei)
chb = NMesh.Vert ((ch + 0.1),ch,hei)
chc = NMesh.Vert ((ch + 0.1),(ch + 0.1 + randis),hei)
chd = NMesh.Vert (ch,(ch + 0.1 + randis),hei)
che = NMesh.Vert (ch,ch,ich)
chf = NMesh.Vert ((ch + 0.1),ch,ich)
chg = NMesh.Vert ((ch + 0.1),(ch + 0.1 + randis),ich)
chh = NMesh.Vert (ch,(ch + 0.1 + randis),ich)
chi = NMesh.Vert ((ch - 0.02),(ch - 0.02),ich)
chj = NMesh.Vert ((ch + 0.12),(ch - 0.02),ich)
chk = NMesh.Vert ((ch + 0.12),(ch + 0.12 + randis),ich)
chl = NMesh.Vert ((ch - 0.02),(ch + 0.12 + randis),ich)
chm = NMesh.Vert ((ch - 0.02),(ch - 0.02),(ich + 0.03))
chn = NMesh.Vert ((ch + 0.12),(ch - 0.02),(ich + 0.03))
cho = NMesh.Vert ((ch + 0.12),(ch + 0.12 + randis),(ich + 0.03))
chp = NMesh.Vert ((ch - 0.02),(ch + 0.12 + randis),(ich + 0.03))
mesh.verts.append(cha)
mesh.verts.append(chb)
mesh.verts.append(chc)
mesh.verts.append(chd)
mesh.verts.append(che)
mesh.verts.append(chf)
mesh.verts.append(chg)
mesh.verts.append(chh)
mesh.verts.append(chi)
mesh.verts.append(chj)
mesh.verts.append(chk)
mesh.verts.append(chl)
mesh.verts.append(chm)
mesh.verts.append(chn)
mesh.verts.append(cho)
mesh.verts.append(chp)
chabcd = NMesh.Face ([chd,chc,chb,cha])
chabfe = NMesh.Face ([cha,chb,chf,che])
chbcgf = NMesh.Face ([chb,chc,chg,chf])
chcdhg = NMesh.Face ([chc,chd,chh,chg])
chdaeh = NMesh.Face ([chd,cha,che,chh])
chefji = NMesh.Face ([che,chf,chj,chi])
chfgkj = NMesh.Face ([chf,chg,chk,chj])
chghlk = NMesh.Face ([chg,chh,chl,chk])
chheil = NMesh.Face ([chh,che,chi,chl])
chijnm = NMesh.Face ([chi,chj,chn,chm])
chjkon = NMesh.Face ([chj,chk,cho,chn])
chklpo = NMesh.Face ([chk,chl,chp,cho])
chlimp = NMesh.Face ([chl,chi,chm,chp])
chmnop = NMesh.Face ([chm,chn,cho,chp])
mesh.faces.append (chabcd)
mesh.faces.append (chabfe)
mesh.faces.append (chbcgf)
mesh.faces.append (chcdhg)
mesh.faces.append (chdaeh)
mesh.faces.append (chefji)
mesh.faces.append (chfgkj)
mesh.faces.append (chghlk)
mesh.faces.append (chheil)
mesh.faces.append (chijnm)
mesh.faces.append (chjkon)
mesh.faces.append (chklpo)
mesh.faces.append (chlimp)
mesh.faces.append (chmnop)
# create the new mesh
obj = Object.New ("Mesh", "House")
obj.link (mesh)
Scene.GetCurrent().link(obj)
# position the new mesh on the grid
obj.setLocation (lun,lat,0)
# rotate the mesh
if (rot):
[rx, ry, rz] = obj.getEuler()
rotate = float(int(Mathutils.Rand(0,9) * 10)) / 10
rz += rotate
obj.setEuler(rx,ry,rz)
# create the mesh
Blender.Redraw()
# reset the x values of the grid
lun = 0
Register (buton, exit, event)
If you make changes i think we should work from this updated version…