*** ParallelLightObjectsAnim.html Wed Jul 8 20:47:11 2015
--- ParallelLightObjectsAnim2.html Thu Jul 9 13:58:34 2015
***************
*** 43,59 ****
var gl = app.gl;
var obj = [ tsuda.cube, tsuda.pyramid ];
! var i,j;
for (i=0; i<obj.length; i++) {
! obj[i].colorList = [];
! obj[i].colorList[0] = tsuda.get3Float32Array(1.0, 0.0, 0.0, obj[i].vertices.length);
! obj[i].colorList[1] = tsuda.get3Float32Array(0.0, 1.0, 0.0, obj[i].vertices.length);
! obj[i].colorList[2] = tsuda.get3Float32Array(0.0, 0.0, 1.0, obj[i].vertices.length);
! obj[i].colorList[3] = tsuda.get3Float32Array(1.0, 1.0, 0.0, obj[i].vertices.length);
! obj[i].colorList[4] = tsuda.get3Float32Array(1.0, 0.0, 1.0, obj[i].vertices.length);
! obj[i].colorList[5] = tsuda.get3Float32Array(0.0, 1.0, 1.0, obj[i].vertices.length);
! obj[i].colorList[6] = tsuda.get3Float32Array(1.0, 1.0, 1.0, obj[i].vertices.length);
obj[i].normals = tsuda.indexNormals(obj[i].vertices,obj[i].indices);
}
var u_MvpMatrix = gl.getUniformLocation(gl.program,'u_MvpMatrix');
--- 43,78 ----
var gl = app.gl;
var obj = [ tsuda.cube, tsuda.pyramid ];
! var i,j,k;
for (i=0; i<obj.length; i++) {
! var clist = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0], [1.0, 1.0, 0.0],
! [1.0, 0.0, 1.0], [0.0, 1.0, 1.0],[1.0, 1.0, 1.0]];
! obj[i].colorList = new Float32Array(obj[i].vertices.length * 3 * clist.length);
! var idx = 0;
! for (j=0; j<clist.length; j++) {
! for (k=0; k<obj[i].vertices.length; k++) {
! obj[i].colorList[idx++] = clist[j][0];
! obj[i].colorList[idx++] = clist[j][1];
! obj[i].colorList[idx++] = clist[j][2];
! }
! }
obj[i].normals = tsuda.indexNormals(obj[i].vertices,obj[i].indices);
+
+ obj[i].a_Position = tsuda.setArrayBuffer(obj[i].vertices); // prepare buffers for later use
+ obj[i].a_Color = tsuda.setArrayBuffer(obj[i].colorList);
+ obj[i].a_Normal = tsuda.setArrayBuffer(obj[i].normals);
+ obj[i].e_indices = tsuda.setElementArrayBuffer(obj[i].indices);
+ if (obj[i].a_Position == null
+ || obj[i].a_Color == null
+ || obj[i].a_Normal == null
+ || obj[i].e_indices == null) {
+ console.log('cannot create array buffer or element array buffer');
+ console.log(obj[i].a_Position);
+ console.log(obj[i].a_Color);
+ console.log(obj[i].a_Normal);
+ console.log(obj[i].e_indices);
+ return null;
+ }
}
var u_MvpMatrix = gl.getUniformLocation(gl.program,'u_MvpMatrix');
***************
*** 93,99 ****
for (oidx=0; oidx<obj.length; oidx++) {
tsuda.objState[oidx] = [];
for (i=0; i<30; i++) {
! tsuda.objState[oidx][i] = tsuda.randomObjState(10,90,obj[oidx].colorList.length);
}
}
};
--- 112,118 ----
for (oidx=0; oidx<obj.length; oidx++) {
tsuda.objState[oidx] = [];
for (i=0; i<30; i++) {
! tsuda.objState[oidx][i] = tsuda.randomObjState(10,90,clist.length);
}
}
};
***************
*** 101,121 ****
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
var oidx,i;
for (oidx = 0; oidx < tsuda.objState.length; oidx ++) {
! var vertices = obj[oidx].vertices;
! var indices = obj[oidx].indices;
! var normals = obj[oidx].normals;
! var colorList = obj[oidx].colorList;
!
! if (! tsuda.initArrayBuffer('a_Position',vertices,3,gl.FLOAT)) return;
! if (! tsuda.initArrayBuffer('a_Color',colorList[0],3,gl.FLOAT)) return;
! if (! tsuda.initArrayBuffer('a_Normal',normals,3,gl.FLOAT)) return;
!
! if (! tsuda.setElementArrayBuffer(indices)) return;
var states = tsuda.objState[oidx];
for (i=0; i<states.length; i++) {
var state = states[i];
! if (! tsuda.initArrayBuffer('a_Color',colorList[state.c],3,gl.FLOAT)) return;
state.setMatrix(modelMatrix);
state.step();
mvpMatrix.set(projMatrix).multiply(viewMatrix).multiply(modelMatrix);
--- 120,137 ----
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
var oidx,i;
for (oidx = 0; oidx < tsuda.objState.length; oidx ++) {
! gl.bindBuffer(gl.ARRAY_BUFFER,obj[oidx].a_Position); // use buffers prepared before
! tsuda.setAttributeVariable('a_Position',3,gl.FLOAT,0,0);
! gl.bindBuffer(gl.ARRAY_BUFFER,obj[oidx].a_Normal);
! tsuda.setAttributeVariable('a_Normal',3,gl.FLOAT,0,0);
! gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,obj[oidx].e_indices);
var states = tsuda.objState[oidx];
for (i=0; i<states.length; i++) {
var state = states[i];
! gl.bindBuffer(gl.ARRAY_BUFFER,obj[oidx].a_Color);
! tsuda.setAttributeVariable('a_Color',3,gl.FLOAT,0,
! obj[oidx].vertices.length*3*state.c*obj[oidx].colorList.BYTES_PER_ELEMENT);
state.setMatrix(modelMatrix);
state.step();
mvpMatrix.set(projMatrix).multiply(viewMatrix).multiply(modelMatrix);
***************
*** 124,130 ****
normalMatrix.transpose();
gl.uniformMatrix4fv(u_NormalMatrix,false,normalMatrix.elements);
! gl.drawElements(gl.TRIANGLES, indices.length,gl.UNSIGNED_BYTE,0);
}
}
};
--- 140,146 ----
normalMatrix.transpose();
gl.uniformMatrix4fv(u_NormalMatrix,false,normalMatrix.elements);
! gl.drawElements(gl.TRIANGLES, obj[oidx].indices.length,gl.UNSIGNED_BYTE,0);
}
}
};
|