spatialgeometry.SceneGroup

class SceneGroup(initlist: Iterable[SceneNode] | None = None, **kwargs)[source]

Bases: SceneNode, UserList

An ordered, list-like collection of SceneNode objects (nodes can be nested groups, shapes, or any other SceneNode subclass) that itself behaves like a single SceneNode.

Parameters:

initlist – Initial elements to populate the group with.

A SceneGroup is itself a SceneNode so its elements can be collectively, parented or nested like any other node in the scene graph. This class inherits from collections.UserList so it behaves like a Python list, but it is not a subclass of list so it can be subclassed itself.

Every element’s scene_parent is kept pointing at the group – adding an element (via the constructor, append, extend, insert, or item assignment) sets it, and removing one (remove, pop, clear, del) clears it back to None. This is what makes moving the group move its elements with it.

The reverse holds too, and isn’t just a side effect – append() is nothing more than item.scene_parent = self, so setting any node’s scene_parent to a SceneGroup directly (with no append call at all) equally makes it a member of that group’s list. List membership and scene-graph parentage are the same relationship, not two things kept in sync – there’s no way for them to disagree.

>>> from spatialgeometry import SceneGroup, Cuboid, Sphere
>>> from spatialmath import SE3
>>> group = SceneGroup()
>>> print(len(group))
0
>>> group.append(Cuboid([1,2,3]))
>>> group.append(Sphere(1, pose=SE3.Trans(1,0,0)))
>>> print(len(group))
2
Parameters:
  • pose – Local reference frame of this node relative to its parent in the scene graph (or the world frame if it has no parent), defaults to the identity transform.

  • scene_parent – Parent node of this node in the scene graph.

  • scene_children – Child nodes of this node in the scene graph.

append(item: SceneNode) None[source]

Add item to the end of the group and set its scene_parent to this group.

clear() None[source]

Remove every element from the group, clearing each one’s scene_parent.

property data: list[SceneNode]
extend(other: Iterable[SceneNode]) None[source]

Add every element of other to the end of the group, setting each one’s scene_parent to this group.

insert(i: int, item: SceneNode) None[source]

Insert item at position i and set its scene_parent to this group.

pop(i: int = -1) SceneNode[source]

Remove and return the element at position i (default: the last one), clearing its scene_parent.

remove(item: SceneNode) None[source]

Remove item from the group and clear its scene_parent.