天天看點

Away3D 基礎5 - 3D基本元素(3)

這是關于3D基本元素的第三篇教程也是最後一篇。在這篇裡要介紹的是我們不常用到的。GridPlane和LineSegment用于調試,然而Cone, Torus 和SeaTurtle更是“非必備品”了。

這篇教程裡介紹過的3D基本元素也存在于别的3D引擎或模型包裡。由于不常用,本教程裡沒有像前兩節裡那樣豐富的執行個體。不過這裡還是提供了能展現其用法的代碼

先決條件

本教程建立在我們别的教程基礎之上。假如你是flash3D菜鳥,你可能會先要去看看這些教程。舉個例子,有些源檔案,點選附帶的as檔案檢視它們是如何工作的。所有這些例子都要用到一個Cover.as檔案。這個檔案是讓教程裡用到的flash影片不能同時工作,否則會拖垮你的電腦。如果你不确定如何使用這些例子,檢視這個教程。

教程裡的一部分例子會用到“紋理”。關于紋理與材質我們會在後邊教程詳細介紹,如果要讓代碼在flash cs3裡工作, 讀這個教程.

The Cone

圓錐用處不大。做冰淇淋甜筒、錐形交通标和宴會帽等效果時可能會用到。圓錐有radius、segmentsH、segmentsW和height屬性,另外一個屬性用于指明是否開口,如果設為開口,我們就可以從圓錐底看到圓錐内部。

Swf:點選觀看as: Basic08_cone.as

在本例展示了幾種可能.下載下傳源檔案,看看各類屬性如何設定。

The Cylinder

圓柱體與圓錐提供的屬性大多相同,看下例:

Swf:點選觀看as: Basic08_cylinder.as

圓柱體可能要比圓錐有用的多,不過用它要付出“昂貴”的代價。記得winxp經典屏保—管道實時渲染嗎?這個看上去很容易實作,但實際上用3D引擎很難實作這個效果。像前面的例子裡看到的那樣,要讓一個3D元素顯示的很“圓”就需要大量的三角形,圓柱體也不例外。回顧曆史我們不難發現在遊戲裡大量使用“圓形表面”還隻是近幾年的事。

The GeodesicSphere

A Geodesic sphere is most commonly referred to as a Geodesic Dome. It's been used in building construction (see Spaceship Earth at Epcot) and has some unique properties when compared to a traditional Sphere primitive. In Away3D the Geodesic Sphere starts off with a basic shape that looks like 2 pyramids combined. This shape is then refined by triangulating each of the triangles in the basic shape to approximate a sphere.

The higher amount of triangulation, the more round the sphere will appear. In the image below, the fracture setting is noted next to each sphere so you can see how this affects the roundness of the sphere.

Away3D 基礎5 - 3D基本元素(3)

as: Basic08_geodesicsphere_refine.as

As you see from the image, this is a quite different way to build the sphere than with a normal sphere primitive. The triangles are almost the same size across the object and this makes a GeodesicSphere more round than a sphere, given the same number of triangles. Mouse over the example below to see how the two compare.

Swf:點選觀看as: Basic08_geodesicsphere.as

It is also possible to create a Geodesic sphere based on other primitives as this code shows.

The RoundedCube

圓角立方體隻在Away3D引擎裡有。最簡單的圓角立方體看上去就像個球。通過增加三角形面數可以得到更佳的效果

Away3D 基礎5 - 3D基本元素(3)

點此去浏覽Fabrice Closier的部落格。Fabrice是Away3D開發團隊裡核心成員。

這個基本元素還是最近在使用者的要求下添加的。假如你需要一種Away3D裡還沒有的3D元素,你可以試圖在away3D論壇裡發帖。論壇會員就有可能去開發這個元素,當然如果你也有開發能力也歡迎您把代碼投稿到away3D引擎。

The Wire primitives

Several of the primitives are also available in Wireframe version. They have no surface so you can see the mesh they consist of.

A final note

As said initially, these primitives have very limited use and some of them even contain bugs. While working on this tutorial, I've added these bugs to the issue list for Away3D. Most notably - the cone and geodesic sphere has texture issues, the cylinder becomes too long if you use more than one segment. The issues are reported to the team and will probably be fixed swiftly, but I'm adding it here as a "nice to know" thing.

The GridPlane

網格平面這個3D元素用于輔助建立場景。它隻是帶網格的平面,但它成為大多3D程式裡必備部分是有原因的。看下面模型。

Swf:點選觀看 as: Basic08_gridplane.as  image: seaturtle.jpg

如上添加了三叉戟與網格後,你對該場景個位置情況一目了然。

The Torus

圓環存在于大多3D工具裡。它可用于油炸圈餅、救生圈。同時這個也用于測試陰影。應用模拟光反射、陰影于旋轉的圓環上,圓環看上去效果很不錯。

Swf:點選觀看 movie: Basic08_torus.as, images: doughnut.jpg mandelbrot.jpg marble.jpg

注意圓環不用segmentsW 和segmentsH設定,取而代之的是segmentsR 和 segmentsT:

 torus.segmentsR = 20;torus.segmentsT = 10;

The LineSegment

像下面例子一樣,有時候我們隻需要在兩點間畫一根線。在away3D裡提供了”線段“元素。把滑鼠移到下面影片上,我們可以看到一根線段始總連着”海龜“

Swf:點選觀看as:Basic08_linesegment.as, image: seaturtle.jpg

The SeaTurtle

This was the first output of the as3 exporter, a class that can generate a compact AS3 class based on any loaded model. This class has since been updated a lot and it's very powerful. If you want a compact 3D project, you should consider testing how the AS3 exporter can improve both file size and load times. While not really a primitive, the Sea Turtle was a fun addition and a bit of a mascot in the early days of Away3D. Since it's kind of complex and has a lot of faces, it is also useful for testing lighting. The texture for the turtle is located in the "/techdemos/images/" folder that you can download from the Away3D subversion repository. You'll see it in use in the next primitive - the GridPlane.

繼續閱讀