Papervision3D(PV3D)笔记&教程(5)-线条

还是看下文档先:
Line3D:Package org.papervision3d.core.geom.renderables
Class public class Line3D
Inheritance Line3D AbstractRenderable
Implements IRenderable
  
Line3D is used by Lines3D to store and render the lines.
Line3D被用来在Lines3D中创建出可以被渲染的线条
 
构造函数
Line3D(instance:Lines3D, material:LineMaterial, size:Number, vertex0:Vertex3D, vertex1:Vertex3D)
instance:Lines3D — The containing Lines3D object
要加入到的Lines3D实例
material:LineMaterial — The material for the line
材质
size:Number — The line weight
粗细
vertex0:Vertex3D — The start vertex
起点
vertex1:Vertex3D — The end vertex
终点
  
再看下它常用的属性和方法:

cV : Vertex3D 控制点
material : LineMaterial 材质
size : Number 粗细
v0 : Vertex3D 起点
v1 : Vertex3D 终点
  
addControlVertex(cx:Number, cy:Number, cz:Number):void
给线条添加一个控制点,感觉好像就是贝塞尔曲线里面那种控制点
  
Lines3D:Package org.papervision3d.core.geom
Class public class Lines3D
Inheritance Lines3D Vertices3D DisplayObject3D DisplayObjectContainer3D flash.events.EventDispatcher
Subclasses UCS

  Lines3D是继承了DisplayObject3D,所以可以直接添加到scene或者其他3D显示对象容器中渲染显示。我们可以把Line3D的实例添加到Lines3D中(使用addLine()方法),也可以直接在Lines3D中画线(使用addNewLine()方法),前一种方法可以添加许多颜色不同的线,而后一种方法只可以画预先定义好材质的线
 
构造函数
Lines3D(material:LineMaterial = null, name:String = null)
material:LineMaterial (default = null)
使用addNewLine()方法添加进来的线条材质
name:String (default = null)
名字
 
属性
lines:Array Lines3D中所有线条的数组
 
方法
addLine(line:Line3D):void
添加一条线
addNewLine(size:Number, x0:Number, y0:Number, z0:Number, x1:Number, y1:Number, z1:Number):Line3D
添加一条线,使用Lines3D中定义的材质,默认为纯红色0xff0000
removeAllLines():void
删除里面的所有线条
removeLine(line:Line3D):void
删除线条
  
下面我们来看一段代码.
  首先我们用addLine()方法画圆,画完以后使用removeAllLines()方法删除刚才画的圆,然后又画了一条线,添加了一个控制点,同时开始用addNewLine()开始重新画圆。
运行代码看效果,然后自己动手做一些练习吧!

ActionScript代码:

package
{
	import flash.events.Event;
	import org.papervision3d.core.geom.Lines3D;
	import org.papervision3d.core.geom.renderables.Line3D;
	import org.papervision3d.core.geom.renderables.Vertex3D;
	import org.papervision3d.materials.special.LineMaterial;
	import org.papervision3d.view.BasicView;
 
	public class DrawCircle extends BasicView
	{
		private static var _segment:int=500;
		private static var _radius:Number=400;
		private static var _offset:int=0;
		private static var _beginVertex:Vertex3D;
		private static var _endVertex:Vertex3D;
		private static var _lineMaterial:LineMaterial;
 
		private var _lines:Lines3D;
 
 
		public function DrawCircle()
		{
			init();
		}
 
		private function init():void
		{
			createLines();
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}
 
		private function createLines():void
		{
			_lines = new Lines3D();
			_lines.addNewLine(10, 0, _radius, 0, 0, -_radius, 0);
			scene.addChild(_lines);
 
			_lineMaterial = new LineMaterial(Math.random() * 0xffffff);
			_beginVertex = new Vertex3D(Math.sin(2*Math.PI*_offset/_segment)*_radius, Math.cos(2*Math.PI*_offset/_segment)*_radius, 0);
		}
 
		private function drawCircle():void {
			_offset += 1;
			_endVertex=new Vertex3D(Math.sin(2*Math.PI*_offset/_segment)*_radius, Math.cos(2*Math.PI*_offset/_segment)*_radius, 0);
			_lines.addLine(new Line3D(_lines, _lineMaterial, 10, _beginVertex, _endVertex));
			_beginVertex = _endVertex;
		}
 
 
		private function onEnterFrame(e:Event):void
		{
 
 
 
			if (_offset < _segment) {
				drawCircle();
			}else {
				_lines.pitch(1);
			}
 
			singleRender();
		}
 
 
 
	}
 
}

 效果图:

你可能感兴趣的:(Flash,actionscript)