Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/contentcreation/orx_artists/SilvanNellen/moonsurface/ANTLandscapeVCol103_10-2005.py @ 4790

Last change on this file since 4790 was 4790, checked in by snellen, 17 years ago

new folder for SilvanNellen, moonsurface

File size: 42.7 KB
Line 
1#!BPY
2"""
3Name: 'A.N.T.Landscape v.1.03'
4Blender: 234
5Group: 'Add'
6Tip: 'Create a landscape mesh.'
7""" 
8
9
10##########################################################################
11##        : A.N.T.(Another Noise Tool) Landscape 1.03 VCol.
12##        : Jimmy Hazevoet  : Jan./Oct. 2005
13##########################################################################
14#------------------------------------------------------------------------#
15## v.1.03 : NEW: Mesh 'VertexColor' gradient.
16##             : Use new 'Mesh Modifier' (Blender2.38+) for SubSurf.
17##             : Some new Effect and Filter stuff.
18#------------------------------------------------------------------------#
19##########################################################################
20
21import Blender
22from Blender import *
23from Blender.Noise import *
24from math import *
25from Blender.Draw import *
26from Blender.BGL import *
27from Blender import Scene
28sc=Scene.getCurrent()
29
30# color stuff #------------------------------
31#############################################
32vcolours = Create(1)
33ColScreen = Create(0)
34preGrad = Create(0)
35newheight = Create(0.50)
36EVB_H      = 125
37EVB_R      = 150
38EVB_G      = 200
39EVB_B      = 250
40EVB_DEL    = 300
41EV_NEW     = 5
42EV_NOEVENT = 1
43colorcontrols=[]
44
45colors = (
46      #default ### [ h, r, g, b] ###
47      [[ 1.0, 227, 228, 231], [ 0.70, 96, 98, 97], [ 0.003, 76, 99, 27], [ 0.20, 96, 74, 23], [ 0.0,  11, 35, 84], [-1.0,  11, 35, 84]],
48      #natural
49      [[ 1.00, 200, 200, 200], [ 0.70, 159, 159, 159], [ 0.20, 157, 131, 67], [ 0.003, 85, 108, 67], [0.0, 3, 71, 109], [-1.0,  2, 39,  89]],
50      #dry
51      [[ 1.00, 169, 115, 54], [ 0.1, 187, 146, 37], [ 0.0, 132, 137, 54], [-1.0, 132, 137, 54]],
52      #red
53      [ [ 1.0 , 249, 225, 163],[ 0.5 , 239, 195, 103], [ 0.25, 214, 115,  72], [ 0.0, 100, 40,  25], [ -1.0,   0,  0,  0]],
54      #stone
55      [[ 1.0 , 236, 219, 196], [ 0.7, 190, 179,  171], [ 0.35, 174, 180,  170], [ 0.0, 114, 114,  114], [ -1.0,   0,  0,  0]],
56      #grayscale
57      [[ 1.0, 255, 255, 255], [ 0.0, 0, 0, 0], [-1.0, 0, 0, 0]]
58      )
59
60# Linear color gradient computation from: BDi_0.0.3.py
61def col_gradient(value, col1, col2):
62    delta = (value-col1[0]) / (col2[0]-col1[0])
63    jitter = random() * 0.05 * delta
64    if (delta+jitter)<1.0:  delta = delta+jitter
65    else:                   delta = delta-jitter
66    gg=col1[2]+(col2[2]-col1[2])*delta
67    bb=col1[3]+(col2[3]-col1[3])*delta
68    rr=col1[1]+(col2[1]-col1[1])*delta
69    return ( NMesh.Col(int(round(rr)),int(round(gg)),int(round(bb))) ), ( ((round(rr)),(round(gg)),(round(bb))) )
70
71######################################################
72#------------------------------
73def reset():
74   global NSize, iScale, invert, FalTyp, Fall, FalHard, offset, slev, plev, pslope, platnoise, edgesatsea
75   global RaPos, RaSiz, RaHgh, RaCha, RaTyp, Noise_Type, Noise_Basis
76   global Distortion_Noise, Damnt, VFunc, VExp, VDep
77   global Ha, La, Oc, Of, Ga, Ri, Ri_S, Ri_B, Depth, Hard, Amp, Freq, Lx, Ly, Lz, Sx, Sy
78   global FX, EffectZ, FXnoise, FXblend, Flt, FilterZ, filtF, filtG, lower, upper
79   global fxSize, fxSx, fxSy, fxLx, fxLy, fxIntens, fxOfst, fxgrad, fxA, fxB, fxC, fxD
80
81   RaPos = Create(1); RaSiz = Create(0); RaHgh = Create(0); RaCha = Create(0); RaTyp = Create(0)
82   FalTyp = Create( 2 ); Fall = Create( 1.0 ); FalHard = Create( 1.0 )
83   plev = Create( 1.0 ); slev = Create( 0.0 ); edgesatsea = Create(0); pslope = Create(0); platnoise = Create(0)
84   NSize = Create(1.0); iScale = Create(0.25); invert = Create(0); offset = Create(0.0)
85   Sx = Create(1.0); Sy = Create(1.0); Lx = Create(0.0); Ly = Create(0.0); Lz = Create(0.0)
86   Noise_Type = Create(3); Noise_Basis = Create(0)
87   Oc = Create(5.0); La = Create(3.0); Ha = Create(1.0); Ga = Create(1.0); Of = Create(1.0)
88   Ri = Create(1.0); Ri_S = Create(1.0); Ri_B = Create(0)
89   Depth = Create(2); Hard = Create(0); Amp = Create(0.5); Freq = Create(2.0)
90   Distortion_Noise = Create(0); Damnt = Create(2.0)
91   VFunc = Create(0); VExp  = Create(2.5); VDep  = Create(0)
92   FX = Create(0); EffectZ = Create(0); fxgrad = Create(0); fxA = Create(2); fxB = Create(0); fxC = Create(1.0); fxD = Create(2.0)
93   fxSize = Create(1.0); fxSx = Create(1.0); fxSy = Create(1.0); fxLx = Create(0.0); fxLy = Create(0.0)
94   fxIntens= Create(0.25);  fxOfst  = Create(0.0); FXnoise  = Create(0); FXblend  = Create(1)
95   Flt = Create(0); FilterZ = Create(0); filtF = Create(1.0); filtG = Create(0.25); lower = Create(0.0); upper = Create(1.0)
96reset()
97#------------------------------
98def resetMe():
99   global MEName, preset, pview, Auto_Update, Quality, resolution, Q_T, smooth, Rseed, RanMod
100   MEName = Create("Landscape"); preset = Create(0); pview = Create(0)
101   Auto_Update = Create(1); Quality = Create(3); resolution = Create(50)
102   Q_T = Create(0); smooth = Create(0)
103   RanMod = Create(0); Rseed = Create(0)
104resetMe()
105
106### Presets ----------------------------------
107#------------------------------
108def Preset_Noise():
109   global preset, NSize, Lx, Ly, Lz, Sx, Sy, iScale, invert, offset, slev, plev, pslope, platnoise, FalTyp, Fall, FalHard
110   global Noise_Type, Noise_Basis, Distortion_Noise, Damnt, Distortion_Noise
111   global Ha, La, Oc, Of, Ga, Depth, Hard, Amp, Freq, VFunc, VDep, Ri, Ri_S, Ri_B
112   global FX, EffectZ, FXblend, FXnoise, FXblend, FilterZ, filtF, filtG, Flt
113   global fxSize, fxSx, fxSy, fxLx, fxLy, fxIntens, fxOfst
114
115   if preset.val >2: ## randomise position ##
116      Lx = Create( 0.0+(random() * 1000 ) ); Ly = Create( 0.0+(random() * 1000 ) ); Lz = Create( 0.0+(random() * 1000 ) )
117   if preset.val == 2: # Original
118      Noise_Type = Create(5); NSize = Create(0.25); iScale = Create(0.1); FalTyp = Create(0); Oc = Create(2.0); La = Create(2.0)
119   elif preset.val == 3: # Blender hills
120      Noise_Type = Create(5); Depth = Create(2)
121   elif preset.val == 4: # Stones hills
122      NSize = Create(0.5); Of = Create(0.9); FX = Create(1); EffectZ = Create(8); FXblend = Create(9); fxIntens = Create(0.125); fxOfst = Create(0.1); fxSize = Create(3.0)
123   elif preset.val == 5: # Round hills
124      Noise_Type = Create(6); VFunc = Create(1); iScale = Create(0.5); invert = Create(1); offset = Create(-0.25); NSize = Create(0.5)
125   elif preset.val == 6: # Plateau
126      Noise_Basis = Create(3); NSize = Create(0.5); iScale = Create(0.5); plev = Create(0.25); pslope = Create(1); slev = Create(-0.25); FalTyp = Create(1) 
127      EffectZ = Create(7); FXblend  = Create(2); platnoise = Create(1)
128   elif preset.val == 7: # Shattered
129      Noise_Type  = Create(2); Noise_Basis = Create(7); Of = Create(2.0); Ga = Create(2.0); NSize = Create(0.25); offset = Create(-0.25); FalHard = Create(2.5) 
130   elif preset.val == 8: # Chaotic
131      NSize  = Create(0.25); Oc = Create(6.0); La = Create(2.0); Ha = Create(0.8); Of = Create(0.4)
132   elif preset.val == 9: # RidgedMF
133      Noise_Type = Create(1); La = Create(2.0); Ha = Create(0.8); Ga = Create(2.5)
134   elif preset.val == 10: # Distorted hTerrain
135      Noise_Type = Create(13); Ri = Create(-1.0); Ri_S = Create(0.75); Ri_B = Create(3)
136   elif preset.val == 11: # Cauliflower
137      Noise_Type = Create(2); Noise_Basis = Create(3); La = Create(5.0); Ga = Create(5.0); iScale = Create(0.35); invert = Create(1); NSize = Create(0.5); FalTyp = Create(1)
138   elif preset.val == 12: # Ridges
139      Noise_Type = Create(4); Noise_Basis = Create(3); NSize = Create(0.5); iScale = Create(0.5); offset = Create(0.1); Ha = Create(1.5)
140   elif preset.val == 13: # Crystalline
141      Noise_Type = Create(2); Noise_Basis = Create(4); iScale = Create(0.75); invert = Create(1); offset = Create(0.25)
142   elif preset.val == 14: # Warped
143      NSize  = Create(0.5); Of = Create(0.5); Flt = Create(1); FilterZ = Create(1)
144   elif preset.val == 15: # ChebyTech
145      Noise_Type = Create(6); VFunc = Create(3); VDep = Create(1); FalTyp = Create(0); plev = Create(0.2); NSize  = Create(0.25); iScale = Create(0.6)
146   elif preset.val == 16: # CellNoise
147      Noise_Type  = Create(5); Noise_Basis = Create(9); FalHard = Create(10.0)
148   elif preset.val == 17: # Canyon
149      NSize = Create(0.5); plev = Create(0.25); platnoise = Create(1); FalHard = Create(2.5); iScale = Create(0.5); offset = Create(-0.25); FilterZ = Create(3)
150   elif preset.val == 18: # Ring o Rock
151      Noise_Type = Create(2); Noise_Basis = Create(7); Of = Create(2.0); Ga = Create(2.0); NSize = Create(0.5); offset = Create(-0.6)
152      iScale = Create(0.5); FX = Create(1); EffectZ = Create(2); FXblend = Create(2)
153   elif preset.val == 19: # xtreme Peaks
154      Noise_Type = Create(10); iScale = Create(0.5); Flt = Create(1); FilterZ = Create(2)
155   elif preset.val == 20: # hardturb
156      Noise_Type = Create(5); Hard = Create(1); Depth = Create(3); Amp = Create(0.65); invert = Create(1); offset = Create(0.5); iScale = Create(0.5); FalTyp = Create(1)
157   elif preset.val == 21: # Cliff
158      FalTyp = Create(0); platnoise = Create(1); iScale = Create(0.5); FX = Create(1); EffectZ = Create(4); FXblend = Create(2)
159      fxIntens= Create(1.0); fxSx  = Create(0.0); fxSy  = Create(0.5)
160
161## Randomise ------------------------------------------------------
162###-----------------------------------
163def Random_N():
164   global iScale, invert, offset, NSize
165   global RaPos, RaSiz, RaCha, RaHgh, RaTyp, Rseed
166   global Noise_Type, Noise_Basis, Distortion_Noise, VFunc
167   global Lx, Ly, Lz, Sx, Sy, Ha, La, Oc, Of, Ga, Ri, Ri_S, Ri_B
168   global Depth, Hard, Amp, Freq, Damnt, VExp, VDep
169
170   setRandomSeed(Rseed.val)
171   inv1=inv2=1
172   randinv_one = int( random() * 2)
173   if randinv_one == 1:   inv1=-1
174   randinv_two = int( random() * 2)
175   if randinv_two == 1:   inv2=-1
176   # randomise Position #--------------------------------
177   if RaPos.val == 1:
178      Lx = Create( (random() * 1000.0 ) * inv1 ); Ly = Create( (random() * 1000.0 ) * inv2 ); Lz = Create( (random() * 1000.0 ) * inv2 )
179   # randomise Size #------------------------------------
180   if RaSiz.val == 1:
181      NSize = Create( 0.1+(random() * 1.0 ) ); Sx = Create( 1.0+(random() * 0.5 ) ); Sy = Create( 1.0+(random() * 0.5 ) )
182   # randomise Height #----------------------------------
183   if RaHgh.val == 1:
184      iScale = Create( 0.1+( random() * 1.0 ) ); invert = Create( int( random() * 2) ); offset = Create( (random() * 0.10 ) * inv2 )
185   # randomise Character #--------------------------------
186   if RaCha.val == 1:
187      Oc = Create( 1.0+( random() * 7.0 ) ); La = Create( 1.0+( random() * 5.0 ) ); Ga = Create( 0.5+( random() * 5.5 ) ); Ha = Create( 0.5+( random() * 1.5 ) ); Of = Create( 0.5+( random() * 1.0 ) )
188      Ri = Create( 0.2+( random() * 1.0 ) * inv1); Ri_S = Create( 0.3+( random() * 0.9 ) ); Ri_B = Create( int( random() * 10) )
189      Depth = Create( int( random() * 10) ); Hard = Create( int( random() * 2) ); Amp = Create( 0.25+( random() * 1.0 ) ); Freq = Create( 0.5+( random() * 2.5 ) )
190      Distortion_Noise = Create( int( random() * 10) ); Damnt = Create( 0.5+( random() * 3.0 ) )
191      VFunc = Create( int( random() * 7) ); VDep = Create( int( random() * 3) ); VExp = Create( ( random() * 10.0 ) )
192   # randomise Type #-----------------------------------
193   if RaTyp.val == 1:
194      Noise_Type = Create( int( random() * 10) ); Noise_Basis = Create( int( random() * 10) )
195
196## Noise --------------------------------------------------------
197###-----------------------------------
198def Noise_func(x,y,z):
199   global iScale, invert, offset, NSize, Sx, Sy, Lx, Ly, Lz, Noise_Type, Noise_Basis
200   global Distortion_Noise, Damnt, VFunc, VExp, VDep
201   global Ha, La, Oc, Of, Ga, Ri, Ri_S, Ri_B, Depth, Hard, Amp, Freq
202
203   x1 = ( x / Sx.val / NSize.val + Lx.val )
204   y1 = ( y / Sy.val / NSize.val + Ly.val )
205   z1 = ( z * 1.0 + Lz.val )
206   Basis = Noise_Basis.val
207   if Basis == 9:   Basis = 14
208   if Noise_Type.val == 0:
209         nz = multiFractal((x1,y1,z1),Ha.val, La.val, Oc.val, Basis)
210   elif Noise_Type.val == 1:
211         nz = ridgedMFractal((x1,y1,z1),Ha.val, La.val, Oc.val, Of.val, Ga.val, Basis)
212   elif Noise_Type.val == 2:
213         nz = hybridMFractal((x1,y1,z1),Ha.val, La.val, Oc.val, Of.val, Ga.val, Basis)
214   elif Noise_Type.val == 3:
215         nz = heteroTerrain((x1,y1,z1),Ha.val, La.val, Oc.val, Of.val, Basis)
216   elif Noise_Type.val == 4:
217         nz = fBm((x1,y1,z1),Ha.val, La.val, Oc.val, Basis)
218   elif Noise_Type.val == 5:
219         nz = turbulence((x1,y1,z1),1+Depth.val, Hard.val, Basis,Amp.val,Freq.val)+1.0
220   elif Noise_Type.val == 6:
221         nz = voronoi((x1,y1,z1),VFunc.val,VExp.val)[0][VDep.val]
222   elif Noise_Type.val == 7:
223         vlBasis = Distortion_Noise.val
224         if vlBasis == 9:   vlBasis = 14
225         distortion = Damnt.val
226         nz = vlNoise((x1,y1,z1), distortion, vlBasis, Basis)+1
227   elif Noise_Type.val == 8:
228         nz = noise((x1,y1,z1),Basis)
229   elif Noise_Type.val == 9:
230         nz = cellNoise((x1,y1,z1))
231   elif Noise_Type.val == 10:
232         ht = heteroTerrain((x1,y1,z1),Ha.val, La.val, Oc.val, Of.val, Basis)
233         nz = (Dist( ( ht**2),( ht**2) )**2)*0.025
234   elif Noise_Type.val == 11:
235         ht = heteroTerrain((x1,y1,z1),Ha.val, La.val, Oc.val, Of.val, Basis)
236         ca = WaveFunc( ht , Ri.val , (0.1/Ri.val*pi) , 1 )
237         nz = BModFunc( ht , ca , 1 )*2.0
238   elif Noise_Type.val == 12:
239         ribasis = Ri_B.val
240         if ribasis == 9: ribasis = 14
241         nz = heteroTerrain((x1,y1,z1),Ha.val, La.val, Oc.val, Of.val, Basis)
242         nz += Ri.val*ridgedMFractal((x1/Ri_S.val,y1/Ri_S.val,z1),Ha.val,La.val,Oc.val,Of.val,Ga.val,ribasis)
243   elif Noise_Type.val == 13:
244         ribasis = Ri_B.val
245         if ribasis == 9: ribasis = 14
246         vlBasis = Distortion_Noise.val
247         if vlBasis == 9:   vlBasis = 14
248         distortion = Damnt.val
249         nz = heteroTerrain((x1,y1,z1),Ha.val, La.val, Oc.val, Of.val, Basis)
250         nz += Ri.val*vlNoise((x1/Ri_S.val,y1/Ri_S.val,z1),distortion,vlBasis,ribasis)
251   else:
252         nt1 = (turbulence(( x1 , y1 , z1), 0, 1, 1, 0.5, 2.0 )*5-0.25)
253         nt2 = (turbulence(( x1 , y1 , z1),1+Depth.val, Hard.val, Basis,Amp.val,Freq.val)*0.1)
254         nz  = ( ClipFunc( nt1, 0.0, 0.25 ) +  (nt1*0.05) + nt2 )*4.0
255   if invert.val == 1:
256      nz *= iScale.val/2
257      z = -nz + iScale.val
258   else:   z = nz * iScale.val/2
259   z += offset.val
260
261   return x,y,z
262
263## Effects  -----------------------------------------------
264###------------------------------------------
265def StonesFunc(x,y,z):
266   return x,y, ClipFunc( (noise((10*x,10*y,z),1)*0.75-0.25), 0.0, 0.25 )
267def SparseCracksFunc(x,y,z):
268   return x,y, ClipFunc( (turbulence((x*2,y*2,z),0,1,1,0.5,2.0 )*4-0.25), 0.0, 0.25 )
269def CratersFunc(x,y,z):
270   return x,y,  ClipFunc( (noise((2*x,2*y,z),3)*1.0+0.5), -0.5, 0.0 )
271def SawFunc(x,y,z):
272   wa1 = WaveFunc( x+y , 1.0 , 1.0, 3 )
273   wa2 = WaveFunc( (y+wa1*0.5) , 1.0 , 1.0, 3 )
274   return x,y, BModFunc( x*wa2, y*wa1, 7 )
275def Dist(x,y):
276   return sqrt( (x*x)+(y*y) )
277def ClipFunc( input, ClipMin, ClipMax ):
278   if ( input < ClipMin ):  input = ClipMin
279   if ( input > ClipMax ):  input = ClipMax
280   return input
281def maxFunc( c1, c2 ):
282   if ( c1 > c2 ): c2 = c1
283   return c2
284def minFunc( c1, c2 ):
285   if ( c1 < c2 ): c2 = c1
286   return c2
287###-----------------------------------
288def BModFunc( c1, c2, bmod ):
289   if   bmod == 0:  return  ( c2 )                      #0  c2
290   elif bmod == 1:  return  ( c1*(1.0-0.5) + c2*0.5 )   #1  blend
291   elif bmod == 2:  return  ( c1 + c2 )                 #2  add
292   elif bmod == 3:  return  ( c1 - c2 )                 #3  subtract
293   elif bmod == 4:  return  ( c1 * c2 )                 #4  multiply
294   elif bmod == 5:  return  (abs( c1 - c2 ))            #5  difference
295   elif bmod == 6:  return  1.0-((1.0-c1)*(1.0-c2)/1.0) #6  screen
296   elif bmod == 7:  return  ( c1 + c2 ) % 1.0           #7  add modulo
297   elif bmod == 8:  return  minFunc( c1, c2 )           #8  min
298   elif bmod == 9:  return  maxFunc( c1, c2 )           #9  max
299   #### elif bmod == 10:                                #10 warp
300   else:            return  ( c1 )                      #11 c1
301###-----------------------------------
302def WaveFunc( input, numb, scale, type ):
303   if   type == 1:  return  (  sin( input * numb*pi ) * scale )
304   elif type == 2:  return  (  cos( input * numb*pi ) * scale )
305   elif type == 3:  return  (  ( input * numb ) % 1.0 * scale )
306   elif type == 4:  return  (  int( input * numb ) * scale ) / ( numb )
307   else:            return  (  ( input * numb*pi ) * scale )
308
309###-----------------------------------
310def Z_Effect(x,y,z):
311   global EffectZ, FXnoise, FXblend
312   global fxSize, fxSx, fxSy, fxLx, fxLy, fxIntens, fxOfst, fxgrad, fxA, fxB, fxC, fxD
313
314   basis = FXnoise.val
315   if basis == 9: basis = 14
316   Nfunc = Noise_func(x,y,z)
317   if EffectZ.val == 0:  z = Nfunc[2]
318   else:
319      phi = 3.14159265359
320      x2 = ( x * fxSize.val * fxSx.val - fxLx.val )
321      y2 = ( y * fxSize.val * fxSy.val - fxLy.val )
322      if   EffectZ.val == 1:  ez = ( x * sin( Dist( x2,y2 ) * phi*2 ) - y * cos( Dist( x2,y2 ) * phi*2 ) )
323      elif EffectZ.val == 2:  ez = sin( -Dist( x2,y2 ) * phi*2 )
324      elif EffectZ.val == 3:  ez = sin( ( x2 * phi ) + sin( y2 * phi ) )
325      elif EffectZ.val == 4:  ez = sin( x2*phi + y2*phi )
326      elif EffectZ.val == 5:  ez = cos( x2 * phi ) * sin( y2 * phi )
327      elif EffectZ.val == 6:  ez = BModFunc(WaveFunc(y2,1.0,1.0,3), WaveFunc(x2,1.0,1.0,3), 1 )
328      elif EffectZ.val in [7,8,9,10]:
329         if   EffectZ.val == 7:  nz = SawFunc(x2,y2,0.0)
330         elif EffectZ.val == 8:  nz = StonesFunc(x2,y2,0.0)
331         elif EffectZ.val == 9:  nz = CratersFunc(x2,y2,0.0)
332         elif EffectZ.val == 10: nz = SparseCracksFunc(x2,y2,0.0)
333         ez = nz[2]
334      elif EffectZ.val == 11:
335         ez = turbulence((x2+2.0,y2-2.0,0.0),1+fxA.val, fxB.val, basis, 0.5,2.0)+1.0
336      elif EffectZ.val == 12:
337         ez = multiFractal((x2,y2,0.0),fxC.val, fxD.val, fxA.val, basis)
338      elif EffectZ.val == 13:
339         bs = fxA.val
340         if bs == 9: bs = 14
341         ez = vlNoise((x2,y2,0.0), fxC.val, bs, basis)+1
342      elif EffectZ.val == 14:
343         value = (x2*x2 + y2*y2)/0.5
344         if value > 1.0:  radg = 0.0
345         radg = 1.0 - value
346         grad = [ x2, -x2, y2, -y2, radg ]
347         ez = grad[ fxgrad.val ]
348      elif EffectZ.val == 15:
349         ez = ( fxSize.val * random() )
350
351      ez *= fxIntens.val
352      ez += fxOfst.val
353      Nfunc=Noise_func(x,y,z)
354      if FXblend.val == 10:
355         Wfunc = Noise_func( x-ez, y-ez, 0.0 )
356         z = Wfunc[2]
357      else:
358         z = BModFunc( Nfunc[2], ez , FXblend.val )
359   return x,y,z
360
361## Filters -------------------------
362###-----------------------------------
363def  Z_Filter(x,y,z):
364   global Flt, FilterZ, filtF, filtG, lower, upper
365
366   Efunc = Z_Effect(x,y,z)
367   if  FilterZ.val == 0:  z = Efunc[2]
368   elif FilterZ.val == 1:
369      zn    = Z_Effect(x,y,z)
370      Sfunc = Z_Effect(x-(zn[2]*filtF.val+filtG.val), y-(zn[2]*filtF.val+filtG.val), z )
371      z = Sfunc[2]
372   elif FilterZ.val == 2:
373      z = (Dist( (Efunc[2]**2),(Efunc[2]**2) )**2)*2.0
374   elif FilterZ.val in [3,4,5,6,7]:
375      canion1      = ( Efunc[2], (filtF.val*10.0), (0.1/(filtF.val*10.0)*pi), 2 , Efunc[2], 2 )
376      canion2      = ( (Dist( Efunc[2]**2 ,Efunc[2]**2 )**2),(filtF.val*10.0),(0.1/(filtF.val*10.0)*pi),1 , (Dist( Efunc[2]**2 ,Efunc[2]**2 )**2),2 )
377      sawf         = ( Efunc[2], filtF.val*1.0, filtG.val , 3 , 0, 0 )
378      poster       = ( Efunc[2]*2.0, filtF.val*20.0 , filtG.val*2.0 ,4 , 0, 0)
379      posternoise  = ( Efunc[2]*2.0, filtF.val*20.0 , filtG.val*2.0 ,4 ,  Efunc[2]*2.0, 1)
380      FiltType = ( 0,0,0, canion1, canion2, sawf, poster, posternoise )
381      FTyp     = FiltType[ FilterZ.val ]
382      Wa  = WaveFunc( FTyp[0], FTyp[1], FTyp[2], FTyp[3] )
383      z   = BModFunc( FTyp[4] , Wa , FTyp[5] )
384   elif FilterZ.val == 8:
385      z = SmoothStep( Efunc[2], lower.val, upper.val )*filtF.val
386   return x,y,z
387###-----------------------------------
388def SmoothStep( input, low, up ):
389   value = input
390   if value < low:  return 0.0
391   elif value > up: return 1.0
392   else:
393      delta = up - low
394      if fabs(delta) > 0.000001:
395         value = (value - low) / delta
396         return value * value * (3.0 - 2.0 * value)
397      else:
398         if value > up:
399            return 1.0
400
401## Limit height --------------------------------------------------------
402###-----------------------------------
403def Z_Limit(x,y,z):
404   global FalTyp, Fall, FalHard, slev, edgesatsea, plev, pslope, platnoise
405
406   plateau  = plev.val; sealevel = slev.val
407   if edgesatsea.val == 1:
408       edgesatsealevel = slev.val
409   else:
410       edgesatsealevel = 0.0
411
412   Ffunc  = Z_Filter(x,y,z)
413   height = Ffunc[2] - edgesatsealevel
414   if FalTyp.val != 0:
415      if FalTyp.val == 2: fha = 2*FalHard.val
416      else:               fha = 1*FalHard.val
417      distype = ( sqrt((x*x + y*y)**fha), sqrt((x*x)**fha+(y*y)**fha), sqrt(y*y)**fha, sqrt(x*x)**fha )
418      dist = distype[ FalTyp.val-1 ]
419      height = Ffunc[2] - edgesatsealevel
420      radius = 1.0 * Fall.val
421      if( dist <  radius ):
422         dist = dist / radius
423         dist = ( (dist) * (dist) * ( 3-2*(dist) ) )
424         z = ( height - height * dist ) + edgesatsealevel
425      else:  z = edgesatsealevel
426   else:     z = Ffunc[2]
427
428   Nfunc = Noise_func(x,y,z)
429   flatnoise = Nfunc[2] * 0.1
430   slope = abs( (x/pi-1)*(y/pi+1) )
431   if pslope.val == 1:
432      if platnoise.val == 1:
433         if ( z > plateau * slope + flatnoise ):  z = plateau * slope + flatnoise
434      else:
435         if ( z > plateau * slope ):              z = plateau * slope
436   if pslope.val == 0:
437      if platnoise.val == 1:
438         if ( z > plateau + flatnoise ):  z = plateau + flatnoise
439      else:
440         if ( z > plateau ):              z = plateau
441   if ( z < sealevel ):  z = sealevel
442
443   return x,y,z
444
445## Mesh -----------------------------------------------------------
446###-----------------------------------
447def Crea(): 
448   global MEName, Quality, resolution, Q_T, smooth, submode, sub, vcolours, preGrad
449
450   reso = ( 32+1, 50+1, 64+1, 100+1, 128+1, 150+1, 200+1, 256+1, 512+1, resolution.val+1 )
451   n = reso[ Quality.val ]
452
453   try:
454      o=Object.Get('Terrainn')
455      me=o.getData()
456      UPDATE=1 
457   except:
458      o=Object.New('Mesh','Terrainn')
459      sc.link(o)
460      me = NMesh.GetRaw()
461      UPDATE=0
462
463   me.verts=[]
464   me.faces=[]
465   COL=[]
466   height = 0
467   # Vertices -----------------------------------
468   i=j=h=0.0
469   for i in range(0, n, 1):
470      i = i-(n-1)/2
471      i = i*2.0/(n-1)
472      for j in range(0, n, 1):
473         j = j-(n-1)/2
474         j = j*2.0/(n-1)
475         Result = Z_Limit(i,j,h)
476         height = Result[2]
477         v=NMesh.Vert(i, j, height)
478         me.verts.append(v)
479         #-----------------------------------
480         for cc in range(len(colors[ preGrad.val ])):
481              if ( height  > colors[ preGrad.val ][cc][0]):
482                      COL.append( col_gradient( height ,colors[ preGrad.val ][cc],colors[ preGrad.val ][cc-1])[0] )
483                      break
484   me.hasVertexColours(1)
485   ##--------------------------------------
486   if Q_T.val == 1:
487      for i in range(n-1):
488         for j in range(n-1):
489            f = NMesh.Face()
490            f.v.append(me.verts[n*i+j])
491            f.v.append(me.verts[n*(i+1)+j])
492            f.v.append(me.verts[n*i+(j+1)])
493            if vcolours.val !=0:
494               f.col.append(COL[n*i+j])
495               f.col.append(COL[n*(i+1)+j])
496               f.col.append(COL[n*i+(j+1)])
497            f.smooth = smooth.val
498            me.faces.append(f)
499            f = NMesh.Face()
500            f.v.append(me.verts[n*i+(j+1)])
501            f.v.append(me.verts[n*(i+1)+j])
502            f.v.append(me.verts[n*(i+1)+(j+1)])
503            if vcolours.val !=0:
504               f.col.append(COL[n*i+(j+1)])
505               f.col.append(COL[n*(i+1)+j])
506               f.col.append(COL[n*(i+1)+(j+1)])
507            f.smooth = smooth.val
508            me.faces.append(f)
509   else:
510      for i in range(n-1):
511         for j in range(n-1):
512            f= NMesh.Face()
513            f.v.append(me.verts[i*n+j])
514            f.v.append(me.verts[(i+1)*n+j])
515            f.v.append(me.verts[(i+1)*n+j+1])
516            f.v.append(me.verts[i*n+j+1])
517            if vcolours.val !=0:
518               f.col.append(COL[i*n+j])
519               f.col.append(COL[(i+1)*n+j])
520               f.col.append(COL[(i+1)*n+j+1])
521               f.col.append(COL[i*n+j+1])
522            f.smooth = smooth.val
523            me.faces.append(f)
524
525   if UPDATE :
526      me.update()
527   else :
528      o.link(me)
529   o.makeDisplayList()
530   Blender.Redraw()
531
532
533### G.U.I.  ,   Preview  ---------------------------
534#----------------------------------------------------------------------
535def Preview_Noise():
536   global pview, preGrad
537   for x in range(-64, 64):
538      for y in range(-64, 64):
539         poco = Z_Limit(x/64.0, y/64.0, 0.0)
540         if pview.val == 1:
541            r,g,b = (poco[2]+1)/2 , (poco[2]+1)/2 , (poco[2]+1)/2
542            glColor3f(r,g,b)
543         elif pview.val == 2:
544            r,g,b = (poco[2]) , (poco[2]) , (poco[2])
545            glColor3f(r,g,b)
546         elif pview.val == 3:
547            for cc in range(len(colors[ preGrad.val ])):
548               if ( poco[2]  > colors[ preGrad.val ][cc][0]):
549                  r,g,b = (col_gradient( poco[2] ,colors[ preGrad.val ][cc],colors[ preGrad.val ][cc-1] )[1] )
550                  break
551            glColor3f(r/255.0,g/255.0,b/255.0)
552
553         glRecti(x+135, y+307, x+136, y+308)
554#------------------------------------
555def ColBox(x,y, w, h, r, g, b):
556   glColor3f(r, g, b)
557   glRecti(x, y, w, h)
558###-----------------------------------
559def GUI():
560   global MEName, preset, pview, Auto_Update, Quality, resolution, Q_T, smooth, submode, sub
561   global NSize, iScale, invert, FalTyp, Fall, FalHard, offset, Lx, Ly, Lz, Sx, Sy, slev, plev
562   global RaPos, RaSiz, RaHgh, RaCha, RaTyp, Rseed, RanMod, Flt, FilterZ, filtF, filtG, lower, upper
563   global Noise_Type, Noise_Basis, Distortion_Noise, Damnt, VFunc, VExp, VDep
564   global Ha, La, Oc, Of, Ga, Ri, Ri_S, Ri_B, Depth, Hard, Amp, Freq
565   global FX, EffectZ, FXnoise, FXblend, fxSize, fxSx, fxSy, fxLx, fxLy
566   global fxIntens, fxOfst, fxgrad, fxA, fxB, fxC, fxD
567   global pslope, platnoise, edgesatsea
568   global vcolours, ColScreen, colorcontrols, colsel, curcol, preGrad, newheight
569
570   BGL.glClearColor(0.66, 0.66, 0.66, 1)
571   BGL.glClear(BGL.GL_COLOR_BUFFER_BIT)
572   glColor3f(0.73,0.73,0.73)
573   glRecti(5, 5, 265, 227)
574   glColor3f(0.61,0.61,0.61)
575   if pview.val !=0:
576      glRecti(5, 225, 265, 390)
577      Preview_Noise()
578   else:
579      glRecti(5, 225, 265, 242)
580   glColor3f(1.0,1.0,1.0)
581   glRasterPos2d(140, 230)
582   Text("A.N.T.Landscape 1.03",'small')
583
584   colorcontrols = [[], [], [], []]
585   ## Colors ##-----------------------------------
586   if ( ColScreen.val == 1 ):
587      ColScreen = Toggle("Col.",EV_NOEVENT, 160,205, 30,15, ColScreen.val,"Change colors")
588      Button("Update", 103, 195, 205, 45, 15,"Update mesh.")
589      #----------------------------------------------
590      glColor3f(1.0,0.0,0.0); glRasterPos2d(10, 190);  Text("Red",'small')
591      glColor3f(0.0,1.0,0.0); glRasterPos2d(60, 190);  Text("Green",'small')
592      glColor3f(0.0,0.0,1.0); glRasterPos2d(110, 190); Text("Blue",'small')
593      glColor3f(0.0,0.0,0.0); glRasterPos2d(195, 190); Text("Height",'small')
594      #----------------------------------------------
595      for c in range ( len(colors[ preGrad.val ]) ):
596         #- Height ---------------------------------------
597         if ( c != ( len(colors[ preGrad.val ]) -1 ) ):
598            ccontrol = Create(colors[ preGrad.val ][c][0])
599            ccontrol = Number("", EVB_H+c, 195, 170-20*c, 45, 15, ccontrol.val, -1.0, 1.0, "Color above this Height")
600            colorcontrols[0].append(ccontrol)
601         #- Red ---------------------------------------
602         ccontrol = Create(colors[ preGrad.val ][c][1])
603         ccontrol = Number("", EVB_R+c, 10, 170-20*c, 45, 15, ccontrol.val, 0, 255, "Red")
604         colorcontrols[1].append(ccontrol)
605         #- Green ---------------------------------------
606         ccontrol = Create(colors[ preGrad.val ][c][2])
607         ccontrol = Number("", EVB_G+c, 60, 170-20*c, 45, 15, ccontrol.val, 0, 255, "Green")
608         colorcontrols[2].append(ccontrol)
609         #- Blue ---------------------------------------
610         ccontrol = Create(colors[ preGrad.val ][c][3])
611         ccontrol = Number("", EVB_B+c, 110, 170-20*c, 45, 15, ccontrol.val, 0, 255, "Blue")
612         colorcontrols[3].append(ccontrol)
613         #- Col -------------------------------------
614         ColBox( 160,185-20*c, 190,170-20*c, (colors[ preGrad.val ][c][1])/255.0, (colors[ preGrad.val ][c][2])/255.0, (colors[ preGrad.val ][c][3])/255.0 )
615         #- Delete ----------------------------------
616         if (c!=0) and (c!=(len(colors[ preGrad.val ])-1)):
617            PushButton("X", EVB_DEL+c , 245,170-20*c, 15,15, "Remove color")
618
619      #- Add New ------------------------------------
620      Button("Add",EV_NEW, 60, 205, 45, 15, "Add new color at given height")
621      newheight = Number("", EV_NOEVENT+c, 110, 205, 45, 15, newheight.val, -1.0, 1.0, "Height for new color")
622      #- Preset grad's ------------------------------
623      gradsmnu = "Gradients %t|Default %x0|Natural %x1|Dry %x2|Red %x3|Stone %x4|Greyscale %x5"
624      preGrad = Menu(gradsmnu,EV_NOEVENT, 10,205, 45,15, preGrad.val,"Preset gradients")
625   else:
626      ColScreen = Toggle("Colors",EV_NOEVENT, 140,205, 60,15, ColScreen.val,"Change colors")
627      vcolours = Toggle("VertCol.", 102,210,205,50,15, vcolours.val,"Faces : Enable VertexColors.")
628      ## Noise ##
629      FX = Toggle( "Effects" ,31,10,205,60,15,FX.val,"Effects")
630      Flt = Toggle( "Filters" ,32,70,205,60,15,Flt.val,"Filter")
631      nbasis = "Noise Basis%t|Blender Original%x0|Original Perlin%x1|Improved Perlin%x2|Voronoi_F1%x3|Voronoi_F2%x4|Voronoi_F3%x5|Voronoi_F4%x6|Voronoi_F2-F1%x7|Voronoi Crackle%x8|CellNoise%x9"
632      ntype  = "Noise Type's %t|multiFractal %x0|ridgedMFractal %x1|hybridMFractal %x2|heteroTerrain %x3|fBm %x4|turbulence %x5|Voronoi %x6|DistortedNoise %x7|noise %x8|cellNoise %x9| %l|Peaked hTerrain %x10|Layered hTerrain %x11|hTerrain + ridgedMF %x12|hTerrain + DistortedN %x13|turbulence Cracks %x14"
633      votype = "Voronoi%t|Distance %x0|Distance Squared %x1|Manhattan %x2|Chebychev %x3|Minkovsky 1/2 %x4|Minkovsky 4 %x5|Minkovsky %x6"
634      if FX.val !=1 and Flt.val !=1:
635         Noise_Type = Menu(ntype,102,10,60,120,20, Noise_Type.val, "Noise Type")
636         if Noise_Type.val == 6:
637            VFunc = Menu(votype, 102, 10,85,120,15, VFunc.val)
638         elif Noise_Type.val != 9:
639            Noise_Basis = Menu(nbasis,102,10,85, 120, 15, Noise_Basis.val, "Noise Basis")
640         if Noise_Type.val in [0,1,2,3,4, 10,11,12,13]:
641            Oc = Slider("Octs: ", 102, 10,180,120,15, Oc.val,0.0,8.0 ,0, "Musgrave:  Octaves")
642            La = Slider("Lacu: ", 102, 10,165,120,15, La.val,0.0,6.0 ,0, "Musgrave:  Lacunarity")
643            Ha = Slider("H: ", 102, 10,150,120,15, Ha.val,0.0,2.0 ,0, "Musgrave:  H")
644            if Noise_Type.val in [1,2,12]:
645               Ga = Slider("Gain: ", 102, 10,120,120,15, Ga.val,0.0,6.0 ,0, "Musgrave:  Gain")
646            if Noise_Type.val in [1,2,3,10,11,12,13]:
647               Of = Slider("Ofst: ", 102, 10,135,120,15, Of.val,0.0,6.0 ,0, "Musgrave:  Offset")
648            if Noise_Type.val == 11:
649               Ri = Number("Layers:", 102, 10,120,120,15, Ri.val,0.0,10.0 ,"number of Layers")
650            if Noise_Type.val == 12:
651               Ri = Number(":", 102, 10,105,50,15, Ri.val,-2.0,2.0 ,"ridgedMF intensity")
652               Ri_S = Number(":", 102, 60,105,50,15, Ri_S.val,0.001,10.0 ,"ridgedMF Size")
653               Ri_B = Menu(nbasis, 102, 110,105,20,15, Ri_B.val,"ridgedMF Noise basis"+" = "+str(int(Ri_B.val)) )
654            elif Noise_Type.val == 13:
655               Ri = Number(":", 102, 10,105,40,15, Ri.val,-2.0,2.0 ,"Distortion intensity")
656               Ri_S = Number(":", 102, 50,105,40,15, Ri_S.val,0.001,10.0 ,"Distortion Size")
657               Damnt = Number("Distortion: ",102,90,105,40,15, Damnt.val, 0.0,10.0,"Distortion amount")
658               Ri_B = Menu(nbasis, 102, 10,120,60,15, Ri_B.val,"Distortion Noise basis")
659               Distortion_Noise = Menu(nbasis ,102,70,120,60,15, Distortion_Noise.val, "Distortion Noise")
660         elif Noise_Type.val in [5,14]:
661            if Hard.val == 0: Hardtext ="Soft"
662            elif Hard.val == 1: Hardtext ="Hard"
663            Hard = Toggle( Hardtext , 102, 10,135,60,15,Hard.val, "Turbulence:  Soft noise / Hard noise")
664            Amp = Slider("Amp:", 102,10,165,120,15,Amp.val,0.0,10.0, 0, "Turbulence: Ampscale ")
665            Freq = Slider("Freq:", 102,10,150,120,15,Freq.val,0.0,10.0, 0, "Turbulence:  Freqscale")
666            Depth = Number("Depth:", 102,70,135,60,15,Depth.val,0.0,10.0, "Turbulence:  Octaves")
667         elif Noise_Type.val == 6:
668            VDep = Number("Depth:",102,10,165,120,15,VDep.val,0,3, "Voronoi:  Depth")
669            if (VFunc.val == 6):
670               VExp = Slider("Exp:",102,10,150,120,15,VExp.val,0.0,10.0, 0, "Voronoi:  Minkovsky exponent")
671         elif Noise_Type.val == 7:
672            Distortion_Noise = Menu(nbasis ,102,10,150,120,15, Distortion_Noise.val, "DistortedNoise:  Distortion Noise")
673            Damnt = Slider("Dist:",102,10, 165, 120, 15, Damnt.val, 0.0,10.0, 0, "DistortedNoise:  Distortion amount")
674      elif FX.val ==1:
675         glColor3f(0.61,0.61,0.61)   ##  Effects ##
676         glRecti(8, 55, 132, 200)
677         efxmnu = "Effect Type's %t|None %x0|Spiral %x1|Ring %x2|ZigZag %x3|Wave %x4|Bumps %x5|Sawteeth %x6|Saw-irregular %x7|Stones %x8|Craters %x9|Cracks %x10|Turbulence %x11|multiFractal %x12|DistortedNoise %x13|Gradient %x14|Random %x15"
678         EffectZ = Menu(efxmnu,102,10,180,60,15, EffectZ.val, "Effect Types")
679         if EffectZ.val !=0:
680            blfxmnu = "Blend Type's %t|None   (Effect only) %x0|Blend %x1|Add %x2|Subtract %x3|Multiply %x4|Difference %x5|Screen %x6|Add modulo %x7|Min %x8|Max %x9|Warp %x10"
681            FXblend = Menu(blfxmnu,102,70,180,60,15, FXblend.val, "Mix Effect with Noise")
682            fxIntens = Number("i:",102,10,110,60,15,fxIntens.val,-10.0,10.0, "Intensity")
683            fxOfst = Number("z:",102,70,110,60,15,fxOfst.val,-10.0,10.0, "Offset")
684            if EffectZ.val < 15:
685               fxSx = Number("x:",102,10,160,60,15,fxSx.val,0.0,25.0, "Freq.X")
686               fxSy = Number("y:",102,70,160,60,15,fxSy.val,0.0,25.0, "Freq.Y")
687               fxLx = Number("x:",102,10,130,60,15,fxLx.val,-25.0,25.0, "Position X")
688               fxLy = Number("y:",102,70,130,60,15,fxLy.val,-25.0,25.0, "Position Y")
689               if EffectZ.val in [11,12,13]:
690                  FXnoise = Menu(nbasis,102,10,60,120,15,FXnoise.val, "Noise Basis" )
691               if EffectZ.val == 11:
692                  fxB = Toggle("Hard:",102,70,75,60,15,fxB.val)
693                  fxA = Number("Oct:",102,10,75,60,15,fxA.val,0,10)
694               if EffectZ.val == 12:
695                  fxA = Number("Oct:",102,10,75,60,15,fxA.val,0,10)
696                  fxC = Number("H:",102,70,75,60,15,fxC.val,0.0,6.0)
697                  fxD = Number("La:",102,70,90,60,15,fxD.val,0.0,6.0)
698               if EffectZ.val == 13:
699                  fxA = Menu(nbasis,102,10,75,60,15,fxA.val, "Noise Basis" )
700                  fxC = Number("Dst:",102,70,75,60,15,fxC.val,0.0,10.0)
701               if EffectZ.val < 14:
702                  fxSize = Number("Freq:",102,10,145,120,15,fxSize.val,0.0,25.0, "Frequency")
703            if EffectZ.val == 14:
704               fxgradmnu = "Gradient's %t|x %x0|-x %x1|y %x2|-y %x3|Radial %x4"
705               fxgrad = Menu(fxgradmnu,102,10,145,120,15, fxgrad.val)
706            if EffectZ.val == 15:
707               fxSize = Number("R: ",102,10,145,120,15,fxSize.val,0.0,25.0, "Random")
708      elif Flt.val ==1:
709         glColor3f(0.61,0.61,0.61)   ## Filters ##
710         glRecti(8, 55, 132, 200)
711         filtmnu = "Filter Type's%t|None %x0|Warp %x1|Peaks %x2|Layers %x3|Peaks and Layers %x4|Saw %x5|Posterise %x6|blended Posterise %x7|SmoothStep %x8"
712         FilterZ = Menu(filtmnu,102,10,180,120,15,  FilterZ.val,"Filter Type's")
713         if FilterZ.val !=0:
714            if FilterZ.val in [1,3,4,5,6,7]:
715               filtF = Number(":",102,10,160,60,15,filtF.val, -25.0,25.0 , "Intensity" )
716            if FilterZ.val in [1,5,6,7]:
717               filtG = Number(":",102,70,160,60,15,filtG.val, -25.0,25.0 , "Offset" )
718            if FilterZ.val == 8:
719               lower = Number(":",102,10,160,60,15,lower.val, -1.0,1.0 , "Lower" )
720               upper = Number(":",102,70,160,60,15,upper.val, -1.0,1.0 , "Upper" )
721               filtF = Number(":",102,10,140,60,15,filtF.val, -25.0,25.0 , "Intensity" )
722
723      Lx = Number("",102,140,50,60,15,Lx.val,-1000.0,1000.0,"Noise x position" )
724      Ly = Number("",102,200,50,60,15,Ly.val,-1000.0,1000.0,"Noise y position" )
725      Lz = Number("",102,200,35,60,15,Lz.val,-1000.0,1000.0,"Noise z position" )
726      NSize = Number("NoiseSize: ",102,140,70, 120, 20, NSize.val, 0.001, 10.0, "Noise size")
727      Sx = Number("x",102,140,90,60,15,Sx.val,0.001,10.0,"Noise x size")
728      Sy = Number("y",102,200,90,60,15,Sy.val,0.001,10.0,"Noise y size")
729      iScale = Number("iScale: ",102,140, 110, 90, 20, iScale.val, -10.0,10.0, "Height:  Noise intensity")
730      invert = Toggle("I",102,230,110,30,20, invert.val,"Height: Invert noise intensity")
731      offset = Number("Offset: ",102,140,130,120,15,offset.val,-10.0,10.0, "Height: Noise z offset")
732      plev = Number("Max.:",102,140,180,90,15,plev.val, slev.val,1.0, "Plateau: Clip z Max.")
733      pslope   = Toggle("S",102,230,180,15,15, pslope.val, "Plateau:  Set Flat  /  Set Slope")
734      platnoise = Toggle("N",102,245,180,15,15, platnoise.val, "Plateau:  Set Flat  /  Set Noise ( +0.1*noise ) ")
735      falmnu = "Falloff Type's %t|None %x0|Round %x1|Square %x2|y Linear %x3|x Linear %x4"
736      if FalTyp.val !=0:
737         slev = Number("Min.:",102,140,165,90,15,slev.val, -0.999,plev.val, "Sealevel: Clip z Min.")
738         edgesatsea = Toggle("E",102,230,165,30,15, edgesatsea.val, "Edge Falloff:  Set Edge's at Sealevel")
739         FalTyp = Menu(falmnu,102,230,150,30,15, FalTyp.val,"Edge Falloff Type's")
740         Fall = Number(":",102,140,150,45,15,Fall.val,0.0,10.0,"Edge Falloff : Radius")
741         FalHard = Number(":",102,185,150,45,15,FalHard.val,0.0,25.0,"Edge Falloff : Hardness")
742      else:
743         FalTyp = Menu(falmnu,102,140,150,120,15, FalTyp.val,"Edge Falloff type's")
744         slev = Number("Min.:",102,140,165,120,15,slev.val, -0.999,plev.val, "Sealevel: Clip z Min.")
745
746      RaPos = Toggle("P",105,10,35,20,15, RaPos.val,"Random Noise Position.")
747      RaSiz = Toggle("S",105,30,35,20,15, RaSiz.val,"Random Noise Size.")
748      RaHgh = Toggle("H",105,50,35,20,15, RaHgh.val,"Random Noise Height.")
749      RaCha = Toggle("C",105,70,35,20,15, RaCha.val,"Random Noise Character.")
750      RaTyp = Toggle("T",105,90,35,20,15, RaTyp.val,"Random Noise Type.")
751      semnu = "Random Mode %t|Random %x0|Seed %x1"
752      RanMod = Menu(semnu,222,110,35,20,15, RanMod.val,"Random Mode")
753      if RanMod.val == 0:
754         Button("Random", 69, 80, 10, 50, 20,"Randomise Noise ( P,S,H,C,T ).")
755         Rseed = Create(0)
756      else:
757         Rseed = Number(":",69,80,10,50,20,Rseed.val,0,255,"Random seed ( P,S,C,H,T )")
758
759      resmnu = "Mesh Quality%t|32 %x0|50 %x1|64 %x2|100 %x3|128 %x4|150 %x5|200 %x6|256 %x7|512 %x8|Manual %x9"
760      if Quality.val == 9:
761         resolution = Number(":",102,140,25,40,15, resolution.val, 2,512,"Mesh resolution ( n*n )")
762         Quality = Menu(resmnu,102,140,10,40,15, Quality.val, "Mesh Quality")
763      else:
764         Quality = Menu(resmnu,102,140,10,40,15, Quality.val, "Mesh Quality")
765      Q_T = Toggle("Faces",102,220,10,40,15,Q_T.val,"Faces : Set Quads / Set Triangles")
766      smooth = Toggle("Smooth",102,180,10,40,15,smooth.val,"Faces : Set Solid / Set Smooth")
767      Auto_Update = Toggle("A",105,60,10,20,20, Auto_Update.val,"Automatic mesh update.")
768      Button("Update", 103, 10, 10, 50, 20,"Update mesh.")
769
770   pvi = "Preview %t|None %x0|Grey %x1|Original %x2|Coloured %x3"
771   pview = Menu(pvi,111, 10,226,20,15, pview.val, "Preview")
772   Button("P", 888, 35, 226, 15, 15,"Presets")
773   Button("X", 999, 245, 226, 15, 15,"Reset / Exit")
774
775### do_it -----------------------------------
776###-----------------------------------
777def do_it():
778   Blender.Window.WaitCursor(1)
779   Crea()
780   Blender.Window.WaitCursor(0)
781   Redraw()
782def do_it_random():
783   Blender.Window.WaitCursor(1)
784   Random_N()
785   Crea()
786   Blender.Window.WaitCursor(0)
787   Redraw()
788###-----------------------------------
789def event(evt, val):
790   if (evt== ESCKEY and not val):
791      Exit()
792def bevent(evt):
793   global Auto_Update, preset, preGrad, colorcontrols, colors
794
795   if (evt== 999):
796      name = "OK ?%t|Exit %x1|Reset %x2"
797      result = Blender.Draw.PupMenu(name)
798      if result == 2:
799         resetMe()
800         reset()
801         do_it()
802      elif result == 1:
803         Exit()
804
805   if (evt == EV_NOEVENT):
806      Draw()
807
808   if (evt == EV_NEW ):
809      colors[ preGrad.val ].append([newheight.val, 128, 128, 128])
810      colors[ preGrad.val ].sort()
811      colors[ preGrad.val ].reverse()
812      Draw()
813   else:
814      for c in range( len(colors[ preGrad.val ]) ):
815         if (evt == EVB_H+c):
816            colors[ preGrad.val ][c][0] = colorcontrols[0][c].val
817         elif (evt == EVB_R+c):
818            colors[ preGrad.val ][c][1] = colorcontrols[1][c].val
819         elif (evt == EVB_G+c):
820            colors[ preGrad.val ][c][2] = colorcontrols[2][c].val
821         elif (evt == EVB_B+c):
822            colors[ preGrad.val ][c][3] = colorcontrols[3][c].val
823         elif (evt == EVB_DEL+c):
824            del(colors[ preGrad.val ][c])
825      colors[ preGrad.val ].sort()
826      colors[ preGrad.val ].reverse()
827      Draw()
828
829   if (evt == 888):
830      pre="Default %x1|Original %x2|Blender hills %x3|Stones hills %x4|Round hills %x5|Plateau %x6|Shattered %x7|Chaotic %x8|RidgedMF %x9|Dist.hTerrain %x10|Cauliflower %x11|Ridges %x12|Crystalline %x13||Warped hT. %x14|ChebyTech %x15|CellNoise %x16|Canyonised %x17|Ring o Rock %x18|Xtreme Peaks %x19|HardTurb %x20|Cliff %x21"
831      result = Blender.Draw.PupMenu(pre,7)
832      if result > 0:
833         preset.val = result
834         if Auto_Update.val == 1:
835            reset()
836            Preset_Noise()
837            do_it()
838         else:
839            reset()
840            Preset_Noise()
841         Draw()
842
843   if (evt in [ 111 , 222 ] ):
844      Draw()
845   if (evt == 103):
846      do_it()
847   if Auto_Update.val == 1:
848      if (evt == 102):
849         do_it()
850      elif (evt == 69):
851         do_it_random()
852   if Auto_Update.val == 0:
853      if (evt == 69):
854         Random_N()
855         Draw()
856      elif (evt == 102):
857         Draw()
858
859   if (evt == 31):
860      if FX.val ==1:
861         Flt.val = 0
862         Draw()
863   if (evt == 32):
864      if Flt.val ==1:
865         FX.val = 0
866         Draw()
867
868Register(GUI, event, bevent)
Note: See TracBrowser for help on using the repository browser.