[Papervision3D] ViewportLayer index sorting problems example (I think ; ).

John Brookes jbpv3d at googlemail.com
Fri Oct 3 06:00:07 PDT 2008


As I understand it, if you specify a single object then the index sort works
fine.(Example1)

Problem is when you specify a DO3D that has children, even though your index
sorting the DO3D
it's children remain Z sorted.(Example2)

Have I got this right!

package
{
    import flash.display.Sprite;
    import flash.events.*;
    import org.papervision3d.objects.DisplayObject3D;

    import org.papervision3d.lights.PointLight3D;
    import org.papervision3d.objects.primitives.*;
    import org.papervision3d.view.BasicView;
    import org.papervision3d.cameras.Camera3D;
    import org.papervision3d.materials.*;
    import org.papervision3d.materials.utils.MaterialsList;
    import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
    import org.papervision3d.view.layer.ViewportLayer;
    import org.papervision3d.view.layer.util.ViewportLayerSortMode;

    /**
     * ...
     * @author me
     */
    public class displaylistEG extends BasicView
    {
        private var PlanesContainer:DisplayObject3D
        private var AquaRedContainer:DisplayObject3D
        private var SilverPlane:Plane
        private var lastMouseX:int;
        private var lastMouseY:int;
        private var doMove:Boolean = false;

        public function displaylistEG():void
        {
            super(400, 300, true, true, "TARGET");
            stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
            stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
            setScene();
            //singleRender();
            startRendering();
        }

        private function setScene():void
        {
            // position the camera
            camera.z = -20000;
            camera.focus = 31;
            camera.zoom = 300;

            var Light:PointLight3D = new PointLight3D();
            Light.x = 500;
            Light.y = 600;
            Light.z = -1000;
            scene.addChild(Light);

            var Plum:uint = 0x880080;
            var Aquamarine:uint = 0x77ffd4;
            var Red:uint = 0xFF0000;
            var Tan:uint = 0xD2B48C;
            var Silver:uint = 0xC0C0C0;

            //the display list is
            // scene
                // PlanesContainer
                    // PlumPlane
                    // Plane container
                        // AquamarinePlane
                        // RedPlane
                    // TanPlane
                    // SilverPlane

            PlanesContainer = new DisplayObject3D();
            scene.addChild(PlanesContainer);
            PlanesContainer.y = -200;

            //Plum Plane
            var PlumPlaneMat:ColorMaterial = new ColorMaterial(Plum);
            var PlumPlane:Plane = new Plane(PlumPlaneMat);
            //PlumPlane.z = -800;
            PlanesContainer.addChild(PlumPlane);

            AquaRedContainer = new DisplayObject3D;
            PlanesContainer.addChild(AquaRedContainer);

            //Aquamarine Plane
            var AquamarinePlaneMat:ColorMaterial = new
ColorMaterial(Aquamarine);
            var AquamarinePlane:Plane = new Plane(AquamarinePlaneMat);
            AquamarinePlane.x = -75;
            AquamarinePlane.y = 75
            //AquamarinePlane.z = -500;
            AquaRedContainer.addChild(AquamarinePlane);

            //Red Plane
            var RedPlaneMat:ColorMaterial = new ColorMaterial(Red);
            var RedPlane:Plane = new Plane(RedPlaneMat);
            RedPlane.x = -150;
            RedPlane.y = 150;
            //RedPlane.z = -600;
            AquaRedContainer.addChild(RedPlane);

            //Tan Plane
            var TanPlaneMat:ColorMaterial = new ColorMaterial(Tan);
            var TanPlane:Plane = new Plane(TanPlaneMat);
            TanPlane.x = -225;
            TanPlane.y = 225
            //SilverPlane.z = -500;
            PlanesContainer.addChild(TanPlane);

            //Silver Plane
            var SilverPlaneMat:ColorMaterial = new ColorMaterial(Silver);
            SilverPlane = new Plane(SilverPlaneMat);
            SilverPlane.x = -300;
            SilverPlane.y = 300
            //SilverPlane.z = -500;
            PlanesContainer.addChild(SilverPlane);

            var parentLayer:ViewportLayer = new ViewportLayer(viewport,
null);
            viewport.containerSprite.addLayer(parentLayer);
            parentLayer.sortMode = ViewportLayerSortMode.INDEX_SORT;

            // Try one of these blocks to see difference

            //This gets each plane and ignores the do3d (AquaRedContainer)
            // Example1
            parentLayer.getChildLayer(PlumPlane, true).layerIndex = 1;
            parentLayer.getChildLayer(AquamarinePlane, true).layerIndex = 2;

            parentLayer.getChildLayer(RedPlane, true).layerIndex = 3;
            parentLayer.getChildLayer(TanPlane, true).layerIndex = 4
            parentLayer.getChildLayer(SilverPlane, true).layerIndex =
5;//closest to camera front.

            /*
            // problem example this uses do3d( AquaRedContainer ) with
children Red Aqua
            // The problem is the red plane and aqua plane contained in that
container remain Z sorted
            //Example2
            parentLayer.getChildLayer(PlumPlane, true).layerIndex = 1;
            parentLayer.getChildLayer(AquaRedContainer,
true,true).layerIndex = 2; //  arrrrg
            parentLayer.getChildLayer(TanPlane, true).layerIndex = 4
            parentLayer.getChildLayer(SilverPlane, true).layerIndex = 5;
             */
        }

        private function onMouseDown(event:MouseEvent):void {
            doMove = true;
            lastMouseX = event.stageX;
            lastMouseY = event.stageY;
            startRendering();
        }

        private function onMouseUp(event:MouseEvent):void
        {
            doMove = false;
            stopRendering();
        }

        override protected function onRenderTick(event:Event = null):void
        {
            if (doMove)
            {
                AquaRedContainer.yaw((lastMouseX - mouseX) / 30);
                //trace();
            }
            super.onRenderTick(event);
        }
    }

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://osflash.org/pipermail/papervision3d_osflash.org/attachments/20081003/626c2680/attachment-0001.html 


More information about the Papervision3D mailing list