From b7a316232a46f7bf2d86189fdc383e15657e1e6b Mon Sep 17 00:00:00 2001 From: Jeremy Reizenstein Date: Tue, 13 Dec 2022 05:34:45 -0800 Subject: [PATCH] fix saved glb length Summary: Make GLB files report their own length correctly. They were off by 28. Reviewed By: davidsonic Differential Revision: D41838340 fbshipit-source-id: 9cd66e8337c142298d5ae1d7c27e51fd812d5c7b --- pytorch3d/io/experimental_gltf_io.py | 5 ++++- pytorch3d/io/pluggable.py | 6 ++++++ tests/test_io_gltf.py | 11 ++++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/pytorch3d/io/experimental_gltf_io.py b/pytorch3d/io/experimental_gltf_io.py index ecfe95c4..d59831aa 100644 --- a/pytorch3d/io/experimental_gltf_io.py +++ b/pytorch3d/io/experimental_gltf_io.py @@ -740,7 +740,10 @@ class _GLTFWriter: json_length = len(json_bytes) # write header - header = struct.pack(" Meshes: return io.load_mesh(path, **kwargs) -def _write(mesh, path, **kwargs) -> bool: +def _write(mesh, path, **kwargs) -> None: io = IO() io.register_meshes_format(MeshGlbFormat()) - return io.save_mesh(mesh, path, **kwargs) + io.save_mesh(mesh, path, **kwargs) + + with open(path, "rb") as f: + _, stored_length = _read_header(f) + assert stored_length == os.path.getsize(path) def _render(