[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [964] trunk/py/scripts/addons/ add_mesh_ant_landscape.py: Script update,

Brendon Murphy meta.androcto1 at gmail.com
Tue Aug 31 11:42:03 CEST 2010


Revision: 964
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=964
Author:   meta-androcto
Date:     2010-08-31 11:42:02 +0200 (Tue, 31 Aug 2010)

Log Message:
-----------
Script update,
new: spherical mesh, strata functions, interactive update, shade
smooth.

Modified Paths:
--------------
    trunk/py/scripts/addons/add_mesh_ant_landscape.py

Modified: trunk/py/scripts/addons/add_mesh_ant_landscape.py
===================================================================
--- trunk/py/scripts/addons/add_mesh_ant_landscape.py	2010-08-31 02:44:33 UTC (rev 963)
+++ trunk/py/scripts/addons/add_mesh_ant_landscape.py	2010-08-31 09:42:02 UTC (rev 964)
@@ -16,6 +16,45 @@
 #
 # ##### END GPL LICENSE BLOCK #####
 
+'''
+Another Noise Tool: Landscape mesh generator
+
+MESH OPTIONS:
+Mesh update:     Turn this on for interactive mesh update.
+Sphere:          Generate sphere or a grid mesh. (Turn height falloff off for sphere mesh)
+Smooth:          Generate smooth shaded mesh.
+Subdivision:     Number of mesh subdivisions, higher numbers gives more detail but also slows down the script.
+Mesh size:       X,Y size of the grid mesh (in blender units).
+
+NOISE OPTIONS: ( Most of these options are the same as in blender textures. )
+Random seed:     Use this to randomise the origin of the noise function.
+Noise size:      Size of the noise.
+Noise type:      Available noise types: multiFractal, ridgedMFractal, hybridMFractal, heteroTerrain, Turbulence, Distorted Noise, Cellnoise, Shattered_hTerrain, Marble
+Noise basis:     Blender, Perlin, NewPerlin, Voronoi_F1, Voronoi_F2, Voronoi_F3, Voronoi_F4, Voronoi_F2-F1, Voronoi Crackle, Cellnoise
+VLNoise basis:   Blender, Perlin, NewPerlin, Voronoi_F1, Voronoi_F2, Voronoi_F3, Voronoi_F4, Voronoi_F2-F1, Voronoi Crackle, Cellnoise
+Distortion:      Distortion amount.
+Hard:            Hard/Soft turbulence noise.
+Depth:           Noise depth, number of frequencies in the fBm.
+Dimension:       Musgrave: Fractal dimension of the roughest areas.
+Lacunarity:      Musgrave: Gap between successive frequencies.
+Offset:          Musgrave: Raises the terrain from sea level.
+Gain:            Musgrave: Scale factor.
+Marble Bias:     Sin, Tri, Saw
+Marble Sharpnes: Soft, Sharp, Sharper
+Marble Shape:    Shape of the marble function: Default, Ring, Swirl, X, Y
+
+HEIGHT OPTIONS:
+Invert:          Invert terrain height.
+Height:          Scale terrain height.
+Offset:          Terrain height offset.
+Falloff:         Terrain height falloff: Type 1, Type 2, X, Y
+Sealevel:        Flattens terrain below sealevel.
+Platlevel:       Flattens terrain above plateau level.
+Strata:          Strata amount, number of strata/terrace layers.
+Strata type:     Strata types, Smooth, Sharp-sub, Sharp-add
+'''
+
+
 bl_addon_info = {
     "name": "ANT Landscape",
     "author": "Jimmy Hazevoet",
@@ -38,6 +77,7 @@
 from noise import *
 from math import *
 
+
 ###------------------------------------------------------------
 # calculates the matrix for the new object depending on user pref
 def align_matrix(context):
@@ -207,12 +247,10 @@
 
     return faces
 
+
 ###------------------------------------------------------------
-
-# some functions for marbleNoise
-def no_bias(a):
-    return a
-
+###------------------------------------------------------------
+# some functions for marble_noise
 def sin_bias(a):
     return 0.5 + 0.5 * sin(a)
 
@@ -242,46 +280,46 @@
         # ring
         x = x*2
         y = y*2
-        s = -cos(x**2+y**2)/(x**2+y**2+0.5)
+        s = (-cos(x**2+y**2)/(x**2+y**2+0.5))
     elif shape == 2:
         # swirl
         x = x*2
         y = y*2
-        s = ( x*sin( x*x+y*y ) + y*cos( x*x+y*y ) )
+        s = (( x*sin( x*x+y*y ) + y*cos( x*x+y*y ) ) / (x**2+y**2+0.5))
     elif shape == 3:
         # bumps
         x = x*2
         y = y*2
-        s = (sin( x*pi ) + sin( y*pi ))
+        s = ((cos( x*pi ) + cos( y*pi ))-0.5)
     elif shape == 4:
         # y grad.
-        s = y*pi
+        s = (y*pi)
     elif shape == 5:
         # x grad.
-        s = x*pi
+        s = (x*pi)
     else:
         # marble
         s = ((x+y)*5)
     return s
 
-# marbleNoise
-def marble_noise(x,y, origin, size, shape, bias, sharpnes, depth, turb, basis ):
+# marble_noise
+def marble_noise(x,y,z, origin, size, shape, bias, sharpnes, turb, depth, hard, basis ):
     x = x / size
     y = y / size
+    z = z / size
     s = shapes(x,y,shape)
 
     x += origin[0]
     y += origin[1]
-    value = s + turb * turbulence_vector((x,y,0.0), depth, 0, basis )[0]
+    z += origin[2]
+    value = s + turb * turbulence_vector((x,y,z), depth, hard, basis )[0]
 
     if bias == 1:
-        value = sin_bias( value )
+        value = tri_bias( value )
     elif bias == 2:
-        value = tri_bias( value )
-    elif bias == 3:
         value = saw_bias( value )
     else:
-        value = no_bias( value )
+        value = sin_bias( value )
 
     if sharpnes == 1:
         value = sharp( value )
@@ -292,15 +330,25 @@
 
     return value
 
-# Shattered_hTerrain:
-def shattered_hterrain( x,y, H, lacunarity, octaves, offset, distort, basis ):
-    d = ( turbulence_vector( ( x, y, 0.0 ), 6, 0, 0, 0.5, 2.0 )[0] * 0.5 + 0.5 )*distort*0.5
-    t0 = ( turbulence_vector( ( x+d, y+d, 0.0 ), 0, 0, 7, 0.5, 2.0 )[0] + 0.5 )
-    t2 = ( hetero_terrain(( x*2, y*2, t0*0.25 ), H, lacunarity, octaves, offset, basis ) )
-    return (( t0*t2 )+t2*0.5)*0.5
+###------------------------------------------------------------
+# custom noise types
 
+# shattered_hterrain:
+def shattered_hterrain( x,y,z, H, lacunarity, octaves, offset, distort, basis ):
+    d = ( turbulence_vector( ( x, y, z ), 6, 0, 0 )[0] * 0.5 + 0.5 )*distort*0.5
+    t1 = ( turbulence_vector( ( x+d, y+d, z ), 0, 0, 7 )[0] + 0.5 )
+    t2 = ( hetero_terrain(( x*2, y*2, z*2 ), H, lacunarity, octaves, offset, basis )*0.5 )
+    return (( t1*t2 )+t2*0.5) * 0.5
+
+# strata_hterrain
+def strata_hterrain( x,y,z, H, lacunarity, octaves, offset, distort, basis ):
+    value = hetero_terrain(( x, y, z ), H, lacunarity, octaves, offset, basis )*0.5
+    steps = ( sin( value*(distort*5)*pi ) * ( 0.1/(distort*5)*pi ) )
+    return ( value * (1.0-0.5) + steps*0.5 )
+
+###------------------------------------------------------------
 # landscape_gen
-def landscape_gen(x,y,falloffsize,options=[0,1.0,1, 0,0,1.0,0,6,1.0,2.0,1.0,2.0,0,0,0, 1.0,0.0,1,0.0,1.0,0]):
+def landscape_gen(x,y,z,falloffsize,options=[0,1.0,1, 0,0,1.0,0,6,1.0,2.0,1.0,2.0,0,0,0, 1.0,0.0,1,0.0,1.0,0,0,0]):
 
     # options
     rseed    = options[0]
@@ -309,7 +357,7 @@
     nbasis     = int( options[3][0] )
     vlbasis    = int( options[4][0] )
     distortion = options[5]
-    hard       = options[6]
+    hardnoise  = options[6]
     depth      = options[7]
     dimension  = options[8]
     lacunarity = options[9]
@@ -324,25 +372,29 @@
     falloff      = int( options[18][0] )
     sealevel     = options[19]
     platlevel    = options[20]
-    terrace      = options[21]
+    strata       = options[21]
+    stratatype   = options[22]
+    sphere       = options[23]
 
     # origin
     if rseed == 0:
         origin = 0.0,0.0,0.0
         origin_x = 0.0
         origin_y = 0.0
+        origin_z = 0.0
     else:
         # randomise origin
         seed_set( rseed )
         origin = random_unit_vector()
-        origin_x = 0.5 - origin[0] * 1000
-        origin_y = 0.5 - origin[1] * 1000
+        origin_x = ( 0.5 - origin[0] ) * 1000.0
+        origin_y = ( 0.5 - origin[1] ) * 1000.0
+        origin_z = ( 0.5 - origin[2] ) * 1000.0
 
     # adjust noise size and origin
-    ncoords = ( x / nsize + origin_x, y / nsize + origin_y, 0.0 )
+    ncoords = ( x / nsize + origin_x, y / nsize + origin_y, z / nsize + origin_z )
 
     # noise basis type's
-    if nbasis == 9: nbasis = 14  # to get cellnoise basis you must set 14 instead of 9 (is this a bug?)
+    if nbasis == 9: nbasis = 14  # to get cellnoise basis you must set 14 instead of 9
     if vlbasis ==9: vlbasis = 14
     # noise type's
     if ntype == 0:   value = multi_fractal(        ncoords, dimension, lacunarity, depth, nbasis ) * 0.5
@@ -350,11 +402,11 @@
     elif ntype == 2: value = hybrid_multi_fractal( ncoords, dimension, lacunarity, depth, offset, gain, nbasis ) * 0.5
     elif ntype == 3: value = hetero_terrain(       ncoords, dimension, lacunarity, depth, offset, nbasis ) * 0.25
     elif ntype == 4: value = fractal(              ncoords, dimension, lacunarity, depth, nbasis )
-    elif ntype == 5: value = turbulence_vector(    ncoords, depth, hard, nbasis )[0]
+    elif ntype == 5: value = turbulence_vector(    ncoords, depth, hardnoise, nbasis )[0]
     elif ntype == 6: value = vl_vector(            ncoords, distortion, nbasis, vlbasis ) + 0.5
-    elif ntype == 7: value = cell( ncoords ) + 0.5
-    elif ntype == 8: value = shattered_hterrain( ncoords[0],ncoords[1], dimension, lacunarity, depth, offset, distortion, nbasis ) * 0.5
-    elif ntype == 9: value = marble_noise( x*2.0/falloffsize,y*2.0/falloffsize, origin, nsize, marbleshape, marblebias, marblesharpnes, depth, distortion, nbasis )
+    elif ntype == 7: value = marble_noise( x*2.0/falloffsize,y*2.0/falloffsize,z*2/falloffsize, origin, nsize, marbleshape, marblebias, marblesharpnes, distortion, depth, hardnoise, nbasis )
+    elif ntype == 8: value = shattered_hterrain( ncoords[0], ncoords[1], ncoords[2], dimension, lacunarity, depth, offset, distortion, nbasis )
+    elif ntype == 9: value = strata_hterrain( ncoords[0], ncoords[1], ncoords[2], dimension, lacunarity, depth, offset, distortion, nbasis )
     else:
         value = 0.0
 
@@ -365,26 +417,37 @@
         value = value * height + heightoffset
 
     # edge falloff
-    if falloff != 0:
-        fallofftypes = [ 0, sqrt((x*x)**2+(y*y)**2), sqrt(x*x+y*y), sqrt(y*y), sqrt(x*x) ]
-        dist = fallofftypes[ falloff]
-        if falloff ==1:
-            radius = (falloffsize/2)**2
-        else:
-            radius = falloffsize/2
-        value = value - sealevel
-        if( dist < radius ):
-            dist = dist / radius
-            dist = ( (dist) * (dist) * ( 3-2*(dist) ) )
-            value = ( value - value * dist ) + sealevel
-        else:
-            value = sealevel
+    if sphere == 0: # no edge falloff if spherical
+        if falloff != 0:
+            fallofftypes = [ 0, sqrt((x*x)**2+(y*y)**2), sqrt(x*x+y*y), sqrt(y*y), sqrt(x*x) ]
+            dist = fallofftypes[ falloff]
+            if falloff ==1:
+                radius = (falloffsize/2)**2
+            else:
+                radius = falloffsize/2
+            value = value - sealevel
+            if( dist < radius ):
+                dist = dist / radius
+                dist = ( (dist) * (dist) * ( 3-2*(dist) ) )
+                value = ( value - value * dist ) + sealevel

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list