Help: How to fully fit an ObjectContainer3D in the viewport?

Software: Away3D 4.x

Mj, Newbie
Posted: 11 October 2014 04:15 PM   Total Posts: 1

the original function find in away builder. i change them in my project. but for each ObjectContainer3D with diffrent sizes not work correctly.
anybody has a solution?

public static function abs( value:Number ):Number {
   
return value < 0 ? -value : value;
  
}
  
public function updateDefaultCameraFarPlane(oC:ObjectContainer3D) : void {
   
var bounds:Vector.<Number> = containerBounds(oC,true);
   if (
abs(bounds[0])==Infinity || abs(bounds[1])==Infinity || abs(bounds[2])==Infinity || abs(bounds[3])==Infinity || abs(bounds[4])==Infinity || abs(bounds[5])==Infinity)
    
cameraController.distance = 100000;
   else 
{
    
var vec:Vector3D = new Vector3D(bounds[3] - bounds[0], bounds[4] - bounds[1], bounds[5] - bounds[2]);
    var 
objRadius:Number = vec.length / 2;
    
vec.x = (vec.x * 0.5) + bounds[0];
    
vec.y = (vec.y * 0.5) + bounds[1];
    
vec.z = (vec.z * 0.5) + bounds[2];

    
cameraController.distance = Vector3D.distance(camera.position, vec) + objRadius;    
   
}
  }
  
  
public static function containerBounds(oC:ObjectContainer3D, sceneBased:Boolean = true) : Vector.<Number> {
   Bounds
.getObjectContainerBounds(oC, sceneBased);
   return 
Vector.<Number>([Bounds.minX, Bounds.minY, Bounds.minZ, Bounds.maxX, Bounds.maxY, Bounds.maxZ]);
  
} 
   

rdoi, Member
Posted: 13 October 2014 03:02 PM   Total Posts: 86   [ # 1 ]

I took a look in this code a while ago, its main problem is the “object length” used. Because it simply uses the objects bounds diagonal as base to calculate the fit distance, so it doen’t work well for irregular shaped geometries.

A more accurate approach would be using the camera lens FOV angle and the objects view projected lengths in the calculation.

Just take a look in this thread that may help you:
http://away3d.com/forum/viewthread/797/

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X