How can I calculate the size of an object which contains multiple meshes?

Software: Away3D 4.x

Oleg1984, Newbie
Posted: 01 March 2013 02:36 PM   Total Posts: 11

I’ve created a 3D-package which is build of multiple surfaces. The main (top parent) object is an ObjectContainer3D. Each surface is a mesh I can click on. I can open and close my package by changing the rotation (with Matrix3D.appendrotation) of each ObjectContainer3D where the mesh is inside. When the package is opened I can calculate the size with getObjectContainerBounds and the BoundingVolumeBase (max.x-min.x | max.y-min.y) of my main ObjectContainer3D. This works fine and I get the correct result.
But how can I calculate the size when the package is closed?
I always get the same size, it does not matter if it’s opened or closed…

You can see the opened and closed package on attached sceenshots.

 

   

Avatar
Fabrice Closier, Administrator
Posted: 01 March 2013 04:06 PM   Total Posts: 1265   [ # 1 ]

take a look at away3d.tools.Bounds class.
getObjectContainerBounds method would be the one you need in this case.

   

Oleg1984, Newbie
Posted: 12 March 2013 07:45 AM   Total Posts: 11   [ # 2 ]

I’ve allready tried this method but it does not give the expected results. Maybe the results are not correct because I’m not using the internal roll, pitch and yaw functions to change the angles?
I’m changing the angle of each surface with the Matrix3D.appendRotation() function.
Maybe I have to update some data after the appendRotation() function?

   

Oleg1984, Newbie
Posted: 25 March 2013 09:06 AM   Total Posts: 11   [ # 3 ]

I solved my problem (how can I change the topic to [SOLVED]...?) by running through all my meshes and saving temporary the min-max values of all meshes with sceneTransform.transformVecor. With this method I get the correct min-max values and can calculate the size of my object.
If someone does not get the expected result from boundingbox, here is my fast-written code (I know that the code could be shorter and more beautiful without all the “if-tags”):

var aitem:Mesh=null;   
var 
minVector:Vector3D=new Vector3D(Infinity,Infinity,Infinity,1);
var 
maxVector:Vector3D=new Vector3D(-Infinity,-Infinity,-Infinity,1);

for (var 
i:Number=0;i<MyMeshArray.length;i++) 
{
  aitem
=Mesh(MyMeshArray.getItemAt(i));
  var 
v1:Vector3D=new Vector3D(0,0,0,0);
  
v1 aitem.sceneTransform.transformVector(new Vector3D(aitem.minXaitem.minYaitem.minZ,1));
  
  var 
v2:Vector3D=new Vector3D(0,0,0,0);
  
v2 aitem.sceneTransform.transformVector(new Vector3D(aitem.maxXaitem.maxYaitem.maxZ,1));
    
  if (
v1.x>maxVector.x{maxVector.x=v1.x;}
  
if (v1.y>maxVector.y{maxVector.y=v1.y;}
  
if (v1.z>maxVector.z{maxVector.z=v1.z;
  
if (v1.x<minVector.x{minVector.x=v1.x;}
  
if (v1.y<minVector.y{minVector.y=v1.y;}
  
if (v1.z<minVector.z{minVector.z=v1.z;}
    
  
if (v2.x>maxVector.x{maxVector.x=v2.x;}
  
if (v2.y>maxVector.y{maxVector.y=v2.y;}
  
if (v2.z>maxVector.z{maxVector.z=v2.z;}
  
if (v2.x<minVector.x{minVector.x=v2.x;}
  
if (v2.y<minVector.y{minVector.y=v2.y;}
  
if (v2.z<minVector.z{minVector.z=v2.z;}
}

MyNewWidth 
maxVector.x-minVector.x;
MyNewHeight maxVector.y-minVector.y;
MyNewDepth maxVector.z-minVector.z
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X