Skip to content

Commit 1314c72

Browse files
authored
Merge pull request #10 from gl-vis/streamtube-color
Handle various orders of input data
2 parents 533bf21 + 40c336f commit 1314c72

File tree

8 files changed

+243
-313
lines changed

8 files changed

+243
-313
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ Creates a stream tube plot of a vector field.
4444
* `params` is an object that has the following properties:
4545

4646
+ `startingPositions` *(Required)* An array of starting positions for the vector field, encoded as arrays.
47-
+ `getVelocity(point)` *(Required)* A getter function to get the velocity at a given point.
47+
+ `getVelocity(point)` *(Optional)* A getter function to get the velocity at a given point.
4848
+ `getDivergence(point)` *(Optional)* A getter function to get the divergence at a given point. Used for the width of the streamtube. Defaults to the divergence of the getVelocity function.
4949
+ `maxLength` *(Optional)* The maximum number of segments to add to a streamtube. Default is 1000.
5050
+ `tubeSize` *(Optional)* The scaling factor for the streamtubes. The default is 1, which avoids two max divergence tubes from touching at adjacent starting positions.
51-
+ `absoluteTubeSize` *(Optional)* Absolute scaling factor for the streamtubes. A value of 1 scales divergence of 1 to 1 coordinate system unit. Overrides tubeSize.
51+
+ `absoluteTubeSize` *(Optional)* Absolute scaling factor for the streamtubes. A value of 1 scales divergence of 1 to 1 coordinate system unit. Overrides tubeSize.
5252
+ `colormap` *(Optional)* The colormap to use.
5353

5454
**Returns** A streamtube plot object that can be passed to gl-mesh3d.

lib/shaders.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ exports.meshShader = {
1010
fragment: triFragSrc,
1111
attributes: [
1212
{name: 'position', type: 'vec4'},
13-
{name: 'normal', type: 'vec3'},
1413
{name: 'color', type: 'vec4'},
1514
{name: 'uv', type: 'vec2'},
1615
{name: 'vector', type: 'vec4'}

lib/triangle-fragment.glsl

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,10 @@ precision highp float;
66
#pragma glslify: outOfRange = require(glsl-out-of-range)
77

88
uniform vec3 clipBounds[2];
9-
uniform float roughness
10-
, fresnel
11-
, kambient
12-
, kdiffuse
13-
, kspecular
14-
, opacity;
9+
uniform float roughness, fresnel, kambient, kdiffuse, kspecular, opacity;
1510
uniform sampler2D texture;
1611

17-
varying vec3 f_normal
18-
, f_lightDirection
19-
, f_eyeDirection
20-
, f_data
21-
, f_position;
12+
varying vec3 f_normal, f_lightDirection, f_eyeDirection, f_data, f_position;
2213
varying vec4 f_color;
2314
varying vec2 f_uv;
2415

lib/triangle-vertex.glsl

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,12 @@ precision highp float;
55
attribute vec4 vector;
66
attribute vec4 color, position;
77
attribute vec2 uv;
8-
uniform float vectorScale;
9-
uniform float tubeScale;
10-
11-
uniform mat4 model
12-
, view
13-
, projection
14-
, inverseModel;
15-
uniform vec3 eyePosition
16-
, lightPosition;
17-
18-
varying vec3 f_normal
19-
, f_lightDirection
20-
, f_eyeDirection
21-
, f_data
22-
, f_position;
8+
9+
uniform float vectorScale, tubeScale;
10+
uniform mat4 model, view, projection, inverseModel;
11+
uniform vec3 eyePosition, lightPosition;
12+
13+
varying vec3 f_normal, f_lightDirection, f_eyeDirection, f_data, f_position;
2314
varying vec4 f_color;
2415
varying vec2 f_uv;
2516

@@ -35,7 +26,7 @@ void main() {
3526
cameraCoordinate.xyz /= cameraCoordinate.w;
3627
f_lightDirection = lightPosition - cameraCoordinate.xyz;
3728
f_eyeDirection = eyePosition - cameraCoordinate.xyz;
38-
f_normal = normalize((vec4(normal,0.0) * inverseModel).xyz);
29+
f_normal = normalize((vec4(normal, 0.0) * inverseModel).xyz);
3930

4031
// vec4 m_position = model * vec4(tubePosition, 1.0);
4132
vec4 t_position = view * tubePosition;

lib/tubemesh.js

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
'use strict'
22

3-
var DEFAULT_VERTEX_NORMALS_EPSILON = 1e-6; // may be too large if triangles are very small
4-
var DEFAULT_FACE_NORMALS_EPSILON = 1e-6;
5-
63
var createShader = require('gl-shader')
74
var createBuffer = require('gl-buffer')
85
var createVAO = require('gl-vao')
96
var createTexture = require('gl-texture2d')
10-
var normals = require('normals')
117
var multiply = require('gl-mat4/multiply')
128
var invert = require('gl-mat4/invert')
139
var ndarray = require('ndarray')
@@ -34,7 +30,6 @@ function SimplicialMesh(gl
3430
, triangleIds
3531
, triangleColors
3632
, triangleUVs
37-
, triangleNormals
3833
, triangleVAO
3934
, edgePositions
4035
, edgeIds
@@ -63,7 +58,6 @@ function SimplicialMesh(gl
6358
this.trianglePositions = trianglePositions
6459
this.triangleVectors = triangleVectors
6560
this.triangleColors = triangleColors
66-
this.triangleNormals = triangleNormals
6761
this.triangleUVs = triangleUVs
6862
this.triangleIds = triangleIds
6963
this.triangleVAO = triangleVAO
@@ -295,18 +289,6 @@ proto.update = function(params) {
295289
this.positions = positions
296290
this.vectors = vectors
297291

298-
//Compute normals
299-
var vertexNormals = params.vertexNormals
300-
var cellNormals = params.cellNormals
301-
var vertexNormalsEpsilon = params.vertexNormalsEpsilon === void(0) ? DEFAULT_VERTEX_NORMALS_EPSILON : params.vertexNormalsEpsilon
302-
var faceNormalsEpsilon = params.faceNormalsEpsilon === void(0) ? DEFAULT_FACE_NORMALS_EPSILON : params.faceNormalsEpsilon
303-
if(params.useFacetNormals && !cellNormals) {
304-
cellNormals = normals.faceNormals(cells, positions, faceNormalsEpsilon)
305-
}
306-
if(!cellNormals && !vertexNormals) {
307-
vertexNormals = normals.vertexNormals(cells, positions, vertexNormalsEpsilon)
308-
}
309-
310292
//Compute colors
311293
var vertexColors = params.vertexColors
312294
var cellColors = params.cellColors
@@ -553,14 +535,6 @@ fill_loop:
553535
}
554536
tUVs.push(uv[0], uv[1])
555537

556-
var q
557-
if(vertexNormals) {
558-
q = vertexNormals[v]
559-
} else {
560-
q = cellNormals[i]
561-
}
562-
tNor.push(q[0], q[1], q[2])
563-
564538
tIds.push(i)
565539
}
566540
triangleCount += 1
@@ -590,7 +564,6 @@ fill_loop:
590564
this.triangleVectors.update(tVec)
591565
this.triangleColors.update(tCol)
592566
this.triangleUVs.update(tUVs)
593-
this.triangleNormals.update(tNor)
594567
this.triangleIds.update(new Uint32Array(tIds))
595568
}
596569

@@ -761,7 +734,6 @@ proto.dispose = function() {
761734
this.triangleVectors.dispose()
762735
this.triangleColors.dispose()
763736
this.triangleUVs.dispose()
764-
this.triangleNormals.dispose()
765737
this.triangleIds.dispose()
766738

767739
this.edgeVAO.dispose()
@@ -786,7 +758,7 @@ function createMeshShader(gl) {
786758
shader.attributes.position.location = 0
787759
shader.attributes.color.location = 2
788760
shader.attributes.uv.location = 3
789-
shader.attributes.vector.location = 5
761+
shader.attributes.vector.location = 4
790762
return shader
791763
}
792764

@@ -795,7 +767,7 @@ function createPickShader(gl) {
795767
var shader = createShader(gl, pickShader.vertex, pickShader.fragment, null, pickShader.attributes)
796768
shader.attributes.position.location = 0
797769
shader.attributes.id.location = 1
798-
shader.attributes.vector.location = 5
770+
shader.attributes.vector.location = 4
799771
return shader
800772
}
801773

@@ -819,7 +791,6 @@ function createSimplicialMesh(gl, params) {
819791
var triangleVectors = createBuffer(gl)
820792
var triangleColors = createBuffer(gl)
821793
var triangleUVs = createBuffer(gl)
822-
var triangleNormals = createBuffer(gl)
823794
var triangleIds = createBuffer(gl)
824795
var triangleVAO = createVAO(gl, [
825796
{ buffer: trianglePositions,
@@ -839,10 +810,6 @@ function createSimplicialMesh(gl, params) {
839810
type: gl.FLOAT,
840811
size: 2
841812
},
842-
{ buffer: triangleNormals,
843-
type: gl.FLOAT,
844-
size: 3
845-
},
846813
{ buffer: triangleVectors,
847814
type: gl.FLOAT,
848815
size: 4
@@ -918,7 +885,6 @@ function createSimplicialMesh(gl, params) {
918885
, triangleIds
919886
, triangleColors
920887
, triangleUVs
921-
, triangleNormals
922888
, triangleVAO
923889
, edgePositions
924890
, edgeIds

package-lock.json

Lines changed: 1 addition & 82 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
"gl-vec4": "^1.0.1",
1818
"glsl-inverse": "^1.0.0",
1919
"glsl-out-of-range": "^1.0.4",
20+
"glsl-specular-cook-torrance": "^2.0.1",
2021
"glslify": "^7.0.0",
2122
"ndarray": "^1.0.18",
22-
"normals": "^1.1.0",
2323
"simplicial-complex-contour": "^1.0.2",
2424
"typedarray-pool": "^1.1.0"
2525
},
@@ -29,7 +29,6 @@
2929
"canvas-fit": "^1.5.0",
3030
"chttps": "^1.0.6",
3131
"gl-axes3d": "^1.5.2",
32-
"gl-mesh3d": "^2.1.1",
3332
"gl-select-static": "^2.0.4",
3433
"gl-spikes3d": "^1.0.9"
3534
},

0 commit comments

Comments
 (0)