Genesis-Embodied-AI/genesis-world · error · ValueError
direction must have shape (3,)
Error message
direction must have shape (3,)
What it means
A directional ForceField (e.g. ConstantForceField) validates its direction argument at construction: after np.asarray, it must have shape exactly (3,). Any other shape (wrong length, nested list, scalar, or a (3,1) array) raises this ValueError before the field is created.
Source
Thrown at genesis/engine/force_fields.py:66
class Constant(ForceField):
"""
Constant force field with a static acceleration everywhere.
Parameters:
-----------
direction: array_like, shape=(3,)
The direction of the force (acceleration). Will be normalized.
strength: float
The strength of the force (acceleration).
"""
def __init__(self, direction=(1, 0, 0), strength=1.0):
super().__init__()
direction = np.array(direction)
if direction.shape != (3,):
raise ValueError("direction must have shape (3,)")
self._direction = direction / np.linalg.norm(direction)
self._strength = strength
self._acc_qd = qd.Vector(self._direction * self._strength, dt=gs.qd_float)
@qd.func
def _get_acc(self, pos, vel, t, i):
return self._acc_qd
@property
def direction(self):
return self._direction
@property
def strength(self):
return self._strength
View on GitHub (pinned to 56e4aa5d82)
Solutions
- Pass a flat 3-element iterable, e.g. direction=[0,0,-1] or np.array([0,0,-1])
- If the value comes from another array, flatten to shape (3,) first: np.ravel(arr) or arr.reshape(3)
- Validate direction.shape == (3,) in your scene-construction code before creating the field
Example fix
# before field = ConstantForceField(direction=[[0], [0], [-1]], strength=1.0) # after field = ConstantForceField(direction=[0, 0, -1], strength=1.0)
Defensive patterns
Strategy: validation
Validate before calling
direction = np.asarray(direction).ravel() assert direction.shape == (3,), 'direction must be a flat 3-vector' field = ConstantForceField(direction=direction, strength=1.0)
Type guard
def is_vec3(x) -> bool:
return np.asarray(x).shape == (3,)
Try / catch
try:
field = ConstantForceField(direction=direction, strength=1.0)
except ValueError as e:
raise ValueError(f'bad direction {direction!r}: {e}') from e
Prevention
- Normalize all 3-vector inputs to shape (3,) at your config boundary
- Avoid storing directions as (3,1) column vectors
When it happens
Trigger: Passing direction=[1,0] (2 elements), direction=[1,0,0,0] (4 elements), a scalar, or a (3,1)/(1,3) nested array to ConstantForceField(direction=...).
Common situations: Configuring wind-like force fields in a scene and passing a 2D vector from a config file, reusing a column-vector numpy array shaped (3,1), or passing a batch of directions where only one is expected.
Related errors
- center must have shape (3,)
- position must have shape (3,)
- probe_arc_spacing must be positive, got {arc_spacing}
- Python module 'uipc' is required by IPCCoupler but is not in
- `morph` in hybrid entity should be either URDF or Mesh
AI-assisted analysis of Genesis-Embodied-AI/genesis-world@56e4aa5d82 (2026-08-28).
Data as JSON: /api/errors/a04b46bbe1d107e5.
Report an issue: GitHub.