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

John Brookes jbpv3d at googlemail.com
Sat Oct 4 11:54:57 PDT 2008


It is set to true though.

The second block of code in the last example.
parentLayer.getChildLayer(AquaRedContainer, true,true).layerIndex = 2;

If you use the second block of code then that AquaRedContainer is index
sorted but it's children remain Z-sorted.

Same code (see below) only with the second block.

WIth
parentLayer.getChildLayer(AquaRedContainer, true,true).layerIndex = 2;

AquamarinePlane.z = -600;
RedPlane.z = -500;

So you will see aqua red

swap tham round

AquamarinePlane.z = -500;
RedPlane.z = -600;

You see red aqua

hence ;) The children are Z sorted.

And if you do
parentLayer.getChildLayer(DO3D, true,false).layerIndex = 2;
then the DO3D ignores the layerindex sits at the back and still z-sorts its
children.

Basically, don't use
parentLayer.getChildLayer(DO3D, true,false).layerIndex =
On DO3D with children.

Use
parentLayer.getChildLayer(DO3D, true,true).layerIndex =
On DO3D with children.
And remember it's children will be z-sorted.


At least I think that's how it goes ;)



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);
            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;  // you see red aqua
            AquamarinePlane.z = -600;    // you see aqua red
            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;  // you see red aqua
            RedPlane.z = -500;    // you see aqua red
            AquaRedContainer.addChild(RedPlane);

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

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

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

            parentLayer.getChildLayer(PlumPlane, true).layerIndex = 1;
            parentLayer.getChildLayer(AquaRedContainer,
true,true).layerIndex = 2;
            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/20081004/0f4696a4/attachment-0001.html 


More information about the Papervision3D mailing list