Today I decided to create this simple example that used Papervision and the 3D physics WOW Engine. It is actually quite simple. Basically all that happens is you setup your objects for papervision (5 minutes) - setup your objects for the wow engine (5 mintues) then when you render - you just attach the movements of the WOW objects to your Papervision objects. (5 more minutes or less and you're DONE)
So taking out 3D and Papervision all together here is what is happening. Let's say you setup an enterframe and then assign a movieclips x and y positions to your mouse x and y position. SAME Exact thing happening here. Except you are attaching the x y and z properties of a papervision object to a wow object. Pretty simple! I'll take corrections if I am wrong since I have spent all of 30 minutes playing around with it.
Here is a quick sample of what goes on when rendering:
-
sphere.x = wowSphere.px;
-
sphere.y = -wowSphere.py;
-
sphere.z = wowSphere.pz;
Not too hard right.
Here is the ActionScript code for creating a simple sphere boucing on the stage. Source code is below. (Basically a modified example shown on the WOW site)
Main.as
-
package
-
{
-
import com.cs54.papervision.PV3DSceneWOW;
-
import flash.display.Sprite;
-
-
public class Main extends Sprite
-
{
-
protected var papervisionSceneWOW:PV3DSceneWOW
-
-
public function Main():void
-
{
-
papervisionSceneWOW = new PV3DSceneWOW();
-
papervisionSceneWOW.init(stage.stageWidth, stage.stageHeight)
-
addChild(papervisionSceneWOW);
-
}
-
}
-
}
PV3DSceneWOW.as:
-
package com.cs54.papervision
-
{
-
-
import flash.events.Event;
-
import fr.seraf.wow.core.data.WVector;
-
import fr.seraf.wow.core.WOWEngine;
-
import fr.seraf.wow.primitive.WBox;
-
import fr.seraf.wow.primitive.WOWPlane;
-
import fr.seraf.wow.primitive.WSphere;
-
import org.papervision3d.materials.ColorMaterial;
-
import org.papervision3d.materials.utils.MaterialsList;
-
import org.papervision3d.materials.WireframeMaterial;
-
import org.papervision3d.objects.DisplayObject3D;
-
import org.papervision3d.objects.primitives.Plane;
-
import org.papervision3d.objects.primitives.Sphere;
-
-
public class PV3DSceneWOW extends PaperBase
-
{
-
-
protected var displayContainer :DisplayObject3D;
-
protected var holder :DisplayObject3D
-
protected var sphere :Sphere;
-
protected var wireframeMat :WireframeMaterial;
-
protected var wow :WOWEngine
-
protected var wowSphere :WSphere
-
override public function init(vpWidth:Number = 800, vpHeight:Number = 600):void
-
{
-
-
super.init(vpWidth, vpHeight);
-
default_camera.y = 300;
-
}
-
-
override protected function createChildren3D():void
-
{
-
super.createChildren3D();
-
-
wireframeMat = new WireframeMaterial(0, 100, .2);
-
wireframeMat.doubleSided = true;
-
sphere = new Sphere(wireframeMat, 100);
-
default_camera.zoom = 40;
-
-
default_scene.addChild(sphere);
-
-
setupWow();
-
createGround();
-
createWOWSphere();
-
}
-
-
public function setupWow(): void
-
{
-
//this is the physics engine
-
wow=new WOWEngine(.3);
-
wow.collisionResponseMode = wow.STANDARD;
-
-
//setup the gravity
-
wow.addMasslessForce(new WVector(0,50,0));
-
}
-
-
public function createGround(): void
-
{
-
//we create a ground on the physics engine
-
var ground:WOWPlane = new WOWPlane(0,0,0);
-
ground.elasticity =.35;
-
ground.friction =2;
-
-
wow.addParticle(ground);
-
-
// we create the ground on the render engine so we start by setup the material...
-
var material:WireframeMaterial = new WireframeMaterial(0,100,1)
-
material.doubleSided = true
-
-
var plane:Plane = new Plane(material , 1000, 1000, 5, 5 );
-
plane.rotationX =-90
-
-
default_scene.addChild(plane);
-
}
-
-
public function createWOWSphere(): void
-
{
-
wowSphere = new WSphere(0,-900,100,100,false,0.1);
-
wowSphere.elasticity = 0;
-
-
wowSphere.friction=3320;
-
wow.addParticle(wowSphere);
-
-
sphere.x =-wowSphere.px;
-
sphere.y =-wowSphere.py;
-
sphere.z =-wowSphere.pz;
-
}
-
-
override protected function processFrame():void
-
{
-
super.processFrame();
-
-
wow.step()
-
-
sphere.x = wowSphere.px;
-
sphere.y = -wowSphere.py;
-
sphere.z = wowSphere.pz;
-
-
}
-
override protected function renderEnterFrame(ThisEvent:Event):void
-
{
-
super.renderEnterFrame(ThisEvent);
-
-
}
-
-
}
-
-
}
The paper base that I reuse:
Based off of this example
-
package com.cs54.papervision
-
{
-
import flash.display.Sprite;
-
import flash.events.Event;
-
import org.papervision3d.view.Viewport3D;
-
import org.papervision3d.cameras.*;
-
import org.papervision3d.scenes.Scene3D;
-
import org.papervision3d.render.BasicRenderEngine;
-
-
public class PaperBase extends Sprite
-
{
-
-
public var viewport:Viewport3D;
-
public var renderer:BasicRenderEngine;
-
public var default_scene:Scene3D;
-
public var default_camera:Camera3D;
-
-
public function init(vpWidth:Number = 800, vpHeight:Number = 600):void
-
{
-
initPapervision(vpWidth, vpHeight);
-
createChildren3D();
-
createChildren2D();
-
size();
-
initEvents();
-
}
-
protected function initPapervision(vpWidth:Number, vpHeight:Number):void
-
{
-
viewport = new Viewport3D(vpWidth, vpHeight);
-
addChild(viewport);
-
-
renderer = new BasicRenderEngine();
-
-
default_scene = new Scene3D();
-
-
default_camera = new Camera3D();
-
}
-
protected function createChildren3D():void
-
{
-
// This function should hold all of the stages needed
-
// to initialise everything used for papervision.
-
// Models, materials, cameras etc.
-
}
-
protected function createChildren2D():void
-
{
-
// This function should create all of the 2d items
-
// that will be overlayed on your papervision project.
-
// User interfaces, Heads up displays etc.
-
}
-
protected function size():void
-
{
-
-
}
-
protected function initEvents():void
-
{
-
addEventListener(Event.ENTER_FRAME, renderEnterFrame);
-
}
-
protected function processFrame():void
-
{
-
// Process any movement or animation here.
-
}
-
protected function renderEnterFrame( ThisEvent:Event ):void
-
{
-
//trace("RENDERING")
-
//We need to render the scene and update anything here.
-
-
renderer.renderScene(default_scene, default_camera, viewport);
-
processFrame();
-
}
-
}
-
}
Don't forget to download the latest Papervision Great White Branch.


Nice start !
Keep in mind that the branch Great White is gone. The latest version is beta 2.0 which is in the trunk of the pv3d svn.
Visit #papervision3d at irc server freenode or http://pv3dchat.flashbookmarks.com/
to talk with other pv3d developers.
Good luck.
Good work.
Please Check out my PV3D-WOW project. It is very similar. Feedback would be great.
http://code.google.com/p/wellenblau/wiki/PhysicPV3D