Changeset 21205
- Timestamp:
- 09/13/16 14:25:35 (9 years ago)
- Location:
- issm/trunk-jpl/src/m/plot
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/plot/applyoptions.js
r21173 r21205 360 360 if (options.getfieldvalue('render',[]).indexOf('sky')!=-1) { 361 361 //atmosphere 362 var node = Node(gl ,options);362 var node = Node(gl); 363 363 canvas.nodes[canvas.nodes.length] = node; 364 364 node["name"] = "atmosphere"; … … 369 369 node["mesh"] = GL.Mesh.icosahedron({size:6371000*atmosphereScale,subdivisions:6}); 370 370 node["useIndexBuffer"] = false; 371 node["rotation"] = [0, 0, 0] 371 node["rotation"] = [0, 0, 0]; 372 372 node["translation"] = translation; 373 373 node["center"] = [0, 0, 0]; … … 376 376 if (options.getfieldvalue('render',[]).indexOf('space')!=-1) { 377 377 //skysphere 378 node = Node(gl ,options);378 node = Node(gl); 379 379 canvas.nodes[canvas.nodes.length] = node; 380 380 node["name"] = "skysphere"; … … 386 386 node["texture"] = initTexture(gl,'../../../js/textures/TychoSkymapII_t4_2k.jpg'); 387 387 node["useIndexBuffer"] = false; 388 node["rotation"] = [0, 0, 0] 388 node["rotation"] = [0, 0, 0]; 389 389 node["translation"] = translation; 390 390 node["center"] = [0, 0, 0]; -
issm/trunk-jpl/src/m/plot/plot_mesh.js
r21173 r21205 59 59 //Compute gl variables: 60 60 var gl = canvas.gl; 61 var node = Node(gl,options); 61 gl.makeCurrent(); 62 var node = Node(gl); 62 63 canvas.nodes[canvas.nodes.length] = node; 63 64 node["name"] = "mesh"; … … 135 136 } 136 137 //}}} 137 node["mesh"] = GL.Mesh.load({vertices:vertices, colors:colors, indices:indices} );138 node["mesh"] = GL.Mesh.load({vertices:vertices, colors:colors, indices:indices}, null, null, gl); 138 139 } -
issm/trunk-jpl/src/m/plot/plot_overlay.js
r21173 r21205 59 59 //Compute gl variables: 60 60 var gl = canvas.gl; 61 var node = Node(gl ,options);61 var node = Node(gl); 62 62 canvas.nodes[canvas.nodes.length] = node; 63 63 node["name"] = "overlay"; … … 159 159 indices[indices.length] = element[2]; 160 160 } 161 node["mesh"] = GL.Mesh.load({vertices:vertices, coords:texcoords, indices:indices} );161 node["mesh"] = GL.Mesh.load({vertices:vertices, coords:texcoords, indices:indices}, null, null, gl); 162 162 } -
issm/trunk-jpl/src/m/plot/plot_quiver.js
r21173 r21205 61 61 //Compute gl variables: 62 62 var gl = canvas.gl; 63 var node = Node(gl ,options);63 var node = Node(gl); 64 64 canvas.nodes[canvas.nodes.length] = node; 65 65 node["name"] = "quiver"; … … 134 134 } 135 135 //}}} 136 node["mesh"] = GL.Mesh.load({vertices:vertices, colors:colors} );136 node["mesh"] = GL.Mesh.load({vertices:vertices, colors:colors}, null, null, gl); 137 137 } -
issm/trunk-jpl/src/m/plot/plot_unit.js
r21173 r21205 61 61 //Compute gl variables: 62 62 var gl = canvas.gl; 63 var node = Node(gl ,options);63 var node = Node(gl); 64 64 canvas.nodes[canvas.nodes.length] = node; 65 65 node["name"] = "unit"; … … 117 117 vertices[vindex++] = vertex[2]; 118 118 119 texcoords[tindex++] = 0. 0;119 texcoords[tindex++] = 0.5; 120 120 texcoords[tindex++] = 0.0; 121 121 continue; 122 122 } 123 123 124 //Scale vertices 124 125 xyz = vec3.fromValues(x[i], y[i], z[i]); … … 131 132 132 133 texcoords[tindex++] = 0.5; 133 texcoords[tindex++] = (data[i] - datamin) / datadelta; 134 texcoords[tindex++] = clamp((data[i] - datamin) / datadelta, 0.0, 1.0); 135 134 136 } 135 137 … … 205 207 for(var j = 0, index = 0; j < x.length; j++){ 206 208 texcoords[i][index++] = 0.5; 207 texcoords[i][index++] = (data[i][j] - datamin) / datadelta;209 texcoords[i][index++] = clamp((data[i][j] - datamin) / datadelta, 0.0, 1.0); 208 210 } 209 211 } … … 248 250 } 249 251 } 250 node["mesh"] = GL.Mesh.load({vertices:vertices, coords:texcoords[0], indices:indices} );252 node["mesh"] = GL.Mesh.load({vertices:vertices, coords:texcoords[0], indices:indices}, null, null, gl); 251 253 break; 252 254 //}}} -
issm/trunk-jpl/src/m/plot/webgl.js
r21173 r21205 1 1 /*This is where we have all our webgl relevant functionality for the plotting routines: */ 2 2 3 3 //{{{ Canvas Initialization 4 4 function initCanvas(options) { … … 7 7 //var canvas = document.getElementById(options.getfieldvalue('canvasid')); 8 8 if (!canvas.initialized) { 9 typedArraySliceSupport(); 9 10 canvas.gl = initWebGL(canvas,options); 10 11 canvas.nodes = []; … … 18 19 var gl; 19 20 try { 20 if (!canvas.gl) gl = GL.create({canvas:canvas}); 21 else gl = canvas.gl; 21 if (!canvas.gl) { 22 gl = GL.create({canvas:canvas}); 23 } 24 else { 25 gl = canvas.gl; 26 } 22 27 } 23 28 catch(e) { … … 25 30 return; 26 31 } 27 32 28 33 // Enable depth testing 29 34 gl.enable(gl.DEPTH_TEST); … … 45 50 canvas.zoom = clamp(options.getfieldvalue('zoom',1.0), canvas.zoomBounds[0], canvas.zoomBounds[1]); 46 51 canvas.zoomLast = canvas.zoom; 52 canvas.cameraPosition = vec3.create(); 47 53 canvas.cameraMatrix = mat4.create(); 48 54 canvas.vInverseMatrix = mat4.create(); 49 canvas.translation = options.getfieldvalue('origin',[0,0,0 .0]);50 canvas.viewPanning = options.getfieldvalue(' viewpanning','off') == 'on';55 canvas.translation = options.getfieldvalue('origin',[0,0,0]); 56 canvas.viewPanning = options.getfieldvalue('enablepanning','off') == 'on'; 51 57 canvas.view = options.getfieldvalue('view',[0,90]); //0 azimuth - up is north, 90 elevation - looking straight down 52 58 canvas.rotation = canvas.view; … … 68 74 var mc = new Hammer.Manager(canvas); 69 75 76 mc.add(new Hammer.Tap()); 70 77 mc.add(new Hammer.Pan({threshold:0, pointers:0})); 71 78 mc.add(new Hammer.Pinch({threshold:0})).recognizeWith(mc.get('pan')); 79 mc.on("tap", function (ev) {onTap(ev,canvas);}); 72 80 mc.on("panstart panmove", function (ev) {onPan(ev,canvas,displayview);}); 73 81 mc.on("pinchstart pinchmove", function (ev) {onPinch(ev,canvas,displayview);}); 74 //mc.on("mousewheel DOMMouseScroll", function (ev) {onZoom(ev,canvas,options);});75 82 76 83 canvas.addEventListener("mousewheel", function (ev) {onZoom(ev,canvas,displayzoom)}, false); … … 80 87 } //}}} 81 88 function initTexture(gl,imageSource) { //{{{ 82 return GL.Texture.fromURL(imageSource, {minFilter:gl.LINEAR_MIPMAP_LINEAR, magFilter:gl.LINEAR} );83 } //}}} 84 function Node(gl ,options) { //{{{89 return GL.Texture.fromURL(imageSource, {minFilter:gl.LINEAR_MIPMAP_LINEAR, magFilter:gl.LINEAR}, null, gl); 90 } //}}} 91 function Node(gl) { //{{{ 85 92 //Returns a Node object that contains default display states for webgl object. center represents pivot point of rotation. 86 93 return { 94 alpha:1.0, 87 95 buffers:[], 96 cullFace:gl.FRONT, 97 disableDepthTest:false, 98 drawMode:gl.TRIANGLES, 99 drawOrder:0, 100 enabled:true, 101 enableCullFace:false, 102 hideOcean:false, 103 lineWidth:1.0, 104 maskEnabled:false, 105 maskHeight:150.0, 106 maskColor:vec4.fromValues(0.0, 0.0, 1.0, 1.0), 107 mesh:null, 88 108 name:"node", 109 shaderName:"Colored", 89 110 shader:gl.shaders["Colored"], 90 draw:null, 91 hideOcean:false, 92 level:0, 111 texture:null, 93 112 useIndexBuffer:true, 94 alpha:1.0, 95 lineWidth:1.0, 96 disableDepthTest:false, 97 enableCullFace:false, 98 cullFace:gl.FRONT, 99 drawMode:gl.TRIANGLES, 100 texture:null, 113 center:vec3.create(), 101 114 scale:vec3.fromValues(1, 1, 1), 102 115 rotation:vec3.create(), 103 116 translation:vec3.create(), 104 center:vec3.create(), 105 modelMatrix:mat4.create(), 106 shaderName:"Colored", 107 drawOrder:0, 108 maskEnabled:false, 109 maskHeight:150.0, 110 maskColor:vec4.fromValues(0.0, 0.0, 1.0, 1.0), 111 enabled:true 117 modelMatrix:mat4.create() 112 118 }; 113 119 } //}}} 114 function d isplayNodes() {115 var nodes = $( '.sim-canvas')[0].nodes;116 console.log( "Nodes:");120 function debugNodes(canvasid) { 121 var nodes = $(canvasid)[0].nodes; 122 console.log(canvasid, "Nodes:"); 117 123 for (var node in nodes) { 118 124 console.log("name", nodes[node]["name"], "translation", nodes[node]["translation"], "center", nodes[node]["center"], "rotation", nodes[node]["rotation"]); 119 125 } 126 return nodes; 120 127 } 121 128 function recalculateModelMatrix(node) { //{{{ 122 //TODO: move to 0,0,0, rotate,move back to normal space, then apply transform123 129 var modelMatrix = mat4.create(); 124 130 … … 145 151 mat4.multiply(modelMatrix, translationMatrix, modelMatrix); 146 152 147 // mat4.identity(translationMatrix);148 // mat4.translate(translationMatrix, translationMatrix, [-node["translation"][0],-node["translation"][1],-node["translation"][2]]); //absolute translation149 // mat4.multiply(modelMatrix, translationMatrix, modelMatrix);150 151 153 mat4.identity(translationMatrix); 152 154 mat4.translate(translationMatrix, translationMatrix, node["translation"]); //absolute translation … … 154 156 return modelMatrix; 155 157 } //}}} 158 function raycast(canvas,mesh,x,y) { //{{{ 159 var raytracer = new GL.Raytracer(canvas.cameraMatrix); 160 var ray = raytracer.getRayForPixel(x, y); 161 if(!mesh || mesh.ready == false) return; 162 if(!mesh.octree) mesh.octree = new GL.Octree(mesh); 163 164 var hit = mesh.octree.testRay(canvas.cameraPosition, ray, 1e2, 1e10); 165 166 if(!hit) return; 167 return hit.pos; 168 } 156 169 function radians (degrees) { //{{{ 157 170 return degrees * Math.PI / 180; … … 170 183 return defaultvalue; 171 184 } //}}} 185 function typedArraySliceSupport() { //{{{ 186 //TypedArray compatibility for Safari/IE 187 if (typeof Int8Array !== 'undefined') { 188 if (!Int8Array.prototype.fill) Int8Array.prototype.fill = Array.prototype.fill; 189 if (!Int8Array.prototype.slice) Int8Array.prototype.slice = Array.prototype.slice; 190 } 191 if (typeof Uint8Array !== 'undefined') { 192 if (!Uint8Array.prototype.fill) Uint8Array.prototype.fill = Array.prototype.fill; 193 if (!Uint8Array.prototype.slice) Uint8Array.prototype.slice = Array.prototype.slice; 194 } 195 if (typeof Uint8ClampedArray !== 'undefined') { 196 if (!Uint8ClampedArray.prototype.fill) Uint8ClampedArray.prototype.fill = Array.prototype.fill; 197 if (!Uint8ClampedArray.prototype.slice) Uint8ClampedArray.prototype.slice = Array.prototype.slice; 198 } 199 if (typeof Int16Array !== 'undefined') { 200 if (!Int16Array.prototype.fill) Int16Array.prototype.fill = Array.prototype.fill; 201 if (!Int16Array.prototype.slice) Int16Array.prototype.slice = Array.prototype.slice; 202 } 203 if (typeof Uint16Array !== 'undefined') { 204 if (!Uint16Array.prototype.fill) Uint16Array.prototype.fill = Array.prototype.fill; 205 if (!Uint16Array.prototype.slice) Uint16Array.prototype.slice = Array.prototype.slice; 206 } 207 if (typeof Int32Array !== 'undefined') { 208 if (!Int32Array.prototype.fill) Int32Array.prototype.fill = Array.prototype.fill; 209 if (!Int32Array.prototype.slice) Int32Array.prototype.slice = Array.prototype.slice; 210 } 211 if (typeof Uint32Array !== 'undefined') { 212 if (!Uint32Array.prototype.fill) Uint32Array.prototype.fill = Array.prototype.fill; 213 if (!Uint32Array.prototype.slice) Uint32Array.prototype.slice = Array.prototype.slice; 214 } 215 if (typeof Float32Array !== 'undefined') { 216 if (!Float32Array.prototype.fill) Float32Array.prototype.fill = Array.prototype.fill; 217 if (!Float32Array.prototype.slice) Float32Array.prototype.slice = Array.prototype.slice; 218 } 219 if (typeof Float64Array !== 'undefined') { 220 if (!Float64Array.prototype.fill) Float64Array.prototype.fill = Array.prototype.fill; 221 if (!Float64Array.prototype.slice) Float64Array.prototype.slice = Array.prototype.slice; 222 } 223 if (typeof TypedArray !== 'undefined') { 224 if (!TypedArray.prototype.fill) TypedArray.prototype.fill = Array.prototype.fill; 225 if (!TypedArray.prototype.slice) TypedArray.prototype.slice = Array.prototype.slice; 226 } 227 } //}}} 172 228 //}}} 173 229 //{{{ Shader Loading 174 230 function loadShaders(gl) { //{{{ 175 shaders = {};176 shaders["Colored"] = new Shader.fromURL("../../../js/shaders/Colored.vsh", "../../../js/shaders/Colored.fsh");177 shaders["Textured"] = new Shader.fromURL("../../../js/shaders/Textured.vsh", "../../../js/shaders/Textured.fsh");178 shaders["SkyFromSpace"] = new Shader.fromURL("../../../js/shaders/SkyFromSpace.vert", "../../../js/shaders/SkyFromSpace.frag");179 shaders["GroundFromSpace"] = new Shader.fromURL("../../../js/shaders/GroundFromSpace.vert", "../../../js/shaders/GroundFromSpace.frag");231 var shaders = {}; 232 shaders["Colored"] = new GL.Shader.fromURL("../../../js/shaders/Colored.vsh", "../../../js/shaders/Colored.fsh", null, gl); 233 shaders["Textured"] = new GL.Shader.fromURL("../../../js/shaders/Textured.vsh", "../../../js/shaders/Textured.fsh", null, gl); 234 shaders["SkyFromSpace"] = new GL.Shader.fromURL("../../../js/shaders/SkyFromSpace.vert", "../../../js/shaders/SkyFromSpace.frag", null, gl); 235 shaders["GroundFromSpace"] = new GL.Shader.fromURL("../../../js/shaders/GroundFromSpace.vert", "../../../js/shaders/GroundFromSpace.frag", null, gl); 180 236 return shaders; 181 237 } //}}} 182 238 //{{{ Interface Functions 239 function onTap(ev,canvas) { //{{{ 240 ev.preventDefault(); 241 if (ev.type == 'panstart') { 242 canvas.lastDeltaX = 0; 243 canvas.lastDeltaY = 0; 244 } 245 } 183 246 function onPan(ev,canvas,displaylog) { //{{{ 184 247 ev.preventDefault(); … … 189 252 if (ev.srcEvent.shiftKey || ev.pointers.length == 2) { 190 253 if (!canvas.viewPanning) return; 191 var deltaX = (canvas.lastDeltaX - ev.deltaX) / canvas.clientWidth / canvas.zoom * -2 * canvas.controlSensitivity * 6371000.0;192 var deltaY = (canvas.lastDeltaY - ev.deltaY) / canvas.clientHeight / canvas.zoom * -2 * canvas.controlSensitivity * 6371000.0;254 var deltaX = (canvas.lastDeltaX - ev.deltaX) / canvas.clientWidth / canvas.zoom * 2 * canvas.controlSensitivity * 6.371e6; 255 var deltaY = (canvas.lastDeltaY - ev.deltaY) / canvas.clientHeight / canvas.zoom * 2 * canvas.controlSensitivity * 6.371e6; 193 256 194 257 if (canvas.twod) { … … 229 292 function onZoom(ev,canvas,displaylog) { //{{{ 230 293 ev.preventDefault(); 231 var delta = clamp(ev.scale || ev.wheelDelta || -ev.detail, -1, 1) * canvas.controlSensitivity * canvas.zoom / 10;294 var delta = clamp(ev.scale || ev.wheelDelta || -ev.detail, -1, 1) * canvas.controlSensitivity * canvas.zoom / 20; 232 295 modifyZoom(canvas.zoom + delta, canvas, displaylog); 233 296 } //}}} … … 247 310 var elevationRotationMatrix = mat4.create(); 248 311 var aspectRatio = canvas.clientWidth / canvas.clientHeight; 312 var cameraPosition = vec3.create(); 249 313 250 314 if (canvas.twod) { 251 mat4.ortho(pMatrix, -aspectRatio*6 371000.0/canvas.zoom, aspectRatio*6371000.0/canvas.zoom, -6371000.0/canvas.zoom, 6371000.0/canvas.zoom, -1.0, 10000000000.0);315 mat4.ortho(pMatrix, -aspectRatio*6.371e6/canvas.zoom, aspectRatio*6.371e6/canvas.zoom, -6.371e6/canvas.zoom, 6.371e6/canvas.zoom, -1.0, 1e10); 252 316 } 253 317 else { 254 mat4.perspective(pMatrix, 60 * Math.PI / 180, aspectRatio, 1 00, 1000000000.0);318 mat4.perspective(pMatrix, 60 * Math.PI / 180, aspectRatio, 1e2, 1e10); 255 319 } 256 320 … … 276 340 //Apply screenspace translation 277 341 mat4.identity(translateMatrix); 278 mat4.translate(translateMatrix, translateMatrix, [0.0, 0.0, -6 371000.0/canvas.zoom]);342 mat4.translate(translateMatrix, translateMatrix, [0.0, 0.0, -6.371e6/canvas.zoom]); 279 343 mat4.multiply(vMatrix, translateMatrix, vMatrix); 280 344 281 //Calculate inverse matrices for lighting345 //Calculate fields for lighting and raycasts 282 346 mat4.invert(canvas.vInverseMatrix, vMatrix); 347 vec3.transformMat4(canvas.cameraPosition, cameraPosition, canvas.vInverseMatrix); 283 348 284 349 //Apply projection matrix to get camera matrix … … 287 352 function drawSceneGraphNode(canvas,node) { //{{{ 288 353 if (!node["enabled"]) return; 354 355 var gl = canvas.gl; 356 gl.makeCurrent(); 289 357 290 358 var mvpMatrix = mat4.create(); … … 302 370 var origin = vec3.fromValues(0, 0, 0); 303 371 var lightOrigin = vec3.fromValues(0, 0, 0); 304 var cameraPosition = vec3.create();372 var cameraPositionRelative = vec3.create(); 305 373 vec3.transformMat4(origin, origin, canvas.vInverseMatrix); 306 374 vec3.normalize(lightOrigin, lightOrigin); 307 vec3.sub(cameraPosition , origin, node["translation"]);308 cameraHeight = vec3.length(cameraPosition );375 vec3.sub(cameraPositionRelative, origin, node["translation"]); 376 cameraHeight = vec3.length(cameraPositionRelative); 309 377 310 378 var atm = { //Default Values … … 328 396 329 397 var inv_wavelength4 = [1.0 / Math.pow(atm.wavelength_r, 4), 1.0 / Math.pow(atm.wavelength_g, 4), 1.0 / Math.pow(atm.wavelength_b, 4)]; 330 var innerRadius = 6 371000.0;398 var innerRadius = 6.371e6; 331 399 var outerRadius = innerRadius*atm.scale; 332 400 var scale = 1.0 / (outerRadius - innerRadius); … … 374 442 } //}}} 375 443 function draw(canvas,options) { //{{{ 444 376 445 // Ensure canvas and gl viewport sizes are the same 377 446 if (canvas.width != canvas.clientWidth || canvas.height != canvas.clientHeight) { … … 389 458 } 390 459 for (var node in nodes) { 391 if (nodes[node]["texture"] && nodes[node]["texture"]["ready"] == false ) {460 if (nodes[node]["texture"] && nodes[node]["texture"]["ready"] == false || nodes[node]["shader"]["ready"] == false) { 392 461 canvas.drawHandler = window.requestAnimationFrame(function(time) {draw(canvas,options)}); 393 462 return; … … 398 467 gl.clearColor(canvas.backgroundcolor[0], canvas.backgroundcolor[1], canvas.backgroundcolor[2], canvas.backgroundcolor[3]); 399 468 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); 469 gl.makeCurrent(); 400 470 401 471 updateCameraMatrix(canvas); … … 407 477 } 408 478 } 479 409 480 canvas.drawHandler = window.requestAnimationFrame(function(time) {draw(canvas,options)}); 410 481 } //}}}
Note:
See TracChangeset
for help on using the changeset viewer.