2
0
Эх сурвалжийг харах

Merge pull request #3 from urho3d/master

Updating from main repository
NickRoyer 10 жил өмнө
parent
commit
746a57bbd4

+ 31 - 0
Docs/ScriptAPI.dox

@@ -275,6 +275,13 @@ namespace Urho3D
 - %Size : unsigned
 - %Position : Vector3 [in/out]
 
+### CrowdAgentNodeFormation
+- %Node : Node pointer
+- %CrowdAgent : CrowdAgent pointer
+- %Index : unsigned
+- %Size : unsigned
+- %Position : Vector3 [in/out]
+
 ### CrowdAgentReposition
 - %Node : Node pointer
 - %CrowdAgent : CrowdAgent pointer
@@ -283,6 +290,14 @@ namespace Urho3D
 - %Arrived : bool
 - %TimeStep : float
 
+### CrowdAgentNodeReposition
+- %Node : Node pointer
+- %CrowdAgent : CrowdAgent pointer
+- %Position : Vector3
+- %Velocity : Vector3
+- %Arrived : bool
+- %TimeStep : float
+
 ### CrowdAgentFailure
 - %Node : Node pointer
 - %CrowdAgent : CrowdAgent pointer
@@ -291,6 +306,14 @@ namespace Urho3D
 - %CrowdAgentState : int
 - %CrowdTargetState : int
 
+### CrowdAgentNodeFailure
+- %Node : Node pointer
+- %CrowdAgent : CrowdAgent pointer
+- %Position : Vector3
+- %Velocity : Vector3
+- %CrowdAgentState : int
+- %CrowdTargetState : int
+
 ### CrowdAgentStateChanged
 - %Node : Node pointer
 - %CrowdAgent : CrowdAgent pointer
@@ -299,6 +322,14 @@ namespace Urho3D
 - %CrowdAgentState : int
 - %CrowdTargetState : int
 
+### CrowdAgentNodeStateChanged
+- %Node : Node pointer
+- %CrowdAgent : CrowdAgent pointer
+- %Position : Vector3
+- %Velocity : Vector3
+- %CrowdAgentState : int
+- %CrowdTargetState : int
+
 ### NavigationObstacleAdded
 - %Node : Node pointer
 - %Obstacle : Obstacle pointer

+ 1 - 1
Source/Urho3D/.soversion

@@ -1 +1 @@
-0.0.177
+0.0.178

+ 1 - 1
Source/Urho3D/Graphics/Batch.cpp

@@ -492,7 +492,7 @@ void Batch::Prepare(View* view, Camera* camera, bool setModelTransform, bool all
 
                 float sizeX = 1.0f / (float)shadowMap->GetWidth();
                 float sizeY = 1.0f / (float)shadowMap->GetHeight();
-                graphics->SetShaderParameter(PSP_SHADOWMAPINVSIZE, Vector4(sizeX, sizeY, 0.0f, 0.0f));
+                graphics->SetShaderParameter(PSP_SHADOWMAPINVSIZE, Vector2(sizeX, sizeY));
 
                 Vector4 lightSplits(M_LARGE_VALUE, M_LARGE_VALUE, M_LARGE_VALUE, M_LARGE_VALUE);
                 if (lightQueue_->shadowSplits_.Size() > 1)

+ 1 - 1
Source/Urho3D/Graphics/View.cpp

@@ -779,7 +779,7 @@ void View::SetGBufferShaderParameters(const IntVector2& texSize, const IntRect&
 
     float invSizeX = 1.0f / texWidth;
     float invSizeY = 1.0f / texHeight;
-    graphics_->SetShaderParameter(PSP_GBUFFERINVSIZE, Vector4(invSizeX, invSizeY, 0.0f, 0.0f));
+    graphics_->SetShaderParameter(PSP_GBUFFERINVSIZE, Vector2(invSizeX, invSizeY));
 }
 
 void View::GetDrawables()

+ 6 - 0
Source/Urho3D/Navigation/CrowdAgent.cpp

@@ -290,6 +290,9 @@ int CrowdAgent::AddAgentToCrowd(bool force)
             map[P_POSITION] = GetPosition();
             map[P_VELOCITY] = GetActualVelocity();
             crowdManager_->SendEvent(E_CROWD_AGENT_FAILURE, map);
+            Node* node = GetNode();
+            if (node)
+                node->SendEvent(E_CROWD_AGENT_NODE_FAILURE, map);
 
             // Reevaluate states as handling of event may have resulted in changes
             previousAgentState_ = GetAgentState();
@@ -526,6 +529,7 @@ void CrowdAgent::OnCrowdUpdate(dtCrowdAgent* ag, float dt)
             map[P_ARRIVED] = HasArrived();
             map[P_TIMESTEP] = dt;
             crowdManager_->SendEvent(E_CROWD_AGENT_REPOSITION, map);
+            node_->SendEvent(E_CROWD_AGENT_NODE_REPOSITION, map);
 
             if (updateNodePosition_)
             {
@@ -550,6 +554,7 @@ void CrowdAgent::OnCrowdUpdate(dtCrowdAgent* ag, float dt)
             map[P_POSITION] = newPos;
             map[P_VELOCITY] = newVel;
             crowdManager_->SendEvent(E_CROWD_AGENT_STATE_CHANGED, map);
+            node_->SendEvent(E_CROWD_AGENT_NODE_STATE_CHANGED, map);
 
             // Send a failure event if either state is a failed status
             if (newAgentState == CA_STATE_INVALID || newTargetState == CA_TARGET_FAILED)
@@ -562,6 +567,7 @@ void CrowdAgent::OnCrowdUpdate(dtCrowdAgent* ag, float dt)
                 map[P_POSITION] = newPos;
                 map[P_VELOCITY] = newVel;
                 crowdManager_->SendEvent(E_CROWD_AGENT_FAILURE, map);
+                node_->SendEvent(E_CROWD_AGENT_NODE_FAILURE, map);
             }
 
             // State may have been altered during the handling of the event

+ 43 - 0
Source/Urho3D/Navigation/NavigationEvents.h

@@ -53,6 +53,16 @@ URHO3D_EVENT(E_CROWD_AGENT_FORMATION, CrowdAgentFormation)
     URHO3D_PARAM(P_POSITION, Position); // Vector3 [in/out]
 }
 
+/// Crowd agent formation specific to a node.
+URHO3D_EVENT(E_CROWD_AGENT_NODE_FORMATION, CrowdAgentNodeFormation)
+{
+    URHO3D_PARAM(P_NODE, Node); // Node pointer
+    URHO3D_PARAM(P_CROWD_AGENT, CrowdAgent); // CrowdAgent pointer
+    URHO3D_PARAM(P_INDEX, Index); // unsigned
+    URHO3D_PARAM(P_SIZE, Size); // unsigned
+    URHO3D_PARAM(P_POSITION, Position); // Vector3 [in/out]
+}
+
 /// Crowd agent has been repositioned.
 URHO3D_EVENT(E_CROWD_AGENT_REPOSITION, CrowdAgentReposition)
 {
@@ -64,6 +74,17 @@ URHO3D_EVENT(E_CROWD_AGENT_REPOSITION, CrowdAgentReposition)
     URHO3D_PARAM(P_TIMESTEP, TimeStep); // float
 }
 
+/// Crowd agent has been repositioned, specific to a node
+URHO3D_EVENT(E_CROWD_AGENT_NODE_REPOSITION, CrowdAgentNodeReposition)
+{
+    URHO3D_PARAM(P_NODE, Node); // Node pointer
+    URHO3D_PARAM(P_CROWD_AGENT, CrowdAgent); // CrowdAgent pointer
+    URHO3D_PARAM(P_POSITION, Position); // Vector3
+    URHO3D_PARAM(P_VELOCITY, Velocity); // Vector3
+    URHO3D_PARAM(P_ARRIVED, Arrived); // bool
+    URHO3D_PARAM(P_TIMESTEP, TimeStep); // float
+}
+
 /// Crowd agent's internal state has become invalidated. This is a special case of CrowdAgentStateChanged event.
 URHO3D_EVENT(E_CROWD_AGENT_FAILURE, CrowdAgentFailure)
 {
@@ -75,6 +96,17 @@ URHO3D_EVENT(E_CROWD_AGENT_FAILURE, CrowdAgentFailure)
     URHO3D_PARAM(P_CROWD_TARGET_STATE, CrowdTargetState); // int
 }
 
+/// Crowd agent's internal state has become invalidated. This is a special case of CrowdAgentStateChanged event.
+URHO3D_EVENT(E_CROWD_AGENT_NODE_FAILURE, CrowdAgentNodeFailure)
+{
+    URHO3D_PARAM(P_NODE, Node); // Node pointer
+    URHO3D_PARAM(P_CROWD_AGENT, CrowdAgent); // CrowdAgent pointer
+    URHO3D_PARAM(P_POSITION, Position); // Vector3
+    URHO3D_PARAM(P_VELOCITY, Velocity); // Vector3
+    URHO3D_PARAM(P_CROWD_AGENT_STATE, CrowdAgentState); // int
+    URHO3D_PARAM(P_CROWD_TARGET_STATE, CrowdTargetState); // int
+}
+
 /// Crowd agent's state has been changed.
 URHO3D_EVENT(E_CROWD_AGENT_STATE_CHANGED, CrowdAgentStateChanged)
 {
@@ -86,6 +118,17 @@ URHO3D_EVENT(E_CROWD_AGENT_STATE_CHANGED, CrowdAgentStateChanged)
     URHO3D_PARAM(P_CROWD_TARGET_STATE, CrowdTargetState); // int
 }
 
+/// Crowd agent's state has been changed.
+URHO3D_EVENT(E_CROWD_AGENT_NODE_STATE_CHANGED, CrowdAgentNodeStateChanged)
+{
+    URHO3D_PARAM(P_NODE, Node); // Node pointer
+    URHO3D_PARAM(P_CROWD_AGENT, CrowdAgent); // CrowdAgent pointer
+    URHO3D_PARAM(P_POSITION, Position); // Vector3
+    URHO3D_PARAM(P_VELOCITY, Velocity); // Vector3
+    URHO3D_PARAM(P_CROWD_AGENT_STATE, CrowdAgentState); // int
+    URHO3D_PARAM(P_CROWD_TARGET_STATE, CrowdTargetState); // int
+}
+
 /// Addition of obstacle to dynamic navigation mesh.
 URHO3D_EVENT(E_NAVIGATION_OBSTACLE_ADDED, NavigationObstacleAdded)
 {

+ 54 - 0
Source/Urho3D/Navigation/NavigationMesh.cpp

@@ -570,6 +570,60 @@ void NavigationMesh::FindPath(PODVector<Vector3>& dest, const Vector3& start, co
         dest.Push(transform * pathData_->pathPoints_[i]);
 }
 
+void NavigationMesh::FindPath(NavigationPathData& dest, const Vector3& start, const Vector3& end, const Vector3& extents,
+    const dtQueryFilter* filter)
+{
+    URHO3D_PROFILE(FindPath);
+
+    dest.pathPoints_.Clear();
+    dest.pathFlags_.Clear();
+    dest.pathAreas_.Clear();
+
+    if (!InitializeQuery())
+        return;
+
+    // Navigation data is in local space. Transform path points from world to local
+    const Matrix3x4& transform = node_->GetWorldTransform();
+    Matrix3x4 inverse = transform.Inverse();
+
+    Vector3 localStart = inverse * start;
+    Vector3 localEnd = inverse * end;
+
+    const dtQueryFilter* queryFilter = filter ? filter : queryFilter_;
+    dtPolyRef startRef;
+    dtPolyRef endRef;
+    navMeshQuery_->findNearestPoly(&localStart.x_, &extents.x_, queryFilter, &startRef, 0);
+    navMeshQuery_->findNearestPoly(&localEnd.x_, &extents.x_, queryFilter, &endRef, 0);
+
+    if (!startRef || !endRef)
+        return;
+
+    int numPolys = 0;
+    int numPathPoints = 0;
+
+    navMeshQuery_->findPath(startRef, endRef, &localStart.x_, &localEnd.x_, queryFilter, pathData_->polys_, &numPolys,
+        MAX_POLYS);
+    if (!numPolys)
+        return;
+
+    Vector3 actualLocalEnd = localEnd;
+
+    // If full path was not found, clamp end point to the end polygon
+    if (pathData_->polys_[numPolys - 1] != endRef)
+        navMeshQuery_->closestPointOnPoly(pathData_->polys_[numPolys - 1], &localEnd.x_, &actualLocalEnd.x_, 0);
+
+    navMeshQuery_->findStraightPath(&localStart.x_, &actualLocalEnd.x_, pathData_->polys_, numPolys,
+        &pathData_->pathPoints_[0].x_, pathData_->pathFlags_, pathData_->pathPolys_, &numPathPoints, MAX_POLYS);
+
+    // Transform path result back to world space
+    for (int i = 0; i < numPathPoints; ++i)
+    {
+        dest.pathPoints_.Push(transform * pathData_->pathPoints_[i]);
+        dest.pathAreas_.Push(pathData_->pathAreras_[i]);
+        dest.pathFlags_.Push(pathData_->pathFlags_[i]);
+    }
+}
+
 Vector3 NavigationMesh::GetRandomPoint(const dtQueryFilter* filter, dtPolyRef* randomRef)
 {
     if (!InitializeQuery())

+ 14 - 0
Source/Urho3D/Navigation/NavigationMesh.h

@@ -65,6 +65,15 @@ struct NavigationGeometryInfo
     BoundingBox boundingBox_;
 };
 
+struct URHO3D_API NavigationPathData
+{
+    PODVector<Vector3> pathPoints_;
+    // Flags on the path.
+    PODVector<unsigned char> pathFlags_;
+    // Area Ids on the path.
+    PODVector<unsigned char> pathAreas_;
+};
+
 /// Navigation mesh component. Collects the navigation geometry from child nodes with the Navigable component and responds to path queries.
 class URHO3D_API NavigationMesh : public Component
 {
@@ -126,6 +135,11 @@ public:
     /// Find a path between world space points. Return non-empty list of points if successful. Extents specifies how far off the navigation mesh the points can be.
     void FindPath(PODVector<Vector3>& dest, const Vector3& start, const Vector3& end, const Vector3& extents = Vector3::ONE,
         const dtQueryFilter* filter = 0);
+
+    /// Find a path between world space points. Returns a NavigationPathData structure. Extents specifies how far off the navigaion mesh the points can be.
+    void FindPath(NavigationPathData& dest, const Vector3& start, const Vector3& end, const Vector3& extents = Vector3::ONE,
+        const dtQueryFilter* filter = 0);
+
     /// Return a random point on the navigation mesh.
     Vector3 GetRandomPoint(const dtQueryFilter* filter = 0, dtPolyRef* randomRef = 0);
     /// Return a random point on the navigation mesh within a circle. The circle radius is only a guideline and in practice the returned point may be further away.