Forráskód Böngészése

[Terrain] Expose spline bus to scripting (#10161)

* Expose spline bus to scripting.
This makes it possible to write scripts for entities to follow splines.

Signed-off-by: Mike Balfour <[email protected]>

* Expose spline methods in SC-friendly way.

Signed-off-by: Mike Balfour <[email protected]>

* PR Feedback: Replace pointers with references.

Signed-off-by: Mike Balfour <[email protected]>
Mike Balfour 3 éve
szülő
commit
359b0923f0

+ 12 - 9
Code/Framework/AzCore/AzCore/Math/Spline.cpp

@@ -98,27 +98,30 @@ namespace AZ
         if (BehaviorContext* behaviorContext = azrtti_cast<BehaviorContext*>(context))
         {
             behaviorContext->Class<SplineAddress>()->
-                Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::ListOnly)->
                 Constructor<u64, float>()->
                 Attribute(Script::Attributes::Storage, Script::Attributes::StorageType::Value)->
                 Attribute(Script::Attributes::ConstructorOverride, &Internal::SplineAddressScriptConstructor)->
                 Attribute(Script::Attributes::GenericConstructorOverride, &Internal::SplineAddressDefaultConstructor)->
                 Property("segmentIndex", BehaviorValueProperty(&SplineAddress::m_segmentIndex))->
-                Property("segmentFraction", BehaviorValueProperty(&SplineAddress::m_segmentFraction));
+                Property("segmentFraction", BehaviorValueProperty(&SplineAddress::m_segmentFraction))->
+                Method("GetSegmentIndexAndFraction", [](SplineAddress& thisPtr)
+                    {
+                        return AZStd::make_tuple(thisPtr.m_segmentIndex, thisPtr.m_segmentFraction);
+                    })
+                ;
 
             behaviorContext->Class<PositionSplineQueryResult>()->
                 Attribute(Script::Attributes::Storage, Script::Attributes::StorageType::Value)->
-                Property("splineAddress", [](PositionSplineQueryResult* thisPtr) { return thisPtr->m_splineAddress; }, nullptr)->
-                Property("distanceSq", [](PositionSplineQueryResult* thisPtr) { return thisPtr->m_distanceSq; }, nullptr);
+                Property("splineAddress", [](PositionSplineQueryResult& thisPtr) { return thisPtr.m_splineAddress; }, nullptr)->
+                Property("distanceSq", [](PositionSplineQueryResult& thisPtr) { return thisPtr.m_distanceSq; }, nullptr);
 
             behaviorContext->Class<RaySplineQueryResult>()->
                 Attribute(Script::Attributes::Storage, Script::Attributes::StorageType::Value)->
-                Property("splineAddress", [](RaySplineQueryResult* thisPtr) { return thisPtr->m_splineAddress; }, nullptr)->
-                Property("distanceSq", [](RaySplineQueryResult* thisPtr) { return thisPtr->m_distanceSq; }, nullptr)->
-                Property("rayDistance", [](RaySplineQueryResult* thisPtr) { return thisPtr->m_rayDistance; }, nullptr);
+                Property("splineAddress", [](RaySplineQueryResult& thisPtr) { return thisPtr.m_splineAddress; }, nullptr)->
+                Property("distanceSq", [](RaySplineQueryResult& thisPtr) { return thisPtr.m_distanceSq; }, nullptr)->
+                Property("rayDistance", [](RaySplineQueryResult& thisPtr) { return thisPtr.m_rayDistance; }, nullptr);
 
             behaviorContext->Class<Spline>()->
-                Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::ListOnly)->
                 Attribute(Script::Attributes::Storage, Script::Attributes::StorageType::RuntimeOwn)->
                 Method("GetNearestAddressRay", &Spline::GetNearestAddressRay)->
                 Method("GetNearestAddressPosition", &Spline::GetNearestAddressPosition)->
@@ -132,7 +135,7 @@ namespace AZ
                 Method("GetSegmentLength", &Spline::GetSegmentLength)->
                 Method("GetSegmentCount", &Spline::GetSegmentCount)->
                 Method("GetSegmentGranularity", &Spline::GetSegmentGranularity)->
-                Method("GetAabb", [](Spline* thisPtr, const Transform& transform) { Aabb aabb; thisPtr->GetAabb(aabb, transform); return aabb; })->
+                Method("GetAabb", [](Spline& thisPtr, const Transform& transform) { Aabb aabb; thisPtr.GetAabb(aabb, transform); return aabb; })->
                 Method("IsClosed", &Spline::IsClosed)->
                 Property("vertexContainer", BehaviorValueGetter(&Spline::m_vertexContainer), nullptr);
         }

+ 6 - 2
Gems/LmbrCentral/Code/Source/Shape/SplineComponent.cpp

@@ -182,10 +182,14 @@ namespace LmbrCentral
                 Handler<BehaviorSplineComponentNotificationBusHandler>();
 
             behaviorContext->EBus<SplineComponentRequestBus>("SplineComponentRequestBus")
-                ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
+                ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
                 ->Attribute(AZ::Edit::Attributes::Category, "Shape")
                 ->Attribute(AZ::Script::Attributes::Module, "shape")
-                ->Event("GetSpline", &SplineComponentRequestBus::Events::GetSpline)
+                ->Event("GetSpline",
+                    [](SplineComponentRequests* handler) -> const AZ::Spline&
+                    {
+                        return *(handler->GetSpline());
+                    })
                 ->Event("SetClosed", &SplineComponentRequestBus::Events::SetClosed)
                 ->Event("AddVertex", &SplineComponentRequestBus::Events::AddVertex)
                 ->Event("UpdateVertex", &SplineComponentRequestBus::Events::UpdateVertex)

+ 138 - 0
Gems/ScriptCanvas/Assets/TranslationAssets/Classes/SplineAddress.names

@@ -0,0 +1,138 @@
+{
+    "entries": [
+        {
+            "base": "SplineAddress",
+            "context": "BehaviorClass",
+            "variant": "",
+            "details": {
+                "name": "Spline Address"
+            },
+            "methods": [
+                {
+                    "base": "GetSegmentIndexAndFraction",
+                    "entry": {
+                        "name": "In",
+                        "tooltip": "When signaled, this will invoke Get Segment Index And Fraction"
+                    },
+                    "exit": {
+                        "name": "Out",
+                        "tooltip": "Signaled after Get Segment Index And Fraction is invoked"
+                    },
+                    "details": {
+                        "name": "Get Segment Index And Fraction"
+                    },
+                    "params": [
+                        {
+                            "typeid": "{865BA2EC-43C5-4E1F-9B6F-2D63F6DC2E70}",
+                            "details": {
+                                "name": "Spline Address"
+                            }
+                        }
+                    ],
+                    "results": [
+                        {
+                            "typeid": "{D6597933-47CD-4FC8-B911-63F3E2B0993A}",
+                            "details": {
+                                "name": "Index"
+                            }
+                        },
+                        {
+                            "typeid": "{EA2C3E90-AFBE-44D4-A90D-FAAF79BAF93D}",
+                            "details": {
+                                "name": "Fraction"
+                            }
+                        }
+                    ]
+                },
+                {
+                    "base": "GetsegmentIndex",
+                    "context": "Getter",
+                    "details": {
+                        "name": "Get Segment Index"
+                    },
+                    "params": [
+                        {
+                            "typeid": "{865BA2EC-43C5-4E1F-9B6F-2D63F6DC2E70}",
+                            "details": {
+                                "name": "Spline Address"
+                            }
+                        }
+                    ],
+                    "results": [
+                        {
+                            "typeid": "{D6597933-47CD-4FC8-B911-63F3E2B0993A}",
+                            "details": {
+                                "name": "segment Index"
+                            }
+                        }
+                    ]
+                },
+                {
+                    "base": "SetsegmentIndex",
+                    "context": "Setter",
+                    "details": {
+                        "name": "Set Segment Index"
+                    },
+                    "params": [
+                        {
+                            "typeid": "{865BA2EC-43C5-4E1F-9B6F-2D63F6DC2E70}",
+                            "details": {
+                                "name": "Spline Address"
+                            }
+                        },
+                        {
+                            "typeid": "{D6597933-47CD-4FC8-B911-63F3E2B0993A}",
+                            "details": {
+                                "name": "segment Index"
+                            }
+                        }
+                    ]
+                },
+                {
+                    "base": "GetsegmentFraction",
+                    "context": "Getter",
+                    "details": {
+                        "name": "Get Segment Fraction"
+                    },
+                    "params": [
+                        {
+                            "typeid": "{865BA2EC-43C5-4E1F-9B6F-2D63F6DC2E70}",
+                            "details": {
+                                "name": "Spline Address"
+                            }
+                        }
+                    ],
+                    "results": [
+                        {
+                            "typeid": "{EA2C3E90-AFBE-44D4-A90D-FAAF79BAF93D}",
+                            "details": {
+                                "name": "segment Fraction"
+                            }
+                        }
+                    ]
+                },
+                {
+                    "base": "SetsegmentFraction",
+                    "context": "Setter",
+                    "details": {
+                        "name": "Set Segment Fraction"
+                    },
+                    "params": [
+                        {
+                            "typeid": "{865BA2EC-43C5-4E1F-9B6F-2D63F6DC2E70}",
+                            "details": {
+                                "name": "Spline Address"
+                            }
+                        },
+                        {
+                            "typeid": "{EA2C3E90-AFBE-44D4-A90D-FAAF79BAF93D}",
+                            "details": {
+                                "name": "segment Fraction"
+                            }
+                        }
+                    ]
+                }
+            ]
+        }
+    ]
+}

+ 1 - 1
Gems/ScriptCanvas/Assets/TranslationAssets/EBus/Senders/SplineComponentRequestBus.names

@@ -128,7 +128,7 @@
                         {
                             "typeid": "{E13859C4-1F24-5C44-A133-F17B4B050D7C}",
                             "details": {
-                                "name": "AZStd::shared_ptr"
+                                "name": "Spline"
                             }
                         }
                     ]