Papervision3D integration in a project MXML

February 16 2008 by Mickael Ruellan

I dwelt on Papervision3D as part of a project and I wanted to test its integration in a project MXML. Unfortunately, I realized that most tutorials on the subject if not all, speak of creating a project in ActionScript 3. So I create classes for the integration of an object papervision3D as MXML tag, allowing for easy inclusion of a 3D scene in a Flex project. I propose you a small example showing the use of these classes within a project MXML.

Example available here with the sources. The explanations are in the following article ... I am inspired by this tutorial on creating a scene and its generic initialization to create a new class PV3DScene.

I added 4 main things:

  • Extending the Canvas class instead of Sprite in AS3 projects
  • The option of not rendering to calculate each frame with the variable needRender and adding a method invalidateScene (which saves a lot of CPU in the case of a static scene!)
  • The scaling of the scene depending on the size of the canvas
  • The creation of objects in the scene using the method as add3DObject and remove3DObject and adding a childrenObjects Array

I then create a class PV3DObject to manage the interactivity type models imported from Collada autres.Le result is the ability to define 3D objects like this:

public class FxCube extends PV3DObject (
public var faceWidth: Number = 500;
public var quality: Number = 20;

FxCube public function () (
super ();
)

override protected function createChildren (): void (
var ml: MaterialsList = new MaterialsList;
var mat: BitmapFileMaterial = new BitmapFileMaterial ( 'fx.jpg');
ml.addMaterial (mat, 'all');
addChild (new Cube (ml, faceWidth, faceWidth, faceWidth, quality));)
)

And additions to the 3D component in an MXML component in this way:

<mx:Panel>
<pv3d:PV3DScene id="scene3D" width="90%" height="90%">
<pv3d:childrenObjects>
<objects:FxCube faceWidth="400" id="cube" />
</ pv3d: childrenObjects>
</ pv3d: PV3DScene>
</ mx: Panel>

The complete sources of the project (including papervision3D) are available here. Namely it is necessary for the compilation of available sources of Papervision.

This is described in this tutorial, but in order to simplify your task, I will include in the project a copy of these sources and it is just necessary to add these sources in the Source Path through the project: Project menu> Properties> Flex Build Path> Source Path Tab> Add Folder ... and select the folder named PV3D_GreatWhite_rev428.

A second example on the use of Collada object format is being prepared. We'll see how to add an object from 3DSMax into papervision and how to interact with the mouse with him.

If you come for the first time on Flex-info.fr, you can subscribe to the RSS feed. Thank you for your visit!

1 étoile2 étoiles3 étoiles4 étoiles5 étoiles (2 votes, 5.00 out of 5)
Loading ... Loading ...

9 Feedback for this article

  1. Julien Says:

    Super article, relevant and clear :)

  2. myrddin Says:

    Yes, very good article indeed!

  3. Albert Says:

    Great article!
    How could I do to import a Collada format object with the class PV3DObject?

    Again thank you for this very good tutorial

  4. florian Says:

    thank you for this picture! :)

  5. news Says:

    thank you for the ticket, it's always interesting to read. I wonder however why this digression: I wanted to test its integration in a project MXML? :)

  6. news Says:

    thank you to you for cett image! : D

  7. Augustine Says:

    I can not find the source file: PV3D_GreatWhite_rev428
    I have a folder com/fr/flexinfo/pv3d /

    but that's all ... I can not, qq'un can help?

    thank you

  8. Emmanuel Says:

    very interesting ticket.

    How can we retrieve an event click on an object.

    ex: I create a new kind of type object map (FxCard) along the lines of the cube.
    I load several objects on the scene how récépérer event click on an object. For example zoom on this object.

  9. Julien Lestel Says:

    Hi Mickael, even the Americans speak of you with this article!

1 Trackbacks This artic

  1. DAY 10: PAPERVISION + Adobe AIR FUN Says:

    [...] To Mickael Ruellan who made the papervision / flex bridge [...]

Write a comment

Subscriptions

  • Add to My AOL
  • Add to Google
  • Add to Zune
  • Add to Netvibes
  • Add to Technorati
  • Add to My Yahoo
  • Add to Zune

Survey

How do you find the new Flex-info.fr?

View Results

Loading ... Loading ...

Mugsho