Commit b7a31623 authored by Jeremy Reizenstein's avatar Jeremy Reizenstein Committed by Facebook GitHub Bot
Browse files

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
parent de3a474d
...@@ -740,7 +740,10 @@ class _GLTFWriter: ...@@ -740,7 +740,10 @@ class _GLTFWriter:
json_length = len(json_bytes) json_length = len(json_bytes)
# write header # write header
header = struct.pack("<III", _GLTF_MAGIC, 2, json_length + byte_offset) version = 2
total_header_length = 28 # (file header = 12) + 2 * (chunk header = 8)
file_length = json_length + byte_offset + total_header_length
header = struct.pack("<III", _GLTF_MAGIC, version, file_length)
self.buffer_stream.write(header) self.buffer_stream.write(header)
# write json # write json
......
...@@ -155,6 +155,9 @@ class IO: ...@@ -155,6 +155,9 @@ class IO:
include_textures: If textures are present, whether to try to save include_textures: If textures are present, whether to try to save
them. them.
""" """
if not isinstance(data, Meshes):
raise ValueError("Meshes object expected.")
if len(data) != 1: if len(data) != 1:
raise ValueError("Can only save a single mesh.") raise ValueError("Can only save a single mesh.")
...@@ -204,6 +207,9 @@ class IO: ...@@ -204,6 +207,9 @@ class IO:
path: file to write path: file to write
binary: If there is a choice, whether to save in a binary format. binary: If there is a choice, whether to save in a binary format.
""" """
if not isinstance(data, Pointclouds):
raise ValueError("Pointclouds object expected.")
if len(data) != 1: if len(data) != 1:
raise ValueError("Can only save a single point cloud.") raise ValueError("Can only save a single point cloud.")
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
# This source code is licensed under the BSD-style license found in the # This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. # LICENSE file in the root directory of this source tree.
import os.path
import unittest import unittest
from math import radians from math import radians
...@@ -11,7 +12,7 @@ import numpy as np ...@@ -11,7 +12,7 @@ import numpy as np
import torch import torch
from PIL import Image from PIL import Image
from pytorch3d.io import IO from pytorch3d.io import IO
from pytorch3d.io.experimental_gltf_io import MeshGlbFormat from pytorch3d.io.experimental_gltf_io import _read_header, MeshGlbFormat
from pytorch3d.renderer import ( from pytorch3d.renderer import (
AmbientLights, AmbientLights,
BlendParams, BlendParams,
...@@ -46,10 +47,14 @@ def _load(path, **kwargs) -> Meshes: ...@@ -46,10 +47,14 @@ def _load(path, **kwargs) -> Meshes:
return io.load_mesh(path, **kwargs) return io.load_mesh(path, **kwargs)
def _write(mesh, path, **kwargs) -> bool: def _write(mesh, path, **kwargs) -> None:
io = IO() io = IO()
io.register_meshes_format(MeshGlbFormat()) 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( def _render(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment