LoginSignup
5
6

More than 5 years have passed since last update.

Away3d 4.0 beta Planeの頂点をランダムに移動し、地面ぽくする

Last updated at Posted at 2012-02-29
RandomMoveVertex.as
/**
 * copyright (c) 2012 www.romatica.com
 * @auther itoz
 */
package
{
    import away3d.containers.View3D;
    import away3d.core.base.SubGeometry;
    import away3d.debug.AwayStats;
    import away3d.entities.Mesh;
    import away3d.materials.ColorMaterial;
    import away3d.primitives.PlaneGeometry;
    import away3d.primitives.PrimitiveBase;

    import flash.events.Event;
    import flash.geom.Vector3D;
    import flash.utils.getTimer;

    [SWF(backgroundColor="#FFFFFF", frameRate="60", width="800", height="600")]
    /**
     * Planeの頂点をランダムに移動し、地面ぽくする
     * 動作サンプル
     * @see http://dl.dropbox.com/u/958512/sample/away3d4/randomMoveVertex/index.html
     */
    public class RandomMoveVertex extends View3D
    {
        private static const ZERO : Vector3D = new Vector3D(0, 0, 0);
        private var _planeMat : ColorMaterial;
        private var _planeGeo : PrimitiveBase;
        private var _plane : Mesh;

        public function RandomMoveVertex()
        {
            antiAlias = 0;
            backgroundColor = 0xa1c3c0;

            // ----------------------------------
            // プレーン
            // ----------------------------------
            _planeMat = new ColorMaterial(0x567524, 0.5);
            _planeGeo = new PlaneGeometry(1024, 1024, 32, 32);
            _plane = new Mesh(_planeGeo, _planeMat);
            scene.addChild(_plane);

            // ----------------------------------
            // 頂点をランダムに移動
            // ----------------------------------
            var subgeos : Vector.<SubGeometry> = _plane.geometry.subGeometries ;
            var  len : int = subgeos.length;
            for (var j : int = 0; j < len; j++) {
                var geo : SubGeometry = subgeos[j] as SubGeometry;
                var vlen : int = geo.vertexData.length;
                for (var k : int = 0; k < vlen; k ++) {
                    geo.vertexData[k] += Math.random() * 50 - 25;
                }
            }

            camera.y = 500;
            addEventListener(Event.ENTER_FRAME, update);
            addChild(new AwayStats());
        }

        private function update(event : Event) : void
        {
            camera.x = Math.sin(getTimer()/1000) *1000;
            camera.z = Math.cos(getTimer()/1000) *1000;
            camera.lookAt(ZERO);
            render();
        }
    }
}

5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6