Open3D icon indicating copy to clipboard operation
Open3D copied to clipboard

ACCESSOR_MAX_MISMATCH validation issue in generated gltf

Open jacopofar opened this issue 3 years ago • 2 comments

Checklist

Describe the issue

I am trying to generate a glTF file from a mesh, and while the output file works in a few visualizers the Khronos Group validator warns of an issue with the generated file:

    "code": "ACCESSOR_MAX_MISMATCH",
    "message": "Declared maximum value for this component (2087) does not match actual maximum (463).",
    "severity": 0,
    "pointer": "/accessors/0/max/0"

This is the file generated by the script, it remains the same if I update to the dev snapshot wheel (always Python 3.9 on Linux 64 bit)

mesh.gltf.zip

Steps to reproduce the bug

I use this code, that transforms one of the example point clouds into a mesh


import open3d as o3d

pcd = o3d.io.read_point_cloud("Open3D/examples/test_data/fragment.ply")
voxel_grid = o3d.geometry.VoxelGrid.create_from_point_cloud(pcd, voxel_size=0.5)

vox_mesh = o3d.geometry.TriangleMesh()
voxels = voxel_grid.get_voxels()
for v in voxels:
    cube = o3d.geometry.TriangleMesh.create_box(width=1, height=1, depth=1)
    cube.paint_uniform_color(v.color)
    cube.translate(v.grid_index, relative=False)
    vox_mesh += cube
o3d.io.write_triangle_mesh("mesh.gltf", vox_mesh)

Error message

No error message, the problem is within the generated file.

Expected behavior

No response

Open3D, Python and System information

- Operating system: Linux (Fedora 35)
- Python version: Python 3.9.10
- Open3D version: 0.14.1+a1cbc21
- System architecture: x86
- Is this a remote workstation?: no
- How did you install Open3D?: pip

Additional information

No response

jacopofar avatar Feb 18 '22 15:02 jacopofar

Can reproduce with this smaller script:

import open3d as o3d
import numpy as np

VISUALIZE_MAP_MESH = True
WRITE_MESH = True
READ_MESH = True

o3d.utility.set_verbosity_level(o3d.utility.VerbosityLevel.Debug)

def main():
  device = o3d.core.Device("CPU:0")
  dtype_f = o3d.core.float32
  dtype_i = o3d.core.int32
  map_mesh = o3d.t.geometry.TriangleMesh(device)

  map_vertices = np.array([
                   [0., 0., 1.],
                   [0., 1., 1.],
                   [1., 0., 1.],
                   [1., 1., 1.]
                  ])
  map_colors = np.array([[112, 100, 88],
                         [121, 109, 97],
                         [123, 111, 99],
                         [123, 111, 99]
                         ])
  map_triangles = np.array([
                            [0, 2, 1],
                            [3, 1, 2],
                            ])

  # print('map_vertices: ', map_vertices.shape, map_vertices.tolist())
  # print('map_colors: ', map_colors.shape, map_colors.tolist())
  # print('map_triangles: ', map_triangles.shape, map_triangles.tolist())

  map_mesh.vertex.positions = o3d.core.Tensor(map_vertices, dtype_f, device)
  map_mesh.vertex.colors = o3d.core.Tensor(map_colors/255.0, dtype_f, device)
  map_mesh.triangle.indices = o3d.core.Tensor(map_triangles, dtype_i, device)

  map_mesh = map_mesh.to_legacy()

  if VISUALIZE_MAP_MESH:
    o3d.visualization.draw_geometries([map_mesh])

  if WRITE_MESH:
    o3d.io.write_triangle_mesh('tmp_o3d.glb', map_mesh, print_progress = True)

  if READ_MESH:
    map_mesh = o3d.io.read_triangle_mesh('tmp_o3d.glb', print_progress = True)

  if VISUALIZE_MAP_MESH:
    o3d.visualization.draw_geometries([map_mesh])


if __name__ == "__main__":
  main()

ssheorey avatar Aug 21 '24 23:08 ssheorey

There is no error if only new tensor APIs are used.

import open3d as o3d
import numpy as np

VISUALIZE_MAP_MESH = True
WRITE_MESH = True
READ_MESH = True

o3d.utility.set_verbosity_level(o3d.utility.VerbosityLevel.Debug)

def main():
  device = o3d.core.Device("CPU:0")
  dtype_f = o3d.core.float32
  dtype_i = o3d.core.int32
  map_mesh = o3d.t.geometry.TriangleMesh(device)

  map_vertices = np.array([
                   [0., 0., 1.],
                   [0., 1., 1.],
                   [1., 0., 1.],
                   [1., 1., 1.]
                  ])
  map_colors = np.array([[112, 100, 88],
                         [121, 109, 97],
                         [123, 111, 99],
                         [123, 111, 99]
                         ])
  map_triangles = np.array([
                            [0, 2, 1],
                            [3, 1, 2],
                            ])

  # print('map_vertices: ', map_vertices.shape, map_vertices.tolist())
  # print('map_colors: ', map_colors.shape, map_colors.tolist())
  # print('map_triangles: ', map_triangles.shape, map_triangles.tolist())

  map_mesh.vertex.positions = o3d.core.Tensor(map_vertices, dtype_f, device)
  map_mesh.vertex.colors = o3d.core.Tensor(map_colors/255.0, dtype_f, device)
  map_mesh.triangle.indices = o3d.core.Tensor(map_triangles, dtype_i, device)

  if WRITE_MESH:
    o3d.t.io.write_triangle_mesh('tmp_o3d.glb', map_mesh, print_progress = True)

  if VISUALIZE_MAP_MESH:
    o3d.visualization.draw([map_mesh])

  if READ_MESH:
    map_mesh = o3d.t.io.read_triangle_mesh('tmp_o3d.glb', print_progress = True)

  if VISUALIZE_MAP_MESH:
    o3d.visualization.draw([map_mesh])


if __name__ == "__main__":
  main()

ssheorey avatar Aug 21 '24 23:08 ssheorey