Skip to content

Instantly share code, notes, and snippets.

@itoz
Created February 29, 2012 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itoz/1938930 to your computer and use it in GitHub Desktop.
Save itoz/1938930 to your computer and use it in GitHub Desktop.
Away3d 4.0 beta Planeの頂点をランダムに移動し、地面ぽくする ref: http://qiita.com/items/2894
/**
* 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();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment