GroupFraming
Keeps every member on screen. It places the camera in line with the group's center, along the camera's current view direction, at the distance where every member fits. By default it never moves the camera closer than the Body placed it; with fitMode: 'rigid' it always sits at exactly that distance, so it also moves in as the group gets smaller.
With an orthographic camera, distance doesn't change what's in view, so it fits the group by orthographicSize instead. The camera keeps the distance the Body gave, and only backs away when a member would end up in front of the near plane. By default it never goes below the size from the lens, so give it one with Lens; with fitMode: 'rigid' it always uses exactly the size that fits.
It doesn't rotate the camera, so pair it with an Aim that already looks at the group. klipp.setSize keeps the viewport size in sync.
Settings
Members
Usage
Members are plain data you keep up to date:
import { vec3 } from 'math';
import { GroupFramingExtension, groupFraming } from '@pmndrs/klipp';
const a = groupFraming.createMember();
const b = groupFraming.createMember();
b.extent.radius = 2;
camera.addExtension(new GroupFramingExtension([a, b], { padding: 1, damping: 0.5 }));
// every frame, before klipp.update
vec3.copy(a.position, aPosition);
vec3.copy(b.position, bPosition);
Members are a TargetGroup:
import { GroupFramingExtensionThree, TargetGroup } from '@pmndrs/klipp/three';
const group = new TargetGroup([{ target: a }, { target: b, radius: 2 }], 'groupCenter');
camera.addExtension(new GroupFramingExtensionThree(group, { padding: 1, damping: 0.5 }));
For meshes, member sizes are measured from their geometry. If a member's shape changes, call recalculateSize() to measure it again.
<VirtualCamera name="party" priority={10}>
<Body.Follow target={leaderRef} offset={[0, 4, 10]} />
<Aim.HardLookAt target={leaderRef} />
<Extension.GroupFraming
members={[{ target: aRef }, { target: bRef, radius: 2 }]}
padding={1}
damping={0.5}
/>
</VirtualCamera>
For meshes, member sizes are measured from their geometry. ref gives you the GroupFramingExtensionThree: if a member's shape changes, call recalculateSize() to measure it again.