def shattered_hterrain(coords, H, lacunarity, octaves, offset, distort, basis): x, y, z = coords d = (turbulence_vector(coords, 6, 0, 0)[0] * 0.5 + 0.5) * distort * 0.5 t1 = (turbulence_vector((x + d, y + d, z + d), 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
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] z += origin[2] value = s + turb * turbulence_vector((x, y, z), depth, hard, basis)[0] if bias == 1: value = tri_bias(value) elif bias == 2: value = saw_bias(value) else: value = sin_bias(value) if sharpnes == 1: value = sharp(value) elif sharpnes == 2: value = sharper(value) else: value = soft(value) return value
def vTurbNoise(x, y, z, iScale=0.25, Size=1.0, Depth=6, Hard=False, Basis=0, Seed=0): """ vTurbNoise((x,y,z), iScale=0.25, Size=1.0, Depth=6, Hard=0, Basis=0, Seed=0 ) Create randomised vTurbulence noise Parameters: xyz - (x,y,z) float values. (type=3-float tuple) iScale - noise intensity scale (type=float) Size - noise size (type=float) Depth - number of noise values added. (type=int) Hard - noise hardness: True - soft noise; False - hard noise (type=int) basis - type of noise used for turbulence (type=int) Seed - the random seed number, if seed is 0, the current time will be used instead (type=int) Returns: the generated turbulence vector. (type=3-float list) """ rand = randnum(-100, 100, Seed) if Basis is 9: Basis = 14 vec = Vector((x / Size + rand, y / Size + rand, z / Size + rand)) vTurb = Noise.turbulence_vector(vec, Depth, Hard) #mathutils.noise.turbulence_vector(position, octaves, hard, noise_basis='PERLIN_ORIGINAL', amplitude_scale=0.5, frequency_scale=2.0) tx = vTurb[0] * iScale ty = vTurb[1] * iScale tz = vTurb[2] * iScale return tx, ty, tz
def vTurbNoise(x,y,z, iScale=0.25, Size=1.0, Depth=6, Hard=0, Basis=0, Seed=0): """ vTurbNoise((x,y,z), iScale=0.25, Size=1.0, Depth=6, Hard=0, Basis=0, Seed=0 ) Create randomised vTurbulence noise Parameters: xyz - (x,y,z) float values. (type=3-float tuple) iScale - noise intensity scale (type=float) Size - noise size (type=float) Depth - number of noise values added. (type=int) Hard - noise hardness: 0 - soft noise; 1 - hard noise (type=int) basis - type of noise used for turbulence (type=int) Seed - the random seed number, if seed is 0, the current time will be used instead (type=int) Returns: the generated turbulence vector. (type=3-float list) """ rand = randnum(-100,100,Seed) if Basis == 9: Basis = 14 vTurb = Noise.turbulence_vector((x/Size+rand, y/Size+rand, z/Size+rand), Depth, Hard, Basis) tx = vTurb[0]*iScale ty = vTurb[1]*iScale tz = vTurb[2]*iScale return tx,ty,tz
def vTurbNoise(x, y, z, iScale=0.25, Size=1.0, Depth=6, Hard=0, Basis=0, Seed=0): """ vTurbNoise((x,y,z), iScale=0.25, Size=1.0, Depth=6, Hard=0, Basis=0, Seed=0 ) Create randomised vTurbulence noise Parameters: xyz - (x,y,z) float values. (type=3-float tuple) iScale - noise intensity scale (type=float) Size - noise size (type=float) Depth - number of noise values added. (type=int) Hard - noise hardness: 0 - soft noise; 1 - hard noise (type=int) basis - type of noise used for turbulence (type=int) Seed - the random seed number, if seed is 0, the current time will be used instead (type=int) Returns: the generated turbulence vector. (type=3-float list) """ rand = randnum(-100, 100, Seed) if Basis == 9: Basis = 14 vTurb = Noise.turbulence_vector((x / Size + rand, y / Size + rand, z / Size + rand), Depth, Hard, Basis) tx = vTurb[0] * iScale ty = vTurb[1] * iScale tz = vTurb[2] * iScale return tx, ty, tz
def marble_noise(x, y, z, origin, size, shape, bias, sharpnes, turb, depth, hard, basis, amp, freq): s = shapes(x, y, z, shape) x += origin[0] y += origin[1] z += origin[2] value = s + turb * turbulence_vector((x, y, z), depth, hard, basis)[1] if bias is 1: value = cos_bias(value) elif bias is 2: value = tri_bias(value) elif bias is 3: value = saw_bias(value) else: value = sin_bias(value) if sharpnes is 1: value = 1.0 - sharp(value) elif sharpnes is 2: value = 1.0 - sharper(value) elif sharpnes is 3: value = soft(value) elif sharpnes is 4: value = sharp(value) elif sharpnes is 5: value = sharper(value) else: value = 1.0 - soft(value) return value
def marble_noise(x, y, z, origin, size, shape, bias, sharpnes, turb, depth, hard, basis, amp, freq): s = shapes(x, y, z, shape) x += origin[0] y += origin[1] z += origin[2] value = s + turb * turbulence_vector( (x, y, z), depth, hard, noise_basis=basis)[1] if bias == 1: value = cos_bias(value) elif bias == 2: value = tri_bias(value) elif bias == 3: value = saw_bias(value) else: value = sin_bias(value) if sharpnes == 1: value = 1.0 - sharp(value) elif sharpnes == 2: value = 1.0 - sharper(value) elif sharpnes == 3: value = soft(value) elif sharpnes == 4: value = sharp(value) elif sharpnes == 5: value = sharper(value) else: value = 1.0 - soft(value) return value
def ant_turbulence(coords, depth, hardnoise, nbasis, amp, freq, distortion): x, y, z = coords t = turbulence_vector((x / 2, y / 2, z / 2), depth, 0, noise_basis=nbasis, amplitude_scale=amp, frequency_scale=freq) * 0.5 * distortion return turbulence( (t[0], t[1], t[2]), 2, hardnoise, noise_basis="VORONOI_F1") * 0.5 + 0.5
def ant_turbulence(coords, depth, hardnoise, nbasis, amp, freq, distortion): x, y, z = coords t = turbulence_vector((x/2, y/2, z/2), depth, 0, nbasis, amp, freq) * 0.5 * distortion return turbulence((t[0], t[1], t[2]), 2, hardnoise, 3) * 0.5 + 0.5
def noise_gen(coords, props): terrain_name = props[0] cursor = props[1] smooth = props[2] triface = props[3] sphere = props[4] land_mat = props[5] water_mat = props[6] texture_name = props[7] subd_x = props[8] subd_y = props[9] meshsize_x = props[10] meshsize_y = props[11] meshsize = props[12] rseed = props[13] x_offset = props[14] y_offset = props[15] z_offset = props[16] size_x = props[17] size_y = props[18] size_z = props[19] nsize = props[20] ntype = props[21] nbasis = props[22] vlbasis = props[23] distortion = props[24] hardnoise = int(props[25]) depth = props[26] amp = props[27] freq = props[28] dimension = props[29] lacunarity = props[30] offset = props[31] gain = props[32] marblebias = int(props[33]) marblesharpnes = int(props[34]) marbleshape = int(props[35]) height = props[36] height_invert = props[37] height_offset = props[38] maximum = props[39] minimum = props[40] falloff = int(props[41]) edge_level = props[42] falloffsize_x = props[43] falloffsize_y = props[44] stratatype = props[45] strata = props[46] addwater = props[47] waterlevel = props[48] vert_group = props[49] remove_double = props[50] fx_mixfactor = props[51] fx_mix_mode = props[52] fx_type = props[53] fx_bias = props[54] fx_turb = props[55] fx_depth = props[56] fx_frequency = props[57] fx_amplitude = props[58] fx_size = props[59] fx_loc_x = props[60] fx_loc_y = props[61] fx_height = props[62] fx_offset = props[63] fx_invert = props[64] x, y, z = coords # Origin if rseed == 0: origin = x_offset, y_offset, z_offset origin_x = x_offset origin_y = y_offset origin_z = z_offset o_range = 1.0 else: # Randomise origin o_range = 100 seed_set(rseed) origin = random_unit_vector() ox = (origin[0] * o_range) oy = (origin[1] * o_range) oz = 0 origin_x = (ox - (ox * 0.5)) + x_offset origin_y = (oy - (oy * 0.5)) + y_offset origin_z = oz + z_offset ncoords = (x / (nsize * size_x) + origin_x, y / (nsize * size_y) + origin_y, z / (nsize * size_z) + origin_z) # Noise type's if ntype in [0, 'multi_fractal']: value = multi_fractal( ncoords, dimension, lacunarity, depth, noise_basis=nbasis) * 0.5 elif ntype in [1, 'ridged_multi_fractal']: value = ridged_multi_fractal(ncoords, dimension, lacunarity, depth, offset, gain, noise_basis=nbasis) * 0.5 elif ntype in [2, 'hybrid_multi_fractal']: value = hybrid_multi_fractal(ncoords, dimension, lacunarity, depth, offset, gain, noise_basis=nbasis) * 0.5 elif ntype in [3, 'hetero_terrain']: value = hetero_terrain( ncoords, dimension, lacunarity, depth, offset, noise_basis=nbasis) * 0.25 elif ntype in [4, 'fractal']: value = fractal(ncoords, dimension, lacunarity, depth, noise_basis=nbasis) elif ntype in [5, 'turbulence_vector']: value = turbulence_vector(ncoords, depth, hardnoise, noise_basis=nbasis, amplitude_scale=amp, frequency_scale=freq)[0] elif ntype in [6, 'variable_lacunarity']: value = variable_lacunarity(ncoords, distortion, noise_type1=nbasis, noise_type2=vlbasis) elif ntype in [7, 'marble_noise']: value = marble_noise( (ncoords[0] - origin_x + x_offset), (ncoords[1] - origin_y + y_offset), (ncoords[2] - origin_z + z_offset), (origin[0] + x_offset, origin[1] + y_offset, origin[2] + z_offset), nsize, marbleshape, marblebias, marblesharpnes, distortion, depth, hardnoise, nbasis, amp, freq) elif ntype in [8, 'shattered_hterrain']: value = shattered_hterrain(ncoords, dimension, lacunarity, depth, offset, distortion, nbasis) elif ntype in [9, 'strata_hterrain']: value = strata_hterrain(ncoords, dimension, lacunarity, depth, offset, distortion, nbasis) elif ntype in [10, 'ant_turbulence']: value = ant_turbulence(ncoords, depth, hardnoise, nbasis, amp, freq, distortion) elif ntype in [11, 'vl_noise_turbulence']: value = vl_noise_turbulence(ncoords, distortion, depth, nbasis, vlbasis, hardnoise, amp, freq) elif ntype in [12, 'vl_hTerrain']: value = vl_hTerrain(ncoords, dimension, lacunarity, depth, offset, nbasis, vlbasis, distortion) elif ntype in [13, 'distorted_heteroTerrain']: value = distorted_heteroTerrain(ncoords, dimension, lacunarity, depth, offset, distortion, nbasis, vlbasis) elif ntype in [14, 'double_multiFractal']: value = double_multiFractal(ncoords, dimension, lacunarity, depth, offset, gain, nbasis, vlbasis) elif ntype in [15, 'rocks_noise']: value = rocks_noise(ncoords, depth, hardnoise, nbasis, distortion) elif ntype in [16, 'slick_rock']: value = slick_rock(ncoords, dimension, lacunarity, depth, offset, gain, distortion, nbasis, vlbasis) elif ntype in [17, 'planet_noise']: value = planet_noise(ncoords, depth, hardnoise, nbasis)[2] * 0.5 + 0.5 elif ntype in [18, 'blender_texture']: if texture_name != "" and texture_name in bpy.data.textures: value = bpy.data.textures[texture_name].evaluate(ncoords)[3] else: value = 0.0 else: value = 0.5 # Effect mix val = value if fx_type in [0, "0"]: fx_mixfactor = -1.0 fxval = val else: fxcoords = Trans_Effect((x, y, z), fx_size, (fx_loc_x, fx_loc_y)) effect = Effect_Function(fxcoords, fx_type, fx_bias, fx_turb, fx_depth, fx_frequency, fx_amplitude) effect = Height_Scale(effect, fx_height, fx_offset, fx_invert) fxval = Mix_Modes(val, effect, fx_mixfactor, fx_mix_mode) value = fxval # Adjust height value = Height_Scale(value, height, height_offset, height_invert) # Edge falloff: if not sphere: if falloff: ratio_x, ratio_y = abs(x) * 2 / meshsize_x, abs(y) * 2 / meshsize_y fallofftypes = [ 0, sqrt(ratio_y**falloffsize_y), sqrt(ratio_x**falloffsize_x), sqrt(ratio_x**falloffsize_x + ratio_y**falloffsize_y) ] dist = fallofftypes[falloff] value -= edge_level if (dist < 1.0): dist = (dist * dist * (3 - 2 * dist)) value = (value - value * dist) + edge_level else: value = edge_level # Strata / terrace / layers if stratatype not in [0, "0"]: if stratatype in [1, "1"]: strata = strata / height strata *= 2 steps = (sin(value * strata * pi) * (0.1 / strata * pi)) value = (value * 0.5 + steps * 0.5) * 2.0 elif stratatype in [2, "2"]: strata = strata / height steps = -abs(sin(value * strata * pi) * (0.1 / strata * pi)) value = (value * 0.5 + steps * 0.5) * 2.0 elif stratatype in [3, "3"]: strata = strata / height steps = abs(sin(value * strata * pi) * (0.1 / strata * pi)) value = (value * 0.5 + steps * 0.5) * 2.0 elif stratatype in [4, "4"]: strata = strata / height value = int(value * strata) * 1.0 / strata elif stratatype in [5, "5"]: strata = strata / height steps = (int(value * strata) * 1.0 / strata) value = (value * (1.0 - 0.5) + steps * 0.5) # Clamp height min max if (value < minimum): value = minimum if (value > maximum): value = maximum return value
def step(self): '''Simulate next frame''' self.frame += 1 self.create_tree() for part in self.particles: if part.active: previous_velocity = part.velocity.copy() #guide vector guide_vector = self.guide.data.vertices[part.guide_index].co - part.location guide_vector = guide_vector.normalized() * self.GUIDE_STRENGTH #turbulence vector turbulence = noise.turbulence_vector(part.noise_seed+part.location, 2, False, 1, self.TURBULENCE_STRENGTH, self.TURBULENCE_FREQUENCY) # part.noise_seed += turbulence / 50 # if part.velocity.length_squared < 0.0001: # part.noise_seed = noise.random_unit_vector() part.noise_seed.z += 0.01 #boid-like vector too_close = self.parts_tree.find_range(part.location, self.AVOID_THRESHOLD) avoid_vector = Vector() for p in too_close: other_vec = part.location - p[0] if other_vec.length_squared < 0.0001: continue other_vec /= other_vec.length avoid_vector += other_vec # avoid_vector.normalize() # avoid_vector -= part.velocity avoid_vector *= self.AVOID_STRENGTH #velocity change part.velocity += avoid_vector part.velocity += turbulence * (1.0-part.behaviour) part.velocity += guide_vector * part.behaviour #limit velocity (drag and shit) if part.velocity.length > part.MAX_VEL: part.velocity.length = part.MAX_VEL # limit rotation rotation_scalar = previous_velocity.dot(part.velocity) * 0.5 + 0.5 # normalized 0-1 # rotation_scalar **= 3 if rotation_scalar > 0.1: rotation_scalar = 0.1 # rotation_scalar = 0 part.velocity *= (rotation_scalar) part.velocity += previous_velocity * (1-rotation_scalar) # put that shit on the ground closest = self.ground.closest_point_on_mesh(part.location) part.location = closest[0] # velocity parallel to the ground vel_norm = part.velocity.length inter = part.velocity.cross(closest[1]) part.velocity = closest[1].cross(inter) part.velocity.length = vel_norm # print(part.velocity) # SET NEW LOCATION part.location += part.velocity # behaviour change part.behaviour += random()*0.1-0.05 if part.behaviour < 0.8: part.behaviour = 0.8 if part.behaviour > 0.9: part.behaviour = 0.9 # # set goal to next vertex if close enough pt, ind, dist = self.guide_tree.find(part.location) if fabs(ind - part.guide_index) < 2: part.guide_index += part.direction # if self.frame % 20 == 0: # part.guide_index += part.direction # if next_point_distance.length_squared < self.vertex_distance: # part.guide_index += 1 # switch direction if end reached if part.guide_index >= len(self.guide.data.vertices)-1 or part.guide_index == 1: # part.active = False # self.kill_particle(part) part.direction = -part.direction part.guide_index += part.direction self.create_frame(self.frame)
def ant_turbulence(coords, depth, hardnoise, nbasis, amp, freq, distortion): x, y, z = coords t = turbulence_vector( (x / 2, y / 2, z / 2), depth, 0, nbasis, amp, freq) * 0.5 * distortion return turbulence((t[0], t[1], t[2]), 2, hardnoise, 3) * 0.5 + 0.5
def noise_gen(coords, props): terrain_name = props[0] cursor = props[1] smooth = props[2] triface = props[3] sphere = props[4] land_mat = props[5] water_mat = props[6] texture_name = props[7] subd_x = props[8] subd_y = props[9] meshsize_x = props[10] meshsize_y = props[11] meshsize = props[12] rseed = props[13] x_offset = props[14] y_offset = props[15] z_offset = props[16] size_x = props[17] size_y = props[18] size_z = props[19] nsize = props[20] ntype = props[21] nbasis = int(props[22]) vlbasis = int(props[23]) distortion = props[24] hardnoise = int(props[25]) depth = props[26] amp = props[27] freq = props[28] dimension = props[29] lacunarity = props[30] offset = props[31] gain = props[32] marblebias = int(props[33]) marblesharpnes = int(props[34]) marbleshape = int(props[35]) height = props[36] height_invert = props[37] height_offset = props[38] maximum = props[39] minimum = props[40] falloff = int(props[41]) edge_level = props[42] falloffsize_x = props[43] falloffsize_y = props[44] stratatype = props[45] strata = props[46] addwater = props[47] waterlevel = props[48] vert_group = props[49] remove_double = props[50] fx_mixfactor = props[51] fx_mix_mode = props[52] fx_type = props[53] fx_bias = props[54] fx_turb = props[55] fx_depth = props[56] fx_frequency = props[57] fx_amplitude = props[58] fx_size = props[59] fx_loc_x = props[60] fx_loc_y = props[61] fx_height = props[62] fx_offset = props[63] fx_invert = props[64] x, y, z = coords # Origin if rseed is 0: origin = x_offset, y_offset, z_offset origin_x = x_offset origin_y = y_offset origin_z = z_offset o_range = 1.0 else: # Randomise origin o_range = 10000.0 seed_set(rseed) origin = random_unit_vector() ox = (origin[0] * o_range) oy = (origin[1] * o_range) oz = (origin[2] * o_range) origin_x = (ox - (ox / 2)) + x_offset origin_y = (oy - (oy / 2)) + y_offset origin_z = (oz - (oz / 2)) + z_offset ncoords = (x / (nsize * size_x) + origin_x, y / (nsize * size_y) + origin_y, z / (nsize * size_z) + origin_z) # Noise basis type's if nbasis == 9: nbasis = 14 # Cellnoise if vlbasis == 9: vlbasis = 14 # Noise type's if ntype in [0, 'multi_fractal']: value = multi_fractal(ncoords, dimension, lacunarity, depth, nbasis) * 0.5 elif ntype in [1, 'ridged_multi_fractal']: value = ridged_multi_fractal(ncoords, dimension, lacunarity, depth, offset, gain, nbasis) * 0.5 elif ntype in [2, 'hybrid_multi_fractal']: value = hybrid_multi_fractal(ncoords, dimension, lacunarity, depth, offset, gain, nbasis) * 0.5 elif ntype in [3, 'hetero_terrain']: value = hetero_terrain(ncoords, dimension, lacunarity, depth, offset, nbasis) * 0.25 elif ntype in [4, 'fractal']: value = fractal(ncoords, dimension, lacunarity, depth, nbasis) elif ntype in [5, 'turbulence_vector']: value = turbulence_vector(ncoords, depth, hardnoise, nbasis, amp, freq)[0] elif ntype in [6, 'variable_lacunarity']: value = variable_lacunarity(ncoords, distortion, nbasis, vlbasis) elif ntype in [7, 'marble_noise']: value = marble_noise( (ncoords[0] - origin_x + x_offset), (ncoords[1] - origin_y + y_offset), (ncoords[2] - origin_z + z_offset), (origin[0] + x_offset, origin[1] + y_offset, origin[2] + z_offset), nsize, marbleshape, marblebias, marblesharpnes, distortion, depth, hardnoise, nbasis, amp, freq ) elif ntype in [8, 'shattered_hterrain']: value = shattered_hterrain(ncoords, dimension, lacunarity, depth, offset, distortion, nbasis) elif ntype in [9, 'strata_hterrain']: value = strata_hterrain(ncoords, dimension, lacunarity, depth, offset, distortion, nbasis) elif ntype in [10, 'ant_turbulence']: value = ant_turbulence(ncoords, depth, hardnoise, nbasis, amp, freq, distortion) elif ntype in [11, 'vl_noise_turbulence']: value = vl_noise_turbulence(ncoords, distortion, depth, nbasis, vlbasis, hardnoise, amp, freq) elif ntype in [12, 'vl_hTerrain']: value = vl_hTerrain(ncoords, dimension, lacunarity, depth, offset, nbasis, vlbasis, distortion) elif ntype in [13, 'distorted_heteroTerrain']: value = distorted_heteroTerrain(ncoords, dimension, lacunarity, depth, offset, distortion, nbasis, vlbasis) elif ntype in [14, 'double_multiFractal']: value = double_multiFractal(ncoords, dimension, lacunarity, depth, offset, gain, nbasis, vlbasis) elif ntype in [15, 'rocks_noise']: value = rocks_noise(ncoords, depth, hardnoise, nbasis, distortion) elif ntype in [16, 'slick_rock']: value = slick_rock(ncoords,dimension, lacunarity, depth, offset, gain, distortion, nbasis, vlbasis) elif ntype in [17, 'planet_noise']: value = planet_noise(ncoords, depth, hardnoise, nbasis)[2] * 0.5 + 0.5 elif ntype in [18, 'blender_texture']: if texture_name != "" and texture_name in bpy.data.textures: value = bpy.data.textures[texture_name].evaluate(ncoords)[3] else: value = 0.0 else: value = 0.5 # Effect mix val = value if fx_type in [0,"0"]: fx_mixfactor = -1.0 fxval = val else: fxcoords = Trans_Effect((x, y, z), fx_size, (fx_loc_x, fx_loc_y)) effect = Effect_Function(fxcoords, fx_type, fx_bias, fx_turb, fx_depth, fx_frequency, fx_amplitude) effect = Height_Scale(effect, fx_height, fx_offset, fx_invert) fxval = Mix_Modes(val, effect, fx_mixfactor, fx_mix_mode) value = fxval # Adjust height value = Height_Scale(value, height, height_offset, height_invert) # Edge falloff: if not sphere: if falloff: ratio_x, ratio_y = abs(x) * 2 / meshsize_x, abs(y) * 2 / meshsize_y fallofftypes = [0, sqrt(ratio_y**falloffsize_y), sqrt(ratio_x**falloffsize_x), sqrt(ratio_x**falloffsize_x + ratio_y**falloffsize_y) ] dist = fallofftypes[falloff] value -= edge_level if(dist < 1.0): dist = (dist * dist * (3 - 2 * dist)) value = (value - value * dist) + edge_level else: value = edge_level # Strata / terrace / layers if stratatype not in [0, "0"]: if stratatype in [1, "1"]: strata = strata / height strata *= 2 steps = (sin(value * strata * pi) * (0.1 / strata * pi)) value = (value * 0.5 + steps * 0.5) * 2.0 elif stratatype in [2, "2"]: strata = strata / height steps = -abs(sin(value * strata * pi) * (0.1 / strata * pi)) value = (value * 0.5 + steps * 0.5) * 2.0 elif stratatype in [3, "3"]: strata = strata / height steps = abs(sin(value * strata * pi) * (0.1 / strata * pi)) value = (value * 0.5 + steps * 0.5) * 2.0 elif stratatype in [4, "4"]: strata = strata / height value = int( value * strata ) * 1.0 / strata elif stratatype in [5, "5"]: strata = strata / height steps = (int( value * strata ) * 1.0 / strata) value = (value * (1.0 - 0.5) + steps * 0.5) # Clamp height min max if (value < minimum): value = minimum if (value > maximum): value = maximum return value
def shattered_hterrain(coords, H, lacunarity, octaves, offset, distort, basis): x, y, z = coords d = (turbulence_vector(coords, 6, 0, 0)[0] * 0.5 + 0.5) * distort * 0.5 t1 = (turbulence_vector((x + d, y + d, z + d), 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
def ant_turbulence(coords, depth, hardnoise, nbasis, amp, freq, distortion): x, y, z = coords t = turbulence_vector((x/2, y/2, z/2), depth, 0, noise_basis=nbasis, amplitude_scale=amp, frequency_scale=freq) * 0.5 * distortion return turbulence((t[0], t[1], t[2]), 2, hardnoise, noise_basis="VORONOI_F1") * 0.5 + 0.5
def landscape_gen(x, y, z, falloffsize, options): # options = [0, 1.0, 'multi_fractal', 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, 0.0, 0.0] rseed = options[0] nsize = options[1] ntype = options[2] nbasis = int(options[3][0]) vlbasis = int(options[4][0]) distortion = options[5] hardnoise = options[6] depth = options[7] dimension = options[8] lacunarity = options[9] offset = options[10] gain = options[11] marblebias = int(options[12][0]) marblesharpnes = int(options[13][0]) marbleshape = int(options[14][0]) invert = options[15] height = options[16] heightoffset = options[17] falloff = int(options[18][0]) sealevel = options[19] platlevel = options[20] strata = options[21] stratatype = options[22] sphere = options[23] x_offset = options[24] y_offset = options[25] # origin if rseed == 0: origin = 0.0 + x_offset, 0.0 + y_offset, 0.0 origin_x = x_offset origin_y = y_offset origin_z = 0.0 else: # randomise origin seed_set(rseed) origin = random_unit_vector() origin[0] += x_offset origin[1] += y_offset origin_x = ((0.5 - origin[0]) * 1000.0) + x_offset origin_y = ((0.5 - origin[1]) * 1000.0) + y_offset origin_z = (0.5 - origin[2]) * 1000.0 # adjust noise size and origin 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 if vlbasis == 9: vlbasis = 14 # noise type's if ntype == 'multi_fractal': value = multi_fractal(ncoords, dimension, lacunarity, depth, nbasis) * 0.5 elif ntype == 'ridged_multi_fractal': value = ridged_multi_fractal(ncoords, dimension, lacunarity, depth, offset, gain, nbasis) * 0.5 elif ntype == 'hybrid_multi_fractal': value = hybrid_multi_fractal(ncoords, dimension, lacunarity, depth, offset, gain, nbasis) * 0.5 elif ntype == 'hetero_terrain': value = hetero_terrain(ncoords, dimension, lacunarity, depth, offset, nbasis) * 0.25 elif ntype == 'fractal': value = fractal(ncoords, dimension, lacunarity, depth, nbasis) elif ntype == 'turbulence_vector': value = turbulence_vector(ncoords, depth, hardnoise, nbasis)[0] elif ntype == 'variable_lacunarity': value = variable_lacunarity(ncoords, distortion, nbasis, vlbasis) + 0.5 elif ntype == 'marble_noise': 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 == 'shattered_hterrain': value = shattered_hterrain(ncoords[0], ncoords[1], ncoords[2], dimension, lacunarity, depth, offset, distortion, nbasis) elif ntype == 'strata_hterrain': value = strata_hterrain(ncoords[0], ncoords[1], ncoords[2], dimension, lacunarity, depth, offset, distortion, nbasis) elif ntype == 'planet_noise': value = planet_noise(ncoords, depth, hardnoise, nbasis)[2] * 0.5 + 0.5 else: value = 0.0 # adjust height if invert != 0: value = (1 - value) * height + heightoffset else: value = value * height + heightoffset # edge falloff if sphere == 0: # no edge falloff if spherical if falloff != 0: fallofftypes = [ 0, hypot(x * x, y * y), hypot(x, y), abs(y), abs(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 # strata / terrace / layered if stratatype != '0': strata = strata / height if stratatype == '1': strata *= 2 steps = (sin(value * strata * pi) * (0.1 / strata * pi)) value = (value * (1.0 - 0.5) + steps * 0.5) * 2.0 elif stratatype == '2': steps = -abs(sin(value * strata * pi) * (0.1 / strata * pi)) value = (value * (1.0 - 0.5) + steps * 0.5) * 2.0 elif stratatype == '3': steps = abs(sin(value * strata * pi) * (0.1 / strata * pi)) value = (value * (1.0 - 0.5) + steps * 0.5) * 2.0 else: value = value # clamp height if (value < sealevel): value = sealevel if (value > platlevel): value = platlevel return value