SmoothStep.cpp 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 <GradientSignal/SmoothStep.h>
  9. #include <AzCore/Debug/Profiler.h>
  10. #include <AzCore/RTTI/BehaviorContext.h>
  11. #include <AzCore/Serialization/EditContext.h>
  12. #include <AzCore/Serialization/SerializeContext.h>
  13. #include <GradientSignal/Util.h>
  14. #include <GradientSignal/Ebuses/SmoothStepRequestBus.h>
  15. namespace GradientSignal
  16. {
  17. void SmoothStep::Reflect(AZ::ReflectContext* context)
  18. {
  19. AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context);
  20. if (serialize)
  21. {
  22. serialize->Class<SmoothStep>()
  23. ->Version(0)
  24. ->Field("FalloffMidpoint", &SmoothStep::m_falloffMidpoint)
  25. ->Field("FalloffRange", &SmoothStep::m_falloffRange)
  26. ->Field("FalloffStrength", &SmoothStep::m_falloffStrength)
  27. ;
  28. AZ::EditContext* edit = serialize->GetEditContext();
  29. if (edit)
  30. {
  31. edit->Class<SmoothStep>("Smooth Step Gradient", "Smooth Step Gradient")
  32. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  33. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  34. ->DataElement(AZ::Edit::UIHandlers::Slider, &SmoothStep::m_falloffMidpoint, "Falloff Midpoint", "")
  35. ->Attribute(AZ::Edit::Attributes::Min, 0.0f)
  36. ->Attribute(AZ::Edit::Attributes::Max, 1.0f)
  37. ->DataElement(AZ::Edit::UIHandlers::Slider, &SmoothStep::m_falloffRange, "Falloff Range", "")
  38. ->Attribute(AZ::Edit::Attributes::Min, 0.0f)
  39. ->Attribute(AZ::Edit::Attributes::Max, 1.0f)
  40. ->DataElement(AZ::Edit::UIHandlers::Slider, &SmoothStep::m_falloffStrength, "Falloff Softness", "")
  41. ->Attribute(AZ::Edit::Attributes::Min, 0.0f)
  42. ->Attribute(AZ::Edit::Attributes::Max, 1.0f)
  43. ;
  44. }
  45. }
  46. if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  47. {
  48. behaviorContext->Class<SmoothStep>()
  49. ->Constructor()
  50. ->Property("falloffMidpoint", BehaviorValueProperty(&SmoothStep::m_falloffMidpoint))
  51. ->Property("falloffRange", BehaviorValueProperty(&SmoothStep::m_falloffRange))
  52. ->Property("falloffStrength", BehaviorValueProperty(&SmoothStep::m_falloffStrength))
  53. ;
  54. behaviorContext->EBus<SmoothStepRequestBus>("SmoothStepRequestBus")
  55. ->Attribute(AZ::Script::Attributes::Category, "Vegetation")
  56. ->Event("GetFallOffMidpoint", &SmoothStepRequestBus::Events::GetFallOffMidpoint)
  57. ->Event("SetFallOffMidpoint", &SmoothStepRequestBus::Events::SetFallOffMidpoint)
  58. ->VirtualProperty("FallOffMidpoint", "GetFallOffMidpoint", "SetFallOffMidpoint")
  59. ->Event("GetFallOffRange", &SmoothStepRequestBus::Events::GetFallOffRange)
  60. ->Event("SetFallOffRange", &SmoothStepRequestBus::Events::SetFallOffRange)
  61. ->VirtualProperty("FallOffRange", "GetFallOffRange", "SetFallOffRange")
  62. ->Event("GetFallOffStrength", &SmoothStepRequestBus::Events::GetFallOffStrength)
  63. ->Event("SetFallOffStrength", &SmoothStepRequestBus::Events::SetFallOffStrength)
  64. ->VirtualProperty("FallOffStrength", "GetFallOffStrength", "SetFallOffStrength")
  65. ;
  66. }
  67. }
  68. }