Bladeren bron

Merge remote-tracking branch '1vanK/master'

Lasse Öörni 9 jaren geleden
bovenliggende
commit
681e9f832c

+ 2 - 1
Source/Urho3D/AngelScript/GraphicsAPI.cpp

@@ -2031,8 +2031,9 @@ static void RegisterDebugRenderer(asIScriptEngine* engine)
     engine->RegisterObjectMethod("DebugRenderer", "bool get_lineAntiAlias() const", asMETHOD(DebugRenderer, GetLineAntiAlias), asCALL_THISCALL);
     engine->RegisterObjectMethod("DebugRenderer", "void AddLine(const Vector3&in, const Vector3&in, const Color&in, bool depthTest = true)", asMETHODPR(DebugRenderer, AddLine, (const Vector3&, const Vector3&, const Color&, bool), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("DebugRenderer", "void AddTriangle(const Vector3&in, const Vector3&in, const Vector3&in, const Color&in, bool depthTest = true)", asMETHODPR(DebugRenderer, AddTriangle, (const Vector3&, const Vector3&, const Vector3&, const Color&, bool), void), asCALL_THISCALL);
+    engine->RegisterObjectMethod("DebugRenderer", "void AddPolygon(const Vector3&in, const Vector3&in, const Vector3&in, const Vector3&in, const Color&in, bool depthTest = true)", asMETHODPR(DebugRenderer, AddPolygon, (const Vector3&, const Vector3&, const Vector3&, const Vector3&, const Color&, bool), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("DebugRenderer", "void AddNode(Node@+, float scale = 1.0, bool depthTest = true)", asMETHOD(DebugRenderer, AddNode), asCALL_THISCALL);
-    engine->RegisterObjectMethod("DebugRenderer", "void AddBoundingBox(const BoundingBox&in, const Color&in, bool depthTest = true)", asMETHODPR(DebugRenderer, AddBoundingBox, (const BoundingBox&, const Color&, bool), void), asCALL_THISCALL);
+    engine->RegisterObjectMethod("DebugRenderer", "void AddBoundingBox(const BoundingBox&in, const Color&in, bool depthTest = true, bool solid = false)", asMETHODPR(DebugRenderer, AddBoundingBox, (const BoundingBox&, const Color&, bool, bool), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("DebugRenderer", "void AddFrustum(const Frustum&in, const Color&in, bool depthTest = true)", asMETHOD(DebugRenderer, AddFrustum), asCALL_THISCALL);
     engine->RegisterObjectMethod("DebugRenderer", "void AddPolyhedron(const Polyhedron&in, const Color&in, bool depthTest = true)", asMETHOD(DebugRenderer, AddPolyhedron), asCALL_THISCALL);
     engine->RegisterObjectMethod("DebugRenderer", "void AddSphere(const Sphere&in, const Color&in, bool depthTest = true)", asMETHOD(DebugRenderer, AddSphere), asCALL_THISCALL);

+ 63 - 27
Source/Urho3D/Graphics/DebugRenderer.cpp

@@ -118,6 +118,18 @@ void DebugRenderer::AddTriangle(const Vector3& v1, const Vector3& v2, const Vect
         noDepthTriangles_.Push(DebugTriangle(v1, v2, v3, color));
 }
 
+void DebugRenderer::AddPolygon(const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, const Color& color, bool depthTest)
+{
+    AddTriangle(v1, v2, v3, color, depthTest);
+    AddTriangle(v3, v4, v1, color, depthTest);
+}
+
+void DebugRenderer::AddPolygon(const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, unsigned color, bool depthTest)
+{
+    AddTriangle(v1, v2, v3, color, depthTest);
+    AddTriangle(v3, v4, v1, color, depthTest);
+}
+
 void DebugRenderer::AddNode(Node* node, float scale, bool depthTest)
 {
     if (!node)
@@ -131,7 +143,7 @@ void DebugRenderer::AddNode(Node* node, float scale, bool depthTest)
     AddLine(start, start + rotation * (scale * Vector3::FORWARD), Color::BLUE.ToUInt(), depthTest);
 }
 
-void DebugRenderer::AddBoundingBox(const BoundingBox& box, const Color& color, bool depthTest)
+void DebugRenderer::AddBoundingBox(const BoundingBox& box, const Color& color, bool depthTest, bool solid)
 {
     const Vector3& min = box.min_;
     const Vector3& max = box.max_;
@@ -145,21 +157,33 @@ void DebugRenderer::AddBoundingBox(const BoundingBox& box, const Color& color, b
 
     unsigned uintColor = color.ToUInt();
 
-    AddLine(min, v1, uintColor, depthTest);
-    AddLine(v1, v2, uintColor, depthTest);
-    AddLine(v2, v3, uintColor, depthTest);
-    AddLine(v3, min, uintColor, depthTest);
-    AddLine(v4, v5, uintColor, depthTest);
-    AddLine(v5, max, uintColor, depthTest);
-    AddLine(max, v6, uintColor, depthTest);
-    AddLine(v6, v4, uintColor, depthTest);
-    AddLine(min, v4, uintColor, depthTest);
-    AddLine(v1, v5, uintColor, depthTest);
-    AddLine(v2, max, uintColor, depthTest);
-    AddLine(v3, v6, uintColor, depthTest);
+    if (!solid)
+    {
+        AddLine(min, v1, uintColor, depthTest);
+        AddLine(v1, v2, uintColor, depthTest);
+        AddLine(v2, v3, uintColor, depthTest);
+        AddLine(v3, min, uintColor, depthTest);
+        AddLine(v4, v5, uintColor, depthTest);
+        AddLine(v5, max, uintColor, depthTest);
+        AddLine(max, v6, uintColor, depthTest);
+        AddLine(v6, v4, uintColor, depthTest);
+        AddLine(min, v4, uintColor, depthTest);
+        AddLine(v1, v5, uintColor, depthTest);
+        AddLine(v2, max, uintColor, depthTest);
+        AddLine(v3, v6, uintColor, depthTest);
+    }
+    else
+    {
+        AddPolygon(min, v1, v2, v3, uintColor, depthTest);
+        AddPolygon(v4, v5, max, v6, uintColor, depthTest);
+        AddPolygon(min, v4, v6, v3, uintColor, depthTest);
+        AddPolygon(v1, v5, max, v2, uintColor, depthTest);
+        AddPolygon(v3, v2, max, v6, uintColor, depthTest);
+        AddPolygon(min, v1, v5, v4, uintColor, depthTest);
+    }
 }
 
-void DebugRenderer::AddBoundingBox(const BoundingBox& box, const Matrix3x4& transform, const Color& color, bool depthTest)
+void DebugRenderer::AddBoundingBox(const BoundingBox& box, const Matrix3x4& transform, const Color& color, bool depthTest, bool solid)
 {
     const Vector3& min = box.min_;
     const Vector3& max = box.max_;
@@ -175,18 +199,30 @@ void DebugRenderer::AddBoundingBox(const BoundingBox& box, const Matrix3x4& tran
 
     unsigned uintColor = color.ToUInt();
 
-    AddLine(v0, v1, uintColor, depthTest);
-    AddLine(v1, v2, uintColor, depthTest);
-    AddLine(v2, v3, uintColor, depthTest);
-    AddLine(v3, v0, uintColor, depthTest);
-    AddLine(v4, v5, uintColor, depthTest);
-    AddLine(v5, v7, uintColor, depthTest);
-    AddLine(v7, v6, uintColor, depthTest);
-    AddLine(v6, v4, uintColor, depthTest);
-    AddLine(v0, v4, uintColor, depthTest);
-    AddLine(v1, v5, uintColor, depthTest);
-    AddLine(v2, v7, uintColor, depthTest);
-    AddLine(v3, v6, uintColor, depthTest);
+    if (!solid)
+    {
+        AddLine(v0, v1, uintColor, depthTest);
+        AddLine(v1, v2, uintColor, depthTest);
+        AddLine(v2, v3, uintColor, depthTest);
+        AddLine(v3, v0, uintColor, depthTest);
+        AddLine(v4, v5, uintColor, depthTest);
+        AddLine(v5, v7, uintColor, depthTest);
+        AddLine(v7, v6, uintColor, depthTest);
+        AddLine(v6, v4, uintColor, depthTest);
+        AddLine(v0, v4, uintColor, depthTest);
+        AddLine(v1, v5, uintColor, depthTest);
+        AddLine(v2, v7, uintColor, depthTest);
+        AddLine(v3, v6, uintColor, depthTest);
+    }
+    else
+    {
+        AddPolygon(v0, v1, v2, v3, uintColor, depthTest);
+        AddPolygon(v4, v5, v7, v6, uintColor, depthTest);
+        AddPolygon(v0, v4, v6, v3, uintColor, depthTest);
+        AddPolygon(v1, v5, v7, v2, uintColor, depthTest);
+        AddPolygon(v3, v2, v7, v6, uintColor, depthTest);
+        AddPolygon(v0, v1, v5, v4, uintColor, depthTest);
+    }
 }
 
 
@@ -505,7 +541,7 @@ void DebugRenderer::Render()
     graphics->SetBlendMode(lineAntiAlias_ ? BLEND_ALPHA : BLEND_REPLACE);
     graphics->SetColorWrite(true);
     graphics->SetCullMode(CULL_NONE);
-    graphics->SetDepthWrite(true);
+    graphics->SetDepthWrite(false);
     graphics->SetLineAntiAlias(lineAntiAlias_);
     graphics->SetScissorTest(false);
     graphics->SetStencilTest(false);

+ 6 - 2
Source/Urho3D/Graphics/DebugRenderer.h

@@ -116,12 +116,16 @@ public:
     void AddTriangle(const Vector3& v1, const Vector3& v2, const Vector3& v3, const Color& color, bool depthTest = true);
     /// Add a triangle with color already converted to unsigned.
     void AddTriangle(const Vector3& v1, const Vector3& v2, const Vector3& v3, unsigned color, bool depthTest = true);
+    /// Add a quadrangular polygon.
+    void AddPolygon(const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, const Color& color, bool depthTest = true);
+    /// Add a quadrangular polygon with color already converted to unsigned.
+    void AddPolygon(const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, unsigned color, bool depthTest = true);
     /// Add a scene node represented as its coordinate axes.
     void AddNode(Node* node, float scale = 1.0f, bool depthTest = true);
     /// Add a bounding box.
-    void AddBoundingBox(const BoundingBox& box, const Color& color, bool depthTest = true);
+    void AddBoundingBox(const BoundingBox& box, const Color& color, bool depthTest = true, bool solid = false);
     /// Add a bounding box with transform.
-    void AddBoundingBox(const BoundingBox& box, const Matrix3x4& transform, const Color& color, bool depthTest = true);
+    void AddBoundingBox(const BoundingBox& box, const Matrix3x4& transform, const Color& color, bool depthTest = true, bool solid = false);
     /// Add a frustum.
     void AddFrustum(const Frustum& frustum, const Color& color, bool depthTest = true);
     /// Add a polyhedron.

+ 4 - 2
Source/Urho3D/LuaScript/pkgs/Graphics/DebugRenderer.pkg

@@ -8,9 +8,11 @@ class DebugRenderer : public Component
     void AddLine(const Vector3& start, const Vector3& end, unsigned color, bool depthTest = true);
     void AddTriangle(const Vector3& v1, const Vector3& v2, const Vector3& v3, const Color& color, bool depthTest = true);
     void AddTriangle(const Vector3& v1, const Vector3& v2, const Vector3& v3, unsigned color, bool depthTest = true);
+    void AddPolygon(const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, const Color& color, bool depthTest = true);
+    void AddPolygon(const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, unsigned color, bool depthTest = true);
     void AddNode(Node* node, float scale = 1.0f, bool depthTest = true);
-    void AddBoundingBox(const BoundingBox& box, const Color& color, bool depthTest = true);
-    void AddBoundingBox(const BoundingBox& box, const Matrix3x4& transform, const Color& color, bool depthTest = true);
+    void AddBoundingBox(const BoundingBox& box, const Color& color, bool depthTest = true, bool solid = false);
+    void AddBoundingBox(const BoundingBox& box, const Matrix3x4& transform, const Color& color, bool depthTest = true, bool solid = false);
     void AddFrustum(const Frustum& frustum, const Color& color, bool depthTest = true);
     void AddPolyhedron(const Polyhedron& poly, const Color& color, bool depthTest = true);
     void AddSphere(const Sphere& sphere, const Color& color, bool depthTest = true);

+ 1 - 0
Source/Urho3D/Navigation/NavArea.cpp

@@ -81,6 +81,7 @@ void NavArea::DrawDebugGeometry(DebugRenderer* debug, bool depthTest)
         Matrix3x4 mat;
         mat.SetTranslation(node_->GetWorldPosition());
         debug->AddBoundingBox(boundingBox_, mat, Color::GREEN, depthTest);
+        debug->AddBoundingBox(boundingBox_, mat, Color(0.0f, 1.0f, 0.0f, 0.15f), true, true);
     }
 }