Effects on PV3D
参考一些外国的demo,做了3个effect,分享之。
随机坐标创建50个3D矩形
for(var i:int = 0; i < 50; i ++)
{
var p:Plane = new Plane(new ColorMaterial(Math.random()*0xFFFFFF), Math.random()*180+10, Math.random()*180+10);
p.x = Math.random() * 1000 - 500;
p.y = Math.random() * 1000 - 500;
p.z = Math.random() * 700 - 400;
p.material.doubleSided = true;
scene.addChild(p);
p.useOwnContainer = true;
planes.push(p);
depthDemo = true;
p.filters = [new BlurFilter()];
p.alpha = Math.random() + 0.1;
}
{
var p:Plane = new Plane(new ColorMaterial(Math.random()*0xFFFFFF), Math.random()*180+10, Math.random()*180+10);
p.x = Math.random() * 1000 - 500;
p.y = Math.random() * 1000 - 500;
p.z = Math.random() * 700 - 400;
p.material.doubleSided = true;
scene.addChild(p);
p.useOwnContainer = true;
planes.push(p);
depthDemo = true;
p.filters = [new BlurFilter()];
p.alpha = Math.random() + 0.1;
}
为每个矩形创建Blur效果
if(depthDemo)
{
for each(var do3d:DisplayObject3D in planes)
{
if(do3d.container)
var deph:int = int(do3d.container.screenDepth);
do3d.filters[0].blurX = do3d.filters[0].blurY = int(deph * 0.005);
}
}
{
for each(var do3d:DisplayObject3D in planes)
{
if(do3d.container)
var deph:int = int(do3d.container.screenDepth);
do3d.filters[0].blurX = do3d.filters[0].blurY = int(deph * 0.005);
}
}
创建一个3D球体
var s:Sphere = new Sphere(new WireframeMaterial(), 150, 12, 8);
s.name = "sphere 11";
scene.addChild(s);
s.name = "sphere 11";
scene.addChild(s);
创建一个特效层
var bfx:BitmapEffectLayer = new BitmapEffectLayer(viewport, 500, 500);
viewport.containerSprite.addLayer(bfx);
viewport.containerSprite.addLayer(bfx);
把球体加入这个特效层,并为层定义特效
bfx.addDisplayObject3D(s);
bfx.addEffect(new BitmapLayerEffect(new BlurFilter(2, 2, 8)));
bfx.setScroll(0, -4);
bfx.setTracking(s);
bfx.addEffect(new BitmapLayerEffect(new BlurFilter(2, 2, 8)));
bfx.setScroll(0, -4);
bfx.setTracking(s);
光照效果在前面的文章已提供源码,请参阅。
Preview:http://niuniuzhu.cn/p/3DRenderDemo/index.html?p=1