Files
Ornament-Generator-RNG/blender/festive_nameplates.py
T
2026-11-16 23:50:40 +03:00

47 lines
3.1 KiB
Python

import bpy,math,os
sc=bpy.context.scene;folder=os.path.dirname(bpy.data.filepath)
bpy.ops.wm.save_as_mainfile(filepath=os.path.join(folder,'map_before_festive_signs.blend'),copy=True)
roots=[o for o in sc.objects if o.type=='EMPTY' and o.name.startswith('Zone_') and o.name.endswith('_Nameplate')]
coll=bpy.data.collections.new('Festive_Nameplate_Details');sc.collection.children.link(coll)
def mat(name,c,metal=0,emit=0):
m=bpy.data.materials.new(name);m.use_nodes=True;m.diffuse_color=(*c,1)
p=next(n for n in m.node_tree.nodes if n.type=='BSDF_PRINCIPLED');p.inputs['Base Color'].default_value=(*c,1);p.inputs['Roughness'].default_value=.37;p.inputs['Metallic'].default_value=metal;p.inputs['Emission Color'].default_value=(*c,1);p.inputs['Emission Strength'].default_value=emit
return m
green=mat('Sign_Deep_Green',(.012,.105,.075));gold=mat('Sign_Gold',(.85,.43,.035),.65);red=mat('Sign_Red',(.65,.012,.025));leaf=mat('Sign_Pine',(.035,.19,.025));light=mat('Sign_Warm_Bulbs',(1,.65,.18),0,4)
snow=bpy.data.materials.get('Snow_Full_Soft')
def box(name,pos,size,material,root,angle=0):
bpy.ops.mesh.primitive_cube_add(size=1,location=pos);o=bpy.context.object;o.name=name;o.dimensions=size
bpy.ops.object.transform_apply(location=False,rotation=False,scale=True);o.rotation_euler.y=angle
for c in list(o.users_collection):c.objects.unlink(o)
coll.objects.link(o);o.parent=root;o.data.materials.append(material)
b=o.modifiers.new('Soft bevel','BEVEL');b.width=.045;b.segments=2
return o
for root in roots:
for o in list(root.children):
if o.name.startswith('Player_Name_Board'):o.hide_render=True;o.hide_set(True)
if o.type=='FONT':o.location.y=-.43;o.data.size=.63;o.data.extrude=.028
for j in range(4):box('Green_Timber',(0,-.06,2.36+j*.49),(6.4,.48,.475),green,root)
for z in (2.1,4.1):box('Gold_Rim',(0,-.12,z),(6.6,.6,.16),gold,root)
for x in (-3.25,3.25):box('Gold_Rim',(x,-.12,3.1),(.16,.6,2.05),gold,root)
for z in (2.27,3.94):
for x in (-2.65,-1.75,-.87,0,.87,1.75,2.65):box('Fairy_Light',(x,-.43,z),(.12,.12,.14),light,root)
for x in (-3.09,3.09):
for z in (2.75,3.45):box('Fairy_Light',(x,-.43,z),(.12,.12,.14),light,root)
for sign in (-1,1):
for j in range(5):
box('Evergreen_Sprig',(sign*(.5+j*.23),-.21,4.48+.11*math.sin(j)),(.62,.25,.20),leaf,root,sign*(.3+j*.16))
box('Bow_Loop',(sign*.43,-.48,4.51),(.85,.32,.47),red,root,sign*-.38)
box('Bow_Tail',(sign*.28,-.49,4.15),(.32,.23,.65),red,root,sign*.35)
box('Bow_Gold_Knot',(0,-.66,4.48),(.33,.27,.34),gold,root)
for x in (-2.9,2.9):
for z in (2.42,3.75):
for j in (-1,0,1):box('Corner_Pine',(x+j*.12,-.43,z),(.2,.18,.5),leaf,root,j*.6)
bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=1,radius=.22,location=(x,-.65,z))
o=bpy.context.object;o.name='Sign_Bauble'
for c in list(o.users_collection):c.objects.unlink(o)
coll.objects.link(o);o.parent=root;o.data.materials.append(red if z>3 else gold)
# Snow-capped post tops keep the same snow material as fences.
for x in (-2.7,2.7):box('Post_Snow',(x,0,3.82),(.65,.72,.23),snow,root)
path=os.path.join(folder,'map_festive_nameplates.blend');bpy.ops.wm.save_as_mainfile(filepath=path)
print('Restyled nameplates:',len(roots),path)