Anti Aliasing stops working if I resize the view..

Software: Away3D 4.x

Mr Margaret Scratcher, Sr. Member
Posted: 25 July 2012 10:42 PM   Total Posts: 344

..but not if the view is resized by the onstageResize event..

I can’t figure this out:

This is just a basic setup, a templatte I generally begin with whenever I start a project using away3d, and when I pinned the lack of anti aliasing in my current project down when the view gets resized, i thought I’d go back to this basic setup to experiment. As expected, the view is scale to fit the stage when the stage is resized, and also it can be resized to an arbitrary amount on resize too. However, if I tried to change the view size anywhere else, I found that the anti aliasing stops working (even though in my main project if I traced the anti aliasing it still reported that it was ‘10’)


Am I doing something silly?

[SWF(width="1280"height="720"frameRate="60"backgroundColor="0xffffff")]
 
public class BasicAway extends Sprite
 {
  
private var view View3D;
  private var 
camera Camera3D
  
private var camController:HoverDragController;
  
  
//private var OBJloader : Loader3D;
  
private var _light PointLight;
  private var 
_light2 PointLight;
  private var 
lightPicker:StaticLightPicker;

 
  private var 
camInitZ:Number = -200;
  private var 
camInitY:Number 15;
  private var 
camInitX:Number 0;
  private var 
camInitRot:Number 0;
  
  private var 
cube:Mesh;
  private var 
Material ColorMaterial;
 
  public function 
BasicAway()
  

   init3D
();
   
AddStageListeners ();
   
testCube();
   
stage.scaleMode StageScaleMode.NO_SCALE;
   
stage.align StageAlign.TOP_LEFT;
   
addEventListener(Event.ENTER_FRAMEonEnterFrame);
  
}
  
  
  
private function testCube():void
  {
   
   
var cubeGeometry:CubeGeometry = new CubeGeometry404040101010);
   
cube = new Mesh(cubeGeometryMaterial);
   
view.scene.addChild(cube);
   
   
//But this stops anti aliasing
   //view.width = 100;
   //view.height = 200;
  
}
 
  
private function AddStageListeners():void
  
//add listeners for resize
  
{
   stage
.addEventListener(Event.RESIZEonStageResize);
  
  
}
  
  
  
 
  
  
  
private function init3D ():void
  
//setup view, cameras
  
{
   stage
.quality "high";
   
view = new View3D();
   
   
   
//This also causes aliasing
   //view.width = 100;
   //view.height = 200;
   
   
view.antiAlias 10;
   
   
this.addChild(view);
   
   
   
camera view.camera;
   
_light = new PointLight();
   
_light.= -100;
   
_light.= -200;
   
_light.200;
   
_light.color 0xfffebc;
   
view.scene.addChild(_light);
   
   
   
_light2 = new PointLight();
   
_light2.= -500;
   
_light2.= -200;
   
_light2.200;
   
_light.color 0xfffebc;
   
view.scene.addChild(_light2);
   
lightPicker = new StaticLightPicker([_light_light2]);
   
addChild(new AwayStats(view));
   
   
   
camera.camInitZ;
   
camera.camInitY;
   
camera.=  camInitX;
   
camera.rotationY camInitRot;
   
camera.lens = new PerspectiveLens (40);
   
setupMaterials();
   
  
}
  
  
private function setupMaterials():void
  {
   Material 
= new ColorMaterial0xffffff );
   
Material.lightPicker lightPicker;
   
  
}
  
  
private function onStageResize(event Event) : void
  
//trigger if stage is resized ie window is resized
  
{
   
   
//This is fine here:
   
view.width stage.stageWidth;
   
view.height stage.stageHeight;
   
//view.width = 300;
   //view.height = 300;
  
}

  
  
  
private function onEnterFrame(ev Event) : void
  {
   
   cube
.rotationY += 1;
   
view.render();
  
}
 }

 

   

Richard Olsson, Administrator
Posted: 26 July 2012 08:54 AM   Total Posts: 1192   [ # 1 ]

I am unable to reproduce this issue. What version are you using?

Can you try setting the antiAlias property to one of the allowed values, i.e. 2, 4 or 16 (according to the AS3 documentation.) The value 10 is probably rounded down to 4 by Flash Player.

 

   

Mr Margaret Scratcher, Sr. Member
Posted: 26 July 2012 12:51 PM   Total Posts: 344   [ # 2 ]

Odd… Just tried antialias = 16, and same result.

I’m using the latest version of away3d, pulled last night via gihub..

Like I say, the odd thing about the example I posted is that when the view is resized by the stageResize listener, it stays anti aliased..

To rule out something that’s maybe odd with my flashplayer, can you confirm that this is not anti aliased?

http://www.margaretscratcher.co.uk/projects/3DkitchenPlanner/ALIAS/index.html

Many thanks!

 

   

Richard Olsson, Administrator
Posted: 26 July 2012 02:00 PM   Total Posts: 1192   [ # 3 ]

That’s anti-aliased for me, both before and after resizing the window. Maybe you can upload a screenshot of what you’re seeing?

 

   

Ivan Moreno, Newbie
Posted: 26 July 2012 02:27 PM   Total Posts: 22   [ # 4 ]

Hello,

If I understood correctly, I ran into the same issue a while ago and apparently is not related with Away3D or the resize event of the Flash Player (No idea why this is happening). The way how I solve it was by adding the different type of antialiasing of the viewport in the update method, it didn’t reduce the performance apparently, at least in my project. So you can give the value of 0, 2 or 4 (visually there is no reason to give higher values of smoothness) like you are doing it in your code, but in the onEnterFrame method. Then you can add Viewport quality buttons and give the ability to the user to change the rendering antialiasing depending on the performance experienced.

Best.

 

   

Mr Margaret Scratcher, Sr. Member
Posted: 26 July 2012 02:57 PM   Total Posts: 344   [ # 5 ]

Here we go then, pic attached.

Oddly enough, if I then resize the browser window which of course triggers the eventlistener, the view is resized to fill the stage, and anti-alias is working…

How odd!

 

   

Mr Margaret Scratcher, Sr. Member
Posted: 26 July 2012 03:03 PM   Total Posts: 344   [ # 6 ]

@Ivan I tried this in onEnterFrame:

view.antiAlias 12;
   
view.render(); 

same result.

I also tried resizing the view within onEnterFrame too, and had the same result.


I’m baffled as to why resizing the view works from within one function but doing it from anywhere else causes anti alising to stop…

Especially as it seem that Richard can see my swf with anti aliasing on initially..

 

   

Mr Margaret Scratcher, Sr. Member
Posted: 26 July 2012 03:16 PM   Total Posts: 344   [ # 7 ]

Okay, so after making a listener to listen for a click on the stage and resize, which worked fine, and then making a copy of that function

private function resizeView() : void
  {
   
   view
.width 300;
   
view.height 300;
  

and triggering that on enterframe:

private function onEnterFrame(ev Event) : void
  {
   
   cube
.rotationY += 1;
   
   
   
view.render();
   
resizeView();
   
  

 

and once more getting a nice new small, but anti- aliased view, I was stumped. So I then just tried

private function onEnterFrame(ev Event) : void
  {
   
   cube
.rotationY += 1;
   
   
   
view.render();
   
//resizeView();
view.width 300;
   
view.height 300;
   
  

and again, results as I expected.

Weird…

Then, I tried resizing before rendering:

private function onEnterFrame(ev Event) : void
  {
   
   cube
.rotationY += 1;
   
   
view.width 300;
   
view.height 300;
   
view.render();
   
//resizeView();
   
  

and this resulted in the non anti-aliased view I was getting before. So I guess so long as I add the ‘onEnterFrame’ listener, before I try to resize the view, I should be alright.

Hopefully this will be of some use to anyone else who might face the same problem smile

 

   

Mr Margaret Scratcher, Sr. Member
Posted: 26 July 2012 03:23 PM   Total Posts: 344   [ # 8 ]

Hmmm, nope -

addEventListener(Event.ENTER_FRAMEonEnterFrame);
   
   
view.width 300;
   
view.height 300

results in the same aliased view - I would have assumed that by doing it this way the view would have been rendered before being resized, but maybe not…


I’m using
away3d-core-fp11_4_0_7_gold
and firefox with Flashplayer 11,3,300,265 installed. Win 7

 

   

Mr Margaret Scratcher, Sr. Member
Posted: 26 July 2012 03:46 PM   Total Posts: 344   [ # 9 ]

So, with my initial project (Rather than the BasicAway testbed), the only way I can get it to work is if I have:

if (need3Dupdate)
   
{
   view
.render();
   
view.width currentPane.extra.viewWidth;
   
view.height currentPane.extra.viewHeight;
   

in my onEnterFrame, which I don’t really want to do every frame. Or if I do not set the view size initially, but do

view.width = currentPane.extra.viewWidth;
  view.height = currentPane.extra.viewHeight;

when I switch between panes it is fine, but then obviously leave me with the view initially taking up the whole stage.

So it seems the issue is with resizing the view before it has been rendered.

For now I guess I’ve made a workaround for it, by making a boolean variable called needsResize, set to true, and have

if (needsResize)
{
view.width = currentPane.extra.viewWidth;
  view.height = currentPane.extra.viewHeight;
needsResize = false;
}

in my onEnterFrame function, although it’s still an extra check on each frame, but that seems better than trying to resize the view on each frame…

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X