‘isInFrustrum’ has now changed - how does it work?

Software: Away3D 4.x

Mr Margaret Scratcher, Sr. Member
Posted: 14 October 2013 08:17 PM   Total Posts: 344

Quick one:

Previously I had this in my code to test it an object was visible:

if ((Entity(caseToUpdate).getEntityPartitionNode().isInFrustum(view.camera)) == true

but now it doesn’t work, giving this error:

Error: Implicit coercion of a value of type away3d.cameras:Camera3D to an unrelated type __AS3__.vec:Vector.<away3d.core.math:Plane3D>.

Bit stuck…


Also, on a related note, this is part of a routine that tests whether an item is in view, and so only loads the textures if so, are there any other methods for seeing whether an item has been culled or not?

Thanks,

Mark

 

 

   

John Brookes, Moderator
Posted: 15 October 2013 12:35 PM   Total Posts: 732   [ # 1 ]

Should do what you want.

trace(myMesh.worldBounds.isInFrustum(camera.frustumPlanescamera.frustumPlanes.length)); 
   

Mr Margaret Scratcher, Sr. Member
Posted: 06 January 2014 07:24 PM   Total Posts: 344   [ # 2 ]

Just got chance to try this out, and I’ve *almost* got it working…

package
{
 import away3d
.cameras.Camera3D;
 
import away3d.containers.View3D;
 
import away3d.entities.Mesh;
 
import away3d.materials.ColorMaterial;
 
import away3d.primitives.CubeGeometry;
 
 
import flash.events.Event;
 
import flash.display.Sprite;
 
import flash.display.StageScaleMode;
 
import flash.display.StageAlign;
 
 
import away3d.entities.Entity;
 
import away3d.core.partition.EntityNode;
 public class 
frustrum_test extends Sprite
 
 {
  
  
private var view:View3D;
  private var 
camera:Camera3D;
  private var 
cube:Mesh;
  
  
  public function 
frustrum_test():void
  {
   trace 
("testing out the new way that aw3d tests to see if a mesh is in the camera frustrum");
   
init3d();
   
  
}
  
  
  
private function init3d():void
  {
   camera 
= new Camera3D();
   
view = new View3D();
   
this.addChild(view);
   
testCube();
   
   
addStageListeners();
  
}
  
  
private function addStageListeners():void
  {
   stage
.scaleMode StageScaleMode.NO_SCALE;
   
stage.align StageAlign.TOP_LEFT;
   
addEventListener(Event.ENTER_FRAMEonEnterFrame);
  
}
  
  
private function testCube():void
  {
   
var cubeGeom:CubeGeometry = new CubeGeometry(100100100);
   
cube = new Mesh(cubeGeom, new ColorMaterial(0xff0000));
   
view.scene.addChild(cube);
  
}
  
  
  
private function onEnterFrame(ev Event) : void
  {
   view
.render();
   
trace (camera.frustumPlanes);
   
trace (camera.frustumPlanes.length);
   if (
cube.worldBounds.isInFrustum(camera.frustumPlanescamera.frustumPlanes.length))
   
   
{
    cube
.+= 5;
   
}
   
else
   
{
    trace 
("cube has gone out of frustum");
   
}
  }
 }
 


Which initially seems to work, but the cube stops moving and I get a trace saying it has gone out of the frustum, but the cube is still on the screen…


Any ideas?

Thanks.

   

John Brookes, Moderator
Posted: 07 January 2014 11:29 AM   Total Posts: 732   [ # 3 ]

You have created a camera, but thats not the camera that the view is using.
When you create a view() a camera is automagically created at the same time.
So thats the camera you would want to use.

So either change that snippet example I posted to view.camera

or create class member for the camera
private var camera:Camera3D;
camera = view.camera;

or tell the view you want to use the camera you created.
view = new View3D(null,camera);

   

Mr Margaret Scratcher, Sr. Member
Posted: 07 January 2014 12:51 PM   Total Posts: 344   [ # 4 ]

YES!

Just tested and that woks brilliantly, thanks!

   

Mr Margaret Scratcher, Sr. Member
Posted: 06 February 2014 06:58 PM   Total Posts: 344   [ # 5 ]

Okay, so a slight variation -> Initially my cull test tested to see if an objectcontainer3d was in the frustum, before iterating through its children, but it seems that you can’t get a worldbounds of an ObjectContainer3D.

i guess i could fake it with an invisible plane/cube which takes on the size of the ObjectContainer3d?

Or is there a better way?

What this is for is a number of shelves, which contain objects each with its own texture material. Each shelf is an OC3D, and so I test to see if that is in view first to see if it is worth checking all the children, and then loading their textures if they are in view. I thought that this way would save some overhead.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X