Fix Z-Sorting issues with the QuadrantRenderEngine

quadrantrenderengine

download-source

Another way to solve your z-sorting issues is the use of the Quadrant Render Engine. The QuadrantRenderEngine only takes one parameter (type).

The three “types” of filtering available to you are:
QuadrantRenderEngine.ALL_FILTERS
QuadrantRenderEngine.CORRECT_Z_FILTER
QuadrantRenderEngine.QUAD_SPLIT_FILTER

For a full explanation of each of the 3 types available to you with this renderer take a look at this article.

The QuadrantRenderEngine use a technique of subdividing the screen into smaller and smaller regions to resolve potential conflicts between triangles.
blog.papervision3d.org

As also noted by others, this is a great tool to have around it does come with its performance issues. You may want to test out using ViewportLayers and optimizing in other areas.

Here is the simple code you need to change your renderer when extending BasicView.as:

renderer = new QuadrantRenderEngine(QuadrantRenderEngine.ALL_FILTERS);

Here is the full code for this example:

package  
{
	import flash.events.Event;
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.objects.primitives.Sphere;
	import org.papervision3d.render.QuadrantRenderEngine;
	import org.papervision3d.view.BasicView;
	import org.papervision3d.materials.BitmapFileMaterial;
 
	public class Main extends BasicView 
	{
		protected var sphere:Sphere
		protected var plane:Plane;
		protected var bitmapMaterial:BitmapFileMaterial;
		protected var colorMaterial:ColorMaterial;
 
		public function Main() 
		{
			super();
 
			//Try commenting out this line to see the issues.
			renderer = new QuadrantRenderEngine(QuadrantRenderEngine.ALL_FILTERS);
 
			createChildren();
			commitProperties();
			startRendering();
		}
		protected function createChildren():void 
		{
 
			//Create a new 3D object
			colorMaterial = new ColorMaterial(0x000000);
			bitmapMaterial = new BitmapFileMaterial("images/ourtex.jpg")
 
			//Create 3D Objects
			plane = new Plane(colorMaterial,1000,1000,5,5)
			sphere = new Sphere(bitmapMaterial, 50, 10,10);
 
 
			//Add to scene
			scene.addChild(plane);
			scene.addChild(sphere);
 
		}
 
		protected function commitProperties():void 
		{
			//Set some properties
			sphere.scale = 4;
			sphere.pitch( -10);
			plane.rotationX = 60;
		}
		override protected function onRenderTick(event:Event = null):void 
		{
			super.onRenderTick(event);
 
			//Rotate
			sphere.yaw(1);
		}
	}
}

download-source

This entry was posted in Actionscript 3.0, AS3, Examples, QuadrantRenderEngine, Tutorials, Z-Sorting Issues and tagged , , , , . Bookmark the permalink.

3 Responses to Fix Z-Sorting issues with the QuadrantRenderEngine

  1. Pingback: Fixing Z-sorting in Papervision 3D at Jozef Chúťka's blog

  2. tresloukadu says:

    the viewportLayer worked better…

  3. Pingback: 3D-Cube Darstellung fehlerhaft mit Papervision - Flashforum

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>