minX causing error

Software: Away3D 4.x

Avatar
FlyOn, Jr. Member
Posted: 06 December 2011 10:02 PM   Total Posts: 36
var container:ObjectContainer3D = new ObjectContainer3D();
container.addChild(new Sphere(new ColorMaterial(0x00ff00)));
trace(container.minX); 

is that a bug or should I do something different?

TypeErrorError #1009: Cannot access a property or method of a null object reference.
 
at away3d.bounds::BoundingVolumeBase/fromGeometry()[D:\1WEBDESIGN\Projects\DaVine\lib\away3d\bounds\BoundingVolumeBase.as:145]
 at away3d
.entities::Mesh/updateBounds()[D:\1WEBDESIGN\Projects\DaVine\lib\away3d\entities\Mesh.as:202]
 at away3d
.entities::Entity/get minX()[D:\1WEBDESIGN\Projects\DaVine\lib\away3d\entities\Entity.as:87]
 at away3d
.containers::ObjectContainer3D/get minX()[D:\1WEBDESIGN\Projects\DaVine\lib\away3d\containers\ObjectContainer3D.as:305] 
   

Avatar
FlyOn, Jr. Member
Posted: 07 December 2011 09:16 AM   Total Posts: 36   [ # 1 ]
testfile:

package 
{
 import away3d
.cameras.Camera3D;
 
import away3d.containers.ObjectContainer3D;
 
import away3d.containers.View3D;
 
import away3d.primitives.Sphere;
 
import flash.display.Sprite;
 
import flash.events.Event;
 
 public class 
MinXBug extends Sprite 
 {
  
public  var _view:View3D;
  public  var 
camera:Camera3D;
  
  public function 
MinXBug():void 
  {
   _view 
= new View3D();
   
this.addChild(_view);   
   
   var 
container:ObjectContainer3D = new ObjectContainer3D();
   var 
sphere:Sphere = new Sphere();
   
container.addChild(sphere);
   
_view.scene.addChild(container);
   
   
trace(container.maxX);
   
trace(container.minX);
   
  
}
  
 }
 
   

John Brookes, Moderator
Posted: 07 December 2011 11:28 AM   Total Posts: 732   [ # 2 ]

If you do a single render before doing the trace it works.
Guess it needs to update.

   

John Brookes, Moderator
Posted: 07 December 2011 11:44 AM   Total Posts: 732   [ # 3 ]

Bounds.getObjectContainerBounds(container)
trace(container.maxX);
trace(container.minX);

   

Avatar
FlyOn, Jr. Member
Posted: 07 December 2011 12:02 PM   Total Posts: 36   [ # 4 ]

Thanks!

Yes with render it works indeed ... but that means I should either do an extra render for every minX call, or an extra render after every child I add right?

with Bounds I’m not always getting a correct answer (-0.5 for minX, which should be around -300)

for now I’ve implemented this not so pretty, but working solution in my View class which extends ObjectContainer3D for minx maxX etc:

for each(var child:ObjectContainer3D in children)
{
 
if (child is Entity)
 
{
  _minX 
Math.min(child.- (child as Entity).bounds.min.y_minX);
 
}
 
else if (child is View)
 
{
  _minX 
Math.min(child.- (child as View).minX_minX);
 
}
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X