Skip to content

Small oversight in trimesh.primitives.Box #2523

@louisreine

Description

@louisreine

Hello !

import trimesh

bounds = [[0, 0, 0],[1, 1, 1]]
box = trimesh.primitives.Box(bounds=bounds)
print(box.bounds)

bounds = [[0, 1, 0],[1, 0, 1]]
box = trimesh.primitives.Box(bounds=bounds)
print(box.bounds)

Those two code should give identical results, but the current implementation in trimesh.primitives.py is using the first bound as a starting point to calculate the center.

if bounds is not None:
      # validate the multiple forms of input available here
      if extents is not None or transform is not None:
          raise ValueError(
              "if `bounds` is passed `extents` and `transform` must not be!"
          )
      bounds = np.array(bounds, dtype=np.float64)
      if bounds.shape != (2, 3):
          raise ValueError("`bounds` must be (2, 3) float")
      # create extents from AABB
      extents = np.ptp(bounds, axis=0)
      # translate to the center of the box
      transform = np.eye(4)
      transform[:3, 3] = bounds[0] + extents / 2.0
 transform[:3, 3] = bounds[0] + extents / 2.0

shoud be

 transform[:3, 3] = np.min(bounds, axis=0) + extents / 2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions