ToggleSphere
package {
import flash.display.*;
import flash.events.*;
import caurina.transitions.Tweener;
import org.papervision3d.core.geom.renderables.Vertex3D;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
import org.papervision3d.materials.shadematerials.PhongMaterial;
import org.papervision3d.materials.shaders.FlatShader;
import org.papervision3d.view.BasicView;
import org.papervision3d.objects.primitives.Sphere;
import org.papervision3d.events.InteractiveScene3DEvent;
[SWF(width = "500", height = "500", frameRate = "41", backgroundColor = "#000000", pageTitle = "milkmidi.com")]
public class TogetogeComposition extends BasicView{
private var togeFlag :Boolean = false;
private var sphere :Sphere;
public function TogetogeComposition():void{
super(0, 0, true, true);
viewport.buttonMode = true;
init3DObject();
startRendering();
}
private function init3DObject():void {
var _light :PointLight3D = new PointLight3D();
var _flatMat:FlatShadeMaterial = new FlatShadeMaterial(_light, 0xeeeeee, 0x51A2A2, 1);
var _phong :PhongMaterial = new PhongMaterial(_light, 0xeeeeee, 0x51A2A2, 1);
_phong.interactive = true;
_flatMat.interactive = true;
sphere = new Sphere(_flatMat, 160, 16, 16);
for each (var i:Vertex3D in sphere.geometry.vertices) {
i.extra = {
baseX:i.x,
baseY:i.y,
baseZ:i.z
};
}
sphere.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, on3DEventClick);
scene.addChild(sphere);
}
private function on3DEventClick(e:InteractiveScene3DEvent):void {
var _num:int = 1;
var _tweenObj:Object;
for each (var i:Vertex3D in sphere.geometry.vertices) {
if (_num % 7 == 0) {
if (! togeFlag) {
_tweenObj =
{
x :i.extra.baseX * 4,
y :i.extra.baseY * 4,
z :i.extra.baseZ * 4
}
} else {
_tweenObj =
{
x :i.extra.baseX,
y :i.extra.baseY,
z :i.extra.baseZ
};
}
_tweenObj.time = 2;
_tweenObj.delay = Math.random();
_tweenObj.transition = "easeOutElastic";
Tweener.addTween(i, _tweenObj);
}
_num++;
}
togeFlag = !togeFlag;
}
override protected function onRenderTick(event:Event = null):void {
super.onRenderTick(event);
sphere.rotationY += viewport.mouseX / 100;
sphere.rotationX += viewport.mouseY / 100;
}
}
}