Papervision3d 分层(ViewportLayer)的概念示范

我们在Papervision3d中有些物体需要分层管理,同时解决了显示物体交叉混乱的问题(新的四叉树相机算法能解决这个问题,但是效率有点低)。下面我们看看示例。
这里我们用了Papervision3d中的复合材质。
http://www.newflash3d.com---flash3D先锋队:北京贝武易科技公司】
有疑问请联系我QQ:363596350

复合材质(CompositeMaterial)的代码:
            var cubeMat:WireframeMaterial = new WireframeMaterial(0xFF0000);
            var colorMat:ColorMaterial = new ColorMaterial(0x00FF00);
            var compMat:CompositeMaterial = new CompositeMaterial();
            compMat.addMaterial(cubeMat);
            compMat.addMaterial(colorMat);
            
            var materialsList:MaterialsList = new MaterialsList({ all:compMat });


这里还用到了一个方法:orbitY
(感谢flab3d.com“flash研究所”)
		///-flab3d.com-18/11/08,绕Y轴旋转的类//////////////////////////////
		///第一个参数是摄像机看着的物体,第二个参数是每祯旋转度数;第三个参数摄像机是离物体的距离,第四个是摄像机的高度

		private var angled:Number=0;

		public function orbitY(do3d:DisplayObject3D=null,angelIncrease:Number=1,distance:int=1000,heightY:Number=0):void {
			this.lookAt(do3d);

			var radius:int=distance;
			angled+=angelIncrease;


			var ss:Number = angled*Math.PI/180;
			//var zz:Number = radius*Math.PI/180;


			this.x = do3d.x + radius * Math.sin(ss);
			this.y=do3d.y+heightY;
			//this.y = do3d.x + radius * Math.cos(zz) * Math.sin(ss);
			this.z = do3d.z + radius * Math.cos(ss);
		}
		/////////////////////////////////////////////

这段代码需要加到我们的Camera3D类,给Camera3D类加一个orbitY的方法,轻松的实现相机的旋转360度,是一个很方便的方法。
效果如下:

这里有个问题是,好像外部导入进去DAE格式文件对这个ViewportLayer的支持不是很好,没有起到作用。
代码如下:
package {
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.BlurFilter;
	import flash.filters.GlowFilter;
	
	import org.papervision3d.cameras.Camera3D;
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.materials.WireframeMaterial;
	import org.papervision3d.materials.special.CompositeMaterial;
	import org.papervision3d.materials.utils.MaterialsList;
	import org.papervision3d.objects.parsers.DAE;
	import org.papervision3d.objects.primitives.Cube;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.render.BasicRenderEngine;
	import org.papervision3d.scenes.Scene3D;
	import org.papervision3d.view.Viewport3D;
	import org.papervision3d.view.layer.ViewportLayer;
	import org.papervision3d.view.layer.util.ViewportLayerSortMode;

	[SWF(backgroundColor="#000000", frameRate="60", width="500", height="400")]

	public class viewportLayerTest01 extends Sprite {
		private var viewport:Viewport3D;
		private var renderer:BasicRenderEngine;
		private var scene:Scene3D;
		private var camera:Camera3D;

		private var cube:Cube;
		private var plane:Plane;
		
		private var layer1:ViewportLayer;
		private var layer2:ViewportLayer;

		public function viewportLayerTest01():void {

			viewport=new Viewport3D(500,400);
			renderer=new BasicRenderEngine  ;
			scene=new Scene3D;
			camera=new Camera3D(60,10,5000);
			
			viewport.containerSprite.sortMode = ViewportLayerSortMode.Z_SORT;

			addChild(viewport);
			
            var planeMat:WireframeMaterial = new WireframeMaterial(0xFF0000);
            var planecolorMat:ColorMaterial = new ColorMaterial(0xFFFF00);
            var planecompMat:CompositeMaterial = new CompositeMaterial();
            planecompMat.addMaterial(planeMat);
            planecompMat.addMaterial(planecolorMat);
			
			plane=new Plane(planecompMat,500,500,1,1);
			plane.pitch(90);
			plane.y=0;
			
            var cubeMat:WireframeMaterial = new WireframeMaterial(0xFF0000);
            var colorMat:ColorMaterial = new ColorMaterial(0x00FF00);
            var compMat:CompositeMaterial = new CompositeMaterial();
            compMat.addMaterial(cubeMat);
            compMat.addMaterial(colorMat);
            
            var materialsList:MaterialsList = new MaterialsList({ all:compMat });
            
			cube=new Cube(materialsList,200,200,200,1,1,1);
			cube.y=100;
/* 			
			var sphere:DAE = new DAE();
			sphere.load("assets/nishuboy.DAE",null);
			sphere.scale=5;

			scene.addChild(sphere);
 */
			scene.addChild(cube);
			
			scene.addChild(plane);
			
			layer1=viewport.getChildLayer(cube);
		    layer2=viewport.getChildLayer(plane);
			
			var filter1:GlowFilter = new GlowFilter(0xccffff,1,52,52,4,1,false,false);
			var filter2:BlurFilter = new BlurFilter(10,10);
			layer1.filters=[filter1];
			layer2.filters=[filter2];

			addEventListener(Event.ENTER_FRAME,process);
		}
		private function process(evt:Event):void {
			camera.orbitY(plane,1,500,100);

			renderer.renderScene(scene,camera,viewport);
		}

	}
}

你可能感兴趣的:(算法,qq,Flash,360)