Changeset 20584
- Timestamp:
- 04/30/16 12:16:16 (9 years ago)
- Location:
- issm/trunk-jpl/src/m/plot
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/plot/plot_manager.js
r20579 r20584 10 10 checkplotoptions(md,options); 11 11 //get data to be displayed 12 var data=options.getfieldvalue('data'); 13 14 //TODO: Move into webgl.js? 15 function initCanvas() { 16 //standard plot: initialize open Gl for each canvas, if needed: 17 var canvas = $('<div><canvas id="'+options.getfieldvalue('canvasid')+'" width="'+options.getfieldvalue('canvassize',480)+'" height="'+options.getfieldvalue('canvassize',480)+'"></canvas></div>)') 18 canvas.css({'height':String(options.getfieldvalue('canvassize',480)+'px')}); 19 if ($('#'+options.getfieldvalue('canvasid')).length == 0) { 20 canvas.appendTo('body'); 21 } 22 canvas=document.getElementById(options.getfieldvalue('canvasid')); 23 //Initialize the buffer structure when first data is drawn to mesh: 24 canvas.requestDrawing = false; 25 var gl = canvas.gl; 26 if (!canvas.hasOwnProperty("nodes")) { 27 canvas.nodes = {}; 28 canvas.datalength = 0; 29 canvas.requestDrawing = true; 30 //Initialize the GL context: 31 gl = initWebGL(canvas,options); 32 if (!gl) { 33 throw Error("plotmodel error message: could not initialize open Gl!"); 34 } 35 canvas.gl = gl; 36 } 37 canvas.nodes["data"+String(++canvas.datalength)] = Node(gl,options); 38 return canvas; 39 } 40 var canvas = initCanvas(); 12 var data = options.getfieldvalue('data'); 13 var canvas = initCanvas(options); 14 var gl = canvas.gl; 15 //TODO: each plot_ should add their node to the canvas.node array 41 16 42 17 //figure out if this is a special plot -
issm/trunk-jpl/src/m/plot/plot_mesh.js
r20579 r20584 135 135 node["arrays"] = [vertices, colors, indices]; 136 136 node["buffers"] = initBuffers(gl, node["arrays"]); 137 if (canvas.requestDrawing) draw(gl,options,canvas);138 137 } -
issm/trunk-jpl/src/m/plot/plot_overlay.js
r20579 r20584 164 164 /*Initalize buffers: */ 165 165 node["arrays"] = [vertices, texcoords, indices]; 166 node["buffers"] = initBuffers(gl,node["arrays"]); 167 if (canvas.requestDrawing) draw(gl,options,canvas); 166 node["buffers"] = initBuffers(gl,node["arrays"]); 168 167 } -
issm/trunk-jpl/src/m/plot/plot_quiver.js
r20565 r20584 105 105 106 106 xyz2 = vec3.fromValues(vx[i], vy[i], 0.0); 107 magnitude = 100 .0; //mesh resolution107 magnitude = 100000.0; //mesh resolution 108 108 vec3.normalize(direction, xyz2); 109 109 vec3.scale(direction, direction, magnitude); … … 128 128 node["arrays"] = [vertices, colors]; 129 129 node["buffers"] = initBuffers(gl, node["arrays"]); 130 if (canvas.requestDrawing) draw(gl,options,canvas);131 130 } -
issm/trunk-jpl/src/m/plot/plot_unit.js
r20579 r20584 273 273 throw Error(sprintf("%s%i%s\n",'case ',datatype,' not supported')); 274 274 } 275 276 if (canvas.requestDrawing) draw(gl,options,canvas);277 275 } -
issm/trunk-jpl/src/m/plot/plotmodel.js
r19929 r20584 34 34 //go through subplots 35 35 if (numberofplots){ 36 // Clear all canvas nodes36 //Reinitialize all canvases 37 37 for (var i=0;i<numberofplots;i++){ 38 var canvas=document.getElementById(options.list[i].getfieldvalue('canvasid')); 39 if (canvas && canvas.nodes) { 40 delete canvas.nodes; 41 } 38 document.getElementById(options.list[i].getfieldvalue('canvasid')).initialized = false; 42 39 } 43 40 //Go through all data plottable and close window if an error occurs -
issm/trunk-jpl/src/m/plot/webgl.js
r20566 r20584 1 1 /*This is where we have all our webgl relevant functionality for the plotting routines: */ 2 //{{{ GL Initialization 2 //{{{ Canvas Initialization 3 function initCanvas(options) { 4 //Initialize open Gl for each canvas, if needed: 5 var canvas=document.getElementById(options.getfieldvalue('canvasid')); 6 if (!canvas) { 7 canvas = $('<div><canvas id="'+options.getfieldvalue('canvasid')+'" width="'+options.getfieldvalue('canvassize',480)+'" height="'+options.getfieldvalue('canvassize',480)+'"></canvas></div>)') 8 canvas.css({'height':String(options.getfieldvalue('canvassize',480)+'px')}); 9 canvas.appendTo('body'); 10 } 11 if (!canvas.initialized) { 12 canvas.gl = initWebGL(canvas,options); 13 canvas.nodes = {}; 14 canvas.datalength = 0; 15 if (canvas.drawHandler) window.cancelAnimationFrame(canvas.drawHandler); 16 draw(canvas,options); 17 canvas.initialized = true; 18 } 19 canvas.nodes["data"+String(++canvas.datalength)] = Node(canvas.gl,options); 20 return canvas; 21 } 3 22 function initWebGL(canvas,options) { //{{{ 4 gl = null;23 var gl; 5 24 6 25 try { … … 13 32 if (!gl) { 14 33 alert("Unable to initialize WebGL. Your browser may not support it."); 15 gl = null;16 34 } 17 35 … … 34 52 // Add context state variables 35 53 //TODO:Group variables in objects for organization and naming 54 canvas.gl = gl; 36 55 canvas.zoomBounds = options.getfieldvalue('zoombounds',[0.001,100.0]); 37 56 canvas.zoomFactor = clamp(options.getfieldvalue('zoomfactor',1.0), canvas.zoomBounds[0], canvas.zoomBounds[1]); … … 408 427 //Apply projection matrix to get camera matrix 409 428 mat4.multiply(canvas.cameraMatrix, pMatrix, vMatrix); 410 // canvas.cameraMatrix = mat4.create();411 429 }//}}} 412 function drawSceneGraphNode( gl,canvas,node) { //{{{430 function drawSceneGraphNode(canvas,node) { //{{{ 413 431 if (!node["enabled"]) { 414 432 return; … … 419 437 } 420 438 } 439 var gl = canvas.gl; 421 440 bindAttributes(gl, node["shader"], node["buffers"]); 422 441 var mvpMatrix = mat4.create(); … … 458 477 } 459 478 } //}}} 460 function draw(gl,options,canvas,nodes) { //{{{ 479 function draw(canvas,options) { //{{{ 480 if (!canvas.nodes) { 481 canvas.drawHandler = window.requestAnimationFrame(function(time) {draw(canvas,options)}); 482 return; 483 } 461 484 // Ensure canvas and gl viewport sizes are the same 462 485 var displayWidth = canvas.clientWidth; … … 465 488 canvas.width = displayWidth; 466 489 canvas.height = displayHeight; 467 gl.viewport(0, 0, canvas.width, canvas.height);490 canvas.gl.viewport(0, 0, canvas.width, canvas.height); 468 491 } 469 492 … … 473 496 474 497 // Set clear color to black, fully opaque 475 var backgroundcolor=new RGBColor(options.getfieldvalue('backgroundcolor','lightcyan')); 498 var gl = canvas.gl; 499 var backgroundcolor = new RGBColor(options.getfieldvalue('backgroundcolor','lightcyan')); 476 500 if(backgroundcolor.ok){ 477 501 gl.clearColor(backgroundcolor.r/255.0, backgroundcolor.g/255.0, backgroundcolor.b/255.0, 1.0); … … 483 507 for (var node in nodes) { 484 508 if (nodes[node]["texture"] && !nodes[node]["texture"]["isLoaded"]) { 485 window.requestAnimationFrame(function(time) {draw(gl,options,canvas,nodes)});509 canvas.drawHandler = window.requestAnimationFrame(function(time) {draw(canvas,options)}); 486 510 return; 487 511 } … … 489 513 // Else, clear the color as well as the depth buffer for new frame 490 514 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); 491 492 window.requestAnimationFrame(function(time) {draw(gl,options,canvas,nodes)});493 515 494 516 updateCameraMatrix(canvas); … … 498 520 for (var node in nodes) { 499 521 if (nodes[node]["drawOrder"] == i) { 500 drawSceneGraphNode(gl, canvas, nodes[node]); 501 } 502 } 503 } 522 drawSceneGraphNode(canvas,nodes[node]); 523 } 524 } 525 } 526 canvas.drawHandler = window.requestAnimationFrame(function(time) {draw(canvas,options)}); 504 527 } //}}} 505 528 //}}}
Note:
See TracChangeset
for help on using the changeset viewer.