Hey Joshua again, these issues should be addressed in the latest svn updates. Although bear in mind that for performance reasons, any objectcontainer approximates its min/max bounds using the bounding spheres of its children
cheers Rob On Sat, Aug 14, 2010 at 5:32 AM, Joshua Granick <[email protected]>wrote: > Hi everyone, > > Perhaps you've been frustrated to find that the minX, maxX, etc. properties > don't seem to work properly? I've been loading up some models, and the > bounding box has been huge. At first I thought it was an issue with how I > exported the model, but later I realized it was simply how Away3D was > handling the dimensions. > > After digging a bit more, I did discover that the Mesh object does report > these values correctly. However, once you attempt to check an > ObjectContainer3D, all bets are off. I'm sure this is for performance > reasons, but I think it would be awesome to have a "real" min/max value > available. Perhaps there would be some way to have a "dirty" flag, so it > wouldn't have to recalculate this too often? I know that once I load my > models, I'm not scaling them or altering the geometry, so it would be great > to have a reliable objectWidth value I could use. > > Well, in lieu of this being a part of the core, I decided to build a > getObject3DMinMax function. I know it isn't perfect ... the values broke > down somewhere as I was trying to get the correct absolute min and max > values, but I was able to reliably get the object dimensions, at least in my > project. I wanted to share this code for the benefit of others, and who > knows? Perhaps someone could improve on this a bit more, or perhaps a > similar feature may find its way in the core. > > > Here is my function: > > > > > package com.eclecticdesignstudio.utils { > > > import away3d.containers.ObjectContainer3D; > import away3d.core.base.Object3D; > > > /** > * @author Joshua Granick > */ > public function getObject3DMinMax (object:Object3D, metrics:Object = > null, offset:Object = null):Object { > > if (!metrics) { > > metrics = { minX: Infinity, minY: Infinity, maxX: > -Infinity, maxY: -Infinity, minZ: Infinity, maxZ: -Infinity }; > > } > > if (!offset) { > > offset = { x: 0, y: 0, z: 0 }; > > } > > //offset.x += object.transform.tx; > //offset.y += object.transform.ty; > //offset.z += object.transform.tz; > > if (!(object is ObjectContainer3D)) { > > if (object.minX + offset.x < metrics.minX) { > > metrics.minX = object.minX + offset.x; > > } > > if (object.maxX + offset.x > metrics.maxX) { > > metrics.maxX = object.maxX + offset.x; > > } > > if (object.minY + offset.y < metrics.minY) { > > metrics.minY = object.minY + offset.y; > > } > > if (object.maxY + offset.y > metrics.maxY) { > > metrics.maxY = object.maxY + offset.y; > > } > > if (object.minZ + offset.z < metrics.minZ) { > > metrics.minZ = object.minZ + offset.z; > > } > > if (object.maxZ + offset.z > metrics.maxZ) { > > metrics.maxZ = object.maxZ + offset.z; > > } > > } else { > > for each (var childObject:Object3D in (object as > ObjectContainer3D).children) { > > metrics = getObject3DMinMax (childObject, > metrics, offset); > > } > > } > > return metrics; > > } > > > } > > > > > As I said before, it is returning the correct dimensions, but not the > correct position. Since the objects in this project are fortunately aligned > to their center, I was able to get the true min and max values by using the > function like this: > > > > > var dimensions:Object = getObject3DMinMax (object); > > var objectWidth:Number = dimensions.maxX - dimensions.minX; > var objectDepth:Number = dimensions.maxY - dimensions.minY; > > dimensions.minX = object.x - objectWidth / 2; > dimensions.maxX = object.x + objectWidth / 2; > dimensions.minY = object.y - objectDepth / 2; > dimensions.maxY = object.y + objectDepth / 2; > > > > If you have any ideas or improvements, please reply to this message, so we > can all benefit. Getting the correct translation for the min/max, and maybe > some changes to support rotation values (not sure if its necessary?) would > be cool. > > Thanks for any help, and I hope this helps someone! > -- Rob Bateman Flash Development & Consultancy [email protected] www.infiniteturtles.co.uk www.away3d.com
