Files
Diabolo/tools/finish_infernal.py
T

41 lines
3.0 KiB
Python
Raw Normal View History

"""Finish paint from the rig checkpoint without repeating geometry conversion."""
import sys,json,bpy
from pathlib import Path
from mathutils import Matrix
sys.path.insert(0,str(Path(__file__).resolve().parent))
from infernal_bake import bake
from infernal_skinning import refine_weights
from infernal_whip import transfer_whip
r=Path(__file__).resolve().parent.parent;out=r/'Demon_v0.19/reviews/infernal_v01';qa=r/'Demon_v0.19/captures/infernal'
bpy.ops.wm.open_mainfile(filepath=str(qa/'retarget_checkpoint.blend'))
scene=bpy.context.scene;low=bpy.data.objects['Infernal_Game_Mesh'];rig=bpy.data.objects['INFERNAL_RIG'];high=bpy.data.objects['Infernal_High_Source_No_Pedestal']
source=next(o for o in scene.objects if o.type=='ARMATURE' and o!=rig)
materials=list(high.data.materials);palette=[(m.name,tuple(m.diffuse_color[:3]),next(n for n in m.node_tree.nodes if n.type=='BSDF_PRINCIPLED').inputs['Roughness'].default_value,next(n for n in m.node_tree.nodes if n.type=='BSDF_PRINCIPLED').inputs['Metallic'].default_value) for m in materials]
def log(*args):print('INFERNAL',*args,flush=True)
refine_weights(low)
# Keep exposed arms red; the hair mask must not paint forearms black.
from mathutils.kdtree import KDTree
kd=KDTree(len(low.data.vertices))
for vertex in low.data.vertices:kd.insert(vertex.co,vertex.index)
kd.balance();regions=low.data.attributes['SemanticRegion'].data
for face in high.data.polygons:
_,index,_=kd.find(face.center)
if regions[index].value in [4,5]:face.material_index=2 if face.center.z+.15<1.025 and abs(face.center.x)>.245 else 0
bake(scene,high,low,materials,palette,out,log)
whip=transfer_whip(scene,source,rig)
for track in rig.animation_data.nla_tracks:track.mute=False
rig.animation_data.action=None;scene.frame_set(1)
for bone in rig.pose.bones:bone.matrix_basis=Matrix.Identity(4)
bpy.ops.object.select_all(action='DESELECT');low.select_set(True);rig.select_set(True)
if whip:whip.select_set(True)
bpy.context.view_layer.objects.active=low
bpy.ops.export_scene.gltf(filepath=str(out/'infernal_game.glb'),export_format='GLB',use_selection=True,export_animations=True,export_animation_mode='NLA_TRACKS',export_nla_strips=True,export_force_sampling=True,export_frame_range=False,export_skins=True,export_materials='EXPORT',export_yup=True)
report=json.loads((out/'manifest.json').read_text());report.update(textures_4k=True,animated_whip=whip is not None,facial_paint='aligned to sculpt: eyes z1.889, lips z1.817',game_vertices=len(low.data.vertices),game_triangles=len(low.data.polygons))
report.update(paint_boundary_reference='tools/model_sources/approved_paint_boundary.png',whip_radius_added_m=.008,approval_status='awaiting_visual_approval')
(out/'manifest.json').write_text(json.dumps(report,indent=2));log('FINISHED',report)
for obj in list(scene.objects):
if obj not in [rig,low,whip]:bpy.data.objects.remove(obj,do_unlink=True)
bpy.data.orphans_purge(do_recursive=True)
bpy.context.preferences.filepaths.save_version=0
bpy.ops.wm.save_as_mainfile(filepath=str(r/'tools/model_sources/infernal_game.blend'))