소스 검색

Added ability for convex hull shape to draw face outlines

Jorrit Rouwe 3 년 전
부모
커밋
373590744d
3개의 변경된 파일21개의 추가작업 그리고 1개의 파일을 삭제
  1. 15 1
      Jolt/Physics/Collision/Shape/ConvexHullShape.cpp
  2. 5 0
      Jolt/Physics/Collision/Shape/ConvexHullShape.h
  3. 1 0
      Samples/SamplesApp.cpp

+ 15 - 1
Jolt/Physics/Collision/Shape/ConvexHullShape.cpp

@@ -832,7 +832,21 @@ void ConvexHullShape::Draw(DebugRenderer *inRenderer, Mat44Arg inCenterOfMassTra
 
 	// Draw the geometry
 	Color color = inUseMaterialColors? GetMaterial()->GetDebugColor() : inColor;
-	inRenderer->DrawGeometry(inCenterOfMassTransform * Mat44::sScale(inScale), color, mGeometry, cull_mode, DebugRenderer::ECastShadow::On, draw_mode);
+	Mat44 transform = inCenterOfMassTransform * Mat44::sScale(inScale);
+	inRenderer->DrawGeometry(transform, color, mGeometry, cull_mode, DebugRenderer::ECastShadow::On, draw_mode);
+
+	// Draw the outline if requested
+	if (sDrawFaceOutlines)
+		for (const Face &f : mFaces)
+		{
+			const uint8 *first_vtx = mVertexIdx.data() + f.mFirstVertex;
+			const uint8 *end_vtx = first_vtx + f.mNumVertices;
+
+			// Draw edges of face
+			inRenderer->DrawLine(transform * mPoints[*(end_vtx - 1)].mPosition, transform * mPoints[*first_vtx].mPosition, Color::sGrey);
+			for (const uint8 *v = first_vtx + 1; v < end_vtx; ++v)
+				inRenderer->DrawLine(transform * mPoints[*(v - 1)].mPosition, transform * mPoints[*v].mPosition, Color::sGrey);
+		}
 }
 
 void ConvexHullShape::DrawShrunkShape(DebugRenderer *inRenderer, Mat44Arg inCenterOfMassTransform, Vec3Arg inScale) const

+ 5 - 0
Jolt/Physics/Collision/Shape/ConvexHullShape.h

@@ -110,6 +110,11 @@ public:
 	// Register shape functions with the registry
 	static void				sRegister();
 
+#ifdef JPH_DEBUG_RENDERER
+	/// Draw the outlines of the faces of the convex hull when drawing the shape
+	inline static bool		sDrawFaceOutlines = false;
+#endif // JPH_DEBUG_RENDERER
+
 protected:
 	// See: Shape::RestoreBinaryState
 	virtual void			RestoreBinaryState(StreamIn &inStream) override;

+ 1 - 0
Samples/SamplesApp.cpp

@@ -406,6 +406,7 @@ SamplesApp::SamplesApp()
 		mDebugUI->CreateCheckBox(drawing_options, "Draw Joints", mPoseDrawSettings.mDrawJoints, [this](UICheckBox::EState inState) { mPoseDrawSettings.mDrawJoints = inState == UICheckBox::STATE_CHECKED; });
 		mDebugUI->CreateCheckBox(drawing_options, "Draw Joint Orientations", mPoseDrawSettings.mDrawJointOrientations, [this](UICheckBox::EState inState) { mPoseDrawSettings.mDrawJointOrientations = inState == UICheckBox::STATE_CHECKED; });
 		mDebugUI->CreateCheckBox(drawing_options, "Draw Joint Names", mPoseDrawSettings.mDrawJointNames, [this](UICheckBox::EState inState) { mPoseDrawSettings.mDrawJointNames = inState == UICheckBox::STATE_CHECKED; });
+		mDebugUI->CreateCheckBox(drawing_options, "Draw Convex Hull Shape Face Outlines", ConvexHullShape::sDrawFaceOutlines, [](UICheckBox::EState inState) { ConvexHullShape::sDrawFaceOutlines = inState == UICheckBox::STATE_CHECKED; });
 		mDebugUI->CreateCheckBox(drawing_options, "Draw Mesh Shape Triangle Groups", MeshShape::sDrawTriangleGroups, [](UICheckBox::EState inState) { MeshShape::sDrawTriangleGroups = inState == UICheckBox::STATE_CHECKED; });
 		mDebugUI->CreateCheckBox(drawing_options, "Draw Mesh Shape Triangle Outlines", MeshShape::sDrawTriangleOutlines, [](UICheckBox::EState inState) { MeshShape::sDrawTriangleOutlines = inState == UICheckBox::STATE_CHECKED; });
 		mDebugUI->CreateCheckBox(drawing_options, "Draw Height Field Shape Triangle Outlines", HeightFieldShape::sDrawTriangleOutlines, [](UICheckBox::EState inState) { HeightFieldShape::sDrawTriangleOutlines = inState == UICheckBox::STATE_CHECKED; });