#include <hboost/asio.hpp>
using namespace HDK_Sample;
using namespace UT::Literal;
void
{
}
void
{
using hboost::asio::ip::udp;
using hboost::asio::ip::address;
try
{
hboost::asio::io_service io_service;
udp::socket socket(io_service, udp::endpoint(udp::v4(), options.
myPort));
int native_socket = socket.native_handle();
{
udp::endpoint remote_endpoint;
hboost::system::error_code
error;
if (res <= 0)
{
continue;
}
size_t num_read = socket.receive_from(
remote_endpoint, 0, error);
if (error && error != hboost::asio::error::message_size)
size_t src_size = num_read;
size_t dst_size = uncompressed_buf.size();
size_t decompress_result;
uncompressed_buf.data(), dst_size,
buf.data(), src_size);
if (decompress_result == 0)
{
}
else
{
state.
setError(
"Could not decompress packet");
}
}
}
{
}
}
{ }
MocapStreamRokokoHDK::~MocapStreamRokokoHDK()
{ }
"hip",
"leftUpLeg", "leftLeg", "leftFoot", "leftToe", "leftToeEnd",
"rightUpLeg", "rightLeg", "rightFoot", "rightToe", "rightToeEnd",
"spine", "chest",
"leftShoulder", "leftUpperArm", "leftLowerArm","leftHand",
"leftIndexProximal", "leftIndexMedial", "leftIndexDistal", "leftIndexTip",
"leftLittleProximal", "leftLittleMedial", "leftLittleDistal", "leftLittleTip",
"leftMiddleProximal", "leftMiddleMedial", "leftMiddleDistal", "leftMiddleTip",
"leftRingProximal", "leftRingMedial", "leftRingDistal", "leftRingTip",
"leftThumbProximal", "leftThumbMedial", "leftThumbDistal", "leftThumbTip",
"neck", "head",
"rightShoulder", "rightUpperArm", "rightLowerArm", "rightHand",
"rightIndexProximal", "rightIndexMedial", "rightIndexDistal", "rightIndexTip",
"rightLittleProximal", "rightLittleMedial", "rightLittleDistal", "rightLittleTip",
"rightMiddleProximal", "rightMiddleMedial", "rightMiddleDistal", "rightMiddleTip",
"rightRingProximal", "rightRingMedial", "rightRingDistal", "rightRingTip",
"rightThumbProximal", "rightThumbMedial", "rightThumbDistal", "rightThumbTip",
};
-1,
0, 1, 2, 3, 4,
0, 6, 7, 8, 9,
0, 11,
12, 13, 14, 15,
16, 17, 18, 19,
16, 21, 22, 23,
16, 25, 26, 27,
16, 29, 30, 31,
16, 33, 34, 35,
12, 37,
12, 39, 40, 41,
42, 43, 44, 45,
42, 47, 48, 49,
42, 51, 52, 53,
42, 55, 56, 57,
42, 59, 60, 61,
};
UT_Matrix4F(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0.9449999928474426, 0.02500000037252903, 1),
UT_Matrix4F(0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0.08799999952316284, 0.9449999928474426, 0.02500000037252903, 1),
UT_Matrix4F(0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0.08799999952316284, 0.4740000069141388, 0.02500000037252903, 1),
UT_Matrix4F(-1, 0, 0, 0, 0, 0, -1, 0, 0, -1, 0, 0, 0.08900000154972076, 0.002000000094994903, 0.02500000037252903, 1),
UT_Matrix4F(-1, 0, 0, 0, 0, 0, -1, 0, 0, -1, 0, 0, 0.08900000154972076, -0.06599999964237213, 0.1679999977350235, 1),
UT_Matrix4F(-1, 0, 0, 0, 0, 0, -1, 0, 0, -1, 0, 0, 0.08900000154972076, -0.07999999821186066, 0.2489999979734421, 1),
UT_Matrix4F(0, 0, -1, 0, 0, 1, 0, 0, 1, 0, 0, 0, -0.08900000154972076, 0.9449999928474426, 0.02500000037252903, 1),
UT_Matrix4F(0, 0, -1, 0, 0, 1, 0, 0, 1, 0, 0, 0, -0.08900000154972076, 0.4740000069141388, 0.02500000037252903, 1),
UT_Matrix4F(-1, 0, 0, 0, 0, 0, -1, 0, 0, -1, 0, 0, -0.08900000154972076, 0.002000000094994903, 0.02500000037252903, 1),
UT_Matrix4F(-1, 0, 0, 0, 0, 0, -1, 0, 0, -1, 0, 0, -0.08900000154972076, -0.06599999964237213, 0.1679999977350235, 1),
UT_Matrix4F(-1, 0, 0, 0, 0, 0, -1, 0, 0, -1, 0, 0, -0.08900000154972076, -0.07999999821186066, 0.2489999979734421, 1),
UT_Matrix4F(-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 1.036999940872192, -0.01799999922513962, 1),
UT_Matrix4F(-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 1.202999949455261, -0.02099999971687794, 1),
UT_Matrix4F(0, 1, 0, 0, -0.9661348462104797, 0, 0.258037656545639, 0, 0.258037656545639, 0, 0.9661348462104797, 0, 0.07699999958276749, 1.478000044822693, 0, 1),
UT_Matrix4F(0, 0, 1, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0.221000000834465, 1.478000044822693, -0.03799999877810478, 1),
UT_Matrix4F(0, 0, 1, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0.5049999952316284, 1.478000044822693, -0.03799999877810478, 1),
UT_Matrix4F(0, 0, 1, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0.8190000057220459, 1.478000044822693, -0.03799999877810478, 1),
UT_Matrix4F(0, 0, 1, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0.9070000052452087, 1.476999998092651, -0.009999999776482582, 1),
UT_Matrix4F(0, 0, 1, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0.9589999914169312, 1.476999998092651, -0.009999999776482582, 1),
UT_Matrix4F(0, 0, 1, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0.9900000095367432, 1.476999998092651, -0.009999999776482582, 1),
UT_Matrix4F(0, 0, 1, 0, -1, 0, 0, 0, 0, -1, 0, 0, 1.021000027656555, 1.476999998092651, -0.009999999776482582, 1),
UT_Matrix4F(0, 0, 1, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0.8960000276565552, 1.476999998092651, -0.07299999892711639, 1),
UT_Matrix4F(0, 0, 1, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0.9369999766349792, 1.476999998092651, -0.07299999892711639, 1),
UT_Matrix4F(0, 0, 1, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0.9639999866485596, 1.476999998092651, -0.07299999892711639, 1),
UT_Matrix4F(0, 0, 1, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0.9900000095367432, 1.476999998092651, -0.07299999892711639, 1),
UT_Matrix4F(0, 0, 1, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0.9079999923706055, 1.476999998092651, -0.03200000151991844, 1),
UT_Matrix4F(0, 0, 1, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0.9599999785423279, 1.476999998092651, -0.03200000151991844, 1),
UT_Matrix4F(0, 0, 1, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0.9950000047683716, 1.476999998092651, -0.03200000151991844, 1),
UT_Matrix4F(0, 0, 1, 0, -1, 0, 0, 0, 0, -1, 0, 0, 1.027999997138977, 1.476999998092651, -0.03200000151991844, 1),
UT_Matrix4F(0, 0, 1, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0.9049999713897705, 1.476999998092651, -0.05400000140070915, 1),
UT_Matrix4F(0, 0, 1, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0.9539999961853027, 1.476999998092651, -0.05400000140070915, 1),
UT_Matrix4F(0, 0, 1, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0.9850000143051147, 1.476999998092651, -0.05400000140070915, 1),
UT_Matrix4F(0, 0, 1, 0, -1, 0, 0, 0, 0, -1, 0, 0, 1.016000032424927, 1.476999998092651, -0.05400000140070915, 1),
UT_Matrix4F(-0.3532975912094116, -0.7077658176422119, 0.6117584705352783, 0, -0.8660871982574463, 0.0002441254764562473, -0.4998929500579834, 0, 0.3536577820777893, -0.7064471244812012, -0.6130731105804443, 0, 0.8420000076293945, 1.476999998092651, -0.00800000037997961, 1),
UT_Matrix4F(0, -0.7061478495597839, 0.7080644369125366, 0, -1, 0, 0, 0, 0, -0.7080644369125366, -0.7061478495597839, 0, 0.8790000081062317, 1.476999998092651, 0.01400000043213367, 1),
UT_Matrix4F(0, -0.7061478495597839, 0.7080644369125366, 0, -1, 0, 0, 0, 0, -0.7080644369125366, -0.7061478495597839, 0, 0.9120000004768372, 1.476999998092651, 0.01400000043213367, 1),
UT_Matrix4F(0, -0.7061478495597839, 0.7080644369125366, 0, -1, 0, 0, 0, 0, -0.7080644369125366, -0.7061478495597839, 0, 0.949999988079071, 1.476999998092651, 0.01400000043213367, 1),
UT_Matrix4F(-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 1.564000010490417, -0.02099999971687794, 1),
UT_Matrix4F(-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 1.677999973297119, -0.02099999971687794, 1),
UT_Matrix4F(0, -1, 0, 0, 0.9661348462104797, 0, 0.258037656545639, 0, -0.258037656545639, 0, 0.9661348462104797, 0, -0.07599999755620956, 1.478000044822693, 0, 1),
UT_Matrix4F(0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 0, 0, -0.2199999988079071, 1.478000044822693, -0.03799999877810478, 1),
UT_Matrix4F(0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 0, 0, -0.5040000081062317, 1.478000044822693, -0.03799999877810478, 1),
UT_Matrix4F(0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 0, 0, -0.8180000185966492, 1.478000044822693, -0.03799999877810478, 1),
UT_Matrix4F(0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 0, 0, -0.9070000052452087, 1.476999998092651, -0.009999999776482582, 1),
UT_Matrix4F(0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 0, 0, -0.9580000042915344, 1.476999998092651, -0.009999999776482582, 1),
UT_Matrix4F(0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 0, 0, -0.9890000224113464, 1.476999998092651, -0.009999999776482582, 1),
UT_Matrix4F(0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 0, 0, -1.019999980926514, 1.476999998092651, -0.009999999776482582, 1),
UT_Matrix4F(0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 0, 0, -0.8949999809265137, 1.476999998092651, -0.07299999892711639, 1),
UT_Matrix4F(0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 0, 0, -0.9369999766349792, 1.476999998092651, -0.07299999892711639, 1),
UT_Matrix4F(0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 0, 0, -0.9629999995231628, 1.476999998092651, -0.07299999892711639, 1),
UT_Matrix4F(0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 0, 0, -0.9890000224113464, 1.476999998092651, -0.07299999892711639, 1),
UT_Matrix4F(0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 0, 0, -0.9079999923706055, 1.476999998092651, -0.03200000151991844, 1),
UT_Matrix4F(0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 0, 0, -0.9599999785423279, 1.476999998092651, -0.03200000151991844, 1),
UT_Matrix4F(0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 0, 0, -0.9940000176429749, 1.476999998092651, -0.03200000151991844, 1),
UT_Matrix4F(0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 0, 0, -1.026999950408936, 1.476999998092651, -0.03200000151991844, 1),
UT_Matrix4F(0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 0, 0, -0.9039999842643738, 1.476999998092651, -0.05400000140070915, 1),
UT_Matrix4F(0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 0, 0, -0.953000009059906, 1.476999998092651, -0.05400000140070915, 1),
UT_Matrix4F(0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 0, 0, -0.984000027179718, 1.476999998092651, -0.05400000140070915, 1),
UT_Matrix4F(0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 0, 0, -1.014999985694885, 1.476999998092651, -0.05400000140070915, 1),
UT_Matrix4F(-0.3532975912094116, 0.7077658176422119, -0.6117584705352783, 0, 0.8660871982574463, 0.0002441254764562473, -0.4998929500579834, 0, -0.3536577820777893, -0.7064471244812012, -0.6130731105804443, 0, -0.8410000205039978, 1.476999998092651, -0.00800000037997961, 1),
UT_Matrix4F(0, 0.7061478495597839, -0.7080644369125366, 0, 1, 0, 0, 0, 0, -0.7080644369125366, -0.7061478495597839, 0, -0.878000020980835, 1.476999998092651, 0.01400000043213367, 1),
UT_Matrix4F(0, 0.7061478495597839, -0.7080644369125366, 0, 1, 0, 0, 0, 0, -0.7080644369125366, -0.7061478495597839, 0, -0.9120000004768372, 1.476999998092651, 0.01400000043213367, 1),
UT_Matrix4F(0, 0.7061478495597839, -0.7080644369125366, 0, 1, 0, 0, 0, 0, -0.7080644369125366, -0.7061478495597839, 0, -0.9490000009536743, 1.476999998092651, 0.01400000043213367, 1),
};
bool
MocapStreamRokokoHDK::parsePacket(
bool &parse_incomplete)
{
{
return false;
}
if (version_val)
version = version_val->
getF();
if (timestamp_val)
setPacketTime(timestamp_val->
getF());
bool is_missing_joints = false;
int num_actors = actors->
entries();
int num_joints =
JOINTS.size();
for (int i = 0; i < num_actors; i++)
{
if (!actor_name)
continue;
receivedSkeleton(name);
bool has_left_glove = true;
bool has_right_glove = true;
bool has_body = true;
bool has_face = true;
if (version >= 3.0
f && meta)
{
bool has_gloves = (has_gloves_value && has_gloves_value->
getB());
has_left_glove = has_gloves && has_left_glove_value
&& has_left_glove_value->
getB();
has_right_glove = has_gloves && has_right_glove_value
&& has_right_glove_value->
getB();
has_body = has_body_value && has_body_value->
getB();
has_face = has_face_value && has_face_value->
getB();
}
Actor *skeleton = mySkeletons.findActor(name);
if (!skeleton)
{
skeleton = mySkeletons.addActor(name);
skeleton->myPoints.setSize(num_joints);
}
skeleton->myIsDirty = true;
for (
int j = 0;
j < num_joints;
j++)
{
ActorPoint &joint = skeleton->myPoints[
j];
if (joint_data)
{
joint_pos = joint_data->
getObject(
"position");
joint_rot = joint_data->
getObject(
"rotation");
if (joint_pos && joint_rot)
{
pos_x = joint_pos->
get(
"x");
pos_y = joint_pos->
get(
"y");
pos_z = joint_pos->
get(
"z");
rot_x = joint_rot->
get(
"x");
rot_y = joint_rot->
get(
"y");
rot_z = joint_rot->
get(
"z");
rot_w = joint_rot->
get(
"w");
}
}
if (!joint_data || !joint_pos || !joint_rot
|| !pos_x || !pos_y || !pos_z
|| !rot_x || !rot_y || !rot_z || !rot_w)
{
joint.myDidReceive = false;
{
bool is_right_hand = joint_name.
fcontain(
"right");
is_missing_joints = (is_right_hand && has_right_glove)
|| (!is_right_hand && has_left_glove);
}
else if (has_body)
{
is_missing_joints = true;
}
continue;
}
rot.getRotationMatrix(rot_mat);
joint.myWorldXform = rot_mat;
joint.myWorldXform.setTranslates(pos);
joint.myDidReceive = true;
}
if (face && has_face)
{
skeleton->myBlendShapes.
clear();
for (const auto& item : *face)
{
{
skeleton->myBlendShapes[item.first] = val->
getF()/100.f;
}
}
}
}
if (is_missing_joints)
addParseWarning("Did not receive data for every joint.");
for (int i = 0; i < num_props; i++)
{
if (!prop_name)
continue;
const char *name = prop_name->
getS();
if (!joint_pos || !joint_rot)
continue;
if (!pos_x || !pos_y || !pos_z
|| !rot_x || !rot_y || !rot_z || !rot_w)
continue;
receivedSkeleton(name);
Actor *device_prop = myProps.findActor(name);
if (!device_prop)
{
device_prop = myProps.addActor(name);
device_prop->myPoints.setSize(1);
}
rot.getRotationMatrix(rot_mat);
ActorPoint &point = device_prop->myPoints[0];
point.myWorldXform = rot_mat;
point.myWorldXform.setTranslates(pos);
point.myDidReceive = true;
}
return true;
}
void
MocapStreamRokokoHDK::computeSkeletonTransforms()
{
int num_skeletons = mySkeletons.size();
int num_joints =
JOINTS.size();
for (int i = 0; i < num_skeletons; i++)
{
Actor &skeleton = mySkeletons(i);
if (!skeleton.myIsDirty)
continue;
skeleton.myIsDirty = false;
if (skeleton.myPoints.size() !=
JOINTS.size())
continue;
bool received_all_points = true;
for (
int j = 0;
j < num_joints;
j++)
{
ActorPoint &joint = skeleton.myPoints[
j];
if (!joint.myDidReceive)
{
received_all_points = false;
continue;
}
{
joint.myLocalXform = joint.myWorldXform;
continue;
}
ActorPoint &parent = skeleton.myPoints[
PARENTS[
j]];
if (!parent.myDidReceive)
continue;
joint.myLocalXform = joint.myWorldXform * parent_xform_inv;
}
if (received_all_points)
continue;
for (
int j = 0;
j < num_joints;
j++)
{
ActorPoint &joint = skeleton.myPoints[
j];
{
joint.myWorldXform = joint.myLocalXform;
continue;
}
ActorPoint &parent = skeleton.myPoints[
PARENTS[
j]];
joint.myWorldXform = joint.myLocalXform * parent.myWorldXform;
}
}
}
void
MocapStreamRokokoHDK::updateJoints(
{
computeSkeletonTransforms();
mySkeletons.resetOccurances();
myProps.resetOccurances();
MocapStreamRokokoHDK::Actor *first_blendshapes_actor = nullptr;
{
const auto& actor_name = actor_name_h.
get(ptoff);
MocapStreamRokokoHDK::Actor *actor = mySkeletons.findActor(actor_name);
if (!actor)
actor = myProps.findActor(actor_name);
else if (!first_blendshapes_actor && actor->myBlendShapes.size() > 0)
first_blendshapes_actor = actor;
if (!actor)
continue;
int i = actor->myOccurances;
actor->myOccurances++;
if (i >= actor->myPoints.entries())
continue;
MocapStreamRokokoHDK::ActorPoint &point = actor->myPoints(i);
point.myWorldXform.getTranslates(pos);
}
transform_h.bumpDataId();
if (!first_blendshapes_actor)
{
for (const auto &blendshape : prev_blendshapes)
{
}
prev_blendshapes.clear();
return;
}
for (const auto &blendshape : prev_blendshapes)
{
if (first_blendshapes_actor->myBlendShapes.contains(blendshape))
continue;
}
prev_blendshapes.clear();
for (auto& item : first_blendshapes_actor->myBlendShapes)
{
prev_blendshapes.append(item.first);
}
}
void
{
if (mySkeletons.removeActor(name))
return;
myProps.removeActor(name);
}
void
{
MocapStreamRokokoHDK::Actor *actor = myProps.findActor(name);
if (actor)
{
joint_name_h.set(ptoff, name);
actor_name_h.set(ptoff, name);
}
else
{
actor = mySkeletons.findActor(name);
if (!actor)
return;
int num_joints =
JOINTS.size();
if (actor->myPoints.size() == num_joints)
{
for (int i = 0; i < num_joints; i++)
{
continue;
auto& xform = rest_xforms[i];
MocapStreamRokokoHDK::ActorPoint &joint
= actor->myPoints[i];
MocapStreamRokokoHDK::ActorPoint &parent
xform.getTranslates(pt);
rest_xforms[
PARENTS[i]].getTranslates(new_origin);
if (joint.myDidReceive && parent.myDidReceive)
{
joint.myWorldXform.getTranslates(joint_pos);
parent.myWorldXform.getTranslates(parent_pos);
bone_length = (joint_pos - parent_pos).
length();
}
else
{
bone_length = (pt - old_origin).
length();
}
pt = new_origin + offset*bone_length/offset.
length();
xform.setTranslates(pt);
}
}
for (int i = 0; i < num_joints; i++)
{
MocapStreamRokokoHDK::ActorPoint &joint
= actor->myPoints[i];
joint_name_h.set(ptoff+i, JOINTS[i]);
actor_name_h.set(ptoff+i, name);
rest_transform_h.set(ptoff+i,
UT_Matrix4F(rest_xforms[i]));
rest_xforms[i].getTranslates(pt);
{
joint.myLocalXform = rest_xforms[i] * parent_xform_inv;
}
else
{
joint.myLocalXform = rest_xforms[i];
}
}
}
}
#if 0
void basicUdpReceiver(ServerState& state, const ServerOptions& options,
{
using hboost::asio::ip::udp;
using hboost::asio::ip::address;
try
{
hboost::asio::io_service io_service;
udp::socket socket(io_service, udp::endpoint(udp::v4(), options.myPort));
int native_socket = socket.native_handle();
state.setPortOpened(true);
while (!state.killed())
{
udp::endpoint remote_endpoint;
hboost::system::error_code
error;
if (res <= 0)
{
state.setError("Request timed out...");
continue;
}
size_t num_read = socket.receive_from(
remote_endpoint, 0, error);
if (error && error != hboost::asio::error::message_size)
state.setConnected(true);
state.resetError();
}
}
{
}
}
void basicTcpClient(ServerState& state, const ServerOptions& options,
{
options.myHostIP, options.myPort, true);
state.setPortOpened(true);
int num_read;
if (client->isValid())
{
while (!state.killed())
{
int cond = client->connect(500);
if (!state.connected())
{
state.setError("Could not connect");
}
while (state.connected() && !state.killed())
{
int status = client->read(
buf.data(),
buf.size(), &num_read, 200);
{
}
{
state.setError("Error receiving data");
state.setConnected(false);
client->close();
options.myHostIP, options.myPort, true);
}
#if UT_ASSERT_LEVEL > 1
else
{
state.setError("No data received within 500ms");
}
#endif
}
}
}
else
{
state.setError("Invalid request");
}
}
#endif