nwebb

Flex, Flash, AIR

Archive for the '3D' Category

Exporting a custom Blender object for use in Papervision3D

I hit a few snags with this along the way, so here is a quick overview:
First of all, be aware of the Blender export issue I blogged about here
In order to create a basic object that can be brought in to PV3D and have a texture applied to it, you can do the following:
1) In Blender create a new file – you will see the default Cube
2) Select UV FaceSelect Mode (not sure why, but seems I have to do this on the first time only, else my export doesn’t work properly)
3) Export with “triangles” option selected.

DO NOT delete the camera or light source.
You may need to:
1) Subdivide
2) Convert quads to triangles

4 comments

Papervision3D tutorial

I've been playing around with Papervision3D and Blender over the last couple of days, and I've been having a lot of fun.

Papervision3D test

I thought I'd write a quick overview of the basic process. These are only really liner notes. I may turn them in to a full tutorial at some point, or I may not ... heck, playing with PV3D is much more fun than writing a tutorial ;]

There will be more to come as I play around, finish reading the class docs and generally discover new things. When following the steps below, please bear in mind that PV3D is still in alpha and is subject to change. If you run your app in debug mode you should see log traces which will warn you of deprecated methods etc. These notes assume that you've already downloaded PV3D from the repository and have set it up as a library project in FlexBuilder - see the wiki for more info if you need help on this.

Papervision From Scratch:
1) Create a new sprite and add it to the display list.

Actionscript:
  1. _container = new Sprite();
  2. addChild( _container );

2) Create a new Scene3D and pass in a reference to the sprite (Scene3D lets you create a scene with all objects rendered in the same container)

Actionscript:
  1. _scene3D = new Scene3D( _container );

3) Create a new Camera. There are two possible types. Here we use the Camera3D. 3D cameras simulate still-image, motion picture, or video cameras. When rendering, the scene is drawn as if you were looking through the camera lens.

Actionscript:
  1. _camera = new Camera3D();

4) Add a child to the Scene3D instance which will be our container clip - it will be of type DisplayObject3D - (think of it like like creating a container clip with createEmptyMovieClip())

Actionscript:
  1. _rootNode = _scene3D.addChild( new DisplayObject3D( "_rootNode" ) );

CREATING PLANES (flat rectangle objects for those of you new to 3d!):

You can create a plane and then add it as a child of your root node.Before you do this you will need to create the plane's material or texture (data concerning how objects appear when rendered)

The BitmapMaterial class creates a material/texture from a BitmapData object.
The ColorMaterial class creates a material/colour from a hex value.

1) If creating a bitmapMaterial, create a new BitmapData object first:

Actionscript:
  1. _someTexture = new BitmapData(width, height);

2) Create the material (and here we ensure it can be seen from both sides - either method for this works, e.g. oneSide=false or doubleSided=true):

Actionscript:
  1. //example of BitmapMaterial...
  2. var material1:BitmapMaterial = new BitmapMaterial( _someTexture );
  3. material1.oneSide=false;
  4.  
  5. //example of ColorMaterial...
  6. material = new ColorMaterial(0xFF0000);
  7. material.doubleSided = true;

3) Create a new Plane. This requires you to specify the material. You can also divide the rectangle in to smaller segments. This is usually done to reduce linear mapping artefacts.

Actionscript:
  1. var plane:Plane = new Plane( material, width, height, horzSegments, vertSegments );

4) Now you want to add the Plane as a child of your root node.
Note: All 3D objects contained within a scene are instances of DisplayObject3D - not only those that can be rendered, but also the camera and its target. We give it a String name of "plane3D" - we can then easily retrieve a reference to it, if we need to, using getChildByName()

Actionscript:
  1. var plane3D:DisplayObject3D = _rootNode.addChild( plane, "plane3D" );

5) If required you can also set properties of the plane such as x, y, scale and rotation (See DisplayObject3D class)

Actionscript:
  1. plane3D.rotationY = -90;

CHANGING THE VIEW & RENDERING THE CAMERA:

In order to see your 3D scene you will need to render the camera. This generates an image from the camera's point of view showing the visible models in the scene. If your scene is static, you only need to do this once, but if your scene is animated in any way you will want to do this regularly. As the Flash player only draws to the screen once every frame, an onEnterFrame loop is the obvious choice.
Within this loop you will also want to animate your objects.

Actionscript:
  1. _camera.x += someNumber; //example of moving the camera
  2.  _scene3D.renderCamera(_camera ); //'draw' your scene

17 comments

Papervision (Collada export issue from Blender)

Papervision3D is an open source 3D engine for the Flash platform which uses COLLADA (an open standard XML schema) to describe 3D objects in an exchangeable format.

If you want to model an object and export the corresponding Collada file then you may wish to use Blender, an open source 3D content creation suite created in Python. It can export Collada files as a result of this plugin (which is bundled with Blender 2.43)

I started playing around with Blender yesterday, but to my disappointment I was unable to export my results as a Collada file. The error message seemed simple enough - an incorrect export path specified; However changing the path didn't resolve the issue. I also tried installing the latest version of Python and updating to the latest version of the Collada plugin.

After some hair-pulling I (by which I mean my friend Simon) eventually resolved the issue by rolling back my installed version of Python from 2.5 to 2.4.4. I've contacted Illsoft, the makers of the plugin to let them know, so hopefully they'll have a fix for it soon, but for the timebeing, if you are experiencing this issue, you know what to do.

10 comments

Bad Behavior has blocked 399 access attempts in the last 7 days.