|
@@ -1338,7 +1338,7 @@ compute_internal_bounds(Geom::CData *cdata, Thread *current_thread) const {
|
|
|
// Now actually compute the bounding volume. We do this by using
|
|
// Now actually compute the bounding volume. We do this by using
|
|
|
// calc_tight_bounds to determine our box first.
|
|
// calc_tight_bounds to determine our box first.
|
|
|
LPoint3 pmin, pmax;
|
|
LPoint3 pmin, pmax;
|
|
|
- PN_stdfloat sq_center_dist;
|
|
|
|
|
|
|
+ PN_stdfloat sq_center_dist = 0.0f;
|
|
|
bool found_any = false;
|
|
bool found_any = false;
|
|
|
do_calc_tight_bounds(pmin, pmax, sq_center_dist, found_any,
|
|
do_calc_tight_bounds(pmin, pmax, sq_center_dist, found_any,
|
|
|
vertex_data, false, LMatrix4::ident_mat(),
|
|
vertex_data, false, LMatrix4::ident_mat(),
|
|
@@ -1379,7 +1379,7 @@ compute_internal_bounds(Geom::CData *cdata, Thread *current_thread) const {
|
|
|
LPoint3 aabb_center = (pmin + pmax) * 0.5f;
|
|
LPoint3 aabb_center = (pmin + pmax) * 0.5f;
|
|
|
PN_stdfloat best_sq_radius = (pmax - aabb_center).length_squared();
|
|
PN_stdfloat best_sq_radius = (pmax - aabb_center).length_squared();
|
|
|
|
|
|
|
|
- if (btype != BoundingVolume::BT_fastest &&
|
|
|
|
|
|
|
+ if (btype != BoundingVolume::BT_fastest && best_sq_radius > 0.0f &&
|
|
|
aabb_center.length_squared() / best_sq_radius >= (0.2f * 0.2f)) {
|
|
aabb_center.length_squared() / best_sq_radius >= (0.2f * 0.2f)) {
|
|
|
// Hmm, this is an off-center model. Maybe we can do a better job
|
|
// Hmm, this is an off-center model. Maybe we can do a better job
|
|
|
// by calculating the bounding sphere from the AABB center.
|
|
// by calculating the bounding sphere from the AABB center.
|
|
@@ -1389,7 +1389,8 @@ compute_internal_bounds(Geom::CData *cdata, Thread *current_thread) const {
|
|
|
do_calc_sphere_radius(aabb_center, better_sq_radius, found_any,
|
|
do_calc_sphere_radius(aabb_center, better_sq_radius, found_any,
|
|
|
vertex_data, cdata, current_thread);
|
|
vertex_data, cdata, current_thread);
|
|
|
|
|
|
|
|
- if (found_any && better_sq_radius <= best_sq_radius) {
|
|
|
|
|
|
|
+ if (found_any && better_sq_radius > 0.0f &&
|
|
|
|
|
+ better_sq_radius <= best_sq_radius) {
|
|
|
// Great. This is as good a sphere as we're going to get.
|
|
// Great. This is as good a sphere as we're going to get.
|
|
|
if (btype == BoundingVolume::BT_best &&
|
|
if (btype == BoundingVolume::BT_best &&
|
|
|
avg_box_area < better_sq_radius * MathNumbers::pi) {
|
|
avg_box_area < better_sq_radius * MathNumbers::pi) {
|
|
@@ -1409,7 +1410,7 @@ compute_internal_bounds(Geom::CData *cdata, Thread *current_thread) const {
|
|
|
cdata->_internal_bounds = new BoundingBox(pmin, pmax);
|
|
cdata->_internal_bounds = new BoundingBox(pmin, pmax);
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
- } else if (sq_center_dist <= best_sq_radius) {
|
|
|
|
|
|
|
+ } else if (sq_center_dist >= 0.0f && sq_center_dist <= best_sq_radius) {
|
|
|
// No, but a sphere centered on the origin is apparently still
|
|
// No, but a sphere centered on the origin is apparently still
|
|
|
// better than a sphere around the bounding box.
|
|
// better than a sphere around the bounding box.
|
|
|
cdata->_internal_bounds =
|
|
cdata->_internal_bounds =
|
|
@@ -1420,7 +1421,8 @@ compute_internal_bounds(Geom::CData *cdata, Thread *current_thread) const {
|
|
|
// This is the worst sphere we can make, which is why we will only
|
|
// This is the worst sphere we can make, which is why we will only
|
|
|
// do it when the user specifically requests a sphere.
|
|
// do it when the user specifically requests a sphere.
|
|
|
cdata->_internal_bounds =
|
|
cdata->_internal_bounds =
|
|
|
- new BoundingSphere(aabb_center, csqrt(best_sq_radius));
|
|
|
|
|
|
|
+ new BoundingSphere(aabb_center,
|
|
|
|
|
+ (best_sq_radius > 0.0f) ? csqrt(best_sq_radius) : 0.0f);
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|