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

0.10.0 - createConvexMeshShape example provided in manual doesn't work #385

Closed
JoeRosselli opened this issue Apr 28, 2024 · 4 comments
Closed
Assignees
Milestone

Comments

@JoeRosselli
Copy link

Given that height map mesh generation is broke for me in 0.10.0 (See: Issue #378) I'm trying to migrate my height map based objects to use convex mesh shapes instead.

I'm trying to create a convex mesh shape as the user manual describes. https://www.reactphysics3d.com/usermanual.html#x1-4300010.1 under "10.1.4 Convex Mesh Shape".

Issue 1

Copy pasting the exact code provided in the manual, the one that creates a simple box with 24 vertices, ends up causing inconsistent behavior. 99% of the time when I run it, the shape fails to build and I get this error message:

Message (error): Error during initial hull creation in QuickHull: vertices too close to each other

However, 1% of the time it seems to not throw that error and let me continue, although the mesh isn't active in the world like I'd expect it to be. So there's maybe some sort of floating point related edge case that rarely causes it to behave differently?

Issue 2

In the example, when the vertices are specified, the third and fourth rows of vertices are identical. The example is missing a negative sign before the x value on the fourth line.

However, both with and without making that fix, I still get the "vertices too close to each other" error from Issue 1.

Issue 3

In the documentation on the website for Convex Mesh Shape, the documentation seems to have the same description and code example twice, one on top of the other, nearly identical except for a slightly different comment in the second version. I'm guessing the one example was supposed to show how to create a convex mesh from a PolygonVertexArray, and one version how to make one from a VertexArray? Both examples show the same VertexArray example code.

As for documentation, I also find it confusing what values we're supposed to provide for "number of vertices" parameters. In the box example, there's 8 vertices, where each vertex has an x, y, and z value, but we're supposed to pass in "24" for "nbVertices Number of vertices in the array"? There's 24 floats that make up the vertices, but there's only 8 actual vertices, so it seems wrong that we're supposed to pass in 24 for the number of vertices. (Unless the example in the documentation is wrong?)

Issue 4

I was also initially trying to create a convex mesh shape from a PolygonVertexArray but I could not find a single working combination of arguments that didn't cause a crash due to a bad map access within rp3d. I guess whenever Issue 3 is fixed and there's sample code for the PolygonVertexArray path and I can test whether it works or not.

@DanielChappuis
Copy link
Owner

Thanks a lot for your feedback.

As you said, there are an multiple issues in the documentation. First that's right there should not be two identical vertices coordinates in the array. Secondly, because it's a cube, the number of vertices is 8 (not 24). You need to use 8 in the parameters when you create the VertexArray.

I will need to fix the documentation.

In the meantime, you can take a look at how a ConvexMeshShape is created in the testbed application.

  • Using a VertexArray (with QuickHull algorithm) take a look here
  • Using a PolygonVertexArrray take a look here

Note that if you want to use a ConvexMeshShape, your shape have to be convex. If you are moving from a HeightFieldShape to a ConvexMeshShape, maybe your HeightFieldShape was not convex. In this case, you should use a ConcaveMeshShape instead.

Again, thanks a lot for reporting this issue. I will take a look at the HeightFieldShape issue you have reported as soon as I have some time.

@DanielChappuis DanielChappuis self-assigned this Apr 29, 2024
@DanielChappuis DanielChappuis added this to the v0.10.1 milestone Apr 29, 2024
@Xeraster
Copy link

Xeraster commented Jun 17, 2024

I'm trying to use Irrlicht to generate the bounding box since Irrlicht makes rectangles that more closely resemble the mesh. Since this can't do rectanlges, I'm trying to make it work with ConvexMeshShape. I made it so that my program gets Irrlicht to return the bounding box and im trying to make it convert that to a ConvexMeshShape.

Changing the vertex count from 8 to 24 allowed it to work a lot better but some rectangles cause the game to crash when collided. There is this one model whos collision box always causes a crash when an object bumps into it but my other models don't. The error is: "reactphysics3d/collision/shapes/ConvexMeshShape.cpp:106: virtual reactphysics3d::Vector3 reactphysics3d::ConvexMeshShape::getLocalSupportPointWithoutMargin(const reactphysics3d::Vector3&) const: Assertion `maxDotProduct >= decimal(0.0)' failed."

I had to go into the source code for this one. In ConvexMeshShape.cpp in the getLocalSupportPointWithoutMargin() function, there is a line of code "assert(maxDotProduct >= decimal(0.0));". I commented that out. The game no longer crashes when object collide into that one object. I don't know what the implications of this hack are but if I'm doing this wrong and that's the reason it's crashing, I would love to find out what the correct way is.

If I can use this to avoid implementing my own special colliders by building off of the plane class, I will. I was just wondering if ConvexMesh is out of date or borked and we're not supposed to be using it or if this is user error.

@DanielChappuis
Copy link
Owner

I'm trying to use Irrlicht to generate the bounding box since Irrlicht makes rectangles that more closely resemble the mesh. Since this can't do rectanlges, I'm trying to make it work with ConvexMeshShape. I made it so that my program gets Irrlicht to return the bounding box and im trying to make it convert that to a ConvexMeshShape.

Changing the vertex count from 8 to 24 allowed it to work a lot better but some rectangles cause the game to crash when collided. There is this one model whos collision box always causes a crash when an object bumps into it but my other models don't. The error is: "reactphysics3d/collision/shapes/ConvexMeshShape.cpp:106: virtual reactphysics3d::Vector3 reactphysics3d::ConvexMeshShape::getLocalSupportPointWithoutMargin(const reactphysics3d::Vector3&) const: Assertion `maxDotProduct >= decimal(0.0)' failed."

I had to go into the source code for this one. In ConvexMeshShape.cpp in the getLocalSupportPointWithoutMargin() function, there is a line of code "assert(maxDotProduct >= decimal(0.0));". I commented that out. The game no longer crashes when object collide into that one object. I don't know what the implications of this hack are but if I'm doing this wrong and that's the reason it's crashing, I would love to find out what the correct way is.

If I can use this to avoid implementing my own special colliders by building off of the plane class, I will. I was just wondering if ConvexMesh is out of date or borked and we're not supposed to be using it or if this is user error.

I have created a new issue here because it doesn't seem to be related to the current one.

@DanielChappuis
Copy link
Owner

This issue should now be fixed in the release of version v0.10.1. The documentation has also been updated.

Thanks again for reporting this issue.

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

No branches or pull requests

3 participants