瀏覽代碼

Add Grid.addUVs() (#312)

trethaller 7 年之前
父節點
當前提交
8124a24511
共有 1 個文件被更改,包括 22 次插入0 次删除
  1. 22 0
      h3d/prim/Grid.hx

+ 22 - 0
h3d/prim/Grid.hx

@@ -2,7 +2,13 @@ package h3d.prim;
 
 
 class Grid extends Polygon {
 class Grid extends Polygon {
 
 
+	var width : Int;
+	var height : Int;
+
 	public function new( width : Int, height : Int, cellWidth = 1., cellHeight = 1. ) {
 	public function new( width : Int, height : Int, cellWidth = 1., cellHeight = 1. ) {
+		this.width = width;
+		this.height = height;
+
 		var idx = new hxd.IndexBuffer();
 		var idx = new hxd.IndexBuffer();
 		for( y in 0...height )
 		for( y in 0...height )
 			for( x in 0...width ) {
 			for( x in 0...width ) {
@@ -20,4 +26,20 @@ class Grid extends Polygon {
 		);
 		);
 	}
 	}
 
 
+	override function addUVs() {
+		unindex();
+		uvs = [];
+		for( y in 0...height ) {
+			for( x in 0...width ) {
+				uvs.push(new UV(x/width,     y/height));
+				uvs.push(new UV((x+1)/width, y/height));
+				uvs.push(new UV(x/width,     (y+1)/height));
+
+				uvs.push(new UV((x+1)/width, y/height));
+				uvs.push(new UV((x+1)/width, (y+1)/height));
+				uvs.push(new UV(x/width,     (y+1)/height));				
+			}
+		}
+	}
+
 }
 }