-
Notifications
You must be signed in to change notification settings - Fork 94
Description
In ConvexMesh::useDimensions(), there is this code that processes planes (halfspaces) generated by qhull:
It checks if the plane for the currently processed triangle/facet isn't too similar to the plane for the previous triangle. If it is, it merges these planes into one and makes both triangles reference the same plane.
However, according to the definition of padding for convex meshes in this library, this optimization goes wrong when non-zero padding is used.
I made some visualizations to make this argument clearly visible:
Here, the red line is original (unscaled) "mesh" (well...). The cyan one is the line after applying only scaling. And the green one is after padding is applied. You can see that the line stops being a line and any planes that would be optimized by the previous algorithm would no longer be parallel.
Maybe even more obvious.
This has also consequences for more code paths. It seems to me that two things are required.
- Get rid of the "if" in the above code excerpt and just add one plane per each triangle.
- Take a broader look around the code, and e.g. add
mesh_data_->scaled_planes_which would contain the correctly scaled and padded planes which could be used for collision checking. For example this code tries to subtract padding from the data, but fails to do it correctly (a part of it is fixed in Fixed computation of intersectsRay() for Cylinder, Box and ConvexMesh #109):
If there were an already precomputed field containing the scaled planes, all computations of this kind could be done both efficiently and without fear if everything is correctly accounted for. My approach to recomputing the scaled planes would be to just take the scaled vertices and reconstruct the scaled planes from them. It has just one drawback - so far, mesh_data_ are not touched in updateInternalData(), however if we wanted to keep a set of scaled planes, these would obviously need to be updated in updateInternalData(). But this function anyways has a loop over all vertices to recompute the scaled vertices, so I think another loop for scaled planes is not a problem. It might well be compensated by the possible speedups from #126.

