TrussC addon for receiving motion-capture data from OptiTrack Motive over the NatNet protocol.
Wraps OptiTrack's official NatNet SDK (NatNetClient) behind a small tcx::NatNet class — 6DOF rigid bodies + 3D markers, full NatNet 4.x support.
The NatNet SDK is governed by the OptiTrack Plugins EULA and cannot be redistributed, so it is not bundled here. You download it once and drop it in:
- Get the NatNet SDK: https://optitrack.com/support/downloads/developer-tools.html
- Place its
include/andlib/underlibs/natnet/in this addon:(or reconfigure withtcxNatNet/libs/natnet/include/NatNetClient.h, NatNetTypes.h, ... tcxNatNet/libs/natnet/lib/x64/NatNetLib.lib + NatNetLib.dll (Windows) tcxNatNet/libs/natnet/lib/libNatNet.so (Linux)-DNATNET_SDK_ROOT=/path/to/NatNetSDK) CMake prints download/placement instructions if the SDK is missing.
On Windows the build links NatNetLib.lib, but NatNetLib.dll is loaded at
runtime from the executable's folder. The addon copies it there automatically
via a post-build step — nothing to add to your app's CMakeLists.txt (the copy
lives in the addon's own CMake, so it survives trusscli update regenerating the
app CMakeLists). On Linux/macOS this is a no-op (the build embeds an rpath to
libNatNet.so).
Requires CMake ≥ 3.19. On older CMake — or if the auto-copy ever misses — copy the DLL by hand, once per build output folder:
copy libs\natnet\lib\x64\NatNetLib.dll <your-app>\bin\
#include "tcxNatNet.h"
tcx::NatNet natnet;
void tcApp::setup() {
natnet.setup("192.168.0.1"); // Motive server ip; optional 2nd arg = local NIC ip
natnet.setScale(100.0f); // NatNet is metres -> cm
}
void tcApp::update() { natnet.update(); } // non-blocking; once per frame
void tcApp::draw() {
for (size_t i = 0; i < natnet.getNumRigidBody(); i++) {
const auto& rb = natnet.getRigidBodyAt(i);
// rb.getMatrix(), rb.getPosition(), rb.name, rb.isActive()
}
}Rotation comes from Motive as a quaternion, converted to tc::Mat4 (unambiguous —
no transpose guesswork). Positions are metres; use setScale() / setTransform().
Rigid-body names come from Motive's data descriptions (fetched on connect;
call requestDescriptions() again if you add/rename bodies while streaming).
- example-basic — 3D viewer: markers as boxes, rigid bodies as axis gizmos.
Needs the SDK in place (above). Requires C++20 (TrussC core). Add tcxNatNet
to addons.make and run trusscli update. Officially supports Windows + Linux
(NatNet SDK has no macOS build).
MIT (glue). The NatNet SDK is OptiTrack's under its EULA — not included.