Z sorting problem ?

Software: Away3D 4.x

hiroalex, Newbie
Posted: 30 November 2011 12:50 AM   Total Posts: 15

Hi,

I have a problem of Z sorting I think, and I don’t understand how Away 3D 4 works with it. I have 2 planes that always face the camera. the red plane is closer than the green plane and hence is in front (at least at start). The camera starts to turn on itself, and then at some point the green plane goes front! I don’t understand why, can somebody explain me what happen? As the green plane is further than the red plane, I would assume that it is ALWAYS back, but obviously it is not the case….
Please help !

Here is my sample code :

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"  backgroundAlpha="0"
      
xmlns:s="library://ns.adobe.com/flex/spark" 
      
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
 <
fx:Declarations>
  <!-- 
Place non-visual elements (e.g., servicesvalue objectshere -->
 </
fx:Declarations>
 
 <
fx:Script>
  <!
[CDATA[
   import away3d
.containers.View3D;
   
import away3d.materials.ColorMaterial;
   
import away3d.primitives.Plane;   
     
   private var 
_viewView3D;
   
   public function 
mainLine() 
   
{
    stage
.scaleMode StageScaleMode.NO_SCALE;
    
stage.align StageAlign.TOP_LEFT;    
    
setupView3D();    
   
}
   
   
private function setupView3D() : void {
    _view 
= new View3D();
    
_view.width=1000;
    
_view.height=700;
    
_view.antiAlias 2;
    
_view.backgroundColor 0x333333;
    
    
uiComponent.addChild(_view);
    
    
initPrimitives();
   
}
   
   
public var plane:Plane;
   public var 
plane2:Plane;
   
   private function 
initPrimitives():void
   {
    plane
=new Plane(new ColorMaterial(0xff0000));
    
plane.x=10;
    
plane.z=500;
    
plane.y=10;
    
plane.rotationX=-90;
    
_view.scene.addChild(plane);
    
    
plane2=new Plane(new ColorMaterial(0x00ff00));
    
plane2.x=-10;
    
plane2.z=510;
    
plane2.y=-10;
    
plane2.rotationX=-90;
    
_view.scene.addChild(plane2);
     
    
addEventListener(Event.ENTER_FRAMEhandleEnterFrame);
    
   
}
   
   
private function handleEnterFrame(ev Event) : void 
   {
    _view
.camera.rotationY+=0.2;
    
plane.rotationY=_view.camera.rotationY;
    
plane2.rotationY=_view.camera.rotationY;
    
_view.render();
   
}
   
  ]]
>
 </
fx:Script>
 
 <
mx:UIComponent id="uiComponent" width="100%" height="100%" addedToStage="mainLine()"/>
 
</
s:Application

 

Thank you very much in advance.
Also if somebody could explain how z-sorting works in general in Away3D4, it would be sweet smile

Take care,

Alex

 

   

Avatar
theMightyAtom, Sr. Member
Posted: 30 November 2011 08:00 AM   Total Posts: 669   [ # 1 ]

Hi Alex.
I would expect this to happen, it’s simple geometry. Your planes are always facing the camera, they are spaced 20 units apart. Obviously as you rotate the camera around them, as you go more than 90 degrees the one infront will change, and again at -90 (or 270).

Z-sorting in Away3d 4.0 is handled on GPU and is always 100% accurate in my experience. (it might get confused when you have 2 faces in exactly the same position). Ironically a lot of us miss being able to control z-sorting manually, for just this sort of scenario.

Good Luck!

   

hiroalex, Newbie
Posted: 30 November 2011 05:57 PM   Total Posts: 15   [ # 2 ]

Hi,

Thank you for your answer but I think this behavior is not expected because the camera does NOT turn around the planes but turns on itself. So the distance from the camera to the planes never changes, that is why it is weird!
Any hint about this issue would be very appreciated.
Thank you.

Alex

   

Avatar
theMightyAtom, Sr. Member
Posted: 30 November 2011 06:46 PM   Total Posts: 669   [ # 3 ]

Please post an example smile

   

hiroalex, Newbie
Posted: 30 November 2011 07:05 PM   Total Posts: 15   [ # 4 ]

Argh, I tried but it’s too big…
Anyways, I suppose the problem comes from the fact that the planes are turning on themselves in order to face the camera (which is turning on itself), because if I don’t make them turning, then there is no problem… but this is not what I want…
Thank you for feedback,

Alex

   

John Brookes, Moderator
Posted: 30 November 2011 07:11 PM   Total Posts: 732   [ # 5 ]

hold a sheet of paper in each hand overlapping, with one slightly in front of the other.
Rotate both same direction.
At some point one will appear in front of the other.
Same as your example.

   

hiroalex, Newbie
Posted: 30 November 2011 07:21 PM   Total Posts: 15   [ # 6 ]

Ah…. you are right, it makes sense…
Thank you

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X