« Papervision3D- Materials Demo
Success! Animated Blender Models in PV3D »

Animated Models: Blender to PV3D

June 30th, 2008 . Posted by brad in Blender, Cast3D, Papervision3D

Some thoughts on the Blender/Papervision3d workflow, collada and Cast3d.

Blender’s collada (.dae) exporter does a great job of exporting mesh data for static models, but it stops playing nicely with PV3D as soon as you export keyframed animation or bone data. The great news is that Tim Knip, the man behind PV3D’s dae parser, is planning to add a blender flag to the parser, to remedy this.

Another great open-source 3d library for bringing animated models into PV3D, is Cast3D which has features like support for sound, animation controls & more. Brilliant!

Cast3d has it’s own lightweight xml format (.x3c) with a command line converter which builds .x3c files from studio max files (.3ds) . Again, blenders exporters prove a little buggy as the blender script exports 3ds files without the node info required by the cast3d converter.

Fortunately, Cast3D’s creator, Dmitri Sviridov, is working on a .dae to .x3c converter which he tells me will also work with blender .dae files! It’s well worth checking the cast3d site to check out it’s great animation support, but here’s a simple unanimated example for cast3d/pv3d 2.0.

(Since I can’t export models from blender to a usable .3ds, I downloaded a cool little model from Turbosquid for this post.)

Setting up Cast3D for Papervision 3d 2.0:

Cast3d is designed for use with a number of 3d engines so you may need to make some very minor tweaks to get it working with PV3D v2.0.

1) Open cast3d/core/Source3d.as

  • a) Uncomment import cast3d.geom.ppv2.*;
  • b) Make sure import statements for other 3d engines are commented out

2) Open cast3d/loader/Xc3loader.as:

  • a) Uncomment import cast3d.loader.ppv2.Xc3PortLoader;
  • b) Make sure import statements for other 3d engines are commented out

3) It should be working fine after the previous changes, but if not, try removing the Sandy3d, Away3d and older papervision folders:

  • a) In the cast3d/geom folder, removed away3d, ppv3d and sandy3d folders
  • b) In cast3d/loader folder, remove ppv3d and sandy3d folders.

Preparing Your Model:
You’ll need to use the command line converter to create .x3c file from the .3ds file. Launch command line prompt, navigate to the directory with the .3ds file and use the converter as follows.

C:\Buggy\3ds2XML buggy.3ds buggy.x3c

Now you’re ready to write some code.

Create a cast3d object:

var animator:Cast3d = new Cast3d(scene, camera);

Create an X3CLoader to load model:

var loader:X3CLoader = new Xc3Loader("models/buggy/buggy.x3c");

loader.resourcePath = "models/buggy/data";

loader.addEventListener(LoadEvent.LOAD_COMPLETE, cast3dLoadComplete);

loader.addEventListener(LoadEvent.LOAD_ERROR, cast3dLoadError);

loader.load(animator.source);

Create a Trackball Object to allow rotation of the model. (This class also ensures the camera always points at your model)

var manipulator:Trackball = new TrackBall(animator, stage,

view.viewportWidth, view.viewportHeight,

Manipulator.Z_UP,

Manipulator.X_S,Manipulator.Z_S,Manipulator.Y_S

);

Last you need to perform a cast3d render before rendering your PV3D scene.

animator.render();

render.renderScene(scene, camera, view);

And the result.

Buggy Render

Nice!

Source
Complete project (fla, swf, source and model).

Links:
http://cast3d.org



7 Responses to “Animated Models: Blender to PV3D”

  • Posted: mirc on July 13th, 2008 at 7:02 am .

    Hello!

    Thank you.

  • Posted: brad on July 13th, 2008 at 6:30 pm .

    Hey Mirc. If you’re interested, the dae converter is now available for download from the cast3d site.

    Haven’t had a chance to play with it myself just yet as it was only released this weekend, but this tool is great news for Blender users.

  • Posted: Matt on July 30th, 2008 at 4:49 pm .

    Hi

    Thanks very much for the tut. I have checked out the source files but seem to be getting an error:
    TrackBall.as, Line 210 : 1137:Incorrect number of arguments. Expected no more than 2.

    this is got me completely stumped as I have all the files in the right directories?!

  • Posted: brad on July 30th, 2008 at 5:34 pm .

    Hi Matt,

    Seems the problem is related to the very recent removal of one of PV3D’s camera methods - camera.lookAt(myTarget). This method which pointed the camera at a target, has been replaced with camera.target=myTarget.

    If you are using subversion, you could simply roll back to a slightly earlier version of PV3D 2.0 to compile the example. The new camera changes where only introduced a couple weeks back, so you wouldn’t need to roll back far. I used revision 628 to compile the posted example.

    Alternatively you could mail cast3d creator, Dmitri, and ask him nicely to update the cast3d source. :-)

    Good luck,
    Brad.

  • Posted: Matt on July 31st, 2008 at 9:44 pm .

    Hi Brad,

    Thanks for the quick heads up, will try that out,

    thanks

  • Posted: Roger Santos on September 3rd, 2008 at 5:13 am .

    really good man, so nice and easy to;

  • Posted: brad on September 5th, 2008 at 9:45 am .

    Hey Roger,

    Dmitri has made some great improvements to the cast3d library as well as fixing quite a few bugs in the blender collada exporter.

    You can see an example of a skinned/animated model, playing very nicely inside PV3d, thanks to cast3d, at
    http://cast3d.org/demos:lwalkfig


Add Comment

Comment