Skip to content

Commit

Permalink
VIRO-4898: Store Bone Bind Transforms in VROSkeleton
Browse files Browse the repository at this point in the history
- Modified and regenerated the Bone protobuf to include bind transforms.
- Modified the VRX script to propogate the bind transforms from FBX models.
  • Loading branch information
dthian committed Feb 1, 2019
1 parent 4ce1538 commit c276863
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 7 deletions.
82 changes: 82 additions & 0 deletions ViroFBX/Nodes.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions ViroFBX/Nodes.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 15 additions & 5 deletions ViroFBX/VROFBXExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void VROFBXExporter::exportFBX(std::string fbxPath, std::string destPath, bool c
for (int i = 0; i < rootNode->GetChildCount(); i++) {
if (isExportableNode(rootNode->GetChild(i))) {
exportNode(scene, rootNode->GetChild(i), 0, compressTextures,
boneNodes, outNode->add_subnode());
boneNodes, skeleton, outNode->add_subnode());
}
}
}
Expand Down Expand Up @@ -214,7 +214,8 @@ bool VROFBXExporter::isExportableNode(FbxNode *node) {
}

void VROFBXExporter::exportNode(FbxScene *scene, FbxNode *node, int depth, bool compressTextures,
const std::vector<FbxNode *> &boneNodes, viro::Node *outNode) {
const std::vector<FbxNode *> &boneNodes,
viro::Node::Skeleton *outSkeleton, viro::Node *outNode) {
passert (isExportableNode(node));

pinfo("Exporting node [%s], type [%s]", node->GetName(),
Expand Down Expand Up @@ -268,7 +269,7 @@ void VROFBXExporter::exportNode(FbxScene *scene, FbxNode *node, int depth, bool
*/
if (boneNodes.size() > 0 && node->GetMesh()->GetDeformerCount() > 0) {
pinfo(" Exporting skin");
exportSkin(node, boneNodes, outNode->mutable_geometry()->mutable_skin());
exportSkin(node, boneNodes, outSkeleton, outNode->mutable_geometry()->mutable_skin());

pinfo(" Exporting skeletal animations");
exportSkeletalAnimations(scene, node, boneNodes, outNode);
Expand All @@ -288,7 +289,7 @@ void VROFBXExporter::exportNode(FbxScene *scene, FbxNode *node, int depth, bool
for (int i = 0; i < node->GetChildCount(); i++) {
if (isExportableNode(node->GetChild(i))) {
exportNode(scene, node->GetChild(i), depth, compressTextures,
boneNodes, outNode->add_subnode());
boneNodes, outSkeleton, outNode->add_subnode());
}
}
}
Expand Down Expand Up @@ -663,7 +664,9 @@ bool SortByBoneWeight(const VROBoneIndexWeight &i, const VROBoneIndexWeight &j)
return (i.weight > j.weight);
}

void VROFBXExporter::exportSkin(FbxNode *node, const std::vector<FbxNode *> &boneNodes,
void VROFBXExporter::exportSkin(FbxNode *node,
const std::vector<FbxNode *> &boneNodes,
viro::Node::Skeleton *outSkeleton,
viro::Node::Geometry::Skin *outSkin) {
FbxMesh *mesh = node->GetMesh();

Expand Down Expand Up @@ -748,6 +751,13 @@ void VROFBXExporter::exportSkin(FbxNode *node, const std::vector<FbxNode *> &bon
cluster->GetTransformLinkMatrix(inverseBoneSpaceTransform);
FbxAMatrix boneSpaceTransform = inverseBoneSpaceTransform.Inverse();

// Save a copy of the bonespace binding transforms in the skeleton and skinner. Note that a given skinner
// may not have the the complete set of bonespace binding transforms pertaining to the model's skeleton.
viro::Node::Matrix *viroBoneSpaceTransform = outSkeleton->mutable_bone(boneIndex)->mutable_bind_transform();
for (int i = 0; i < 16; i++) {
viroBoneSpaceTransform->add_value(boneSpaceTransform.Get(i / 4, i % 4));
}

viro::Node::Matrix *bt = outSkin->mutable_bind_transform(boneIndex);
for (int i = 0; i < 16; i++) {
bt->add_value(boneSpaceTransform.Get(i / 4, i % 4));
Expand Down
4 changes: 2 additions & 2 deletions ViroFBX/VROFBXExporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ class VROFBXExporter {
#pragma mark - Export Methods

void exportNode(FbxScene *scene, FbxNode *node, int depth, bool compressTextures,
const std::vector<FbxNode *> &boneNodes, viro::Node *outNode);
const std::vector<FbxNode *> &boneNodes, viro::Node::Skeleton *outSkeleton, viro::Node *outNode);
void exportGeometry(FbxNode *node, int depth, bool compressTextures, viro::Node::Geometry *geo);
void exportMaterial(FbxSurfaceMaterial *inMaterial, bool compressTextures, viro::Node::Geometry::Material *outMaterial);
void exportHardwareMaterial(FbxSurfaceMaterial *inMaterial, const FbxImplementation *implementation,
viro::Node::Geometry::Material *outMaterial);
void exportSkeleton(FbxNode *rootNode, std::vector<FbxNode *> *outBoneNodes, viro::Node::Skeleton *outSkeleton);
void exportSkeletonRecursive(FbxNode *node, int depth, int index, int parentIndex, std::vector<FbxNode *> *outBoneNodes, viro::Node::Skeleton *outSkeleton);
void exportSkin(FbxNode *node, const std::vector<FbxNode *> &boneNodes, viro::Node::Geometry::Skin *outSkin);
void exportSkin(FbxNode *node, const std::vector<FbxNode *> &boneNodes, viro::Node::Skeleton *outSkeleton, viro::Node::Geometry::Skin *outSkin);

void exportKeyframeAnimations(FbxScene *scene, FbxNode *node, viro::Node *outNode);
void exportSampledKeyframeAnimations(FbxScene *scene, FbxNode *node, viro::Node *outNode);
Expand Down
1 change: 1 addition & 0 deletions protobuf/Nodes.proto
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ message Node {
string name = 1;
int32 parent_index = 2;
Matrix local_transform = 3;
Matrix bind_transform = 4;
}
repeated Bone bone = 1;
}
Expand Down

0 comments on commit c276863

Please sign in to comment.