Merge pull request from overte-org/fix/SphereCollapse

Made ExtractionMode::SphereCollapse fail more gracefully in case of incorrect data
This commit is contained in:
Dale Glass 2022-12-10 21:09:23 +01:00 committed by GitHub
commit c7a8f01234
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions
libraries
model-serializers/src
physics/src

View file

@ -1572,7 +1572,8 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash&
glm::vec3 globalMeshScale = extractScale(globalTransforms[nodeIndex]);
const glm::mat4 meshToJoint = glm::scale(glm::mat4(), globalMeshScale) * jointInverseBindTransforms[clusterIndex];
const float EXPANSION_WEIGHT_THRESHOLD = 0.25f;
// TODO: The entire clustering is probably broken and detailed collision shapes fail to generate due to it.
const uint16_t EXPANSION_WEIGHT_THRESHOLD = UINT16_MAX/4; // Equivalent of 0.25f?
if (mesh.clusterWeights[j] >= EXPANSION_WEIGHT_THRESHOLD) {
// TODO: fix transformed vertices being pushed back
auto& vertex = mesh.vertices[i];

View file

@ -210,6 +210,7 @@ MultiSphereShape::CollapsingMode MultiSphereShape::computeSpheres(ExtractionMode
auto& diff = data._diff;
auto& epsilon = data._epsilon;
auto& dimensions = data._dimensions;
const float DIMENSIONS_EPSILON = 0.000001f;
if (_mode == ExtractionMode::Automatic) {
if (diff.xy < 0.5f * epsilon.xy && diff.xz < 0.5f * epsilon.xz && diff.yz < 0.5f * epsilon.yz) {
@ -243,8 +244,12 @@ MultiSphereShape::CollapsingMode MultiSphereShape::computeSpheres(ExtractionMode
break;
case ExtractionMode::SphereCollapse:
sphere._radius = 0.5f * glm::min(glm::min(dimensions.x, dimensions.y), dimensions.z);
sphere._position = glm::vec3(0.0f);
_spheres.push_back(sphere);
if (sphere._radius > DIMENSIONS_EPSILON) {
sphere._position = glm::vec3(0.0f);
_spheres.push_back(sphere);
} else {
qDebug() << "MultiSphereShape::computeSpheres in mode ExtractionMode::SphereCollapse generated sphere with zero radius";
}
break;
case ExtractionMode::SpheresX:
axis = 0.5f* dimensions.x * Vectors::UNIT_NEG_X;