Work around lack of scikits.audiolab support on Python 3.
[mediagoblin.git] / extlib / thingiview.js / plane.js
CommitLineData
47cd2f66
AN
1/**
2 * @author mr.doob / http://mrdoob.com/
3 * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
4 */
5
6var Plane = function ( width, height, segments_width, segments_height ) {
7
8 THREE.Geometry.call( this );
9
10 var ix, iy,
11 width_half = width / 2,
12 height_half = height / 2,
13 gridX = segments_width || 1,
14 gridY = segments_height || 1,
15 gridX1 = gridX + 1,
16 gridY1 = gridY + 1,
17 segment_width = width / gridX,
18 segment_height = height / gridY;
19
20
21 for( iy = 0; iy < gridY1; iy++ ) {
22
23 for( ix = 0; ix < gridX1; ix++ ) {
24
25 var x = ix * segment_width - width_half;
26 var y = iy * segment_height - height_half;
27
28 this.vertices.push( new THREE.Vertex( new THREE.Vector3( x, - y, 0 ) ) );
29
30 }
31
32 }
33
34 for( iy = 0; iy < gridY; iy++ ) {
35
36 for( ix = 0; ix < gridX; ix++ ) {
37
38 var a = ix + gridX1 * iy;
39 var b = ix + gridX1 * ( iy + 1 );
40 var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
41 var d = ( ix + 1 ) + gridX1 * iy;
42
43 this.faces.push( new THREE.Face4( a, b, c, d ) );
44 this.uvs.push( [
45 new THREE.UV( ix / gridX, iy / gridY ),
46 new THREE.UV( ix / gridX, ( iy + 1 ) / gridY ),
47 new THREE.UV( ( ix + 1 ) / gridX, ( iy + 1 ) / gridY ),
48 new THREE.UV( ( ix + 1 ) / gridX, iy / gridY )
49 ] );
50
51 }
52
53 }
54
55 this.computeCentroids();
56 this.computeFaceNormals();
57 this.sortFacesByMaterial();
58
59};
60
61Plane.prototype = new THREE.Geometry();
62Plane.prototype.constructor = Plane;