ViewportLayers – in depth

4 02 2009

This article has been moved to:

Make sure to visit this new blog for great articles and tutorials regarding PV3D and other flash related subjects.





24 responses

4 02 2009

Best article about ViewportLayers since the Zupko one :) Thanks!

On a side note, if you want to get buttonMode on all your objects, the easiest way to do it is setting viewport.buttonMode to true, so you don’t have to do it for every ViewportLayer.
However, I don’t recommend doing it that way cause at some time, you may decide some DO3D shouldn’t have buttonMode and you can’t do it anymore because when viewport.buttonMode is true, setting buttonMode on a ViewportLayer doesn’t change anything.

4 02 2009

Thanx, good stuff

Have problems with this atm so will try it out :)

4 02 2009

Thanx for this, I have no clue with papervision (yet) and your posts helps a lot with certain things.

4 02 2009

Thank you all! I really have enjoyed starting up this even more than I thought I would. It’s quite busy at work at the moment but as soon as it settles I will try t continue on the game.

4 02 2009
Marc Pelland

Awesome ! been wanting to either write something or find something in depth on viewports

5 02 2009

just one question here. When I do this tutorial it all works great. I get an error with this bit though.

viewport.containerSprite.sortMode = ViewportLayerSortMode.INDEX_SORT;

it gives me this error.

H:\…\ col: 40 Error: Access of undefined property ViewportLayerSortMode.

I figured it must be something that I didn’t import bit I don’t really know what the problem is.

5 02 2009

franco: yes, you need to import:
import org.papervision3d.view.layer.util.ViewportLayerSortMode;
to be able to get those constants. I missed that part as I mostly work with autogenerating imports.

8 05 2009

Thanks man!
I was wondering about that 2

5 02 2009

thank you.

5 02 2009

Thanks for this great article, it’s very useful !
But I have a little problem when I try ti use DO3D.useOwnContainer and DO3D.filters.
I have a Sphere and I move this Sphere behind a Cube, but when this Sphere has filters, the layer with filters is display in front of the Cube.

You can see my problem here :

This problem is maybe due to z-sorting…
Any ideas how to fix this problem?

5 03 2009

I just wanted to drop a comment to appreciate your article
It helped me a lot to understand ViewportLayer
Most of the PV3D blogs have many cool examples, but not many blogs for basic concept.
This is definitely one of them and I will keep it in my list.
I tried to vote on the forum, but it seems that the server has some issue.
I will try later. Thanks.

15 03 2009
Philippe Roy

Very clear & useful explanation,
thanks a lot !

17 04 2009

I was trying to sort a DAE and a DisplayObject3D following this tutorial but I couldn’t…. These two display object don’t respect the layer structure. Is there any way to do this….

Thank you….

28 04 2009

Thank for this all precision about this obscure class. But i’ve just one question about the useOwnContainer method.

I have something like this. i hope is clear…

— using useOwnContainer to apply a GlowEffect

And all it’s fine.

But when i try somenthing like this

— using useOwnContainer for alpha and blur
— using useOwnContainer to apply a GlowEffect

Alpha and blur are applied to the DO3D but the GlowEffect on sphere disapear.

it’s seams to be impossible to use useOwnContainer = true inside an useOwnContainer ?

28 04 2009

Sorry something wrong with the format in my last post

I have something like this. i hope is clear…

|-sphere <— using useOwnContainer to apply a GlowEffect
|- plane <– nothing applied

And all it’s fine.

But when i try somenthing like this

DO3D <— using useOwnContainer for alpha and blur
|-sphere <— using useOwnContainer to apply a GlowEffect
|- plane <– nothing applied

Alpha and blur are applied to the DO3D but the GlowEffect on sphere disapear.

it’s seams to be impossible to use useOwnContainer = true inside an useOwnContainer ?

20 05 2009

I made a ring using’s script and it rotates around a sphere, each object has a filter glow added to them. when using useOwnCanvas on both objects, the planet always sits on top, when i use viewportLayer, it fixes the problem but i’d lose the filter glow, do u have an idea of what to do? please help, thank.

31 05 2009

Another great article!
I was trying to figure out how you manage the layers in your game. You have a static class with static constants? How do you initiate the layers?

24 07 2009

Never understood the viewportLayer thing that well, untill i read this blog!
Thank you very much for the explanation.

28 07 2009

Wow, you helped me a lot!

3 08 2009
Pedro Paulo Almeida


I´ve followed yor great tutorial and everything was ok. So I decide make use of the same thecnique in my simple “memory card” game.

So I have two display objects3D: “floor” and “cardsHolder”. The cardsHolder do3D is builded with 15 cubes inside of it. And this is the unique difference between “wall” and “floor”. But the cardsHolder is always under floor.

This is a link to my example:

Could you help me on this?
Thanks in advice!

pedro paulo almeida

13 08 2009

You might want to mention that when you move more complicated objects into layers such as .DAE objects, that there is a 2nd parameter in ViewportLayer.addDisplayObject3D(obj, recurse : Boolean) which also adds all children of the DisplayObject being added. Default it’s set to false, which is why at first your tutorial appeared not to work for me.. (DAE objects have the actual triangles etc. hidden in children).

Btw, the index sorting doesn’t work for me. It always draws them in the same order regardless of what I do to the indices.. But it’ll probably turn out to be something silly (as usual)….

13 08 2009

Oh and make sure you wait until your .DAE is fully loaded before putting everything in ViewportLayers … ! (this took me a while to figure out)

14 01 2010

I am trying to get this to work for my dae models. I have 3 flat layers being stacked on top of one another and they are not showing up correctly. Here is a code snippet:
var view:BasicView=new BasicView(stage.stageWidth,stage.stageHeight,false,false,CameraType.FREE);

// this time, let’s use the viewport to create layers, through objects.
// true means that if ‘sphere’ does not belong to a layer, create one for it and put it there.
var grassLayer:ViewportLayer = view.viewport.getChildLayer(daeGrass, true);
var cementLayer:ViewportLayer = view.viewport.getChildLayer(daeCement, true);
var asphaltLayer:ViewportLayer = view.viewport.getChildLayer(daeAsphalt, true);
view.viewport.containerSprite.sortMode = ViewportLayerSortMode.INDEX_SORT;

// set the sort index of the new layer
grassLayer.layerIndex = 1
cementLayer.layerIndex = 2
asphaltLayer.layerIndex = 3

// add our objects to the new layers
grassLayer.addDisplayObject3D(daeGrass, true)
cementLayer.addDisplayObject3D(daeCement, true)
asphaltLayer.addDisplayObject3D(daeAsphalt, true)

Any Ideas what could be wrong??

16 03 2010


How can I use viewportlayers with Augmented reality and DAE files? I can get it work.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: