06-fun/scripts/06-02-modelloader.js
/**
 * Entry point of the application.
 */
Entry point of the application.
Entry point of the application .
function main() {
    var c = document.getElementById('c');
    gl = WebGLUtils.setupWebGL( c );
    if(!gl) {
        return;
    }
    window.onresize = reshape;
    window.onkeydown = function(event) {
        if( event.keyCode == 107 || event.keyCode == 187 ) {
            zoomval += 0.1;
            reshape();
        } else if( event.keyCode == 109 || event.keyCode == 189 ) {
            zoomval -= 0.1;
            reshape();
        }
    }
    c.ondragover = function () { 
        this.className = 'hover'; 
        return false; 
    };
    c.ondragend = function () { 
        this.className = ''; 
        return false; 
    };
    c.ondrop = function (e) {
        this.className = '';
        e.preventDefault();
        var file = e.dataTransfer.files[0],
          reader = new FileReader();
        reader.onload = function (event) {
            readDataFile(event.target.result);
        };
        reader.readAsText(file);
        return false;
    };
    var wf = document.getElementById('wireframe');
    var wft = document.getElementById('wireframe-text');
    wf.onclick = function(e) {
        e.preventDefault();
        line = !line;
        wf.className = line ? 'wire' : 'solid'; 
        wft.innerHTML = line ? 'Wireframe Mode' : 'Solid Mode';
        display();
    }
    var lg = document.getElementById('lighting');
    var lgt = document.getElementById('lighting-text');
    lg.onclick = function(e) {
        e.preventDefault();
        lighting = !lighting;
        lg.className = lighting ? 'light' : 'nolight'; 
        lgt.innerHTML = lighting ? 'Lighting Enabled' : 'Lighting Disabled';
        display();
    }
    controller = new CameraController(c);
    controller.onchange = display;
    init();
    display();
}
function main ( ) { var c = document . getElementById ( 'c' ) ; gl = WebGLUtils . setupWebGL ( c ) ; if ( ! gl ) { return ; } window . onresize = reshape ; window . onkeydown = function ( event ) { if ( event . keyCode == 107 || event . keyCode == 187 ) { zoomval += 0.1 ; reshape ( ) ; } else if ( event . keyCode == 109 || event . keyCode == 189 ) { zoomval -= 0.1 ; reshape ( ) ; } } c . ondragover = function ( ) { this . className = 'hover' ; return false ; } ; c . ondragend = function ( ) { this . className = '' ; return false ; } ; c . ondrop = function ( e ) { this . className = '' ; e . preventDefault ( ) ; var file = e . dataTransfer . files [ 0 ] , reader = new FileReader ( ) ; reader . onload = function ( event ) { readDataFile ( event . target . result ) ; } ; reader . readAsText ( file ) ; return false ; } ; var wf = document . getElementById ( 'wireframe' ) ; var wft = document . getElementById ( 'wireframe-text' ) ; wf . onclick = function ( e ) { e . preventDefault ( ) ; line = ! line ; wf . className = line ? 'wire' : 'solid' ; wft . innerHTML = line ? 'Wireframe Mode' : 'Solid Mode' ; display ( ) ; } var lg = document . getElementById ( 'lighting' ) ; var lgt = document . getElementById ( 'lighting-text' ) ; lg . onclick = function ( e ) { e . preventDefault ( ) ; lighting = ! lighting ; lg . className = lighting ? 'light' : 'nolight' ; lgt . innerHTML = lighting ? 'Lighting Enabled' : 'Lighting Disabled' ; display ( ) ; } controller = new CameraController ( c ) ; controller . onchange = display ; init ( ) ; display ( ) ; }
Entry point of the application.
Entry point of the application .
// Get the WebGL canvas, and initialize WebGL // Escape on any error // Setup the window's resize function // On key presses, zoom in or out // If '+' is pressed, zoom in, '-' zoom out // Set the drag over function, // This changes the appearance of the canvas to notify the  // user that something is being dragged over it // Set the drag end function // This resets the appearance of the canvas to notify the // user the drag event has ended // Set the on drop function to actually load in the drag and // dropped data file // Get the dragged file, and create a new FileReader object // Set the onload function called when the file is fully loaded // Read in the file and display the specified model // Finally, start reading in the file, when finished, the onload // function will be called // Initialize a new camera controller that draws the scene // on an update // Initialize all variables and display the scene