From d656a469a0fc1bc907a0ed373bf0bcb2edaf79e9 Mon Sep 17 00:00:00 2001 From: archmoj Date: Tue, 15 Oct 2019 17:36:34 -0400 Subject: [PATCH] reuse cone create_mesh - drop unused contours - no need for lines and points - remove unused texture argument as well as vertexUVs, cellUVs and cellIntensity --- lib/tubemesh.js | 908 ---------------------------------------------- package-lock.json | 109 ++---- package.json | 12 +- streamtube.js | 9 +- 4 files changed, 41 insertions(+), 997 deletions(-) delete mode 100644 lib/tubemesh.js diff --git a/lib/tubemesh.js b/lib/tubemesh.js deleted file mode 100644 index 9b7467a..0000000 --- a/lib/tubemesh.js +++ /dev/null @@ -1,908 +0,0 @@ -'use strict' - -var createShader = require('gl-shader') -var createBuffer = require('gl-buffer') -var createVAO = require('gl-vao') -var createTexture = require('gl-texture2d') -var multiply = require('gl-mat4/multiply') -var invert = require('gl-mat4/invert') -var ndarray = require('ndarray') -var colormap = require('colormap') -var getContour = require('simplicial-complex-contour') -var pool = require('typedarray-pool') -var shaders = require('./shaders') - -var meshShader = shaders.meshShader -var pickShader = shaders.pickShader - -var IDENTITY = [ - 1,0,0,0, - 0,1,0,0, - 0,0,1,0, - 0,0,0,1] - -function SimplicialMesh(gl - , texture - , triShader - , pickShader - , trianglePositions - , triangleVectors - , triangleIds - , triangleColors - , triangleUVs - , triangleVAO - , edgePositions - , edgeIds - , edgeColors - , edgeUVs - , edgeVAO - , pointPositions - , pointIds - , pointColors - , pointUVs - , pointSizes - , pointVAO - , contourPositions - , contourVAO) { - - this.gl = gl - this.cells = [] - this.positions = [] - this.intensity = [] - this.texture = texture - this.dirty = true - - this.triShader = triShader - this.pickShader = pickShader - - this.trianglePositions = trianglePositions - this.triangleVectors = triangleVectors - this.triangleColors = triangleColors - this.triangleUVs = triangleUVs - this.triangleIds = triangleIds - this.triangleVAO = triangleVAO - this.triangleCount = 0 - - this.lineWidth = 1 - this.edgePositions = edgePositions - this.edgeColors = edgeColors - this.edgeUVs = edgeUVs - this.edgeIds = edgeIds - this.edgeVAO = edgeVAO - this.edgeCount = 0 - - this.pointPositions = pointPositions - this.pointColors = pointColors - this.pointUVs = pointUVs - this.pointSizes = pointSizes - this.pointIds = pointIds - this.pointVAO = pointVAO - this.pointCount = 0 - - this.contourLineWidth = 1 - this.contourPositions = contourPositions - this.contourVAO = contourVAO - this.contourCount = 0 - this.contourColor = [0,0,0] - this.contourEnable = false - - this.pickId = 1 - this.bounds = [ - [ Infinity, Infinity, Infinity], - [-Infinity,-Infinity,-Infinity] ] - this.clipBounds = [ - [-Infinity,-Infinity,-Infinity], - [ Infinity, Infinity, Infinity] ] - - this.lightPosition = [1e5, 1e5, 0] - this.ambientLight = 0.8 - this.diffuseLight = 0.8 - this.specularLight = 2.0 - this.roughness = 0.5 - this.fresnel = 1.5 - - this.opacity = 1.0 - - this.tubeScale = 1.0 - - this._model = IDENTITY - this._view = IDENTITY - this._projection = IDENTITY - this._resolution = [1,1] - this.pixelRatio = 1 -} - -var proto = SimplicialMesh.prototype - -proto.isOpaque = function() { - return this.opacity >= 1 -} - -proto.isTransparent = function() { - return this.opacity < 1 -} - -proto.pickSlots = 1 - -proto.setPickBase = function(id) { - this.pickId = id -} - -function genColormap(param) { - var colors = colormap({ - colormap: param - , nshades: 256 - , format: 'rgba' - }) - - var result = new Uint8Array(256*4) - for(var i=0; i<256; ++i) { - var c = colors[i] - for(var j=0; j<3; ++j) { - result[4*i+j] = c[j] - } - result[4*i+3] = c[3]*255 - } - - return ndarray(result, [256,256,4], [4,0,1]) -} - -function unpackIntensity(cells, numVerts, cellIntensity) { - var result = new Array(numVerts) - for(var i=0; i 0) { - var shader = this.triShader - shader.bind() - shader.uniforms = uniforms - - this.triangleVAO.bind() - gl.drawArrays(gl.TRIANGLES, 0, this.triangleCount*3) - this.triangleVAO.unbind() - } -} - -proto.drawPick = function(params) { - params = params || {} - - var gl = this.gl - - var model = params.model || IDENTITY - var view = params.view || IDENTITY - var projection = params.projection || IDENTITY - - var clipBounds = [[-1e6,-1e6,-1e6],[1e6,1e6,1e6]] - for(var i=0; i<3; ++i) { - clipBounds[0][i] = Math.max(clipBounds[0][i], this.clipBounds[0][i]) - clipBounds[1][i] = Math.min(clipBounds[1][i], this.clipBounds[1][i]) - } - - //Save camera parameters - this._model = [].slice.call(model) - this._view = [].slice.call(view) - this._projection = [].slice.call(projection) - this._resolution = [gl.drawingBufferWidth, gl.drawingBufferHeight] - - var uniforms = { - model: model, - view: view, - projection: projection, - clipBounds: clipBounds, - - tubeScale: this.tubeScale, - - pickId: this.pickId / 255.0, - } - - var shader = this.pickShader - shader.bind() - shader.uniforms = uniforms - - if(this.triangleCount > 0) { - this.triangleVAO.bind() - gl.drawArrays(gl.TRIANGLES, 0, this.triangleCount*3) - this.triangleVAO.unbind() - } - - if(this.edgeCount > 0) { - this.edgeVAO.bind() - gl.lineWidth(this.lineWidth * this.pixelRatio) - gl.drawArrays(gl.LINES, 0, this.edgeCount*2) - this.edgeVAO.unbind() - } - -} - - -proto.pick = function(pickData) { - if(!pickData) { - return null - } - if(pickData.id !== this.pickId) { - return null - } - - var cellId = pickData.value[0] + 256*pickData.value[1] + 65536*pickData.value[2] - var cell = this.cells[cellId] - - var pos = this.positions[cell[1]].slice(0, 3) - var intensity = this.intensity[cell[1]] - var velocity = this.vectors[cell[1]].slice(0, 3) - var divergence = this.vectors[cell[1]][3] - - return { - index: cellId, - position: pos, - intensity: intensity, - velocity: velocity, - divergence: divergence, - dataCoordinate: pos - } -} - - -proto.dispose = function() { - this.texture.dispose() - - this.triShader.dispose() - this.pickShader.dispose() - - this.triangleVAO.dispose() - this.trianglePositions.dispose() - this.triangleVectors.dispose() - this.triangleColors.dispose() - this.triangleUVs.dispose() - this.triangleIds.dispose() - - this.edgeVAO.dispose() - this.edgePositions.dispose() - this.edgeColors.dispose() - this.edgeUVs.dispose() - this.edgeIds.dispose() - - this.pointVAO.dispose() - this.pointPositions.dispose() - this.pointColors.dispose() - this.pointUVs.dispose() - this.pointSizes.dispose() - this.pointIds.dispose() - - this.contourVAO.dispose() - this.contourPositions.dispose() -} - -function createMeshShader(gl) { - var shader = createShader(gl, meshShader.vertex, meshShader.fragment, null, meshShader.attributes) - shader.attributes.position.location = 0 - shader.attributes.color.location = 2 - shader.attributes.uv.location = 3 - shader.attributes.vector.location = 4 - return shader -} - - -function createPickShader(gl) { - var shader = createShader(gl, pickShader.vertex, pickShader.fragment, null, pickShader.attributes) - shader.attributes.position.location = 0 - shader.attributes.id.location = 1 - shader.attributes.vector.location = 4 - return shader -} - - -function createSimplicialMesh(gl, params) { - if (arguments.length === 1) { - params = gl; - gl = params.gl; - } - - var triShader = params.triShader || createMeshShader(gl) - var pickShader = createPickShader(gl) - - var meshTexture = createTexture(gl, - ndarray(new Uint8Array([255,255,255,255]), [1,1,4])) - meshTexture.generateMipmap() - meshTexture.minFilter = gl.LINEAR_MIPMAP_LINEAR - meshTexture.magFilter = gl.LINEAR - - var trianglePositions = createBuffer(gl) - var triangleVectors = createBuffer(gl) - var triangleColors = createBuffer(gl) - var triangleUVs = createBuffer(gl) - var triangleIds = createBuffer(gl) - var triangleVAO = createVAO(gl, [ - { buffer: trianglePositions, - type: gl.FLOAT, - size: 4 - }, - { buffer: triangleIds, - type: gl.UNSIGNED_BYTE, - size: 4, - normalized: true - }, - { buffer: triangleColors, - type: gl.FLOAT, - size: 4 - }, - { buffer: triangleUVs, - type: gl.FLOAT, - size: 2 - }, - { buffer: triangleVectors, - type: gl.FLOAT, - size: 4 - } - ]) - - var edgePositions = createBuffer(gl) - var edgeColors = createBuffer(gl) - var edgeUVs = createBuffer(gl) - var edgeIds = createBuffer(gl) - var edgeVAO = createVAO(gl, [ - { buffer: edgePositions, - type: gl.FLOAT, - size: 3 - }, - { buffer: edgeIds, - type: gl.UNSIGNED_BYTE, - size: 4, - normalized: true - }, - { buffer: edgeColors, - type: gl.FLOAT, - size: 4 - }, - { buffer: edgeUVs, - type: gl.FLOAT, - size: 2 - } - ]) - - var pointPositions = createBuffer(gl) - var pointColors = createBuffer(gl) - var pointUVs = createBuffer(gl) - var pointSizes = createBuffer(gl) - var pointIds = createBuffer(gl) - var pointVAO = createVAO(gl, [ - { buffer: pointPositions, - type: gl.FLOAT, - size: 3 - }, - { buffer: pointIds, - type: gl.UNSIGNED_BYTE, - size: 4, - normalized: true - }, - { buffer: pointColors, - type: gl.FLOAT, - size: 4 - }, - { buffer: pointUVs, - type: gl.FLOAT, - size: 2 - }, - { buffer: pointSizes, - type: gl.FLOAT, - size: 1 - } - ]) - - var contourPositions = createBuffer(gl) - var contourVAO = createVAO(gl, [ - { buffer: contourPositions, - type: gl.FLOAT, - size: 3 - }]) - - var mesh = new SimplicialMesh(gl - , meshTexture - , triShader - , pickShader - , trianglePositions - , triangleVectors - , triangleIds - , triangleColors - , triangleUVs - , triangleVAO - , edgePositions - , edgeIds - , edgeColors - , edgeUVs - , edgeVAO - , pointPositions - , pointIds - , pointColors - , pointUVs - , pointSizes - , pointVAO - , contourPositions - , contourVAO) - - mesh.update(params) - - return mesh -} - -module.exports = createSimplicialMesh diff --git a/package-lock.json b/package-lock.json index 72905d7..9454287 100644 --- a/package-lock.json +++ b/package-lock.json @@ -50,14 +50,6 @@ "pad-left": "^1.0.2" } }, - "affine-hull": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/affine-hull/-/affine-hull-1.0.0.tgz", - "integrity": "sha1-dj/x040GPOt+Jy8X7k17vK+QXF0=", - "requires": { - "robust-orientation": "^1.1.3" - } - }, "align-text": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/align-text/-/align-text-0.1.4.tgz", @@ -326,16 +318,6 @@ } } }, - "convex-hull": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/convex-hull/-/convex-hull-1.0.3.tgz", - "integrity": "sha1-IKOqbOh/St6i/30XlxyfwcZ+H/8=", - "requires": { - "affine-hull": "^1.0.0", - "incremental-convex-hull": "^1.0.1", - "monotone-convex-hull-2d": "^1.0.1" - } - }, "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", @@ -649,6 +631,25 @@ "typedarray-pool": "^1.0.0" } }, + "gl-cone3d": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/gl-cone3d/-/gl-cone3d-1.5.0.tgz", + "integrity": "sha512-Hkdx04QvqbzkHAP1nt4jkJD9F9hwJBqZR6ty2DbnQgkgWfIC2sRksDbzFkwPQ3HscTBNLdnuPIBBZ3123jBBVg==", + "requires": { + "colormap": "^2.3.1", + "gl-buffer": "^2.1.2", + "gl-mat4": "^1.2.0", + "gl-shader": "^4.2.1", + "gl-texture2d": "^2.1.0", + "gl-vao": "^1.3.0", + "gl-vec3": "^1.1.3", + "glsl-inverse": "^1.0.0", + "glsl-out-of-range": "^1.0.4", + "glsl-specular-cook-torrance": "^2.0.1", + "glslify": "^7.0.0", + "ndarray": "^1.0.18" + } + }, "gl-constants": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/gl-constants/-/gl-constants-1.0.0.tgz", @@ -1004,26 +1005,6 @@ "is-browser": "^2.0.1" } }, - "incremental-convex-hull": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/incremental-convex-hull/-/incremental-convex-hull-1.0.1.tgz", - "integrity": "sha1-UUKMFMudmmFEv+abKFH7N3M0vh4=", - "requires": { - "robust-orientation": "^1.1.2", - "simplicial-complex": "^1.0.0" - }, - "dependencies": { - "simplicial-complex": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/simplicial-complex/-/simplicial-complex-1.0.0.tgz", - "integrity": "sha1-bDOk7Wn81Nkbe8rdOzC2NoPq4kE=", - "requires": { - "bit-twiddle": "^1.0.0", - "union-find": "^1.0.0" - } - } - } - }, "inherits": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", @@ -1118,14 +1099,6 @@ } } }, - "marching-simplex-table": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/marching-simplex-table/-/marching-simplex-table-1.0.0.tgz", - "integrity": "sha1-vBYlbg+Pm1WKqbKHL4gy2UM/Uuo=", - "requires": { - "convex-hull": "^1.0.3" - } - }, "mat4-decompose": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/mat4-decompose/-/mat4-decompose-1.0.4.tgz", @@ -1175,14 +1148,6 @@ "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" }, - "monotone-convex-hull-2d": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/monotone-convex-hull-2d/-/monotone-convex-hull-2d-1.0.1.tgz", - "integrity": "sha1-R/Xa6t88Sv03dkuqGqh4ekDu4Iw=", - "requires": { - "robust-orientation": "^1.1.3" - } - }, "mouse-change": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/mouse-change/-/mouse-change-1.4.0.tgz", @@ -1246,14 +1211,6 @@ "cwise-compiler": "^1.0.0" } }, - "ndarray-sort": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/ndarray-sort/-/ndarray-sort-1.0.1.tgz", - "integrity": "sha1-/qBbTLg0x/TgIWo1TzynUTAN/Wo=", - "requires": { - "typedarray-pool": "^1.0.0" - } - }, "nextafter": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/nextafter/-/nextafter-1.0.0.tgz", @@ -1516,6 +1473,7 @@ "version": "1.1.3", "resolved": "https://registry.npmjs.org/robust-orientation/-/robust-orientation-1.1.3.tgz", "integrity": "sha1-2v9bANO+TmByLw6cAVbvln8cIEk=", + "dev": true, "requires": { "robust-scale": "^1.0.2", "robust-subtract": "^1.0.0", @@ -1537,6 +1495,7 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/robust-scale/-/robust-scale-1.0.2.tgz", "integrity": "sha1-d1Ey7QlULQKOWLLMecBikLz3jDI=", + "dev": true, "requires": { "two-product": "^1.0.2", "two-sum": "^1.0.0" @@ -1554,12 +1513,14 @@ "robust-subtract": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/robust-subtract/-/robust-subtract-1.0.0.tgz", - "integrity": "sha1-4LFk4e2LpOOl3aRaEgODSNvtPpo=" + "integrity": "sha1-4LFk4e2LpOOl3aRaEgODSNvtPpo=", + "dev": true }, "robust-sum": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/robust-sum/-/robust-sum-1.0.0.tgz", - "integrity": "sha1-FmRuUlKStNJdgnV6KGlV4Lv6U9k=" + "integrity": "sha1-FmRuUlKStNJdgnV6KGlV4Lv6U9k=", + "dev": true }, "safe-buffer": { "version": "5.1.2", @@ -1601,17 +1562,6 @@ } } }, - "simplicial-complex-contour": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/simplicial-complex-contour/-/simplicial-complex-contour-1.0.2.tgz", - "integrity": "sha1-iQqsrChDZTQBEFRc8mKaJuBL+dE=", - "requires": { - "marching-simplex-table": "^1.0.0", - "ndarray": "^1.0.15", - "ndarray-sort": "^1.0.0", - "typedarray-pool": "^1.1.0" - } - }, "simplify-planar-graph": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/simplify-planar-graph/-/simplify-planar-graph-2.0.1.tgz", @@ -1860,12 +1810,14 @@ "two-product": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/two-product/-/two-product-1.0.2.tgz", - "integrity": "sha1-Z9ldSyV6kh4stL16+VEfkIhSLqo=" + "integrity": "sha1-Z9ldSyV6kh4stL16+VEfkIhSLqo=", + "dev": true }, "two-sum": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/two-sum/-/two-sum-1.0.0.tgz", - "integrity": "sha1-MdPzIjnk9zHsqd+RVeKyl/AIq2Q=" + "integrity": "sha1-MdPzIjnk9zHsqd+RVeKyl/AIq2Q=", + "dev": true }, "type-check": { "version": "0.3.2", @@ -1918,7 +1870,8 @@ "union-find": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/union-find/-/union-find-1.0.2.tgz", - "integrity": "sha1-KSusQV5q06iVNdI3AQ20pTYoTlg=" + "integrity": "sha1-KSusQV5q06iVNdI3AQ20pTYoTlg=", + "dev": true }, "uniq": { "version": "1.0.1", diff --git a/package.json b/package.json index 370c532..6a7bf58 100644 --- a/package.json +++ b/package.json @@ -7,21 +7,13 @@ "example": "example" }, "dependencies": { - "colormap": "^2.3.1", - "gl-buffer": "^2.1.2", - "gl-mat4": "^1.2.0", - "gl-shader": "^4.2.1", - "gl-texture2d": "^2.1.0", - "gl-vao": "^1.3.0", + "gl-cone3d": "^1.5.0", "gl-vec3": "^1.1.3", "gl-vec4": "^1.0.1", "glsl-inverse": "^1.0.0", "glsl-out-of-range": "^1.0.4", "glsl-specular-cook-torrance": "^2.0.1", - "glslify": "^7.0.0", - "ndarray": "^1.0.18", - "simplicial-complex-contour": "^1.0.2", - "typedarray-pool": "^1.1.0" + "glslify": "^7.0.0" }, "devDependencies": { "3d-view-controls": "^2.2.2", diff --git a/streamtube.js b/streamtube.js index 785603d..6a72e73 100644 --- a/streamtube.js +++ b/streamtube.js @@ -548,4 +548,11 @@ module.exports = function(vectorField, bounds) { return tubes; }; -module.exports.createTubeMesh = require('./lib/tubemesh'); +var shaders = require('./lib/shaders'); +var createMesh = require('gl-cone3d').createMesh; +module.exports.createTubeMesh = function(gl, params) { + return createMesh(gl, params, { + shaders: shaders, + traceType: 'streamtube' + }); +}