[Away3D] Planeの頂点をランダムに移動し地面ぽくする
/**
* Copyright romatica ( http://wonderfl.net/user/romatica )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/l2cL
*/
/**
* copyright (c) 2012 www.romatica.com
* @author 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;
//import flash.display.*;
[SWF(backgroundColor="#FFFFFF", frameRate="60", width="465", height="465")]
/**
* Planeの頂点をランダムに移動し、地面ぽくする
*/
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;
// private var source:BitmapData = new BitmapData(465, 465, true, 0x000000);
public function RandomMoveVertex()
{
//Wonderfl.disable_capture();
//addChild(new Bitmap(source));
antiAlias = 0;
backgroundColor = 0xa1c3c0;
// ----------------------------------
// Plane
// ----------------------------------
_planeMat = new ColorMaterial(0x237524, 0.85);
_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();
// renderer.queueSnapshot(source);
}
}
}