Drawing Stage3D to BitmapData while Resizing

Software: Away3D 4.x

RIPI, Jr. Member
Posted: 22 May 2012 09:51 AM   Total Posts: 33

Hi!

I need to blur the stage3D. As the Blur3D is not very good to animate, i found a Workaround using BitmapData. So, when i need to blur my scene (because a layer pops up and i don’t need the scene to update anymore) i just call a function that draws the content of Stage3D to a BitmapData. That works fine! Now i encountered a problem: When a user resizes the browser window, also the blurred BitmapData should be updated. If it try to resize the View3D and then call my method for drawing the Stage3D to BitmapData again, everything freezes.

Can somebody see what i do wrong? Is there a “best practice”? or has somebody another hint for me?

here’s my code:

//initial blurring:

public function blurStage3D() : void {
 _isBlurred 
true;
 
_renderStage3DToBitmap();
}

private function _renderStage3DToBitmap() : void {
 
if (_stage3DDuplicateBMD_stage3DDuplicateBMD.dispose();
 
_stage3DDuplicateBMD = new BitmapData(AppConfig.stageWidthAppConfig.stageHeight);
 
_stage3DView.renderer.swapBackBuffer false;
 
_stage3DView.render();
 
_stage3DView.stage3DProxy.context3D.drawToBitmapData(_stage3DDuplicateBMD);
 
_stage3DView.renderer.swapBackBuffer true;
 
_stage3DDuplicateBM.bitmapData _stage3DDuplicateBMD;
 
_stage3DDuplicateBM.filters [new BlurFilter(2020)];

//reblurring on resize, BUT THATS NOT WORKING:

if (_stage3DView{
 _stage3DView
.width AppConfig.stageWidth;
 
_stage3DView.height AppConfig.stageHeight;
 if (
_isBlurred){
  _renderStage3DToBitmap
();
 
}

Thank you very much!!

 

   

RIPI, Jr. Member
Posted: 24 May 2012 09:14 AM   Total Posts: 33   [ # 1 ]

I finally found a work-around and would like to share it with you.

The framework i work with uses a render()-function which is also called onResize. So that’s the place where i have to resize the View3D.
If my View3D should be blurred (it’s the case when a Layer is opened by a user) i first change the size of the View3D. Then i lock this function by setting a Boolean to false. on the next frame i redraw the Bitmap that contains a copy of the View3D-Image. And in a third step i redraw the View3D. And this is how it works:

override public function render() : void {
   stage
.transform.perspectiveProjection.projectionCenter = new Point(Math.round(_width 0.5), Math.round(_height 0.5));
   if (
_stage3DView && !_blockStage3DResizing{
   _stage3DView
.width AppConfig.stageWidth;
   
_stage3DView.height AppConfig.stageHeight;
   if (
_isBlurred{
      _blockStage3DResizing 
true;
      
addEventListener(Event.ENTER_FRAME_updateBlurredStage3DBitmap);
      
}
   }
}

private function _updateBlurredStage3DBitmap(event Event) : void {
   _renderStage3DToBitmap
();
   
removeEventListener(Event.ENTER_FRAME_updateBlurredStage3DBitmap);
   
addEventListener(Event.ENTER_FRAME_updateStage3D);
}

private function _updateStage3D(event Event) : void {
   stage3DView
.render();
   
_blockStage3DResizing false;
   
removeEventListener(Event.ENTER_FRAME_updateStage3D);

And again, my _renderStage3DToBitmap()-method:

private function _renderStage3DToBitmap() : void {
   
if (_stage3DDuplicateBMD_stage3DDuplicateBMD.dispose();
   
_stage3DDuplicateBMD = new BitmapData(AppConfig.stageWidthAppConfig.stageHeight);
   
_stage3DView.renderer.swapBackBuffer false;
   
_stage3DView.render();
   
_stage3DView.stage3DProxy.context3D.drawToBitmapData(_stage3DDuplicateBMD);
   
_stage3DView.renderer.swapBackBuffer true;
   
_stage3DDuplicateBM.bitmapData _stage3DDuplicateBMD;

Maybe somebody will need something like this in the future…

Have a nice day! wink

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X