Files
AstraWeapons/tools/build_visuals_v2.py

65 lines
3.8 KiB
Python

"""Stable hand models driven by vanilla swing animations, plus timed slash frames."""
from pathlib import Path
import json, math
from PIL import Image
ROOT = Path(__file__).resolve().parents[1] / 'src/main/resources'
D = ROOT / 'defaults/resources/assets/astraweapons'
def write(path, value):
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(json.dumps(value, ensure_ascii=False, indent=2)+'\n', encoding='utf-8')
def model(name):
return {'type':'minecraft:model','model':name}
def hand_item(name, parent, gui, display):
write(D/f'models/v2/{name}.json', {'parent':parent, 'display':display})
write(D/f'items/v2/{name}.json', {'hand_animation_on_swap':False, 'model':{
'type':'minecraft:select','property':'minecraft:display_context',
'cases':[{'when':['gui','ground','fixed'],'model':model(gui)}],
'fallback':model(f'astraweapons:v2/{name}')}})
def main():
# No third-person pose offsets: the glove stays attached to the wrist while
# the vanilla STAB/WHACK animation moves the actual arm with frame interpolation.
base=json.loads((D/'models/item/iron_gauntlet_3d.json').read_text(encoding='utf-8'))
for pose, pitch, roll in [('guard',0,0),('jab',0,0),('hook',0,12),('uppercut',-12,0),('lunge',0,0)]:
display={}
for side,sign in [('righthand',1),('lefthand',-1)]:
src=base['display']['firstperson_'+side]
display['firstperson_'+side]={'rotation':[src['rotation'][0]+pitch,0,sign*(-8+roll)],
'translation':[sign*.5,5.0,0], 'scale':[.9,.9,.9]}
hand_item(pose,'astraweapons:item/iron_gauntlet_3d','astraweapons:item/iron_gauntlet_2d',display)
hand_item('twinblade','astraplus:item/netherite_twinblade','astraplus:internal/twinblade_gui',{
'firstperson_righthand':{'rotation':[0,-90,55],'translation':[1.1,1.4,0],'scale':[1.85,1.85,.68]},
'firstperson_lefthand':{'rotation':[0,90,-55],'translation':[1.1,1.4,0],'scale':[1.85,1.85,.68]}})
# Each transient display selects frames by its own age. No globally running
# animated texture, so every slash starts at the beginning of the same trail.
for fiery in (False, True):
for frame in range(4):
name=f'slash_{"fire_" if fiery else ""}{frame}'
size=192; im=Image.new('RGBA',(size,size))
lead=(-.9,-.15,.6,1.15)[frame]
for y in range(size):
for x in range(size):
dx=(x+.5-size/2)/(size/2);z=(y+.5-size/2)/(size/2)
r=math.hypot(dx,z);a=math.atan2(dx,z)
tail=lead-a
if z<=0 or not 0<tail<1.65:continue
width=.09*(1-tail/1.65)*(1-frame*.13)
outer=.87+frame*.02
if outer-width<r<outer:
core=(outer-r)<width*.4
rgb=((255,247,205) if core else (255,158,45)) if fiery else ((255,255,255) if core else (185,180,221))
im.putpixel((x,y),(*rgb,255))
path=D/f'textures/item/v2/{name}.png';path.parent.mkdir(parents=True,exist_ok=True);im.save(path)
write(D/f'models/v2/{name}.json',{'textures':{'slash':f'astraweapons:item/v2/{name}','particle':f'astraweapons:item/v2/{name}'},
'elements':[{'from':[0,8,0],'to':[16,8,16],'shade':False,'light_emission':15,'faces':{
'up':{'texture':'#slash','uv':[0,0,16,16]},'down':{'texture':'#slash','uv':[0,0,16,16],'rotation':180}}}]})
write(D/f'items/v2/{name}.json',{'model':model(f'astraweapons:v2/{name}')})
index=sorted(str(f.relative_to(ROOT/'defaults')).replace('\\','/') for f in (ROOT/'defaults').rglob('*') if f.is_file())
(ROOT/'weapons-index.txt').write_text('\n'.join(index)+'\n',encoding='utf-8')
if __name__=='__main__':main()