球体组成的球体,入门PV3D

package {
	import flash.display.Sprite;
	import flash.events.Event;
	
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Sphere;
	import org.papervision3d.scenes.Scene3D;
	import org.papervision3d.view.BasicView;

	public class VerticesExample extends BasicView
	{
		
		/**
		 * 声明一个实例
		 * */
		private var pivotDO3D:DisplayObject3D;
		
		public function VerticesExample()
		{
			
			this.init();
			this.startRendering();
		}
		
		/**
		 * 初始化方法
		 * */
		private function init():void
		{
			
			pivotDO3D = new DisplayObject3D();
			
			scene.addChild(pivotDO3D);
			
			var bigSphere:Sphere = new Sphere(null,700,12,8);
			
			/**
			 * 循环变量大球体的顶点数组
			 * */
			var numberOfVerts:uint = bigSphere.geometry.vertices.length;
			for(var i:uint = 0;i<numberOfVerts;i++)
			{
				var smallSphere:Sphere = new Sphere(null,Math.random()*30,2,2);
				
				smallSphere.x = bigSphere.geometry.vertices[i].x;
				smallSphere.y = bigSphere.geometry.vertices[i].y;
				smallSphere.z = bigSphere.geometry.vertices[i].z;
				
				pivotDO3D.addChild(smallSphere);
			}
			
			pivotDO3D.addChild(bigSphere);
		}
		/**
		 * 重写渲染功能
		 * */
		override protected function onRenderTick(event:Event=null):void
		{
			pivotDO3D.localRotationY--;
			super.onRenderTick();
		}
	}
}

你可能感兴趣的:(Flash)