How to make DisplayObject3D alpha work in Papervision

7 Comments 8 July 2009

I was recently playing around with Papervision and wanted to create a cube that faded in and out. A pretty simple thing to do, I was even using a Tween engine so it was just a few lines of code. However, the cube would just not fade! After a quick search on Google I found a useful post that quickly explain how to fix this. Basically you need to set the DO3D so it uses it’s own container like this:

DisplayObject3D.useOwnContainer = true;

Simple! But why is this? Being an inquisitive person I wanted to know exactly what was the reason for this and after a quick search into the code I found out why.

Basically, as I’m sure most people are aware, everything you render in Papervision is drawn to a Viewport3D, which extends Sprite and can be added to the display list. In order for you to have an alpha on an individual DisplayObject3D (or anything that extends it like a Sphere or a Cube) you need to give that object it’s own ViewportLayer and then the alpha can be applied to that. This is also useful for putting filters on objects in PaperVision.

Whilst doing this bit of snooping around I thought that a much nicer way of doing this would be to make the alpha variable a private member of the DisplayObject3D class, then create a getter/setter for it. Within the setter we can check to see if useOwnContainer is set to true, if it isn’t, we can do so thus removing the need for the code snippet above. I’ve amended the DisplayObject3D class slightly to incorporate this and you can download it here. Just replace the current in org/papervision3d/objects and away you go.

I’ve also added getters/setters for filters and blendMode which work in the same way.

I hope the above helps people and I really recommend doing your own snooping about in the PaperVision code to get a better understanding of how it all works as this will really help you to work with it.

UPDATE July 8, 2009, 18:33:
Since writing this post I have spoke to Chris O’Byrne about it and he raised some interested points that maybe I overlooked. His main point was that in a way my “fix” obfuscates how Papervision works and that it’s perhaps better to make developers set useOwnContainer themselves so they gather a better understanding of what they are actually doing. I think Chris may have a good point to be honest, although maybe an alert/warning to make beginners with Papervision aware would be a good compromise.

Posted in 3D, ActionScript

7 Responses to How to make DisplayObject3D alpha work in Papervision

  1. Papervision 3d Digital Clock | Flash Monkey

    [...] project I work on I learnt something new with this experiment. You may have read my recent post How to make DisplayObject3D alpha work in Papervision. Basically you have to set the useOwnContainer variable to true, which renders out the object onto [...]

  2. 1 January 2010

    thanks a lot, man!!

  3. 11 August 2010

    unfortunaly it doesnt work for collada files…

  4. 11 November 2010

    Thanks a lot for the help!

  5. 21 December 2010

    thanks. it helped.

  6. 17 January 2011
    Noble Silence

    How is useOwnContainer’s performance compared to using ViewportLayer?

  7. 17 January 2011

    Hi Noble Silence. I’m not sure I understand your question – setting useOwnContainer to true will render that DisplayObject3D’s graphics on a different ViewportLayer (within a new/seperate Sprite) so there isn’t really a performance comparison to be made.

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>