`
jy00314996
  • 浏览: 72841 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

Papervision3D(PV3D)笔记&教程(6)-材质Material

阅读更多

PV3D中材质的种类非常多,都是MaterialObject3D的子类,每个显示对象都需要材质才能显示。我们先来大致看一下所有的材质类:

MaterialObject3D
————LineMaterial
————ParticleMaterial
————————BitmapParticleMaterial
————————MovieAssetParticleMaterial
————TriangleMaterial
————————AbstractLightShadeMaterial
————————————AbstractSmoothShadeMaterial
————————————————EnvMapMaterial
————————————————————CellMaterial
————————————————————PhongMaterial
————————————————GouraudMaterial
————————————FlatShadeMaterial
————————BitmapMaterial
————————————BitmapAssetMaterial
————————————BitmapColorMaterial
————————————BitmapFileMaterial
————————————BitmapViewportMaterial
————————————MovieMaterial
————————————————MovieAssetMaterial
————————————————VideoStreamMaterial
————————BitmapWireframeMaterial
————————ColorMaterial
————————CompositeMaterial
————————ShadedMaterial
————————WireframeMaterial
————VectorShapeMaterial
————————Letter3DMaterial

  上面列出了PV3D中所有的材质,大家可以先看一下,有个印象,以后用到的话方便查文档。下面看一下比较常用的几个。

ColorMaterial
  ColorMaterial是最常用的一个材质,它只有单纯的颜色和透明度,看下构造函数
ColorMaterial (color:Number = 0xFF00FF, alpha:Number = 1, interactive:Boolean = false)
主要说下interactive这个参数,如果你需要你的三维物体接收交互(例如鼠标点击)的话要将它设为true,还有就是经常问到的一个问题,怎么实现鼠标手型,首先要将viewport的interactive设为true,然后将材质的interactive也设为true以后,在显示对象上监听InteractiveScene3DEvent.OBJECT_OVER事件,监听器中将viewport的buttonMode设为true(前面说过viewport是Sprite的子类,所以可以设置buttonMode),鼠标离开事件里再设为false就可以了,关于交互以后会专门学习下给大家分享

package  
{
	import gs.TweenLite;
	import org.papervision3d.events.InteractiveScene3DEvent;
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.view.BasicView;
 

	public class InteractivePlane extends BasicView
	{
		private var _plane:Plane
		private var _material:ColorMaterial;
 
		public function InteractivePlane() 
		{
			super();
			init()
		}
 
		private function init():void
		{
			initPanel();
			startRendering();
		}
 
		private function initPanel():void
		{
 
			_material = new ColorMaterial(0x1D9DAD, 1, true);
			_material.interactive = true;
			_plane = new Plane(_material,500,500);
			_plane.rotationX = 45;
 
			scene.addChild(_plane);
			viewport.interactive = true;
 
			_plane.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, onOver);
			_plane.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, onOut);			
			_plane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, onClick);			
 
		}
 
		private function onClick(e:InteractiveScene3DEvent):void 
		{
			_material.fillColor = Math.random() * 0xffffff;
		}
 
		private function onOver(e:InteractiveScene3DEvent):void 
		{
			viewport.buttonMode = true;
			TweenLite.to(_plane, 1, { rotationX:0 } );
		}
 
		private function onOut(e:InteractiveScene3DEvent):void 
		{
			viewport.buttonMode = false;
			TweenLite.to(_plane, 1, { rotationX:45 } );
		}
 
 
	}
 
}

 

代码中创建了一个平面,然后给它了一个ColorMaterial的材质,然后监听鼠标的OVER,OUT,CLICK事件,当鼠标移上去的时候平面转动一定角度并出现手型,移开的话转动复原手型消失,当点击的时候给ColorMaterial的fillColor属性重新赋值改变平面颜色。
 
  另外比较常用的还有位图材质BitmapMaterial和带阴影的材质FlatShadeMaterial,使用方法网上都很多大家google一下。
  目前蚂蚁的详细PV3D教程就告一段落,基础的已经基本讲得差不多了,后面还会有一些高级应用的专项笔记教程。现在你已经可以创造自己的3D世界啦~发挥你的想象力,have a try~

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics