Billboarding in Papervision3D 2.0 using DisplayObject2D

As mentioned on the about page Tweetpond displays tweet content using standard Flash TextFields that are rendered as part of the 3D scene. This is often called billboarding or point sprites.

Tweetpond DisplayObject2D

Our DisplayObject2D implementation is based on the following sources:

  1. DisplayObject2D by Blitz Agency
  2. Revision for Papervision3D 2.0 by Sleepy Design.

Our implementation solves the Z-ordering issues reported when using DisplayObject2D with Papervision3D 2.0.

We recently received a request to share our version with the community so here you go! You can download the ActionScript3 class files below:

This code is released under the MIT licence, same as Papervision3D. To get an idea on how to use this class please see this post by Blitz Agency and source comments.

Please feel free to share your project that makes use of DisplayObject2D below!

This entry was posted in Technology and tagged , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

12 Comments

  1. Posted 16 Sep 2009 at 8:08 pm | Permalink

    A reader recently asked for some examples on how to use the DisplayObject2D class so I’ve attached some example code below to illustrate.

    The magic is in having everything on their own individual layers that Papervision3D can the z-order correctly. I also highly recommend installing http://www.monsterdebugger.com/ so you can see what’s happening in your application in real time. Good luck!


    var parentLayer:ViewportLayer;
    var vpl:ViewportLayer;
     
    // create an empty parent viewport layer and add it to the container
    parentLayer = new ViewportLayer(viewport, null);
    viewport.containerSprite.addLayer(parentLayer);
     
    // create shape
    var shape = new Sphere(material, SIZE);
     
    // create layer and add to scene
    shape.useOwnContainer = true;
    vpl = parentLayer.getChildLayer(shape, true);
    scene.addChild(shape);
     
    // create text box (movieclip)
    var box = new Box();
    //...set box properties here...
     
    // create do2d that encapsulates the movieclip
    var label = new DisplayObject2D(box as DisplayObject, parentLayer, 0, null, SIZE*1.25, 0);
     
    // create layer and add to scene
    label.useOwnContainer = true;
    vpl = parentLayer.getChildLayer(label, true);
    scene.addChild(label);

  2. Fernando
    Posted 07 Dec 2009 at 6:47 pm | Permalink

    Hello from Spain,

    “A reader recently asked for some examples on how to use the DisplayObject2D class so I’ve attached some example code below to illustrate.”

    I started to program in papervision recently not for profesional job. I readed your post.

    ¿Could you give me an code source example for a movieclip like ‘circle’?

    Thank for all,

  3. Posted 09 Dec 2009 at 7:34 am | Permalink

    Hi Fernando, sounds like you’re trying to run the original example from Blitz Agency.

    “Circle” is not defined in ActionScript at all, it is a movieclip you can find in the Library of the DisplayObject2DTest.fla project:

    DisplayObject2d Library: Circle

    You will also notice under the “linkage” column how this movieclip has been exported to ActionScript as class “Circle”. In the Library, right click on the Circle and select Properties to view and change symbol properties.

    Hope this helps.

    Cheers, Jussi

  4. Posted 07 Mar 2010 at 4:09 am | Permalink

    Hi… I´m trying yor classes and at this moment I can see various displayObject3d and a displayObject2d on the stage. This displayObject2d is a child of one of those displayObject3d. I want both to rotate at the same time but when I rotate the displayObject3d the displayObject2d doesn`t change its rotation.

    By the way, Tweetpond is great.

    Thank you.

  5. Posted 11 Mar 2010 at 10:38 am | Permalink

    Hi Iker,

    I assume you’re trying to rotate the DisplayObject2D around its Z-axis, similar to what changing the standard Flash rotation property would do (i.e. “obj._rotation = angle”)?

    I don’t think this will work, as the whole idea behind billboarding is that the DisplayObject2D is always facing the same way on the two-dimensional plane (your screen).

    If you’re looking for something that ‘participates’ more fully in the 3D world, including rotations around X, Y and Z axes, perhaps you can look into org.papervision3d.objects.Plane class (with a suitable material such as bitmap).

    Hope this helps.

    Cheers, Jussi

  6. Posted 26 May 2010 at 12:33 pm | Permalink

    Your do2d is great to me, and I have encountered an issue that I am unable to make the z-sorting work correctly when my do2ds on the stage with other collada objects.
    It seems it always in front of other 3d models:
    http://www.busysuzie.com/testing/#/opening

    I wonder if my code add the do2d wrongly:
    —————————————————————————
    var parentLayer:ViewportLayer;
    parentLayer = new ViewportLayer(viewport, null);
    viewport.containerSprite.addLayer(parentLayer);

    //create table models and loaded successfully
    .
    .
    //
    tables.useOwnContainer = true;
    parentLayer.getChildLayer(tables, true);
    scene.addChild(tables);

    //create middle column models and loaded successfully
    .
    .
    //
    middleColumn.useOwnContainer = true;
    parentLayer.getChildLayer(middleColumn, true);
    scene.addChild(middleColumn);

    //loop for creating paddle and character on a do3d and add do3d to scene
    for(var i:int = 0; i<6; i++)
    {
    personHolderArr[i] = new DisplayObject3D();

    //create paddle and loaded successfully
    .
    .
    //
    paddleArr[i].useOwnContainer = true;
    parentLayer.getChildLayer(paddleArr[i], true);
    personHolderArr[i].addChild(paddleArr[i]);

    var do2D:DisplayObject2D = new DisplayObject2D(new Character() as DisplayObject, parentLayer, 180);
    personHolderArr[i].addChild(do2D);

    scene.addChild(personHolderArr[i]);
    }
    —————————————————————————
    I suppose it is due to layering, but I cannot figure out where I code it wrongly.
    I would be very appreciated if you can inspire me for any solution. Thanks

  7. Posted 26 May 2010 at 3:41 pm | Permalink

    Hi Gordon,

    this is a bit of a stab in the dark but looking at these lines:

    personHolderArr[i].addChild(paddleArr[i]);

    personHolderArr[i].addChild(do2D);

    I am wondering if you should add the paddles and characters directly to the scene by calling scene.addChild(paddleArr[i]) and scene.addChild(do2D) instead?

    Just an idea, let me know how you go.

    Cheers, Jussi

  8. Posted 26 May 2010 at 6:54 pm | Permalink

    Thanks for your rapid respond, the DO2D and paddle is put to a DO3D with purpose, so that I can assign that DO3D always face to the camera instead of assigning them individually.

    I just wonder if the issue is related to the:
    viewport.containerSprite.addLayer(parentLayer);

    And I tried to change the sortMode of viewportlayer to index_sort, z_sort, nothing help /~\

    This is the simplified file package, hope you may interest and see if there is any solution:
    http://snap-f.net/do2D_z_Issue.zip

  9. Posted 27 May 2010 at 10:56 am | Permalink

    Hi Gordon,

    I won’t be able to have a detailed look at your code, however I did notice that you’ve commented out the following:

    //paddleArr[i].useOwnContainer = true;
    //parentLayer.getChildLayer(paddleArr[i], true);

    //do2D.useOwnContainer = true;
    //parentLayer.getChildLayer(do2D, true);

    From memory, correct z-sorting using these classes depends on the fact that all child objects have their own individual layer – hence the explicit ‘true’ for the createNew parameter in the method call.

    I’d recommend you try these classes out in a clean Flash project first and make sure DO2D’s behave correctly in terms of z-ordering. Then drop in some DO3D’s and confirm that objects are still sorted properly. Once this works you can then apply same logic to your actual project.

    Also make sure you have a debugger on hand to be able to see inside your project at runtime. It’s really helpful to see object properites, how they nest etc.

    Cheers, Jussi

  10. Posted 27 May 2010 at 1:16 pm | Permalink

    I finally figure that, sadly not a solution yet, dae model is always behind the do2d…
    I use your sample code and add one more dae model, no matter how I change the z, the dae model is covered by the box and do2d~

  11. Posted 27 May 2010 at 1:19 pm | Permalink

    Anyway, big thanks to you, Jussi, at least I can put movieclip to the 3d environment in a pretty way. Just keep on digging into collada import procedure to see if there is any hint to solve the issue~ Thank you.

  12. Posted 27 May 2010 at 1:22 pm | Permalink

    No worries at all Gordon, I’m sure you will find a good solution soon. Cheers, Jussi

Post a Comment

Your email is never published nor shared. 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>