zoukankan      html  css  js  c++  java
  • 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.

    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引擎里有。最简单的圆角立方体看上去就像个球。通过增加三角形面数可以得到更佳的效果

    点此去浏览Fabrice Closier的博客。FabriceAway3D开发团队里核心成员。

    这个基本元素还是最近在用户的要求下添加的。假如你需要一种Away3D里还没有的3D元素,你可以试图在away3D论坛里发帖。论坛会员就有可能去开发这个元素,当然如果你也有开发能力也欢迎您把代码投稿到away3D引擎。

    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.

    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 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.

  • 相关阅读:
    如何用C#代码管理SharePoint解决方案
    8 Reasons why SharePoint is Bad for Your Business 8个理由告诉你,为什么SharePoint对你的业务有害
    漫画教你了解SharePoint
    如何增强你的SharePoint 团队网站首页
    4 Reasons why SharePoint is Dying 四个理由告诉你,为什么SharePoint即将死去
    SharePoint 创建站点地图树视图及格式枚举截图
    C++虚函数与多态
    [DirectX 9.0笔记]第二章 渲染管线
    VC6.0 和 VS2010 time_t的区别
    [DirectX 9.0笔记]第一章 初始化 Direct3D
  • 原文地址:https://www.cnblogs.com/nooon/p/1458662.html
Copyright © 2011-2022 走看看