Added mipmapping.
1 function Node(position, rotation, geometry)
5 this.geometry = geometry;
8 Node.prototype.update = function(time)
10 // this.right = [1, 0, 0];
11 // this.up = [0, 1, 0];
12 // this.target = [0, 0, -1];
13 // var x = vec3.dot([1, 0, 0], this.pos);
14 // var y = vec3.dot([0, 1, 0], this.pos);
15 // var z = vec3.dot([0, 0, -1], this.pos);
16 // this.matrix = mat4.create([this.right[0], this.up[0], -this.target[0], 0,
17 // this.right[1], this.up[1], -this.target[1], 0,
18 // this.right[2], this.up[2], -this.target[2], 0,
20 for (var id in this.children) this.children[id].update(time);
23 function CubeVbo(size, context, texture)
26 this.texture = texture;
27 this.useTexture = texture;
28 this.size = size || 1;
29 this.positionBuffer = gl.createBuffer();
30 gl.bindBuffer(gl.ARRAY_BUFFER, this.positionBuffer);
67 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW);
68 this.positionBuffer.itemSize = 3;
69 this.positionBuffer.numItems = 24;
71 this.normalBuffer = gl.createBuffer();
72 gl.bindBuffer(gl.ARRAY_BUFFER, this.normalBuffer);
73 var normals = [// font face
103 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(normals), gl.STATIC_DRAW);
104 this.normalBuffer.itemSize = 3;
105 this.normalBuffer.numItems = 24;
109 this.textureCoordBuffer = gl.createBuffer();
110 gl.bindBuffer(gl.ARRAY_BUFFER, this.textureCoordBuffer);
111 var textureCoords = [// front face
141 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(textureCoords), gl.STATIC_DRAW);
142 this.textureCoordBuffer.itemSize = 2;
143 this.textureCoordBuffer.numItems = 24;
146 this.colourBuffer = gl.createBuffer();
147 gl.bindBuffer(gl.ARRAY_BUFFER, this.colourBuffer);
149 var uni = [1.0, 1.0, 1.0, alpha];
150 var colours = [[0.0, 0.0, 0.0, alpha],
151 [0.0, 0.0, 0.0, alpha],
152 [0.0, 0.0, 0.0, alpha],
153 [0.0, 0.0, 0.0, alpha],
154 [0.0, 0.0, 0.0, alpha],
155 [0.0, 0.0, 0.0, alpha]];
156 var unpackedColours = [];
157 for (var i in colours)
159 var colour = uni;//colours[i];
160 for (var j = 0; j < 4; j++)
162 unpackedColours = unpackedColours.concat(colour);
164 //colours = colours.concat([0.5, 0.5, 1.0, 1.0]);
166 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(unpackedColours), gl.STATIC_DRAW);
167 this.colourBuffer.itemSize = 4;
168 this.colourBuffer.numItems = 24;
170 this.indexBuffer = gl.createBuffer();
171 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
172 var indices = [0, 1, 2, 0, 2, 3,
175 12, 13, 14, 12, 14, 15,
176 16, 17, 18, 16, 18, 19,
177 20, 21, 22, 20, 22, 23];
178 gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(indices), gl.STATIC_DRAW);
179 this.indexBuffer.itemSize = 1;
180 this.indexBuffer.numItems = 36;