Papervision3D + Box2D

PaperBox2D image

In a recent project I wanted to incorporate some physics with a 3D environment. I decided on Box2DFlash (a port of Box2D), which is a great engine even if the syntax is a little awkward for an Actionscript 3 library.

See the PaperBox2D demo, and the source is available (or right-click on the demo). Hit the ‘d’ button during the simulation to toggle the debug regions for the 2d calculations and see how they are mapped to the objects in 3d space.


Updated 11.20.08, recent api changes in Box2DFlash.


Larry Lague has done a port of this demo using Away3D. Very nice!

Posted on October 21, 2008

Tags: , ,

Hey Man !! great work !! can you help me ?
Im wondering why im getting an error :

1046: Type was not found or was not a compile-time constant: Body.

Comment by Eduardo Maluf de Campos — December 2, 2008 @ 12:31 pm

Hi Eduardo,
You probably meant to reference ‘b2Body’. Box2D is a little funny like that when it comes to naming things.

Comment by billy — December 4, 2008 @ 2:50 pm

HI, nice work! But I cannot compile your code, although I have all packages:

1061: call of not defined methode GetSprite ..

1061: .. Methode SetDrawScale ..

1061: .. Methode SetFillAlpha ..

1061:..Methode SetLineThickness ..

1061: .. Methode SetSprite ..
Iam a beginner, thast why it is a bad question.

Comment by Stas — January 6, 2009 @ 10:33 am

Hello Stas,
I just upgraded to the latest sources and everything still seems to be in working order (that’s good!) — PV3D build 856 and Box2DFlash build 28.
From your errors I’d double check and make sure you’ve imported the Box2D debug draw:
import Box2D.Dynamics.b2DebugDraw;

Hope that helps!

Comment by billy — January 6, 2009 @ 6:57 pm

Thank You!
It was the old build of Box2DFlash.

Comment by Stas — January 7, 2009 @ 10:31 am

Hello dear it is very nice work

but i’m sorry to tell that i could not find
the PV3D build 856 and Box2DFlash build 28

would you please upload them so we can download from your site… :)

Comment by davecon — January 19, 2009 @ 1:37 pm

@davecon, Those build numbers refer to revisions in the SVN. I just tested against the latest (as of this writing — PV3D: 865, Box2D: 30), and everything still works. Though you may receive some warning messages about a lack of type declarations in the Box2D source.
I include the build versions as a reference in case something breaks, that way I can roll back to a previous revision and see what went wrong. Consult the documentation on your SVN client of choice on how to use these features.

Comment by billy — January 19, 2009 @ 4:41 pm

Thank you Billy

Comment by davecon — January 20, 2009 @ 10:52 am

[…] The physics is handled using Box2D and if anyone is curious, I’ve posted a little demo with source that shows an example of using it with PV3D. PaperBox2D: http://www.lamberta.org/blog/paperbox2d/ […]

Pingback by Daniel Skrok « Daily Papervision3d — January 23, 2009 @ 12:03 am

Great work, im trying to explore your example but i am getting a 1046 error with Pv3dArrayEvent line 112 how can i fix this

Comment by Dean — January 27, 2009 @ 1:21 am

Unfortunately it seems the latest changes to the Box2dFlash API (build 33) have broken a few things. I will go in when I have some time and try to update everything to the latest revision, or if someone else wants to send me a fix — that’d be great!
It has been my experience working with the Box2dFlash library that they will make some rather drastic changes with the incremental builds in the SVN. If you are going to use it for a project I’d suggest locking in your version and refrain from updating too much or you’ll have to hunt down api changes. But I guess that’s life on the cutting edge eh?

Edit:
Without digging too deep into the new Box2dFlash changes, I’ve gotten the following to work — 
In Box2dScene.as, line 144, change to
world.Step(timestep, iterations, iterations);
then just comment out line 180,
//md.timeStep = timestep;

Comment by billy — January 28, 2009 @ 10:56 pm

Leave a comment