Skip to content

Managing objects#

Accessing 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.

Modifying objects#

Why are the object IDs discussed above 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')

Moving objects interactively#

You can designate a single object to be moved interactively:

>>> v.moveable_object = "Duck"

transform widget

To remove the transform widget again simple do:

>>> v.moveable_object = None

What next?#

  • Objects


    Manipulate viewer and objects (color, size, visibility, etc).

    Viewer Controls

  • Selection


    Selecting objects on the viewer.

    Selection