Changeset 19864


Ignore:
Timestamp:
12/07/15 23:23:47 (9 years ago)
Author:
dlcheng
Message:

ADD: javascript: plot_overlay functionality.

Location:
issm/trunk-jpl/src/m/plot
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/plot/plot_manager.js

    r19853 r19864  
    2929       
    3030        //Initialize the buffer structure:
    31         var node = Node(gl,options);
     31        var nodes = {};
     32        nodes["main"] = Node(gl,options);
    3233       
    3334        //figure out if this is a special plot
     
    9596                        case 'mesh':
    9697                                //plot_mesh(md,options,nlines,ncols,i);
    97                                 plot_mesh(md,options,canvas,gl,node);
     98                                plot_mesh(md,options,canvas,gl,nodes["main"]);
    9899                                break;
    99100                        case 'none':
     
    187188
    188189        //Figure out if this is a semi-transparent plot.
    189         if (options.exist('overlay')){
    190                 plot_overlay(md,data,options,nlines,ncols,i);
    191                 return;
     190        if (options.getfieldvalue('overlay','off')=='on'){
     191                nodes["overlay"] = Node(gl,options);
     192                plot_overlay(md,data,options,canvas,gl,nodes["overlay"]);
    192193        }
    193194
     
    218219        if (typeof data !== 'string'){
    219220                //plot unit
    220                 plot_unit(md,data,options,canvas,gl,node);
     221                plot_unit(md,data,options,canvas,gl,nodes["main"]);
    221222        }
    222223
    223224        //applyoptions(md,data2,options);
    224         applyoptions(md,data,options,canvas,gl,node);
     225        applyoptions(md,data,options,canvas,gl,nodes["main"]);
    225226       
    226227        /*Draw into the canvas:*/
    227         draw(gl,options,canvas,node);
     228        draw(gl,options,canvas,nodes);
    228229}
  • issm/trunk-jpl/src/m/plot/plot_unit.js

    r19854 r19864  
    140140        /*Initalize buffers: */
    141141        node["buffers"] = initBuffers(gl,[vertices, texcoords, indices]);
     142        node["overlay"] = false;
    142143}
  • issm/trunk-jpl/src/m/plot/webgl.js

    r19853 r19864  
    2222        // Clear the color as well as the depth buffer.
    2323        gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
     24        // Enable color blending/overlay
     25        gl.enable(gl.BLEND);
    2426
    2527        // Allocate arrays equal to maximium number of attributes used by any one shader
     
    99101} //}}}
    100102function Node(gl,options) { //{{{
    101        
    102         var node;
    103 
    104         node= {buffers:[],
     103        //Returns a Node object that contains default display states for webgl object
     104        return {buffers:[],
    105105                shader:gl.shaders["unlit_textured"]["program"],
    106106                draw:null,
     
    109109                useIndexBuffer:true,
    110110                useOrthographic:false,
    111                 transparency:1.0,
     111                alpha:1.0,
    112112                disableDepthTest:false,
    113113                enableCullFace:false,
     
    120120                modelMatrix:mat4.create(),
    121121                shaderName:"unlit_textured",
     122                overlay:false,
    122123        };
    123        
    124         return node;
    125 
    126124} //}}}
    127125function recalculateModelMatrix(node) { //{{{
     
    210208                '',
    211209                'uniform sampler2D uColorSampler;',
     210                'uniform float uAlpha;',
    212211                '',
    213212                'void main(void) {',
    214                 '       gl_FragColor = texture2D(uColorSampler, vec2(vTextureCoord.s, vTextureCoord.t));',
     213                '       gl_FragColor = vec4(texture2D(uColorSampler, vec2(vTextureCoord.s, vTextureCoord.t)).rgb, uAlpha);',
    215214                '}'].join('\n');
    216215        shaderNames.forEach(function(shaderName){
     
    323322        }
    324323        gl.uniformMatrix4fv(node["shader"]["uMVPMatrix"], false, mvpMatrix);
    325         gl.uniform1f(node["shader"]["uAlpha"], node["transparency"]);
     324        gl.uniform1f(node["shader"]["uAlpha"], node["alpha"]);
    326325        if (node["texture"]) {
    327326                gl.activeTexture(gl.TEXTURE0);
     
    329328                gl.uniform1i(node["shader"]["uColorSampler"], 0);       
    330329        }
    331         if  (node["useIndexBuffer"]) {
     330        if (node["overlay"] == true) {
     331                gl.blendFunc(gl.SRC_ALPHA, gl.ONE);
     332        }
     333        else {
     334                gl.blendFunc (gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
     335        }
     336        if  (node["useIndexBuffer"] == true) {
    332337                gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, node["buffers"][node["buffers"].length - 1]);
    333338                gl.drawElements(node["drawMode"], node["buffers"][node["buffers"].length - 1].numItems, gl.UNSIGNED_SHORT, 0);
     
    350355        }
    351356} //}}}
    352 function draw(gl,options,canvas,node) { //{{{
     357function draw(gl,options,canvas,nodes) { //{{{
    353358
    354359        // Set clear color to black, fully opaque
     
    358363        }
    359364        else throw Error(sprintf("s%s%s\n","initWebGL error message: cound not find out background color for curent canvas ",canvas));
    360        
     365               
    361366        // Clear the color as well as the depth buffer.
    362367        gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
    363368
    364         window.requestAnimationFrame(function(time) {draw(gl,options,canvas,node)});
     369        window.requestAnimationFrame(function(time) {draw(gl,options,canvas,nodes)});
    365370        updateCameraMatrix(canvas);
    366 
    367         drawSceneGraphNode(gl, canvas, node);
     371        for (var node in nodes) {
     372                drawSceneGraphNode(gl, canvas, nodes[node]);
     373        }
    368374} //}}}
    369375//}}}
Note: See TracChangeset for help on using the changeset viewer.