1 | #!BPY |
---|
2 | """ |
---|
3 | Name: 'A.N.T.Landscape v.1.04a' |
---|
4 | Blender: 241 |
---|
5 | Group: 'Add' |
---|
6 | Tip: 'Create landscape mesh.' |
---|
7 | """ |
---|
8 | |
---|
9 | |
---|
10 | # |
---|
11 | ## Execute Script: Alt P |
---|
12 | # |
---|
13 | |
---|
14 | ################################################################################################################ |
---|
15 | # Another Noise Tool 'Landscape' v.1.04 ( build and tested in Blender 2.41 ) |
---|
16 | # Jimmy Hazevoet April/May 2006 |
---|
17 | # license: Do whatever you want with it. |
---|
18 | ################################################################################################################ |
---|
19 | |
---|
20 | ################################################################################################################ |
---|
21 | ## BugFix: Sept./2006 v.1.04a |
---|
22 | # _ Image Effect did not worked well with tiled mesh. |
---|
23 | # Fixed (now use Freq. and Loc. buttons to scale and position image). |
---|
24 | ## |
---|
25 | ################################################################################################################ |
---|
26 | |
---|
27 | ################################################################################################################ |
---|
28 | # Readme: |
---|
29 | # |
---|
30 | # v.1.04: |
---|
31 | # _ New G.U.I. |
---|
32 | # |
---|
33 | # _ New noise types like: Double_Terrain, StatsByAlt_Terrain, slickRock, ditorted_heteroTerrain, vlNoise_turbulence, and many more. |
---|
34 | # |
---|
35 | # _ New fractalized Effect functions. |
---|
36 | # Effect types such as: gradient, waves and bumps, dome, piramide, squares, grid, shattered rocks, lunar, and many more. |
---|
37 | # Bias types: Sin, Cos, Tri, Saw, and Default(no bias). |
---|
38 | # For example the 'Rings' effect with 'Sin Bias' makes 'Rings' and 'Default Bias' makes 'Dome'. |
---|
39 | # _ The Effect 'Mix factor' Slider gives control over how much of the Effect is vissible, -1.0=noise, 0.0=average, 1.0=effect |
---|
40 | # this slider controls also the 'Warp amount' if mix type 'Warp' is selected. |
---|
41 | # |
---|
42 | # _ Image effect: mix image with noise |
---|
43 | # |
---|
44 | # _ IPOCurve Filter: use Ipo curve to filter terrain height. |
---|
45 | # I know it's a bit strange to use animation curves for landscape modelling, (actualy i want a curves panel in my G.U.I. but i dont know how to do that) |
---|
46 | # the downside of this method is that you have this 'Empty' moving around in your scene, so put it on another layer and 'Pin' the Ipo block so that it stays visible. |
---|
47 | # Usage: |
---|
48 | # Add one 'Empty' Object to your scene, now add one Loc Key at Frame 1, go to Frame 101 (UpArrow ten times), |
---|
49 | # move the 'Empty' +100 units in X+ direction and add another Loc Key, open the Ipo Curve Editor Window, rename this IpoBlock if you want, |
---|
50 | # Copie the first curve to buffer and Paste it in the empty slots (from top to bottom), now you can edit the curves freely. |
---|
51 | # (use the 'Pin' option to keep the curves visible while other objects are selected) |
---|
52 | # Set the CurveLength and CurveHeight Button value's according to the length and height of the selected curve. |
---|
53 | # A curve filter is very versatile when it comes to 'height' filtering. |
---|
54 | # |
---|
55 | # _ PreView in UV/Image Editor Window: |
---|
56 | # The preview image is now rendered as Blender.Image and will be saved to file directory as 'ANTview_size.tga' |
---|
57 | # you have to select 'ANTview_size.tga' in the UV/Image Editor Window |
---|
58 | # now it's posible to render and save a large HeightMap image (you can also create nice texture images when the VertCol gradient is enabled), |
---|
59 | # ! If you Change the preview image Size a New Blender.Image object is created. (one for size 256, one for size 512 one for.....) ! |
---|
60 | # |
---|
61 | # _ VertexColours: use any image as colour gradient. |
---|
62 | # This function actualy uses one 'row' of pixels from a image to produce the color gradient, |
---|
63 | # Make one or more custom gradient images with the Gimp or any other graphics software, the gradients must go from left to right (left is bottom and right is top. |
---|
64 | # you only need one row of pixels so you can put 10 gradients in a 256*10 image.(higher resolutions like 512*n or 1024*n gives smoother result) |
---|
65 | # Set Window DrawMode 'Textured' , and set the 'VCol Paint' option in the Materials panel ! |
---|
66 | # |
---|
67 | # _ Mesh Tiles: Create large scale terrains. |
---|
68 | # |
---|
69 | # _ Vertices Selection: select flat areas. |
---|
70 | # |
---|
71 | # _ Keyboard HotKeys: |
---|
72 | # SPACE = Update mesh. |
---|
73 | # R = Randomise. |
---|
74 | # V = Redraw preview. |
---|
75 | # |
---|
76 | # _ and more... |
---|
77 | # |
---|
78 | ################################################################################################################ |
---|
79 | |
---|
80 | |
---|
81 | import Blender |
---|
82 | from Blender import * |
---|
83 | from math import * |
---|
84 | from Blender.Noise import * |
---|
85 | from Blender.Draw import * |
---|
86 | from Blender.BGL import * |
---|
87 | from Blender import Image |
---|
88 | import string |
---|
89 | import BPyMathutils |
---|
90 | from BPyMathutils import genrand |
---|
91 | scene = Scene.getCurrent() |
---|
92 | |
---|
93 | |
---|
94 | ###--------------------------------------------------------------------------- |
---|
95 | ##-------------------------------------------------------------------------- |
---|
96 | # Customise: --------------------------------------------------------------- |
---|
97 | |
---|
98 | # G.U.I.: |
---|
99 | guitabs = [ Create( 0 ), Create( 1 ), Create( 0 ), Create( 0 ), Create( 0 ) ] # G.U.I. Tabs |
---|
100 | FullScreen = Create( 1 ) # FullScreen |
---|
101 | size_x = 320 # gui x size |
---|
102 | size_y = 280 # gui y size |
---|
103 | lightgrey = [ 0.76, 0.76, 0.76 ] # gui col. |
---|
104 | grey = [ 0.6, 0.6, 0.6 ] # panel col. |
---|
105 | background = [ 0.7, 0.7, 0.7, 1.0 ] # background col. |
---|
106 | black = [ 0.0, 0.0, 0.0 ] # text col. |
---|
107 | |
---|
108 | # Names: |
---|
109 | TerName = Create( 'Terrain' ) # Terrain Name |
---|
110 | previewname = Create( 'ANTview' ) # Preview / Heightmap Image Name |
---|
111 | |
---|
112 | # Mesh Resolutions: |
---|
113 | resolution = [ '16','32', '40', '64', '80', '100', '128', '160', '200', '256', '320', '400', '512', '640', '800', '960', '1024' ] |
---|
114 | |
---|
115 | ## Mesh Tiles: ## |
---|
116 | # |
---|
117 | # Tiles: Number of Positions is Number of Tiles: |
---|
118 | # 3 tiles: |
---|
119 | tiles_3 = [ ( 0 , 0 ), ( -1 , 0 ), ( +1 , 0 ) ] |
---|
120 | # 3*3: 9 tiles: |
---|
121 | tiles_9 = [ ( 0 , 0 ), ( -1 , 0 ), ( +1 , 0 ), ( -1 , -1 ), ( 0 , -1 ), ( +1 , -1 ), ( -1 , +1 ), ( 0 , +1 ), ( +1 , +1 ) ] |
---|
122 | # 5*5: 25 tiles: |
---|
123 | tiles_25 = [ ( 0 , 0 ), ( -2 , -2 ), ( -1 , -2 ), ( 0 , -2 ), ( +1 , -2 ) , ( +2 , -2 ), ( -2 , -1 ), ( -1 , -1 ), ( 0 , -1 ), ( +1 , -1 ), ( +2 , -1 ), ( -2 , 0 ), ( -1 , 0 ), ( +1 , 0 ) , ( +2 , 0 ), ( -2 , +1 ), ( -1 , +1 ), ( 0 , +1 ), ( +1 , +1 ), ( +2 , +1 ), ( -2 , +2 ), ( -1 , +2 ), ( 0 , +2 ) , ( +1 , +2 ), ( +2 , +2 ) ] |
---|
124 | |
---|
125 | # list of tile positions to choose from: |
---|
126 | tiles_positions = [ tiles_3, tiles_9, tiles_25 ] |
---|
127 | |
---|
128 | # re-scale (for falloff and preview) set this according to the x number of tiles: |
---|
129 | tile_rescale = [ 3 , 3 , 5 ] |
---|
130 | |
---|
131 | #--------------------------------------------------------------------------- |
---|
132 | ##-------------------------------------------------------------------------- |
---|
133 | ###--------------------------------------------------------------------------- |
---|
134 | |
---|
135 | columns = 10 # gui columns |
---|
136 | rows = 13 # gui rows |
---|
137 | |
---|
138 | effect_image = 'Load and Select image.' |
---|
139 | colgrad_image = 'Load and Select gradient image.' |
---|
140 | |
---|
141 | ipoblockname = '' |
---|
142 | thiscurve = [] |
---|
143 | selectedcurve = 0 |
---|
144 | |
---|
145 | phi = 3.14159265359 |
---|
146 | |
---|
147 | No_Evt = 1 |
---|
148 | Btn_Evt = 2 |
---|
149 | Upd_Evt = 3 |
---|
150 | Rndm_Evt = 4 |
---|
151 | Load_Evt = 5 |
---|
152 | Sel_Evt = 6 |
---|
153 | Grad_Sel_Evt = 61 |
---|
154 | Save_Evt = 7 |
---|
155 | Rend_Evt = 8 |
---|
156 | End_Evt = 9 |
---|
157 | Scrn_Evt = 15 |
---|
158 | Im_Evt = 16 |
---|
159 | gt0_Evt = 10 |
---|
160 | gt1_Evt = 11 |
---|
161 | gt2_Evt = 12 |
---|
162 | gt3_Evt = 13 |
---|
163 | gt4_Evt = 14 |
---|
164 | |
---|
165 | noisetypemenu = "Noise type: %t|multiFractal %x0|ridgedMFractal %x1|hybridMFractal %x2|heteroTerrain %x3|fBm %x4|turbulence %x5|Voronoi turb. %x6|vlNoise turb. %x7|noise %x8|cellNoise %x9| %l|Marble %x10|lava_multiFractal %x11|slopey_noise %x12|duo_multiFractal %x13|distorted_heteroTerrain %x14|slickRock %x15|terra_turbulence %x16|rocky_fBm %x17|StatsByAlt_Terrain %x18|Double_Terrain %x19" |
---|
166 | noisebasismenu = "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" |
---|
167 | voronitypemenu = "Voronoi type %t|Distance %x0|Distance Squared %x1|Manhattan %x2|Chebychev %x3|Minkovsky 1/2 %x4|Minkovsky 4 %x5|Minkovsky %x6" |
---|
168 | tBasismodemenu = "Terrain basis mode: %t|noise %x0|ridged noise %x1|vlNoise %x2|ridged vlNoise %x3" |
---|
169 | |
---|
170 | effecttypemenu = ['Effect Type %t','No Effect %x0','Image %x1','Turbulence %x2','vlNoise %x3','Marble %x4','Gradient %x5','Waves and Bumps %x6','ZigZag %x7','Wavy %x8','Sine Bump %x9','Dots %x10','Rings / Dome %x11','Spiral %x12','Square / Piramide %x13','Blocks %x14','Grid %x15','Tech %x16','Crackle %x17','Sparse Cracks %x18','Shattered Rocks %x19','Lunar %x20','Cosine noise %x21','Spike noise %x22','Stone noise %x23','Flat Turb %x24','Flat Voroni %x25' ] |
---|
171 | mixtypemenu = ['Mix Type %t','Effect only %x0','%l','Mix %x1','Add %x2','Subtract %x3','Multiply %x4','Difference %x5','Screen %x6','addmodulo %x7','Minimum %x8','Maximum %x9','%l','Warp Effect %x10','Warp Noise %x11'] |
---|
172 | |
---|
173 | biastypemenu = "Bias %t|Sin bias %x0|Cos bias %x1|Tri bias %x2|Saw bias %x3|Default (no bias)%x4" |
---|
174 | sharptypemenu = "Sharpen %t|Soft %x0|Sharp %x1|Sharper %x2" |
---|
175 | |
---|
176 | filtermodemenu = "Filter Mode %t|No Filter %x0| %l|Default Filters %x1|IPOCurve Filter %x2" |
---|
177 | filtertypemenu = "Filter Type %t|Default Terrace %x0|Sharper Terrace %x1|Rounded Terrace %x2|Posterise Mixed %x3|Posterise %x4|Layered Peaks %x5|Peaked %x6|Smooth-thing %x7|Sin bias %x8|Cos bias %x9|Tri bias %x10|Saw bias %x11" |
---|
178 | falloftypemenu = "Edge Falloff %t|No Edge Falloff %x0| %l|Soft Falloff %x1|Default Falloff %x2|Hard Falloff %x3|Linear Falloff Y %x4|Linear Falloff X %x5|Diagonal Falloff + %x6|Diagonal Falloff - %x7|Square %x8|Round %x9" |
---|
179 | |
---|
180 | randomtypemenu = "Random type: %t|setRandomSeed() : Blender.Noise %x0|Rand() : Blender.Mathutils %x1|genrand() : BPyMathutils MersenneTwister %x2" |
---|
181 | |
---|
182 | ##-------------------------------------------------- |
---|
183 | def Set_ReSet_Values(): |
---|
184 | global Quality, Quad_Tri, Smooth, vSelRange, maketiles |
---|
185 | global iScale, Offset, Invert, NSize, Sx, Sy, Lx, Ly |
---|
186 | global NType, Basis, musgr, vlnoi, vlnoiTwo, voron, turbOne, turbTwo, marbleOne, marbleTwo, tBasismod |
---|
187 | global Effect_Ctrl, Min, Max, Falloff, Filter_Mode, Def_Filter_Ctrl, Ipo_Filter_Ctrl |
---|
188 | global RandMod, RSeed, rand_H, rand_S, rand_L |
---|
189 | global AutoUpd, PreView, ViewiScale, vcolours, vcolGradRow, gradScale |
---|
190 | |
---|
191 | AutoUpd = Create( 0 ) |
---|
192 | PreView = [ Create( 0 ), Create( 7 ), Create( 0 ) ] |
---|
193 | ViewiScale = Create( 1.0 ) |
---|
194 | vcolours = Create( 0 ) |
---|
195 | vcolGradRow = Create( 0 ) |
---|
196 | gradScale = Create( 1.0 ) |
---|
197 | ## Mesh controls: |
---|
198 | Quality = Create( 7 ) |
---|
199 | Quad_Tri = Create( 0 ) |
---|
200 | Smooth = Create( 0 ) |
---|
201 | vSelRange = Create( 0.0 ) |
---|
202 | maketiles = [ Create( 0 ), Create( 0 ) ] |
---|
203 | ## Coords controls: |
---|
204 | iScale = [ Create( 1.0 ), Create( 1.0 ), Create( 0.25) ] |
---|
205 | Offset = [ Create( 0.0 ), Create( 0.0), Create( 0.0) ] |
---|
206 | Invert = [ Create( 0 ), Create( 0 ), Create( 0 ) ] |
---|
207 | NSize = [ Create( 1.0 ), Create( 2.0 ) ] |
---|
208 | Sx = [ Create( 1.0 ), Create( 1.0 ) ] |
---|
209 | Sy = [ Create( 1.0 ), Create( 1.0 ) ] |
---|
210 | Lx = [ Create( 0.0 ), Create( 0.0 ) ] |
---|
211 | Ly = [ Create( 0.0 ), Create( 0.0 ) ] |
---|
212 | ## Noise controls: |
---|
213 | NType = Create( 0 ) |
---|
214 | Basis = [ Create( 0 ), Create( 0 ) ] |
---|
215 | musgr = [ Create( 1.0 ), Create( 2.0 ), Create( 8 ), Create( 1.0 ), Create( 1.0 ), Create( 0.5 ) ] |
---|
216 | vlnoi = [ Create( 1.0 ), Create( 0 ) ] |
---|
217 | vlnoiTwo = [ Create( 1.0 ), Create( 0 ) ] |
---|
218 | voron = [ Create( 0 ), Create( 2.5 ) ] |
---|
219 | turbOne = [ Create( 3 ), Create( 0 ), Create( 0.5 ), Create( 2.0 ) ] |
---|
220 | turbTwo = [ Create( 3 ), Create( 0 ), Create( 0.5 ), Create( 2.0 ) ] |
---|
221 | marbleOne = [ Create( 6 ), Create( 0 ), Create( 2.0 ), Create( 0 ), Create( 0 ), Create( 1.0 ) ] |
---|
222 | marbleTwo = [ Create( 6 ), Create( 0 ), Create( 2.0 ), Create( 0 ), Create( 0 ), Create( 1.0 ) ] |
---|
223 | tBasismod = Create(0) |
---|
224 | ## Effect controls: |
---|
225 | Effect_Ctrl = [ Create( 0 ), Create( 2 ), Create( 0.0 ), Create( 0 ), Create( 0.0 ) , Create( 0 ), Create( 2.0 ) , Create( 0.5 ) ] |
---|
226 | ## Filter controls: |
---|
227 | Min = Create( 0.0 ) |
---|
228 | Max = Create( 1.0 ) |
---|
229 | Falloff = [ Create( 0 ), Create( 1.0 ), Create( 1.0 ), Create( 0 ) , Create( 0 ) ] |
---|
230 | Filter_Mode = Create( 0 ) |
---|
231 | Def_Filter_Ctrl = [ Create( 0 ), Create( 3.0 ) ] |
---|
232 | Ipo_Filter_Ctrl = [ Create( "ObIpo" ), Create( 0 ), Create( 100.0 ), Create( 100.0 ) ] |
---|
233 | ## Randomise noise buttons: |
---|
234 | RandMod = Create( 1 ) |
---|
235 | RSeed = Create( 0 ) |
---|
236 | rand_H = Create( 0 ) |
---|
237 | rand_S = Create( 0 ) |
---|
238 | rand_L = Create( 1 ) |
---|
239 | |
---|
240 | ##------------------------- |
---|
241 | |
---|
242 | Set_ReSet_Values() |
---|
243 | |
---|
244 | ##------------------------- |
---|
245 | |
---|
246 | ###--------------------------------------------------------------------------- |
---|
247 | ## Randomise: |
---|
248 | ##------------------------- |
---|
249 | |
---|
250 | # Generate random numbers: |
---|
251 | def randnum(low,high): |
---|
252 | global RandMod, RSeed |
---|
253 | if RandMod.val == 0: |
---|
254 | # Noise.random setRandomSeed |
---|
255 | s = setRandomSeed( RSeed.val ) |
---|
256 | num = random() |
---|
257 | num = num*(high-low) |
---|
258 | num = num+low |
---|
259 | elif RandMod.val == 1: |
---|
260 | # Mathutils.Rand |
---|
261 | num = Mathutils.Rand( 0.0, 1.0 ) |
---|
262 | num = num*(high-low) |
---|
263 | num = num+low |
---|
264 | else: |
---|
265 | # BPyMathutils Mersenne Twister genrand |
---|
266 | num = genrand() |
---|
267 | num = num*(high-low) |
---|
268 | num = num+low |
---|
269 | return num |
---|
270 | |
---|
271 | # Randomise noise: height, size and location: |
---|
272 | def randomiseNoise(): |
---|
273 | global rand_H, rand_S, rand_L, NSize, iScale, Offset, Invert, Lx, Ly, Sx, Sy |
---|
274 | if rand_H.val !=0: |
---|
275 | iScale[2] = Create( randnum( 0.1 , 1.0 ) ) |
---|
276 | Offset[2] = Create( randnum(-0.25 , 0.25 ) ) |
---|
277 | #Invert[2] = Create( randnum( 0 , 2 ) ) |
---|
278 | if rand_S.val !=0: |
---|
279 | NSize[0] = Create( randnum( 0.2 , 3.0 ) ) |
---|
280 | #Sx[0] = Create( randnum( 0.75 , 1.25 ) ) |
---|
281 | #Sy[0] = Create( randnum( 0.75 , 1.25 ) ) |
---|
282 | if rand_L.val !=0: |
---|
283 | Lx[0] = Create( randnum( -1000 , 1000 ) ) |
---|
284 | Ly[0] = Create( randnum( -1000 , 1000 ) ) |
---|
285 | |
---|
286 | |
---|
287 | ###---------------------------------------------------------------------------------------------------- |
---|
288 | ## G.U.I.: text,backpanel,panel and frame |
---|
289 | #-------------------------------------------------- |
---|
290 | def draw_Text( ( x, y ), text, color, size ): |
---|
291 | glColor3f( color[0],color[1],color[2] ) |
---|
292 | glRasterPos2d(x,y) |
---|
293 | txtsize = 'small', 'normal', 'large' |
---|
294 | Text( text, txtsize[ size ] ) |
---|
295 | def draw_BackPanel( text, x, y, w, h, colors ): |
---|
296 | glColor3f( colors[0]*0.76, colors[1]*0.76, colors[2]*0.76 ) |
---|
297 | glRecti( x, h, w, h+20 ) |
---|
298 | glColor3f( colors[0], colors[1], colors[2] ) |
---|
299 | glRecti( x, y, w, h ) |
---|
300 | glColor3f( colors[0], colors[1], colors[2] ) |
---|
301 | glRasterPos2d( x+10, h+5 ) |
---|
302 | Text( text, 'small' ) |
---|
303 | def draw_Panel( x, y, w, h, colors ): |
---|
304 | glColor3f( colors[0], colors[1], colors[2] ) |
---|
305 | glRecti( x,y, w,h ) |
---|
306 | def draw_Frame( text, x, y, w, h, color ): |
---|
307 | glColor3f( color[0], color[1], color[2] ) |
---|
308 | glRasterPos2i(x+3,h-3) |
---|
309 | Text(text ,'small') |
---|
310 | stringwidth = GetStringWidth( text,'small' ) |
---|
311 | glColor3f( color[0], color[1], color[2] ) |
---|
312 | glBegin(Blender.BGL.GL_LINE_STRIP) |
---|
313 | glVertex2i(x,h) |
---|
314 | glVertex2i(x,y) |
---|
315 | glVertex2i(w,y) |
---|
316 | glVertex2i(w,h) |
---|
317 | glVertex2i(x+stringwidth+10,h) |
---|
318 | glEnd() |
---|
319 | |
---|
320 | |
---|
321 | ###---------------------------------------------------------------------------------------------------- |
---|
322 | ## Buttons: |
---|
323 | #---------------------------------------------------------------------------------------------------- |
---|
324 | |
---|
325 | ###------------------------- |
---|
326 | ## Mesh Buttons: |
---|
327 | # |
---|
328 | def MeshButtons( col, row, width, height ): |
---|
329 | global TerName, AutoUpd, Quality, Quad_Tri, Smooth, vSelRange, maketiles |
---|
330 | |
---|
331 | draw_Text( ( col[2], row[1] ), 'Make Duplicate: [ Shift D ] in 3D View.', black, 0 ) |
---|
332 | TerName = String( "OB:", No_Evt, col[2], row[3], width[5], height[2] ,TerName.val,20, "Object name. (New name generates new mesh)" ) |
---|
333 | Quality = Menu( 'Vertices: Resolution n*n %t|' + '|'.join( resolution ), No_Evt ,col[2], row[5], width[5], height[2], Quality.val, "Verts: Number of Vertices ( n*n )" ) |
---|
334 | smoothmnu = "Faces: %t|Solid %x0|Smooth %x1" |
---|
335 | Smooth = Menu( smoothmnu, No_Evt ,col[2], row[6], width[2], height[1], Smooth.val, "Faces: SetSmooth / SetSolid" ) |
---|
336 | facemnu = "Faces: %t|Quads %x0|Triangles %x1" |
---|
337 | Quad_Tri = Menu( facemnu, No_Evt ,col[5], row[6], width[2], height[1], Quad_Tri.val, "Faces: Quads / Triangles" ) |
---|
338 | vSelRange = Slider( "VertSel:", No_Evt, col[2], row[8], width[5], height[2], vSelRange.val, 0.0, 10.0, 0 , "Vertices Selection: Select flat areas (higher value selects more slopes)" ) |
---|
339 | if maketiles[0].val !=0: |
---|
340 | maketiles[1] = Number("" , No_Evt, col[6], row[10], width[1], height[2], maketiles[1].val, 0, len(tiles_positions)-1 , "Tiles: Select Number of tiles" ) |
---|
341 | maketiles[0] = Toggle( str(len(tiles_positions[maketiles[1].val])) + " Tiles", No_Evt, col[2], row[10], width[3], height[2], maketiles[0].val, "Tiled Mesh: Generate Terrain Tiles (for making large scale terrain)") |
---|
342 | else: |
---|
343 | maketiles[0] = Toggle("Tiles", No_Evt, col[2], row[10], width[5], height[2], maketiles[0].val, "Tiled Mesh: Generate Terrain Tiles (for making large scale terrain)") |
---|
344 | |
---|
345 | ###------------------------- |
---|
346 | ## Noise Buttons: |
---|
347 | # |
---|
348 | def NoiseButtons( col, row, width, height ): |
---|
349 | global NSize, iScale, Offset, Invert, Lx, Ly, Sx, Sy |
---|
350 | global Ha, La, Oc, Of, Ga, Basis, NType, musgr, vlnoi, voron, turbOne, tBasismod |
---|
351 | global Depth, Hard, Amp, Freq, vlBasis, Distort, VFunc, VExp, VDep, marbleOne |
---|
352 | global RandMod, RSeed, rand_H, rand_S, rand_L |
---|
353 | |
---|
354 | bth = height[1]/2+5 |
---|
355 | iScale[0] = Number("iScale:", Btn_Evt, col[5], row[2]+bth, width[3], height[1], iScale[0].val, -10.0, 10.0 , "Noise: Intensity Scale. ( To scale terrain height, use 'HeightScale' in the Height panel )" ) |
---|
356 | Invert[0] = Toggle("Inv.", Btn_Evt, col[9], row[2]+bth, width[0], height[1], Invert[0].val, "Noise: Invert") |
---|
357 | Offset[0] = Number("Offset:", Btn_Evt, col[5], row[3]+bth, width[4], height[1], Offset[0].val, -10.0, 10.0 , "Noise: Offset " ) |
---|
358 | NSize[0] = Number("Noise Size:",Btn_Evt, col[5], row[5], width[4], height[2], NSize[0].val, 0.001, 10.0 , "Noise Size" ) |
---|
359 | Sx[0] = Number("Size X:", Btn_Evt, col[5], row[6], width[4], height[1], Sx[0].val, 0.001, 10.0 , "Size X" ) |
---|
360 | Sy[0] = Number("Size Y:", Btn_Evt, col[5], row[7], width[4], height[1], Sy[0].val, 0.001, 10.0 , "Size Y" ) |
---|
361 | Lx[0] = Number("Loc X:", Btn_Evt, col[5], row[9], width[4], height[1], Lx[0].val, -1000.0, 1000.0 , "Loc X" ) |
---|
362 | Ly[0] = Number("Loc Y:", Btn_Evt, col[5], row[10],width[4], height[1], Ly[0].val, -1000.0, 1000.0 , "Loc Y" ) |
---|
363 | |
---|
364 | NType = Menu( noisetypemenu, Btn_Evt, col[0], row[2], width[4], height[2], NType.val, "Noise type" ) |
---|
365 | if NType.val == 6: |
---|
366 | voron[0] = Menu( voronitypemenu, Btn_Evt, col[0], row[3], width[4], height[1], voron[0].val, "Voronoi type" ) |
---|
367 | else: |
---|
368 | Basis[0] = Menu( noisebasismenu, Btn_Evt, col[0], row[3], width[4], height[1], Basis[0].val, "Noise Basis" ) |
---|
369 | |
---|
370 | if NType.val in [0,1,2,3,4,11,12,13,14,15,17,18,19]: |
---|
371 | musgr[0] = Slider( "H: ", Btn_Evt, col[0], row[5], width[4], height[1], musgr[0].val, 0.0, 3.0, 0 , "H" ) |
---|
372 | musgr[1] = Slider( "Lacu: ", Btn_Evt, col[0], row[6], width[4], height[1], musgr[1].val, 0.0, 6.0, 0 , "Lacunarity" ) |
---|
373 | musgr[2] = Slider( "Octs: ", Btn_Evt, col[0], row[4], width[4], height[1], musgr[2].val, 0, 12, 0 , "Octaves" ) |
---|
374 | if NType.val in [1,2,3,13,14,15,18,19]: |
---|
375 | musgr[3] = Slider( "Offst: ", Btn_Evt, col[0], row[7], width[4], height[1], musgr[3].val, 0.0, 6.0, 0 , "Offset" ) |
---|
376 | if NType.val in [1,2,13,15,18]: |
---|
377 | musgr[4] = Slider( "Gain: ", Btn_Evt, col[0], row[8], width[4], height[1], musgr[4].val, 0.0, 6.0, 0 , "Gain" ) |
---|
378 | if NType.val == 19: |
---|
379 | musgr[5] = Slider( "Thresh: ", Btn_Evt, col[0], row[8], width[4], height[1], musgr[5].val, 0.001, 2.0, 0 , "Threshold" ) |
---|
380 | if NType.val in [5,6,7,16]: |
---|
381 | turbOne[0] = Number( "Depth:", Btn_Evt, col[0], row[4], width[4], height[1], turbOne[0].val, 0, 12, "Octaves") |
---|
382 | turbOne[1] = Toggle("Hard noise", Btn_Evt, col[0], row[5], width[4], height[1], turbOne[1].val, "Soft noise / Hard noise") |
---|
383 | turbOne[2] = Slider( "Amp:", Btn_Evt, col[0], row[6], width[4], height[1], turbOne[2].val, 0.0, 3.0, 0, "Ampscale ") |
---|
384 | turbOne[3] = Slider( "Freq:", Btn_Evt, col[0], row[7], width[4], height[1], turbOne[3].val, 0.0, 6.0, 0, "Freqscale") |
---|
385 | if NType.val in [18,19]: |
---|
386 | tBasismod = Menu( tBasismodemenu, Btn_Evt, col[0], row[9], width[4], height[1], tBasismod.val, "Terrain basis mode.") |
---|
387 | if NType.val == 6: |
---|
388 | if voron[0].val == 6: |
---|
389 | voron[1] = Slider( "Exp: ", Btn_Evt, col[0], row[8], width[4], height[1], voron[1].val, 0.0,10.0, 0, "Minkovsky exponent") |
---|
390 | if NType.val in [7,11,12,14]: |
---|
391 | vlnoi[0] = Slider( "Dist: ", Btn_Evt, col[0], row[8], width[4], height[1], vlnoi[0].val, 0.0, 10.0, 0 , "Distort" ) |
---|
392 | if NType.val == 7: |
---|
393 | vlnoi[1] = Menu(noisebasismenu,Btn_Evt, col[0], row[9], width[4], height[1], vlnoi[1].val, "Distortion Noise") |
---|
394 | if NType.val == 10: |
---|
395 | marbleOne[0] = Number( "Depth: ", Btn_Evt, col[0], row[6], width[4], height[1], marbleOne[0].val, 0, 12, "Octaves") |
---|
396 | marbleOne[2] = Slider( "Turb: ", Btn_Evt, col[0], row[7], width[4], height[1], marbleOne[2].val, 0.0,20.0, 0, "Turbulence ") |
---|
397 | marbleOne[3] = Menu( biastypemenu, Btn_Evt ,col[0], row[4], width[4], height[1], marbleOne[3].val, "Bias") |
---|
398 | marbleOne[5] = Slider( "ReScale: ", Btn_Evt, col[0], row[8], width[4], height[1], marbleOne[5].val, 0.0,20.0, 0, "ReScale") |
---|
399 | if marbleOne[3].val != 4: |
---|
400 | marbleOne[4] = Menu(sharptypemenu, Btn_Evt ,col[0], row[5], width[4], height[1], marbleOne[4].val, "Sharpen") |
---|
401 | |
---|
402 | RandMod = Menu( randomtypemenu, No_Evt, col[0], row[10], width[1], height[1], RandMod.val, "Random Type" ) |
---|
403 | rand_H = Toggle("H",No_Evt ,col[2], row[10], width[0], height[1], rand_H.val, "Randomise Terrain Height ( in Height panel )") |
---|
404 | rand_S = Toggle("S",No_Evt ,col[3], row[10], width[0], height[1], rand_S.val, "Randomise Noise Size") |
---|
405 | rand_L = Toggle("L",No_Evt ,col[4], row[10], width[0], height[1], rand_L.val, "Randomise Noise Location") |
---|
406 | |
---|
407 | ###------------------------- |
---|
408 | ## Effect Buttons: |
---|
409 | # |
---|
410 | def EffectButtons( col, row, width, height ): |
---|
411 | global Effect_Type, Effect_Ctrl, Blend_Effect |
---|
412 | global NSize, iScale, Offset, Invert, Lx, Ly, Sx, Sy |
---|
413 | global BasisTwo, turbTwo, marbleTwo, vlnoiTwo |
---|
414 | |
---|
415 | Effect_Ctrl[0] = Menu( '|'.join( effecttypemenu ), Btn_Evt, col[0], row[2], width[4], height[2], Effect_Ctrl[0].val, "Effect: Type" ) |
---|
416 | if Effect_Ctrl[0].val != 0: |
---|
417 | Effect_Ctrl[1] = Menu( '|'.join( mixtypemenu ), Btn_Evt, col[5], row[2], width[4], height[2], Effect_Ctrl[1].val, "Mix: Type" ) |
---|
418 | Effect_Ctrl[2] = Slider("Mix: ", Btn_Evt, col[5], row[3], width[4], height[1], Effect_Ctrl[2].val, -1.0, 1.0, 0, "Mix factor / Warp amount" ) |
---|
419 | iScale[1] = Number("iScale:", Btn_Evt, col[5], row[4], width[3], height[1], iScale[1].val, -20.0, 20.0 , "Effect: Intensity Scale " ) |
---|
420 | Invert[1] = Toggle("Inv.", Btn_Evt, col[9], row[4], width[0], height[1], Invert[1].val, "Effect: Invert") |
---|
421 | Offset[1] = Number("Offset:", Btn_Evt, col[5], row[5], width[4], height[1], Offset[1].val, -20.0, 20.0 , "Effect: Offset " ) |
---|
422 | NSize[1] = Number("Frequency:", Btn_Evt, col[5], row[6], width[4], height[1], NSize[1].val, 0.001, 100.0, "Effect Frequency ( Scale )" ) |
---|
423 | Sx[1] = Number("Freq X:", Btn_Evt, col[5], row[7], width[4], height[1], Sx[1].val, -50.0, 50.0 , "Effect Frequency X ( ScaleX )" ) |
---|
424 | Sy[1] = Number("Freq Y:", Btn_Evt, col[5], row[8], width[4], height[1], Sy[1].val, -50.0, 50.0 , "Effect Frequency Y ( ScaleY )" ) |
---|
425 | Lx[1] = Number("Loc X:", Btn_Evt, col[5], row[9], width[4], height[1], Lx[1].val, -1000.0, 1000.0 , "Effect Loc X" ) |
---|
426 | Ly[1] = Number("Loc Y:", Btn_Evt, col[5], row[10], width[4], height[1], Ly[1].val, -1000.0, 1000.0 , "Effect Loc Y" ) |
---|
427 | |
---|
428 | if Effect_Ctrl[0].val == 1: |
---|
429 | PushButton("Load Image", Load_Evt, col[0], row[4], width[4], height[2] , "Load Image") |
---|
430 | PushButton("Select Image", Sel_Evt, col[0], row[6], width[4], height[3] , "Select Image") |
---|
431 | draw_Text( ( col[0]+5, row[7] ), effect_image, black, 1 ) |
---|
432 | |
---|
433 | if Effect_Ctrl[0].val in [2,3,4]: |
---|
434 | Basis[1] = Menu( noisebasismenu, Btn_Evt, col[0], row[3], width[4], height[1], Basis[1].val, "Basis" ) |
---|
435 | if Effect_Ctrl[0].val == 2: |
---|
436 | turbTwo[0] = Number( "Depth:", Btn_Evt, col[0], row[4], width[4], height[1], turbTwo[0].val, 1, 12, "Octaves") |
---|
437 | turbTwo[1] = Toggle("Hard noise", Btn_Evt, col[0], row[5], width[4], height[1], turbTwo[1].val, "Hard noise") |
---|
438 | turbTwo[2] = Slider( "Amp:", Btn_Evt, col[0], row[6], width[4], height[1], turbTwo[2].val, 0.0, 3.0, 0, "Ampscale ") |
---|
439 | turbTwo[3] = Slider( "Freq:", Btn_Evt, col[0], row[7], width[4], height[1], turbTwo[3].val, 0.0, 6.0, 0, "Freqscale") |
---|
440 | if Effect_Ctrl[0].val == 3: |
---|
441 | vlnoiTwo[1] = Menu(noisebasismenu,Btn_Evt, col[0], row[4], width[4], height[1], vlnoiTwo[1].val, "Distortion Noise") |
---|
442 | vlnoiTwo[0] = Slider( "Dist: ", Btn_Evt, col[0], row[5], width[4], height[1], vlnoiTwo[0].val, 0.0, 10.0, 0 , "Distort" ) |
---|
443 | if Effect_Ctrl[0].val == 4: |
---|
444 | marbleTwo[0] = Number( "Depth: ", Btn_Evt, col[0], row[6], width[4], height[1], marbleTwo[0].val, 1, 12, "Octaves") |
---|
445 | marbleTwo[2] = Slider( "Turb: ", Btn_Evt, col[0], row[7], width[4], height[1], marbleTwo[2].val, 0.0,20.0, 0, "Turbulence") |
---|
446 | marbleTwo[3] = Menu( biastypemenu, Btn_Evt ,col[0], row[4], width[4], height[1], marbleTwo[3].val, "Bias") |
---|
447 | marbleTwo[5] = Slider( "ReScale: ", Btn_Evt, col[0], row[8], width[4], height[1], marbleTwo[5].val, 0.0,20.0, 0, "ReScale") |
---|
448 | if marbleTwo[3].val != 4: |
---|
449 | marbleTwo[4] = Menu( sharptypemenu,Btn_Evt ,col[0], row[5], width[4], height[1], marbleTwo[4].val, "Sharpen") |
---|
450 | if Effect_Ctrl[0].val > 4: |
---|
451 | Effect_Ctrl[5] = Number("Depth:", Btn_Evt, col[0], row[4], width[4], height[1], Effect_Ctrl[5].val, 0, 12 , "Fractalize Effect: Octaves" ) |
---|
452 | Effect_Ctrl[4] = Number("Distort:",Btn_Evt, col[0], row[7], width[4], height[1], Effect_Ctrl[4].val, 0.0, 10.0 , "Distort Effect: Distortion amount" ) |
---|
453 | Effect_Ctrl[6] = Slider("Freq:", Btn_Evt, col[0], row[5], width[4], height[1], Effect_Ctrl[6].val, 0.0, 6.0, 0, "Fractalize Effect: Frequency" ) |
---|
454 | Effect_Ctrl[7] = Slider("Amp:", Btn_Evt, col[0], row[6], width[4], height[1], Effect_Ctrl[7].val, 0.0, 3.0, 0, "Fractalize Effect: Amplitude" ) |
---|
455 | if Effect_Ctrl[0].val < 17: |
---|
456 | Effect_Ctrl[3] = Menu( biastypemenu, Btn_Evt ,col[0], row[3], width[4], height[1], Effect_Ctrl[3].val, "Effect bias") |
---|
457 | |
---|
458 | |
---|
459 | |
---|
460 | ###------------------------- |
---|
461 | ## Filter Buttons: |
---|
462 | # |
---|
463 | def FilterButtons( col, row, width, height ): |
---|
464 | global iScale, Offset, Invert, Min, Max, Falloff |
---|
465 | global Filter_Mode, Def_Filter_Ctrl, Ipo_Filter_Ctrl |
---|
466 | |
---|
467 | iScale[2] = Number("Height:", Btn_Evt, col[5], row[2], width[3], height[2], iScale[2].val, -10.0, 10.0 , "Terrain Height: Scale" ) |
---|
468 | Invert[2] = Toggle("Inv.", Btn_Evt, col[9], row[2], width[0], height[2], Invert[2].val, "Terrain Height: Invert") |
---|
469 | Offset[2] = Number("Offset:", Btn_Evt, col[5], row[3], width[4], height[1], Offset[2].val, -10.0, 10.0 , "Terrain Height: Offset" ) |
---|
470 | Falloff[0] = Menu( falloftypemenu, Btn_Evt ,col[5], row[5], width[4], height[2], Falloff[0].val, "Terrain Height: Edge falloff") |
---|
471 | if Falloff[0].val !=0: |
---|
472 | Falloff[1] = Number("X:", Btn_Evt, col[5], row[6], width[1], height[1], Falloff[1].val , 0.01, 10.0 , "Edge falloff: X Size" ) |
---|
473 | Falloff[2] = Number("Y:", Btn_Evt, col[8], row[6], width[1], height[1], Falloff[2].val , 0.01, 10.0 , "Edge falloff: Y Size" ) |
---|
474 | Falloff[4] = Toggle("Inv.", Btn_Evt, col[7], row[6], width[0], height[1], Falloff[4].val, "Edge falloff: Invert") |
---|
475 | Falloff[3] = Toggle("Edge At Sealevel", Btn_Evt, col[5], row[7], width[4], height[1], Falloff[3].val, "Edge falloff: Edge at Sealevel") |
---|
476 | Max = Number("Plateau:", Btn_Evt, col[5], row[8], width[4], height[1], Max.val, Min.val, 1.0 , "Terrain Height: Clamp Max. ( Plateau )" ) |
---|
477 | Min = Number("Sealevel:", Btn_Evt, col[5], row[9], width[4], height[1], Min.val, -1.0, Max.val , "Terrain Height: Clamp Min. ( Sealevel )" ) |
---|
478 | Filter_Mode = Menu( filtermodemenu, No_Evt ,col[0], row[2], width[4], height[2], Filter_Mode.val, "Filter: Mode") |
---|
479 | if Filter_Mode.val ==1: |
---|
480 | Def_Filter_Ctrl[0] = Menu( filtertypemenu, Btn_Evt ,col[0], row[4], width[4], height[2], Def_Filter_Ctrl[0].val, "Filter: Type") |
---|
481 | Def_Filter_Ctrl[1] = Number("Amount: ", Btn_Evt, col[0], row[5], width[4], height[1], Def_Filter_Ctrl[1].val, 0.1, 25.0 , "Filter: Amount" ) |
---|
482 | elif Filter_Mode.val ==2: |
---|
483 | Ipo_Filter_Ctrl[0] = String("IP:", No_Evt, col[0], row[4], width[4], height[2], Ipo_Filter_Ctrl[0].val,20, "Ipo datablock name" ) |
---|
484 | Ipo_Filter_Ctrl[1] = Number("Selected Curve:", No_Evt, col[0], row[6], width[4], height[3], Ipo_Filter_Ctrl[1].val, 0, 29, "Selected curve" ) |
---|
485 | Ipo_Filter_Ctrl[2] = Number("Curve Length:", No_Evt, col[0], row[7], width[4], height[1], Ipo_Filter_Ctrl[2].val, 0.0, 1000.0, "X: Length (number of frames) of the selected curve." ) |
---|
486 | Ipo_Filter_Ctrl[3] = Number("Curve Height:", No_Evt, col[0], row[8], width[4], height[1], Ipo_Filter_Ctrl[3].val, 0.0, 1000.0, "Y: Height (offset) of the selected curve." ) |
---|
487 | |
---|
488 | ###------------------------- |
---|
489 | ## Option Buttons: |
---|
490 | # |
---|
491 | def OptionButtons( col, row, width, height ): |
---|
492 | global PreView, previewname, ViewiScale, vcolours, vcolGradRow, gradScale |
---|
493 | |
---|
494 | PreView[0] = Toggle("Preview Image", No_Evt, col[0], row[2], width[4], height[2], PreView[0].val, "Preview image: On/Off (See image in UV/Image Editor Window)") |
---|
495 | if PreView[0].val !=0: |
---|
496 | previewname = String( "IM:", No_Evt, col[0], row[3], width[2], height[1] ,previewname.val, 8, "Preview / HeightMap Image Name." ) |
---|
497 | ViewiScale = Number("", No_Evt, col[0], row[4], width[1], height[1], ViewiScale.val, 0.0, 10.0, "Preview image: intensity scale ( brightness )") |
---|
498 | PushButton( "Redraw", Im_Evt, col[2], row[4], width[2], height[1] , "Preview: Generate/Update image ( KEY: V )") |
---|
499 | PreView[1] = Menu( 'Preview_size: %t|' + '|'.join( resolution ), No_Evt ,col[3], row[3], width[1], height[1], PreView[1].val, "Preview image size.(Every image size will generate its own image object)") |
---|
500 | draw_Text( ( col[5], row[1] ), 'Select the preview image', black, 0 ) |
---|
501 | draw_Text( ( col[5], row[2] ), 'IM: ' + previewname.val + '_' + resolution[PreView[1].val-1] + '.tga', black, 0 ) |
---|
502 | draw_Text( ( col[5], row[3] ), 'in UV/Image Editor Window.', black, 0 ) |
---|
503 | |
---|
504 | draw_Frame( 'Vertex Colour:', col[1], row[10], col[9]-5, row[5], black ) |
---|
505 | draw_Text( ( col[2], row[6] ), 'Selected: '+colgrad_image , black, 0 ) |
---|
506 | PushButton( "Load", Load_Evt, col[2], row[7], width[2], height[1] , "VertCol: Load colour gradient image") |
---|
507 | PushButton( "Select", Grad_Sel_Evt, col[5], row[7], width[2], height[1] , "VertCol: Select colour gradient image") |
---|
508 | vcolours = Toggle("Enable 'VertCol' Gradient",No_Evt, col[2], row[8], width[5], height[1], vcolours.val, "VertCol: Enable VertexColours gradient ( Set Window DrawMode 'Textured', and set Material 'VCol Paint' on! )") |
---|
509 | if vcolours.val !=0: |
---|
510 | vcolGradRow = Number("Select Row:", Btn_Evt, col[2], row[9], width[2], height[1], vcolGradRow.val, 0, 1024 , "VertCol: Select row of pixels") |
---|
511 | gradScale = Number("Scale:", Btn_Evt, col[5], row[9], width[2], height[1], gradScale.val, 0.01, 10.0, "VertCol: Scale gradient") |
---|
512 | |
---|
513 | |
---|
514 | ###--------------------------------------------------------------------------- |
---|
515 | ###-------------------------------------------------------------------------- |
---|
516 | ## Draw G.U.I. ------------------------------------------------------------- |
---|
517 | #-------------------------------------------------------------------------- |
---|
518 | |
---|
519 | def drawgui(): |
---|
520 | global guitabs |
---|
521 | global FullScreen, AutoUpd, RandMod, RSeed |
---|
522 | |
---|
523 | glClearColor(background[0],background[1],background[2],background[3]) |
---|
524 | glClear(GL_COLOR_BUFFER_BIT) |
---|
525 | scissorbox=Buffer(GL_FLOAT,4) |
---|
526 | glGetFloatv(GL_SCISSOR_BOX,scissorbox) |
---|
527 | scissbleft=int(scissorbox[0]) |
---|
528 | scissbbase=int(scissorbox[1]) |
---|
529 | scissbwidth=int(scissorbox[2]) |
---|
530 | scissbheight=int(scissorbox[3]) |
---|
531 | xstart = 5 |
---|
532 | ystart = 5 |
---|
533 | xgap = 5 |
---|
534 | ygap = 5 |
---|
535 | if FullScreen.val==1: |
---|
536 | guiwidth = scissbwidth-10 |
---|
537 | guiheight = scissbheight-25 |
---|
538 | if guiwidth < size_x/2: |
---|
539 | guiwidth = size_x/2 |
---|
540 | if guiheight < size_y/2: |
---|
541 | guiheight = size_y/2 |
---|
542 | else: |
---|
543 | guiwidth = size_x |
---|
544 | guiheight = size_y |
---|
545 | col,row = [],[] |
---|
546 | xpart = ( ( guiwidth-xstart ) / columns ) |
---|
547 | ypart = ( ( guiheight-ystart ) / rows ) |
---|
548 | width = [] |
---|
549 | for c in range( columns ): |
---|
550 | col.append( xgap + xpart * c + xstart ) |
---|
551 | width.append( xpart*(c+1)-xgap ) |
---|
552 | height = [ (ypart-ygap)/2 , ypart-ygap, (ypart*3-ygap)/2, ypart*2-ygap, (ypart*5-ygap)/2 ] |
---|
553 | for r in range( rows ): |
---|
554 | row.append( ygap + ypart * r + ystart ) |
---|
555 | row.reverse() |
---|
556 | |
---|
557 | ###------------------------- |
---|
558 | ## Draw: |
---|
559 | draw_BackPanel( 'A.N.T. Landscape 1.04a', xstart, ystart, guiwidth, guiheight + ygap, lightgrey ) |
---|
560 | FullScreen = Toggle("", Scrn_Evt, guiwidth-32, guiheight+ygap+3, 15, 15, FullScreen.val ,"FullScreen" ) |
---|
561 | PushButton( "X", End_Evt, guiwidth-16, guiheight+ygap+3, 15, 15, "Exit" ) |
---|
562 | |
---|
563 | guitabs[0] = Toggle("Mesh", gt0_Evt, col[0], row[0], width[1], height[1], guitabs[0].val ,"Mesh settings" ) |
---|
564 | guitabs[1] = Toggle("Noise", gt1_Evt, col[2], row[0], width[1], height[1], guitabs[1].val ,"Noise settings" ) |
---|
565 | guitabs[2] = Toggle("Effect", gt2_Evt, col[4], row[0], width[1], height[1], guitabs[2].val ,"Add Effect" ) |
---|
566 | guitabs[3] = Toggle("Height", gt3_Evt, col[6], row[0], width[1], height[1], guitabs[3].val ,"Height Filter" ) |
---|
567 | guitabs[4] = Toggle("Options", gt4_Evt, col[8], row[0], width[1], height[1], guitabs[4].val ,"Options" ) |
---|
568 | |
---|
569 | if guitabs[0].val !=0: |
---|
570 | MeshButtons( col, row, width, height ) |
---|
571 | elif guitabs[1].val !=0: |
---|
572 | NoiseButtons( col, row, width, height ) |
---|
573 | elif guitabs[2].val !=0: |
---|
574 | EffectButtons( col, row, width, height ) |
---|
575 | elif guitabs[3].val !=0: |
---|
576 | FilterButtons( col, row, width, height ) |
---|
577 | elif guitabs[4].val !=0: |
---|
578 | OptionButtons( col, row, width, height ) |
---|
579 | else: |
---|
580 | funnycol = [ randnum(0.0,1.0), randnum(0.0,1.0), randnum(0.0,1.0) ] |
---|
581 | funnypos = int( randnum(1,11) ) |
---|
582 | draw_Text( ( col[0]+10, row[ funnypos ] ), 'Another Noise Tool "Landscape" v.1.04 May/2006', funnycol, 1 ) |
---|
583 | |
---|
584 | AutoUpd = Toggle("Auto", No_Evt, col[3], row[12], width[1], height[2], AutoUpd.val ,"Automatic update" ) |
---|
585 | PushButton("Generate", Upd_Evt, col[5], row[12], width[4], height[2] , "Generate / Update Mesh. ( KEY: SPACE )") |
---|
586 | if RandMod.val in [1,2]: |
---|
587 | PushButton("Randomise", Rndm_Evt, col[0], row[12], width[2], height[2] , "Randomise Noise ( KEY: R )") |
---|
588 | else: |
---|
589 | RSeed = Number("Seed: ", Rndm_Evt, col[0], row[12], width[2], height[2], RSeed.val, 0, 255 , "Random Seed: If seed = 0, the current time will be used as seed." ) |
---|
590 | |
---|
591 | |
---|
592 | ###--------------------------------------------------------------------------- |
---|
593 | ###--------------------------------------------------------------------------- |
---|
594 | ## Events: |
---|
595 | def events(evt, val): |
---|
596 | global PreView |
---|
597 | |
---|
598 | if (evt == QKEY and not val): |
---|
599 | Exit() |
---|
600 | |
---|
601 | if (evt == SPACEKEY and not val): |
---|
602 | do_it() |
---|
603 | if (evt in [ RKEY ] and not val): |
---|
604 | if AutoUpd.val == 0: |
---|
605 | randomiseNoise() |
---|
606 | Draw() |
---|
607 | elif AutoUpd.val == 1: |
---|
608 | do_it_random() |
---|
609 | if PreView[0].val == 1: |
---|
610 | if (evt in [ VKEY, RKEY ] and not val): |
---|
611 | do_it_preview() |
---|
612 | |
---|
613 | ###--------------------------------------------------------------------------- |
---|
614 | ## Button events: |
---|
615 | def bevents(evt): |
---|
616 | global effect_image, colgrad_image, PreView |
---|
617 | global Filter_Mode, Ipo_Filter_Ctrl, iponame, thiscurve, selectedcurve |
---|
618 | |
---|
619 | if (evt == End_Evt ): |
---|
620 | name = "OK ?%t|Reset %x1|Quit %x2" |
---|
621 | result = Blender.Draw.PupMenu(name) |
---|
622 | if result==1: |
---|
623 | Set_ReSet_Values() |
---|
624 | Draw() |
---|
625 | if result==2: |
---|
626 | Exit() |
---|
627 | |
---|
628 | if (evt in [No_Evt, Scrn_Evt] ): |
---|
629 | Draw() |
---|
630 | |
---|
631 | if (evt == Upd_Evt ): |
---|
632 | do_it() |
---|
633 | |
---|
634 | if AutoUpd.val == 1: |
---|
635 | if (evt == Btn_Evt ): |
---|
636 | do_it() |
---|
637 | elif (evt == Rndm_Evt ): |
---|
638 | do_it_random() |
---|
639 | |
---|
640 | if AutoUpd.val == 0: |
---|
641 | if (evt == Rndm_Evt ): |
---|
642 | randomiseNoise() |
---|
643 | Draw() |
---|
644 | elif (evt == Btn_Evt ): |
---|
645 | Draw() |
---|
646 | |
---|
647 | if PreView[0].val != 0: |
---|
648 | if (evt in [ Im_Evt, Btn_Evt, Rndm_Evt ] ): |
---|
649 | do_it_preview() |
---|
650 | |
---|
651 | if (evt == gt0_Evt ): |
---|
652 | if guitabs[0].val == 1: |
---|
653 | guitabs[1].val = ( 0 ) |
---|
654 | guitabs[2].val = ( 0 ) |
---|
655 | guitabs[3].val = ( 0 ) |
---|
656 | guitabs[4].val = ( 0 ) |
---|
657 | Draw() |
---|
658 | if (evt == gt1_Evt ): |
---|
659 | if guitabs[1].val == 1: |
---|
660 | guitabs[0].val = ( 0 ) |
---|
661 | guitabs[2].val = ( 0 ) |
---|
662 | guitabs[3].val = ( 0 ) |
---|
663 | guitabs[4].val = ( 0 ) |
---|
664 | Draw() |
---|
665 | if (evt == gt2_Evt ): |
---|
666 | if guitabs[2].val == 1: |
---|
667 | guitabs[0].val = ( 0 ) |
---|
668 | guitabs[1].val = ( 0 ) |
---|
669 | guitabs[3].val = ( 0 ) |
---|
670 | guitabs[4].val = ( 0 ) |
---|
671 | Draw() |
---|
672 | if (evt == gt3_Evt ): |
---|
673 | if guitabs[3].val == 1: |
---|
674 | guitabs[0].val = ( 0 ) |
---|
675 | guitabs[1].val = ( 0 ) |
---|
676 | guitabs[2].val = ( 0 ) |
---|
677 | guitabs[4].val = ( 0 ) |
---|
678 | Draw() |
---|
679 | if (evt == gt4_Evt ): |
---|
680 | if guitabs[4].val == 1: |
---|
681 | guitabs[0].val = ( 0 ) |
---|
682 | guitabs[1].val = ( 0 ) |
---|
683 | guitabs[2].val = ( 0 ) |
---|
684 | guitabs[3].val = ( 0 ) |
---|
685 | Draw() |
---|
686 | |
---|
687 | ###--------------------------------------------------------- |
---|
688 | ## get IPOCurve to use as Filter: |
---|
689 | if Filter_Mode.val == 2: |
---|
690 | try: |
---|
691 | ipoblockname = Ipo.Get( Ipo_Filter_Ctrl[0].val ) |
---|
692 | thiscurve = ipoblockname.getCurves() |
---|
693 | selectedcurve = thiscurve[ Ipo_Filter_Ctrl[1].val ] |
---|
694 | except: |
---|
695 | pass |
---|
696 | ###--------------------------------------------------------- |
---|
697 | ## Effect and Gradient Image Load/Select: |
---|
698 | if (evt == Load_Evt ): |
---|
699 | Blender.Window.FileSelector ( load_image, 'LOAD IMAGE') |
---|
700 | if (evt == Sel_Evt ): |
---|
701 | try: |
---|
702 | effect_image = Image_Menu() |
---|
703 | except: |
---|
704 | pass |
---|
705 | Draw() |
---|
706 | if (evt == Grad_Sel_Evt ): |
---|
707 | try: |
---|
708 | colgrad_image = Image_Menu() |
---|
709 | except: |
---|
710 | pass |
---|
711 | Draw() |
---|
712 | |
---|
713 | ###------------------------------------------------------------------------------------- |
---|
714 | ### Functions: |
---|
715 | ###------------------------------------------------------------------------------------- |
---|
716 | |
---|
717 | ## Load Image: |
---|
718 | def load_image( ImageFileName ): |
---|
719 | Image.Load( ImageFileName ) |
---|
720 | |
---|
721 | ## Select Image Menu: |
---|
722 | def Image_Menu(): |
---|
723 | try: |
---|
724 | names=[] |
---|
725 | imagelist = Image.Get() |
---|
726 | imagelist.reverse() |
---|
727 | for numbers, obnames in enumerate( imagelist ): |
---|
728 | n = obnames.getName() |
---|
729 | names.append( n ) |
---|
730 | imlistText = string.join( [ '|' + str(names[key]) + '%x' + str(key) for key in range(numbers+1) ], '' ) |
---|
731 | image_menu = Blender.Draw.PupMenu( "Images: %t" + imlistText ) |
---|
732 | if image_menu == -1: |
---|
733 | return '' |
---|
734 | return imagelist[ image_menu ].getName() |
---|
735 | except: |
---|
736 | return 'No image found!' |
---|
737 | |
---|
738 | |
---|
739 | |
---|
740 | #*# Get Image Pixels: |
---|
741 | def Image_Func( x,y ): |
---|
742 | try: |
---|
743 | pic = Image.Get( effect_image ) |
---|
744 | except: |
---|
745 | return 0.0 |
---|
746 | w, h = pic.getSize() |
---|
747 | x, y = x,-y |
---|
748 | x = int(w * ((x + 1.0) % 2.0) / 2.0) |
---|
749 | y = int((h-1) - h * ((y + 1.0) % 2.0) / 2.0) |
---|
750 | c = pic.getPixelF( x,y ) |
---|
751 | return ( c[0] + c[1] + c[2] ) / 3. |
---|
752 | |
---|
753 | |
---|
754 | |
---|
755 | ## Pixel color gradient: |
---|
756 | def pixlGrad( hght, pixelrow, gradScale ): |
---|
757 | gradimage = Image.Get( colgrad_image ) |
---|
758 | imgsiz = gradimage.getSize() |
---|
759 | imgsizhold = imgsiz[0]-1 |
---|
760 | pxl=[] |
---|
761 | imgsiz[0] = int( imgsiz[0] * gradScale ) |
---|
762 | if pixelrow >= imgsiz[1]: |
---|
763 | pixelrow = 0 |
---|
764 | for i in range( imgsiz[0]-1 ): |
---|
765 | hght = int( (imgsiz[0]-1) * hght ) |
---|
766 | if hght < 0: |
---|
767 | hght = 0 |
---|
768 | if hght > imgsizhold: |
---|
769 | hght = imgsizhold |
---|
770 | grad = gradimage.getPixelF( hght, imgsiz[1]-1-pixelrow ) |
---|
771 | r,g,b = grad[0], grad[1], grad[2] |
---|
772 | pxl.append( (r,g,b) ) |
---|
773 | return NMesh.Col(int(pxl[i][0]*255),int(pxl[i][1]*255),int(pxl[i][2]*255)) , (pxl[i][0],pxl[i][1],pxl[i][2]) |
---|
774 | |
---|
775 | ##------------------------------------------------------------------------------------- |
---|
776 | |
---|
777 | # Transpose noise coords: |
---|
778 | def Trans((x,y,z), size, loc ): |
---|
779 | x = ( x / size[1] / size[0] + loc[0] ) |
---|
780 | y = ( y / size[2] / size[0] + loc[1] ) |
---|
781 | z = 0.0 |
---|
782 | return x,y,z |
---|
783 | |
---|
784 | # Transpose effect coords: |
---|
785 | def Trans_Effect((x,y,z), size, loc ): |
---|
786 | x = ( x * size[1] * size[0] + loc[0] ) |
---|
787 | y = ( y * size[2] * size[0] + loc[1] ) |
---|
788 | z = 0.0 |
---|
789 | return x,y,z |
---|
790 | |
---|
791 | # Height scale: |
---|
792 | def HeightScale( input, iscale, offset, invert ): |
---|
793 | if invert !=0: |
---|
794 | return (1.0-input) * iscale + offset |
---|
795 | else: |
---|
796 | return input * iscale + offset |
---|
797 | |
---|
798 | # dist. |
---|
799 | def Dist(x,y): |
---|
800 | return sqrt( (x*x)+(y*y) ) |
---|
801 | |
---|
802 | ##----------------------------------- |
---|
803 | # bias types: |
---|
804 | def no_bias(a): |
---|
805 | return a |
---|
806 | def sin_bias(a): |
---|
807 | return 0.5 + 0.5 * sin(a) |
---|
808 | def cos_bias(a): |
---|
809 | return 0.5 + 0.5 * cos(a) |
---|
810 | def tri_bias(a): |
---|
811 | b = 2 * phi |
---|
812 | a = 1 - 2 * abs(floor((a * (1/b))+0.5) - (a*(1/b))) |
---|
813 | return a |
---|
814 | def saw_bias(a): |
---|
815 | b = 2 * phi |
---|
816 | n = int(a/b) |
---|
817 | a -= n * b |
---|
818 | if a < 0: |
---|
819 | a += b |
---|
820 | return a / b |
---|
821 | |
---|
822 | # sharpen types: |
---|
823 | def soft(a): |
---|
824 | return a |
---|
825 | def sharp(a): |
---|
826 | return a**0.5 |
---|
827 | def sharper(a): |
---|
828 | return sharp(sharp(a)) |
---|
829 | |
---|
830 | Bias_Types = [ sin_bias, cos_bias, tri_bias, saw_bias, no_bias ] |
---|
831 | Sharp_Types = [ soft, sharp, sharper ] |
---|
832 | |
---|
833 | ##----------------------------------- |
---|
834 | # Mix modes |
---|
835 | |
---|
836 | def maximum( a, b ): |
---|
837 | if ( a > b ): b = a |
---|
838 | return b |
---|
839 | def minimum( a, b ): |
---|
840 | if ( a < b ): b = a |
---|
841 | return b |
---|
842 | |
---|
843 | def Mix_Modes( (i,j),(x,y,z) , a, b, mixfactor, mode ): |
---|
844 | a = a * ( 1.0 + mixfactor ) |
---|
845 | b = b * ( 1.0 - mixfactor ) |
---|
846 | if mode == 0: return ( a ) #0 a |
---|
847 | elif mode == 1: return ( a*(1.0-0.5) + b*0.5 ) #1 mix |
---|
848 | elif mode == 2: return ( a + b ) #2 add |
---|
849 | elif mode == 3: return ( a - b ) #3 sub. |
---|
850 | elif mode == 4: return ( a * b ) #4 mult. |
---|
851 | elif mode == 5: return (abs( a - b )) #5 abs diff. |
---|
852 | elif mode == 6: return 1.0-((1.0-a)*(1.0-b)/1.0) #6 screen |
---|
853 | elif mode == 7: return ( a + b ) % 1.0 #7 addmodulo |
---|
854 | elif mode == 8: return minimum( a, b ) #8 min. |
---|
855 | elif mode == 9: return maximum( a, b ) #9 max. |
---|
856 | elif mode == 10: #10 warp: effect |
---|
857 | noise = mixfactor * Noise_Function(x,y,z) |
---|
858 | return Effects( (i,j),(x+noise,y+noise,z) ) |
---|
859 | elif mode == 11: #11 warp: noise |
---|
860 | effect = mixfactor * Effects( (i,j),(x,y,z) ) |
---|
861 | return Noise_Function( x+effect, y+effect, z ) |
---|
862 | else: return b |
---|
863 | |
---|
864 | ###---------------------------------------------------------------------- |
---|
865 | # Effect functions: |
---|
866 | |
---|
867 | # Effect_Basis_Function: |
---|
868 | def Effect_Basis_Function((x,y), type, bias ): |
---|
869 | |
---|
870 | iscale = 1.0 |
---|
871 | offset = 0.0 |
---|
872 | ## gradient: |
---|
873 | if type == 0: |
---|
874 | effect = offset + iscale * ( Bias_Types[ bias ]( x + y ) ) |
---|
875 | ## waves / bumps: |
---|
876 | if type == 1: |
---|
877 | effect = offset + iscale * 0.5 * ( Bias_Types[ bias ]( x*phi ) + Bias_Types[ bias ]( y*phi ) ) |
---|
878 | ## zigzag: |
---|
879 | if type == 2: |
---|
880 | effect = offset + iscale * Bias_Types[ bias ]( offset + iscale * sin( x*phi + sin( y*phi ) ) ) |
---|
881 | ## wavy: |
---|
882 | if type == 3: |
---|
883 | effect = offset + iscale * ( Bias_Types[ bias ]( cos( x ) + sin( y ) + cos( x*2+y*2 ) - sin( -x*4+y*4) ) ) |
---|
884 | ## sine bump: |
---|
885 | if type == 4: |
---|
886 | effect = offset + iscale * 1-Bias_Types[ bias ](( sin( x*phi ) + sin( y*phi ) )) |
---|
887 | ## dots: |
---|
888 | if type == 5: |
---|
889 | effect = offset + iscale * ( Bias_Types[ bias ](x*phi*2) * Bias_Types[ bias ](y*phi*2) )-0.5 |
---|
890 | ## rings / dome: |
---|
891 | if type == 6: |
---|
892 | effect = offset + iscale * ( Bias_Types[ bias ]( 1.0-(x*x+y*y) ) ) |
---|
893 | ## spiral: |
---|
894 | if type == 7: |
---|
895 | effect = offset + iscale * Bias_Types[ bias ](( x*sin( x*x+y*y ) + y*cos( x*x+y*y ) ))*0.5 |
---|
896 | ## square / piramide: |
---|
897 | if type == 8: |
---|
898 | effect = offset + iscale * Bias_Types[ bias ](1.0-sqrt( (x*x)**10 + (y*y)**10 )**0.1) |
---|
899 | ## blocks: |
---|
900 | if type == 9: |
---|
901 | effect = ( 0.5-max( Bias_Types[ bias ](x*phi) , Bias_Types[ bias ](y*phi) )) |
---|
902 | if effect > 0.0: effect = 1.0 |
---|
903 | effect = offset + iscale * effect |
---|
904 | ## grid: |
---|
905 | if type == 10: |
---|
906 | effect = ( 0.025-min( Bias_Types[ bias ](x*phi) , Bias_Types[ bias ](y*phi) )) |
---|
907 | if effect > 0.0: effect = 1.0 |
---|
908 | effect = offset + iscale * effect |
---|
909 | ## tech: |
---|
910 | if type == 11: |
---|
911 | a = ( max( Bias_Types[ bias ](x*pi) , Bias_Types[ bias ](y*pi) )) |
---|
912 | b = ( max( Bias_Types[ bias ](x*pi*2+2) , Bias_Types[ bias ](y*pi*2+2) )) |
---|
913 | effect = ( min( Bias_Types[ bias ](a) , Bias_Types[ bias ](b) ))*3.0-2.0 |
---|
914 | if effect > 0.5: effect = 1.0 |
---|
915 | effect = offset + iscale * effect |
---|
916 | |
---|
917 | ## crackle: |
---|
918 | if type == 12: |
---|
919 | t = turbulence(( x, y, 0 ), 6, 0, 0 ) * 0.25 |
---|
920 | effect = vlNoise(( x, y, t ), 0.25, 0, 8 ) |
---|
921 | if effect > 0.5: effect = 0.5 |
---|
922 | effect = offset + iscale * ( effect ) |
---|
923 | ## sparse cracks noise: |
---|
924 | if type == 13: |
---|
925 | effect = 2.5 * abs( noise((x*0.5,y*0.5, 0 ), 1 ) )-0.1 |
---|
926 | if effect > 0.25: effect = 0.25 |
---|
927 | effect = offset + iscale * ( effect * 2.5 ) |
---|
928 | ## shattered rock noise: |
---|
929 | if type == 14: |
---|
930 | effect = 0.5 + noise((x,y,0), 7 ) |
---|
931 | if effect > 0.75: effect = 0.75 |
---|
932 | effect = offset + iscale * effect |
---|
933 | ## lunar noise: |
---|
934 | if type == 15: |
---|
935 | effect = 0.25 + 1.5 * voronoi(( x+2, y+2, 0 ), 1 )[0][0] |
---|
936 | if effect > 0.5: effect = 0.5 |
---|
937 | effect = offset + iscale * ( effect * 2.0 ) |
---|
938 | ## cosine noise: |
---|
939 | if type == 16: |
---|
940 | effect = cos( 5*noise(( x, y, 0 ), 0 ) ) |
---|
941 | effect = offset + iscale * ( effect*0.5 ) |
---|
942 | ## spikey noise: |
---|
943 | if type == 17: |
---|
944 | n = 0.5 + 0.5 * turbulence(( x*5, y*5, 0 ), 8, 0, 0 ) |
---|
945 | effect = ( ( n*n )**5 ) |
---|
946 | effect = offset + iscale * effect |
---|
947 | ## stone noise: |
---|
948 | if type == 18: |
---|
949 | effect = offset + iscale *( noise((x*2,y*2, 0 ), 0 ) * 1.5 - 0.75) |
---|
950 | ## Flat Turb: |
---|
951 | if type == 19: |
---|
952 | t = turbulence(( x, y, 0 ), 6, 0, 0 ) |
---|
953 | effect = t*2.0 |
---|
954 | if effect > 0.25: effect = 0.25 |
---|
955 | effect = offset + iscale * ( effect ) |
---|
956 | ## Flat Voroni: |
---|
957 | if type == 20: |
---|
958 | t = 1-noise(( x, y, 0 ), 3 ) |
---|
959 | effect = t*2-1.75 |
---|
960 | if effect > 0.25: effect = 0.25 |
---|
961 | effect = offset + iscale * ( effect ) |
---|
962 | |
---|
963 | if effect < 0.0: effect = 0.0 |
---|
964 | return effect |
---|
965 | |
---|
966 | # fractalize Effect_Basis_Function: ------------------------------ |
---|
967 | def Effect_Function((x,y), type,bias, turb, depth,frequency,amplitude ): |
---|
968 | |
---|
969 | ## turbulence: |
---|
970 | if turb != 0.0: |
---|
971 | t = turb * ( 0.5 + 0.5 * turbulence(( x, y, 0 ), 6, 0, 0 )) |
---|
972 | x = x + t |
---|
973 | y = y + t |
---|
974 | |
---|
975 | result = Effect_Basis_Function((x,y), type, bias ) |
---|
976 | ## fractalize: |
---|
977 | if depth != 0: |
---|
978 | i=0 |
---|
979 | for i in range( depth ): |
---|
980 | i+=1 |
---|
981 | x *= frequency |
---|
982 | y *= frequency |
---|
983 | amplitude = amplitude / i |
---|
984 | result += Effect_Basis_Function( (x,y), type, bias ) * amplitude |
---|
985 | |
---|
986 | return result |
---|
987 | |
---|
988 | |
---|
989 | ###-------------------------------------------------- |
---|
990 | ## Effect Selector: |
---|
991 | def Effects( (i,j),(x,y,z) ): |
---|
992 | global Effect_Type, Effect_Ctrl, twister_amount, iScale, Offset, Invert |
---|
993 | global Quality, NSize, Lx, Ly, Lz, Sx, Sy, Sz, marbleTwo, turbTwo, vlnoiTwo, Basis |
---|
994 | |
---|
995 | x,y,z = Trans_Effect((x,y,z),( NSize[1].val, Sx[1].val, Sy[1].val, 0 ),( Lx[1].val, Ly[1].val, 0 ) ) |
---|
996 | |
---|
997 | basis = Basis[1].val |
---|
998 | if basis == 9: basis = 14 |
---|
999 | |
---|
1000 | if Effect_Ctrl[0].val == 1: |
---|
1001 | try: |
---|
1002 | effect = Image_Func( x,y ) |
---|
1003 | except: |
---|
1004 | effect = 0.0 |
---|
1005 | |
---|
1006 | elif Effect_Ctrl[0].val == 2: |
---|
1007 | effect = 0.5+0.5*turbulence(( x,y,z ),turbTwo[0].val, turbTwo[1].val, basis, turbTwo[2].val, turbTwo[3].val ) |
---|
1008 | elif Effect_Ctrl[0].val == 3: |
---|
1009 | effect = 0.5+0.5*vlNoise(( x,y,z ),vlnoiTwo[0].val, vlnoiTwo[1].val, basis ) |
---|
1010 | elif Effect_Ctrl[0].val == 4: |
---|
1011 | effect = 0.5*marbleNoise((x,y,z), marbleTwo[0].val, basis, marbleTwo[2].val, marbleTwo[3].val, marbleTwo[4].val, marbleTwo[5].val ) |
---|
1012 | else: |
---|
1013 | effect = Effect_Function((x,y), Effect_Ctrl[0].val-5, Effect_Ctrl[3].val, Effect_Ctrl[4].val, Effect_Ctrl[5].val, Effect_Ctrl[6].val, Effect_Ctrl[7].val ) |
---|
1014 | |
---|
1015 | effect = HeightScale( effect, iScale[1].val , Offset[1].val, Invert[1].val ) |
---|
1016 | |
---|
1017 | return effect |
---|
1018 | |
---|
1019 | |
---|
1020 | |
---|
1021 | ###---------------------------------------------------------------------- |
---|
1022 | # Noise: |
---|
1023 | ##----------------------------------- |
---|
1024 | |
---|
1025 | ## voronoi_turbulence: |
---|
1026 | def voroTurbMode((x,y,z), voro, mode ): |
---|
1027 | if mode == 0: # soft |
---|
1028 | return voronoi(( x,y,z ),voro[0], voro[1] )[0][0] |
---|
1029 | if mode == 1: # hard |
---|
1030 | return ( abs( 0.5-voronoi(( x,y,z ),voro[0], voro[1] )[0][0] ) )+0.5 |
---|
1031 | def voronoi_turbulence((x,y,z), voro, tur ): |
---|
1032 | result = voroTurbMode((x,y,z), voro, tur[1] ) |
---|
1033 | depth = tur[0] |
---|
1034 | amp = tur[2] |
---|
1035 | freq = tur[3] |
---|
1036 | i=0 |
---|
1037 | for i in range( depth ): |
---|
1038 | i+=1 |
---|
1039 | result += voroTurbMode( ( x*(freq*i), y*(freq*i), z ), voro, tur[1] )* ( amp*0.5/i ) |
---|
1040 | return (result*4.0-2.0) |
---|
1041 | |
---|
1042 | ## DistortedNoise / vlNoise_turbulence: |
---|
1043 | def vlnTurbMode((x,y,z), vlno, basis, mode ): |
---|
1044 | if mode == 0: # soft |
---|
1045 | return vlNoise(( x,y,z ),vlno[0], vlno[1], basis ) |
---|
1046 | if mode == 1: # hard |
---|
1047 | return ( abs( -vlNoise(( x,y,z ),vlno[0], vlno[1], basis ) ) ) |
---|
1048 | def vlNoise_turbulence((x,y,z), vlno, tur, basis ): |
---|
1049 | result = vlnTurbMode((x,y,z), vlno, basis, tur[1] ) |
---|
1050 | depth = tur[0] |
---|
1051 | amp = tur[2] |
---|
1052 | freq = tur[3] |
---|
1053 | i=0 |
---|
1054 | for i in range( depth ): |
---|
1055 | i+=1 |
---|
1056 | result += vlnTurbMode( ( x*(freq*i), y*(freq*i), z ), vlno, basis, tur[1] ) * ( amp*0.5/i ) |
---|
1057 | return result*2.0+0.5 |
---|
1058 | |
---|
1059 | ## marbleNoise: |
---|
1060 | def marbleNoise( (x,y,z), depth, basis, turb, bias, sharpnes, rescale ): |
---|
1061 | m = ( x * rescale + y * rescale + z ) * 5 |
---|
1062 | height = m + turb * turbulence( ( x ,y ,z ), depth, 0, basis, 0.5, 2.0 ) |
---|
1063 | height = Bias_Types[ bias ]( height ) |
---|
1064 | if bias != 4: |
---|
1065 | height = Sharp_Types[ sharpnes ]( height ) |
---|
1066 | return height*2.0 |
---|
1067 | |
---|
1068 | ## lava_multiFractal: |
---|
1069 | def lava_multiFractal( ( x,y,z ),Ha, La, Oc, distort, Basis ): |
---|
1070 | m = multiFractal( ( x,y,z ), Ha, La, Oc, Basis) |
---|
1071 | d = m * distort |
---|
1072 | m2 = 0.5 * multiFractal( ( x+d,y+d,d*0.5 ), Ha, La, Oc, Basis) |
---|
1073 | return (m * m2)**0.5 |
---|
1074 | |
---|
1075 | ## slopey_noise: |
---|
1076 | def slopey_noise((x,y,z), H, lacunarity, octaves, distort, basis ): |
---|
1077 | turb = fBm((x,y,z), H, lacunarity, octaves, 2 ) * 0.5 |
---|
1078 | map = 0.5 + noise( ( x+turb, y+turb, z ), basis ) |
---|
1079 | result = map + turb * distort |
---|
1080 | return result |
---|
1081 | |
---|
1082 | ## duo_multiFractal: |
---|
1083 | def double_multiFractal((x,y,z), H, lacunarity, octaves, offset, gain, basis ): |
---|
1084 | n1 = multiFractal( (x*1.5+1,y*1.5+1,z), 1.0, 1.0, 1.0, basis ) * offset |
---|
1085 | n2 = multiFractal( (x-1,y-1,z), H, lacunarity, octaves, basis ) * gain |
---|
1086 | result = ( n1*n1 + n2*n2 )*0.5 |
---|
1087 | return result |
---|
1088 | |
---|
1089 | ## distorted_heteroTerrain: |
---|
1090 | def distorted_heteroTerrain((x,y,z), H, lacunarity, octaves, offset, distort, basis ): |
---|
1091 | h1 = ( heteroTerrain((x,y,z), 1.0, 2.0, 1.0, 1.0, basis ) * 0.5 ) |
---|
1092 | h2 = ( heteroTerrain(( x, y, h1*distort ), H, lacunarity, octaves, offset, basis ) * 0.25 ) |
---|
1093 | result = ( h1*h1 + h2*h2 ) |
---|
1094 | return result |
---|
1095 | |
---|
1096 | ## SlickRock: |
---|
1097 | def SlickRock((x,y,z), H, lacunarity, octaves, offset, gain, basis ): |
---|
1098 | n = multiFractal( (x,y,z), 1.0, 2.0, 1.0, basis ) |
---|
1099 | r = ridgedMFractal((x,y,n*0.5), H, lacunarity, octaves, offset, gain, basis )*0.5 |
---|
1100 | return n+(n*r) |
---|
1101 | |
---|
1102 | ## terra_turbulence: |
---|
1103 | def terra_turbulence((x,y,z), depth, hard, basis, amp, freq ): |
---|
1104 | t2 = turbulence( ( x, y, z ), depth, hard , basis, amp, freq ) |
---|
1105 | return (t2*t2*t2)+0.5 |
---|
1106 | |
---|
1107 | ## rocky_fBm: |
---|
1108 | def rocky_fBm((x,y,z), H, lacunarity, octaves, basis ): |
---|
1109 | turb = fBm((x,y,z), H, lacunarity, octaves, 2 ) * 0.25 |
---|
1110 | coords = ( x+turb, y+turb, z ) |
---|
1111 | map = noise( coords, 7 ) |
---|
1112 | result = map + fBm( coords, H, lacunarity, octaves, basis ) + 1.0 |
---|
1113 | return result |
---|
1114 | |
---|
1115 | ####---------------------------------------. |
---|
1116 | ### StatsByAlt, double terrain basis mode: |
---|
1117 | def TerrainBasisMode((x,y,z), basis, mode ): |
---|
1118 | if mode == 0: # noise |
---|
1119 | return noise((x,y,z),basis) |
---|
1120 | if mode == 1: # noise ridged |
---|
1121 | return ( 1.0-abs( noise((x,y,z),basis) ) )-0.5 |
---|
1122 | if mode == 2: # vlNoise |
---|
1123 | return vlNoise((x,y,z), 1.0, 0, basis ) |
---|
1124 | else: # vlNoise ridged |
---|
1125 | return ( 1.0-abs( vlNoise((x,y,z), 1.0, 0, basis ) ) )-0.5 |
---|
1126 | |
---|
1127 | #### StatsByAlt terrain: |
---|
1128 | def StatsByAltTerrain((x,y,z), exp, lacu, octs, offset, amp, basis, mode ): |
---|
1129 | result = 0.5 * (offset + TerrainBasisMode((x,y,z), basis, mode ) ) |
---|
1130 | octs = int( octs ) |
---|
1131 | i = 0 |
---|
1132 | for i in range( 1, octs ): |
---|
1133 | i += 1 |
---|
1134 | result += result * amp * 0.5 * (offset + TerrainBasisMode((x,y,z), basis, mode ) ) |
---|
1135 | x *= lacu |
---|
1136 | y *= lacu |
---|
1137 | amp /= ( exp * 0.5 ) * i |
---|
1138 | return result |
---|
1139 | |
---|
1140 | ##### double terrain: |
---|
1141 | def doubleTerrain((x,y,z), exp, lacu, octs, offset, threshold, basis, mode ): |
---|
1142 | result = amp = freq = 1.0 |
---|
1143 | octs = int( octs ) |
---|
1144 | i = 1 |
---|
1145 | signal = result = 0.5 * (offset + TerrainBasisMode((x,y,z), basis, mode ) ) |
---|
1146 | for i in range( i, octs ): |
---|
1147 | i -= 1 |
---|
1148 | x = x * lacu |
---|
1149 | y = y * lacu |
---|
1150 | freq *= lacu |
---|
1151 | amp = pow( freq, -exp ) |
---|
1152 | if i < 1.0: amp *= i |
---|
1153 | weight = signal / threshold |
---|
1154 | if weight > 1.0: weight = 1.0 |
---|
1155 | if weight < 0.0: weigth = 0.0 |
---|
1156 | signal = weight * 0.5 * ( offset + TerrainBasisMode((x,y,z), basis, mode ) ) |
---|
1157 | result += amp * signal |
---|
1158 | return result * 2.0 |
---|
1159 | |
---|
1160 | ##------------------------------------------------------------ |
---|
1161 | # Noise Functions: |
---|
1162 | def Noise_Function(x,y,z): |
---|
1163 | global Basis, NType, musgr, vlnoi, voron, turbOne, marbleOne, tBasismod |
---|
1164 | global vlBasis, Distort, VFunc, VExp, VDep |
---|
1165 | global iScale, Offset, Invert, NSize, Lx, Ly, Sx, Sy |
---|
1166 | |
---|
1167 | x,y,z = Trans((x,y,z),( NSize[0].val, Sx[0].val, Sy[0].val, 0 ),( Lx[0].val, Ly[0].val, 0 ) ) |
---|
1168 | |
---|
1169 | basis = Basis[0].val |
---|
1170 | if basis == 9: basis = 14 |
---|
1171 | vbasis = vlnoi[0].val |
---|
1172 | if vbasis == 9: vbasis = 14 |
---|
1173 | |
---|
1174 | if NType.val == 0: z = multiFractal(( x,y,z ),musgr[0].val, musgr[1].val, musgr[2].val, basis ) |
---|
1175 | elif NType.val == 1: z = ridgedMFractal(( x,y,z ),musgr[0].val, musgr[1].val, musgr[2].val, musgr[3].val, musgr[4].val, basis ) |
---|
1176 | elif NType.val == 2: z = hybridMFractal(( x,y,z ),musgr[0].val, musgr[1].val, musgr[2].val, musgr[3].val, musgr[4].val, basis ) |
---|
1177 | elif NType.val == 3: z = heteroTerrain(( x,y,z ),musgr[0].val, musgr[1].val, musgr[2].val, musgr[3].val, basis )*0.5 |
---|
1178 | elif NType.val == 4: z = fBm(( x,y,z ),musgr[0].val, musgr[1].val, musgr[2].val, basis )+0.5 |
---|
1179 | elif NType.val == 5: z = turbulence(( x,y,z ),turbOne[0].val, turbOne[1].val, basis, turbOne[2].val, turbOne[3].val )*0.5+0.5 |
---|
1180 | elif NType.val == 6: z = voronoi_turbulence((x,y,z),(voron[0].val,voron[1].val),(turbOne[0].val,turbOne[1].val,turbOne[2].val,turbOne[3].val) )*0.5+0.5 |
---|
1181 | elif NType.val == 7: z = vlNoise_turbulence((x,y,z),(vlnoi[0].val,vlnoi[1].val), (turbOne[0].val,turbOne[1].val,turbOne[2].val,turbOne[3].val), basis )*0.5+0.5 |
---|
1182 | elif NType.val == 8: z = noise(( x,y,z ),basis )+0.5 |
---|
1183 | elif NType.val == 9: z = cellNoise(( x,y,z ))+0.5 |
---|
1184 | elif NType.val == 10: z = marbleNoise(( x,y,z), marbleOne[0].val, basis, marbleOne[2].val, marbleOne[3].val, marbleOne[4].val, marbleOne[5].val ) |
---|
1185 | elif NType.val == 11: z = lava_multiFractal(( x,y,z ), musgr[0].val, musgr[1].val, musgr[2].val, vlnoi[0].val, basis ) |
---|
1186 | elif NType.val == 12: z = slopey_noise(( x,y,z), musgr[0].val, musgr[1].val, musgr[2].val, vlnoi[0].val, basis )+0.5 |
---|
1187 | elif NType.val == 13: z = double_multiFractal(( x,y,z), musgr[0].val, musgr[1].val, musgr[2].val, musgr[3].val, musgr[4].val, basis ) |
---|
1188 | elif NType.val == 14: z = distorted_heteroTerrain((x,y,z), musgr[0].val, musgr[1].val, musgr[2].val, musgr[3].val, vlnoi[0].val, basis ) |
---|
1189 | elif NType.val == 15: z = SlickRock(( x,y,z), musgr[0].val, musgr[1].val, musgr[2].val, musgr[3].val, musgr[4].val, basis ) |
---|
1190 | elif NType.val == 16: z = terra_turbulence(( x,y,z), turbOne[0].val, turbOne[1].val, basis, turbOne[2].val, turbOne[3].val ) |
---|
1191 | elif NType.val == 17: z = rocky_fBm(( x,y,z ),musgr[0].val, musgr[1].val, musgr[2].val, basis ) |
---|
1192 | elif NType.val == 18: z = StatsByAltTerrain( (x,y,z), musgr[0].val, musgr[1].val, musgr[2].val, musgr[3].val, musgr[4].val*0.5, basis, tBasismod.val ) |
---|
1193 | elif NType.val == 19: z = doubleTerrain( (x,y,z), musgr[0].val, musgr[1].val, musgr[2].val, musgr[3].val, musgr[5].val, basis, tBasismod.val ) |
---|
1194 | else: z = 0.0 |
---|
1195 | return HeightScale( z, iScale[0].val , Offset[0].val, Invert[0].val ) |
---|
1196 | |
---|
1197 | |
---|
1198 | ##---------------------------------------------------------------------- |
---|
1199 | ##----------------------------------- |
---|
1200 | # Filter functions: |
---|
1201 | |
---|
1202 | # Filters: terrace / posterise / peaked / bias: |
---|
1203 | def Def_Filter((x,y,z), input, numb, type ): |
---|
1204 | if type == 0: |
---|
1205 | s = ( sin( input*numb*phi ) * ( 0.1/numb*phi ) ) |
---|
1206 | return ( input * (1.0-0.5) + s*0.5 ) * 2.0 |
---|
1207 | elif type == 1: |
---|
1208 | s = -abs( sin( input*(numb*0.5)*phi ) * ( 0.1/(numb*0.5)*phi ) ) |
---|
1209 | return ( input * (1.0-0.5) + s*0.5 ) * 2.0 |
---|
1210 | elif type == 2: |
---|
1211 | s = abs( sin( input*(numb*0.5)*phi ) * ( 0.1/(numb*0.5)*phi ) ) |
---|
1212 | return ( input * (1.0-0.5) + s*0.5 ) * 2.0 |
---|
1213 | elif type == 3: |
---|
1214 | numb = numb*0.5 |
---|
1215 | s = ( int( input*numb ) * 1.0/numb ) |
---|
1216 | return ( input * (1.0-0.5) + s*0.5 ) * 2.0 |
---|
1217 | elif type == 4: |
---|
1218 | numb = numb*0.5 |
---|
1219 | s = ( int( input*numb ) * 1.0/numb ) |
---|
1220 | return ( s ) * 2.0 |
---|
1221 | elif type == 5: |
---|
1222 | s = ( sin( input*(2*numb)*phi ) * ( 0.1/(2*numb)*phi ) ) |
---|
1223 | l = ( input * (1.0-0.5) + s*0.5 ) * 2.0 |
---|
1224 | p = ( ( l*numb*0.25 ) * ( l*numb*0.25 ) )**2 |
---|
1225 | return ( l * (1.0-0.5) + p*0.5 ) * 2.0 |
---|
1226 | elif type == 6: |
---|
1227 | return ( input*numb*0.25 )**4 |
---|
1228 | elif type == 7: |
---|
1229 | return 2.0-exp( 1.0-(input*numb/3.0) ) |
---|
1230 | elif type == 8: |
---|
1231 | return sin_bias( input*numb )*2.0 |
---|
1232 | elif type == 9: |
---|
1233 | return cos_bias( input*numb )*2.0 |
---|
1234 | elif type == 10: |
---|
1235 | return tri_bias( input*numb )*2.0 |
---|
1236 | else: |
---|
1237 | return saw_bias( input*numb )*2.0 |
---|
1238 | |
---|
1239 | # Filter: Clamp height |
---|
1240 | def Clamp_Max( height, max ): |
---|
1241 | if ( height > max ): height = max |
---|
1242 | return height |
---|
1243 | def Clamp_Min( height, min ): |
---|
1244 | if ( height < min ): height = min |
---|
1245 | return height |
---|
1246 | |
---|
1247 | # Filter: Edge falloff |
---|
1248 | def EdgeFalloff( (x,y,z), height, type ): |
---|
1249 | global Falloff, maketiles |
---|
1250 | |
---|
1251 | x = x / Falloff[1].val |
---|
1252 | y = y / Falloff[2].val |
---|
1253 | if maketiles[0].val !=0: |
---|
1254 | x = x / tile_rescale[ maketiles[1].val ] |
---|
1255 | y = y / tile_rescale[ maketiles[1].val ] |
---|
1256 | if Falloff[3].val != 0: |
---|
1257 | sealevel = Min.val*2.0/iScale[2].val |
---|
1258 | else: |
---|
1259 | sealevel = 0.0 |
---|
1260 | falltypes = ( 0, sqrt(x*x+y*y), sqrt((x*x)**2+(y*y)**2), sqrt((x*x)**10+(y*y)**10), sqrt(y*y), sqrt(x*x), abs(x-y), abs(x+y), ((x*x)**10+(y*y)**10)**0.1, ((x*x)+(y*y)) ) |
---|
1261 | dist = falltypes[ type ] |
---|
1262 | if Falloff[4].val != 0: |
---|
1263 | dist = 1.0 - dist |
---|
1264 | radius = 1.0 |
---|
1265 | height = height - sealevel |
---|
1266 | if( dist < radius ): |
---|
1267 | dist = dist / radius |
---|
1268 | dist = ( (dist) * (dist) * ( 3-2*(dist) ) ) |
---|
1269 | height = ( height - height * dist ) + sealevel |
---|
1270 | else: |
---|
1271 | height = sealevel |
---|
1272 | if Falloff[3].val != 0: |
---|
1273 | height = Clamp_Min( height, sealevel ) |
---|
1274 | else: |
---|
1275 | height = Clamp_Min( height, Min.val ) |
---|
1276 | |
---|
1277 | return height |
---|
1278 | |
---|
1279 | |
---|
1280 | #####-------------------------------------------------------------------------------------##### |
---|
1281 | ####-------------------------------------------------------------------------------------#### |
---|
1282 | ### Combine Functions: (get noise, Add effect, filter height and return result) ### |
---|
1283 | ##-------------------------------------------------------------------------------------## |
---|
1284 | |
---|
1285 | def Combine_Functions( (i,j),(x,y,z) ): |
---|
1286 | global Quality, Effect_Ctrl, Blend_Effect, Filter_Mode, Def_Filter_Ctrl, Ipo_Filter_Ctrl |
---|
1287 | global iScale, Offset, Invert, Min, Max, Falloff |
---|
1288 | |
---|
1289 | # get noise height: |
---|
1290 | height = Noise_Function(x,y,0.0) |
---|
1291 | |
---|
1292 | # mix noise with effect: |
---|
1293 | if Effect_Ctrl[0].val !=0: |
---|
1294 | height = Mix_Modes( (i,j),(x,y,z) , Effects( (i,j),(x,y,z) ), height, Effect_Ctrl[2].val, Effect_Ctrl[1].val ) |
---|
1295 | |
---|
1296 | # edge fallof: |
---|
1297 | if Falloff[0].val !=0: |
---|
1298 | height = EdgeFalloff( (x,y,z), height, Falloff[0].val ) |
---|
1299 | |
---|
1300 | # height filter |
---|
1301 | if Filter_Mode.val !=0: |
---|
1302 | # height Def_Filter (Terrace/peaked/bias): |
---|
1303 | if Filter_Mode.val ==1: |
---|
1304 | if Def_Filter_Ctrl[ 0 ].val != 12: |
---|
1305 | height = Def_Filter((x,y,z), height, Def_Filter_Ctrl[ 1 ].val, Def_Filter_Ctrl[ 0 ].val ) |
---|
1306 | |
---|
1307 | ## 'IPOCurve' height filter: |
---|
1308 | elif Filter_Mode.val ==2: |
---|
1309 | try: |
---|
1310 | height = selectedcurve.evaluate( 1 + ( height*Ipo_Filter_Ctrl[2].val/2 ) )*2.0/Ipo_Filter_Ctrl[3].val |
---|
1311 | except: |
---|
1312 | height = height |
---|
1313 | |
---|
1314 | # height scale: |
---|
1315 | height = HeightScale( height, 0.5*iScale[2].val , Offset[2].val, Invert[2].val ) |
---|
1316 | |
---|
1317 | # clamp height min. max.: |
---|
1318 | if Falloff[0].val !=1: |
---|
1319 | height = Clamp_Min( height, Min.val ) |
---|
1320 | height = Clamp_Max( height, Max.val ) |
---|
1321 | |
---|
1322 | # return height: |
---|
1323 | return height |
---|
1324 | |
---|
1325 | |
---|
1326 | #-------------------------------------------------------------------------------- |
---|
1327 | #-------------------------------------------------------------------------------- |
---|
1328 | # Make preview image: |
---|
1329 | |
---|
1330 | #---------------------- |
---|
1331 | # resize pixels #---------------------- |
---|
1332 | def resizepixels( (i,j),(x,y), res ): |
---|
1333 | global Quality, maketiles |
---|
1334 | size = int( resolution[ Quality.val-1 ] ) |
---|
1335 | i = int( i * ( 1.0 * size / 1.0 ) / res ) |
---|
1336 | j = int( j * ( 1.0 * size / 1.0 ) / res ) |
---|
1337 | if maketiles[0].val !=0: |
---|
1338 | x = x * tile_rescale[ maketiles[1].val ] |
---|
1339 | y = y * tile_rescale[ maketiles[1].val ] |
---|
1340 | return Combine_Functions( (i,j),(x,y,0.0) ) |
---|
1341 | |
---|
1342 | #---------------------- |
---|
1343 | # render image #---------------------- |
---|
1344 | def heightMap(): |
---|
1345 | global PreView, previewname, ViewiScale, vcolours, vcolGradRow, gradScale |
---|
1346 | |
---|
1347 | imsize = resolution[ PreView[1].val-1 ] |
---|
1348 | iname = previewname.val + '_' + imsize + '.tga' |
---|
1349 | res = int( imsize ) |
---|
1350 | ##------------------------------ |
---|
1351 | try: |
---|
1352 | pic = Image.Get( iname ) |
---|
1353 | except: |
---|
1354 | pic = Image.New( iname, res, res ,24 ) |
---|
1355 | #------------------------------ |
---|
1356 | for i in range( 0, res ): |
---|
1357 | for j in range( 0, res ): |
---|
1358 | x = i - (res) / 2.0 |
---|
1359 | y = j - (res) / 2.0 |
---|
1360 | x = (x*2.0) / (res) |
---|
1361 | y = (y*2.0) / (res) |
---|
1362 | # |
---|
1363 | height = resizepixels( (i,j),(x,y), res ) |
---|
1364 | height *= ViewiScale.val |
---|
1365 | ## |
---|
1366 | if vcolours.val == 1: |
---|
1367 | try: |
---|
1368 | r,g,b = pixlGrad( height, vcolGradRow.val, gradScale.val )[1] |
---|
1369 | except: |
---|
1370 | r,g,b = height, height, height |
---|
1371 | else: |
---|
1372 | r,g,b = height, height, height |
---|
1373 | |
---|
1374 | ### |
---|
1375 | if r > 1.0: r = 1.0 |
---|
1376 | if g > 1.0: g = 1.0 |
---|
1377 | if b > 1.0: b = 1.0 |
---|
1378 | if r < 0.0: r = 0.0 |
---|
1379 | if g < 0.0: g = 0.0 |
---|
1380 | if b < 0.0: b = 0.0 |
---|
1381 | #### |
---|
1382 | pic.setPixelF( i, j, ( r, g, b, 1.0 ) ) |
---|
1383 | |
---|
1384 | # get dir. to save to: |
---|
1385 | filepath = Blender.Get( 'filename' ) |
---|
1386 | dirpath = Blender.sys.dirname( filepath ) |
---|
1387 | # Set name and save image: |
---|
1388 | pic.setFilename( dirpath+'/'+iname ) |
---|
1389 | pic.save() |
---|
1390 | #------------------------------------------------------- |
---|
1391 | |
---|
1392 | #------------------------------------------------------------------------ |
---|
1393 | ## Make Mesh ----------------------------------------------------------- |
---|
1394 | ###-------------------------------------------------------------------- |
---|
1395 | |
---|
1396 | #------------------------------------------------------------------------ |
---|
1397 | # VertSelect: select flat areas: |
---|
1398 | def Flat_Vert_Select(me, res, slope_range ): |
---|
1399 | for y in range( 1, res[1]-1 ): |
---|
1400 | for x in range( 1, res[0]-1 ): |
---|
1401 | a = x + y * res[0] |
---|
1402 | try: |
---|
1403 | s = max(abs(me.verts[a].co.z - me.verts[a + res[0] + 1].co.z), abs(me.verts[a + res[0]].co.z - me.verts[a + 1].co.z)) |
---|
1404 | if ( s < (slope_range / res[0]) ): |
---|
1405 | me.verts[a].sel = 1 |
---|
1406 | except: pass |
---|
1407 | |
---|
1408 | #------------------------------------------------------------------------ |
---|
1409 | def Make_Mesh( tiles ): |
---|
1410 | global TerName, Quality, Quad_Tri, Smooth, maketiles, vSelRange, vcolours, vcolGradRow, gradScale |
---|
1411 | |
---|
1412 | n = int( resolution[ Quality.val-1 ] ) |
---|
1413 | |
---|
1414 | try: |
---|
1415 | o = Object.Get( TerName.val + '_' + str( tiles) ) |
---|
1416 | me = o.getData() |
---|
1417 | UPDATE = 1 |
---|
1418 | except: |
---|
1419 | o = Object.New('Mesh', TerName.val + '_' + str( tiles) ) |
---|
1420 | scene.link(o) |
---|
1421 | me = NMesh.GetRaw() |
---|
1422 | UPDATE = 0 |
---|
1423 | |
---|
1424 | me.verts=[] |
---|
1425 | me.faces=[] |
---|
1426 | COL=[] |
---|
1427 | # Vertices ----------------------------------- |
---|
1428 | for i in range( 0, n ): |
---|
1429 | for j in range( 0, n ): |
---|
1430 | # Tile size and position: |
---|
1431 | x = i - (n-1) / 2.0 |
---|
1432 | x = x * 2.0 / (n-1) + ( tiles_positions[maketiles[1].val][ tiles ][0] * 2 ) |
---|
1433 | y = j - (n-1) / 2.0 |
---|
1434 | y = y * 2.0 / (n-1) + ( tiles_positions[maketiles[1].val][ tiles ][1] * 2 ) |
---|
1435 | z = 0.0 |
---|
1436 | # height: |
---|
1437 | height = Combine_Functions( (i,j),(x,y,z) ) |
---|
1438 | v = NMesh.Vert( x, y, height ) |
---|
1439 | me.verts.append(v) |
---|
1440 | |
---|
1441 | # VertCol ----------------------------------- |
---|
1442 | if vcolours.val == 1: |
---|
1443 | try: |
---|
1444 | COL.append( pixlGrad( height, vcolGradRow.val, gradScale.val )[0] ) |
---|
1445 | except: |
---|
1446 | pass |
---|
1447 | |
---|
1448 | ## Vertices: Select Flat Areas -------------------------------------- |
---|
1449 | if vSelRange.val !=0.0: |
---|
1450 | Flat_Vert_Select(me, [n,n], vSelRange.val ) |
---|
1451 | |
---|
1452 | ##-------------------------------------- |
---|
1453 | me.hasVertexColours( vcolours.val ) |
---|
1454 | |
---|
1455 | ## Faces -------------------------------------- |
---|
1456 | if Quad_Tri.val == 1: |
---|
1457 | ## make triangles |
---|
1458 | for i in range(n-1): |
---|
1459 | for j in range(n-1): |
---|
1460 | f = NMesh.Face() |
---|
1461 | f.v.append(me.verts[n*i+j]) |
---|
1462 | f.v.append(me.verts[n*(i+1)+j]) |
---|
1463 | f.v.append(me.verts[n*i+(j+1)]) |
---|
1464 | if vcolours.val !=0: |
---|
1465 | f.col.append(COL[n*i+j]) |
---|
1466 | f.col.append(COL[n*(i+1)+j]) |
---|
1467 | f.col.append(COL[n*i+(j+1)]) |
---|
1468 | f.smooth = Smooth.val |
---|
1469 | me.faces.append(f) |
---|
1470 | f = NMesh.Face() |
---|
1471 | f.v.append(me.verts[n*i+(j+1)]) |
---|
1472 | f.v.append(me.verts[n*(i+1)+j]) |
---|
1473 | f.v.append(me.verts[n*(i+1)+(j+1)]) |
---|
1474 | if vcolours.val !=0: |
---|
1475 | f.col.append(COL[n*i+(j+1)]) |
---|
1476 | f.col.append(COL[n*(i+1)+j]) |
---|
1477 | f.col.append(COL[n*(i+1)+(j+1)]) |
---|
1478 | f.smooth = Smooth.val |
---|
1479 | me.faces.append(f) |
---|
1480 | else: |
---|
1481 | ## make quads |
---|
1482 | for i in range(n-1): |
---|
1483 | for j in range(n-1): |
---|
1484 | f= NMesh.Face() |
---|
1485 | f.v.append(me.verts[i*n+j]) |
---|
1486 | f.v.append(me.verts[(i+1)*n+j]) |
---|
1487 | f.v.append(me.verts[(i+1)*n+j+1]) |
---|
1488 | f.v.append(me.verts[i*n+j+1]) |
---|
1489 | if vcolours.val !=0: |
---|
1490 | f.col.append(COL[i*n+j]) |
---|
1491 | f.col.append(COL[(i+1)*n+j]) |
---|
1492 | f.col.append(COL[(i+1)*n+j+1]) |
---|
1493 | f.col.append(COL[i*n+j+1]) |
---|
1494 | f.smooth = Smooth.val |
---|
1495 | me.faces.append(f) |
---|
1496 | ## |
---|
1497 | if UPDATE ==1: |
---|
1498 | me.update(1) |
---|
1499 | else : |
---|
1500 | o.link(me) |
---|
1501 | #o.select(1) |
---|
1502 | o.layers = Window.ViewLayers() |
---|
1503 | o.makeDisplayList() |
---|
1504 | |
---|
1505 | |
---|
1506 | ###---------------------------------------------------------------------------------------------------- |
---|
1507 | ## Do_it: |
---|
1508 | #-------------------------------------- |
---|
1509 | def do_it(): |
---|
1510 | global maketiles |
---|
1511 | in_editmode = Window.EditMode() |
---|
1512 | if in_editmode: Window.EditMode(0) |
---|
1513 | Blender.Window.WaitCursor(1) |
---|
1514 | if maketiles[0].val !=0: |
---|
1515 | for mt in range( len(tiles_positions[maketiles[1].val]) ): |
---|
1516 | Make_Mesh( mt ) |
---|
1517 | else: |
---|
1518 | Make_Mesh( 0 ) |
---|
1519 | Blender.Window.WaitCursor(0) |
---|
1520 | if in_editmode: Window.EditMode(1) |
---|
1521 | #Redraw() |
---|
1522 | #-------------------------------------- |
---|
1523 | def do_it_random(): |
---|
1524 | global maketiles |
---|
1525 | in_editmode = Window.EditMode() |
---|
1526 | if in_editmode: Window.EditMode(0) |
---|
1527 | Blender.Window.WaitCursor(1) |
---|
1528 | randomiseNoise() |
---|
1529 | if maketiles[0].val !=0: |
---|
1530 | for mt in range( len(tiles_positions[ maketiles[1].val ]) ): |
---|
1531 | Make_Mesh( mt ) |
---|
1532 | else: |
---|
1533 | Make_Mesh( 0 ) |
---|
1534 | Blender.Window.WaitCursor(0) |
---|
1535 | if in_editmode: Window.EditMode(1) |
---|
1536 | #Redraw() |
---|
1537 | #-------------------------------------- |
---|
1538 | def do_it_preview(): |
---|
1539 | heightMap() |
---|
1540 | Window.RedrawAll() |
---|
1541 | |
---|
1542 | ##---------------------------------------------------------------------------------------------------- |
---|
1543 | # Register: |
---|
1544 | |
---|
1545 | Register( drawgui, events, bevents ) |
---|
1546 | |
---|
1547 | ###---------------------------------------------------------------------------------------------------- |
---|