MixingCamera
Mixes its cameras into one shot by weight.
Mixes its child cameras into one shot. Each child's share is its weight over the sum of all weights, and a weight of 0 or less leaves the child out. With one weighted child, the shot is that child's.
Unlike a blend, nothing here runs on a timer: you set the weights, every frame if you like, from a slider, a distance or a speed. Mixing works the same way as a blend at that point, so blend hints on the children apply.
The child with the highest weight is the live one: transitions on children follow it. Every child with a weight runs every frame, the others as their standbyUpdate says.
Settings
Usage
import { MixingCamera } from '@pmndrs/klipp';
const chase = new MixingCamera('chase', { priority: 10, weights: { calm: 1, fast: 0 } });
chase.children.add(calm);
chase.children.add(fast);
klipp.add(chase);
// every frame
chase.weights.fast = speed / maxSpeed;
chase.weights.calm = 1 - chase.weights.fast;
import { MixingCamera } from '@pmndrs/klipp';
import { VirtualCameraThree } from '@pmndrs/klipp/three';
const chase = new MixingCamera('chase', { priority: 10, weights: { calm: 1, fast: 0 } });
chase.children.add(new VirtualCameraThree('calm'));
chase.children.add(new VirtualCameraThree('fast'));
klipp.add(chase);
import { MixingCamera, VirtualCamera } from '@pmndrs/klipp/react';
<MixingCamera name="chase" priority={10} weights={{ calm: 1 - boost, fast: boost }}>
<VirtualCamera name="calm">...</VirtualCamera>
<VirtualCamera name="fast">...</VirtualCamera>
</MixingCamera>;
To change the weights every frame without re-rendering, pass an object that lives across renders and set them on it:
const [weights] = useState(() => ({ calm: 1, fast: 0 }));
useFrame(() => {
weights.fast = speed / maxSpeed;
weights.calm = 1 - weights.fast;
});
<MixingCamera name="chase" priority={10} weights={weights}>
...
</MixingCamera>;
ref gives you the MixingCamera.