SkinRuleBehavior.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzCore/Memory/SystemAllocator.h>
  9. #include <AzCore/std/smart_ptr/make_shared.h>
  10. #include <SceneAPI/SceneCore/Containers/Scene.h>
  11. #include <SceneAPI/SceneCore/Containers/Utilities/SceneGraphUtilities.h>
  12. #include <SceneAPI/SceneCore/DataTypes/Groups/IMeshGroup.h>
  13. #include <SceneAPI/SceneCore/DataTypes/GraphData/ISkinWeightData.h>
  14. #include <SceneAPI/SceneData/Rules/SkinRule.h>
  15. #include <SceneAPI/SceneData/Behaviors/SkinRuleBehavior.h>
  16. namespace AZ
  17. {
  18. namespace SceneAPI
  19. {
  20. namespace SceneData
  21. {
  22. void SkinRuleBehavior::Reflect(AZ::ReflectContext* context)
  23. {
  24. SkinRule::Reflect(context);
  25. AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
  26. if (serializeContext)
  27. {
  28. serializeContext->Class<SkinRuleBehavior, SceneCore::BehaviorComponent>()->Version(1);
  29. }
  30. }
  31. void SkinRuleBehavior::Activate()
  32. {
  33. AZ::SceneAPI::Events::ManifestMetaInfoBus::Handler::BusConnect();
  34. }
  35. void SkinRuleBehavior::Deactivate()
  36. {
  37. AZ::SceneAPI::Events::ManifestMetaInfoBus::Handler::BusDisconnect();
  38. }
  39. void SkinRuleBehavior::InitializeObject([[maybe_unused]] const Containers::Scene& scene, DataTypes::IManifestObject& target)
  40. {
  41. if (azrtti_istypeof<DataTypes::IMeshGroup>(target))
  42. {
  43. DataTypes::IMeshGroup* meshGroup = azrtti_cast<DataTypes::IMeshGroup*>(&target);
  44. AZ::SceneAPI::Containers::RuleContainer& rules = meshGroup->GetRuleContainer();
  45. // Only add the skin rule if the scene contain any skinning data.
  46. if (!rules.ContainsRuleOfType<SkinRule>() && Utilities::DoesSceneGraphContainDataLike<DataTypes::ISkinWeightData>(scene, true))
  47. {
  48. rules.AddRule(AZStd::make_shared<SkinRule>());
  49. }
  50. }
  51. }
  52. }
  53. }
  54. }