148 lines
10 KiB
Python
148 lines
10 KiB
Python
"""Batch 4 (2026-11-23, from build3.py): models/conv4 (fixups + UV anim/lights/step visibility; multi-view kept), FDIDs 8810100+,
|
|
batch-3 models reused, ItemDisplayInfoModelMatRes emitted. Batch 3 notes:: Octo item models that are not in the client, for displays of appearance-less items.
|
|
Octo MD20 v256 -> m2_equipment_convert (models/conv) -> MD21/SFID/TXID container on new FDIDs 8810000+ (m2, skin).
|
|
Hardcoded textures: the client FDID holding Octo's exact bytes (content-key match), else the native file of that path.
|
|
Rows: ModelFileData (new ModelResources 2100001+, L/R shoulders share one), ComponentModelFileData for shoulders
|
|
(GenderIndex 2, PositionIndex 0 left / 1 right, as native), then ItemDisplayInfo / materials / IA / IMA like rows.py.
|
|
Only displays whose every model converted are emitted; the rest stay held."""
|
|
import json, struct, sys, hashlib, collections
|
|
from pathlib import Path
|
|
sys.path.insert(0, '/mnt/Games/@project/wt-master-merge/ops'); sys.path.insert(0, '/mnt/Games/@project/gateway/ops/maps14-20261122')
|
|
from casc_asset_package import model_container
|
|
import octo_mpq
|
|
W = Path('/mnt/Games/@project/gateway/runtime/continuation-20261113/claude-lane/item-displays-20261123')
|
|
C = Path('/mnt/Games/@project/gateway/runtime/continuation-20261113/claude-lane/content/item-sickle7-2ecc-20261123/db2')
|
|
S = '/tmp/claude-1000/-home-praxis-Projects/c41b4c2f-f4c2-4e21-8c6d-a961250d8864/scratchpad'
|
|
PREFIX = 'add7'; FD0 = 8810700
|
|
md5 = lambda b: hashlib.md5(b).hexdigest()
|
|
def tsv(path):
|
|
for l in open(path):
|
|
p = l.rstrip('\n').split('\t'); yield dict(x.split('=', 1) for x in p[1:])
|
|
ck = json.load(open(W / 'root-ckeys.json')); root = set(json.load(open(W / 'root-fdids.json')))
|
|
assert not any(FD0 <= f < FD0 + 1000 for f in root)
|
|
lf = {}
|
|
for l in open('/mnt/Games/@project/listfiles/community-listfile.csv', errors='replace'):
|
|
i, _, p = l.rstrip('\n').partition(';'); lf[p.lower()] = int(i)
|
|
def tex_fdid(path):
|
|
try: h = md5(octo_mpq.read(path))
|
|
except Exception: h = None
|
|
if h and h in ck: return min(ck[h])
|
|
f = lf.get(path.lower().replace('\\', '/'))
|
|
assert f in root, path
|
|
return f
|
|
# --- containers
|
|
conv = json.load(open(W / 'models/conv7/manifest.json'))
|
|
prev3 = {**json.load(open(W / 'add3-models.json'))['models'], **json.load(open(W / 'add4-models.json'))['models']}
|
|
out_dir = W / 'models/out7'; out_dir.mkdir(exist_ok=True)
|
|
models = {}; art = []; nxt = FD0
|
|
for r in sorted(conv['records'], key=lambda r: r['source_candidates'][0]['member']):
|
|
if not r['structural_conversion_complete']: continue
|
|
member = r['source_candidates'][0]['member']; base = member[:-3]
|
|
if base.split('/')[-1] in prev3: continue
|
|
body = (W / 'models/conv7' / (r['source_sha256'] + '.md20')).read_bytes()
|
|
skinl = [(W / 'models/conv7' / o['file']).read_bytes() for o in r['outputs'] if o['role'] == 'native-skin']
|
|
n, o = struct.unpack_from('<II', body, 80); txid = []
|
|
for i in range(n):
|
|
t, _, ln, no = struct.unpack_from('<IIII', body, o + 16 * i)
|
|
txid.append(tex_fdid(body[no:no + ln].rstrip(b'\0').decode('latin1')) if t == 0 else 0)
|
|
m2f = nxt; skfs = list(range(nxt + 1, nxt + 1 + len(skinl))); nxt += 1 + len(skinl)
|
|
m2 = model_container(body, skfs, txid)
|
|
box = list(struct.unpack_from('<6f', body, 0xA0))
|
|
(out_dir / f'{m2f}.m2').write_bytes(m2)
|
|
art.append(dict(file_data_id=m2f, path=base + '.m2', ckey=md5(m2), kind='M2', file=str(out_dir / f'{m2f}.m2')))
|
|
for v, (skf, skin) in enumerate(zip(skfs, skinl)):
|
|
(out_dir / f'{skf}.skin').write_bytes(skin)
|
|
art.append(dict(file_data_id=skf, path=base + f'{v:02}.skin', ckey=md5(skin), kind='SKIN', file=str(out_dir / f'{skf}.skin')))
|
|
models[base.split('/')[-1]] = dict(m2=m2f, skins=skfs, box=box, txid=txid, member=member)
|
|
json.dump(dict(models=models, art=art), open(W / f'{PREFIX}-models.json', 'w'), indent=1)
|
|
# --- rows
|
|
tfd = {int(r['FileDataID']): int(r['MaterialResourcesID']) for r in tsv(C / 'TextureFileData.tsv')}
|
|
mfd = {int(r['FileDataID']): int(r['ModelResourcesID']) for r in tsv(C / 'ModelFileData.tsv')}
|
|
items = {int(r['ID']): r for r in tsv(f'{S}/itemdb2/Item.tsv')}
|
|
apps = collections.defaultdict(list)
|
|
for f in ('add', 'add2', 'add3', 'add4', 'add5', 'add6'):
|
|
for r in json.load(open(W / f'{f}-ItemAppearance.json')): apps[r['ItemDisplayInfoID']].append(r['ID'])
|
|
for r in tsv(f'{S}/itemdb2/ItemAppearance.tsv'):
|
|
if r['TransmogPlayerConditionID'] == '0': apps[int(r['ItemDisplayInfoID'])].append(int(r['ID']))
|
|
prev_ia = json.load(open(f'{S}/ia-add.json')) + json.load(open(W / 'add-ItemAppearance.json')) + json.load(open(W / 'add2-ItemAppearance.json')) + [r for f in ('add3', 'add4', 'add5', 'add6') for r in json.load(open(W / f'{f}-ItemAppearance.json'))]
|
|
prev_ima = json.load(open(f'{S}/ima-add.json')) + json.load(open(W / 'add-ItemModifiedAppearance.json')) + json.load(open(W / 'add2-ItemModifiedAppearance.json')) + [r for f in ('add3', 'add4', 'add5', 'add6') for r in json.load(open(W / f'{f}-ItemModifiedAppearance.json'))]
|
|
nia = max(r['ID'] for r in prev_ia) + 1; nima = max(r['ID'] for r in prev_ima) + 1
|
|
nmr = max(tfd.values()) + 1; nmres = max(v for v in mfd.values() if v < 2200000) + 1
|
|
for nm, md in prev3.items(): mfd[md['m2']] = mfd[md['m2']]
|
|
nidimr = max(r['ID'] for f in ('add', 'add2') for r in json.load(open(W / f'{f}-ItemDisplayInfoMaterialRes.json'))) + 1
|
|
import subprocess
|
|
nmmr = 1 + max(int(l.split('\t')[0]) for l in subprocess.run(['dotnet', '/mnt/Games/@project/wt-merge/ops/db2-bake-20261122/tool/bin/Debug/net10.0/Db2Bake.dll', 'dump', str(C.parent / 'inputs/before'), '/mnt/Games/@project/tools/WoWDBDefs/definitions', 'ItemDisplayInfoModelMatRes'], capture_output=True, text=True, check=True).stdout.splitlines())
|
|
HELM_KEEP = {(245, 245), (247, 247), (248, 306), (249, 305)}
|
|
R = json.load(open(W / 'resolved.json')); plan = json.load(open(f'{S}/ima-plan.json'))
|
|
done_before = {r['ID'] for f in ('add', 'add2', 'add3', 'add4', 'add5', 'add6') for r in json.load(open(W / f'{f}-ItemDisplayInfo.json'))}
|
|
out = collections.defaultdict(list); done = {}; holds = []; mres_of = {}
|
|
def mat_res(fids):
|
|
global nmr
|
|
have = {tfd[f] for f in fids if f in tfd}
|
|
if have: return min(have) if all(f in tfd for f in fids) else None
|
|
m = nmr; nmr += 1
|
|
for f in fids: out['TextureFileData'].append(dict(ID=f, FileDataID=f, UsageType=0, MaterialResourcesID=m)); tfd[f] = m
|
|
return m
|
|
def model_res(names): # one ModelResources for a display's model set (L+R shoulder share)
|
|
global nmres
|
|
key = tuple(sorted(names))
|
|
if key in mres_of: return mres_of[key]
|
|
m = nmres; nmres += 1; mres_of[key] = m
|
|
for nm in names:
|
|
md = models[nm]
|
|
if any(r['FileDataID'] == md['m2'] for r in out['ModelFileData']): raise ValueError(f'{nm} in two resource sets')
|
|
out['ModelFileData'].append(dict(ID=md['m2'], GeoBox=[0] * 6, FileDataID=md['m2'], Flags=0, LodCount=0, ModelResourcesID=m))
|
|
if nm.startswith(('lshoulder', 'rshoulder', 'custom_puffed_sleeves_', 'custom_xmas_shoulder_')):
|
|
pos = 0 if (nm.startswith('lshoulder') or nm.endswith(('lshoulder_001', '_lshoulder'))) else 1
|
|
out['ComponentModelFileData'].append(dict(ID=md['m2'], GenderIndex=2, ClassID=0, RaceID=0, PositionIndex=pos))
|
|
return m
|
|
for x in R:
|
|
d = x['display']
|
|
if x['cls'] in ('icon-only', 'no-octo-row') or d in done_before: continue
|
|
mp = [p for p in x['parts'] if p['kind'] == 'model']
|
|
names = [p['name'].lower().rsplit('.', 1)[0] for p in mp]
|
|
native = {}
|
|
for p, n in zip(mp, names):
|
|
if n not in models and n in prev3: native[p['side']] = mfd[prev3[n]['m2']]
|
|
elif n not in models and p['in_root'] and any(f in mfd for f in p['in_root']): native[p['side']] = mfd[min(f for f in p['in_root'] if f in mfd)]
|
|
miss = [n for p, n in zip(mp, names) if n not in models and p['side'] not in native]
|
|
if miss: holds.append((d, 'model not converted: ' + ','.join(miss))); continue
|
|
mmr = [0, 0]; mats = []; bad = None
|
|
for p in x['parts']:
|
|
if p['kind'] == 'model': continue
|
|
of = p.get('octo_files', {})
|
|
if len(of) > 1: # same name in several item folders: the one beside this display's model
|
|
dirs = {models[n]['member'].split('/')[-2] for n in names}
|
|
of = {k: v for k, v in of.items() if k.lower().split('\\')[-2] in dirs} or of
|
|
fl = sorted({v[0] for v in of.values() if v}) or sorted(p['in_root'])
|
|
if not fl or not all(p.get('octo_files', {'x': [1]}).values()): bad = f"{p['kind']} {p['name']} has no client file"; break
|
|
m = mat_res(fl)
|
|
if m is None: bad = f"{p['name']} split material groups"; break
|
|
if p['kind'] == 'modeltex': mmr[p['side']] = m
|
|
else: mats.append((p['section'], m))
|
|
if bad: holds.append((d, bad)); continue
|
|
if len(names) == 2 and names[0] != names[1] and not native:
|
|
r = model_res(names); mres = [r, r]
|
|
if not mmr[1]: mmr[1] = mmr[0]
|
|
else:
|
|
mres = [0, 0]
|
|
for p in mp: mres[p['side']] = native.get(p['side']) or model_res([p['name'].lower().rsplit('.', 1)[0]])
|
|
hv = tuple(x['helmvis']); hv = list(hv) if hv in HELM_KEEP else [0, 0]
|
|
out['ItemDisplayInfo'].append(dict(ID=d, ItemVisual=x['item_visual'], Flags=0, ModelResourcesID=mres, ModelMaterialResourcesID=mmr,
|
|
ModelType=[0, 0], GeosetGroup=list(x['geosets']) + [0] * 3, AttachmentGeosetGroup=[0] * 6, HelmetGeosetVis=hv))
|
|
for i, m in enumerate(mmr):
|
|
if m: out['ItemDisplayInfoModelMatRes'].append(dict(ID=nmmr, MaterialResourcesID=m, TextureType=2, ModelIndex=i, ItemDisplayInfoID=d)); globals()['nmmr'] += 1
|
|
for sec, m in mats:
|
|
out['ItemDisplayInfoMaterialRes'].append(dict(ID=nidimr, ComponentSection=sec, MaterialResourcesID=m, ItemDisplayInfoID=d)); nidimr += 1
|
|
done[d] = True
|
|
for item, d, inv in plan['conv']:
|
|
if d not in done: continue
|
|
if d in apps: a = min(apps[d])
|
|
else:
|
|
a = nia; nia += 1; apps[d].append(a)
|
|
out['ItemAppearance'].append(dict(ID=a, DisplayType=0, ItemDisplayInfoID=d, DefaultIconFileDataID=int(items[item]['IconFileDataID']), UiOrder=0, TransmogPlayerConditionID=0))
|
|
out['ItemModifiedAppearance'].append(dict(ID=nima, ItemID=item, ItemAppearanceModifierID=0, ItemAppearanceID=a, OrderIndex=0, TransmogSourceTypeEnum=0, Flags=0)); nima += 1
|
|
for t, rows in out.items(): json.dump(rows, open(W / f'{PREFIX}-{t}.json', 'w'))
|
|
json.dump(holds, open(W / f'{PREFIX}-holds.json', 'w'), indent=0)
|
|
print('models', len(models), {t: len(v) for t, v in out.items()}, 'displays', len(done), 'holds', len(holds))
|