Page 1 of 1

Debug draw triangles

Posted: Thu Jul 21, 2011 3:52 pm
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.

Re: Debug draw triangles

Posted: Thu Jul 05, 2018 3:31 pm
by mqnc
I second this post.

Re: Debug draw triangles

Posted: Fri Jul 06, 2018 9:48 pm
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)

Re: Debug draw triangles

Posted: Mon Jul 09, 2018 9:00 am
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?

Re: Debug draw triangles

Posted: Fri Feb 07, 2020 2:47 pm
by KlausSu
I just encountered the same thing. Have you created a pull request?