Skip to content

Managing objects#

As you add objects to the octarine.Viewer, you might want to keep track of them so you can e.g. colorize or remove them at a later point.

Unless specified, each object gets a generic identifier:

>>> duck = tm.load_remote(
...         'https://github.com/mikedh/trimesh/raw/main/models/Duck.glb'
...     )

>>> # Add the duck
>>> v.add_mesh(duck)

bunny example

Let's check what objects are there:

>>> v.objects
OrderedDict([('Object', [<pygfx.Mesh at 0x37f4f8b90>])])

The .objects property will return a dictionary mapping IDs to pygfx visuals.

Alternatively, you can also do this:

>>> v['Object']
[<pygfx.Mesh at 0x37f4f8b90>]

Instead of generic IDs, we can also explicitly set the ID:

>>> v.add_mesh(duck, name='Duck')
>>> v.objects
OrderedDict([('Duck', [<pygfx.Mesh at 0x37f5f8a12>])])

This can also be used to combine multiple objects under the same ID.

Why are these IDs relevant? Well, they help you manipulate objects after they've been added:

>>> v.set_colors({'Duck': 'w'})
>>> v.hide_objects('Duck')
>>> v.remove_objects('Duck')

Check out Viewer Controls for details on how to manipulate objects.