Skip to content

Commit 12c2d8c

Browse files
committed
Merge pull request #556 from monfera/fix-brain
Adding light position configurability for `surface` and `mesh3d`, and general lighting configurability for the latter
2 parents 8128622 + d300a9b commit 12c2d8c

20 files changed

+150
-24
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"gl-line2d": "^1.3.0",
6262
"gl-line3d": "^1.1.0",
6363
"gl-mat4": "^1.1.2",
64-
"gl-mesh3d": "^1.0.7",
64+
"gl-mesh3d": "^1.2.0",
6565
"gl-plot2d": "^1.1.6",
6666
"gl-plot3d": "^1.5.0",
6767
"gl-scatter2d": "^1.0.5",

src/traces/mesh3d/attributes.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,29 @@ module.exports = {
124124
reversescale: colorscaleAttrs.reversescale,
125125
showscale: colorscaleAttrs.showscale,
126126

127-
lighting: extendFlat({}, surfaceAtts.lighting),
127+
lightposition: {
128+
'x': extendFlat({}, surfaceAtts.lightposition.x, {dflt: 1e5}),
129+
'y': extendFlat({}, surfaceAtts.lightposition.y, {dflt: 1e5}),
130+
'z': extendFlat({}, surfaceAtts.lightposition.z, {dflt: 0})
131+
},
132+
lighting: extendFlat({}, {
133+
vertexnormalsepsilon: {
134+
valType: 'number',
135+
role: 'style',
136+
min: 0.00,
137+
max: 1,
138+
dflt: 1e-12, // otherwise finely tessellated things eg. the brain will have no specular light reflection
139+
description: 'Epsilon for vertex normals calculation avoids math issues arising from degenerate geometry.'
140+
},
141+
facenormalsepsilon: {
142+
valType: 'number',
143+
role: 'style',
144+
min: 0.00,
145+
max: 1,
146+
dflt: 1e-6, // even the brain model doesn't appear to need finer than this
147+
description: 'Epsilon for face normals calculation avoids math issues arising from degenerate geometry.'
148+
}
149+
}, surfaceAtts.lighting),
128150

129151
_nestedModules: { // nested module coupling
130152
'colorbar': 'Colorbar'

src/traces/mesh3d/convert.js

+3
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,14 @@ proto.update = function(data) {
106106
var config = {
107107
positions: positions,
108108
cells: cells,
109+
lightPosition: [data.lightposition.x, data.lightposition.y, data.lightposition.z],
109110
ambient: data.lighting.ambient,
110111
diffuse: data.lighting.diffuse,
111112
specular: data.lighting.specular,
112113
roughness: data.lighting.roughness,
113114
fresnel: data.lighting.fresnel,
115+
vertexNormalsEpsilon: data.lighting.vertexnormalsepsilon,
116+
faceNormalsEpsilon: data.lighting.facenormalsepsilon,
114117
opacity: data.opacity,
115118
contourEnable: data.contour.show,
116119
contourColor: str2RgbaArray(data.contour.color).slice(0, 3),

src/traces/mesh3d/defaults.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,17 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
4949
}
5050

5151
//Coerce remaining properties
52-
['lighting.ambient',
52+
[
53+
'lighting.ambient',
5354
'lighting.diffuse',
5455
'lighting.specular',
5556
'lighting.roughness',
5657
'lighting.fresnel',
58+
'lighting.vertexnormalsepsilon',
59+
'lighting.facenormalsepsilon',
60+
'lightposition.x',
61+
'lightposition.y',
62+
'lightposition.z',
5763
'contour.show',
5864
'contour.color',
5965
'contour.width',

src/traces/surface/attributes.js

+40-5
Original file line numberDiff line numberDiff line change
@@ -147,41 +147,76 @@ module.exports = {
147147
].join(' ')
148148
},
149149

150+
lightposition: {
151+
x: {
152+
valType: 'number',
153+
role: 'style',
154+
min: -1e5,
155+
max: 1e5,
156+
dflt: 10,
157+
description: 'Numeric vector, representing the X coordinate for each vertex.'
158+
},
159+
y: {
160+
valType: 'number',
161+
role: 'style',
162+
min: -1e5,
163+
max: 1e5,
164+
dflt: 1e5,
165+
description: 'Numeric vector, representing the Y coordinate for each vertex.'
166+
},
167+
z: {
168+
valType: 'number',
169+
role: 'style',
170+
min: -1e5,
171+
max: 1e5,
172+
dflt: 0,
173+
description: 'Numeric vector, representing the Z coordinate for each vertex.'
174+
}
175+
},
176+
150177
lighting: {
151178
ambient: {
152179
valType: 'number',
153180
role: 'style',
154181
min: 0.00,
155182
max: 1.0,
156-
dflt: 0.8
183+
dflt: 0.8,
184+
description: 'Ambient light increases overall color visibility but can wash out the image.'
157185
},
158186
diffuse: {
159187
valType: 'number',
160188
role: 'style',
161189
min: 0.00,
162190
max: 1.00,
163-
dflt: 0.8
191+
dflt: 0.8,
192+
description: 'Represents the extent that incident rays are reflected in a range of angles.'
164193
},
165194
specular: {
166195
valType: 'number',
167196
role: 'style',
168197
min: 0.00,
169198
max: 2.00,
170-
dflt: 0.05
199+
dflt: 0.05,
200+
description: 'Represents the level that incident rays are reflected in a single direction, causing shine.'
171201
},
172202
roughness: {
173203
valType: 'number',
174204
role: 'style',
175205
min: 0.00,
176206
max: 1.00,
177-
dflt: 0.5
207+
dflt: 0.5,
208+
description: 'Alters specular reflection; the rougher the surface, the wider and less contrasty the shine.'
178209
},
179210
fresnel: {
180211
valType: 'number',
181212
role: 'style',
182213
min: 0.00,
183214
max: 5.00,
184-
dflt: 0.2
215+
dflt: 0.2,
216+
description: [
217+
'Represents the reflectance as a dependency of the viewing angle; e.g. paper is reflective',
218+
'when viewing it from the edge of the paper (almost 90 degrees), causing shine.'
219+
].join(' ')
185220
}
186221
},
187222

src/traces/surface/convert.js

+10
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,16 @@ proto.update = function(data) {
334334
surface.fresnel = data.lighting.fresnel;
335335
}
336336

337+
if('lightposition' in data) {
338+
if(surface.lightPosition === void(0)) {
339+
surface.lightPosition = [data.lightposition.x, data.lightposition.y, data.lightposition.z];
340+
} else {
341+
surface.lightPosition.x = data.lightposition.x;
342+
surface.lightPosition.y = data.lightposition.y;
343+
surface.lightPosition.z = data.lightposition.z;
344+
}
345+
}
346+
337347
if(alpha && alpha < 1) {
338348
surface.supportsTransparency = true;
339349
}

src/traces/surface/defaults.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,19 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
5050
}
5151
}
5252

53-
coerce('lighting.ambient');
54-
coerce('lighting.diffuse');
55-
coerce('lighting.specular');
56-
coerce('lighting.roughness');
57-
coerce('lighting.fresnel');
58-
coerce('hidesurface');
59-
coerce('opacity');
53+
//Coerce remaining properties
54+
[
55+
'lighting.ambient',
56+
'lighting.diffuse',
57+
'lighting.specular',
58+
'lighting.roughness',
59+
'lighting.fresnel',
60+
'lightposition.x',
61+
'lightposition.y',
62+
'lightposition.z',
63+
'hidesurface',
64+
'opacity'
65+
].forEach(function(x) { coerce(x); });
6066

6167
var surfaceColor = coerce('surfacecolor');
6268

0 Bytes
Loading
-1.11 KB
Loading

test/image/baselines/gl3d_bunny.png

-884 Bytes
Loading
-884 Bytes
Loading
-2 Bytes
Loading

test/image/baselines/gl3d_ribbons.png

29 Bytes
Loading

test/image/baselines/gl3d_snowden.png

13.4 KB
Loading
35.6 KB
Loading
-8.71 KB
Loading
-3 Bytes
Loading

test/image/mocks/gl3d_snowden.json

+7-1
Large diffs are not rendered by default.

test/image/mocks/gl3d_snowden_altered.json

+33
Large diffs are not rendered by default.

test/image/mocks/gl3d_surface-lighting.json

+13-8
Original file line numberDiff line numberDiff line change
@@ -510,12 +510,17 @@
510510
"show": false
511511
}
512512
},
513+
"lightposition": {
514+
"x": 1e5,
515+
"y": 1e5,
516+
"z": 1e5
517+
},
513518
"lighting": {
514-
"fresnel": 0.8,
515-
"roughness": 0.5,
516-
"diffuse": 0.5,
517-
"ambient": 0.5,
518-
"specular": 0.5
519+
"fresnel": 0.2,
520+
"roughness": 0.1,
521+
"diffuse": 2,
522+
"ambient": 0.15,
523+
"specular": 2
519524
}
520525
}
521526
],
@@ -550,18 +555,18 @@
550555
"xaxis": {
551556
"showbackground": true,
552557
"type": "linear",
553-
"backgroundcolor": "rgb(255, 127, 14)",
558+
"backgroundcolor": "rgba(255, 127, 14, 0.2)",
554559
"tickangle": 180
555560
},
556561
"yaxis": {
557562
"showbackground": true,
558563
"type": "linear",
559-
"backgroundcolor": "rgb(255, 0, 0)",
564+
"backgroundcolor": "rgba(255, 0, 0, 0.2)",
560565
"tickangle": -45
561566
},
562567
"zaxis": {
563568
"showbackground": true,
564-
"backgroundcolor": "rgb(44, 160, 44)",
569+
"backgroundcolor": "rgba(44, 160, 44, 0.35)",
565570
"tickangle": 30
566571
}
567572
}

0 commit comments

Comments
 (0)