Papervision3D and Desuade Motion Package Example [updated]
With Desuade releasing Beta1 of the Motion Package, I thought I’d do a little example showing how easy it is to use and integrate with PV3D.
Read more to see the demo…
The example uses the basic physics class in the package to control rotation as it builds up real momentum, uses color tweening to change the color of ColorMaterial, and uses a MotionController to make a complex Z tween which brings the cube closer to the camera.
package {
import flash.display.Sprite;
import flash.events.Event;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.materials.*;
import org.papervision3d.materials.utils.*;
import org.papervision3d.view.BasicView;
import com.desuade.motion.*;
import com.desuade.motion.tweens.*;
import com.desuade.motion.physics.*;
import com.desuade.motion.controllers.*;
import com.desuade.motion.eases.*;
import com.desuade.motion.events.*;
import com.desuade.debugging.*
public class ExampleDMP extends BasicView {
private var plane:Cube;
public var yrp:BasicPhysics;
public var xrt:Tween;
public var mct:ColorTween;
public var zvc:MotionController;
public function ExampleDMP() {
super();
Debug.load(new DebugCodesMotion());
//Debug.level = 60000;
Debug.enabled = true;
var material:ColorMaterial = new ColorMaterial();
material.doubleSided = true;
material.fillColor = 0xFF0000;
material.fillAlpha = 1.0;
var ml:MaterialsList = new MaterialsList();
ml.addMaterial(material, 'all');
plane = new Cube(ml, 300, 300, 300);
scene.addChild(plane);
stage.addEventListener(Event.ENTER_FRAME, render);
//DMP code
xrt = new Tween({target:plane, property:'rotationZ', delay:0, value:'1000', duration:20, ease:Bounce.easeOut});
xrt.start();
zvc = new MotionController(plane, 'z', 10);
zvc.keyframes.end.value = null;
zvc.keyframes.end.ease = Bounce.easeOut;
zvc.keyframes.add(new Keyframe(.3, -400, Sine.easeOut));
zvc.keyframes.add(new Keyframe(.7, 3000, Elastic.easeOut));
zvc.start();
mct = new ColorTween({target:material, property:'fillColor', delay:2, value:"CCCCCC", ease:Cubic.easeOut, duration:10})
mct.start();
yrp = new BasicPhysics({target:plane, property:'rotationY', velocity:0, acceleration:.02});
yrp.start();
yrp.addEventListener(PhysicsEvent.UPDATED, valuecheck);
function valuecheck(u:Object):void {
var va = u.data.basicPhysics.target[u.data.basicPhysics.property];
if(va >= 1000){
u.data.basicPhysics.acceleration = -Math.abs(u.data.basicPhysics.acceleration);
} else if(va <= 0) {
u.data.basicPhysics.acceleration = Math.abs(u.data.basicPhysics.acceleration);
}
}
//end dmp
}
private function render(event:Event):void {
singleRender();
}
}
}
Being able to use physics and tweening motion, along with powerful sequencing and color tweening all in one package is super convenient, and the performance is super smooth.
This has been updated for Beta 2 with the new syntax
About this entry
You’re currently reading “Papervision3D and Desuade Motion Package Example [updated],” an entry on visualcondition blog – flash & ruby on rails
- Published:
- 06.26.09 / 9pm
- Category:
- Actionscript, Flash
4 Comments
Jump to comment form | comments rss [?] | trackback uri [?]