43 lines
2.2 KiB
Python
43 lines
2.2 KiB
Python
import bpy,math,random,os,bmesh
|
|
from mathutils import Vector
|
|
sc=bpy.context.scene;folder=os.path.dirname(bpy.data.filepath)
|
|
bpy.ops.wm.save_as_mainfile(filepath=os.path.join(folder,'map_before_terrain_drifts.blend'),copy=True)
|
|
coll=bpy.data.collections.new('Landscape_Snowdrifts');sc.collection.children.link(coll)
|
|
mat=bpy.data.materials.get('Snow_Full_Soft') or bpy.data.materials.get('Snow')
|
|
rng=random.Random(814)
|
|
def hill(x,y,rx,ry,h,angle,index):
|
|
N=32;R=10;verts=[(x,y,h-.1)];faces=[]
|
|
for j in range(1,R+1):
|
|
r=j/R
|
|
for k in range(N):
|
|
a=k*math.tau/N
|
|
edge=1+.10*math.sin(3*a+index)+.055*math.cos(5*a-index)
|
|
u=math.cos(a)*rx*r*edge;v=math.sin(a)*ry*r*edge
|
|
z=h*(1-r*r)**2-.10
|
|
z+=h*.09*math.sin(a*2+index)*r*(1-r)
|
|
verts.append((x+u*math.cos(angle)-v*math.sin(angle),y+u*math.sin(angle)+v*math.cos(angle),z))
|
|
for k in range(N):faces.append((0,k+1,(k+1)%N+1))
|
|
for j in range(R-1):
|
|
for k in range(N):
|
|
a=1+j*N+k;b=1+j*N+(k+1)%N;faces.append((a,a+N,b+N,b))
|
|
faces.append(tuple(reversed([1+(R-1)*N+k for k in range(N)])))
|
|
me=bpy.data.meshes.new('SoftSnowHill');me.from_pydata(verts,[],faces);me.update()
|
|
bm=bmesh.new();bm.from_mesh(me);bmesh.ops.recalc_face_normals(bm,faces=list(bm.faces));bm.to_mesh(me);bm.free()
|
|
o=bpy.data.objects.new('Landscape_Drift_%02d'%index,me);coll.objects.link(o)
|
|
if mat:me.materials.append(mat)
|
|
for p in me.polygons:p.use_smooth=True
|
|
idx=0
|
|
for sector in range(10):
|
|
# Outside the plots, raised snowy banks follow the island perimeter.
|
|
a=sector*math.tau/10+.10
|
|
r=123+rng.uniform(-2,2)
|
|
hill(-math.sin(a)*r,math.cos(a)*r,rng.uniform(9,12),rng.uniform(4.5,6.5),rng.uniform(1.6,2.8),a,idx);idx+=1
|
|
# In the open wedges between radial paths, below the plot ring.
|
|
a=(sector+.5)*math.tau/10;r=59+rng.uniform(-3,3)
|
|
hill(-math.sin(a)*r,math.cos(a)*r,rng.uniform(4,5.5),rng.uniform(6,8),rng.uniform(1.0,1.8),a,idx);idx+=1
|
|
# Smaller bank outside each plot corner, avoiding its gate.
|
|
a=(sector+.48)*math.tau/10;r=112
|
|
hill(-math.sin(a)*r,math.cos(a)*r,4.5,6.0,rng.uniform(1.1,1.9),a,idx);idx+=1
|
|
path=os.path.join(folder,'map_landscape_snow.blend');bpy.ops.wm.save_as_mainfile(filepath=path)
|
|
print('Added',len(coll.objects),'smooth landscape snowdrifts. Saved',path)
|