Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
package {
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.materials.*;
import org.papervision3d.materials.special.CompositeMaterial;
import org.papervision3d.core.math.Matrix3D;
import org.papervision3d.materials.utils.MaterialsList;
// effect用
import flash.display.BlendMode;
import flash.filters.BlurFilter;
import flash.geom.ColorTransform;
import flash.geom.Point;
import org.papervision3d.core.effects.BitmapColorEffect;
import org.papervision3d.core.effects.BitmapLayerEffect;
import org.papervision3d.core.effects.utils.BitmapClearMode;
import org.papervision3d.core.effects.utils.BitmapDrawCommand;
import org.papervision3d.view.layer.BitmapEffectLayer;
public class Papervision3DImage2 extends Sprite {
private var scene:Scene3D;
private var viewport:Viewport3D;
private var camera:Camera3D;
private var renderer:BasicRenderEngine;
private var cube:Array = new Array();
private var cubeCount:Number = 45;
// effect用
private var bfx:BitmapEffectLayer;
public function Papervision3DImage2() {
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.frameRate = 30;
init();
}
private function init():void {
// viewport
viewport = new Viewport3D(0,0,true);
viewport.opaqueBackground = 0xFFFFFF;
addChild(viewport);
// renderer
renderer = new BasicRenderEngine();
// camera
camera = new Camera3D();
camera.focus = 500;
camera.zoom = 1;
// scene
scene = new Scene3D();
// effect
bfx=new BitmapEffectLayer(viewport, stage.stageWidth, stage.stageHeight, true, 0, BitmapClearMode.CLEAR_PRE);
bfx.addEffect(new BitmapLayerEffect(new BlurFilter(2, 2, 4)));
bfx.addEffect(new BitmapColorEffect(0.99, 0.98, 0.98, 0.98));
bfx.clippingPoint=new Point(0, -7);
bfx.drawLayer.blendMode=BlendMode.OVERLAY;
viewport.containerSprite.addLayer(bfx);
// object
cube[0] = new Cube(getMaterialsList(), 300, 300, 300, 1, 1, 1);
scene.addChild(cube[0]);
// effectをcubeに適用
bfx.addDisplayObject3D(cube[0]);
// リングマリオ作成
for (var i:int = 1; i<cubeCount; ++i) {
cube[i] = new Cube(getMaterialsList(), 40, 40, 40);
cube[i].x = Math.cos(i) * 300;
cube[i].y = Math.sin(i) * 300;
scene.addChild(cube[i]);
}
// event
addEventListener(Event.ENTER_FRAME, onEnerFrameHandler);
}
private function getMaterialsList():MaterialsList {
// BitmapFileMaterial
var material1:BitmapMaterial = new BitmapMaterial(new Mario(100, 100));
return new MaterialsList({
front :material1
,back :material1
,right :material1
,left :material1
,top :material1
,bottom:material1
});
}
private function onEnerFrameHandler(evt:Event):void{
for (var i:int = 0; i<cubeCount; ++i) {
cube[i].rotationX++;
cube[i].rotationY++;
}
// フォーカスをズームする
camera.focus = getFocus();
renderer.renderScene(scene,camera,viewport);
}
private var focus:Number = 0;
private var _focus:Number = 0;
private function getFocus():Number {
if (focus == 0) {
_focus = 10;
} else if (focus == 1500) {
_focus = -10;
}
return focus += _focus;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment