Skip to content

Merging#

Merging many small objects into a few shared pygfx objects, which is much faster to render. See Merging objects for how to use it; this is the machinery underneath.

The entry points on the viewer are Viewer.merge_objects, Viewer.unmerge_objects and Viewer.merge_stats, plus the merge parameter of Viewer and of the add methods.

octarine.handles.MergeStats dataclass #

What merging currently costs and saves on a canvas.

ATTRIBUTE DESCRIPTION
objects

Objects on the canvas, merged or not.

TYPE: int

visuals

pygfx objects the renderer actually walks. This is the number merging exists to bring down.

TYPE: int

merged

How many of those visuals hold more than one member.

TYPE: int

members

Objects currently living inside a merged visual.

TYPE: int

largest

Members in the biggest merged visual.

TYPE: int

split_outs

Members that have been split back out since the canvas was created, because something was asked of them that a merged object cannot express. A number that climbs during normal use means the merge is being eroded - see SubVisualHandle._write_shared.

TYPE: int

Source code in octarine/handles.py
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
@dataclass
class MergeStats:
    """What merging currently costs and saves on a canvas.

    Attributes
    ----------
    objects :       int
                    Objects on the canvas, merged or not.
    visuals :       int
                    pygfx objects the renderer actually walks. This is the
                    number merging exists to bring down.
    merged :        int
                    How many of those visuals hold more than one member.
    members :       int
                    Objects currently living inside a merged visual.
    largest :       int
                    Members in the biggest merged visual.
    split_outs :    int
                    Members that have been split back out since the canvas
                    was created, because something was asked of them that a
                    merged object cannot express. A number that climbs during
                    normal use means the merge is being eroded - see
                    `SubVisualHandle._write_shared`.

    """

    objects: int = 0
    visuals: int = 0
    merged: int = 0
    members: int = 0
    largest: int = 0
    split_outs: int = 0

octarine.handles.SubVisualHandle #

One object inside a merged visual, addressable as if it were its own.

PARAMETER DESCRIPTION
manager
    The manager that owns this handle. Used to split the member
    back out when a write cannot be expressed on a merged object.

TYPE: MergeManager

visual
    The merged visual the member currently lives in.

TYPE: pygfx visual

sub
    Which vertex (and face) range the member owns.

TYPE: merge.SubVisual

See Also

merge.SubVisual The record this wraps.

Source code in octarine/handles.py
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
class SubVisualHandle:
    """One object inside a merged visual, addressable as if it were its own.

    Parameters
    ----------
    manager :   MergeManager
                The manager that owns this handle. Used to split the member
                back out when a write cannot be expressed on a merged object.
    visual :    pygfx visual
                The merged visual the member currently lives in.
    sub :       merge.SubVisual
                Which vertex (and face) range the member owns.

    See Also
    --------
    merge.SubVisual
                The record this wraps.

    """

    # Defaults for the bookkeeping the viewer hangs off its objects. Without
    # them every `getattr(obj, "_pinned", False)` probe - several per object
    # per styling or legend pass - costs a raised-and-swallowed AttributeError
    # from `__getattr__`.
    _pinned = False
    _highlighted = False

    def __init__(self, manager, visual, sub):
        self._manager = manager
        self.visual = visual
        self.sub = sub
        self._geometry = _HandleGeometry(self)
        self._material = _HandleMaterial(self)
        # Positions are destroyed to hide a member (see `visible`), so the
        # originals are kept here while it is hidden - and only while it is,
        # which keeps the cost proportional to how much is hidden.
        self._stashed_positions = None

    def __repr__(self):
        return (
            f"<SubVisualHandle {self._object_id!r} "
            f"in {type(self.visual).__name__} at {self.sub.offset}:"
            f"{self.sub.offset + self.sub.count}>"
        )

    # ------------------------------------------------------------ identity

    @property
    def _object_id(self):
        return self.sub.object_id

    @property
    def _object_group(self):
        return self.sub.group

    @property
    def _object_type(self):
        return getattr(self.visual, "_object_type", None)

    @property
    def material(self):
        return self._material

    @property
    def geometry(self):
        return self._geometry

    # ------------------------------------------------------------ retarget

    def _retarget(self, visual, sub):
        """Point this handle at a rebuilt merged visual.

        Merging, splitting and compacting all produce *new* pygfx objects, so
        the handles for the members that moved have to be pointed at them -
        the viewer and the legend hold on to handles across all of that.

        """
        self.visual = visual
        self.sub = sub

    # ---------------------------------------------------------- visibility

    @property
    def visible(self):
        return self._stashed_positions is None and self.visual.visible

    @visible.setter
    def visible(self, value):
        if bool(value) == (self._stashed_positions is None):
            return

        buffer = self.visual.geometry.positions
        if value:
            buffer.data[self.sub.slice] = self._stashed_positions
            self._stashed_positions = None
            self._manager._hidden.discard(self)
        else:
            # A copy, not a view: the next line overwrites what it points at.
            self._stashed_positions = buffer.data[self.sub.slice].copy()
            buffer.data[self.sub.slice] = np.nan
            self._manager._hidden.add(self)
        buffer.update_range(self.sub.offset, self.sub.count)
        self._manager._touch()

    # -------------------------------------------------------------- bounds

    def get_bounding_box(self):
        """This member's axis-aligned bounds, in the merged visual's space.

        Computed from the member's own positions rather than the merged
        object's, and from the stash while it is hidden - `Viewer.get_bounds`
        documents itself as covering visible *and* invisible objects, and a
        hidden member's vertices are NaN in the buffer.

        Deliberately pygfx's own `points_to_bounds`: it is what every real
        visual's bounds go through, it already drops non-finite vertices (which
        a merged line's gap vertices and a hidden member's are), and going
        through it is what keeps a handle's bounds identical to those of the
        unmerged object it stands in for.

        """
        aabb, _ = points_to_bounds(self._positions(), calculate_radius=False)
        return aabb

    def get_world_bounding_box(self):
        """This member's axis-aligned bounds, in world space."""
        aabb = self.get_bounding_box()
        if aabb is None:
            return None
        matrix = self.visual.world.matrix
        if np.array_equal(matrix, _IDENTITY):
            return aabb
        return la.aabb_transform(aabb, matrix)

    # ------------------------------------------------------- shared fields

    def __getattr__(self, name):
        # Only reached for names this class does not define, which is where
        # the shared object-level state (`render_order`, `cast_shadow`, ...)
        # and anything a plugin reads off a visual ends up.
        if name.startswith("_"):
            raise AttributeError(name)
        return getattr(self.visual, name)

    # ------------------------------------------------------------ internals

    def _positions(self):
        """The member's positions, from the stash while it is hidden."""
        if self._stashed_positions is not None:
            return self._stashed_positions
        return self.visual.geometry.positions.data[self.sub.slice]

    def _buffer_data(self, name):
        if name == "positions":
            return self._positions()
        buffer = getattr(self.visual.geometry, name)
        if name == "indices":
            return buffer.data[self.sub.face_slice]
        return buffer.data[self.sub.slice]

    def _update_buffer(self, name, offset, size):
        buffer = getattr(self.visual.geometry, name)
        base = self.sub.face_offset if name == "indices" else self.sub.offset
        count = self.sub.face_count if name == "indices" else self.sub.count
        buffer.update_range(base + offset, count if size is None else size)
        self._manager._touch()

    def _read_color(self):
        colors = getattr(self.visual.geometry, "colors", None)
        if colors is None:
            # Still a single colour for the whole merged visual
            return self.visual.material.color
        stored = colors.data[self.sub.offset]
        # Whether the buffer holds physical or sRGB values depends on the
        # visual type - see `merge.colors_are_physical`.
        if colors_are_physical(self.visual):
            return _color_from_physical(stored)
        return gfx.Color(stored)

    def _write_color(self, value):
        if colors_are_physical(self.visual):
            rgba = _color_to_physical(value)
        else:
            rgba = np.asarray(gfx.Color(value).rgba, dtype=np.float32)
        # Writing one member's colour is what forces a merged visual off its
        # shared colour, so the buffer may have to be created here.
        colors = self._manager._ensure_vertex_colors(self.visual)
        colors.data[self.sub.slice] = rgba
        colors.update_range(self.sub.offset, self.sub.count)
        self._manager._touch()

    def _write_shared(self, owner, name, value):
        """Apply a write that a merged object can only hold once.

        Inside a bulk write this member stakes its claim on the shared value
        first (see `MergeManager.bulk_shared_write`), *before* the "nothing
        would change" shortcut below. Taking the shortcut first would let a
        member that is happy with the current value stay silent, and a later
        member asking for a different one would then find the visual
        unclaimed and write its value to everybody.

        Outside a bulk, an unchanged value is simply dropped: splitting an
        object out to write what is already there would be pure loss.

        """
        target = self.visual.material if owner == "material" else self.visual
        try:
            current, known = getattr(target, name), True
        except AttributeError:
            current, known = None, False

        if self._manager._covered_by_bulk(self.visual, name, value):
            # Every member of this visual is in this bulk and none of them has
            # asked for anything else, so it can go on the shared object.
            if not (known and _same(current, value)):
                setattr(target, name, value)
                self._manager._touch()
            return

        if known and _same(current, value):
            return

        split = self._manager.split_out([self._object_id])[self._object_id]
        self._manager.note_erosion()
        setattr(getattr(split, owner) if owner == "material" else split, name, value)

get_bounding_box() #

This member's axis-aligned bounds, in the merged visual's space.

Computed from the member's own positions rather than the merged object's, and from the stash while it is hidden - Viewer.get_bounds documents itself as covering visible and invisible objects, and a hidden member's vertices are NaN in the buffer.

Deliberately pygfx's own points_to_bounds: it is what every real visual's bounds go through, it already drops non-finite vertices (which a merged line's gap vertices and a hidden member's are), and going through it is what keeps a handle's bounds identical to those of the unmerged object it stands in for.

Source code in octarine/handles.py
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
def get_bounding_box(self):
    """This member's axis-aligned bounds, in the merged visual's space.

    Computed from the member's own positions rather than the merged
    object's, and from the stash while it is hidden - `Viewer.get_bounds`
    documents itself as covering visible *and* invisible objects, and a
    hidden member's vertices are NaN in the buffer.

    Deliberately pygfx's own `points_to_bounds`: it is what every real
    visual's bounds go through, it already drops non-finite vertices (which
    a merged line's gap vertices and a hidden member's are), and going
    through it is what keeps a handle's bounds identical to those of the
    unmerged object it stands in for.

    """
    aabb, _ = points_to_bounds(self._positions(), calculate_radius=False)
    return aabb

get_world_bounding_box() #

This member's axis-aligned bounds, in world space.

Source code in octarine/handles.py
357
358
359
360
361
362
363
364
365
def get_world_bounding_box(self):
    """This member's axis-aligned bounds, in world space."""
    aabb = self.get_bounding_box()
    if aabb is None:
        return None
    matrix = self.visual.world.matrix
    if np.array_equal(matrix, _IDENTITY):
        return aabb
    return la.aabb_transform(aabb, matrix)

octarine.merge.merge_visuals(visuals, max_size=None, max_nodes=_MAX_MERGED_NODES) #

Merge compatible visuals into fewer pygfx objects.

Lines, points and meshes are merged; everything else - volumes, text, tubes, and any visual whose material or geometry we can't concatenate - is passed through untouched and in place, as are visuals that end up alone in their group.

Visuals are merged only if they agree on everything the merged object can hold just once: the material's uniforms and blend/depth state, the object's transform, visibility and render order. Colour is the exception, along with line width and point size - where members disagree on those, they move into the geometry as per-vertex buffers.

Merging is destructive to the per-object handles the viewer relies on (material.color, visual.visible, one _object_id per object); those are replaced by the vertex ranges in visual._sub_visuals. See SubVisual for how to address an individual member.

PARAMETER DESCRIPTION
visuals
    Visuals to merge. Visuals that have already been through this
    function are taken apart member by member and re-merged, so a
    group can be grown one visual at a time.

TYPE: list of pygfx visuals

max_size
    Maximum number of members per merged visual. `None` (default)
    puts every compatible visual in one object. The gain flattens
    out below ~50 objects, so capping this keeps the buffers small
    enough to rebuild cheaply without giving much up.

TYPE: int DEFAULT: None

max_nodes
    Maximum number of vertices per merged visual. Guards against
    producing buffers larger than the GPU will bind.

TYPE: int DEFAULT: _MAX_MERGED_NODES

RETURNS DESCRIPTION
list of pygfx visuals

The merged visuals. Merged ones carry a _sub_visuals list.

See Also

SubVisual Addressing an individual object inside a merged visual.

Source code in octarine/merge.py
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
def merge_visuals(visuals, max_size=None, max_nodes=_MAX_MERGED_NODES):
    """Merge compatible visuals into fewer pygfx objects.

    Lines, points and meshes are merged; everything else - volumes, text,
    tubes, and any visual whose material or geometry we can't concatenate - is
    passed through untouched and in place, as are visuals that end up alone in
    their group.

    Visuals are merged only if they agree on everything the merged object can
    hold just once: the material's uniforms and blend/depth state, the
    object's transform, visibility and render order. Colour is the exception,
    along with line width and point size - where members disagree on those,
    they move into the geometry as per-vertex buffers.

    Merging is destructive to the per-object handles the viewer relies on
    (`material.color`, `visual.visible`, one `_object_id` per object); those
    are replaced by the vertex ranges in `visual._sub_visuals`. See
    `SubVisual` for how to address an individual member.

    Parameters
    ----------
    visuals :   list of pygfx visuals
                Visuals to merge. Visuals that have already been through this
                function are taken apart member by member and re-merged, so a
                group can be grown one visual at a time.
    max_size :  int, optional
                Maximum number of members per merged visual. `None` (default)
                puts every compatible visual in one object. The gain flattens
                out below ~50 objects, so capping this keeps the buffers small
                enough to rebuild cheaply without giving much up.
    max_nodes : int, optional
                Maximum number of vertices per merged visual. Guards against
                producing buffers larger than the GPU will bind.

    Returns
    -------
    list of pygfx visuals
                The merged visuals. Merged ones carry a `_sub_visuals` list.

    See Also
    --------
    SubVisual
                Addressing an individual object inside a merged visual.

    """
    # Groups in first-appearance order. Visuals we can't merge get a group of
    # their own, which the loop below passes straight through.
    order, buckets = [], {}

    for vis in visuals:
        merger = _MERGERS.get(type(vis))
        key = merger.key(vis) if merger is not None else None
        group = buckets.get((type(vis), key)) if key is not None else None
        if group is None:
            group = []
            order.append(group)
            if key is not None:
                buckets[type(vis), key] = group
        group.append(vis)

    merged = []
    for group in order:
        # A lone visual is already as merged as it is going to get
        if len(group) == 1:
            merged.append(group[0])
            continue

        merger = _MERGERS[type(group[0])]
        members = [m for vis in group for m in merger.members(vis)]
        for batch in _batch_members(members, max_size, max_nodes):
            merged.append(merger.merge(group[0], batch))

    return merged

octarine.merge.split_visual(merged, object_ids=None, extract=True) #

Split members back out of a merged visual.

The inverse of merge_visuals, to the extent that one exists: the members are decomposed exactly as a re-merge would decompose them and rebuilt as visuals of their own. What is not restored is the material class a member had before merging - a gfx.LineMaterial line that merged into a FlexLineMaterial splits back out as a FlexLineMaterial, since the merged visual is all the split has to go on.

Members sharing an object_id stay together in one visual, because that is what the viewer addresses as a single object.

PARAMETER DESCRIPTION
merged
        A visual produced by `merge_visuals`, i.e. one carrying
        `_sub_visuals`.

TYPE: pygfx visual

object_ids
        The `object_id`(s) to extract. `None` (default) extracts
        every member, leaving no remainder. IDs that aren't in
        this visual are ignored.

TYPE: hashable | list thereof | None DEFAULT: None

extract
        Whether to build the extracted visuals at all. `False`
        returns only the remainder, for a caller that is throwing
        the extracted members away (removing them, say) - building
        one visual per member is the expensive half of a split.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
remainder

A visual holding the members that were not extracted, or None if none were left.

TYPE: pygfx visual | None

extracted

One visual per extracted object_id, in the order the ids first appear in merged._sub_visuals. Empty if extract is False.

TYPE: list of pygfx visuals

See Also

merge_visuals The operation this undoes.

Source code in octarine/merge.py
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
def split_visual(merged, object_ids=None, extract=True):
    """Split members back out of a merged visual.

    The inverse of `merge_visuals`, to the extent that one exists: the
    members are decomposed exactly as a re-merge would decompose them and
    rebuilt as visuals of their own. What is *not* restored is the material
    class a member had before merging - a `gfx.LineMaterial` line that merged
    into a `FlexLineMaterial` splits back out as a `FlexLineMaterial`, since
    the merged visual is all the split has to go on.

    Members sharing an `object_id` stay together in one visual, because that
    is what the viewer addresses as a single object.

    Parameters
    ----------
    merged :        pygfx visual
                    A visual produced by `merge_visuals`, i.e. one carrying
                    `_sub_visuals`.
    object_ids :    hashable | list thereof | None
                    The `object_id`(s) to extract. `None` (default) extracts
                    every member, leaving no remainder. IDs that aren't in
                    this visual are ignored.
    extract :       bool
                    Whether to build the extracted visuals at all. `False`
                    returns only the remainder, for a caller that is throwing
                    the extracted members away (removing them, say) - building
                    one visual per member is the expensive half of a split.

    Returns
    -------
    remainder :     pygfx visual | None
                    A visual holding the members that were not extracted, or
                    `None` if none were left.
    extracted :     list of pygfx visuals
                    One visual per extracted `object_id`, in the order the
                    ids first appear in `merged._sub_visuals`. Empty if
                    `extract` is False.

    See Also
    --------
    merge_visuals
                    The operation this undoes.

    """
    merger = _MERGERS.get(type(merged))
    subs = getattr(merged, "_sub_visuals", None)
    if merger is None or not subs:
        raise ValueError(
            f"{type(merged).__name__} is not a merged visual - nothing to split."
        )

    if object_ids is None:
        wanted = {sub.object_id for sub in subs}
    else:
        wanted = set(utils.make_iterable(object_ids))

    # `members` comes back in `_sub_visuals` order, so grouping by id as we go
    # preserves first-appearance order for the extracted visuals.
    keep, taken = [], {}
    for member in merger.members(merged):
        if member.object_id in wanted:
            taken.setdefault(member.object_id, []).append(member)
        else:
            keep.append(member)

    # Both sides: a remainder whose members turn out to agree should go back
    # to a uniform value just as a fresh merge of them would.
    _collapse_members(keep, merger.kind)

    # N.B. `merged` is the template for both sides: it is where the shared
    # material and object state the members have to keep living now lives.
    extracted = []
    if extract:
        for group in taken.values():
            _collapse_members(group, merger.kind)
            extracted.append(_strip_if_whole(merger.merge(merged, group)))
    remainder = _strip_if_whole(merger.merge(merged, keep)) if keep else None

    return remainder, extracted

octarine.merge.sub_visual_at(merged, pick_info) #

Which member of a merged visual a pick landed on.

Picking reports the merged visual as the world object, so the member has to be recovered from the index that comes with it: the face index for meshes, which is what the merged indices buffer is laid out by, and the vertex index for points and lines.

PARAMETER DESCRIPTION
merged
    The world object the pick reported.

TYPE: pygfx visual

pick_info
    The event's `pick_info`.

TYPE: dict

RETURNS DESCRIPTION
SubVisual | None

The member that was hit, or None if merged isn't a merged visual, carries no usable index, or the index falls in one of the gap vertices between members.

Source code in octarine/merge.py
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
def sub_visual_at(merged, pick_info):
    """Which member of a merged visual a pick landed on.

    Picking reports the merged visual as the world object, so the member has
    to be recovered from the index that comes with it: the face index for
    meshes, which is what the merged `indices` buffer is laid out by, and the
    vertex index for points and lines.

    Parameters
    ----------
    merged :    pygfx visual
                The world object the pick reported.
    pick_info : dict
                The event's `pick_info`.

    Returns
    -------
    SubVisual | None
                The member that was hit, or `None` if `merged` isn't a merged
                visual, carries no usable index, or the index falls in one of
                the gap vertices between members.

    """
    subs = getattr(merged, "_sub_visuals", None)
    if not subs:
        return None

    # Meshes index by face, everything else by vertex. Note that `face_index`
    # is also absent on a mesh whose material doesn't write pick info.
    faces = isinstance(merged, gfx.Mesh)
    index = pick_info.get("face_index" if faces else "vertex_index")
    if index is None:
        return None

    offsets = _pick_offsets(merged, faces)
    at = int(np.searchsorted(offsets, index, side="right")) - 1
    if at < 0:
        return None

    sub = subs[at]
    count = sub.face_count if faces else sub.count
    # A line's members are separated by a NaN vertex, which belongs to no
    # member - an index pointing at one lands past the end of the member
    # before it.
    if index >= (sub.face_offset if faces else sub.offset) + count:
        return None

    return sub

octarine.merge.SubVisual dataclass #

One of the original visuals inside a visual merged by merge_visuals.

Merging turns N objects into one, which means per-object operations (hiding, recolouring, picking) can no longer address an object as a whole. Instead each original visual becomes a contiguous range of vertices in the merged buffers, and this is the record of where it went::

sub = merged._sub_visuals[3]
merged.geometry.colors.data[sub.slice] = (1, 0, 0, 1)
merged.geometry.colors.update_range(sub.offset, sub.count)

Hiding works the same way, by writing NaN into the position slice - those vertices then drop out for lines, points and meshes alike, exactly like the NaN breaks that separate merged lines. Note that this is destructive, so callers that want to unhide again have to keep a copy of the slice.

Merged meshes additionally own a range of faces, which is what picking reports and what the merged indices buffer is laid out by.

ATTRIBUTE DESCRIPTION
object_id

The _object_id the original visual carried.

TYPE: str | uuid

group

The _object_group the original visual carried.

TYPE: str | None

offset

Index of the member's first vertex in the merged buffers.

TYPE: int

count

Number of vertices the member occupies. For lines this excludes the NaN vertex that separates it from the next member.

TYPE: int

face_offset

Index of the member's first face. Meshes only.

TYPE: int | None

face_count

Number of faces the member occupies. Meshes only.

TYPE: int | None

Source code in octarine/merge.py
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
@dataclass
class SubVisual:
    """One of the original visuals inside a visual merged by `merge_visuals`.

    Merging turns N objects into one, which means per-object operations
    (hiding, recolouring, picking) can no longer address an object as a whole.
    Instead each original visual becomes a contiguous range of vertices in the
    merged buffers, and this is the record of where it went::

        sub = merged._sub_visuals[3]
        merged.geometry.colors.data[sub.slice] = (1, 0, 0, 1)
        merged.geometry.colors.update_range(sub.offset, sub.count)

    Hiding works the same way, by writing NaN into the position slice - those
    vertices then drop out for lines, points and meshes alike, exactly like
    the NaN breaks that separate merged lines. Note that this is destructive,
    so callers that want to unhide again have to keep a copy of the slice.

    Merged meshes additionally own a range of *faces*, which is what picking
    reports and what the merged `indices` buffer is laid out by.

    Attributes
    ----------
    object_id : str | uuid
                The `_object_id` the original visual carried.
    group :     str | None
                The `_object_group` the original visual carried.
    offset :    int
                Index of the member's first vertex in the merged buffers.
    count :     int
                Number of vertices the member occupies. For lines this
                excludes the NaN vertex that separates it from the next
                member.
    face_offset : int | None
                Index of the member's first face. Meshes only.
    face_count : int | None
                Number of faces the member occupies. Meshes only.

    """

    object_id: object
    group: object
    offset: int
    count: int
    face_offset: int = None
    face_count: int = None

    @property
    def slice(self):
        """The member's vertex range, as a slice into the merged buffers."""
        return slice(self.offset, self.offset + self.count)

    @property
    def face_slice(self):
        """The member's face range, or None if this isn't a mesh."""
        if self.face_offset is None:
            return None
        return slice(self.face_offset, self.face_offset + self.face_count)

face_slice property #

The member's face range, or None if this isn't a mesh.

slice property #

The member's vertex range, as a slice into the merged buffers.