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(e : Event = null) : void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
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.y = 2500;
_light.z = -4000;
_view = new View3D();
_view.focusRect = true;
_view.scene.addChild(_light);
_view.camera = springcam;
_view.camera.lens.far = 10000;
_view.camera.y = _light.y;
_view.camera.z = _light.z;
//_view.camera.x += 2000;
_view.camera.rotationX = 25;
}
private function initLights():void
{
_light = new PointLight();
_light.y = 2500;
_light.z = -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(0, 1, 0));
groundRigidbody = new AWPRigidBody(groundShape, ground, 0);
shape = null;
body = null;
}
private function initObjects():void
{
debugDraw = new AWPDebugDraw(_view, physicsWorld);
//Draw ground
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
material = new ColorMaterial(0x252525);
material.lightPicker = _lightPicker;
ground = new Mesh();
ground.geometry = new PlaneGeometry(50000, 50000);
ground.material = material;
_view.scene.addChild(ground);
groundShape = new AWPStaticPlaneShape(new Vector3D(0, 1, 0));
groundRigidbody = new AWPRigidBody(groundShape, ground, 0);
physicsWorld.addRigidBodyWithGroup(groundRigidbody, collsionGround, collisionAll);
//Draw cube
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var i:int = 0;
for (i = 0; i < 30; i++){
material = new ColorMaterial(0xfc6a11);
material.lightPicker = _lightPicker;
mesh = new Mesh();
mesh.geometry = new CubeGeometry(15, 15 + i*15, 15, 1, 1, 1);
mesh.material = material;
_view.scene.addChild(mesh);
shape = new AWPBoxShape(15, 15, 15);
body = new AWPRigidBody(shape, mesh, 1);
body.fricti body.positi Vector3D(-1000, 600, 0);
body.mass = 1;
body.gravity = new Vector3D(0, 0, 0);
// 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_FRAME, handleEnterFrame);
//_view.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
private function rotateMeshes():void
{
var i:int = 0;
for (i = 0; i < 30; i++){ //meshes[i].rotati
meshes[i].rotate(new Vector3D(0, 2, 0), 10);
material = new ColorMaterial(0xfc6a11 *Math.random());
meshes[i].material = material;
//meshes[i].visible = false;
}
}
private function handleEnterFrame(e : 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(0, 0, 0);
//Try to stay 100 units behind target.
rotateMeshes(); springcam.positi Vector3D(0, 20, -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?