出處:http://hi.baidu.com/heguang
Papervision3D仍然處理2.0 alpha階段,在測試這些例子之前,確保更新到了Papervision3D 2.0 alpha Great White branch的最新版本。
原文地址:http://www.insideria.com/2008/05/textures-wireframe-bitmap-movi-1.html
Materials
關于Papervision3D的材質你需要知道些什么呢?以一個球體為例,你怎樣確定這個球體是地球呢,還是眼睛或籃球?你只能通過貼在球體上面的材質來判斷。
這篇文章介紹了Papervision3D材質的基本內容并且教會你怎樣把材質加到一個平面上。讓我們開始吧。
材質的基類
在單獨介紹每種材質之前,需要著重了解每種材質都擴展了的抽象父類“MaterialObject3D” (org.papervision3d.core.proto.MaterialObject3D)。也就是說,無論哪種材質,你都可以找到以下共同的屬性。
所有的材質都很常用的
1. name(String):材質的名稱。
2. interactive(Boolean)允許指定監聽器。
3. oneSide或doubleSided(Boolean):在網格(即3D物體)的正面和反面貼上材質。例如,一個轉動的平面在它的兩面都顯示相同的材質。
4. smooth(Boolean):在材質上應用平滑算法。把材質或者高分辨率的材質的平滑打開,會增強它的表現效果。
較少用到,但很有用的
5. bitmap(BitmapData):允許你訪問材質的bitmap data。
6. tiled(Boolean):決定紋理是否平鋪在整個材質上。對于原始對象,需要調整maxU 和maxV才能生效。關于UV映射的更多信息請訪問:http://en.wikipedia.org/wiki/UV_mapping/
7. maxU (Number):“U”最大值。
8. maxV (Number):“V”的最大值。
9. scene (Scene3D):持有物體所屬舞臺的引用。
特別情況下使用的
10. invisible(Boolean):表明物體表明是否被繪制。
11. opposite(Boolean):indicates whether the face is flipped. Only use this if the material is double sided.
12. widthOffset (Number): holds the original width of the bitmap before auto mip-mapping resizes
13. heightOffset (Number): holds the original height of the bitmap before auto mip-mapping resizes
Wireframe Material(或者包含了Wireframe Material的組合材質)
14. lineColor (Number):表面線條的RGB值(如0xabc123)。
15. lineAlpha (Number):0到1之間的數值,代表了線條的透明度。
16. lineThickness (Number):線條厚度。
僅適用于Color Material(或者包含了Color Material的組合材質)
1. fillColor (Number):填充網格的RGB值(如0xabc123)。
2. fillAlpha (Number):0到1之間的數值,填充的透明度。
1. Wireframe
WireframeMaterial( color:Number=0xFF00FF, alpha:Number=100, thickness:Number = 0 )
2.Color
ColorMaterial( color:Number=0xFF00FF, alpha:Number = 1, interactive:Boolean = false )
3.Bitmap
如果想要將圖像應用到3D物體上,你需要用到下面的方法來得到.gif、.jpeg或者.png文件的bitmap數據。
在這個例子里用到上面這幅logo。Bitmap Material, Bitmap Asset Material, 和 Bitmap File Material是三種不同的方式,得到相同下面相同的效果。
a.Bitmap
Bitmap
Material允許將任何BitmapData貼到材質上。最典型的用法是綁定一個位圖,從而獲取它的bitmapData再應用到材質上。你可以從這
里獲得關于在Flex中綁定位圖的更多信息:http://livedocs.adobe.com/flex/3/html
/help.html?content=embed_3.html
BitmapMaterial( asset:BitmapData=null, precise:Boolean = false)
b.Asset(僅在Flash CS3使用)
使用Bitmap Asset Materials將Flash庫里的一幅位圖貼到物體上。僅需要增加任何位圖到library里,右鍵單擊->屬性
c. Color
Bitmap Color Material的用法跟Color Material差不多,但它允許你訪問bitmapData,按照自己的意愿繪制或改變顏色的像素。
d.File
Bitmap File Material僅需要一個字符串,指出圖片的位置。你可以為材質增加監聽器,來監聽圖片下載進度或什么時候完成下載。
BitmapFileMaterial( url :String=”" )
e.Viewport
Bitmap Viewport Material獲取一幅視口位圖的快照,并允許你把它應用到其它的3D物體上。類似于籃球比賽,通過大屏幕而不是直接觀看。
BitmapViewportMaterial(bitmapViewport:BitmapViewport3D,precise:Boolean=false);
BitmapViewport3D(viewportWidth:Number=640,viewportHeight:Number=480,
autoScaleToStage:Boolean = false, bitmapTransparent:Boolean=false,
bgColor:int=0×000000, interactive:Boolean=false,
autoCulling:Boolean=true);
f.Wireframe
Bitmap Wireframe Material類似于Wireframe Material,但允許訪問材質的bitmapData。
BitmapWireframeMaterial(color:Number=0xFF00FF, alpha:Number=1,thickness:Number=3)
4.MovieClip
Papervision3D允許你直接使用Flash庫里的MovieClip,通過鏈接標識符(linkage identifier)貼到3D物體上。對于Flex,就需要綁定公開的.swf和MovieClip。
a.Asset (僅用于Flash CS3)
MovieAssetMaterial( linkageID:String=”", transparent:Boolean=false,
animated:Boolean=false, createUnique:Boolean=false, precise:Boolean =
false)
b.MovieMaterial
MovieMaterial( movieAsset:DisplayObject=null, transparent:Boolean=false, animated:Boolean=false, precise:Boolean = false )
5. Video Stream
嗯,你可以在3D物體上顯示視頻了。真酷!
VideoStreamMaterial ( video:Video, stream:NetStream , precise:Boolean = false )
6.Shade
陰影材質是基于光線的,一束光照射在材質上,反射與否就形成了陰影。你可能已經猜到了,你首先需要創造一束光:
light = new PointLight3D();
通過x、y和z屬性,你可以把這束光移動到你想要的位置。陰影物體會朝向這束光。如果你想這束光可見,需要傳遞一個為“true”的參數,并把它“addChild”到舞臺上。否則,它就是一束不可見的光,在同樣的位置上創建3D物體,看起來光源就像是太陽或燈那樣。
a.cell
http://en.wikipedia.org/wiki/Cel-shaded_animation
Cell Material用到了兩種顏色,你可以設置步數來混合它們。
CellMaterial(light:LightObject3D, color_1:int, color_2:int, steps:int)
b.Environment Map
http://en.wikipedia.org/wiki/Environment_map
environment map接受投影過的位圖。下一篇文章里會提到需要“shaders”的environment map的更多高級用法。
EnvMapMaterial(light:LightObject3D, lightMap:BitmapData, backEnvMap:BitmapData=null, ambientColor:int = 0)
c. Flat Shade
http://en.wikipedia.org/wiki/Flat_shading
平面陰影使多邊形的每一面都有固體陰影。這個效果用在球體上會比在平面或立方體上更好。你會看見光線環繞著這個球體。
FlatShadeMaterial(light:LightObject3D, diffuse:uint=0xffffff, ambient:uint=0×000000)
d.Gouraud
http://en.wikipedia.org/wiki/Gouraud_shading
Gouraud Material具有更平滑的陰影。上面的鏈接討論了它的局限性。
GouraudMaterial(light3D:LightObject3D, lightColor:int = 0xFFFFFF, ambientColor:int=0×000000)
e. Phong
http://en.wikipedia.org/wiki/Phong_shading
Phong Material跟Gouraud Material類似,不過它允許高光。
PhongMaterial(light3D:LightObject3D, lightColor:int, ambientColor:int, specular:int)
7.Composite
composite material就是多種材質組合到一起變成了一種材質。在這里我們看到的是bitmap material和wireframe material混在一起的效果。
8.運行時材質交換
在運行時(run-time)交換材質將很容易辦到。感謝Ralph的更新。
my3DObject.material = myMaterial;
最用使用是在翻轉的時候,但Papervision3D的交互要在接下來的文章里才會介紹。
9.網絡上Material的例子
http://www.zeropointnine.com/blog/a-papervision-20-alpha-example
http://www.unitzeroone.com/blog/2008/03/12/papervision3d-shaders-bumpmap-example-sourcecode-for-cs3/
標簽: Material, Papervision 3D, 紋理