Newb: Only displaying things ‘on screen’

Software: Away3D 4.x

Babylon, Jr. Member
Posted: 09 July 2012 07:53 AM   Total Posts: 39

Hello, I’ve been trying to figure out how I can have my view only show what is on the stage and visible. Say only a few faces of a Square is visible, or if an object is behind another.

I generate 30 cubes and I start to lose framerate. My laptop graphics card does suck, but I wouldn’t think something like a few cubes would really start killing it.

private function init(Event null) : void 
  {
   removeEventListener
(Event.ADDED_TO_STAGEinit);
   
initEngine();
   
initText();
   
initLights();
   
initPhysics();
   
initMaterial();
   
initMesh();
   
initShapeBody();
   
initObjects();
   
initChildren();
   
initListener();
  
}
  
  
private function initEngine():void
  {
   stage
.scaleMode StageScaleMode.NO_SCALE;
   
stage.align StageAlign.TOP_LEFT;
   
stage.quality StageQuality.LOW;
   
   
_light = new PointLight();
   
_light.2500;
   
_light.= -4000;
   
   
_view = new View3D();
   
_view.focusRect true;
   
_view.scene.addChild(_light);
   
_view.camera springcam;  
   
_view.camera.lens.far 10000;
   
_view.camera._light.y;
   
_view.camera._light.z;
   
//_view.camera.x += 2000;
   
_view.camera.rotationX 25;
  
}
  
  
private function initLights():void
  {
   _light 
= new PointLight();
   
_light.2500;
   
_light.= -4000;
  
}
  
  
private function initText():void
  {
   
  }
  
  
private function initPhysics():void{
   
   physicsWorld 
AWPDynamicsWorld.getInstance();
   
physicsWorld.initWithDbvtBroadphase();
   
//physicsWorld.gravity = new Vector3D(0,0,0);
  
}
  
  
private function initMaterial():void{
   
   material 
= new ColorMaterial(0x252525);
  
}
  
  
private function initMesh():void{
   _lightPicker 
= new StaticLightPicker([_light]);
   
ground = new Mesh();
   
mesh = new Mesh();
   
meshes = new Vector.<Mesh>();
  
}
  
  
private function initShapeBody():void
  {
   groundShape 
= new AWPStaticPlaneShape(new Vector3D(010));
   
groundRigidbody = new AWPRigidBody(groundShapeground0);
   
   
shape null;
      
body null;
  
}
  
  
private function initObjects():void
  {
   debugDraw 
= new AWPDebugDraw(_viewphysicsWorld);
   
//Draw ground
   ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   
material  = new ColorMaterial(0x252525);
   
material.lightPicker _lightPicker;
   
ground = new Mesh();
   
ground.geometry = new PlaneGeometry(5000050000);
   
ground.material material;
   
_view.scene.addChild(ground);
   
   
groundShape = new AWPStaticPlaneShape(new Vector3D(010));
   
groundRigidbody = new AWPRigidBody(groundShapeground0);

   
physicsWorld.addRigidBodyWithGroup(groundRigidbodycollsionGroundcollisionAll);
   
   
//Draw cube
   ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   
var i:int 0;
   for (
030i++){
   material 
= new ColorMaterial(0xfc6a11);
   
material.lightPicker _lightPicker;
   
mesh = new Mesh();
   
mesh.geometry = new CubeGeometry(1515 i*1515111);
   
mesh.material material;
   
_view.scene.addChild(mesh);
   
shape = new AWPBoxShape(151515);
   
body = new AWPRigidBody(shapemesh1);
       
body.fricti    body.positi Vector3D(-10006000);
   
body.mass 1;
   
body.gravity = new Vector3D(000);
   
// make box collision enabled with other all rigidbodies
   //physicsWorld.addRigidBody(body);
   //physicsWorld.addRigidBodyWithGroup(body, collsionBox, collsionGround);
   
meshes.push(mesh);
   
trace(i);
   
}
   
  }
  
  
private function initChildren():void
  {
   this
.addChild(_view);
   
   
this.addChild(new AwayStats(_view));
  
}
  
  
private function initListener():void
  {
   
//stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
   //stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
   
stage.addEventListener(Event.ENTER_FRAMEhandleEnterFrame);
   
//_view.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
  
}
  
private function rotateMeshes():void
  {
   
var i:int 0;
   for (
030i++){     //meshes[i].rotati
    
meshes[i].rotate(new Vector3D(020), 10);
    
material = new ColorMaterial(0xfc6a11 *Math.random());
    
meshes[i].material material;
    
//meshes[i].visible = false;
    
   
}
  }
  
private function handleEnterFrame(Event) : void
  {
   springcam
.target mesh;
  
   
springcam.mass 10;  
   
springcam.damping 4;  
   
springcam.stiffness 1;  
   
   
//Try to look 100 units in front of target  
   
springcam.lookOffset = new Vector3D(000);   
   
   
//Try to stay 100 units behind target. 
   
rotateMeshes();    springcam.positi Vector3D(020, -650);
   
physicsWorld.step(timeStep);
   
debugDraw.debugDrawWorld();
   
_view.render();
   
  
}
  
 } 

Under initOject -> DrawCube is where the action of drawing the cube is at. initEngine is where the spring camera is set up.

Any optimization examples compatible with FP11 Away3D and :AwayPhysics v0.68 (23-11-2011) would be great.

EDIT: You might see ‘rotateMeshes’ and it actually changes the material of every square every second. This was just me seeing how badly I could destroy my framerate after my initial inquery on frame rate. Can be ignored.

I do have access to this book:
http://www.amazon.co.uk/exec/obidos/ASIN/1430225416/ref=nosim/friendofed-20

which talks about Level-of-detail (LOD). I haven’t specifically been able to get it to work, but I figured it didn’t matter since my segments on the cubes were already set to 1, 1, 1.

To my understanding back-face culling is also set so that my screen only draws the triangles it needs to?

I’d like to learn how to get _view.clipping.objectCulling = true; or any type of clipping to work. I can’t seem to find the import for it, since import away3d.core.clip doesn’t exist for me.

I guess my polygon count is only 366, so can I safely assume that the framerate is dropping because my laptop is bad?

   

kochumvk, Newbie
Posted: 09 July 2012 09:24 AM   Total Posts: 17   [ # 1 ]

To improve frame rates you can take few simple steps.
1.Reuse geometry
2.Reuse material(if possible)

In your case you are creating new geometry every time you create a cube.
You can use scaleX,scaleY scaleZ properties of mesh to achieve different sized cubes.

I have managed in excess of 3000 cubes without any trouble.

   

Babylon, Jr. Member
Posted: 09 July 2012 10:35 AM   Total Posts: 39   [ # 2 ]

Thanks for the advice, I didn’t realize I could re-use the geometry in that way.
It shows me that my laptop uses software to run the program rather than my GPU, even though I have flash player 11 and it shows my graphics card is compatible with flash’s GPU rendering I can’t figure out how to activate it. Any ideas?

   

Avatar
Matse, Sr. Member
Posted: 09 July 2012 10:59 AM   Total Posts: 149   [ # 3 ]

Make sure wmode = direct in the html ?

Another thing is you create new materials all the time it seems : since each mesh already has a different one you can just change materials colors instead of creating new ones.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X