empty bounds bug fix

This commit is contained in:
2016-02-07 02:58:26 +06:00
parent ba02ef7803
commit 9704155e72

View File

@@ -357,31 +357,29 @@ namespace IsoTools {
IsoUtils.MinMax IsoObjectMinMax3D(IsoObject iso_object) { IsoUtils.MinMax IsoObjectMinMax3D(IsoObject iso_object) {
iso_object.GetComponentsInChildren<Renderer>(_tmpRenderers); iso_object.GetComponentsInChildren<Renderer>(_tmpRenderers);
if ( _tmpRenderers.Count < 1 ) { bool inited = false;
return IsoUtils.MinMax.zero; var result = IsoUtils.MinMax.zero;
} for ( int i = 0, e = _tmpRenderers.Count; i < e; ++i ) {
// high performance tricks var bounds = _tmpRenderers[i].bounds;
var bounds = _tmpRenderers[0].bounds; var extents = bounds.extents;
var center = bounds.center.z; if ( extents.x > 0.0f || extents.y > 0.0f || extents.z > 0.0f ) {
var extent = bounds.extents.z; var center = bounds.center.z;
var minbounds = center - extent; var minbounds = center - extents.z;
var maxbounds = center + extent; var maxbounds = center + extents.z;
var result_min = minbounds; if ( inited ) {
var result_max = maxbounds; if ( minbounds < result.min ) {
for ( int i = _tmpRenderers.Count - 1; i > 0; --i ) { result.min = minbounds;
bounds = _tmpRenderers[i].bounds; }
center = bounds.center.z; if ( maxbounds > result.max ) {
extent = bounds.extents.z; result.max = maxbounds;
minbounds = center - extent; }
maxbounds = center + extent; } else {
if ( minbounds < result_min ) { inited = true;
result_min = minbounds; result = new IsoUtils.MinMax(minbounds, maxbounds);
} }
if ( maxbounds > result_max ) {
result_max = maxbounds;
} }
} }
return new IsoUtils.MinMax(result_min, result_max); return inited ? result : IsoUtils.MinMax.zero;
} }
bool IsIsoObjectVisible(IsoObject iso_object) { bool IsIsoObjectVisible(IsoObject iso_object) {