zoukankan      html  css  js  c++  java
  • away3d 4.0学习(5)primitives包

    没有目的,没有参考文件,所以瞎逛,看到陌生的东西就试一试。

    今天试的是away3d.primitives包里面的东西。
    primitive在google词典上查阅意思如下:
    形容词
    原始 original, primitive, primeval, aboriginal, primaeval, first
    原语 primitive
    图元 primitive
    名词
    原始人 primitive
    原函数 primitive
    根据以上的形容词和名词的解释,暂时理解他的意思为基础图元。
     
    away3d.primitives包里面有一下几个类,我只用过其中的几个,那么我暂时假装我神马都不知道,我一个都不认识他们:
     类名描述
      CapsuleGeometry 一个UV胶囊图元面
      ConeGeometry 一个UV圆锥图元面。
      CubeGeometry 一个UV长方体图元面。
      CylinderGeometry 一个UV圆柱图元面。
      LineSegment 一个线段图元。
      PlaneGeometry 一个平面图元。
      PrimitiveBase PrimitiveBase是面图元的抽象基类,(指的是这个包里的他的子类)用来预建立一些简单的图元。
      RegularPolygonGeometry 一个UV RegularPolygon (规则多边形)图元面。
      SkyBox  Skybox在场景里面用来渲染天空。
      SphereGeometry 一个UV球体图元面。
      TorusGeometry 一个UV圆环图元面。
      WireframeCube 一个线框长方体图元面。
      WireframeCylinder 生成一个线框锥体。
      WireframePlane 一个线框平面图元面。
      WireframePrimitiveBase  
      WireframeSphere 一个线框球体图元面。


    可以大致的看出,除了基类PrimitiveBase之外,其余的类分为两种类型:
    一种是继承自PrimitiveBase<==Geometry图元数据面;
    另一种是是继承自SegmentSet与Mesh同级别的可以直接添加到场景的元素。
     
    两种类的交汇点位NameAssetBase,这个类是直接继承flash.events.EventDispatcher的。
     
    Geometry是意思是集合形状的意思,源代码里面的说明如下:

    /**
    * Geometry is a collection of SubGeometries, each of which contain the actual geometrical data such as vertices,
    * normals, uvs, etc. It also contains a reference to an animation class, which defines how the geometry moves.
    * A Geometry object is assigned to a Mesh, a scene graph occurence of the geometry, which in turn assigns
    * the SubGeometries to its respective SubMesh objects.

    翻译如下:

    Geometry是一系列的SubGeometry的集合,每个SubGeometry包含了实际的几何数据,例如顶点,法线,uv等等。同时他也

    包含了一个动画类的引用,这个动画类定义了这个几何图形需要如何移动。Geometry将被指派给一个Mesh,Geometry在场景上的图形存在,他将按顺序指派SubGeometries给他对于的SubMesh对象。
     
    这里我把一些比较简单的图元面都实例化了一下,添加到舞台上,代码如下:
     
    View Code
    package samples
    {
        import assets.Resource;
        
        import away3d.controllers.HoverController;
        import away3d.entities.Mesh;
        import away3d.materials.ColorMaterial;
        import away3d.materials.TextureMaterial;
        import away3d.primitives.CapsuleGeometry;
        import away3d.primitives.ConeGeometry;
        import away3d.primitives.CubeGeometry;
        import away3d.primitives.CylinderGeometry;
        import away3d.primitives.RegularPolygonGeometry;
        import away3d.primitives.SphereGeometry;
        import away3d.primitives.TorusGeometry;
        import away3d.primitives.WireframeCube;
        import away3d.primitives.WireframeCylinder;
        import away3d.primitives.WireframeSphere;
        import away3d.utils.Cast;
        
        import template.AwayTemplate;
    
        [SWF(width=1000,height=600,frameRate=30)]
        public class PrimitiveTest extends AwayTemplate
        {
            private var capsule:Mesh;//胶囊
            private var cone:Mesh;//圆锥
            private var cube:Mesh;//立方体
            private var cylinder:Mesh;//圆柱
            private var polygon:Mesh;//多边形
            private var sphere:Mesh;//球体
            private var torus:Mesh;
            private var wireCube:WireframeCube;
            private var wireCyliner:WireframeCylinder;
            private var wireSphere:WireframeSphere;//线条球体
            
            private var material:TextureMaterial;
            public function PrimitiveTest()
            {
                super();
            }
            override protected function initView():void
            {
                super.initView();
                _view.camera.y = 500;
                material = new TextureMaterial(Cast.bitmapTexture(Resource.Earth_Bitmap));
                capsule = new Mesh(new CapsuleGeometry(),material);
                capsule.x = -700;
                _view.scene.addChild(capsule);
                cone = new Mesh(new ConeGeometry(), material);
                cone.x = -500;
                _view.scene.addChild(cone);
                cube = new Mesh(new CubeGeometry(50,50,50),material);
                cube.x = -300;
                _view.scene.addChild(cube);
                cylinder = new Mesh(new CylinderGeometry(),material);
                cylinder.x = -100;
                _view.scene.addChild(cylinder);
                polygon = new Mesh(new RegularPolygonGeometry(100,7),material);
                polygon.x = 100;
                _view.scene.addChild(polygon);
                sphere = new Mesh(new SphereGeometry(),material);
                sphere.x = 300;
                _view.scene.addChild(sphere);
                torus = new Mesh(new TorusGeometry(100),material);
                torus.x = 500;
                _view.scene.addChild(torus);
                wireCube =new WireframeCube();
                wireCube.x = 700;
                _view.scene.addChild(wireCube);
                wireCyliner = new WireframeCylinder(100);
                wireCyliner.x = 900;
                _view.scene.addChild(wireCyliner);
                wireSphere = new WireframeSphere();
                wireSphere.x = -900;
                _view.scene.addChild(wireSphere);
            }
            override protected function render():void
            {
                capsule.yaw(1);
                cone.yaw(1);
                cube.yaw(1);
                cylinder.yaw(1);
                polygon.yaw(1);
                sphere.yaw(1);
                torus.yaw(1);
                wireCyliner.yaw(1);
                wireCube.yaw(1);
                wireSphere.yaw(1);
                super.render();
            }
        }
    }

    效果图如下:


    从左到右依次是 线框球体, 胶囊体, 圆锥体, 长方体, 圆柱体, 规则多边形, 球体, 圆环体,线框长方体,线框锥体。
     
    下一节练习 SkyBox,因为这个比较重要,相对于其他的基础图元相对复杂。
  • 相关阅读:
    hdu 1176 免费馅饼
    http://codeforces.com/contest/741/problem/B B. Arpa's weak amphitheater and Mehrdad's valuable Hoses
    瞎搞题
    1D1D决策单调性dp
    整体二分(POJ2104 静态第k大查询)
    B
    http://codeforces.com/contest/776/problem/G
    http://codeforces.com/contest/776/problem/D 2-sat
    bzoj1492(cdq分治 && 平衡树维护dp)
    F. Bear and Bowling 4(斜率优化)
  • 原文地址:https://www.cnblogs.com/adoontheway/p/2708766.html
Copyright © 2011-2022 走看看