Expand description
OptiTrack NatNet protocol
use natnet::{Decoder, Message, PlannedBody, SyntheticServer, Version};
let server = SyntheticServer::new(Version::V4_1, 1_000_000);
let body = PlannedBody::tracked(7, [1.0, 2.0, 3.0], [0.0, 0.0, 0.0, 1.0]);
let wire = server.datagram(42, 0.5, &[body])?;
let decoded = Decoder::new(Version::V4_1)?.parse(&wire)?;
let Message::FrameOfData(frame) = decoded.message() else {
panic!("expected a frame");
};
assert_eq!(frame.frame_number, 42);
assert_eq!(frame.rigid_bodies[0].id, 7);
assert_eq!(decoded.to_datagram()?, wire);§Where to start
- With
net, callnet::CommandClient::connect_handshaketo getServerInfo::protocol_version. Theexamples/probe.rsexample shows the full exchange. - Build a
Decoderfor that version andparseeach datagram; inspectMessageforModelDeforFrameOfData. - Read the
commandAPI and thenetmodule docs for requests and socket clients.
See Decoder and ParsePolicy for parsing policies; encoder limits are
documented on each method’s # Errors section.
See frame round-trip and float equality
for preservation limits, and Version for supported layouts. Poses are
plain arrays in the server’s frame.
§Features
net: std UDP clients. Peer filtering is not authentication.imagery: the AUGI/1 codec (not part of NatNet); its TCPimagery::net::ImageClientrequires bothimageryandnet.serde: derives on value types.nalgebra: one-way conversions from plain arrays.
Re-exports§
pub use frame::Asset;pub use frame::Device;pub use frame::ForcePlate;pub use frame::FrameOfData;pub use frame::FrameTiming;pub use frame::LabeledMarker;pub use frame::MarkerSet;pub use frame::RawSection;pub use frame::RigidBody;pub use frame::Skeleton;pub use generate::PlannedBody;pub use generate::PlannedSections;pub use generate::SyntheticServer;pub use modeldef::AssetDef;pub use modeldef::CameraDef;pub use modeldef::DataSet;pub use modeldef::DeviceDef;pub use modeldef::ForcePlateDef;pub use modeldef::MarkerDef;pub use modeldef::MarkerSetDef;pub use modeldef::ModelDef;pub use modeldef::RigidBodyDef;pub use modeldef::SkeletonDef;pub use serverinfo::ConnectionInfo;pub use serverinfo::ServerInfo;
Modules§
- command
- Validated NatNet command requests and guarded property writes.
- frame
- FrameOfData (message id 7) — one streamed data frame.
- generate
- Synthetic FrameOfData datagrams for tests and examples.
- imagery
imagery - AUGI/1 camera-image side channel (
imageryfeature). Not part of NatNet. Parse records withparse_record. - modeldef
- MODELDEF data descriptions (message id 5).
- net
net - std UDP clients (
netfeature). - serverinfo
- SERVERINFO (message id 1): server identity, protocol version, clock frequency and data-channel parameters.
Structs§
- Decoded
Message - A decoded message paired with the layout used to interpret it.
- Decoder
- Decodes messages using a supported protocol layout and parsing policy.
Construct from
ServerInfo’s reported version. - Message
Header - The parsed 4-byte framing header.
- Version
- A four-part version quadruple
major.minor.build.revision.
Enums§
- Error
- A NatNet decode/encode failure.
- Message
- A decoded NatNet message — the ones this crate understands, plus a verbatim fallback for any other message id.
- Parse
Policy - Validation of otherwise bounded, structurally decodable input.
Constants§
- HEADER_
LEN - The fixed 4-byte header size.
- NAT_
CONNECT - NAT_CONNECT client hello.
- NAT_
DISCONNECT - NAT_DISCONNECT announcement; no payload or reply.
- NAT_
DISCONNECTBYTIMEOUT - NAT_DISCONNECTBYTIMEOUT — defined by the NatNet SDK 4.1
NatNetTypes.h; the SDK samples neither send nor handle it. - NAT_
DISCOVERY - NAT_DISCOVERY — defined by the NatNet SDK 4.1
NatNetTypes.h; id only. - NAT_
ECHOREQUEST - NAT_ECHOREQUEST — defined by the NatNet SDK 4.1
NatNetTypes.h. The SDK documents no payload layout for it; this crate only names the id. - NAT_
ECHORESPONSE - NAT_ECHORESPONSE — the reply to
NAT_ECHOREQUEST; id only, as above. - NAT_
FRAMEOFDATA - NAT_FRAMEOFDATA streamed frame.
- NAT_
KEEPALIVE - NAT_KEEPALIVE liveness message sent by unicast clients on the command channel; no payload or reply.
- NAT_
MESSAGESTRING - NAT_MESSAGESTRING asynchronous string message; see
parse_message_string. - NAT_
MODELDEF - NAT_MODELDEF data-description reply.
- NAT_
REQUEST - NAT_REQUEST generic request.
- NAT_
REQUEST_ FRAMEOFDATA - NAT_REQUEST_FRAMEOFDATA single-frame request.
- NAT_
REQUEST_ MODELDEF - NAT_REQUEST_MODELDEF data-description request.
- NAT_
RESPONSE - NAT_RESPONSE generic reply.
- NAT_
SERVERINFO - SERVERINFO connect reply.
- NAT_
UNRECOGNIZED_ REQUEST - NAT_UNRECOGNIZED_REQUEST — the reply a NatNet server sends to a request it
does not recognize (
NatNetTypes.hand the SDK samples define it as 100).
Functions§
- marker_
vector nalgebra - A plain
[f32; 3]marker position as annalgebravector. - parse_
message_ string - Parses a NAT_MESSAGESTRING datagram, including its header, into text.