32 PStatCollector BulletDebugNode::_pstat_debug(
"App:Bullet:DoPhysics:Debug");
38 BulletDebugNode(
const char *name) :
PandaNode(name) {
41 _debug_world =
nullptr;
45 _drawer._normals =
true;
50 set_overall_hidden(
true);
130 _drawer.setDebugMode(DebugDraw::DBG_NoDebug);
133 int mode = DebugDraw::DBG_DrawText |
134 DebugDraw::DBG_DrawFeaturesText |
135 DebugDraw::DBG_DrawContactPoints;
138 mode |= DebugDraw::DBG_DrawWireframe;
142 mode |= DebugDraw::DBG_DrawConstraints;
143 mode |= DebugDraw::DBG_DrawConstraintLimits;
147 mode |= DebugDraw::DBG_DrawAabb;
150 _drawer.setDebugMode(mode);
172 PT(
Geom) debug_lines;
173 PT(
Geom) debug_triangles;
177 if (_debug_world ==
nullptr) {
181 nassertv(_debug_world !=
nullptr);
185 _drawer._lines.clear();
186 _drawer._triangles.clear();
188 _debug_world->debugDrawWorld();
194 vdata->unclean_set_num_rows(_drawer._lines.size() * 2);
200 for (lit = _drawer._lines.begin(); lit != _drawer._lines.end(); lit++) {
201 const Line &line = *lit;
205 cwriter.
set_data4(LVecBase4(line._color));
206 cwriter.
set_data4(LVecBase4(line._color));
210 prim->set_shade_model(Geom::SM_uniform);
211 prim->add_next_vertices(_drawer._lines.size() * 2);
213 debug_lines =
new Geom(vdata);
214 debug_lines->add_primitive(prim);
215 _debug_lines = debug_lines;
222 vdata->unclean_set_num_rows(_drawer._triangles.size() * 3);
228 for (tit = _drawer._triangles.begin(); tit != _drawer._triangles.end(); tit++) {
229 const Triangle &tri = *tit;
234 cwriter.
set_data4(LVecBase4(tri._color));
235 cwriter.
set_data4(LVecBase4(tri._color));
236 cwriter.
set_data4(LVecBase4(tri._color));
240 prim->set_shade_model(Geom::SM_uniform);
241 prim->add_next_vertices(_drawer._triangles.size() * 3);
243 debug_triangles =
new Geom(vdata);
244 debug_triangles->add_primitive(prim);
245 _debug_triangles = debug_triangles;
249 _drawer._lines.clear();
250 _drawer._triangles.clear();
252 _debug_stale =
false;
254 debug_lines = _debug_lines;
255 debug_triangles = _debug_triangles;
260 trav->_geoms_pcollector.add_level(2);
276 void BulletDebugNode::
277 do_sync_b2p(btDynamicsWorld *world) {
279 _debug_world = world;
286 void BulletDebugNode::DebugDraw::
287 setDebugMode(
int mode) {
295 int BulletDebugNode::DebugDraw::
296 getDebugMode()
const {
304 void BulletDebugNode::DebugDraw::
305 reportErrorWarning(
const char *warning) {
307 bullet_cat.error() << warning << std::endl;
313 void BulletDebugNode::DebugDraw::
314 drawLine(
const btVector3 &from,
const btVector3 &to,
const btVector3 &color) {
316 PN_stdfloat r = color.getX();
317 PN_stdfloat g = color.getY();
318 PN_stdfloat b = color.getZ();
322 if (_normals==
false && r==1.0f && g==1.0f && b==0.0f)
return;
326 line._p0 = LVecBase3((PN_stdfloat)from.getX(),
327 (PN_stdfloat)from.getY(),
328 (PN_stdfloat)from.getZ());
329 line._p1 = LVecBase3((PN_stdfloat)to.getX(),
330 (PN_stdfloat)to.getY(),
331 (PN_stdfloat)to.getZ());
332 line._color = UnalignedLVecBase4((PN_stdfloat)r,
334 (PN_stdfloat)b, 1.0f);
336 _lines.push_back(line);
342 void BulletDebugNode::DebugDraw::
343 drawTriangle(
const btVector3 &v0,
const btVector3 &v1,
const btVector3 &v2,
const btVector3 &color, btScalar) {
345 btScalar r = color.getX();
346 btScalar g = color.getY();
347 btScalar b = color.getZ();
351 tri._p0 = LVecBase3((PN_stdfloat)v0.getX(),
352 (PN_stdfloat)v0.getY(),
353 (PN_stdfloat)v0.getZ());
355 tri._p1 = LVecBase3((PN_stdfloat)v1.getX(),
356 (PN_stdfloat)v1.getY(),
357 (PN_stdfloat)v1.getZ());
359 tri._p2 = LVecBase3((PN_stdfloat)v2.getX(),
360 (PN_stdfloat)v2.getY(),
361 (PN_stdfloat)v2.getZ());
363 tri._color = UnalignedLVecBase4((PN_stdfloat)r,
365 (PN_stdfloat)b, 1.0f);
367 _triangles.push_back(tri);
385 void BulletDebugNode::DebugDraw::
386 drawTriangle(
const btVector3 &v0,
const btVector3 &v1,
const btVector3 &v2,
const btVector3 &n0,
const btVector3 &n1,
const btVector3 &n2,
const btVector3 &color, btScalar alpha) {
387 if (bullet_cat.is_debug()) {
388 bullet_cat.debug() <<
"drawTriangle(2) - not yet implemented!" << std::endl;
395 void BulletDebugNode::DebugDraw::
396 drawContactPoint(
const btVector3 &point,
const btVector3 &normal, btScalar distance,
int lifetime,
const btVector3 &color) {
398 const btVector3 to = point + normal * distance;
399 const btVector3 &from = point;
401 drawLine(from, to, color);
407 void BulletDebugNode::DebugDraw::
408 draw3dText(
const btVector3 &location,
const char *text) {
409 if (bullet_cat.is_debug()) {
410 bullet_cat.debug() <<
"draw3dText - not yet implemented!" << std::endl;
417 void BulletDebugNode::DebugDraw::
418 drawSphere(btScalar radius,
const btTransform &transform,
const btVector3 &color) {
420 btVector3 center = transform.getOrigin();
422 const btVector3 xoffs = transform.getBasis() * btVector3(1, 0, 0);
423 const btVector3 yoffs = transform.getBasis() * btVector3(0, 1, 0);
424 const btVector3 zoffs = transform.getBasis() * btVector3(0, 0, 1);
426 drawArc(center, xoffs, yoffs, radius, radius, 0, SIMD_2_PI, color,
false, 10.0);
427 drawArc(center, yoffs, zoffs, radius, radius, 0, SIMD_2_PI, color,
false, 10.0);
428 drawArc(center, zoffs, xoffs, radius, radius, 0, SIMD_2_PI, color,
false, 10.0);
465 param->fillin(scan, manager);
474 void BulletDebugNode::
476 PandaNode::fillin(scan, manager);