111 lines
6.4 KiB
Python
111 lines
6.4 KiB
Python
|
|
"""Prepare five Meshy props for Godot. Blender 5.0+, no paid API calls.
|
||
|
|
|
||
|
|
Source GLBs remain intact. Coordinates below come from inspected source rays;
|
||
|
|
the playable contact surfaces use the existing soul pose in metres. Blender
|
||
|
|
-Y exports as Godot +Z, which is the station's approach/occupant-facing side.
|
||
|
|
"""
|
||
|
|
import bpy,bmesh,json,math,hashlib
|
||
|
|
from pathlib import Path
|
||
|
|
from mathutils import Vector
|
||
|
|
ROOT=Path(__file__).resolve().parents[1]
|
||
|
|
SOURCE=ROOT/'tools/model_sources/equipment_meshy_v01'
|
||
|
|
OUT=ROOT/'Demon_v0.19/art/equipment/meshy_v01'
|
||
|
|
OUT.mkdir(parents=True,exist_ok=True)
|
||
|
|
|
||
|
|
def interp(value,knots):
|
||
|
|
for (a,b),(c,d) in zip(knots,knots[1:]):
|
||
|
|
if value<=c:return b+(value-a)*(d-b)/(c-a)
|
||
|
|
a,b=knots[-2];c,d=knots[-1]
|
||
|
|
return b+(value-a)*(d-b)/(c-a)
|
||
|
|
def symmetric(value,knots):return math.copysign(interp(abs(value),knots),value)
|
||
|
|
|
||
|
|
def part(name,c):
|
||
|
|
x,y,z=c
|
||
|
|
if name=='pillory':
|
||
|
|
return 'UpperYoke' if abs(x)<.335 and z>.131 and z<.26 else 'Body'
|
||
|
|
if name=='rack':
|
||
|
|
# Remove the source's empty cuffs/ropes. Runtime follows actual bones.
|
||
|
|
if .13<abs(x+.038)<.365 and .04<abs(y)<.14 and z>.044:return None
|
||
|
|
if abs(y)<.077 and z>.032:
|
||
|
|
if -.440<x<-.382:return 'HeadRoller'
|
||
|
|
if .302<x<.361:return 'FootRoller'
|
||
|
|
if x>.398 and z>.005:return None # replaced by functional crank
|
||
|
|
return 'Body'
|
||
|
|
if name=='wheel_vat':
|
||
|
|
# Cuffs are re-created on actual hands/feet rather than baked empty.
|
||
|
|
if .075<abs(x)<.195 and y<-.017 and (-.15<z<-.04 or .14<z<.26):return None
|
||
|
|
radius=math.hypot(x,z-.114)
|
||
|
|
if radius<.260 and z>-.149 and (abs(y)<.020 or radius<.100 and abs(y)<.060):return 'Wheel'
|
||
|
|
# Fixed side bearing ornament in the source intersects the rotor.
|
||
|
|
# Remove its ragged cut caps; clean authored frame caps replace it.
|
||
|
|
if .22<abs(x)<.36 and .02<z<.20 and abs(y)<.09:return None
|
||
|
|
if x>.355 and z>-.02:return None # functional side handle added locally
|
||
|
|
return 'Body'
|
||
|
|
return 'Body'
|
||
|
|
|
||
|
|
def point(name,p,group):
|
||
|
|
x,y,z=p
|
||
|
|
if name=='pillory':
|
||
|
|
return Vector((interp(x,[(-.480,-.99),(-.360,-.85),(-.185,-.59),(.015,0),(.195,.59),(.360,.85),(.480,.99)]),y*3.5,interp(z,[(-.397,0),(-.315,.10),(.131,1.70),(.395,2.48)])))
|
||
|
|
if name=='rack':
|
||
|
|
return Vector((-y*4.45,(x+.038)*3.62,interp(z,[(-.114,0),(-.090,.07),(.01,.82),(.037,.94),(.113,1.31)])))
|
||
|
|
if name=='wheel_vat':
|
||
|
|
if group=='Wheel':return Vector((x*5.04,y*3.5+.07,1.62+(z-.114)*5.04))
|
||
|
|
rear_clearance=min(1,max(0,(z+.16)/.20))*.20
|
||
|
|
return Vector((symmetric(x,[(0,0),(.26,1.30),(.31,1.43),(.478,1.87)]),y*3.4+rear_clearance,interp(z,[(-.365,0),(-.319,.10),(-.160,.99),(.114,1.62),(.17,1.80),(.369,2.9)])))
|
||
|
|
if name=='musical_chair':
|
||
|
|
depth=interp(y,[(-.262,-.90),(-.170,-.36),(-.020,.10),(.125,.48),(.261,.65)])
|
||
|
|
# Shorten only the cushion/apron, not the arms, legs or speaker cabinets.
|
||
|
|
# The front edge clears the seated thigh/knee sweep for all ten souls.
|
||
|
|
if abs(x)<.19 and -.235<z<-.11 and depth<.10:
|
||
|
|
depth=.10+(depth-.10)*.49
|
||
|
|
return Vector((symmetric(x,[(0,0),(.180,.48),(.218,.60),(.360,1.02),(.460,1.26)]),depth,interp(z,[(-.476,0),(-.440,.06),(-.123,.70),(-.020,1.06),(.153,1.75),(.292,2.18),(.476,2.65)])))
|
||
|
|
return Vector((x*3.64,y*3.64,interp(z,[(-.280,0),(-.200,.22),(-.154,.40),(.211,1.65),(.238,1.72),(.280,1.88)])))
|
||
|
|
|
||
|
|
report={}
|
||
|
|
for name in ['pillory','rack','wheel_vat','musical_chair','cauldron']:
|
||
|
|
bpy.ops.wm.read_factory_settings(use_empty=True)
|
||
|
|
source=SOURCE/name/'model.glb'
|
||
|
|
bpy.ops.import_scene.gltf(filepath=str(source))
|
||
|
|
original=next(o for o in bpy.context.scene.objects if o.type=='MESH')
|
||
|
|
bpy.context.view_layer.objects.active=original;original.select_set(True)
|
||
|
|
bpy.ops.object.transform_apply(location=True,rotation=True,scale=True)
|
||
|
|
labels={part(name,f.center) for f in original.data.polygons};labels.discard(None)
|
||
|
|
output=[]
|
||
|
|
for label in sorted(labels):
|
||
|
|
mesh=original.data.copy();bm=bmesh.new();bm.from_mesh(mesh)
|
||
|
|
bmesh.ops.delete(bm,geom=[f for f in bm.faces if part(name,f.calc_center_median())!=label],context='FACES')
|
||
|
|
bmesh.ops.delete(bm,geom=[v for v in bm.verts if not v.link_faces],context='VERTS')
|
||
|
|
for v in bm.verts:v.co=point(name,v.co,label)
|
||
|
|
# Source splits UV islands; welding retains per-loop UVs and removes cracks.
|
||
|
|
bmesh.ops.remove_doubles(bm,verts=list(bm.verts),dist=.00001)
|
||
|
|
bmesh.ops.delete(bm,geom=[f for f in bm.faces if f.calc_area()<1e-10],context='FACES')
|
||
|
|
bmesh.ops.recalc_face_normals(bm,faces=list(bm.faces))
|
||
|
|
bm.to_mesh(mesh);bm.free();mesh.update()
|
||
|
|
custom=mesh.attributes.get('custom_normal')
|
||
|
|
if custom:mesh.attributes.remove(custom)
|
||
|
|
for f in mesh.polygons:f.use_smooth=True
|
||
|
|
obj=bpy.data.objects.new(label,mesh);bpy.context.collection.objects.link(obj);output.append(obj)
|
||
|
|
bpy.data.objects.remove(original,do_unlink=True)
|
||
|
|
# Origins are real mechanical pivots. These objects are animated independently.
|
||
|
|
pivots={'Wheel':(0,.07,1.62),'HeadRoller':(0,(-.410+.038)*3.62,1.08),'FootRoller':(0,(.333+.038)*3.62,1.08)}
|
||
|
|
for obj in output:
|
||
|
|
if obj.name in pivots:
|
||
|
|
pivot=Vector(pivots[obj.name])
|
||
|
|
for v in obj.data.vertices:v.co-=pivot
|
||
|
|
obj.location=pivot
|
||
|
|
# Export game textures at 2K; keep the service's full 4K maps in source.glb.
|
||
|
|
for image in bpy.data.images:
|
||
|
|
if image.type=='IMAGE' and max(image.size)>2048:
|
||
|
|
factor=2048/max(image.size);image.scale(round(image.size[0]*factor),round(image.size[1]*factor))
|
||
|
|
points=[o.matrix_world@v.co for o in output for v in o.data.vertices]
|
||
|
|
bpy.context.view_layer.update()
|
||
|
|
points=[o.matrix_world@v.co for o in output for v in o.data.vertices]
|
||
|
|
lo=[min(v[i] for v in points) for i in range(3)];hi=[max(v[i] for v in points) for i in range(3)]
|
||
|
|
triangles=sum(len(f.vertices)-2 for o in output for f in o.data.polygons)
|
||
|
|
path=OUT/(name+'.glb')
|
||
|
|
bpy.ops.export_scene.gltf(filepath=str(path),export_format='GLB',export_yup=True,export_animations=False)
|
||
|
|
report[name]={'source_sha256':hashlib.sha256(source.read_bytes()).hexdigest(),'game_sha256':hashlib.sha256(path.read_bytes()).hexdigest(),'triangles':triangles,'blender_bounds':[lo,hi],'parts':[o.name for o in output]}
|
||
|
|
(OUT/'manifest.json').write_text(json.dumps(report,indent=2)+'\n')
|
||
|
|
print('EQUIPMENT_BUILD',json.dumps(report))
|