pygfx.objects.WorldObject
- class pygfx.objects.WorldObject(geometry: Geometry | None = None, material: Material | None = None, *, visible: bool = True, render_order: float = 0, name: str = '')
Bases:
EventTarget,TrackableBase class for objects.
This class represents objects in the world, i.e., the scene graph.Each WorldObject has geometry to define it’s data, and material to define its appearance. The object itself is only responsible for defining object hierarchies (parent / children) and its position and orientation in the world.
- Parameters:
geometry (Geometry) – The data defining the shape of the object. See the documentation on the different WorldObject subclasses for what attributes the geometry should and may have.
material (Material) – The data defining the appearance of the object.
visible (bool) – Whether the object is visible.
render_order (float) – Value that helps controls the order in which objects are rendered.
name (str) – The name of the object.
Notes
Use
Groupto collect multiple world objects into a single empty world object.See also
pygfx.utils.transform.AffineBaseVarious getters and setters defined on
obj.localandobj.world.pygfx.utils.transform.AffineTransformThe class used to implement
obj.local.pygfx.utils.transform.RecursiveTransformThe class used to implement
obj.world.
- local
The object’s transform expressed in parent space.
- world
The object’s transform expressed in world space.
- uniform_buffer
The GPU data of this WorldObject.
- property up: ndarray
Relic of old WorldObjects that aliases with the new
transform.updirection. Prefer obj.world.reference_up instead.
- property render_order: float
Per-object rendering priority used to fine-tune the draw order within a render queue.
Objects with higher render_order values are rendered later than those with lower values. This affects both opaque and transparent objects and can be used to resolve z-fighting, or control draw order beyond automatic depth sorting.
If the object is part of a Group, the group’s render_order is considered first (that is the group_order of the object).
- The order in wich objects are rendered is:
the
material.render_queue.the
ob.parent.render_order(ifisinstance(ob.parent, gfx.Group)).the
ob.render_order.the distance to camera (if
renderer.sort_objects==True).the position of the object in the scene graph.
Also see
material.render_queue.
- property geometry: Geometry | None
The object’s geometry, the data that defines (the shape of) this object.
- property material: Material | None
The object’s material, the data that defines the appearance of this object.
- property cast_shadow: bool
Whether this object casts shadows, i.e. whether it is rendered into a shadow map. Default False.
- property parent: WorldObject | None
Object’s parent in the scene graph (read-only). An object can have at most one parent.
- property children: Tuple[WorldObject, ...]
tuple of children of this object. (read-only)
- add(*objects: WorldObject, before: WorldObject | None = None, keep_world_matrix: bool = False) WorldObject
Add child objects.
Any number of objects may be added. Any current parent on an object passed in here will be removed, since an object can have at most one parent. If
beforeargument is given, then the items are inserted before the given element.- Parameters:
*objects (WorldObject) – The world objects to add as children.
before (WorldObject) – If not None, insert the objects before this child object.
keep_world_matrix (bool) – If True, the child will keep it’s world transform. It moves in the scene graph but will visually remain in the same place. If False, the child will keep it’s parent transform.
- remove(*objects: WorldObject, keep_world_matrix: bool = False) None
Removes object as child of this object. Any number of objects may be removed.
- traverse(callback: Callable[[WorldObject], Any], skip_invisible: bool = False)
Executes the callback on this object and all descendants.
If
skip_invisibleis given and True, objects whosevisibleproperty is False - and their children - are skipped. Note that modifying the scene graph inside the callback is discouraged.
- iter(filter_fn: Callable[[WorldObject], bool] | None = None, skip_invisible: bool = False) Iterator[WorldObject]
Create a generator that iterates over this objects and its children. If
filter_fnis given, only objects for which it returnsTrueare included.
- get_bounding_box() ndarray | None
Axis-aligned bounding box in local model space.
- Returns:
aabb – An axis-aligned bounding box, or None when the object does not take up a particular space.
- Return type:
ndarray, [2, 3] or None
- get_bounding_sphere() ndarray | None
Bounding Sphere in local model space.
- Returns:
bounding_shere – A sphere (x, y, z, radius), or None when the object does not take up a particular space.
- Return type:
ndarray, [4] or None
- get_world_bounding_box() ndarray | None
Axis aligned bounding box in world space.
- Returns:
aabb – The transformed axis-aligned bounding box, or None when the object does not take up a particular space.
- Return type:
ndarray, [2, 3] or None
- get_world_bounding_sphere() ndarray | None
Bounding Sphere in world space.
- Returns:
bounding_shere – A sphere (x, y, z, radius), or None when the object does not take up a particular space.
- Return type:
ndarray, [4] or None
- look_at(target: WorldObject) None
Orient the object so it looks at the given position.
This sets the object’s rotation such that its
forwarddirection points towardstarget(given in world space). This rotation takes reference_up into account, i.e., the rotation is chosen in such a way that a camera lookingforwardfollows the rotation of a human head looking around without tilting the head sideways.