Nodes/camera-comfyUI/TrajectoryCompose
ComfyUI Node

TrajectoryCompose

Multiply two trajectories — or rebase a camera path onto another pose

By Alexankharin·Created about a year ago·Updated about a month ago· 36
TrajectoryCompose
  • trajectory_a
  • trajectory_b
  • trajectory

TrajectoryCompose is one of those two-input math nodes you don't think about until you need it, and then it's the answer to a genuinely confusing problem: how do I take a camera move I designed in one place and play it from a different starting pose? It computes the per-frame matrix product A @ B of two trajectory tensors, and - this is the useful part - a single [4,4] matrix on either side broadcasts across the other's full length.

The headline use case is retargeting a novel camera path. You record a nice dolly move relative to some pose, but your scene's camera sits somewhere else. The recipe the pack's own docs suggest: compose the relative path with the inverse of your source pose zero, i.e. TrajectoryCompose(relative_path, TrajectoryInvert(source_pose0)). Out pops a trajectory that plays that exact move from where your scene actually is.

Inputs are just trajectory_a and trajectory_b, both TENSOR - each either [K,4,4] or a lone [4,4]. One output, trajectory. A few honest cautions:

  • Order matters. A @ B is not B @ A, and in camera-matrix land the difference is "camera orbits the wrong way around the world." If the result looks like the move happened in the wrong place or reversed, swap the inputs before you question the math.
  • Lengths must broadcast. If you feed a 64-frame trajectory against a 32-frame one, the node raises a clear error. One side has to be a single [4,4].
  • It does no interpolation. Compose with two different-length full trajectories and you'll get an error, not a blended path. If you need to resample lengths, that's what CameraInterpolationNode is for.

The pack's convention is worth keeping in your head: poses are 4x4 world-to-camera matrices in an OpenCV-style frame (+X right, +Y down, +Z forward). Compose chains them in the order you'd apply them, and since this node is pure tensor math - torch.matmul per frame - it's fast and dependency-free. There's no GPU requirement, no model, no download. It just works, which is more than you can say for most nodes in this pack.

Installation is the pack's standard story, but honestly for a node this small you could reimplement it yourself faster than the setup:

git clone https://github.com/Alexankharin/camera-comfyUI.git custom_nodes/camera-comfyUI
cd custom_nodes/camera-comfyUI && python install.py

or via ComfyUI Manager, search camera-comfyUI, Install, restart. TrajectoryCompose needs none of the heavy optional deps (no VGGT, no gsplat), so it shows up and runs even on a machine where the rest of the pack's deep nodes are disabled. When the 4D render you just built is flying off at a weird angle and you suspect the camera path is in the wrong coordinate frame, this node plus TrajectoryInvert is where you go to fix it.

CategoryCamera/Pose

Inputs (2)

NameTypeDefaultDescription
trajectory_aTENSOR
trajectory_bTENSOR

Outputs (1)

NameTypeDescription
trajectoryTENSOR