1 
  2 
  3 function Plane(name, parent){
  4 	SceneNode.call(this, name, parent);
  5 	var tesselationX = 100;
  6 	var tesselationZ = 100;
  7 	this._mesh = null;
  8 	this.tesselationX = tesselationX;
  9 	this.tesselationZ = tesselationZ;
 10 }
 11 
 12 Plane.prototype = new SceneNode(inheriting);
 13 
 14 Object.defineProperty(Plane.prototype, "mesh", {
 15 	get: function(){
 16 		if(this._mesh  == null){
 17 			this._mesh  = new Mesh("plane");
 18 			var subMesh = new SubMesh(this._mesh);
 19 			this._mesh .addSubMesh(subMesh);
 20 			
 21 			
 22 			var vertices = [];
 23 			var normals = [];
 24 			var texCoords = [];
 25 			var indices = [];
 26 			
 27 			for(var x = 0; x <= this.tesselationX; x++){
 28 				for(var z = 0; z <= this.tesselationZ; z++){
 29 					var posX = (x / this.tesselationX) - 0.5;
 30 					var posY = 0;
 31 					var posZ = (z / this.tesselationZ) - 0.5;
 32 					
 33 					vertices.push(posX);
 34 					vertices.push(posY);
 35 					vertices.push(posZ);
 36 
 37 					normals.push(0);
 38 					normals.push(1);
 39 					normals.push(0);
 40 					
 41 					texCoords.push(x / this.tesselationX);
 42 					texCoords.push(z / this.tesselationZ);
 43 				}
 44 			}
 45 			
 46 			for(var x = 0; x < this.tesselationX; x++){
 47 				for(var z = 0; z < this.tesselationZ; z++){
 48 					var zOffset = x*(this.tesselationZ+1);
 49 					indices.push(zOffset + z);
 50 					indices.push(zOffset + z + 1);
 51 					indices.push((x+1)*(this.tesselationZ+1) + z);
 52 					
 53 					indices.push((x+1)*(this.tesselationZ+1) + z);
 54 					indices.push(zOffset + z + 1);
 55 					indices.push((x+1)*(this.tesselationZ+1) + z+1);
 56 				}
 57 			}
 58 			
 59 			
 60 			subMesh.setVertexBufferData("POSITION", new Float32Array(vertices));
 61 			subMesh.setVertexBufferData("NORMAL", new Float32Array(normals));
 62 			subMesh.setVertexBufferData("TEXCOORD_0", new Float32Array(texCoords));
 63 			subMesh.setIndexBufferData(new Uint16Array(indices));
 64 			
 65 			var material = MaterialManager.getMaterial("default");
 66 			this._mesh.setMaterial(material);
 67 		}
 68 		
 69 		return this._mesh;
 70 	}
 71 });
 72 
 73 Plane.prototype.render = function(renderQueue, camera){
 74 	this.mesh.render(this, renderQueue, camera);
 75 };