/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include #include #include #include #include #include namespace AZ { namespace FbxSDKWrapper { FbxNodeWrapper::FbxNodeWrapper(FbxNode* fbxNode) : m_fbxNode(fbxNode) { AZ_Assert(fbxNode, "Invalid FbxNode to initialize FbxNodeWrapper"); } FbxNodeWrapper::~FbxNodeWrapper() { m_fbxNode = nullptr; } FbxNode* FbxNodeWrapper::GetFbxNode() { return m_fbxNode; } int FbxNodeWrapper::GetMaterialCount() const { return m_fbxNode->GetMaterialCount(); } const char* FbxNodeWrapper::GetMaterialName(int index) const { if (index < GetMaterialCount()) { return m_fbxNode->GetMaterial(index)->GetName(); } AZ_Assert(index < GetMaterialCount(), "Invalid material index %d", index); return nullptr; } const std::shared_ptr FbxNodeWrapper::GetMesh() const { FbxMesh* mesh = m_fbxNode->GetMesh(); return mesh ? std::shared_ptr(new FbxMeshWrapper(mesh)) : nullptr; } const std::shared_ptr FbxNodeWrapper::FindProperty(const char* name) const { FbxProperty propertyName = m_fbxNode->FindProperty(name); return std::shared_ptr(new FbxPropertyWrapper(&propertyName)); } bool FbxNodeWrapper::IsBone() const { return (m_fbxNode->GetSkeleton() != nullptr); } bool FbxNodeWrapper::IsMesh() const { return (m_fbxNode->GetMesh() != nullptr); } const char* FbxNodeWrapper::GetName() const { return m_fbxNode->GetName(); } AZ::u64 FbxNodeWrapper::GetUniqueId() const { return m_fbxNode->GetUniqueID(); } Transform FbxNodeWrapper::EvaluateGlobalTransform() { return FbxTypeConverter::ToTransform(m_fbxNode->EvaluateGlobalTransform()); } Vector3 FbxNodeWrapper::EvaluateLocalTranslation() { return FbxTypeConverter::ToVector3(m_fbxNode->EvaluateLocalTranslation()); } Vector3 FbxNodeWrapper::EvaluateLocalTranslation(FbxTimeWrapper& time) { return FbxTypeConverter::ToVector3(m_fbxNode->EvaluateLocalTranslation(time.m_fbxTime)); } Transform FbxNodeWrapper::EvaluateLocalTransform() { return FbxTypeConverter::ToTransform(m_fbxNode->EvaluateLocalTransform()); } Transform FbxNodeWrapper::EvaluateLocalTransform(FbxTimeWrapper& time) { return FbxTypeConverter::ToTransform(m_fbxNode->EvaluateLocalTransform(time.m_fbxTime)); } Vector3 FbxNodeWrapper::EvaluateLocalRotation() { return FbxTypeConverter::ToVector3(m_fbxNode->EvaluateLocalTransform().GetR()); } Vector3 FbxNodeWrapper::EvaluateLocalRotation(FbxTimeWrapper& time) { return FbxTypeConverter::ToVector3(m_fbxNode->EvaluateLocalTransform(time.m_fbxTime).GetR()); } Vector3 FbxNodeWrapper::GetGeometricTranslation() const { return FbxTypeConverter::ToVector3(m_fbxNode->GetGeometricTranslation(FbxNode::eSourcePivot)); } Vector3 FbxNodeWrapper::GetGeometricScaling() const { return FbxTypeConverter::ToVector3(m_fbxNode->GetGeometricScaling(FbxNode::eSourcePivot)); } Vector3 FbxNodeWrapper::GetGeometricRotation() const { return FbxTypeConverter::ToVector3(m_fbxNode->GetGeometricRotation(FbxNode::eSourcePivot)); } Transform FbxNodeWrapper::GetGeometricTransform() const { FbxAMatrix geoTransform(m_fbxNode->GetGeometricTranslation(FbxNode::eSourcePivot), m_fbxNode->GetGeometricRotation(FbxNode::eSourcePivot), m_fbxNode->GetGeometricScaling(FbxNode::eSourcePivot)); return FbxTypeConverter::ToTransform(geoTransform); } const AZStd::shared_ptr FbxNodeWrapper::GetLocalTranslationCurve(const AZStd::shared_ptr& layer, CurveNodeComponent component) const { if (!layer) { return nullptr; } const char* componentString = nullptr; switch (component) { case Component_X: componentString = FBXSDK_CURVENODE_COMPONENT_X; break; case Component_Y: componentString = FBXSDK_CURVENODE_COMPONENT_Y; break; case Component_Z: componentString = FBXSDK_CURVENODE_COMPONENT_Z; break; default: break; } // If there is available animation curve data of specified component/channel for translation, create and return a wrapped version of it. return m_fbxNode->LclTranslation.GetCurve(layer->m_fbxAnimLayer, componentString) ? AZStd::make_shared(m_fbxNode->LclTranslation.GetCurve(layer->m_fbxAnimLayer, componentString)) : nullptr; } const AZStd::shared_ptr FbxNodeWrapper::GetLocalRotationCurve(const AZStd::shared_ptr& layer, CurveNodeComponent component) const { if (!layer) { return nullptr; } const char* componentString = nullptr; switch (component) { case Component_X: componentString = FBXSDK_CURVENODE_COMPONENT_X; break; case Component_Y: componentString = FBXSDK_CURVENODE_COMPONENT_Y; break; case Component_Z: componentString = FBXSDK_CURVENODE_COMPONENT_Z; break; default: break; } // If there is available animation curve data of specified component/channel for rotation, create and return a wrapped version of it. return m_fbxNode->LclRotation.GetCurve(layer->m_fbxAnimLayer, componentString) ? AZStd::make_shared(m_fbxNode->LclRotation.GetCurve(layer->m_fbxAnimLayer, componentString)) : nullptr; } bool FbxNodeWrapper::IsAnimated() const { return FbxAnimUtilities::IsAnimated(m_fbxNode); } int FbxNodeWrapper::GetChildCount() const { return m_fbxNode->GetChildCount(); } const std::shared_ptr FbxNodeWrapper::GetChild(int childIndex) const { FbxNode* child = m_fbxNode->GetChild(childIndex); AZ_Assert(child, "Cannot get child FbxNode at index %d", childIndex); return child ? std::shared_ptr(new FbxNodeWrapper(child)) : nullptr; } const std::shared_ptr FbxNodeWrapper::GetMaterial(int index) const { if (index < GetMaterialCount()) { return std::shared_ptr(new FbxMaterialWrapper(m_fbxNode->GetMaterial(index))); } AZ_Assert(index < GetMaterialCount(), "Invalid material index %d", index); return nullptr; } } // namespace FbxSDKWrapper } // namespace AZ