Debug draw triangles

Post Reply
User avatar
dphil
Posts: 237
Joined: Tue Jun 29, 2010 10:27 pm
Contact:

Debug draw triangles

Post by dphil »

The debug drawer has methods for drawing triangles, however when I implement them they never get called. I've tried various debug modes. Upon searching through Bullet's source code, I couldn't find any calls to drawTriangle, except for a bit of specialized code for soft bodies. Even for mesh shapes, I notice the physics world just calls the drawLine debug drawer functions to render wireframe triangles. So are the drawTriangle functions just there in case someone wants to use them, and they are not actually used in the default drawing process? (except for the soft body rendering). What I'd like is to render the surfaces of things like btGImpactMeshShapes and btConvexHullShapes (right now meshes get rendered as wireframe, and my convex hulls appear as a jumble of lines which generally do not represent the external edges of the hull). I suppose I could subclass btCollisionWorld and override debugDrawObject() and/or debugDrawWorld(), but if there is a better approach I'm all ears.
mqnc
Posts: 6
Joined: Fri Jun 29, 2018 10:23 am

Re: Debug draw triangles

Post by mqnc »

I second this post.
PcChip
Posts: 33
Joined: Sun May 20, 2018 3:09 pm

Re: Debug draw triangles

Post by PcChip »

I'm still very new to this, but an idea comes to mind:

in btCollisionWorld.cpp , check out this area:

Code: Select all

                /// for polyhedral shapes
                if (shape->isPolyhedral())
                {
                    btPolyhedralConvexShape* polyshape = (btPolyhedralConvexShape*) shape;
                    
                    int i;
                    if (polyshape->getConvexPolyhedron())
                    {
                        const btConvexPolyhedron* poly = polyshape->getConvexPolyhedron();
                        for (i=0;i<poly->m_faces.size();i++)
                        {
                            btVector3 centroid(0,0,0);
                            int numVerts = poly->m_faces[i].m_indices.size();
                            if (numVerts)
                            {
                                int lastV = poly->m_faces[i].m_indices[numVerts-1];
                                for (int v=0;v<poly->m_faces[i].m_indices.size();v++)
                                {
                                    int curVert = poly->m_faces[i].m_indices[v];
                                    centroid+=poly->m_vertices[curVert];
                                    getDebugDrawer()->drawLine(worldTransform*poly->m_vertices[lastV],worldTransform*poly->m_vertices[curVert],color);
                                    lastV = curVert;
                                }
                            }
                            centroid*= btScalar(1.f)/btScalar(numVerts);
                            if (getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawNormals)
                            {
                                btVector3 normalColor(1,1,0);
                                btVector3 faceNormal(poly->m_faces[i].m_plane[0],poly->m_faces[i].m_plane[1],poly->m_faces[i].m_plane[2]);
                                getDebugDrawer()->drawLine(worldTransform*centroid,worldTransform*(centroid+faceNormal),normalColor);
                            }
                            
                        }
for your convex hulls that look like "garbled lines", instead of the drawLine() , maybe have it draw a triangle strip instead?

I've never bothered because while I agree that simplified convex hulls look like garbled lines, it hasn't bothered me (since it's only a debug drawing anyway)
mqnc
Posts: 6
Joined: Fri Jun 29, 2018 10:23 am

Re: Debug draw triangles

Post by mqnc »

I am working with btTriangleMesh and it's also drawn with lines. The problem here is that in btCollisionWorld.cpp, it should be

Code: Select all

m_debugDrawer->drawTriangle(wv0,wv1,wv2,m_color,1.0);
instead of

Code: Select all

m_debugDrawer->drawLine(wv0,wv1,m_color);
m_debugDrawer->drawLine(wv1,wv2,m_color);
m_debugDrawer->drawLine(wv2,wv0,m_color);
and I wonder why this is the case. Especially since the default tirangle drawing function uses lines in the same way if it is not overloaded. Is this because it was only implemented half way or because there is a problem with having a triangle function, so it had to be changed to always drawing lines?

Should I just create a pull request?
KlausSu
Posts: 1
Joined: Fri Jan 24, 2020 12:12 pm

Re: Debug draw triangles

Post by KlausSu »

I just encountered the same thing. Have you created a pull request?
Post Reply