//====================================================================================================== // Copyright 2025, Rokoko Glove OptiTrack Integration //====================================================================================================== /** * RokokoDataParser class provides JSON parsing functionality for Rokoko glove data. * This parser handles the LiveFrame_v4 JSON format from Rokoko Studio. */ #pragma once #include #include #include #include // Forward declarations for JSON data structures namespace RokokoData { struct Vector3Frame; struct Vector4Frame; struct ActorJointFrame; struct ActorData; struct LiveFrame_v4; struct Body; } namespace RokokoIntegration { class RokokoDataParser { public: /** * Parses LiveFrame_v4 JSON data * @param jsonString JSON string to parse * @param frame Output frame data structure * @return true if parsing successful */ static bool ParseLiveFrame(const std::string& jsonString, RokokoData::LiveFrame_v4& frame); /** * Validates parsed frame data * @param frame Frame data to validate * @return true if frame data is valid */ static bool ValidateFrameData(const RokokoData::LiveFrame_v4& frame); /** * Extracts finger joint data from frame * @param frame Input frame data * @param leftHandFingers Output left hand finger data * @param rightHandFingers Output right hand finger data * @return true if extraction successful */ static bool ExtractFingerData(const RokokoData::LiveFrame_v4& frame, std::vector& leftHandFingers, std::vector& rightHandFingers); private: /** * Parses body frame data from JSON * @param bodyJson JSON object containing body data * @param body Output body data structure */ static void ParseBodyFrame(const nlohmann::json& bodyJson, RokokoData::Body& body); /** * Parses individual finger joint data from JSON * @param bodyJson JSON object containing body data * @param jointName Name of the joint to parse * @param joint Output joint data structure */ static void ParseFingerJoint(const nlohmann::json& bodyJson, const std::string& jointName, std::shared_ptr& joint); /** * Parses actor data from JSON * @param actorJson JSON object containing actor data * @param actor Output actor data structure * @return true if parsing successful */ static bool ParseActorData(const void* actorJson, RokokoData::ActorData& actor); /** * Parses finger joint data from JSON * @param fingerJson JSON object containing finger data * @param finger Output finger data structure * @return true if parsing successful */ static bool ParseFingerData(const void* fingerJson, RokokoData::ActorJointFrame& finger); /** * Validates quaternion values * @param x, y, z, w Quaternion components * @return true if quaternion is valid */ static bool ValidateQuaternion(float x, float y, float z, float w); /** * Normalizes quaternion values * @param x, y, z, w Quaternion components (modified in place) */ static void NormalizeQuaternion(float& x, float& y, float& z, float& w); }; }