Changeset 22758 for issm/trunk/src/m/plot/plot_quiver.js
- Timestamp:
- 05/10/18 10:24:27 (7 years ago)
- Location:
- issm/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk
- Property svn:mergeinfo changed
-
issm/trunk/src
- Property svn:mergeinfo changed
-
issm/trunk/src/m/plot/plot_quiver.js
r21729 r22758 1 function plot_quiver(md, options, canvas, updateVel) { //{{{1 function plot_quiver(md, options, canvas, noCacheNodesOverride) { //{{{ 2 2 //PLOT_QUIVER - quiver plot with colors 3 3 // … … 7 7 // See also: PLOTMODEL, PLOT_MANAGER 8 8 9 //Disabling for now, since quivers are "sticky" - once turned on, they won't turn off. This is due to cachenodes, but should find better way to handle it. 10 return; 11 12 if ('quiver' in canvas.nodes && noCacheNodesOverride && options.getfieldvalue('cachenodes','on') === 'on') return; 13 9 14 //{{{ declare variables: 10 var vertices = [];11 var indices = [];12 var colors = [];13 var xmin, xmax;14 var ymin, ymax;15 var zmin, zmax;16 var scale, matrixscale, vertexscale;17 18 15 //Process data and model 19 var meshresults = processmesh(md,[], options); 20 16 var meshresults = processmesh(md, [], options); 21 17 var x = meshresults[0]; 22 18 var y = meshresults[1]; … … 25 21 var is2d = meshresults[4]; 26 22 var isplanet = meshresults[5]; 27 var v = updateVel != undefined ? updateVel.vel : md.initialization.vel; 28 var vx = updateVel != undefined ? updateVel.vx : md.initialization.vx; 29 var vy = updateVel != undefined ? updateVel.vy : md.initialization.vy; 23 if (md.mesh.classname() !== 'mesh3dsurface') z = md.geometry.surface; 30 24 31 //Compue scaling through matrices for 2d meshes and vertices for 3d meshes 32 if (!md.geometry.surface) { 33 md.geometry.surface=NewArrayFill(md.mesh.x.length, 0); 34 } 35 if (md.mesh.classname() == 'mesh3dsurface') { 36 matrixscale = 1; 37 vertexscale = options.getfieldvalue('heightscale', 1); 25 //Compute coordinates and data range: 26 var xlim = options.getfieldvalue('xlim', [ArrayMin(x), ArrayMax(x)]); 27 var ylim = options.getfieldvalue('ylim', [ArrayMin(y), ArrayMax(y)]); 28 var zlim = options.getfieldvalue('zlim', [ArrayMin(z), ArrayMax(z)]); 29 30 //Only displaying velocity fields for now 31 var v = VESL.Helpers.isEmptyOrUndefined(md.results) ? md.initialization.vel : md.results[canvas.animation.frame].Vel; 32 var vx = VESL.Helpers.isEmptyOrUndefined(md.results) ? md.initialization.vx : md.results[canvas.animation.frame].Vx; 33 var vy = VESL.Helpers.isEmptyOrUndefined(md.results) ? md.initialization.vy : md.results[canvas.animation.frame].Vy; 34 35 //Handle heightscale 36 var vertices, scale; 37 if (md.mesh.classname() !== 'mesh3dsurface') { 38 vertices = [x, y, z]; 39 scale = [1, 1, options.getfieldvalue('heightscale', 1)]; 38 40 } 39 41 else { 40 if (md.geometry.surface) { 41 z=md.geometry.surface; 42 } 43 matrixscale = options.getfieldvalue('heightscale', 1); 44 vertexscale = 0; 42 vertices = Node.prototype.scaleVertices(md, x, y, z, elements, options.getfieldvalue('heightscale', 1), options.getfieldvalue('maskregion',{'enabled':false})); 43 scale = [1, 1, 1]; 45 44 } 46 //}}} 47 48 //Compute coordinates and data range: 49 var modelxlim = [ArrayMin(x), ArrayMax(x)]; 50 var modelylim = [ArrayMin(y), ArrayMax(y)]; 51 var modelzlim = [ArrayMin(z), ArrayMax(z)]; 52 var xlim = options.getfieldvalue('xlim', modelxlim); 53 var ylim = options.getfieldvalue('ylim', modelylim); 54 var zlim = options.getfieldvalue('zlim', modelzlim); 55 xmin = xlim[0]; 56 xmax = xlim[1]; 57 ymin = ylim[0]; 58 ymax = ylim[1]; 59 zmin = zlim[0]; 60 zmax = zlim[1]; 61 45 62 46 //Compute gl variables: 63 var gl = canvas.gl; 64 var node = Node(gl); 65 canvas.nodes["velocity"] = node; 66 node.name = "quiver"; 67 node.shaderName = "Colored"; 68 node.shader = gl.shaders[node.shaderName]; 69 node.lineWidth = options.getfieldvalue('linewidth', 1); 70 node.scale = [1, 1, matrixscale]; 71 node.rotation = [-90, 0, 0]; 72 node.translation = [0, 0, 0]; 73 node.center = [(xmin + xmax) / 2, (ymin + ymax) / 2, (zmin + zmax) / 2]; 74 node.drawMode = gl.LINES; 75 node.useIndexBuffer = false; 76 node.drawOrder = 0; 77 node.maskEnabled = options.getfieldvalue('innermask','off') == 'on'; 78 node.maskHeight = options.getfieldvalue('innermaskheight', 150.0)*options.getfieldvalue('heightscale', 1); 79 node.maskColor = options.getfieldvalue('innermaskcolor',[0.0, 0.0, 1.0, 1.0]); 80 updateModelMatrix(node); 81 82 //retrieve some options 83 var edgecolor=new RGBColor(options.getfieldvalue('edgecolor','black')); 84 if (edgecolor.ok) edgecolor = [edgecolor.r/255.0, edgecolor.g/255.0, edgecolor.b/255.0, 1.0]; 85 else throw Error(sprintf("s%s%s\n","initWebGL error message: cound not find out edgecolor color for curent canvas ", canvas)); 86 47 var edgecolor = options.getfieldvalue('edgecolor', 'black'); 48 var node = new Node( 49 'canvas', canvas, 50 'options', options, 51 'name', 'quiver', 52 'shaderName', 'Colored', 53 'alpha', options.getfieldvalue('alpha', 1.0), 54 //'center', [(xlim[0] + xlim[1]) / 2, (ylim[0] + ylim[1]) / 2, md.mesh.classname() === 'mesh3dsurface' ? (zlim[0] + zlim[1]) / 2 : zlim[0]], 55 'center', [(xlim[0] + xlim[1]) / 2, (ylim[0] + ylim[1]) / 2, (zlim[0] + zlim[1]) / 2], 56 'drawMode', canvas.gl.LINES, 57 'diffuseColor', edgecolor, 58 'lineWidth', options.getfieldvalue('linewidth', 1), 59 'maskEnabled', options.getfieldvalue('innermask','off') == 'on', 60 'maskHeight', options.getfieldvalue('innermaskheight', 150.0) / options.getfieldvalue('heightscale', 1), 61 'maskColor', options.getfieldvalue('innermaskcolor',[0.0, 0.0, 1.0, 1.0]), 62 'rotation', [-90, 0, 0], 63 'scale', scale 64 ); 65 66 87 67 //{{{ node plot 88 68 if (elements[0].length==6){ //prisms … … 91 71 } 92 72 else{ //2D triangular elements 73 //Create arow vertices, and use vx/vy to determine rotation before adding to quiver mesh. 74 var verticesArrow = [vec3.fromValues(0.0, 0.0, 0.0), vec3.fromValues(1.0, 0.0, 0.0), vec3.fromValues(0.667, -0.167, 0.0), vec3.fromValues(1.0, 0.0, 0.0), vec3.fromValues(0.667, 0.166, 0.0), vec3.fromValues(1.0, 0.0, 0.0)]; 75 76 var newX = []; 77 var newY = []; 78 var newZ = []; 93 79 var xyz = vec3.create(); 94 var xyz = vec3.create();95 var direction = vec3.create();96 80 var vertex = vec3.create(); 97 var vertexBase = vec3.create();98 var verticesArrow = [vec3.fromValues(0.0, 0.0, 0.0), vec3.fromValues(1.0, 0.0, 0.0), vec3.fromValues(0.667, -0.167, 0.0), vec3.fromValues(1.0, 0.0, 0.0), vec3.fromValues(0.667, 0.166, 0.0), vec3.fromValues(1.0, 0.0, 0.0)];99 var magnitude;100 var color = edgecolor;101 81 var scaling = options.getfieldvalue('scaling', 1); 102 var scale; 103 for(var i = 0; i < x.length; i++){ 104 //Check for NaN values and remove from indices array as necessary, but preserve vertex array spacing 105 if (isNaN(x[i]) || isNaN(y[i]) || isNaN(z[i])) continue; 106 //Scale vertices 82 var heightScale = options.getfieldvalue('heightscale', 1); 83 var arrowScale; 84 var modelMatrix = mat4.create(); 85 var scaleMatrix = mat4.create(); 86 var rotationMatrix = mat4.create(); 87 88 for(var i = 0, iX = 0, iY = 0, iZ = 0; i < x.length; i++){ 107 89 xyz = vec3.fromValues(x[i], y[i], z[i]); 108 magnitude = vec3.length(xyz) + md.geometry.surface[i] * vertexscale; 109 vec3.normalize(direction, xyz); 110 vec3.scale(vertex, direction, magnitude); 111 vec3.copy(vertexBase, vertex); 112 113 scale = scaling*v[i]; 114 var modelMatrix = mat4.create(); 115 var scaleMatrix = mat4.create(); 116 var rotationMatrix = mat4.create(); 117 mat4.scale(scaleMatrix, scaleMatrix, vec3.fromValues(scale, scale, scale)); 118 mat4.rotate(rotationMatrix, rotationMatrix, Math.atan2(vy[i], vx[i]), [0.0, 0.0, 1.0]); 90 arrowScale = v[i] * scaling; 91 scaleMatrix = mat4.create(); 92 mat4.scale(scaleMatrix, mat4.create(), vec3.fromValues(arrowScale, arrowScale, arrowScale)); 93 mat4.rotate(rotationMatrix, mat4.create(), Math.atan2(vy[i], vx[i]), [0.0, 0.0, 1.0]); 119 94 mat4.multiply(modelMatrix, rotationMatrix, scaleMatrix); 120 121 var temp = vec3.fromValues(0.0, 0.0, 0.0);122 95 for (var j = 0; j < 6; j++){ 123 96 vec3.transformMat4(vertex, verticesArrow[j], modelMatrix); 124 vec3.add(vertex, vertex, vertexBase); 125 vertices[vertices.length] = vertex[0]; 126 vertices[vertices.length] = vertex[1]; 127 vertices[vertices.length] = vertex[2]; 128 129 colors[colors.length] = color[0]; 130 colors[colors.length] = color[1]; 131 colors[colors.length] = color[2]; 132 colors[colors.length] = color[3]; 97 vec3.add(vertex, vertex, xyz); 98 newX[iX++] = vertex[0]; 99 newY[iY++] = vertex[1]; 100 newZ[iZ++] = vertex[2]; 133 101 } 134 102 } 103 node.patch('Vertices', [newX, newY, newZ], 'FaceColor', 'none'); 135 104 } 136 105 //}}} 137 node.mesh = GL.Mesh.load({vertices: vertices, colors: colors}, null, null, gl);138 106 } //}}}
Note:
See TracChangeset
for help on using the changeset viewer.