49 lines
2.7 KiB
Python
49 lines
2.7 KiB
Python
import bpy, math, random, os
|
|
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_asphalt.blend'),copy=True)
|
|
m=bpy.data.materials.new('Asphalt_Stylized_BlueGrey');m.use_nodes=True;m.diffuse_color=(.12,.16,.205,1)
|
|
n=m.node_tree.nodes;l=m.node_tree.links;p=next(x for x in n if x.type=='BSDF_PRINCIPLED')
|
|
p.inputs['Roughness'].default_value=.92
|
|
tex=n.new('ShaderNodeTexNoise');tex.inputs['Scale'].default_value=.45;tex.inputs['Detail'].default_value=0
|
|
coord=n.new('ShaderNodeTexCoord');l.new(coord.outputs['Object'],tex.inputs['Vector'])
|
|
r=n.new('ShaderNodeValToRGB');r.color_ramp.elements[0].color=(.105,.14,.18,1);r.color_ramp.elements[1].color=(.15,.19,.235,1)
|
|
l.new(tex.outputs['Fac'],r.inputs[0]);l.new(r.outputs[0],p.inputs['Base Color'])
|
|
changed=[]
|
|
for o in sc.objects:
|
|
if o.type!='MESH' or o.name not in ('Paths','Plaza_Inner_Tiles','Plaza_Inner_Ring'):continue
|
|
for i,old in enumerate(o.data.materials):
|
|
if old and ('Tile' in old.name or o.name=='Plaza_Inner_Ring'):o.data.materials[i]=m
|
|
changed.append(o.name)
|
|
snow=bpy.data.materials.get('Snow_Full_Soft') or bpy.data.materials.get('Snow_Soft')
|
|
coll=bpy.data.collections.new('Asphalt_Edge_Snowdrifts');sc.collection.children.link(coll)
|
|
rng=random.Random(71)
|
|
def mound(x,y,z,length,width,height,angle):
|
|
bpy.ops.mesh.primitive_uv_sphere_add(segments=16,ring_count=8,radius=1,location=(x,y,z))
|
|
o=bpy.context.object;o.name='Asphalt_Snowbank'
|
|
for v in o.data.vertices:
|
|
a=math.atan2(v.co.y,v.co.x);f=1+.10*math.sin(a*3+angle)+.055*math.cos(a*5)
|
|
v.co.x*=length*f;v.co.y*=width*f;v.co.z*=height
|
|
o.rotation_euler.z=angle
|
|
for c in list(o.users_collection):c.objects.unlink(o)
|
|
coll.objects.link(o)
|
|
if snow:o.data.materials.append(snow)
|
|
for p in o.data.polygons:p.use_smooth=True
|
|
# Patchy snow around the central disc, keeping each radial entrance open.
|
|
for i in range(10):
|
|
center=i*math.tau/10
|
|
for off in (.19,.31,.43):
|
|
a=center+off;r0=38.2+rng.uniform(-.5,.6)
|
|
mound(-math.sin(a)*r0,math.cos(a)*r0,.65,rng.uniform(2,3.8),rng.uniform(.9,1.8),rng.uniform(.3,.65),a)
|
|
# Drifts accumulate at the sides of the paths rather than crossing them.
|
|
for i in range(10):
|
|
a=i*math.tau/10;d=Vector((-math.sin(a),math.cos(a),0));s=Vector((math.cos(a),math.sin(a),0))
|
|
for side in (-1,1):
|
|
for t in (44,55,66):
|
|
if rng.random()<.22:continue
|
|
pos=d*(t+rng.uniform(-2,2))+s*(side*rng.uniform(4.4,5.4))
|
|
mound(pos.x,pos.y,.65,rng.uniform(2.1,4.1),rng.uniform(.8,1.4),rng.uniform(.28,.6),a+math.pi/2)
|
|
path=os.path.join(folder,'map_compact_asphalt.blend')
|
|
bpy.ops.wm.save_as_mainfile(filepath=path)
|
|
print('Changed:',changed,'Snowbanks:',len(coll.objects),'Saved:',path)
|