zincjs 2.3.0 → 2.3.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/zinc.js +268 -71
- package/build/zinc.js.map +1 -1
- package/package.json +2 -2
- package/src/loaders/niftiReader.js +1 -1
- package/src/minimap.js +2 -2
- package/src/primitives/augmentShader.js +39 -22
- package/src/primitives/geometry.js +24 -29
- package/src/primitives/glyphset.js +2 -2
- package/src/primitives/lines.js +4 -2
- package/src/primitives/pointset.js +7 -2
- package/src/primitives/zincObject.js +0 -1
- package/src/region.js +0 -2
- package/src/renderer.js +6 -1
- package/src/scene.js +1 -3
- package/src/sceneLoader.js +10 -6
- package/src/texture/textureArray.js +1 -1
- package/src/three/Geometry.js +45 -34
- package/src/three/Loader.js +1 -0
- package/src/three/line/Line.js +2 -2
- package/src/three/line/LineMaterial.js +432 -212
- package/src/three/line/LineSegments2.js +299 -151
- package/src/three/line/LineSegmentsGeometry.js +68 -20
- package/src/utilities.js +62 -2
- package/src/videoHandler.js +4 -1
|
@@ -3,31 +3,18 @@ import {
|
|
|
3
3
|
ShaderMaterial,
|
|
4
4
|
UniformsLib,
|
|
5
5
|
UniformsUtils,
|
|
6
|
-
Vector2
|
|
6
|
+
Vector2,
|
|
7
7
|
} from 'three';
|
|
8
8
|
|
|
9
|
-
/**
|
|
10
|
-
* parameters = {
|
|
11
|
-
* color: <hex>,
|
|
12
|
-
* linewidth: <float>,
|
|
13
|
-
* dashed: <boolean>,
|
|
14
|
-
* dashScale: <float>,
|
|
15
|
-
* dashSize: <float>,
|
|
16
|
-
* dashOffset: <float>,
|
|
17
|
-
* gapSize: <float>,
|
|
18
|
-
* resolution: <Vector2>, // to be set by renderer
|
|
19
|
-
* }
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
9
|
UniformsLib.line = {
|
|
23
10
|
|
|
11
|
+
worldUnits: { value: 1 },
|
|
24
12
|
linewidth: { value: 1 },
|
|
25
|
-
resolution: { value: new Vector2(
|
|
13
|
+
resolution: { value: new Vector2() },
|
|
14
|
+
dashOffset: { value: 0 },
|
|
26
15
|
dashScale: { value: 1 },
|
|
27
16
|
dashSize: { value: 1 },
|
|
28
|
-
|
|
29
|
-
gapSize: { value: 1 }, // todo FIX - maybe change to totalSize
|
|
30
|
-
opacity: { value: 1 }
|
|
17
|
+
gapSize: { value: 1 } // todo FIX - maybe change to totalSize
|
|
31
18
|
|
|
32
19
|
};
|
|
33
20
|
|
|
@@ -39,7 +26,8 @@ ShaderLib[ 'line' ] = {
|
|
|
39
26
|
UniformsLib.line
|
|
40
27
|
] ),
|
|
41
28
|
|
|
42
|
-
vertexShader:
|
|
29
|
+
vertexShader:
|
|
30
|
+
/* glsl */`
|
|
43
31
|
#include <common>
|
|
44
32
|
#include <color_pars_vertex>
|
|
45
33
|
#include <fog_pars_vertex>
|
|
@@ -55,7 +43,23 @@ ShaderLib[ 'line' ] = {
|
|
|
55
43
|
attribute vec3 instanceColorStart;
|
|
56
44
|
attribute vec3 instanceColorEnd;
|
|
57
45
|
|
|
58
|
-
|
|
46
|
+
#ifdef WORLD_UNITS
|
|
47
|
+
|
|
48
|
+
varying vec4 worldPos;
|
|
49
|
+
varying vec3 worldStart;
|
|
50
|
+
varying vec3 worldEnd;
|
|
51
|
+
|
|
52
|
+
#ifdef USE_DASH
|
|
53
|
+
|
|
54
|
+
varying vec2 vUv;
|
|
55
|
+
|
|
56
|
+
#endif
|
|
57
|
+
|
|
58
|
+
#else
|
|
59
|
+
|
|
60
|
+
varying vec2 vUv;
|
|
61
|
+
|
|
62
|
+
#endif
|
|
59
63
|
|
|
60
64
|
#ifdef USE_DASH
|
|
61
65
|
|
|
@@ -66,18 +70,20 @@ ShaderLib[ 'line' ] = {
|
|
|
66
70
|
|
|
67
71
|
#endif
|
|
68
72
|
|
|
69
|
-
|
|
73
|
+
float trimSegmentAlpha( const in vec4 start, const in vec4 end ) {
|
|
70
74
|
|
|
71
|
-
//
|
|
75
|
+
// compute the interpolation factor needed to trim the segment so it terminates
|
|
76
|
+
// between the camera plane and the near plane
|
|
72
77
|
|
|
73
78
|
// conservative estimate of the near plane
|
|
74
79
|
float a = projectionMatrix[ 2 ][ 2 ]; // 3nd entry in 3th column
|
|
75
80
|
float b = projectionMatrix[ 3 ][ 2 ]; // 3nd entry in 4th column
|
|
76
|
-
float nearEstimate = - 0.5 * b / a;
|
|
77
81
|
|
|
78
|
-
|
|
82
|
+
// we need different nearEstimate formula for reversed and default depth buffer
|
|
83
|
+
// a is positive with a reversed depth buffer so it can be used for controlling the code flow
|
|
84
|
+
float nearEstimate = ( a > 0.0 ) ? ( - b / ( a + 1.0 ) ) : ( - 0.5 * b / a );
|
|
79
85
|
|
|
80
|
-
|
|
86
|
+
return ( nearEstimate - start.z ) / ( end.z - start.z );
|
|
81
87
|
|
|
82
88
|
}
|
|
83
89
|
|
|
@@ -89,19 +95,29 @@ ShaderLib[ 'line' ] = {
|
|
|
89
95
|
|
|
90
96
|
#endif
|
|
91
97
|
|
|
98
|
+
float aspect = resolution.x / resolution.y;
|
|
99
|
+
|
|
100
|
+
// camera space
|
|
101
|
+
vec4 start = modelViewMatrix * vec4( instanceStart, 1.0 );
|
|
102
|
+
vec4 end = modelViewMatrix * vec4( instanceEnd, 1.0 );
|
|
103
|
+
|
|
92
104
|
#ifdef USE_DASH
|
|
93
105
|
|
|
94
|
-
|
|
106
|
+
float lineDistanceStart = dashScale * instanceDistanceStart;
|
|
107
|
+
float lineDistanceEnd = dashScale * instanceDistanceEnd;
|
|
95
108
|
|
|
96
109
|
#endif
|
|
97
110
|
|
|
98
|
-
|
|
111
|
+
#ifdef WORLD_UNITS
|
|
99
112
|
|
|
100
|
-
|
|
113
|
+
worldStart = start.xyz;
|
|
114
|
+
worldEnd = end.xyz;
|
|
101
115
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
116
|
+
#else
|
|
117
|
+
|
|
118
|
+
vUv = uv;
|
|
119
|
+
|
|
120
|
+
#endif
|
|
105
121
|
|
|
106
122
|
// special case for perspective projection, and segments that terminate either in, or behind, the camera plane
|
|
107
123
|
// clearly the gpu firmware has a way of addressing this issue when projecting into ndc space
|
|
@@ -114,65 +130,127 @@ ShaderLib[ 'line' ] = {
|
|
|
114
130
|
|
|
115
131
|
if ( start.z < 0.0 && end.z >= 0.0 ) {
|
|
116
132
|
|
|
117
|
-
|
|
133
|
+
float alpha = trimSegmentAlpha( start, end );
|
|
134
|
+
end.xyz = mix( start.xyz, end.xyz, alpha );
|
|
135
|
+
|
|
136
|
+
#ifdef USE_DASH
|
|
137
|
+
|
|
138
|
+
lineDistanceEnd = mix( lineDistanceStart, lineDistanceEnd, alpha );
|
|
139
|
+
|
|
140
|
+
#endif
|
|
118
141
|
|
|
119
142
|
} else if ( end.z < 0.0 && start.z >= 0.0 ) {
|
|
120
143
|
|
|
121
|
-
|
|
144
|
+
float alpha = trimSegmentAlpha( end, start );
|
|
145
|
+
start.xyz = mix( end.xyz, start.xyz, alpha );
|
|
146
|
+
|
|
147
|
+
#ifdef USE_DASH
|
|
148
|
+
|
|
149
|
+
lineDistanceStart = mix( lineDistanceEnd, lineDistanceStart, alpha );
|
|
150
|
+
|
|
151
|
+
#endif
|
|
122
152
|
|
|
123
153
|
}
|
|
124
154
|
|
|
125
155
|
}
|
|
126
156
|
|
|
157
|
+
#ifdef USE_DASH
|
|
158
|
+
|
|
159
|
+
vLineDistance = ( position.y < 0.5 ) ? lineDistanceStart : lineDistanceEnd;
|
|
160
|
+
vUv = uv;
|
|
161
|
+
|
|
162
|
+
#endif
|
|
163
|
+
|
|
127
164
|
// clip space
|
|
128
165
|
vec4 clipStart = projectionMatrix * start;
|
|
129
166
|
vec4 clipEnd = projectionMatrix * end;
|
|
130
167
|
|
|
131
168
|
// ndc space
|
|
132
|
-
|
|
133
|
-
|
|
169
|
+
vec3 ndcStart = clipStart.xyz / clipStart.w;
|
|
170
|
+
vec3 ndcEnd = clipEnd.xyz / clipEnd.w;
|
|
134
171
|
|
|
135
172
|
// direction
|
|
136
|
-
vec2 dir = ndcEnd - ndcStart;
|
|
173
|
+
vec2 dir = ndcEnd.xy - ndcStart.xy;
|
|
137
174
|
|
|
138
175
|
// account for clip-space aspect ratio
|
|
139
176
|
dir.x *= aspect;
|
|
140
177
|
dir = normalize( dir );
|
|
141
178
|
|
|
142
|
-
|
|
143
|
-
vec2 offset = vec2( dir.y, - dir.x );
|
|
179
|
+
#ifdef WORLD_UNITS
|
|
144
180
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
181
|
+
vec3 worldDir = normalize( end.xyz - start.xyz );
|
|
182
|
+
vec3 tmpFwd = normalize( mix( start.xyz, end.xyz, 0.5 ) );
|
|
183
|
+
vec3 worldUp = normalize( cross( worldDir, tmpFwd ) );
|
|
184
|
+
vec3 worldFwd = cross( worldDir, worldUp );
|
|
185
|
+
worldPos = position.y < 0.5 ? start: end;
|
|
148
186
|
|
|
149
|
-
|
|
150
|
-
|
|
187
|
+
// height offset
|
|
188
|
+
float hw = linewidth * 0.5;
|
|
189
|
+
worldPos.xyz += position.x < 0.0 ? hw * worldUp : - hw * worldUp;
|
|
151
190
|
|
|
152
|
-
|
|
153
|
-
|
|
191
|
+
// don't extend the line if we're rendering dashes because we
|
|
192
|
+
// won't be rendering the endcaps
|
|
193
|
+
#ifndef USE_DASH
|
|
154
194
|
|
|
155
|
-
|
|
195
|
+
// cap extension
|
|
196
|
+
worldPos.xyz += position.y < 0.5 ? - hw * worldDir : hw * worldDir;
|
|
156
197
|
|
|
157
|
-
|
|
198
|
+
// add width to the box
|
|
199
|
+
worldPos.xyz += worldFwd * hw;
|
|
158
200
|
|
|
159
|
-
|
|
201
|
+
// endcaps
|
|
202
|
+
if ( position.y > 1.0 || position.y < 0.0 ) {
|
|
160
203
|
|
|
161
|
-
|
|
204
|
+
worldPos.xyz -= worldFwd * 2.0 * hw;
|
|
205
|
+
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
#endif
|
|
162
209
|
|
|
163
|
-
|
|
164
|
-
|
|
210
|
+
// project the worldpos
|
|
211
|
+
vec4 clip = projectionMatrix * worldPos;
|
|
165
212
|
|
|
166
|
-
|
|
167
|
-
|
|
213
|
+
// shift the depth of the projected points so the line
|
|
214
|
+
// segments overlap neatly
|
|
215
|
+
vec3 clipPose = ( position.y < 0.5 ) ? ndcStart : ndcEnd;
|
|
216
|
+
clip.z = clipPose.z * clip.w;
|
|
168
217
|
|
|
169
|
-
|
|
170
|
-
|
|
218
|
+
#else
|
|
219
|
+
|
|
220
|
+
vec2 offset = vec2( dir.y, - dir.x );
|
|
221
|
+
// undo aspect ratio adjustment
|
|
222
|
+
dir.x /= aspect;
|
|
223
|
+
offset.x /= aspect;
|
|
224
|
+
|
|
225
|
+
// sign flip
|
|
226
|
+
if ( position.x < 0.0 ) offset *= - 1.0;
|
|
227
|
+
|
|
228
|
+
// endcaps
|
|
229
|
+
if ( position.y < 0.0 ) {
|
|
230
|
+
|
|
231
|
+
offset += - dir;
|
|
232
|
+
|
|
233
|
+
} else if ( position.y > 1.0 ) {
|
|
234
|
+
|
|
235
|
+
offset += dir;
|
|
236
|
+
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// adjust for linewidth
|
|
240
|
+
offset *= linewidth;
|
|
241
|
+
|
|
242
|
+
// adjust for clip-space to screen-space conversion // maybe resolution should be based on viewport ...
|
|
243
|
+
offset /= resolution.y;
|
|
171
244
|
|
|
172
|
-
|
|
173
|
-
|
|
245
|
+
// select end
|
|
246
|
+
vec4 clip = ( position.y < 0.5 ) ? clipStart : clipEnd;
|
|
174
247
|
|
|
175
|
-
|
|
248
|
+
// back to clip space
|
|
249
|
+
offset *= clip.w;
|
|
250
|
+
|
|
251
|
+
clip.xy += offset;
|
|
252
|
+
|
|
253
|
+
#endif
|
|
176
254
|
|
|
177
255
|
gl_Position = clip;
|
|
178
256
|
|
|
@@ -182,32 +260,83 @@ ShaderLib[ 'line' ] = {
|
|
|
182
260
|
#include <clipping_planes_vertex>
|
|
183
261
|
#include <fog_vertex>
|
|
184
262
|
|
|
185
|
-
}
|
|
263
|
+
}
|
|
264
|
+
`,
|
|
186
265
|
|
|
187
|
-
fragmentShader:
|
|
266
|
+
fragmentShader:
|
|
267
|
+
/* glsl */`
|
|
188
268
|
uniform vec3 diffuse;
|
|
189
269
|
uniform float opacity;
|
|
270
|
+
uniform float linewidth;
|
|
190
271
|
|
|
191
272
|
#ifdef USE_DASH
|
|
192
273
|
|
|
193
|
-
uniform float dashSize;
|
|
194
274
|
uniform float dashOffset;
|
|
275
|
+
uniform float dashSize;
|
|
195
276
|
uniform float gapSize;
|
|
196
277
|
|
|
197
278
|
#endif
|
|
198
279
|
|
|
199
280
|
varying float vLineDistance;
|
|
200
281
|
|
|
282
|
+
#ifdef WORLD_UNITS
|
|
283
|
+
|
|
284
|
+
varying vec4 worldPos;
|
|
285
|
+
varying vec3 worldStart;
|
|
286
|
+
varying vec3 worldEnd;
|
|
287
|
+
|
|
288
|
+
#ifdef USE_DASH
|
|
289
|
+
|
|
290
|
+
varying vec2 vUv;
|
|
291
|
+
|
|
292
|
+
#endif
|
|
293
|
+
|
|
294
|
+
#else
|
|
295
|
+
|
|
296
|
+
varying vec2 vUv;
|
|
297
|
+
|
|
298
|
+
#endif
|
|
299
|
+
|
|
201
300
|
#include <common>
|
|
202
301
|
#include <color_pars_fragment>
|
|
203
302
|
#include <fog_pars_fragment>
|
|
204
303
|
#include <logdepthbuf_pars_fragment>
|
|
205
304
|
#include <clipping_planes_pars_fragment>
|
|
206
305
|
|
|
207
|
-
|
|
306
|
+
vec2 closestLineToLine(vec3 p1, vec3 p2, vec3 p3, vec3 p4) {
|
|
307
|
+
|
|
308
|
+
float mua;
|
|
309
|
+
float mub;
|
|
310
|
+
|
|
311
|
+
vec3 p13 = p1 - p3;
|
|
312
|
+
vec3 p43 = p4 - p3;
|
|
313
|
+
|
|
314
|
+
vec3 p21 = p2 - p1;
|
|
315
|
+
|
|
316
|
+
float d1343 = dot( p13, p43 );
|
|
317
|
+
float d4321 = dot( p43, p21 );
|
|
318
|
+
float d1321 = dot( p13, p21 );
|
|
319
|
+
float d4343 = dot( p43, p43 );
|
|
320
|
+
float d2121 = dot( p21, p21 );
|
|
321
|
+
|
|
322
|
+
float denom = d2121 * d4343 - d4321 * d4321;
|
|
323
|
+
|
|
324
|
+
float numer = d1343 * d4321 - d1321 * d4343;
|
|
325
|
+
|
|
326
|
+
mua = numer / denom;
|
|
327
|
+
mua = clamp( mua, 0.0, 1.0 );
|
|
328
|
+
mub = ( d1343 + d4321 * ( mua ) ) / d4343;
|
|
329
|
+
mub = clamp( mub, 0.0, 1.0 );
|
|
330
|
+
|
|
331
|
+
return vec2( mua, mub );
|
|
332
|
+
|
|
333
|
+
}
|
|
208
334
|
|
|
209
335
|
void main() {
|
|
210
336
|
|
|
337
|
+
float alpha = opacity;
|
|
338
|
+
vec4 diffuseColor = vec4( diffuse, alpha );
|
|
339
|
+
|
|
211
340
|
#include <clipping_planes_fragment>
|
|
212
341
|
|
|
213
342
|
#ifdef USE_DASH
|
|
@@ -218,37 +347,69 @@ ShaderLib[ 'line' ] = {
|
|
|
218
347
|
|
|
219
348
|
#endif
|
|
220
349
|
|
|
221
|
-
|
|
350
|
+
#ifdef WORLD_UNITS
|
|
222
351
|
|
|
223
|
-
|
|
352
|
+
// Find the closest points on the view ray and the line segment
|
|
353
|
+
vec3 rayEnd = normalize( worldPos.xyz ) * 1e5;
|
|
354
|
+
vec3 lineDir = worldEnd - worldStart;
|
|
355
|
+
vec2 params = closestLineToLine( worldStart, worldEnd, vec3( 0.0, 0.0, 0.0 ), rayEnd );
|
|
224
356
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
357
|
+
vec3 p1 = worldStart + lineDir * params.x;
|
|
358
|
+
vec3 p2 = rayEnd * params.y;
|
|
359
|
+
vec3 delta = p1 - p2;
|
|
360
|
+
float len = length( delta );
|
|
361
|
+
float norm = len / linewidth;
|
|
230
362
|
|
|
231
|
-
|
|
363
|
+
#ifndef USE_DASH
|
|
232
364
|
|
|
233
|
-
|
|
365
|
+
#ifdef USE_ALPHA_TO_COVERAGE
|
|
234
366
|
|
|
235
|
-
|
|
367
|
+
float dnorm = fwidth( norm );
|
|
368
|
+
alpha = 1.0 - smoothstep( 0.5 - dnorm, 0.5 + dnorm, norm );
|
|
369
|
+
|
|
370
|
+
#else
|
|
371
|
+
|
|
372
|
+
if ( norm > 0.5 ) {
|
|
373
|
+
|
|
374
|
+
discard;
|
|
375
|
+
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
#endif
|
|
379
|
+
|
|
380
|
+
#endif
|
|
236
381
|
|
|
237
382
|
#else
|
|
238
383
|
|
|
239
|
-
|
|
384
|
+
#ifdef USE_ALPHA_TO_COVERAGE
|
|
240
385
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
386
|
+
// artifacts appear on some hardware if a derivative is taken within a conditional
|
|
387
|
+
float a = vUv.x;
|
|
388
|
+
float b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;
|
|
389
|
+
float len2 = a * a + b * b;
|
|
390
|
+
float dlen = fwidth( len2 );
|
|
244
391
|
|
|
245
|
-
|
|
392
|
+
if ( abs( vUv.y ) > 1.0 ) {
|
|
246
393
|
|
|
247
|
-
|
|
394
|
+
alpha = 1.0 - smoothstep( 1.0 - dlen, 1.0 + dlen, len2 );
|
|
248
395
|
|
|
249
|
-
|
|
396
|
+
}
|
|
250
397
|
|
|
251
|
-
|
|
398
|
+
#else
|
|
399
|
+
|
|
400
|
+
if ( abs( vUv.y ) > 1.0 ) {
|
|
401
|
+
|
|
402
|
+
float a = vUv.x;
|
|
403
|
+
float b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;
|
|
404
|
+
float len2 = a * a + b * b;
|
|
405
|
+
|
|
406
|
+
if ( len2 > 1.0 ) discard;
|
|
407
|
+
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
#endif
|
|
411
|
+
|
|
412
|
+
#endif
|
|
252
413
|
|
|
253
414
|
#include <logdepthbuf_fragment>
|
|
254
415
|
#include <color_fragment>
|
|
@@ -256,22 +417,42 @@ ShaderLib[ 'line' ] = {
|
|
|
256
417
|
gl_FragColor = vec4( diffuseColor.rgb, alpha );
|
|
257
418
|
|
|
258
419
|
#include <tonemapping_fragment>
|
|
259
|
-
#include <
|
|
420
|
+
#include <colorspace_fragment>
|
|
260
421
|
#include <fog_fragment>
|
|
261
422
|
#include <premultiplied_alpha_fragment>
|
|
262
423
|
|
|
263
|
-
}
|
|
264
|
-
|
|
424
|
+
}
|
|
425
|
+
`
|
|
265
426
|
};
|
|
266
427
|
|
|
428
|
+
/**
|
|
429
|
+
* A material for drawing wireframe-style geometries.
|
|
430
|
+
*
|
|
431
|
+
* Unlike {@link LineBasicMaterial}, it supports arbitrary line widths and allows using world units
|
|
432
|
+
* instead of screen space units. This material is used with {@link LineSegments2} and {@link Line2}.
|
|
433
|
+
*
|
|
434
|
+
* This module can only be used with {@link WebGLRenderer}. When using {@link WebGPURenderer},
|
|
435
|
+
* use {@link Line2NodeMaterial}.
|
|
436
|
+
*
|
|
437
|
+
* @augments ShaderMaterial
|
|
438
|
+
* @three_import import { LineMaterial } from 'three/addons/lines/LineMaterial.js';
|
|
439
|
+
*/
|
|
267
440
|
class LineMaterial extends ShaderMaterial {
|
|
268
441
|
|
|
442
|
+
/**
|
|
443
|
+
* Constructs a new line segments geometry.
|
|
444
|
+
*
|
|
445
|
+
* @param {Object} [parameters] - An object with one or more properties
|
|
446
|
+
* defining the material's appearance. Any property of the material
|
|
447
|
+
* (including any property from inherited materials) can be passed
|
|
448
|
+
* in here. Color values can be passed any type of value accepted
|
|
449
|
+
* by {@link Color#set}.
|
|
450
|
+
*/
|
|
269
451
|
constructor( parameters ) {
|
|
270
452
|
|
|
271
453
|
super( {
|
|
272
454
|
|
|
273
455
|
type: 'LineMaterial',
|
|
274
|
-
|
|
275
456
|
uniforms: UniformsUtils.clone( ShaderLib[ 'line' ].uniforms ),
|
|
276
457
|
|
|
277
458
|
vertexShader: ShaderLib[ 'line' ].vertexShader,
|
|
@@ -281,226 +462,265 @@ class LineMaterial extends ShaderMaterial {
|
|
|
281
462
|
|
|
282
463
|
} );
|
|
283
464
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
return this.uniforms.diffuse.value;
|
|
293
|
-
|
|
294
|
-
},
|
|
295
|
-
|
|
296
|
-
set: function ( value ) {
|
|
297
|
-
|
|
298
|
-
this.uniforms.diffuse.value = value;
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
},
|
|
465
|
+
/**
|
|
466
|
+
* This flag can be used for type testing.
|
|
467
|
+
*
|
|
468
|
+
* @type {boolean}
|
|
469
|
+
* @readonly
|
|
470
|
+
* @default true
|
|
471
|
+
*/
|
|
472
|
+
this.isLineMaterial = true;
|
|
303
473
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
enumerable: true,
|
|
307
|
-
|
|
308
|
-
get: function () {
|
|
309
|
-
|
|
310
|
-
return this.uniforms.linewidth.value;
|
|
311
|
-
|
|
312
|
-
},
|
|
313
|
-
|
|
314
|
-
set: function ( value ) {
|
|
315
|
-
|
|
316
|
-
this.uniforms.linewidth.value = value;
|
|
317
|
-
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
},
|
|
474
|
+
this.setValues( parameters );
|
|
321
475
|
|
|
322
|
-
|
|
476
|
+
}
|
|
323
477
|
|
|
324
|
-
|
|
478
|
+
/**
|
|
479
|
+
* The material's color.
|
|
480
|
+
*
|
|
481
|
+
* @type {Color}
|
|
482
|
+
* @default (1,1,1)
|
|
483
|
+
*/
|
|
484
|
+
get color() {
|
|
325
485
|
|
|
326
|
-
|
|
486
|
+
return this.uniforms.diffuse.value;
|
|
327
487
|
|
|
328
|
-
|
|
488
|
+
}
|
|
329
489
|
|
|
330
|
-
|
|
490
|
+
set color( value ) {
|
|
331
491
|
|
|
332
|
-
|
|
492
|
+
this.uniforms.diffuse.value = value;
|
|
333
493
|
|
|
334
|
-
|
|
494
|
+
}
|
|
335
495
|
|
|
336
|
-
|
|
496
|
+
/**
|
|
497
|
+
* Whether the material's sizes (width, dash gaps) are in world units.
|
|
498
|
+
*
|
|
499
|
+
* @type {boolean}
|
|
500
|
+
* @default false
|
|
501
|
+
*/
|
|
502
|
+
get worldUnits() {
|
|
337
503
|
|
|
338
|
-
|
|
504
|
+
return 'WORLD_UNITS' in this.defines;
|
|
339
505
|
|
|
340
|
-
|
|
506
|
+
}
|
|
341
507
|
|
|
342
|
-
|
|
508
|
+
set worldUnits( value ) {
|
|
343
509
|
|
|
344
|
-
|
|
510
|
+
if ( ( value === true ) !== this.worldUnits ) {
|
|
345
511
|
|
|
346
|
-
|
|
512
|
+
this.needsUpdate = true;
|
|
347
513
|
|
|
348
|
-
|
|
514
|
+
}
|
|
349
515
|
|
|
350
|
-
|
|
516
|
+
if ( value === true ) {
|
|
351
517
|
|
|
352
|
-
|
|
518
|
+
this.defines.WORLD_UNITS = '';
|
|
353
519
|
|
|
354
|
-
|
|
520
|
+
} else {
|
|
355
521
|
|
|
356
|
-
|
|
522
|
+
delete this.defines.WORLD_UNITS;
|
|
357
523
|
|
|
358
|
-
|
|
524
|
+
}
|
|
359
525
|
|
|
360
|
-
|
|
526
|
+
}
|
|
361
527
|
|
|
362
|
-
|
|
528
|
+
/**
|
|
529
|
+
* Controls line thickness in CSS pixel units when `worldUnits` is `false` (default),
|
|
530
|
+
* or in world units when `worldUnits` is `true`.
|
|
531
|
+
*
|
|
532
|
+
* @type {number}
|
|
533
|
+
* @default 1
|
|
534
|
+
*/
|
|
535
|
+
get linewidth() {
|
|
363
536
|
|
|
364
|
-
|
|
537
|
+
return this.uniforms.linewidth.value;
|
|
365
538
|
|
|
366
|
-
|
|
539
|
+
}
|
|
367
540
|
|
|
368
|
-
|
|
541
|
+
set linewidth( value ) {
|
|
369
542
|
|
|
370
|
-
|
|
543
|
+
if ( ! this.uniforms.linewidth ) return;
|
|
544
|
+
this.uniforms.linewidth.value = value;
|
|
371
545
|
|
|
372
|
-
|
|
546
|
+
}
|
|
373
547
|
|
|
374
|
-
|
|
548
|
+
/**
|
|
549
|
+
* Whether the line is dashed, or solid.
|
|
550
|
+
*
|
|
551
|
+
* @type {boolean}
|
|
552
|
+
* @default false
|
|
553
|
+
*/
|
|
554
|
+
get dashed() {
|
|
375
555
|
|
|
376
|
-
|
|
556
|
+
return 'USE_DASH' in this.defines;
|
|
377
557
|
|
|
378
|
-
|
|
558
|
+
}
|
|
379
559
|
|
|
380
|
-
|
|
560
|
+
set dashed( value ) {
|
|
381
561
|
|
|
382
|
-
|
|
562
|
+
if ( ( value === true ) !== this.dashed ) {
|
|
383
563
|
|
|
384
|
-
|
|
564
|
+
this.needsUpdate = true;
|
|
385
565
|
|
|
386
|
-
|
|
566
|
+
}
|
|
387
567
|
|
|
388
|
-
|
|
568
|
+
if ( value === true ) {
|
|
389
569
|
|
|
390
|
-
|
|
570
|
+
this.defines.USE_DASH = '';
|
|
391
571
|
|
|
392
|
-
|
|
572
|
+
} else {
|
|
393
573
|
|
|
394
|
-
|
|
574
|
+
delete this.defines.USE_DASH;
|
|
395
575
|
|
|
396
|
-
|
|
576
|
+
}
|
|
397
577
|
|
|
398
|
-
|
|
578
|
+
}
|
|
399
579
|
|
|
400
|
-
|
|
580
|
+
/**
|
|
581
|
+
* The scale of the dashes and gaps.
|
|
582
|
+
*
|
|
583
|
+
* @type {number}
|
|
584
|
+
* @default 1
|
|
585
|
+
*/
|
|
586
|
+
get dashScale() {
|
|
401
587
|
|
|
402
|
-
|
|
588
|
+
return this.uniforms.dashScale.value;
|
|
403
589
|
|
|
404
|
-
|
|
590
|
+
}
|
|
405
591
|
|
|
406
|
-
|
|
592
|
+
set dashScale( value ) {
|
|
407
593
|
|
|
408
|
-
|
|
594
|
+
this.uniforms.dashScale.value = value;
|
|
409
595
|
|
|
410
|
-
|
|
596
|
+
}
|
|
411
597
|
|
|
412
|
-
|
|
598
|
+
/**
|
|
599
|
+
* The size of the dash.
|
|
600
|
+
*
|
|
601
|
+
* @type {number}
|
|
602
|
+
* @default 1
|
|
603
|
+
*/
|
|
604
|
+
get dashSize() {
|
|
413
605
|
|
|
414
|
-
|
|
606
|
+
return this.uniforms.dashSize.value;
|
|
415
607
|
|
|
416
|
-
|
|
608
|
+
}
|
|
417
609
|
|
|
418
|
-
|
|
610
|
+
set dashSize( value ) {
|
|
419
611
|
|
|
420
|
-
|
|
612
|
+
this.uniforms.dashSize.value = value;
|
|
421
613
|
|
|
422
|
-
|
|
614
|
+
}
|
|
423
615
|
|
|
424
|
-
|
|
616
|
+
/**
|
|
617
|
+
* Where in the dash cycle the dash starts.
|
|
618
|
+
*
|
|
619
|
+
* @type {number}
|
|
620
|
+
* @default 0
|
|
621
|
+
*/
|
|
622
|
+
get dashOffset() {
|
|
425
623
|
|
|
426
|
-
|
|
624
|
+
return this.uniforms.dashOffset.value;
|
|
427
625
|
|
|
428
|
-
|
|
626
|
+
}
|
|
429
627
|
|
|
430
|
-
|
|
628
|
+
set dashOffset( value ) {
|
|
431
629
|
|
|
432
|
-
|
|
630
|
+
this.uniforms.dashOffset.value = value;
|
|
433
631
|
|
|
434
|
-
|
|
632
|
+
}
|
|
435
633
|
|
|
436
|
-
|
|
634
|
+
/**
|
|
635
|
+
* The size of the gap.
|
|
636
|
+
*
|
|
637
|
+
* @type {number}
|
|
638
|
+
* @default 0
|
|
639
|
+
*/
|
|
640
|
+
get gapSize() {
|
|
437
641
|
|
|
438
|
-
|
|
642
|
+
return this.uniforms.gapSize.value;
|
|
439
643
|
|
|
440
|
-
|
|
644
|
+
}
|
|
441
645
|
|
|
442
|
-
|
|
646
|
+
set gapSize( value ) {
|
|
443
647
|
|
|
444
|
-
|
|
648
|
+
this.uniforms.gapSize.value = value;
|
|
445
649
|
|
|
446
|
-
|
|
650
|
+
}
|
|
447
651
|
|
|
448
|
-
|
|
652
|
+
/**
|
|
653
|
+
* The opacity.
|
|
654
|
+
*
|
|
655
|
+
* @type {number}
|
|
656
|
+
* @default 1
|
|
657
|
+
*/
|
|
658
|
+
get opacity() {
|
|
449
659
|
|
|
450
|
-
|
|
660
|
+
return this.uniforms.opacity.value;
|
|
451
661
|
|
|
452
|
-
|
|
662
|
+
}
|
|
453
663
|
|
|
454
|
-
|
|
664
|
+
set opacity( value ) {
|
|
455
665
|
|
|
456
|
-
|
|
666
|
+
if ( ! this.uniforms ) return;
|
|
667
|
+
this.uniforms.opacity.value = value;
|
|
457
668
|
|
|
458
|
-
|
|
669
|
+
}
|
|
459
670
|
|
|
460
|
-
|
|
671
|
+
/**
|
|
672
|
+
* The size of the viewport, in screen pixels. This must be kept updated to make
|
|
673
|
+
* screen-space rendering accurate. The `LineSegments2.onBeforeRender` callback
|
|
674
|
+
* performs the update for visible objects.
|
|
675
|
+
*
|
|
676
|
+
* @type {Vector2}
|
|
677
|
+
*/
|
|
678
|
+
get resolution() {
|
|
461
679
|
|
|
462
|
-
|
|
680
|
+
return this.uniforms.resolution.value;
|
|
463
681
|
|
|
464
|
-
|
|
682
|
+
}
|
|
465
683
|
|
|
466
|
-
|
|
684
|
+
set resolution( value ) {
|
|
467
685
|
|
|
468
|
-
|
|
686
|
+
this.uniforms.resolution.value.copy( value );
|
|
469
687
|
|
|
470
|
-
|
|
688
|
+
}
|
|
471
689
|
|
|
472
|
-
|
|
690
|
+
/**
|
|
691
|
+
* Whether to use alphaToCoverage or not. When enabled, this can improve the
|
|
692
|
+
* anti-aliasing of line edges when using MSAA.
|
|
693
|
+
*
|
|
694
|
+
* @type {boolean}
|
|
695
|
+
*/
|
|
696
|
+
get alphaToCoverage() {
|
|
473
697
|
|
|
474
|
-
|
|
698
|
+
return 'USE_ALPHA_TO_COVERAGE' in this.defines;
|
|
475
699
|
|
|
476
|
-
|
|
700
|
+
}
|
|
477
701
|
|
|
478
|
-
|
|
702
|
+
set alphaToCoverage( value ) {
|
|
479
703
|
|
|
480
|
-
|
|
704
|
+
if ( ! this.defines ) return;
|
|
481
705
|
|
|
482
|
-
|
|
483
|
-
this.extensions.derivatives = true;
|
|
706
|
+
if ( ( value === true ) !== this.alphaToCoverage ) {
|
|
484
707
|
|
|
485
|
-
|
|
708
|
+
this.needsUpdate = true;
|
|
486
709
|
|
|
487
|
-
|
|
488
|
-
this.extensions.derivatives = false;
|
|
710
|
+
}
|
|
489
711
|
|
|
490
|
-
|
|
712
|
+
if ( value === true ) {
|
|
491
713
|
|
|
492
|
-
|
|
714
|
+
this.defines.USE_ALPHA_TO_COVERAGE = '';
|
|
493
715
|
|
|
494
|
-
|
|
716
|
+
} else {
|
|
495
717
|
|
|
496
|
-
|
|
718
|
+
delete this.defines.USE_ALPHA_TO_COVERAGE;
|
|
497
719
|
|
|
498
|
-
|
|
720
|
+
}
|
|
499
721
|
|
|
500
722
|
}
|
|
501
723
|
|
|
502
724
|
}
|
|
503
725
|
|
|
504
|
-
LineMaterial.prototype.isLineMaterial = true;
|
|
505
|
-
|
|
506
726
|
export { LineMaterial };
|