Created
June 23, 2012 03:22
-
-
Save lizhi525/2976629 to your computer and use it in GitHub Desktop.
MazeGeometry.as
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
import aerys.minko.scene.node.mesh.geometry.Geometry; | |
import aerys.minko.scene.node.mesh.geometry.primitive.CubeGeometry; | |
import aerys.minko.type.stream.IVertexStream; | |
import aerys.minko.type.stream.IndexStream; | |
import aerys.minko.type.stream.StreamUsage; | |
import aerys.minko.type.stream.VertexStream; | |
import aerys.minko.type.stream.format.VertexFormat; | |
import flash.geom.Matrix3D; | |
public class MazeGeometry extends Geometry | |
{ | |
public function MazeGeometry(datas:Vector.<Number>, | |
numColumns : uint = 1, | |
numRows : uint = 1, | |
streamsUsage : uint = 0) | |
{ | |
var xyz : Vector.<Number> = new Vector.<Number>; | |
var uv:Vector.<Number> = new Vector.<Number>; | |
var dx:Number = 1 / numColumns; | |
var dy:Number = 1 / numRows; | |
for (var y : int = 0; y < numRows; y++) | |
{ | |
for (var x : int = 0; x < numColumns; x++) | |
{ | |
var v:Number = datas[numColumns * y + x]; | |
var x0:Number = x *dx - .5; | |
var y0:Number = y * dy - .5; | |
var x1:Number = x0+dx; | |
var y1:Number = y0 + dy; | |
if (v == 0) { | |
xyz.push( | |
// back | |
x1, y0, v, x0, y1, v, x1, y1, v, | |
x0, y1, v, x1, y0, v, x0, y0, v); | |
uv.push( | |
// back | |
0., 1., 1., 0., 0., 0., | |
1., 0., 0., 1., 1., 1.); | |
}else { | |
xyz.push( | |
// top | |
x1, y1, v, x0, y1, 0, x1, y1, 0, | |
x1, y1, v, x0, y1, v, x0, y1, 0, | |
// bottom | |
x0, y0, 0, x1, y0, v, x1, y0, 0, | |
x0, y0, v, x1, y0, v, x0, y0, 0, | |
// back | |
x1, y0, v, x0, y1, v, x1, y1, v, | |
x0, y1, v, x1, y0, v, x0, y0, v, | |
// front | |
//x0, y1, 0, x0, y0, 0, x1, y1, 0, | |
//x0, y0, 0, x1, y0, 0, x1, y1, 0, | |
// left | |
x0, y0, 0, x0, y1, v, x0, y0, v, | |
x0, y1, v, x0, y0, 0, x0, y1, 0, | |
// right | |
x1, y0, v, x1, y1, v, x1, y1, 0, | |
x1, y1, 0, x1, y0, 0, x1, y0, v | |
); | |
uv.push(// top | |
1., 0., 0., 1., 1., 1., | |
1., 0., 0., 0., 0., 1., | |
// bottom | |
0., 0., 1., 1., 1., 0., | |
0., 1., 1., 1., 0., 0., | |
// back | |
0., 1., 1., 0., 0., 0., | |
1., 0., 0., 1., 1., 1., | |
// front | |
//0., 0., 0., 1., 1., 0., | |
//0., 1., 1., 1., 1., 0., | |
// left | |
1., 1., 0., 0., 0., 1., | |
0., 0., 1., 1., 1., 0., | |
// right | |
1., 1., 1., 0., 0., 0., | |
0., 0., 0., 1., 1., 1.); | |
} | |
} | |
} | |
super( | |
new <IVertexStream>[VertexStream.fromPositionsAndUVs(xyz, uv, StreamUsage.DYNAMIC)], | |
null | |
); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment