Browse Source

AABB-test physics geometry before adding it to the debug renderer.
Never debug draw heightfields, as it hugely slows down execution.

Lasse Öörni 13 years ago
parent
commit
073347c950

+ 10 - 4
Bin/Data/Scripts/Editor/EditorView.as

@@ -373,12 +373,18 @@ void ViewRaycast(bool mouseClick)
         if (result.drawable !is null)
         {
             Drawable@ drawable = result.drawable;
-            if (debug !is null)
+            // If selecting a terrain patch, select the parent terrain instead
+            if (drawable.typeName != "TerrainPatch")
             {
-                debug.AddNode(drawable.node, 1.0, false);
-                drawable.DrawDebugGeometry(debug, false);
+                selected = drawable;
+                if (debug !is null)
+                {
+                    debug.AddNode(drawable.node, 1.0, false);
+                    drawable.DrawDebugGeometry(debug, false);
+                }
             }
-            selected = drawable;
+            else if (drawable.node.parent !is null)
+                selected = drawable.node.parent.GetComponent("Terrain");
         }
     }
     else

+ 4 - 2
Bin/Data/Scripts/Terrain.as

@@ -292,7 +292,7 @@ void HandleKeyDown(StringHash eventType, VariantMap& eventData)
         if (key == ' ')
         {
             drawDebug++;
-            if (drawDebug > 1)
+            if (drawDebug > 2)
                 drawDebug = 0;
         }
 
@@ -432,7 +432,9 @@ void HandlePostRenderUpdate()
     // Draw rendering debug geometry without depth test to see the effect of occlusion
     if (drawDebug == 1)
         renderer.DrawDebugGeometry(false);
-
+    if (drawDebug == 2)
+        testScene.physicsWorld.DrawDebugGeometry(true);
+    
     IntVector2 pos = ui.cursorPosition;
     if (ui.GetElementAt(pos, true) is null && testScene.octree !is null)
     {

+ 3 - 3
Bin/Data/UI/EditorSettingsDialog.xml

@@ -132,15 +132,15 @@
         <element type="Text" style="FileSelectorFilterText" name="PickZones">
             <text value="Zones" />
         </element>
-        <element type="Text" style="FileSelectorFilterText" name="PickCollisionShapes">
-            <text value="Col.shapes" />
+        <element type="Text" style="FileSelectorFilterText" name="PickRigidBodies">
+            <text value="Rigidbodies" />
         </element>
         <element type="DropDownList" name="PickModeEdit">
             <fixedwidth value="100" />
             <popupitem name="PickGeometries" />
             <popupitem name="PickLights" />
             <popupitem name="PickZones" />
-            <popupitem name="PickCollisionShapes" />
+            <popupitem name="PickRigidBodies" />
         </element>
     </element>
     <element>

+ 1 - 1
Docs/Reference.dox

@@ -384,8 +384,8 @@ Graphics implements the low-level functionality:
 - Setting the screen mode
 - Keeping track of GPU resources
 - Keeping track of rendering context state (current rendertarget, vertex and index buffers, textures, shaders and renderstates)
-- Handling lost device
 - Performing primitive rendering operations
+- Handling lost device
 
 Screen resolution, fullscreen/windowed, vertical sync and hardware multisampling level are all set at once by calling Graphics's \ref Graphics::SetMode "SetMode()" function.
 

+ 0 - 14
Engine/Graphics/DebugRenderer.cpp

@@ -76,14 +76,6 @@ void DebugRenderer::AddLine(const Vector3& start, const Vector3& end, const Colo
     if (lines_.Size() + noDepthLines_.Size() >= MAX_LINES)
         return;
     
-    // Perform sphere culling to reject lines outside the view
-    /// \todo This is slow to do on a per line basis
-    Vector3 center = (start + end) * 0.5f;
-    Vector3 extent = end - center;
-    Sphere sphere(center, extent.Length());
-    if (frustum_.IsInsideFast(sphere) == OUTSIDE)
-        return;
-    
     if (depthTest)
         lines_.Push(DebugLine(start, end, color.ToUInt()));
     else
@@ -95,12 +87,6 @@ void DebugRenderer::AddLine(const Vector3& start, const Vector3& end, unsigned c
     if (lines_.Size() + noDepthLines_.Size() >= MAX_LINES)
         return;
     
-    Vector3 center = (start + end) * 0.5f;
-    Vector3 extent = end - center;
-    Sphere sphere(center, extent.Length());
-    if (frustum_.IsInsideFast(sphere) == OUTSIDE)
-        return;
-    
     if (depthTest)
         lines_.Push(DebugLine(start, end, color));
     else

+ 8 - 0
Engine/Physics/PhysicsWorld.cpp

@@ -161,6 +161,14 @@ void PhysicsWorld::RegisterObject(Context* context)
     ATTRIBUTE(PhysicsWorld, VAR_BOOL, "Interpolation", interpolation_, true, AM_FILE);
 }
 
+bool PhysicsWorld::isVisible(const btVector3& aabbMin, const btVector3& aabbMax)
+{
+    if (debugRenderer_)
+        return debugRenderer_->IsInside(BoundingBox(ToVector3(aabbMin), ToVector3(aabbMax)));
+    else
+        return false;
+}
+
 void PhysicsWorld::drawLine(const btVector3& from, const btVector3& to, const btVector3& color)
 {
     if (debugRenderer_)

+ 2 - 0
Engine/Physics/PhysicsWorld.h

@@ -97,6 +97,8 @@ public:
     /// Register object factory.
     static void RegisterObject(Context* context);
     
+    /// Check if an AABB is visible for debug drawing.
+    virtual bool isVisible(const btVector3& aabbMin, const btVector3& aabbMax);
     /// Draw a physics debug line.
     virtual void drawLine(const btVector3& from, const btVector3& to, const btVector3& color);
     /// Log warning from the physics engine.

+ 10 - 0
ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp

@@ -1219,9 +1219,19 @@ public:
 
 void btCollisionWorld::debugDrawObject(const btTransform& worldTransform, const btCollisionShape* shape, const btVector3& color)
 {
+	// Urho3D: perform AABB visibility test first
+	btVector3 aabbMin, aabbMax;
+	shape->getAabb(worldTransform, aabbMin, aabbMax);
+	if (!getDebugDrawer()->isVisible(aabbMin, aabbMax))
+		return;
+
 	// Draw a small simplex at the center of the object
 	getDebugDrawer()->drawTransform(worldTransform,1);
 
+	// Urho3D: never draw heightfields as they are potentially huge
+	if (shape->getShapeType() == TERRAIN_SHAPE_PROXYTYPE)
+		return;
+
 	if (shape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE)
 	{
 		const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(shape);

+ 4 - 0
ThirdParty/Bullet/src/LinearMath/btIDebugDraw.h

@@ -13,6 +13,7 @@ subject to the following restrictions:
 3. This notice may not be removed or altered from any source distribution.
 */
 
+// Modified by Lasse Öörni for Urho3D
 
 #ifndef BT_IDEBUG_DRAW__H
 #define BT_IDEBUG_DRAW__H
@@ -52,6 +53,9 @@ class	btIDebugDraw
 
 	virtual ~btIDebugDraw() {};
 
+	// Urho3D: added function to test visibility of an AABB
+	virtual bool    isVisible(const btVector3& aabbMin,const btVector3& aabbMax)=0;
+
 	virtual void	drawLine(const btVector3& from,const btVector3& to,const btVector3& color)=0;
 		
 	virtual void    drawLine(const btVector3& from,const btVector3& to, const btVector3& fromColor, const btVector3& toColor)