سؤال

I am fooling aroung with Papervision3D in as3. I am currently stuck with a BitmapEffectLayer. WHen I want to add an effect to an object, the object with the effects will always be rendered infront of everything. That means, even though its behind another object in the cordinat system, it gets drawn infront of it. Heres some source code, dunno if it helps.

spherer = new Sphere(shadedMaterial, 120, 20, 14);
        //spherer.x = 0;
        //spherer.y = 0;
        //spherer.z = 0;

        displayEarth = new DisplayObject3D();
        displayEarth.x =0;
        displayEarth.y = 0;
        displayEarth.z = 0;
        displayEarth.addChild(spherer);


        smallSphere = new Sphere(flatMaterial, 10, 10, 10);

        smallSphere.x = 0;
        smallSphere.z = 130;
        smallSphere.y = 00;

        displayEarth.addChild(smallSphere);
        //scene.addChild(smallSphere);
        scene.addChild(light);


        var partMaterial:ParticleMaterial = new ParticleMaterial(0x000000, 1.0, ParticleMaterial.SHAPE_CIRCLE);
        var part:Particle = new Particle(partMaterial, 3, 0, -150, 30);
        var part2:Particle = new Particle(partMaterial, 3, 0,0,135);
        var partsHolder:Particles = new Particles();
        partsHolder.addParticle(part);
        parrr.push(part);
        partsHolder.addParticle(part2);
        parrr.push(part2);

        var effectLayer:BitmapEffectLayer = new BitmapEffectLayer(viewport, stage.stageWidth, stage.stageHeight, true, 0x000000, BitmapClearMode.CLEAR_PRE);
        effectLayer.drawLayer.blendMode = BlendMode.OVERLAY;

        effectLayer.addDisplayObject3D(smallSphere);
        viewport.containerSprite.addLayer(effectLayer);

        displayEarth.addChild(partsHolder);

        scene.addChild(displayEarth);
        effectLayer.addEffect(new BitmapLayerEffect(new BlurFilter(2,2,2)));

And now, the "smallSphere" which is attached to the effectLayer, will always be rendered infront of the "sphere". Any help is appreciated! - David

هل كانت مفيدة؟

المحلول

When you set a DisplayObject3D to it's own layer (.useOwnContainer = true; being the simplest option, essentially you get that 3D object rendered into a separate 2D sprite on the 2D typical display list. Using ViewportLayer makes it easier to control this stacking/ordering, so be sure to read through Andy Zupko's detailed post on ViewportLayers. The idea is that if you add 3D objects to 2D render layers, you'll have to deal with sorting. You can for example check the z position of 3D objects and based on that sort the layers if the objects move a lot in 3D. You obviously loose speed when doing this type of operations, so it's best to plan things a bit (e.g. what moves in the scene, what doesn't, what are pros and cons of adding an effect, etc.)

Also it's probably a good idea to bear in mind that the Papervision3D project has not being updated in some time now. It currently only supplies software rendering (with Flash Player 9 and I think partially with Flash Player 10's new drawing API, but probably not in the stable branch). You might want to have a look at Away3D as it's still currently being developed. You can use the Flash Player 10 software rendering API or even the light weight Away3DLite version (which is faster than Papervision3D I think) but there's also the Away3D 4.0 version which uses hardware acceleration.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top