One of the big problems with Papervision as a 3D engine is that because it’s cross platform, not hardware accelerated, it really uses up a lot of the hardware CPU.
Many Papervision projects can really bog down the CPU and can be a major turnoff for a user or a site visitor.

One of the easiest most common sense things to do is to render only when necessary. This only works for certain types of Papervision projects. If you have a 3D 1st person shooter, this probably won’t apply as much since you are always in motion. However if you have a project with clearly defined animation states that end up into mostly static states, this trick is a good one.

What I do is have a global variable, singleton or what have you called NEEDS_RENDER, which is set to true only when you need to render of course. By that I mean, only when there’s animation. If the scene does not change, there’s no need for us to call the Papervision render loop to update the scene.

// our render loop should look something like this now:
private function enterFrameHandler(event:Event):void {
if (NEEDS_RENDER)
view.singleRender();
}

If we are doing tween based animation (I am a big fan of TweenMax), then right before we do the animation, we set ourvariable to true so that the render loop knows to update the scene.
We use the onComplete event to set the NEEDS_RENDER variable back to false so that when the animation is done, we are no longer updating the scene.

NEEDS_RENDER = true;
TweenMax.to(cube, 1, {
rotationY:180,
onComplete:function():void {NEEDS_RENDER = false;}
})

This works for really simple cases where we only have at most ONE animation going on at any one time. In a more complicated scene where there maybe animations starting in the middle of other animations ending, using this method will produce rendering artifacts where animations suddenly stop or freeze or disappear. This is because the previous animation has not had a chance to finish its animation when a new animation starts. When the first animation finishes, the global variable is set and the render loop gets the message to not have to update the scene. This results in the new animation not being able to finish.

The simple workaround for this is to use the onUpdate event of TweenMax. We just keep setting the variable to true on this event which will keep firing until the animation is complete.

TweenMax.to(cube, 1, {
rotationY:180,
onComplete:function():void {NEEDS_RENDER = false;},
onUpdate:function():void {NEEDS_RENDER = true;}
})

Using these simple techniques, I was able to get a Papervision project that was constantly eating up 70-80% CPU to something that hovered around 20%, only spiking up during the animation.

Popularity: 8% [?]