Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feeding a better initial penetration axis to GJK this improves performance #41

Merged
merged 1 commit into from
Feb 5, 2022

Conversation

jrouwe
Copy link
Owner

@jrouwe jrouwe commented Feb 5, 2022

No description provided.

@sonarcloud
Copy link

sonarcloud bot commented Feb 5, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@jrouwe jrouwe merged commit 6aa0465 into master Feb 5, 2022
@jrouwe jrouwe deleted the feature/penetration_axis branch February 5, 2022 13:24
@virt00l
Copy link

virt00l commented Aug 10, 2023

Sorry for necroposting, but this change seems to cause this issue:

// Don't supply a zero ioV, we only want to get points on the hull of the Minkowsky sum and not internal
JPH_ASSERT(!ioV.IsNearZero());

actual data from game mesh (triangle seems to be long, but not degenerate?):

v0 = array((0.279280782, -0.467894495, 0.105353981))
v1 = array((0.280091137, -0.467545986, 0.104968153))
v2 = array((0.277769983, -0.469322920, 0.105590254))
n = np.cross(v1 - v0, v2 - v0)
print(v1 - v0)
print(v2 - v0)
print(n)
print(n.dot(n))
...
[ 0.00081035  0.00034851 -0.00038583]
[-0.0015108  -0.00142842  0.00023627]
[ -4.68783094e-07   3.91443550e-07  -6.31004292e-07]
7.71152058489e-13

Not sure how to better handle this.
Check length and fallback to sAxisX instead of using normal ? Wouldn't this length check + branch cause net loss of said 5%?
Revert this change? Increase threshold (e.g. 1e-12 -> 1e-14)? Fix the data (mesh)?

@jrouwe
Copy link
Owner Author

jrouwe commented Aug 11, 2023

Hello,

Is it just this assert that is triggering or is there an actual issue? What is the full call stack? Is this a heavily scaled MeshShape perhaps?

In any case, the triangle is really really tiny (less than 1 mm^2), and it looks like it is barely bigger than the degenerate check that would have thrown the triangle away:

if (tri.IsDegenerate(mTriangleVertices) // Degenerate triangle

Are you able to clean up your mesh before providing it to Jolt? (it's just not a good idea to put triangles this small into the collision detection pipeline)

@virt00l
Copy link

virt00l commented Aug 11, 2023

Hello,

Is it just this assert that is triggering or is there an actual issue?

Well, I havent considered that there could be the difference. Will indeed try to comment it and see what happen

What is the full call stack

>	enlisted-dev.exe!JPH::CollideConvexVsTriangles::Collide(JPH::Vec3 inV0, JPH::Vec3 inV1, JPH::Vec3 inV2, unsigned char inActiveEdges, const JPH::SubShapeID & inSubShapeID2) Line 82	C++	Symbols loaded.
 	[Inline Frame] enlisted-dev.exe!JPH::MeshShape::sCollideConvexVsMesh::Visitor::VisitTriangle(JPH::Vec3 inV0, JPH::Vec3 inV1, JPH::Vec3 inV2, unsigned char inActiveEdges, JPH::SubShapeID inSubShapeID2) Line 1091	C++	Symbols loaded.
 	[Inline Frame] enlisted-dev.exe!JPH::MeshShape::WalkTreePerTriangle<Visitor>::ChainedVisitor::VisitTriangles(const JPH::TriangleCodecIndexed8BitPackSOA4Flags::DecodingContext & ioContext, const void * inTriangles, int inNumTriangles, unsigned int inTriangleBlockID) Line 487	C++	Symbols loaded.
 	[Inline Frame] enlisted-dev.exe!JPH::NodeCodecQuadTreeHalfFloat<1>::DecodingContext::WalkTree(const unsigned char * inBufferStart, const JPH::TriangleCodecIndexed8BitPackSOA4Flags::DecodingContext & inTriangleContext, JPH::MeshShape::WalkTreePerTriangle<Visitor>::ChainedVisitor & ioVisitor) Line 260	C++	Symbols loaded.
 	[Inline Frame] enlisted-dev.exe!JPH::MeshShape::WalkTree(JPH::MeshShape::WalkTreePerTriangle<Visitor>::ChainedVisitor & ioVisitor) Line 437	C++	Symbols loaded.
 	[Inline Frame] enlisted-dev.exe!JPH::MeshShape::WalkTreePerTriangle(const JPH::SubShapeIDCreator & inSubShapeIDCreator2, JPH::MeshShape::sCollideConvexVsMesh::Visitor & ioVisitor) Line 501	C++	Symbols loaded.
 	enlisted-dev.exe!JPH::MeshShape::sCollideConvexVsMesh(const JPH::Shape * inShape1, const JPH::Shape * inShape2, JPH::Vec3 inScale1, JPH::Vec3 inScale2, const JPH::Mat44 & inCenterOfMassTransform1, const JPH::Mat44 & inCenterOfMassTransform2, const JPH::SubShapeIDCreator & inSubShapeIDCreator1, const JPH::SubShapeIDCreator & inSubShapeIDCreator2, const JPH::CollideShapeSettings & inCollideShapeSettings, JPH::CollisionCollector<JPH::CollideShapeResult,JPH::CollisionCollectorTraitsCollideShape> & ioCollector, const JPH::ShapeFilter & inShapeFilter) Line 1096	C++	Symbols loaded.

In any case, the triangle is really really tiny (less than 1 mm^2), and it looks like it is barely bigger than the degenerate check >that would have thrown the triangle away:

I forgot to mention - this coords are in after this translation mTransform2To1 * (mScale2 * inV0), it's scaled, but not that much (0.6875), values are taken raw from debugger (last stack frame of above stack trace):

triangle:
{mValue=0x000000a8e5a39c60 {0.279185504, -0.478402555, -0.0955970585, 1.00000000}
{mValue=0x000000a8e5a39c70 {0.278547287, -0.478054047, -0.0962281227, 1.00000000}
{mValue=0x000000a8e5a39c80 {0.279921055, -0.479830980, -0.0942564011, 1.00000000}

mTransform2To1:
{-0.854890704, 0.00000000, -0.518808305, 0.00000000}
{0.00000000, 1.00000000, 0.00000000, 0.00000000}
{0.518808305, 0.00000000, -0.854890704, 0.00000000}
{0.286158055, -1.08555472, -0.273416281, 1.00000000}

From first look into the coll mesh it doesn't look too bad, but I'm currently in process of gathering additional info
image (3)

@virt00l
Copy link

virt00l commented Aug 11, 2023

Okay, we found the root cause of it (it seems) - it was broken mesh after all (was fixed recently, thats why I wasnt be able spot it right away in asset viewer, but existed in slightly outdated form within game)
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants