diff --git a/ViroFBX/Nodes.pb.cc b/ViroFBX/Nodes.pb.cc index 8f82a0a..b734eb3 100644 --- a/ViroFBX/Nodes.pb.cc +++ b/ViroFBX/Nodes.pb.cc @@ -118,6 +118,8 @@ void TableStruct::InitDefaultsImpl() { ::viro::Node_Geometry_Skin::internal_default_instance()); _Node_Skeleton_Bone_default_instance_.get_mutable()->local_transform_ = const_cast< ::viro::Node_Matrix*>( ::viro::Node_Matrix::internal_default_instance()); + _Node_Skeleton_Bone_default_instance_.get_mutable()->bind_transform_ = const_cast< ::viro::Node_Matrix*>( + ::viro::Node_Matrix::internal_default_instance()); _Node_default_instance_.get_mutable()->geometry_ = const_cast< ::viro::Node_Geometry*>( ::viro::Node_Geometry::internal_default_instance()); _Node_default_instance_.get_mutable()->skeleton_ = const_cast< ::viro::Node_Skeleton*>( @@ -4536,6 +4538,7 @@ void Node_Geometry::set_allocated_skin(::viro::Node_Geometry_Skin* skin) { const int Node_Skeleton_Bone::kNameFieldNumber; const int Node_Skeleton_Bone::kParentIndexFieldNumber; const int Node_Skeleton_Bone::kLocalTransformFieldNumber; +const int Node_Skeleton_Bone::kBindTransformFieldNumber; #endif // !defined(_MSC_VER) || _MSC_VER >= 1900 Node_Skeleton_Bone::Node_Skeleton_Bone() @@ -4560,6 +4563,11 @@ Node_Skeleton_Bone::Node_Skeleton_Bone(const Node_Skeleton_Bone& from) } else { local_transform_ = NULL; } + if (from.has_bind_transform()) { + bind_transform_ = new ::viro::Node_Matrix(*from.bind_transform_); + } else { + bind_transform_ = NULL; + } parent_index_ = from.parent_index_; // @@protoc_insertion_point(copy_constructor:viro.Node.Skeleton.Bone) } @@ -4581,6 +4589,9 @@ void Node_Skeleton_Bone::SharedDtor() { if (this != internal_default_instance()) { delete local_transform_; } + if (this != internal_default_instance()) { + delete bind_transform_; + } } void Node_Skeleton_Bone::SetCachedSize(int size) const { @@ -4608,6 +4619,10 @@ void Node_Skeleton_Bone::Clear() { delete local_transform_; } local_transform_ = NULL; + if (GetArenaNoVirtual() == NULL && bind_transform_ != NULL) { + delete bind_transform_; + } + bind_transform_ = NULL; parent_index_ = 0; } @@ -4660,6 +4675,17 @@ bool Node_Skeleton_Bone::MergePartialFromCodedStream( break; } + // .viro.Node.Matrix bind_transform = 4; + case 4: { + if (tag == 34u) { + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + input, mutable_bind_transform())); + } else { + goto handle_unusual; + } + break; + } + default: { handle_unusual: if (tag == 0 || @@ -4705,6 +4731,12 @@ void Node_Skeleton_Bone::SerializeWithCachedSizes( 3, *this->local_transform_, output); } + // .viro.Node.Matrix bind_transform = 4; + if (this->has_bind_transform()) { + ::google::protobuf::internal::WireFormatLite::WriteMessage( + 4, *this->bind_transform_, output); + } + // @@protoc_insertion_point(serialize_end:viro.Node.Skeleton.Bone) } @@ -4726,6 +4758,13 @@ size_t Node_Skeleton_Bone::ByteSizeLong() const { *this->local_transform_); } + // .viro.Node.Matrix bind_transform = 4; + if (this->has_bind_transform()) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + *this->bind_transform_); + } + // int32 parent_index = 2; if (this->parent_index() != 0) { total_size += 1 + @@ -4756,6 +4795,9 @@ void Node_Skeleton_Bone::MergeFrom(const Node_Skeleton_Bone& from) { if (from.has_local_transform()) { mutable_local_transform()->::viro::Node_Matrix::MergeFrom(from.local_transform()); } + if (from.has_bind_transform()) { + mutable_bind_transform()->::viro::Node_Matrix::MergeFrom(from.bind_transform()); + } if (from.parent_index() != 0) { set_parent_index(from.parent_index()); } @@ -4779,6 +4821,7 @@ void Node_Skeleton_Bone::Swap(Node_Skeleton_Bone* other) { void Node_Skeleton_Bone::InternalSwap(Node_Skeleton_Bone* other) { name_.Swap(&other->name_); std::swap(local_transform_, other->local_transform_); + std::swap(bind_transform_, other->bind_transform_); std::swap(parent_index_, other->parent_index_); std::swap(_cached_size_, other->_cached_size_); } @@ -4895,6 +4938,45 @@ void Node_Skeleton_Bone::set_allocated_local_transform(::viro::Node_Matrix* loca // @@protoc_insertion_point(field_set_allocated:viro.Node.Skeleton.Bone.local_transform) } +// .viro.Node.Matrix bind_transform = 4; +bool Node_Skeleton_Bone::has_bind_transform() const { + return this != internal_default_instance() && bind_transform_ != NULL; +} +void Node_Skeleton_Bone::clear_bind_transform() { + if (GetArenaNoVirtual() == NULL && bind_transform_ != NULL) delete bind_transform_; + bind_transform_ = NULL; +} +const ::viro::Node_Matrix& Node_Skeleton_Bone::bind_transform() const { + // @@protoc_insertion_point(field_get:viro.Node.Skeleton.Bone.bind_transform) + return bind_transform_ != NULL ? *bind_transform_ + : *::viro::Node_Matrix::internal_default_instance(); +} +::viro::Node_Matrix* Node_Skeleton_Bone::mutable_bind_transform() { + + if (bind_transform_ == NULL) { + bind_transform_ = new ::viro::Node_Matrix; + } + // @@protoc_insertion_point(field_mutable:viro.Node.Skeleton.Bone.bind_transform) + return bind_transform_; +} +::viro::Node_Matrix* Node_Skeleton_Bone::release_bind_transform() { + // @@protoc_insertion_point(field_release:viro.Node.Skeleton.Bone.bind_transform) + + ::viro::Node_Matrix* temp = bind_transform_; + bind_transform_ = NULL; + return temp; +} +void Node_Skeleton_Bone::set_allocated_bind_transform(::viro::Node_Matrix* bind_transform) { + delete bind_transform_; + bind_transform_ = bind_transform; + if (bind_transform) { + + } else { + + } + // @@protoc_insertion_point(field_set_allocated:viro.Node.Skeleton.Bone.bind_transform) +} + #endif // PROTOBUF_INLINE_NOT_IN_HEADERS // =================================================================== diff --git a/ViroFBX/Nodes.pb.h b/ViroFBX/Nodes.pb.h index 694d59d..f8939b3 100644 --- a/ViroFBX/Nodes.pb.h +++ b/ViroFBX/Nodes.pb.h @@ -1412,6 +1412,15 @@ class Node_Skeleton_Bone : public ::google::protobuf::MessageLite /* @@protoc_in ::viro::Node_Matrix* release_local_transform(); void set_allocated_local_transform(::viro::Node_Matrix* local_transform); + // .viro.Node.Matrix bind_transform = 4; + bool has_bind_transform() const; + void clear_bind_transform(); + static const int kBindTransformFieldNumber = 4; + const ::viro::Node_Matrix& bind_transform() const; + ::viro::Node_Matrix* mutable_bind_transform(); + ::viro::Node_Matrix* release_bind_transform(); + void set_allocated_bind_transform(::viro::Node_Matrix* bind_transform); + // int32 parent_index = 2; void clear_parent_index(); static const int kParentIndexFieldNumber = 2; @@ -1424,6 +1433,7 @@ class Node_Skeleton_Bone : public ::google::protobuf::MessageLite /* @@protoc_in ::google::protobuf::internal::InternalMetadataWithArenaLite _internal_metadata_; ::google::protobuf::internal::ArenaStringPtr name_; ::viro::Node_Matrix* local_transform_; + ::viro::Node_Matrix* bind_transform_; ::google::protobuf::int32 parent_index_; mutable int _cached_size_; friend struct protobuf_Nodes_2eproto::TableStruct; @@ -3999,6 +4009,45 @@ inline void Node_Skeleton_Bone::set_allocated_local_transform(::viro::Node_Matri // @@protoc_insertion_point(field_set_allocated:viro.Node.Skeleton.Bone.local_transform) } +// .viro.Node.Matrix bind_transform = 4; +inline bool Node_Skeleton_Bone::has_bind_transform() const { + return this != internal_default_instance() && bind_transform_ != NULL; +} +inline void Node_Skeleton_Bone::clear_bind_transform() { + if (GetArenaNoVirtual() == NULL && bind_transform_ != NULL) delete bind_transform_; + bind_transform_ = NULL; +} +inline const ::viro::Node_Matrix& Node_Skeleton_Bone::bind_transform() const { + // @@protoc_insertion_point(field_get:viro.Node.Skeleton.Bone.bind_transform) + return bind_transform_ != NULL ? *bind_transform_ + : *::viro::Node_Matrix::internal_default_instance(); +} +inline ::viro::Node_Matrix* Node_Skeleton_Bone::mutable_bind_transform() { + + if (bind_transform_ == NULL) { + bind_transform_ = new ::viro::Node_Matrix; + } + // @@protoc_insertion_point(field_mutable:viro.Node.Skeleton.Bone.bind_transform) + return bind_transform_; +} +inline ::viro::Node_Matrix* Node_Skeleton_Bone::release_bind_transform() { + // @@protoc_insertion_point(field_release:viro.Node.Skeleton.Bone.bind_transform) + + ::viro::Node_Matrix* temp = bind_transform_; + bind_transform_ = NULL; + return temp; +} +inline void Node_Skeleton_Bone::set_allocated_bind_transform(::viro::Node_Matrix* bind_transform) { + delete bind_transform_; + bind_transform_ = bind_transform; + if (bind_transform) { + + } else { + + } + // @@protoc_insertion_point(field_set_allocated:viro.Node.Skeleton.Bone.bind_transform) +} + // ------------------------------------------------------------------- // Node_Skeleton diff --git a/ViroFBX/VROFBXExporter.cpp b/ViroFBX/VROFBXExporter.cpp index 812a31e..10acc0b 100644 --- a/ViroFBX/VROFBXExporter.cpp +++ b/ViroFBX/VROFBXExporter.cpp @@ -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()); } } } @@ -214,7 +214,8 @@ bool VROFBXExporter::isExportableNode(FbxNode *node) { } void VROFBXExporter::exportNode(FbxScene *scene, FbxNode *node, int depth, bool compressTextures, - const std::vector &boneNodes, viro::Node *outNode) { + const std::vector &boneNodes, + viro::Node::Skeleton *outSkeleton, viro::Node *outNode) { passert (isExportableNode(node)); pinfo("Exporting node [%s], type [%s]", node->GetName(), @@ -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); @@ -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()); } } } @@ -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 &boneNodes, +void VROFBXExporter::exportSkin(FbxNode *node, + const std::vector &boneNodes, + viro::Node::Skeleton *outSkeleton, viro::Node::Geometry::Skin *outSkin) { FbxMesh *mesh = node->GetMesh(); @@ -748,6 +751,13 @@ void VROFBXExporter::exportSkin(FbxNode *node, const std::vector &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)); diff --git a/ViroFBX/VROFBXExporter.h b/ViroFBX/VROFBXExporter.h index 8cfb104..189012e 100644 --- a/ViroFBX/VROFBXExporter.h +++ b/ViroFBX/VROFBXExporter.h @@ -69,14 +69,14 @@ class VROFBXExporter { #pragma mark - Export Methods void exportNode(FbxScene *scene, FbxNode *node, int depth, bool compressTextures, - const std::vector &boneNodes, viro::Node *outNode); + const std::vector &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 *outBoneNodes, viro::Node::Skeleton *outSkeleton); void exportSkeletonRecursive(FbxNode *node, int depth, int index, int parentIndex, std::vector *outBoneNodes, viro::Node::Skeleton *outSkeleton); - void exportSkin(FbxNode *node, const std::vector &boneNodes, viro::Node::Geometry::Skin *outSkin); + void exportSkin(FbxNode *node, const std::vector &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); diff --git a/protobuf/Nodes.proto b/protobuf/Nodes.proto index 318b8dd..bada874 100644 --- a/protobuf/Nodes.proto +++ b/protobuf/Nodes.proto @@ -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; }