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

64 lines
4.3 KiB
Python

import bpy,math,os,ast
from mathutils import Vector
OUT=r'C:\roblox\Ornament Generator RNG\shop'
bpy.ops.wm.open_mainfile(filepath=os.path.join(OUT,'christmas_shop_v2.blend'))
sc=bpy.context.scene
for node in ast.parse(open(os.path.join(OUT,'build_shop.py'),encoding='utf-8-sig').read()).body:
if isinstance(node,ast.FunctionDef):exec(compile(ast.Module(body=[node],type_ignores=[]),'helpers','exec'))
wood=bpy.data.materials['Warm satin chestnut'];wood2=bpy.data.materials['Wood trim'];red=bpy.data.materials['Christmas scarlet'];gold=bpy.data.materials['Warm gold'];green=bpy.data.materials['Holly green'];snow=bpy.data.materials['Soft snow'];inner=bpy.data.materials['Ribbon lining']
for o in list(sc.objects):
if o.name.startswith(('Timber post','Red ribbon','Gold ribbon','Ribbon fishtail','Tail gold','Holly leaf','Bow berry','Post capital')):bpy.data.objects.remove(o,do_unlink=True)
for x in (-4.25,4.25):
for y in (-1.75,1.75):
box('Structural timber post',(x,y,2.5),(.57,.57,4.25),wood,.055)
for z in (.6,4.43):box('Post moulding',(x,y,z),(.78,.78,.3),wood2,.055)
# Closed ribbon loop shell; front and rear are both in front of the snow.
def bow(cx,cy,cz,s=1,prefix='Main bow'):
for side in (-1,1):
vs=[];N=64;W=12
for i in range(N):
a=i*math.tau/N;x=.08+.83*(1-math.cos(a));f=(x/1.74)**.65
for j in range(W+1):
u=j/W
vs.append((cx+s*side*x*(1-.13*u),cy+s*u*(.22+.35*f),cz+s*(.10*(1-math.cos(a))+.24*math.sin(a)+.91*u*f+.08*math.sin(math.pi*u))))
fs=[(i*(W+1)+j,((i+1)%N)*(W+1)+j,((i+1)%N)*(W+1)+j+1,i*(W+1)+j+1) for i in range(N) for j in range(W)]
o=mesh(prefix+' loop',vs,fs,red,True);o.data.materials.append(inner);so=o.modifiers.new('Ribbon lining','SOLIDIFY');so.thickness=.045*s;so.material_offset=1
for j in (0,W):curve(prefix+' gold hem',[vs[i*(W+1)+j] for i in range(N)]+[vs[j]],.038*s,gold)
vs=[];T=16;K=8
for j in range(T+1):
t=j/T;w=.17+.19*t
for k in range(K+1):
u=k/K*2-1;notch=.22*(1-abs(u))*max(0,(t-.8)/.2)
vs.append((cx+s*side*(.14+.64*t+u*w),cy-s*(.03+.08*t+.04*(1-u*u)),cz+s*(-.85*t+notch)))
fs=[(j*(K+1)+k,j*(K+1)+k+1,(j+1)*(K+1)+k+1,(j+1)*(K+1)+k) for j in range(T) for k in range(K)]
o=mesh(prefix+' fishtail',vs,fs,red,True);so=o.modifiers.new('Fabric thickness','SOLIDIFY');so.thickness=.04*s
boundary=[vs[j*(K+1)] for j in range(T+1)]+[vs[T*(K+1)+k] for k in range(1,K+1)]+[vs[j*(K+1)+K] for j in range(T-1,-1,-1)]
curve(prefix+' tail trim',boundary+[boundary[0]],.022*s,gold)
for dx,dz in [(0,.20),(-.17,-.05),(.17,-.05)]:ball(prefix+' berry',(cx+s*dx,cy-.10*s,cz+s*dz),(.18*s,.15*s,.18*s),red)
bow(0,-3.48,6.35)
# Gold-backed mounting bracket joins the bow and roof ridge.
beam('Bow mounting bracket',(0,-2.2,6.5),(0,-3.1,6.5),.16,wood)
for side in (-1,1):bow(side*4.25,-2.34,2.5,.21,'Candy cane bow')
# Bring the tree out from behind the stall so its full silhouette is visible.
for o in sc.objects:
if o.name.startswith(('Scalloped fir','Fir soft snow','Fir trunk')):o.location.x-=.40;o.location.y-=.45
# Warm, saturated roof and timber; softly illuminated displays.
p=next(n for n in red.node_tree.nodes if n.type=='BSDF_PRINCIPLED');p.inputs['Base Color'].default_value=(.55,.008,.018,1);p.inputs['Roughness'].default_value=.38
for name in ('Warm satin chestnut','Wood trim'):
m=bpy.data.materials[name];p=next(n for n in m.node_tree.nodes if n.type=='BSDF_PRINCIPLED');p.inputs['Roughness'].default_value=.48
for o in sc.objects:
if o.type=='LIGHT' and o.name.startswith('Interior'):o.data.energy=220
sc.camera.location=(5.5,-25,8.7);sc.camera.rotation_euler=(Vector((-.15,0,3.6))-sc.camera.location).to_track_quat('-Z','Y').to_euler();sc.camera.data.ortho_scale=14
sc.view_settings.look='AgX - Medium High Contrast'
sc.cycles.samples=48;sc.render.resolution_percentage=90
# Organize studio separately so the model can be exported cleanly.
asset=bpy.data.collections.new('SHOP_MODEL');sc.collection.children.link(asset)
studio=bpy.data.collections.new('STUDIO_RENDER_ONLY');sc.collection.children.link(studio)
for o in list(sc.objects):
target=studio if o.type in ('CAMERA','LIGHT') or o.name=='Studio ground' else asset
for c in list(o.users_collection):c.objects.unlink(o)
target.objects.link(o)
sc.render.filepath=os.path.join(OUT,'christmas_shop_final_preview.png')
bpy.ops.wm.save_as_mainfile(filepath=os.path.join(OUT,'christmas_shop_final.blend'))
bpy.ops.render.render(write_still=True)