Skip to content

In NumPy 2, NumPy index and vertex arrays are all zeros #401

@paulmelnikow

Description

@paulmelnikow

Describe the issue
In Numpy 2, NumPy index and vertex arrays are all zeros.

To Reproduce
Run the following Python code:

from tinyobjloader import ObjReader, ObjReaderConfig

reader = ObjReader()
config = ObjReaderConfig()
config.triangulate = False
reader.ParseFromString(mesh_string, "", config)

Load the following mesh:

v 0 0 0
v 0 0 0
v 0 0 0
v 0 0 0
f 1 2 3 4
v 46.367584 82.676086 8.867414
v 46.524185 82.81955 8.825487
v 46.59864 83.086678 8.88121
v 46.461926 82.834091 8.953863
f 5 6 7 8

Expected behavior

Observed:

(Pdb) [x.vertex_index for x in reader.GetShapes()[0].mesh.indices]
[0, 1, 2, 3, 4, 5, 6, 7]
(Pdb) reader.GetShapes()[0].mesh.numpy_indices()
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0], dtype=int32)

Expected:

(Pdb) reader.GetShapes()[0].mesh.numpy_indices()
array([ 0, -1, -1,  1, -1, -1,  2, -1, -1,  3, -1, -1,  4, -1, -1,  5, -1,
       -1,  6, -1, -1,  7, -1, -1], dtype=int32)

Observed:

(Pdb) reader.GetAttrib().vertices
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 46.367583999999994, 82.67608599999998, 8.867414000000002, 46.524185, 82.81955, 8.825487000000003, 46.59864, 83.08667799999999, 8.88121, 46.461926, 82.834091, 8.953863]
(Pdb) reader.GetAttrib().numpy_vertices()
array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
       0., 0., 0., 0., 0., 0., 0.])

Expected:

(Pdb) reader.GetAttrib().numpy_vertices()
array([ 0.      ,  0.      ,  0.      ,  0.      ,  0.      ,  0.      ,
        0.      ,  0.      ,  0.      ,  0.      ,  0.      ,  0.      ,
       46.367584, 82.676086,  8.867414, 46.524185, 82.81955 ,  8.825487,
       46.59864 , 83.086678,  8.88121 , 46.461926, 82.834091,  8.953863])

A clear and concise description of what you expected to happen.

Environment

  • TinyObjLoader 2.0.0rc12
  • OS: Mac or Linux
  • Compiler Wheels from PyPI
  • Other environment Python 3.11 or 3.12, NumPy 2.4.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions