[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57641] branches/soc-2013-rigid_body_sim: rigidbody: Add debug drawing
Sergej Reich
sergej.reich at googlemail.com
Fri Jun 21 20:01:14 CEST 2013
Revision: 57641
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57641
Author: sergof
Date: 2013-06-21 18:01:14 +0000 (Fri, 21 Jun 2013)
Log Message:
-----------
rigidbody: Add debug drawing
This is very much a hack (crashes with big scenes), and will be removed
or at least rewritten in the future.
Use debug value 616 to enable.
Modified Paths:
--------------
branches/soc-2013-rigid_body_sim/intern/rigidbody/CMakeLists.txt
branches/soc-2013-rigid_body_sim/intern/rigidbody/rb_bullet_api.cpp
branches/soc-2013-rigid_body_sim/source/blender/editors/space_view3d/view3d_draw.c
branches/soc-2013-rigid_body_sim/source/blender/gpu/GPU_draw.h
branches/soc-2013-rigid_body_sim/source/blender/gpu/intern/gpu_draw.c
Modified: branches/soc-2013-rigid_body_sim/intern/rigidbody/CMakeLists.txt
===================================================================
--- branches/soc-2013-rigid_body_sim/intern/rigidbody/CMakeLists.txt 2013-06-21 17:04:07 UTC (rev 57640)
+++ branches/soc-2013-rigid_body_sim/intern/rigidbody/CMakeLists.txt 2013-06-21 18:01:14 UTC (rev 57641)
@@ -23,6 +23,7 @@
set(INC
.
+ ../../source/blender/gpu
../../extern/bullet2/src
)
Modified: branches/soc-2013-rigid_body_sim/intern/rigidbody/rb_bullet_api.cpp
===================================================================
--- branches/soc-2013-rigid_body_sim/intern/rigidbody/rb_bullet_api.cpp 2013-06-21 17:04:07 UTC (rev 57640)
+++ branches/soc-2013-rigid_body_sim/intern/rigidbody/rb_bullet_api.cpp 2013-06-21 18:01:14 UTC (rev 57641)
@@ -58,6 +58,8 @@
#include <stdio.h>
+#include "GPU_draw.h"
+
#include "RBI_api.h"
#include "btBulletDynamicsCommon.h"
@@ -106,6 +108,49 @@
}
};
+class rbDebugDraw : public btIDebugDraw {
+private:
+ int debug_mode;
+public:
+ rbDebugDraw() { }
+ virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color)
+ {
+ float root[3] = {from.x(), from.y(), from.z()};
+ float tip[3] = {to.x(), to.y(), to.z()};
+ float col[3] = {color.x(), color.y(), color.z()};
+ GPU_debug_add_line(root, tip, col);
+ }
+ virtual void drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB,btScalar distance,int lifeTime,const btVector3& color)
+ {
+ float root[3] = {PointOnB.x(), PointOnB.y(), PointOnB.z()};
+ btVector3 to = PointOnB + normalOnB;
+ float nor_tip[3] = {to.x(), to.y(), to.z()};
+
+ float col[3] = {0.0f, 1.0f, 1.0f};
+ GPU_debug_add_point(root, col);
+ col[0] = 1.0f;
+ col[1] = 0.0f;
+ col[2] = 1.0f;
+ GPU_debug_add_line(root, nor_tip, col);
+ }
+ virtual void reportErrorWarning(const char *warningString)
+ {
+
+ }
+ virtual void draw3dText(const btVector3& location,const char *textString)
+ {
+
+ }
+ virtual void setDebugMode(int debugMode)
+ {
+ debug_mode = debugMode;
+ }
+ virtual int getDebugMode() const
+ {
+ return debug_mode;
+ }
+};
+
static inline void copy_v3_btvec3(float vec[3], const btVector3 &btvec)
{
vec[0] = (float)btvec[0];
@@ -151,6 +196,18 @@
RB_dworld_set_gravity(world, gravity);
+ // HACK set debug drawer, this is only temporary
+ btIDebugDraw *debugDrawer = new rbDebugDraw();
+ debugDrawer->setDebugMode(btIDebugDraw::DBG_DrawWireframe |
+ btIDebugDraw::DBG_DrawAabb |
+ btIDebugDraw::DBG_DrawContactPoints |
+ btIDebugDraw::DBG_DrawText |
+ btIDebugDraw::DBG_DrawConstraintLimits |
+ btIDebugDraw::DBG_DrawConstraints |
+ btIDebugDraw::DBG_DrawConstraintLimits
+ );
+ world->dynamicsWorld->setDebugDrawer(debugDrawer);
+
return world;
}
@@ -200,6 +257,10 @@
void RB_dworld_step_simulation(rbDynamicsWorld *world, float timeStep, int maxSubSteps, float timeSubStep)
{
world->dynamicsWorld->stepSimulation(timeStep, maxSubSteps, timeSubStep);
+
+ // draw debug information
+ GPU_debug_reset();
+ world->dynamicsWorld->debugDrawWorld();
}
/* Export -------------------------- */
Modified: branches/soc-2013-rigid_body_sim/source/blender/editors/space_view3d/view3d_draw.c
===================================================================
--- branches/soc-2013-rigid_body_sim/source/blender/editors/space_view3d/view3d_draw.c 2013-06-21 17:04:07 UTC (rev 57640)
+++ branches/soc-2013-rigid_body_sim/source/blender/editors/space_view3d/view3d_draw.c 2013-06-21 18:01:14 UTC (rev 57641)
@@ -3357,6 +3357,9 @@
draw_object(scene, ar, v3d, base, 0);
}
}
+
+ // HACK draw bullet debug world
+ GPU_debug_draw();
// REEB_draw();
Modified: branches/soc-2013-rigid_body_sim/source/blender/gpu/GPU_draw.h
===================================================================
--- branches/soc-2013-rigid_body_sim/source/blender/gpu/GPU_draw.h 2013-06-21 17:04:07 UTC (rev 57640)
+++ branches/soc-2013-rigid_body_sim/source/blender/gpu/GPU_draw.h 2013-06-21 18:01:14 UTC (rev 57641)
@@ -45,6 +45,17 @@
struct RegionView3D;
struct SmokeModifierData;
+// HACK bullet debug draw functions
+typedef struct GPUDebugVert {
+ float pos[3];
+ float col[3];
+} GPUDebugVert;
+
+void GPU_debug_add_line(float p1[3], float p2[3], float col[3]);
+void GPU_debug_add_point(float pos[3], float col[3]);
+void GPU_debug_draw(void);
+void GPU_debug_reset(void);
+
/* OpenGL drawing functions related to shading. These are also
* shared with the game engine, where there were previously
* duplicates of some of these functions. */
Modified: branches/soc-2013-rigid_body_sim/source/blender/gpu/intern/gpu_draw.c
===================================================================
--- branches/soc-2013-rigid_body_sim/source/blender/gpu/intern/gpu_draw.c 2013-06-21 17:04:07 UTC (rev 57640)
+++ branches/soc-2013-rigid_body_sim/source/blender/gpu/intern/gpu_draw.c 2013-06-21 18:01:14 UTC (rev 57641)
@@ -74,6 +74,11 @@
extern Material defmaterial; /* from material.c */
+static GPUDebugVert GPU_varr[100000];
+static int GPU_varr_numverts = 0;
+static GPUDebugVert GPU_parr[100000];
+static int GPU_parr_numverts = 0;
+
/* These are some obscure rendering functions shared between the
* game engine and the blender, in this module to avoid duplicaten
* and abstract them away from the rest a bit */
@@ -87,6 +92,57 @@
glColor3ub(cp[3], cp[2], cp[1]);
}
+// HACK bullet debug draw functions
+void GPU_debug_add_line(float p1[3], float p2[3], float col[3])
+{
+ if (G.debug_value == 616) {
+ copy_v3_v3(GPU_varr[GPU_varr_numverts].pos, p1);
+ copy_v3_v3(GPU_varr[GPU_varr_numverts].col, col);
+ GPU_varr_numverts++;
+ copy_v3_v3(GPU_varr[GPU_varr_numverts].pos, p2);
+ copy_v3_v3(GPU_varr[GPU_varr_numverts].col, col);
+ GPU_varr_numverts++;
+ }
+}
+void GPU_debug_add_point(float pos[3], float col[3])
+{
+ if (G.debug_value == 616) {
+ copy_v3_v3(GPU_parr[GPU_parr_numverts].pos, pos);
+ copy_v3_v3(GPU_parr[GPU_parr_numverts].col, col);
+ GPU_parr_numverts++;
+ }
+}
+void GPU_debug_draw(void)
+{
+ if (G.debug_value == 616) {
+// glDisable(GL_DEPTH_TEST);
+
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_COLOR_ARRAY);
+
+ glVertexPointer(3, GL_FLOAT, sizeof(GPUDebugVert), GPU_varr);
+ glColorPointer(3, GL_FLOAT, sizeof(GPUDebugVert), &(GPU_varr->col[0]));
+ glDrawArrays(GL_LINES, 0, GPU_varr_numverts);
+
+ glDisable(GL_DEPTH_TEST);
+ glPointSize(5.0f);
+
+ glVertexPointer(3, GL_FLOAT, sizeof(GPUDebugVert), GPU_parr);
+ glColorPointer(3, GL_FLOAT, sizeof(GPUDebugVert), &(GPU_parr->col[0]));
+ glDrawArrays(GL_POINTS, 0, GPU_parr_numverts);
+
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_COLOR_ARRAY);
+
+ glEnable(GL_DEPTH_TEST);
+ }
+}
+void GPU_debug_reset(void)
+{
+ GPU_varr_numverts = 0;
+ GPU_parr_numverts = 0;
+}
+
void GPU_render_text(MTFace *tface, int mode,
const char *textstr, int textlen, unsigned int *col,
float *v1, float *v2, float *v3, float *v4, int glattrib)
More information about the Bf-blender-cvs
mailing list