29#include <nlohmann/json.hpp>
31#include <gsl/span_ext>
39#include <unordered_map>
46Eigen::Vector3d toEigen(
const ofbx::DVec3& v) {
47 return {v.x, v.y, v.z};
50Eigen::Affine3d toEigen(
const ofbx::DMatrix& mat) {
51 return Eigen::Affine3d(Eigen::Matrix4d(mat.m));
54Eigen::Vector3i getRotationOrder(ofbx::RotationOrder order) {
56 case ofbx::RotationOrder::EULER_XYZ:
59 case ofbx::RotationOrder::EULER_XZY:
61 case ofbx::RotationOrder::EULER_YZX:
63 case ofbx::RotationOrder::EULER_YXZ:
65 case ofbx::RotationOrder::EULER_ZXY:
67 case ofbx::RotationOrder::EULER_ZYX:
72const char* rotationOrderStr(ofbx::RotationOrder order) {
74 case ofbx::RotationOrder::EULER_XYZ:
76 case ofbx::RotationOrder::EULER_XZY:
78 case ofbx::RotationOrder::EULER_YZX:
80 case ofbx::RotationOrder::EULER_YXZ:
82 case ofbx::RotationOrder::EULER_ZXY:
84 case ofbx::RotationOrder::EULER_ZYX:
86 case ofbx::RotationOrder::SPHERIC_XYZ:
93const char* propertyTypeStr(ofbx::IElementProperty::Type type) {
95 case ofbx::IElementProperty::LONG:
97 case ofbx::IElementProperty::INTEGER:
99 case ofbx::IElementProperty::STRING:
101 case ofbx::IElementProperty::FLOAT:
103 case ofbx::IElementProperty::DOUBLE:
105 case ofbx::IElementProperty::ARRAY_DOUBLE:
106 return "ARRAY_DOUBLE";
107 case ofbx::IElementProperty::ARRAY_INT:
109 case ofbx::IElementProperty::ARRAY_LONG:
111 case ofbx::IElementProperty::ARRAY_FLOAT:
112 return "ARRAY_FLOAT";
118ofbx::IElement* resolveProperty(
const ofbx::Object&
object,
const char* name);
119std::string resolveStringProperty(
const ofbx::Object&
object,
const char* name);
123 const std::vector<const ofbx::Object*>& jointFbxNodes) {
126 for (
size_t jointIndex = 0; jointIndex < jointFbxNodes.size(); ++jointIndex) {
127 const ofbx::Object* jointNode = jointFbxNodes.at(jointIndex);
128 if (jointNode ==
nullptr) {
138 if (resolveProperty(*jointNode,
"physicalProperties") ==
nullptr) {
143 resolveStringProperty(*jointNode,
"physicalProperties"),
144 skeleton.joints.at(jointIndex).name,
146 result.push_back(std::move(*jointProperties));
148 }
catch (
const std::exception& e) {
150 "Skipping physical properties for FBX joint '{}': {}",
151 skeleton.joints.at(jointIndex).name,
160Eigen::Quaternion<T> computeEulerRotation(
161 const Eigen::Vector3<T>& angles,
162 ofbx::RotationOrder order) {
163 using VecType = Eigen::Vector3<T>;
164 using QuaternionType = Eigen::Quaternion<T>;
166 if (order == ofbx::RotationOrder::SPHERIC_XYZ) {
168 return QuaternionType(
169 std::sqrt(std::max(T(1) - angles.squaredNorm(), T(0))), angles.x(), angles.y(), angles.z());
171 const Eigen::Vector3i rotOrder = getRotationOrder(order);
172 QuaternionType result = QuaternionType::Identity();
173 for (uint32_t index = 0; index < 3; ++index) {
174 const auto& rIndex = rotOrder(index);
175 result = QuaternionType(Eigen::AngleAxis<T>(angles(rIndex), VecType::Unit(rIndex))) * result;
181Eigen::Quaterniond fbxEulerRotationToQuat(
182 const ofbx::DVec3& eulerAngles,
183 const ofbx::RotationOrder rotOrder) {
184 const Eigen::Vector3d rotDegrees = toEigen(eulerAngles).head<3>();
185 const Eigen::Vector3d rotRadians =
toRad<double>() * rotDegrees;
186 return computeEulerRotation<double>(rotRadians, rotOrder);
189const ofbx::IElement* findChild(
const ofbx::IElement& element,
const char*
id) {
190 auto* curChild = element.getFirstChild();
192 if (curChild->getID() ==
id) {
195 curChild = curChild->getSibling();
200bool equalsCaseInsensitive(
const ofbx::DataView& data,
const char* rhs) {
202 const char* c2 = (
const char*)data.begin;
203 while (*c && c2 != (
const char*)data.end) {
204 if (tolower(*c) != tolower(*c2)) {
210 return c2 == (
const char*)data.end && *c ==
'\0';
213bool equalsCaseInsensitive(
const std::string& lhs,
const char* rhs) {
215 auto it = lhs.begin();
216 while (*c && it != lhs.end()) {
217 if (tolower(
static_cast<unsigned char>(*c)) != tolower(
static_cast<unsigned char>(*it))) {
223 return it == lhs.end() && *c ==
'\0';
227ofbx::IElement* resolveProperty(
const ofbx::Object&
object,
const char* name) {
230 const ofbx::IElement* props = findChild(
object.element,
"Properties70");
235 ofbx::IElement* prop = props->getFirstChild();
237 auto* firstProp = prop->getFirstProperty();
239 firstProp->getType() != ofbx::IElementProperty::STRING,
240 "Expected string for first property value but got {}.",
241 propertyTypeStr(firstProp->getType()));
245 if (firstProp !=
nullptr && equalsCaseInsensitive(firstProp->getValue(), name)) {
248 prop = prop->getSibling();
255const ofbx::IElementProperty* getElementProperty(
const ofbx::IElement* element,
size_t iProp) {
256 auto* prop = element->getFirstProperty();
257 for (
size_t j = 0; j < iProp; ++j) {
258 if (prop ==
nullptr) {
261 prop = prop->getNext();
267double resolveDoubleProperty(
const ofbx::Object&
object,
const char* name) {
268 const ofbx::IElement* element = resolveProperty(
object, name);
269 MT_THROW_IF(element ==
nullptr,
"Unable to find property element in {}",
object.name);
270 const ofbx::IElementProperty* x = getElementProperty(element, 4);
271 MT_THROW_IF(x ==
nullptr,
"Unable to find property {} in {}", name,
object.name);
272 if (x->getType() == ofbx::IElementProperty::DOUBLE) {
273 return x->getValue().toDouble();
274 }
else if (x->getType() == ofbx::IElementProperty::FLOAT) {
275 return x->getValue().toFloat();
278 "For property {}, expected float/double but got {}.", name, propertyTypeStr(x->getType()));
282std::string resolveStringProperty(
const ofbx::Object&
object,
const char* name) {
283 const ofbx::IElement* element = resolveProperty(
object, name);
284 MT_THROW_IF(element ==
nullptr,
"Unable to find property element in {}",
object.name);
285 const ofbx::IElementProperty* x = getElementProperty(element, 4);
286 MT_THROW_IF(x ==
nullptr,
"Unable to find property {} in {}", name,
object.name);
287 if (x->getType() == ofbx::IElementProperty::STRING) {
288 const auto& val = x->getValue();
289 const size_t len = val.end - val.begin;
290 std::string result(
reinterpret_cast<const char*
>(val.begin), len);
293 MT_THROW(
"For property {}, expected string but got {}.", name, propertyTypeStr(x->getType()));
297template <
typename VecArray,
typename EltType>
298VecArray extractPropertyArrayImp(
const ofbx::IElementProperty* prop,
const char* what) {
299 using VecType =
typename VecArray::value_type;
300 using Scalar =
typename VecType::Scalar;
302 const auto nScalar = prop->getCount();
307 const auto vecLength = VecType::RowsAtCompileTime;
308 const auto nVec = nScalar / vecLength;
311 nVec * vecLength != nScalar,
312 "For {}; expected to be divisible by {} but got {} as count",
317 std::vector<EltType> vals(nScalar);
318 prop->getValues(vals.data(), (
int)(
sizeof(EltType) * vals.size()));
321 result.reserve(nVec);
322 for (
int iVec = 0; iVec < nVec; ++iVec) {
324 for (Eigen::DenseIndex k = 0; k < vecLength; ++k) {
325 v[k] = (Scalar)vals[iVec *
static_cast<size_t>(vecLength) + k];
333template <
typename VecArray>
334VecArray extractPropertyVecArray(
const ofbx::IElement* element,
const char* what) {
335 const auto* prop = element->getFirstProperty();
336 MT_THROW_IF(prop ==
nullptr,
"For element {} found no property.", what);
337 if (prop->getType() == ofbx::IElementProperty::ARRAY_DOUBLE) {
338 return extractPropertyArrayImp<VecArray, double>(prop, what);
339 }
else if (prop->getType() == ofbx::IElementProperty::ARRAY_FLOAT) {
340 return extractPropertyArrayImp<VecArray, float>(prop, what);
343 "For property {} expected float/double array but got {}.",
345 propertyTypeStr(prop->getType()));
350ofbx::IElementProperty::Type propertyArrayType();
352ofbx::IElementProperty::Type propertyArrayType<double>() {
353 return ofbx::IElementProperty::ARRAY_DOUBLE;
356ofbx::IElementProperty::Type propertyArrayType<float>() {
357 return ofbx::IElementProperty::ARRAY_FLOAT;
360ofbx::IElementProperty::Type propertyArrayType<int>() {
361 return ofbx::IElementProperty::ARRAY_INT;
365std::vector<T> extractPropertyArray(
const ofbx::IElement* element,
const char* what) {
366 const auto* prop = element->getFirstProperty();
367 MT_THROW_IF(prop ==
nullptr,
"For element {} found no property.", what);
368 if (prop->getType() == propertyArrayType<T>()) {
369 std::vector<T> vals(prop->getCount());
370 prop->getValues(&vals[0], (
int)(
sizeof(T) * vals.size()));
374 "For property {}, expected {} but got {}.",
376 propertyTypeStr(propertyArrayType<T>()),
377 propertyTypeStr(prop->getType()));
381std::vector<double> extractPropertyFloatArray(
const ofbx::IElement* element,
const char* what) {
382 const auto* prop = element->getFirstProperty();
383 MT_THROW_IF(prop ==
nullptr,
"For element {}, found no property.", what);
384 if (prop->getType() == ofbx::IElementProperty::ARRAY_DOUBLE) {
385 return extractPropertyArray<double>(element, what);
386 }
else if (prop->getType() == ofbx::IElementProperty::ARRAY_FLOAT) {
387 auto res = extractPropertyArray<float>(element, what);
388 std::vector<double> result(res.begin(), res.end());
392 "For property {}, expected float array but got {}.",
394 propertyTypeStr(prop->getType()));
398void stripNamespace(
const ofbx::Object* obj) {
399 const char* lastColon = std::strrchr(obj->name,
':');
401 const char* newName = lastColon + 1;
402 std::memmove(
const_cast<char*
>(obj->name), newName, std::strlen(newName) + 1);
406void extractCollisionCapsule(
const ofbx::Object* node,
size_t parent,
CollisionGeometry& capsules) {
407 const double length = resolveDoubleProperty(*node,
"length");
408 const double rad_a = resolveDoubleProperty(*node,
"rad_a");
409 const double rad_b = resolveDoubleProperty(*node,
"rad_b");
411 const auto xf = node->getLocalTransform();
414 capsule.parent = parent;
415 capsule.length = length;
416 capsule.radius = {rad_a, rad_b};
417 capsule.transformation = toEigen(xf).cast<
float>();
418 capsules.emplace_back(capsule);
421void extractCollisionEllipsoid(
422 const ofbx::Object* node,
425 const double radiusX = resolveDoubleProperty(*node,
"radii_x");
426 const double radiusY = resolveDoubleProperty(*node,
"radii_y");
427 const double radiusZ = resolveDoubleProperty(*node,
"radii_z");
429 const auto xf = node->getLocalTransform();
432 ellipsoid.parent = parent;
433 ellipsoid.radii = Eigen::Vector3f(
434 static_cast<float>(radiusX),
static_cast<float>(radiusY),
static_cast<float>(radiusZ));
435 ellipsoid.transformation = toEigen(xf).cast<
float>();
436 collisionGeometry.emplace_back(ellipsoid);
439void extractCollisionBox(
440 const ofbx::Object* node,
443 const double halfExtentsX = resolveDoubleProperty(*node,
"half_extents_x");
444 const double halfExtentsY = resolveDoubleProperty(*node,
"half_extents_y");
445 const double halfExtentsZ = resolveDoubleProperty(*node,
"half_extents_z");
447 const auto xf = node->getLocalTransform();
451 box.halfExtents = Eigen::Vector3f(
452 static_cast<float>(halfExtentsX),
453 static_cast<float>(halfExtentsY),
454 static_cast<float>(halfExtentsZ));
455 box.transformation = toEigen(xf).cast<
float>();
456 collisionGeometry.emplace_back(box);
459void extractCollisionPrimitive(
460 const ofbx::Object* node,
463 auto* shapeProperty = resolveProperty(*node,
"col_shape");
464 if (shapeProperty !=
nullptr) {
465 const std::string shape = resolveStringProperty(*node,
"col_shape");
466 if (equalsCaseInsensitive(shape,
"ellipsoid") ||
467 equalsCaseInsensitive(shape,
"collision_ellipsoid")) {
468 extractCollisionEllipsoid(node, parent, collisionGeometry);
471 if (equalsCaseInsensitive(shape,
"box") || equalsCaseInsensitive(shape,
"collision_box")) {
472 extractCollisionBox(node, parent, collisionGeometry);
475 if (equalsCaseInsensitive(shape,
"tapered_capsule") ||
476 equalsCaseInsensitive(shape,
"capsule") ||
477 equalsCaseInsensitive(shape,
"collision_capsule")) {
478 extractCollisionCapsule(node, parent, collisionGeometry);
483 "Unknown FBX collision shape '{}' on node '{}'; falling back to tapered capsule.",
488 extractCollisionCapsule(node, parent, collisionGeometry);
491void extractLocator(
const ofbx::Object* node,
size_t parent,
LocatorList& locators) {
493 locator.
name = node->name;
494 const auto translationOffset = node->getLocalTranslation();
495 locator.offset = toEigen(translationOffset).cast<
float>();
496 locator.parent = parent;
497 locators.push_back(locator);
500void validateAndLogRotation(
501 const ofbx::Object* node,
502 const std::string& jointName,
504 auto order = node->getRotationOrder();
505 if (order != ofbx::RotationOrder::EULER_XYZ) {
508 "momentum supports only XYZ rotation; joint {} has {} rotation order.",
510 rotationOrderStr(order));
513 "momentum supports only XYZ rotation; joint {} has {} rotation order.",
515 rotationOrderStr(order));
520Eigen::Quaterniond computeLocalRotation(
521 const ofbx::Object* node,
522 const std::string& jointName,
524 auto order = node->getRotationOrder();
525 auto localRot = fbxEulerRotationToQuat(node->getLocalRotation(), order);
526 if (Eigen::AngleAxisd(localRot).angle() > 1e-2) {
529 "{}: Node {} has nonzero rest rotation ({}, {}, {}), which will be baked into the skeleton.",
532 node->getLocalRotation().x,
533 node->getLocalRotation().y,
534 node->getLocalRotation().z);
537 "{}: Node {} has nonzero rest rotation ({}, {}, {}) and it will be ignored",
540 node->getLocalRotation().x,
541 node->getLocalRotation().y,
542 node->getLocalRotation().z);
543 localRot = Eigen::Quaterniond::Identity();
550 const ofbx::Object* curSkelNode,
553 std::vector<const ofbx::Object*>& fbxObjects,
557 MT_CHECK(curSkelNode,
"Skeleton node for parent '{}' is null", parent);
559 if (!curSkelNode->isNode()) {
563 const auto type = curSkelNode->getType();
564 const std::string jointName = curSkelNode->name;
566 if (type == ofbx::Object::Type::NULL_NODE) {
567 auto* res = resolveProperty(*curSkelNode,
"col_type");
568 if (res !=
nullptr) {
569 extractCollisionPrimitive(curSkelNode, parent, capsules);
571 extractLocator(curSkelNode, parent, locators);
574 while (ofbx::Object* child = curSkelNode->resolveObjectLink(i++)) {
575 parseSkeleton(child,
kInvalidIndex, skeleton, fbxObjects, capsules, locators, permissive);
581 if (type != ofbx::Object::Type::LIMB_NODE) {
585 validateAndLogRotation(curSkelNode, jointName, permissive);
586 const Eigen::Quaterniond localRot = computeLocalRotation(curSkelNode, jointName, permissive);
588 const auto preRotEuler = curSkelNode->getPreRotation();
589 const Eigen::Quaterniond preRotation =
590 fbxEulerRotationToQuat(preRotEuler, ofbx::RotationOrder::EULER_XYZ) * localRot;
593 toEigen(curSkelNode->getPostRotation()).head<3>().norm() > 1e-8,
594 "{}: Node {} has nonzero post-rotation; it will be ignored.",
598 const auto translationOffset = curSkelNode->getLocalTranslation();
601 joint.name = jointName;
602 joint.parent = parent;
603 joint.preRotation = preRotation.cast<
float>();
604 joint.translationOffset = toEigen(translationOffset).cast<
float>();
605 const size_t jointIndex = skeleton.joints.size();
606 skeleton.joints.push_back(joint);
607 fbxObjects.push_back(curSkelNode);
610 while (ofbx::Object* child = curSkelNode->resolveObjectLink(i++)) {
611 parseSkeleton(child, jointIndex, skeleton, fbxObjects, capsules, locators, permissive);
616parseSkeleton(
const ofbx::Object* sceneRoot,
const std::string& skelRoot,
Permissive permissive) {
617 MT_CHECK(sceneRoot,
"Scene root with skel root '{}' is null", skelRoot);
622 std::vector<const ofbx::Object*>
626 while (ofbx::Object* child = sceneRoot->resolveObjectLink(i)) {
628 if (!skelRoot.empty() && child->name != skelRoot) {
631 parseSkeleton(child,
kInvalidIndex, skeleton, jointFbxNodes, collision, locators, permissive);
634 return {skeleton, jointFbxNodes, locators, collision};
640void populatePolyFaceData(
644 size_t textureCoordOffset) {
645 for (
const auto& idx : vertices.indices) {
646 mesh.polyFaces.push_back(idx +
static_cast<uint32_t
>(vertexOffset));
648 for (
size_t i = 0; i + 1 < vertices.offsets.size(); ++i) {
649 mesh.polyFaceSizes.push_back(vertices.offsets[i + 1] - vertices.offsets[i]);
651 if (!vertices.textureIndices.empty()) {
652 for (
const auto& idx : vertices.textureIndices) {
653 mesh.polyTexcoordFaces.push_back(idx +
static_cast<uint32_t
>(textureCoordOffset));
670std::vector<Eigen::Vector2f>
671parseUVMapping(
const ofbx::IElement& geomElement,
PolygonData& vertices,
size_t nVerts) {
672 std::vector<Eigen::Vector2f> textureCoords;
673 const auto* layer_uv_element = findChild(geomElement,
"LayerElementUV");
674 if (layer_uv_element ==
nullptr) {
675 return textureCoords;
678 const auto* uvs_element = findChild(*layer_uv_element,
"UV");
679 if (uvs_element ==
nullptr || !uvs_element->getFirstProperty()) {
680 MT_LOGE(
"No UVs found in mesh element.");
681 return textureCoords;
684 EMapping mapping = MappingUnknown;
685 const auto* mapping_element = findChild(*layer_uv_element,
"MappingInformationType");
686 if (mapping_element !=
nullptr && mapping_element->getFirstProperty() !=
nullptr) {
687 const ofbx::DataView& view = mapping_element->getFirstProperty()->getValue();
688 if (view ==
"ByPolygonVertex") {
689 mapping = MappingByPolyVertex;
690 }
else if (view ==
"ByVertex" || view ==
"ByVertice") {
691 mapping = MappingByVertex;
695 mapping == MappingUnknown,
696 "Don't currently know how to deal with mapping type that is not 'ByPolygonVertex' or 'ByVertex'.");
698 EReference reference = RefUnknown;
699 const auto* reference_element = findChild(*layer_uv_element,
"ReferenceInformationType");
700 if (reference_element !=
nullptr && reference_element->getFirstProperty() !=
nullptr) {
701 const ofbx::DataView& view = reference_element->getFirstProperty()->getValue();
702 if (view ==
"IndexToDirect") {
703 reference = RefIndexToDirect;
704 }
else if (view ==
"Direct") {
705 reference = RefDirect;
709 reference == RefUnknown,
710 "Don't currently know how to deal with reference type that is not 'IndexToDirect' or 'Direct'.");
712 textureCoords = extractPropertyVecArray<std::vector<Eigen::Vector2f>>(uvs_element,
"UV");
714 if (reference == RefIndexToDirect) {
715 const auto* indices_element = findChild(*layer_uv_element,
"UVIndex");
716 MT_THROW_IF(indices_element ==
nullptr,
"Missing indices element.");
717 const auto textureIndices = extractPropertyArray<int>(indices_element,
"PolygonVertexIndex");
720 textureIndices.size() != vertices.indices.size(),
721 "Mismatch between texture indices size {} and vertex indices size {}.",
722 textureIndices.size(),
723 vertices.indices.size());
725 textureIndices.begin(), textureIndices.end(), std::back_inserter(vertices.textureIndices));
726 }
else if (reference == RefDirect) {
727 if (mapping == MappingByPolyVertex) {
729 textureCoords.size() != vertices.indices.size(),
730 "Mismatch between 'Direct' texture coord array size {} and vertex indices size {}.",
731 textureCoords.size(),
732 vertices.indices.size());
733 vertices.textureIndices.resize(vertices.indices.size());
734 }
else if (mapping == MappingByVertex) {
736 textureCoords.size() != nVerts,
737 "Mismatch between 'Direct' texture coord array size {} and vertex count {}.",
738 textureCoords.size(),
741 std::iota(vertices.textureIndices.begin(), vertices.textureIndices.end(), 0);
743 MT_THROW(
"UV reading code failed to handle a valid reference type. This is a bug.");
746 for (
auto& tc : textureCoords) {
747 tc.y() = 1.0f - tc.y();
750 return textureCoords;
753void parseBlendShapes(
754 const ofbx::BlendShape* blendshapes,
755 const std::vector<Eigen::Vector3f>& vertexPositions,
760 blendShape = std::make_shared<BlendShape>();
764 int numChannels = blendshapes->getBlendShapeChannelCount();
765 for (
int c = 0; c < numChannels; ++c) {
766 const auto* channel = blendshapes->getBlendShapeChannel(c);
767 newShapes += channel->getShapeCount();
770 std::vector<std::string> shapeNames = blendShape->getShapeNames();
771 MatrixXf shapes = blendShape->getShapeVectors();
772 const int currentShapes =
static_cast<int>(shapes.cols());
773 shapes.conservativeResize(shapes.rows() + vertexPositions.size() * 3, shapes.cols() + newShapes);
774 shapes.bottomRows(vertexPositions.size() * 3) =
775 MatrixXf::Zero(vertexPositions.size() * 3, shapes.cols());
776 shapes.rightCols(newShapes) = MatrixXf::Zero(shapes.rows(), newShapes);
777 shapeNames.resize(shapeNames.size() + newShapes,
"");
780 for (
int c = 0; c < numChannels; ++c) {
781 const auto*
const channel = blendshapes->getBlendShapeChannel(c);
782 int numShapes = channel->getShapeCount();
783 for (
int s = 0; s < numShapes; ++s) {
784 const auto*
const shape = channel->getShape(s);
785 int numVertices = shape->getVertexCount();
786 const auto*
const shapeV = shape->getVertices();
787 int numIndices = shape->getIndexCount();
788 const auto*
const indexV = shape->getIndices();
789 MT_CHECK(numIndices == numVertices);
790 for (
int v = 0; v < numVertices; ++v) {
791 MT_THROW_IF(v >= numIndices,
"Vertex index {} exceeds numIndices {}", v, numIndices);
792 shapes(vertexOffset * 3 + indexV[v] * 3 + 0, currentShapes + shapeIndex) = shapeV[v].x;
793 shapes(vertexOffset * 3 + indexV[v] * 3 + 1, currentShapes + shapeIndex) = shapeV[v].y;
794 shapes(vertexOffset * 3 + indexV[v] * 3 + 2, currentShapes + shapeIndex) = shapeV[v].z;
797 static_cast<size_t>(currentShapes + shapeIndex) < shapeNames.size(),
798 "Shape index {} out of bounds (shapeNames size: {})",
799 currentShapes + shapeIndex,
801 shapeNames[currentShapes + shapeIndex] = shape->name;
806 blendShape->setShapeVectors(shapes, shapeNames);
807 blendShape->setBaseShape(mesh.vertices);
810using VertexBoneWithWeight = std::tuple<size_t, size_t, double>;
812void collectClusterWeights(
813 const ofbx::Skin* fbxskin,
814 const std::unordered_map<const ofbx::Object*, size_t>& boneMap,
816 std::vector<VertexBoneWithWeight>& weights,
818 const char* meshName) {
819 int clusterCount = fbxskin->getClusterCount();
820 for (
int clusterIndex = 0; clusterIndex < clusterCount; clusterIndex++) {
821 const auto* cluster = fbxskin->getCluster(clusterIndex);
824 const auto* bone = cluster->getLink();
825 const auto fbxJointItr = boneMap.find(bone);
827 fbxJointItr == boneMap.end(),
828 "Cluster {} references invalid bone: {}",
832 const size_t boneIndex = fbxJointItr->second;
833 if (boneIndex < inverseBindPoseTransforms.size()) {
834 inverseBindPoseTransforms[boneIndex] =
835 toEigen(cluster->getTransformLinkMatrix()).inverse().cast<
float>();
838 const auto* skinning_indices_element = findChild(cluster->element,
"Indexes");
839 if (skinning_indices_element ==
nullptr || !skinning_indices_element->getFirstProperty()) {
841 "Skipping as no skinning indices found in cluster element {} (mesh is {}).",
847 const auto skinningIndices = extractPropertyArray<int>(skinning_indices_element,
"Indexes");
849 const auto* skinning_weights_element = findChild(cluster->element,
"Weights");
851 skinning_weights_element ==
nullptr || !skinning_weights_element->getFirstProperty(),
852 "No skinning weights found in cluster element {} (mesh is {}).",
855 const auto skinningWeights = extractPropertyFloatArray(skinning_weights_element,
"Weights");
858 skinningIndices.size() != skinningWeights.size(),
859 "Mismatch between indices count ({}) and weight count ({}) in cluster {}",
860 skinningIndices.size(),
861 skinningWeights.size(),
864 const auto numBoneVertexIndices = skinningIndices.size();
865 for (
size_t boneVIndex = 0; boneVIndex < numBoneVertexIndices; boneVIndex++) {
866 const int boneVertexIndex = skinningIndices[boneVIndex];
868 boneVertexIndex < 0 ||
static_cast<size_t>(boneVertexIndex) >= nVerts,
869 "Invalid vertex index ({}) in cluster {}",
872 const auto boneWeight = skinningWeights[boneVIndex];
873 if (boneWeight <= 0) {
878 "{}: Bone weight of {} found; expected value between 0 and 1.",
881 weights.emplace_back(boneVertexIndex, boneIndex, boneWeight);
886void assignSkinWeights(
887 std::vector<VertexBoneWithWeight>& weights,
888 std::unique_ptr<SkinWeights>& skinWeights,
891 const char* meshName) {
893 skinWeights = std::make_unique<SkinWeights>();
895 skinWeights->index.conservativeResize(vertexOffset + nVerts, Eigen::NoChange);
896 skinWeights->weight.conservativeResize(vertexOffset + nVerts, Eigen::NoChange);
897 skinWeights->index.bottomRows(nVerts).setZero();
898 skinWeights->weight.bottomRows(nVerts).setZero();
903 [](
const VertexBoneWithWeight& b1,
const VertexBoneWithWeight& b2) {
904 return std::get<0>(b1) < std::get<0>(b2);
906 auto weightItr = weights.begin();
908 using BoneWeight = std::pair<size_t, double>;
909 std::vector<BoneWeight> curBoneWeights;
911 for (
size_t iVertex = 0; iVertex < nVerts; ++iVertex) {
912 curBoneWeights.clear();
914 weightItr == weights.end() || std::get<0>(*weightItr) != iVertex,
915 "No weights found for vertex {} in mesh {}",
919 auto vertWeightsBegin = weightItr;
920 while (weightItr != weights.end() && std::get<0>(*weightItr) == iVertex) {
923 auto vertWeightsEnd = weightItr;
925 for (
auto itr = vertWeightsBegin; itr != vertWeightsEnd; ++itr) {
926 const auto boneIndex = std::get<1>(*itr);
927 const auto boneWeight = std::clamp(std::get<2>(*itr), 0.0, 1.0);
928 curBoneWeights.emplace_back(boneIndex, boneWeight);
932 curBoneWeights.begin(),
933 curBoneWeights.end(),
934 [](
const BoneWeight& b1,
const BoneWeight& b2) { return b1.second > b2.second; });
935 curBoneWeights.resize(std::min<size_t>(curBoneWeights.size(),
kMaxSkinJoints));
937 double weightSum = 0;
938 for (
const auto& [idx, weight] : curBoneWeights) {
943 weightSum <= 0,
"Empty weight sum found for vertex {} in mesh {}", iVertex, meshName);
945 for (
int iPr = 0; iPr < curBoneWeights.size() && iPr <
kMaxSkinJoints; ++iPr) {
947 const auto [boneIdx, weight] = curBoneWeights[iPr];
948 skinWeights->index(vertexOffset + iVertex, iPr) =
static_cast<uint32_t
>(boneIdx);
949 skinWeights->weight(vertexOffset + iVertex, iPr) = weight / weightSum;
954void parseSkinnedModel(
955 const ofbx::Mesh* meshRoot,
956 const std::vector<const ofbx::Object*>& boneFbxNodes,
958 std::unique_ptr<SkinWeights>& skinWeights,
963 const auto* geometry = meshRoot->getGeometry();
964 const auto& geomElement = geometry->element;
966 const auto* vertices_element = findChild(geomElement,
"Vertices");
968 vertices_element ==
nullptr || !vertices_element->getFirstProperty(),
969 "No vertices found in mesh element.");
970 const auto vertexPositions =
971 extractPropertyVecArray<std::vector<Eigen::Vector3f>>(vertices_element,
"Vertices");
972 const auto nVerts = vertexPositions.size();
974 const auto* polys_element = findChild(geomElement,
"PolygonVertexIndex");
976 polys_element ==
nullptr || !polys_element->getFirstProperty(),
977 "No polygons found in mesh element.");
978 const auto indices = extractPropertyArray<int>(polys_element,
"PolygonVertexIndex");
981 vertices.
indices.reserve(indices.size());
982 for (
const auto& i : indices) {
984 vertices.indices.push_back(-(i + 1));
985 vertices.offsets.push_back((uint32_t)vertices.indices.size());
987 vertices.indices.push_back(i);
991 std::vector<Eigen::Vector2f> textureCoords = parseUVMapping(geomElement, vertices, nVerts);
993 auto errMsg = vertices.errorMessage(nVerts);
994 MT_THROW_IF(!errMsg.empty(),
"Error reading polygons from FBX file: {}", errMsg);
995 errMsg = vertices.warnMessage(textureCoords.size());
996 MT_LOGW_IF(!errMsg.empty(),
"Error reading polygon data from FBX file: {}", errMsg);
998 const size_t vertexOffset = mesh.vertices.size();
1000 std::begin(vertexPositions), std::end(vertexPositions), std::back_inserter(mesh.vertices));
1001 for (
const auto& t :
triangulate(vertices.indices, vertices.offsets)) {
1002 mesh.faces.emplace_back(t + Eigen::Vector3i::Constant(
static_cast<int>(vertexOffset)));
1005 mesh.normals.resize(vertexOffset + nVerts, Vector3f::Zero());
1006 mesh.colors.resize(vertexOffset + nVerts, Vector3b::Constant(255));
1007 mesh.confidence.resize(vertexOffset + nVerts, 1);
1009 const size_t textureCoordOffset = mesh.texcoords.size();
1010 std::copy(std::begin(textureCoords), std::end(textureCoords), std::back_inserter(mesh.texcoords));
1011 for (
const auto& t :
triangulate(vertices.textureIndices, vertices.offsets)) {
1012 mesh.texcoord_faces.emplace_back(
1013 t + Eigen::Vector3i::Constant(
static_cast<int>(textureCoordOffset)));
1017 populatePolyFaceData(mesh, vertices, vertexOffset, textureCoordOffset);
1019 const auto* blendshapes = geometry->getBlendShape();
1021 parseBlendShapes(blendshapes, vertexPositions, vertexOffset, blendShape, mesh);
1024 const auto* fbxskin = geometry->getSkin();
1028 "No skin found for geometry. Enable permissive mode to allow saving as a mesh-only character.");
1032 std::unordered_map<const ofbx::Object*, size_t> boneMap;
1033 for (
size_t i = 0; i < boneFbxNodes.size(); ++i) {
1034 boneMap.insert(std::make_pair(boneFbxNodes[i], i));
1037 std::vector<VertexBoneWithWeight> weights;
1038 weights.reserve(2 * nVerts);
1039 collectClusterWeights(
1040 fbxskin, boneMap, inverseBindPoseTransforms, weights, nVerts, meshRoot->name);
1041 assignSkinWeights(weights, skinWeights, vertexOffset, nVerts, meshRoot->name);
1044double getMaxSeconds(
const std::vector<const ofbx::AnimationCurveNode*>& curves) {
1045 ofbx::i64 fbxTime = 0;
1046 for (
const ofbx::AnimationCurveNode* node : curves) {
1047 for (
int iChannel = 0; iChannel < 3; ++iChannel) {
1048 const ofbx::AnimationCurve* channel = node->getCurve(iChannel);
1049 if (channel ==
nullptr) {
1052 const int count = channel->getKeyCount();
1056 const ofbx::i64* time = channel->getKeyTime();
1057 if (time[count - 1] > fbxTime) {
1058 fbxTime = time[count - 1];
1062 return ofbx::fbxTimeToSeconds(fbxTime);
1065size_t findJointIndex(
1066 const ofbx::Object* queryObj,
1067 const std::vector<const ofbx::Object*>& fbxNodes) {
1069 for (
size_t iNode = 0; iNode < fbxNodes.size(); ++iNode) {
1070 if (queryObj == fbxNodes[iNode]) {
1080 const ofbx::AnimationStack* animStack,
1081 const std::vector<const ofbx::Object*>& boneFbxNodes,
1087 std::vector<const ofbx::AnimationCurveNode*> skeletonAnimCurves;
1091 while (
const ofbx::AnimationLayer* animLayer = animStack->getLayer(iLayer++)) {
1093 while (
const ofbx::AnimationCurveNode* curve = animLayer->getCurveNode(iCurve++)) {
1095 const ofbx::Object* bone = curve->getBone();
1100 for (
const ofbx::Object* jointNode : boneFbxNodes) {
1101 if (bone == jointNode) {
1102 skeletonAnimCurves.push_back(curve);
1108 if (skeletonAnimCurves.empty()) {
1112 const double totalSeconds = getMaxSeconds(skeletonAnimCurves);
1113 const size_t numFrames = ceil(totalSeconds * fps) + 1;
1117 boneFbxNodes.size() < skeleton.joints.size(),
1118 "boneFbxNodes size {} is less than skeleton joints size {}",
1119 boneFbxNodes.size(),
1120 skeleton.joints.size());
1121 for (
size_t i = 0; i < skeleton.joints.size(); ++i) {
1129 const auto localRot = boneFbxNodes[i]->getLocalRotation();
1135 .setConstant(std::log2(boneFbxNodes[i]->getLocalScaling().x));
1141 for (
const ofbx::AnimationCurveNode* curveNode : skeletonAnimCurves) {
1143 const size_t jointIndex = findJointIndex(curveNode->getBone(), boneFbxNodes);
1148 const auto&
property = curveNode->getBoneLinkProperty();
1150 if (property ==
"Lcl Translation") {
1152 }
else if (property ==
"Lcl Rotation") {
1154 }
else if (property ==
"Lcl Scaling") {
1161 const size_t endIndex = startIndex + ((mode == 2) ? 1 : 3);
1162 for (
size_t i = startIndex; i < endIndex; ++i) {
1163 if (writtenJoints.at(i)) {
1165 char propertyName[128];
1166 property.toString(propertyName);
1168 "Multiple curves affecting the same parameter {} in {}",
1170 curveNode->getBone()->name);
1173 writtenJoints.at(i) =
true;
1177 for (
size_t iFrame = 0; iFrame < numFrames; ++iFrame) {
1178 const ofbx::DVec3 values =
1179 curveNode->getNodeLocalTransform(
static_cast<double>(iFrame) / fps);
1184 if (jointIndex < skeleton.joints.size()) {
1185 motion.col(iFrame).template segment<3>(startIndex).noalias() =
1186 toEigen(values).cast<
float>() - skeleton.joints[jointIndex].translationOffset;
1188 }
else if (mode == 1) {
1190 motion.col(iFrame).template segment<3>(startIndex).noalias() =
1191 toRad() * toEigen(values).cast<
float>();
1192 }
else if (mode == 2) {
1195 const float kMaxScaleDiff = 1e-4;
1196 if (std::abs(values.x - values.y) > kMaxScaleDiff ||
1197 std::abs(values.x - values.z) > kMaxScaleDiff) {
1199 "Animation has non-uniform scale, which is not supported: ({}, {}, {})",
1203 scale = (values.x + values.y + values.z) / 3.0;
1209 motion.col(iFrame)[startIndex] = std::log2(scale);
1216std::vector<ofbx::u8> readFileToBuffer(
const filesystem::path& path) {
1219 std::ifstream ifs(path.string(), std::ios::binary | std::ios::ate);
1220 MT_THROW_IF(!ifs.good(),
"Error reading FBX file from {}", path.string());
1222 auto length = ifs.tellg();
1223 ifs.seekg(0, std::ifstream::beg);
1225 MT_THROW_IF(length > INT32_MAX,
"File too large for OpenFBX.");
1227 std::vector<ofbx::u8> buffer(length);
1228 ifs.read(
reinterpret_cast<char*
>(buffer.data()), length);
1229 MT_THROW_IF(!ifs.good(),
"Error reading the entire FBX file from {}", path.string());
1236parseMarkerSequence(
const ofbx::IScene* scene,
const ofbx::Object* root,
const float fps) {
1240 if (!scene || scene->getAnimationStackCount() == 0) {
1245 const ofbx::Object* markersRoot =
nullptr;
1246 std::function<
const ofbx::Object*(
const ofbx::Object*)> findMarkersRoot =
1247 [&](
const ofbx::Object* node) ->
const ofbx::Object* {
1252 if (std::string(node->name) ==
"Markers") {
1255 if (markerRootProp) {
1261 while (
const ofbx::Object* child = node->resolveObjectLink(childIndex++)) {
1262 if (
const auto* found = findMarkersRoot(child)) {
1269 markersRoot = findMarkersRoot(root);
1277 std::vector<const ofbx::Object*> markerNodes;
1278 std::vector<std::string> markerNames;
1280 while (
const ofbx::Object* child = markersRoot->resolveObjectLink(childIndex++)) {
1284 markerNodes.push_back(child);
1285 markerNames.emplace_back(child->name);
1289 if (markerNodes.empty()) {
1295 const ofbx::AnimationStack* animStack = scene->getAnimationStack(0);
1302 std::vector<const ofbx::AnimationCurveNode*> markerAnimCurves;
1304 while (
const ofbx::AnimationLayer* animLayer = animStack->getLayer(iLayer++)) {
1306 while (
const ofbx::AnimationCurveNode* curve = animLayer->getCurveNode(iCurve++)) {
1308 const ofbx::Object* bone = curve->getBone();
1310 for (
const ofbx::Object* markerNode : markerNodes) {
1311 if (bone == markerNode) {
1312 markerAnimCurves.push_back(curve);
1320 if (markerAnimCurves.empty()) {
1326 const double totalSeconds = getMaxSeconds(markerAnimCurves);
1327 const size_t numFrames = std::ceil(totalSeconds * fps) + 1;
1328 result.frames.resize(numFrames);
1331 for (
size_t markerIndex = 0; markerIndex < markerNodes.size(); ++markerIndex) {
1332 const ofbx::Object* markerNode = markerNodes.at(markerIndex);
1333 const std::string& markerName = markerNames.at(markerIndex);
1336 const ofbx::AnimationCurveNode* translationCurve =
nullptr;
1337 for (
const ofbx::AnimationCurveNode* curveNode : markerAnimCurves) {
1338 if (curveNode->getBone() == markerNode) {
1339 const auto&
property = curveNode->getBoneLinkProperty();
1340 if (property ==
"Lcl Translation") {
1341 translationCurve = curveNode;
1347 if (translationCurve) {
1349 const ofbx::AnimationCurve* curveX = translationCurve->getCurve(0);
1350 const ofbx::AnimationCurve* curveY = translationCurve->getCurve(1);
1351 const ofbx::AnimationCurve* curveZ = translationCurve->getCurve(2);
1354 std::set<ofbx::i64> keyframeTimes;
1356 const int keyCount = curveX->getKeyCount();
1357 const ofbx::i64* times = curveX->getKeyTime();
1358 for (
int i = 0; i < keyCount; ++i) {
1359 keyframeTimes.insert(times[i]);
1363 const int keyCount = curveY->getKeyCount();
1364 const ofbx::i64* times = curveY->getKeyTime();
1365 for (
int i = 0; i < keyCount; ++i) {
1366 keyframeTimes.insert(times[i]);
1370 const int keyCount = curveZ->getKeyCount();
1371 const ofbx::i64* times = curveZ->getKeyTime();
1372 for (
int i = 0; i < keyCount; ++i) {
1373 keyframeTimes.insert(times[i]);
1378 for (
const ofbx::i64 fbxTime : keyframeTimes) {
1379 const double timeInSeconds = ofbx::fbxTimeToSeconds(fbxTime);
1380 const size_t frameIndex = std::round(timeInSeconds * fps);
1383 if (frameIndex >= numFrames) {
1388 const ofbx::DVec3 position = translationCurve->getNodeLocalTransform(timeInSeconds);
1391 marker.
name = markerName;
1392 marker.pos = toEigen(position);
1393 marker.occluded =
false;
1395 result.frames[frameIndex].push_back(marker);
1403std::tuple<Character, std::vector<MatrixXf>,
float> loadOpenFbx(
1404 const std::span<const std::byte> inputData,
1409 bool stripNamespaces) {
1411 const size_t length = fbxCharDataRaw.size();
1412 MT_THROW_IF(length > INT32_MAX,
"File too large for OpenFBX.");
1414 auto ofbx_deleter = [](ofbx::IScene* s) { s->destroy(); };
1417 auto loadFlags = ofbx::LoadFlags::IGNORE_CAMERAS | ofbx::LoadFlags::IGNORE_LIGHTS |
1418 ofbx::LoadFlags::IGNORE_VIDEOS | ofbx::LoadFlags::IGNORE_MATERIALS;
1420 loadFlags |= ofbx::LoadFlags::IGNORE_BLEND_SHAPES;
1423 loadFlags |= ofbx::LoadFlags::IGNORE_ANIMATIONS;
1425 std::unique_ptr<ofbx::IScene,
decltype(ofbx_deleter)> scene(
1426 ofbx::load(fbxCharDataRaw.data(),
static_cast<int32_t
>(length), (ofbx::u16)loadFlags),
1428 MT_THROW_IF(!scene,
"Error reading FBX scene data. Error: {}", ofbx::getError());
1429 MT_THROW_IF(!scene->getRoot(),
"FBX scene has no root node. Error: {}", ofbx::getError());
1431 if (stripNamespaces) {
1433 for (
int i = 0; i < scene->getAllObjectCount(); ++i) {
1434 const ofbx::Object* obj = scene->getAllObjects()[i];
1435 if (obj && obj->name[0] !=
'\0') {
1436 stripNamespace(obj);
1441 const auto [skeleton, jointFbxNodes, locators, collision] =
1442 parseSkeleton(scene->getRoot(), {}, permissive);
1445 std::string metadata =
"{}";
1446 if (!jointFbxNodes.empty()) {
1447 auto* resName = resolveProperty(*jointFbxNodes[0],
"name");
1448 if (resName !=
nullptr) {
1449 name = resolveStringProperty(*jointFbxNodes[0],
"name");
1451 auto* resMeta = resolveProperty(*jointFbxNodes[0],
"metadata");
1452 if (resMeta !=
nullptr) {
1453 metadata = resolveStringProperty(*jointFbxNodes[0],
"metadata");
1458 auto json = nlohmann::json::parse(metadata);
1459 }
catch (
const nlohmann::json::parse_error& e) {
1460 MT_LOGW(
"Failed to parse metadata: {}", e.what());
1464 for (
const auto& j : jointFbxNodes) {
1465 Eigen::Affine3d mat = Eigen::Affine3d::Identity();
1467 mat = toEigen(j->getGlobalTransform());
1469 inverseBindPoseTransforms.push_back(mat.inverse().cast<
float>());
1473 std::unique_ptr<SkinWeights> skinWeights;
1476 for (
int iMesh = 0; iMesh < scene->getMeshCount(); ++iMesh) {
1478 scene->getMesh(iMesh),
1482 inverseBindPoseTransforms,
1487 mesh.updateNormals();
1489 std::vector<MatrixXf> jointParamMotions;
1491 for (
int iAnim = 0; iAnim < scene->getAnimationStackCount(); ++iAnim) {
1492 const ofbx::AnimationStack* stack = scene->getAnimationStack(iAnim);
1493 if (stack !=
nullptr) {
1494 jointParamMotions.emplace_back(
1495 parseAnimation(stack, jointFbxNodes, skeleton, scene->getSceneFrameRate(), permissive));
1507 collision.empty() ?
nullptr : &collision,
1515 result.resetJointMap();
1516 result.inverseBindPose = inverseBindPoseTransforms;
1517 result.physicalProperties = loadPhysicalPropertiesFromNodes(result.skeleton, jointFbxNodes);
1519 return {result, jointParamMotions, scene->getSceneFrameRate()};
1525 const std::span<const std::byte> inputData,
1529 bool stripNamespaces) {
1530 auto [character, motion, fps] =
1531 loadOpenFbx(inputData, keepLocators,
false, permissive, loadBlendShapes, stripNamespaces);
1536 const filesystem::path& path,
1540 bool stripNamespaces) {
1541 auto buffer = readFileToBuffer(path);
1543 gsl::as_bytes(gsl::make_span(buffer)),
1551 std::span<const std::byte> inputData,
1555 bool stripNamespaces) {
1556 return loadOpenFbx(inputData, keepLocators,
true, permissive, loadBlendShapes, stripNamespaces);
1560 const filesystem::path& inputPath,
1564 bool stripNamespaces) {
1565 auto buffer = readFileToBuffer(inputPath);
1567 gsl::as_bytes(gsl::make_span(buffer)),
1575 std::span<const std::byte> inputData,
1576 bool stripNamespaces) {
1578 const size_t length = fbxCharDataRaw.size();
1579 MT_THROW_IF(length > INT32_MAX,
"File too large for OpenFBX.");
1581 auto ofbx_deleter = [](ofbx::IScene* s) { s->destroy(); };
1584 auto loadFlags = ofbx::LoadFlags::IGNORE_CAMERAS | ofbx::LoadFlags::IGNORE_LIGHTS |
1585 ofbx::LoadFlags::IGNORE_VIDEOS | ofbx::LoadFlags::IGNORE_MATERIALS |
1586 ofbx::LoadFlags::IGNORE_BLEND_SHAPES;
1588 std::unique_ptr<ofbx::IScene,
decltype(ofbx_deleter)> scene(
1589 ofbx::load(fbxCharDataRaw.data(),
static_cast<int32_t
>(length), (ofbx::u16)loadFlags),
1591 MT_THROW_IF(!scene,
"Error reading FBX scene data. Error: {}", ofbx::getError());
1592 MT_THROW_IF(!scene->getRoot(),
"FBX scene has no root node. Error: {}", ofbx::getError());
1594 if (stripNamespaces) {
1596 for (
int i = 0; i < scene->getAllObjectCount(); ++i) {
1597 const ofbx::Object* obj = scene->getAllObjects()[i];
1598 if (obj && obj->name[0] !=
'\0') {
1599 stripNamespace(obj);
1604 return parseMarkerSequence(scene.get(), scene->getRoot(), scene->getSceneFrameRate());
1608 auto buffer = readFileToBuffer(filename);
#define MT_CHECK(condition,...)
Runtime check macros with two interchangeable backends:
#define MT_THROW(...)
Throws a std::runtime_error with a formatted message.
#define MT_THROW_IF(Condition,...)
Conditionally throws a std::runtime_error with a formatted message if the condition is true.
#define MT_LOGE_IF(condition,...)
#define MT_LOGW_IF(condition,...)
std::span< T > cast_span(std::span< std::byte > bs)
Casts a span of bytes to a span of a different type.
CollisionGeometryT< float > CollisionGeometry
SkeletonT< float > Skeleton
CollisionEllipsoidT< float > CollisionEllipsoid
constexpr const char * kMomentumMarkersRootProperty
std::vector< Affine3f > TransformationList
One affine transform per joint, indexed by joint id.
std::vector< ParameterLimit > ParameterLimits
std::tuple< Character, std::vector< MatrixXf >, float > loadOpenFbxCharacterWithMotion(std::span< const std::byte > inputData, KeepLocators keepLocators, Permissive permissive, LoadBlendShapes loadBlendShapes, bool stripNamespaces)
::std::shared_ptr< BlendShape > BlendShape_p
MarkerSequence loadOpenFbxMarkerSequence(std::span< const std::byte > inputData, bool stripNamespaces)
Load a MarkerSequence from an in-memory FBX byte buffer.
Character loadOpenFbxCharacter(const std::span< const std::byte > inputData, KeepLocators keepLocators, Permissive permissive, LoadBlendShapes loadBlendShapes, bool stripNamespaces)
constexpr T toRad(T x=T(1)) noexcept
Converts the given angle x (in degrees) to radians.
std::optional< JointPhysicalProperties > jointPhysicalPropertiesFromJsonString(const std::string &json, const std::string &jointName, const size_t jointIndex)
Parses one joint's physical mass properties from its canonical on-disk JSON string.
std::vector< JointPhysicalProperties > PhysicalProperties
Optional physical mass properties for a character.
CollisionBoxT< float > CollisionBox
std::vector< Eigen::Vector3i > triangulate(std::span< const uint32_t > indices, std::span< const uint32_t > offsets)
constexpr size_t kParametersPerJoint
constexpr size_t kInvalidIndex
Sentinel value indicating an invalid or unset size_t index.
constexpr const char * kMomentumMarkerProperty
TaperedCapsuleT< float > TaperedCapsule
constexpr uint32_t kMaxSkinJoints
Maximum number of joints that can influence a single vertex.
MatrixX< float > MatrixXf
std::vector< Locator > LocatorList
A collection of locators attached to a skeleton.
A character model with skeletal structure, mesh, and optional components.
Represents a point attached to a joint in a skeleton.
All frames from a single motion capture sequence for one subject (actor).
float fps
Frame rate of the capture, in frames per second.
A single motion capture marker observation (position, occlusion, confidence).
std::string name
The name of the marker.
std::vector< uint32_t > indices