"""Exact original Scooter resources, material links and source-pivot expansion.""" from pathlib import Path import hashlib import json import sys import tempfile import unittest from unittest.mock import patch ROOT = Path(__file__).resolve().parents[1] ORIGINAL = ROOT.parent/'Original' sys.path.insert(0, str(ROOT/'tools/extractors')) sys.path.insert(0, str(ROOT/'tools/binary')) from scooter_resources import (CANVASES, CLIPS, JIMMY_RGBA_SHA256, SOURCES, export_scooter) from ase import expand_mesh, read_ase from entities import resolve_asset from omt import Database, FormatError, read_canvas, read_shape from pe_inspect import PE from checkpoint_script_state import read_va @unittest.skipUnless(ORIGINAL.exists(), 'Original resources are local fixtures') class ScooterResourceTests(unittest.TestCase): def test_exact_omt_shapes_canvas_pixels_and_material_links(self): with tempfile.TemporaryDirectory() as directory: out = Path(directory)/'scooter'; manifest = export_scooter(ORIGINAL, out) self.assertEqual(manifest, json.loads((out/'scooter.json').read_text())) self.assertEqual(manifest['sources'], SOURCES) for id_, name, offset, size, width, height, digest in CANVASES: self.assertEqual(hashlib.sha256((out/f'canvas_{id_}.rgba').read_bytes()).hexdigest(), digest) self.assertEqual((out/f'canvas_{id_}.rgba').stat().st_size, width*height*4) body = json.loads((out/manifest['bodyMesh']).read_text()) wheel = json.loads((out/manifest['wheelMesh']).read_text()) self.assertEqual((len(body['vertices']), len(body['indices'])), (176*3, 176*3)) self.assertEqual((len(wheel['vertices']), len(wheel['indices'])), (56*3, 56*3)) for mesh in (body, wheel): self.assertEqual({m['id']:m['texture']['id'] for m in mesh['materials']}, {0:1,1:0}) self.assertTrue(all((out/Path(manifest['bodyMesh']).parent/t['path']).is_file() for t in mesh['textures'])) self.assertEqual([s['materialPolygons'] for s in manifest['shapes']], [{'0':176},{'1':28,'null':28}]) self.assertEqual(sum(p['materialId'] is None for p in wheel['collisionPolygons']),28) def test_original_mesh_pivots_vertices_uvs_normals_and_null_draws_preserved(self): database = Database(resolve_asset(ORIGINAL, 'omt/scooter.omt')) with tempfile.TemporaryDirectory() as directory: out=Path(directory)/'scooter';m=export_scooter(ORIGINAL,out) for metadata in m['shapes']: entry=next(e for e in database.entries if e.type=='3DSh' and e.id==metadata['shapeId']) source=read_shape(database.payload(entry));actual=json.loads((out/metadata['path']).read_text()) expected_vertices=[];expected_uvs=[];expected_normals=[] for poly in source['polygons']: for corner in poly['corners']: expected_vertices.append(list(source['vertices'][corner['vertex']])) expected_uvs.append(list(corner['uv'])) ni=corner['normal'];expected_normals.append(list(source['normals'][ni] if ni