CSC 4356/prog7/prog7.js
/**
* Object representing a 3D webGl model with the use of input
* parameter that uses JSON data needed
*/
Object representing a 3D webGl model with the use of input
parameter that uses JSON data needed
Object representing a 3D webGl model with the use of input parameter that uses JSON data needed
function Model(input){
    var positionArray = new Float32Array(flatten(input.positions));
    var triangleArray = new Uint16Array(flatten(input.triangles));
    var normalArray   = new Float32Array(flatten(input.normals));
    var texCoordArray = new Float32Array(flatten(input.texCoords));
    this.positionBuffer = gl.createBuffer();
    this.triangleBuffer  = gl.createBuffer();
    this.normalBuffer    = gl.createBuffer();
    this.texCoordBuffer = gl.createBuffer();
    gl.bindBuffer(gl.ARRAY_BUFFER, this.positionBuffer);
    gl.bufferData(gl.ARRAY_BUFFER, positionArray, gl.STATIC_DRAW);
    gl.bindBuffer(gl.ARRAY_BUFFER, this.normalBuffer);
    gl.bufferData(gl.ARRAY_BUFFER, normalArray,   gl.STATIC_DRAW);
    gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.triangleBuffer);
    gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, triangleArray, gl.STATIC_DRAW);
    this.triangleArrayLength = triangleArray.length;
    gl.bindBuffer(gl.ARRAY_BUFFER, this.texCoordBuffer);
    gl.bufferData(gl.ARRAY_BUFFER, texCoordArray, gl.STATIC_DRAW);
    this.triangleArrayLength = triangleArray.length;
}
function Model ( input ) { var positionArray = new Float32Array ( flatten ( input . positions ) ) ; var triangleArray = new Uint16Array ( flatten ( input . triangles ) ) ; var normalArray = new Float32Array ( flatten ( input . normals ) ) ; var texCoordArray = new Float32Array ( flatten ( input . texCoords ) ) ; this . positionBuffer = gl . createBuffer ( ) ; this . triangleBuffer = gl . createBuffer ( ) ; this . normalBuffer = gl . createBuffer ( ) ; this . texCoordBuffer = gl . createBuffer ( ) ; gl . bindBuffer ( gl . ARRAY_BUFFER , this . positionBuffer ) ; gl . bufferData ( gl . ARRAY_BUFFER , positionArray , gl . STATIC_DRAW ) ; gl . bindBuffer ( gl . ARRAY_BUFFER , this . normalBuffer ) ; gl . bufferData ( gl . ARRAY_BUFFER , normalArray , gl . STATIC_DRAW ) ; gl . bindBuffer ( gl . ELEMENT_ARRAY_BUFFER , this . triangleBuffer ) ; gl . bufferData ( gl . ELEMENT_ARRAY_BUFFER , triangleArray , gl . STATIC_DRAW ) ; this . triangleArrayLength = triangleArray . length ; gl . bindBuffer ( gl . ARRAY_BUFFER , this . texCoordBuffer ) ; gl . bufferData ( gl . ARRAY_BUFFER , texCoordArray , gl . STATIC_DRAW ) ; this . triangleArrayLength = triangleArray . length ; }
Object representing a 3D webGl model with the use of input
parameter that uses JSON data needed
Object representing a 3D webGl model with the use of input parameter that uses JSON data needed
//Instantiate arrays //Create Buffers //Copy vertex data to GPU //Copy normal data to GPU //Copy triangle data to GPU //Copy texture data to GPU