mirror of
https://github.com/overte-org/overte.git
synced 2025-07-23 19:44:13 +02:00
Merge pull request #16059 from luiscuenca/fixMultisphereCrash
BUGZ-1156: Allow collapsing of all multi spheres
This commit is contained in:
commit
4d2e7eaaba
1 changed files with 22 additions and 8 deletions
|
@ -306,6 +306,7 @@ void MultiSphereShape::spheresFromAxes(const std::vector<glm::vec3>& points, con
|
||||||
float distance = glm::length(axis);
|
float distance = glm::length(axis);
|
||||||
float correntionRatio = radiusRatio * (spheres[j]._radius / maxAverageRadius);
|
float correntionRatio = radiusRatio * (spheres[j]._radius / maxAverageRadius);
|
||||||
float radius = (correntionRatio < 0.8f * radiusRatio ? 0.8f * radiusRatio : correntionRatio) * spheres[j]._radius;
|
float radius = (correntionRatio < 0.8f * radiusRatio ? 0.8f * radiusRatio : correntionRatio) * spheres[j]._radius;
|
||||||
|
maxRadius = radius > maxRadius ? radius : maxRadius;
|
||||||
if (sphereCount > 3) {
|
if (sphereCount > 3) {
|
||||||
distance = contractionRatio * distance;
|
distance = contractionRatio * distance;
|
||||||
}
|
}
|
||||||
|
@ -317,17 +318,30 @@ void MultiSphereShape::spheresFromAxes(const std::vector<glm::vec3>& points, con
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Collapse spheres if too close
|
// Collapse spheres if too close
|
||||||
if (sphereCount == 2) {
|
if (sphereCount > 1) {
|
||||||
int maxRadiusIndex = spheres[0]._radius > spheres[1]._radius ? 0 : 1;
|
bool collapsed = false;
|
||||||
if (glm::length(spheres[0]._position - spheres[1]._position) < 0.2f * spheres[maxRadiusIndex]._radius) {
|
for (size_t i = 0; i < spheres.size() - 1; i++) {
|
||||||
|
for (size_t j = i + 1; j < spheres.size(); j++) {
|
||||||
|
if (i != j) {
|
||||||
|
size_t maxRadiusIndex = spheres[i]._radius > spheres[j]._radius ? i : j;
|
||||||
|
if (glm::length(spheres[i]._position - spheres[j]._position) < 0.2f * spheres[maxRadiusIndex]._radius) {
|
||||||
SphereShapeData newSphere;
|
SphereShapeData newSphere;
|
||||||
newSphere._position = 0.5f * (spheres[0]._position + spheres[1]._position);
|
newSphere._position = _midPoint;
|
||||||
newSphere._radius = spheres[maxRadiusIndex]._radius;
|
newSphere._radius = maxRadius;
|
||||||
spheres.clear();
|
spheres.clear();
|
||||||
spheres.push_back(newSphere);
|
spheres.push_back(newSphere);
|
||||||
|
collapsed = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (collapsed) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MultiSphereShape::connectSpheres(int index1, int index2, bool onlyEdges) {
|
void MultiSphereShape::connectSpheres(int index1, int index2, bool onlyEdges) {
|
||||||
auto sphere1 = _spheres[index1]._radius > _spheres[index2]._radius ? _spheres[index1] : _spheres[index2];
|
auto sphere1 = _spheres[index1]._radius > _spheres[index2]._radius ? _spheres[index1] : _spheres[index2];
|
||||||
|
|
Loading…
Reference in a new issue