import json import struct import tempfile import unittest from pathlib import Path from preflight import inspect_glb class PreflightTests(unittest.TestCase): def write_fixture(self, root, faces, copies=1): # Valid unindexed triangles. Repeated triangle vertices exercise the # parser with real binary payload, without a 2M-face Python object graph. count = faces * 3 doc = {"asset":{"version":"2.0"}, "buffers":[{"byteLength":count*12}], "bufferViews":[{"buffer":0,"byteLength":count*12}], "accessors":[{"bufferView":0,"componentType":5126,"count":count, "type":"VEC3","min":[0,0,0],"max":[1,1,0]}], "meshes":[{"primitives":[{"attributes":{"POSITION":0}}]}], "nodes":[{"mesh":0} for _ in range(copies)], "scenes":[{"nodes":list(range(copies))}],"scene":0} payload = json.dumps(doc).encode() payload += b" " * (-len(payload) % 4) p = Path(root)/"fixture.glb" with p.open("wb") as stream: stream.write(struct.pack("<4sIIII", b"glTF",2,28+len(payload)+count*12,len(payload),0x4E4F534A)) stream.write(payload) stream.write(struct.pack("