############################################################# ## ## _ Terrain_Tool ## ## turbulence/fBm/noise/cellnoise ## + formulae functions ## _ ## _ Jim Hazevoet ## _ ## _ Amsterdam ## _ 11/2003 ## ## ############################################################# ##*********************************************************** ############################################################# ## ## 1_ You have to download CGKit 1.0+ (by: Matthias Baas) ## ---------- ## from : www.sourceforge.net ## ------------------- ## ## 2_ Install CGKit... ## ##(3)_(step 3 only for Blender 2.27/2.28) ## copy "noise.pyd" and "cgtypes.pyd" ## (from: c:\Python\Lib\site-packages\) ## and paste to your Blender 2.27/2.28 directory. ## ############################################################# ##*********************************************************** ############################################################# ## ## _ To start... ## _ ## _ Set noise height parameter(s), ## _ " other " ## _ ## _ falloff = flatten edges ## _ floor/plateau = flat floor / flat plateau height ## _ ## _ For creation of other shapes write"math"formula (string) ## _ or use preset,and hit redraw button. ##___(to use preset 2 set nf noise height and C,D,E,F) ## _ ## _ Useable in formula : _C,D,E,F (user values) ## _ _nt,nf,nn,nc (noises) ## _ _x,y,z,xmax,ymax,random() ## _ _ ## _ __from math import ## _ __from noise import ## _ __from whrandom import ## ############################################################# # # import Blender from Blender import * from Blender.Draw import * from Blender.BGL import * from math import * from whrandom import * import noise # ########################### #-strings Astring = Create("B") Bstring = Create("C") # # user formula value's uC = Create(0.0) uD = Create(0.0) uE = Create(0.0) uF = Create(0.0) # #-mesh xres =Create(32) yres =Create(32) smooth=Create(0) # #-floor and plateau plev =Create(10.0) plno =Create(0.0) flev =Create(-10.0) flno =Create(0.0) # #-extra hght =Create(1.0) rand =Create(0.0) shft =Create(0.0) # #-turbulence = nt tfrq =Create(1.0) tuO =Create(3) tuL =Create(1.0) tuG =Create(0.5) tpox =Create(0.0) tpoy =Create(0.0) tuz =Create(0) tufall =Create(0.0) ptx =Create(0.0) pty =Create(0.0) # #-fBm = nf ffrq =Create(1.0) fbO =Create(10) fbL =Create(1.5) fbG =Create(0.60) fpox =Create(0.0) fpoy =Create(0.0) fbz =Create(0) fbfall =Create(0.0) pfx =Create(0.0) pfy =Create(0.0) # #-noise = nn nfrqx =Create(1.0) nfrqy =Create(1.0) npox =Create(0.0) npoy =Create(0.0) noz =Create(0) nofall =Create(0.0) pnx =Create(0.0) pny =Create(0.0) # #-cellnoise = nc cfrqx =Create(1.0) cfrqy =Create(1.0) cpox =Create(0.0) cpoy =Create(0.0) cez =Create(0) cefall =Create(0.0) pcx =Create(0.0) pcy =Create(0.0) ############################################################# # # write your own preset formula ############################################################# # Preset string # ################# # def prestring1(): global Astring, Bstring, uC, uD, uE, uF # # Astring=Create("sin(B*2.0)*2*sqrt(B*2.0)*exp(-B/2.0)*2") # Bstring=Create("sqrt((x-xmax/2)**2+(y-ymax/2)**2)") Astring=Create("sin(x*C)*cos(y*D)*exp(-B/4.0)*E") Bstring=Create("sqrt((x-xmax/2)**2+(y-ymax/2)**2)") # ################## # def prestring2(): global Astring, Bstring, uC, uD, uE, uF # Astring=Create("sin(y>C+B)*D*nf") Bstring=Create("sin(x*xmax)*E*cos(y*ymax)*random()*F") # ################## # def clearstring(): global Astring, Bstring, uC, uD, uE, uF # Astring=Create("B") Bstring=Create("C") # ############################################################# # # ############################################################# def create(): global Astring, Bstring, plev, flev, flno, plno global xres, yres, tfrq, ffrq, hght, shft, rand global fbO,fbL, fbG, fbfall, fbz, fpox, fpoy global tuO,tuL, tuG, tufall, tuz, tpox, tpoy global ptx, pty, pfx, pfy, pnx, pny, pcx, pcy global nofall, cefall, noz, cez global nfrqx, nfrqy, cfrqx, cfrqy global npox, npoy, cpox, cpoy global smooth, uC, uD, uE, uF ### me=NMesh.GetRaw() ### x=0.0 y=0.0 z=0.0 xmax = xres.val ymax = yres.val ra= rand.val Afunc=Astring.val Bfunc=Bstring.val C=uC.val D=uD.val E=uE.val F=uF.val ### for x in range(0, xmax, 1): for y in range(0, ymax, 1): # xt = (x-xmax/2.0)/10.0 yt = (y-ymax/2.0)/10.0 # xu=(xt*tfrq.val)+tpox.val yu=(yt*tfrq.val)+tpoy.val zu=2.0+shft.val xf=(xt*ffrq.val)+fpox.val yf=(yt*ffrq.val)+fpoy.val zf=2.0-shft.val xno=(xt*nfrqx.val)+npox.val+shft.val yno=(yt*nfrqy.val)+npoy.val-shft.val xce=(xt*cfrqx.val)+cpox.val+shft.val yce=(yt*cfrqy.val)+cpoy.val-shft.val # nt=noise.turbulence((xu,yu,zu),tuO.val,tuL.val,tuG.val) nt*=tuz.val+ra*random() nf=noise.fBm((xf,yf,zf),fbO.val,fbL.val,fbG.val) nf*=fbz.val+ra*random() nn=noise.noise(xno,yno) nn*=noz.val+ra*random() nc=noise.cellnoise(xce,yce) nc*=cez.val+ra*random() # nflo=noise.fBm((xf,yf,zf),9,2.0,0.75) nplat=noise.fBm((xf,yf,zf),11,2.8,0.75) # pt= sqrt((x-xmax/2-ptx.val)**4+(y-ymax/2-pty.val)**4) pf= sqrt((x-xmax/2-pfx.val)**4+(y-ymax/2-pfy.val)**4) pn= sqrt((x-xmax/2-pnx.val)**4+(y-ymax/2-pny.val)**4) pc= sqrt((x-xmax/2-pcx.val)**4+(y-ymax/2-pcy.val)**4) # # B=eval(Bfunc) z=eval(Afunc) z+=nt*exp(-pt/2*tufall.val*0.1) z+=nf*exp(-pf/2*fbfall.val*0.1) z+=nn*exp(-pn/2*nofall.val*0.1) z+=nc*exp(-pc/2*cefall.val*0.1) z*=hght.val if (z < flev.val): z = flev.val+flno.val*nflo if (z > plev.val): z = plev.val+plno.val*nplat # # ### v=NMesh.Vert(x, y, z) me.verts.append(v) # ################################ #? ### for x in range(0,ymax-1): for y in range(0,xmax-1): a=x+y*ymax f= NMesh.Face() if smooth.val: f.smooth=1 f.v.append(me.verts[a]) f.v.append(me.verts[a+ymax]) f.v.append(me.verts[a+ymax+1]) f.v.append(me.verts[a+1]) me.faces.append(f) ### NMesh.PutRaw(me, "Plane", 1) Blender.Redraw() ############################################################# # Gui ############################################################# # ############ def draw(): global Astring, Bstring, plev, flev, plno, flno global xres, yres, tfrq, ffrq, hght, shft, rand global fbO,fbL, fbG, fbfall, fbz, fpox, fpoy global tuO,tuL, tuG, tufall, tuz, tpox, tpoy global ptx, pty, pfx, pfy, pnx, pny, pcx, pcy global nofall, cefall, noz, cez global nfrqx, nfrqy, cfrqx, cfrqy global npox, npoy, cpox, cpoy global smooth, uC, uD, uE, uF ### # BGL.glClearColor(0.6, 0.6, 0.6, 1) BGL.glColor3f(1,1,1) BGL.glClear(BGL.GL_COLOR_BUFFER_BIT) # glColor3f(0.5, 0.5, 0.5) glRectf(1, 1, 310, 510) glColor3f(0.7, 0.7, 0.7) glRectf(5, 377.5, 305, 475) glColor3f(0.6, 0.6, 0.6) glRectf(5, 150, 155, 330) glColor3f(0.7, 0.7, 0.7) glRectf(155, 150, 305, 330) glColor3f(0.7, 0.7, 0.7) glRectf(5, 10, 155, 150) glColor3f(0.6, 0.6, 0.6) glRectf(155, 10, 305, 150) # glColor3f(0.0, 0.0, 0.0) glRasterPos2d(20, 320) Text("nt = Turbulence") glRasterPos2d(215, 320) Text("nf = fBm") glRasterPos2d(20, 140) Text("nn = Noise") glRasterPos2d(170, 140) Text("nc = Cellnoise") # # smooth=Toggle("Smooth", 2, 10,480,50,25, smooth.val) xres=Number("X Size",2,65,480,90,25,xres.val,2,256,"xmax") yres=Number("Y Size",2,155,480,90,25,yres.val,2,256,"ymax") Button("Redraw", 3, 10, 455, 90, 15) Button("Pre.1", 5, 105, 455, 50, 15) Button("Pre.2", 6, 155, 455, 50, 15) Button("Clear string", 7, 210, 455, 90, 15) Astring= String("A = ",4,10,430,290,20,Astring.val,200) Bstring= String("B = ",4,10,407.5,290,20,Bstring.val,200) uC=Number("C",2,15,382.5,70,20,uC.val,-100.0,100.0,"user C") uD=Number("D",2,85,382.5,70,20,uD.val,-100.0,100.0,"user D") uE=Number("E",2,155,382.5,70,20,uE.val,-100.0,100.0,"user E") uF=Number("F",2,225,382.5,70,20,uF.val,-100.0,100.0,"user F") flev=Number("Floor",2,10,335,100,25,flev.val,-50.0,50.0) plev=Number("Plateau",2,200,335,100,25,plev.val,-50.0,50.0) flno=Number("F noise",2,10,362.5,100,10,flno.val,-10.0,10.0) plno=Number("P noise",2,200,362.5,100,10,plno.val,-10.0,10.0) hght=Number("Height",2,110,335,90,37.5,hght.val,-32.0,32.0) rand=Number("Rndm",2,110,320,90,11,rand.val,-16.0,16.0) shft=Number("Shift",2,110,300,90,20,shft.val,-99.0,99.0,) tfrq=Number("Turb.",2,15,300,85,15,tfrq.val,0.0,32.0,"freq.") tuO=Number("Octaves",2,15,280,130,15,tuO.val,0.0,32.0) tuL=Number("Lacunarity",2,15,260,130,15,tuL.val,0.0,100.0) tuG=Number("Gain",2,15,240,130,15,tuG.val,-16.0,16.0) tpox=Number("X",2,15,220,65,15,tpox.val,-99.0,99.0,"x pos.") tpoy=Number("Y",2,80,220,65,15,tpoy.val,-99.0,99.0,"y pos.") tuz=Number("Turb.Height",2,15,200,130,15,tuz.val,-64.0,64.0) tufall=Number("Falloff",2,15,180,130,15,tufall.val,0.0,1.0) ptx=Number("FX",2,15,160,65,15,ptx.val,-64.0,64.0,"x Loc.") pty=Number("FY",2,80,160,65,15,pty.val,-64.0,64.0,"y Loc.") ffrq=Number("fBm",2,210,300,85,15,ffrq.val,0.0,32.0,"freq.") fbO=Number("Octaves",2,165,280,130,15,fbO.val,0.0,32.0) fbL=Number("Lacunarity",2,165,260,130,15,fbL.val,0.0,100.0) fbG=Number("Gain",2,165,240,130,15,fbG.val,-16.0,16.0) fpox=Number("X",2,165,220,65,15,fpox.val,-99.0,99.0,"x pos.") fpoy=Number("Y",2,230,220,65,15,fpoy.val,-99.0,99.0,"y pos.") fbz=Number("fBm Height",2,165,200,130,15,fbz.val,-64.0,64.0) fbfall=Number("Falloff",2,165,180,130,15,fbfall.val,0.0,1.0) pfx=Number("FX",2,165,160,65,15,pfx.val,-64.0,64.0,"x Loc.") pfy=Number("FY",2,230,160,65,15,pfy.val,-64.0,64.0,"y Loc.") nfrqx=Number("X freq",2,15,120,130,15,nfrqx.val,0.0,64.0) nfrqy=Number("Y freq",2,15,100,130,15,nfrqy.val,0.0,64.0) npox=Number("X",2,15,80,65,15,npox.val,-99.0,99.0,"x pos.") npoy=Number("Y",2,80,80,65,15,npoy.val,-99.0,99.0,"y pos.") noz=Number("Noise Height",2,15,60,130,15,noz.val,-64.0,64.0) nofall=Number("Falloff",2,15,40,130,15,nofall.val,0.0,1.0) pnx=Number("FX",2,15,20,65,15,pnx.val,-64.0,64.0,"x Loc.") pny=Number("FY",2,80,20,65,15,pny.val,-64.0,64.0,"y Loc.") cfrqx=Number("X freq",2,165,120,130,15,cfrqx.val,0.0,64.0) cfrqy=Number("Y freq",2,165,100,130,15,cfrqy.val,0.0,64.0) cpox=Number("X",2,165,80,65,15,cpox.val,-99.0,99.0,"x pos.") cpoy=Number("Y",2,230,80,65,15,cpoy.val,-99.0,99.0,"y pos.") cez=Number("Cell Height",2,165,60,130,15,cez.val,-64.0,64.0) cefall=Number("Falloff",2,165,40,130,15,cefall.val,0.0,1.0) pcx=Number("FX",2,165,20,65,15,pcx.val,-64.0,64.0,"x Loc.") pcy=Number("FY",2,230,20,65,15,pcy.val,-64.0,64.0,"y Loc.") # Button("Exit ", 1, 250, 480, 50, 25) # ### def event(evt, val): if (evt== QKEY and not val): Exit() def bevent(evt): if (evt== 1): Exit() elif (evt== 2): create() Draw() elif (evt== 3): create() Redraw() elif (evt== 5): prestring1() Draw() elif (evt== 6): prestring2() Draw() elif (evt== 7): clearstring() Draw() # create() Register(draw, event, bevent) Blender.Redraw() #