@ohuoy/easymap 1.0.19 → 1.0.21
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/dist/bundle.js +318 -290
- package/dist/example - /345/211/257/346/234/254/bundle.js" +318 -290
- package/dist/example - /345/211/257/346/234/254/index.html" +11 -11
- package/index.js +4 -0
- package/lib/threebox-plugin/CHANGELOG.md +665 -0
- package/lib/threebox-plugin/LICENSE.txt +97 -0
- package/lib/threebox-plugin/README.md +199 -0
- package/lib/threebox-plugin/exports.js +2 -0
- package/lib/threebox-plugin/main.js +8 -0
- package/lib/threebox-plugin/package.json +44 -0
- package/lib/threebox-plugin/server.stop.js +13 -0
- package/lib/threebox-plugin/src/Threebox.js +1216 -0
- package/lib/threebox-plugin/src/animation/AnimationManager.js +483 -0
- package/lib/threebox-plugin/src/camera/CameraSync.js +302 -0
- package/lib/threebox-plugin/src/objects/CSS2DRenderer.js +245 -0
- package/lib/threebox-plugin/src/objects/LabelRenderer.js +71 -0
- package/lib/threebox-plugin/src/objects/Object3D.js +34 -0
- package/lib/threebox-plugin/src/objects/effects/BuildingShadows.js +115 -0
- package/lib/threebox-plugin/src/objects/extrusion.js +61 -0
- package/lib/threebox-plugin/src/objects/fflate.min.js +15 -0
- package/lib/threebox-plugin/src/objects/label.js +29 -0
- package/lib/threebox-plugin/src/objects/line.js +1386 -0
- package/lib/threebox-plugin/src/objects/loadObj.js +142 -0
- package/lib/threebox-plugin/src/objects/loaders/ColladaLoader.js +3751 -0
- package/lib/threebox-plugin/src/objects/loaders/FBXLoader.js +3864 -0
- package/lib/threebox-plugin/src/objects/loaders/GLTFLoader.js +3857 -0
- package/lib/threebox-plugin/src/objects/loaders/MTLLoader.js +498 -0
- package/lib/threebox-plugin/src/objects/loaders/OBJLoader.js +818 -0
- package/lib/threebox-plugin/src/objects/objects.js +1113 -0
- package/lib/threebox-plugin/src/objects/sphere.js +28 -0
- package/lib/threebox-plugin/src/objects/tooltip.js +27 -0
- package/lib/threebox-plugin/src/objects/tube.js +35 -0
- package/lib/threebox-plugin/src/three.js +6 -0
- package/lib/threebox-plugin/src/three.module.js +54571 -0
- package/lib/threebox-plugin/src/utils/ValueGenerator.js +11 -0
- package/lib/threebox-plugin/src/utils/constants.js +21 -0
- package/lib/threebox-plugin/src/utils/material.js +52 -0
- package/lib/threebox-plugin/src/utils/suncalc.js +322 -0
- package/lib/threebox-plugin/src/utils/utils.js +424 -0
- package/lib/threebox-plugin/src/utils/validate.js +115 -0
- package/package.json +18 -18
- package/src/components/EasyMapMarker.js +8 -0
- package/src/components/control/DrawBar.js +5 -0
- package/src/components/control/TilesBar.js +116 -27
- package/src/components/control/Toobars.js +20 -1
- package/src/components/layer/AlarmLayer.js +4 -1
- package/src/components/layer/AnimationBarbsLayer.js +1 -1
- package/src/components/layer/AnimationLayer copy.js +1 -1
- package/src/components/layer/AnimationLayer.js +11 -3
- package/src/components/layer/CustomIconLayer.js +1 -1
- package/src/components/layer/ExtrusionLayer.js +1 -1
- package/src/components/layer/ExtrusionLayerold.js +2 -1
- package/src/components/layer/MarkerAreaLayer.js +1 -1
- package/src/components/layer/PathLineLayer.js +1 -1
- package/src/components/layer/ThreeScanLayer.js +51 -14
- package/src/components/layer/ThreeWallLayer.js +1 -1
- package/webpack.config.js +2 -1
|
@@ -0,0 +1,1386 @@
|
|
|
1
|
+
import * as THREEOBJ from '../three.module.js'
|
|
2
|
+
import utils from '../utils/utils.js';
|
|
3
|
+
import Objects from './objects.js';
|
|
4
|
+
// const THREE = require("../three.js");
|
|
5
|
+
// const utils = require("../utils/utils.js");
|
|
6
|
+
// const Objects = require('./objects.js');
|
|
7
|
+
let THREE = Object.assign({},THREEOBJ)
|
|
8
|
+
function line(obj){
|
|
9
|
+
|
|
10
|
+
obj = utils._validate(obj, Objects.prototype._defaults.line);
|
|
11
|
+
|
|
12
|
+
// Geometry
|
|
13
|
+
var straightProject = utils.lnglatsToWorld(obj.geometry);
|
|
14
|
+
var normalized = utils.normalizeVertices(straightProject);
|
|
15
|
+
var flattenedArray = utils.flattenVectors(normalized.vertices);
|
|
16
|
+
//console.log('line', normalized.vertices)
|
|
17
|
+
|
|
18
|
+
var geometry = new THREE.LineGeometry();
|
|
19
|
+
geometry.setPositions( flattenedArray );
|
|
20
|
+
|
|
21
|
+
// Material
|
|
22
|
+
let matLine = new THREE.LineMaterial( {
|
|
23
|
+
color: obj.color,
|
|
24
|
+
linewidth: obj.width, // in pixels
|
|
25
|
+
dashed: false,
|
|
26
|
+
opacity: obj.opacity
|
|
27
|
+
} );
|
|
28
|
+
|
|
29
|
+
matLine.resolution.set( window.innerWidth, window.innerHeight );
|
|
30
|
+
matLine.isMaterial = true;
|
|
31
|
+
matLine.transparent = true;
|
|
32
|
+
matLine.depthWrite = false;
|
|
33
|
+
|
|
34
|
+
// Mesh
|
|
35
|
+
line = new THREE.Line2( geometry, matLine );
|
|
36
|
+
line.position.copy(normalized.position)
|
|
37
|
+
line.computeLineDistances();
|
|
38
|
+
|
|
39
|
+
return line
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default line;
|
|
43
|
+
// module.exports = exports = line;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* custom line shader by WestLangley, sourced from https://github.com/mrdoob/three.js/tree/master/examples/js/lines
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
(function () {
|
|
51
|
+
|
|
52
|
+
const _box = new THREE.Box3();
|
|
53
|
+
|
|
54
|
+
const _vector = new THREE.Vector3();
|
|
55
|
+
|
|
56
|
+
class LineSegmentsGeometry extends THREE.InstancedBufferGeometry {
|
|
57
|
+
|
|
58
|
+
constructor() {
|
|
59
|
+
|
|
60
|
+
super();
|
|
61
|
+
this.type = 'LineSegmentsGeometry';
|
|
62
|
+
const positions = [- 1, 2, 0, 1, 2, 0, - 1, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 0, - 1, - 1, 0, 1, - 1, 0];
|
|
63
|
+
const uvs = [- 1, 2, 1, 2, - 1, 1, 1, 1, - 1, - 1, 1, - 1, - 1, - 2, 1, - 2];
|
|
64
|
+
const index = [0, 2, 1, 2, 3, 1, 2, 4, 3, 4, 5, 3, 4, 6, 5, 6, 7, 5];
|
|
65
|
+
this.setIndex(index);
|
|
66
|
+
this.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3));
|
|
67
|
+
this.setAttribute('uv', new THREE.Float32BufferAttribute(uvs, 2));
|
|
68
|
+
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
applyMatrix4(matrix) {
|
|
72
|
+
|
|
73
|
+
const start = this.attributes.instanceStart;
|
|
74
|
+
const end = this.attributes.instanceEnd;
|
|
75
|
+
|
|
76
|
+
if (start !== undefined) {
|
|
77
|
+
|
|
78
|
+
start.applyMatrix4(matrix);
|
|
79
|
+
end.applyMatrix4(matrix);
|
|
80
|
+
start.needsUpdate = true;
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (this.boundingBox !== null) {
|
|
85
|
+
|
|
86
|
+
this.computeBoundingBox();
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (this.boundingSphere !== null) {
|
|
91
|
+
|
|
92
|
+
this.computeBoundingSphere();
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return this;
|
|
97
|
+
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
setPositions(array) {
|
|
101
|
+
|
|
102
|
+
let lineSegments;
|
|
103
|
+
|
|
104
|
+
if (array instanceof Float32Array) {
|
|
105
|
+
|
|
106
|
+
lineSegments = array;
|
|
107
|
+
|
|
108
|
+
} else if (Array.isArray(array)) {
|
|
109
|
+
|
|
110
|
+
lineSegments = new Float32Array(array);
|
|
111
|
+
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const instanceBuffer = new THREE.InstancedInterleavedBuffer(lineSegments, 6, 1); // xyz, xyz
|
|
115
|
+
|
|
116
|
+
this.setAttribute('instanceStart', new THREE.InterleavedBufferAttribute(instanceBuffer, 3, 0)); // xyz
|
|
117
|
+
|
|
118
|
+
this.setAttribute('instanceEnd', new THREE.InterleavedBufferAttribute(instanceBuffer, 3, 3)); // xyz
|
|
119
|
+
//
|
|
120
|
+
|
|
121
|
+
this.computeBoundingBox();
|
|
122
|
+
this.computeBoundingSphere();
|
|
123
|
+
return this;
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
setColors(array) {
|
|
128
|
+
|
|
129
|
+
let colors;
|
|
130
|
+
|
|
131
|
+
if (array instanceof Float32Array) {
|
|
132
|
+
|
|
133
|
+
colors = array;
|
|
134
|
+
|
|
135
|
+
} else if (Array.isArray(array)) {
|
|
136
|
+
|
|
137
|
+
colors = new Float32Array(array);
|
|
138
|
+
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const instanceColorBuffer = new THREE.InstancedInterleavedBuffer(colors, 6, 1); // rgb, rgb
|
|
142
|
+
|
|
143
|
+
this.setAttribute('instanceColorStart', new THREE.InterleavedBufferAttribute(instanceColorBuffer, 3, 0)); // rgb
|
|
144
|
+
|
|
145
|
+
this.setAttribute('instanceColorEnd', new THREE.InterleavedBufferAttribute(instanceColorBuffer, 3, 3)); // rgb
|
|
146
|
+
|
|
147
|
+
return this;
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
fromWireframeGeometry(geometry) {
|
|
152
|
+
|
|
153
|
+
this.setPositions(geometry.attributes.position.array);
|
|
154
|
+
return this;
|
|
155
|
+
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
fromEdgesGeometry(geometry) {
|
|
159
|
+
|
|
160
|
+
this.setPositions(geometry.attributes.position.array);
|
|
161
|
+
return this;
|
|
162
|
+
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
fromMesh(mesh) {
|
|
166
|
+
|
|
167
|
+
this.fromWireframeGeometry(new THREE.WireframeGeometry(mesh.geometry)); // set colors, maybe
|
|
168
|
+
|
|
169
|
+
return this;
|
|
170
|
+
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
fromLineSegments(lineSegments) {
|
|
174
|
+
|
|
175
|
+
const geometry = lineSegments.geometry;
|
|
176
|
+
|
|
177
|
+
if (geometry.isGeometry) {
|
|
178
|
+
|
|
179
|
+
console.error('THREE.LineSegmentsGeometry no longer supports Geometry. Use THREE.BufferGeometry instead.');
|
|
180
|
+
return;
|
|
181
|
+
|
|
182
|
+
} else if (geometry.isBufferGeometry) {
|
|
183
|
+
|
|
184
|
+
this.setPositions(geometry.attributes.position.array); // assumes non-indexed
|
|
185
|
+
|
|
186
|
+
} // set colors, maybe
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
return this;
|
|
190
|
+
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
computeBoundingBox() {
|
|
194
|
+
|
|
195
|
+
if (this.boundingBox === null) {
|
|
196
|
+
|
|
197
|
+
this.boundingBox = new THREE.Box3();
|
|
198
|
+
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const start = this.attributes.instanceStart;
|
|
202
|
+
const end = this.attributes.instanceEnd;
|
|
203
|
+
|
|
204
|
+
if (start !== undefined && end !== undefined) {
|
|
205
|
+
|
|
206
|
+
this.boundingBox.setFromBufferAttribute(start);
|
|
207
|
+
|
|
208
|
+
_box.setFromBufferAttribute(end);
|
|
209
|
+
|
|
210
|
+
this.boundingBox.union(_box);
|
|
211
|
+
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
computeBoundingSphere() {
|
|
217
|
+
|
|
218
|
+
if (this.boundingSphere === null) {
|
|
219
|
+
|
|
220
|
+
this.boundingSphere = new THREE.Sphere();
|
|
221
|
+
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (this.boundingBox === null) {
|
|
225
|
+
|
|
226
|
+
this.computeBoundingBox();
|
|
227
|
+
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const start = this.attributes.instanceStart;
|
|
231
|
+
const end = this.attributes.instanceEnd;
|
|
232
|
+
|
|
233
|
+
if (start !== undefined && end !== undefined) {
|
|
234
|
+
|
|
235
|
+
const center = this.boundingSphere.center;
|
|
236
|
+
this.boundingBox.getCenter(center);
|
|
237
|
+
let maxRadiusSq = 0;
|
|
238
|
+
|
|
239
|
+
for (let i = 0, il = start.count; i < il; i++) {
|
|
240
|
+
|
|
241
|
+
_vector.fromBufferAttribute(start, i);
|
|
242
|
+
|
|
243
|
+
maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector));
|
|
244
|
+
|
|
245
|
+
_vector.fromBufferAttribute(end, i);
|
|
246
|
+
|
|
247
|
+
maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector));
|
|
248
|
+
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
this.boundingSphere.radius = Math.sqrt(maxRadiusSq);
|
|
252
|
+
|
|
253
|
+
if (isNaN(this.boundingSphere.radius)) {
|
|
254
|
+
|
|
255
|
+
console.error('THREE.LineSegmentsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.', this);
|
|
256
|
+
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
toJSON() { // todo
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
applyMatrix(matrix) {
|
|
267
|
+
|
|
268
|
+
console.warn('THREE.LineSegmentsGeometry: applyMatrix() has been renamed to applyMatrix4().');
|
|
269
|
+
return this.applyMatrix4(matrix);
|
|
270
|
+
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
LineSegmentsGeometry.prototype.isLineSegmentsGeometry = true;
|
|
276
|
+
|
|
277
|
+
THREE.LineSegmentsGeometry = LineSegmentsGeometry;
|
|
278
|
+
|
|
279
|
+
})();
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* @author WestLangley / http://github.com/WestLangley
|
|
283
|
+
*
|
|
284
|
+
*/
|
|
285
|
+
|
|
286
|
+
(function () {
|
|
287
|
+
|
|
288
|
+
class LineGeometry extends THREE.LineSegmentsGeometry {
|
|
289
|
+
|
|
290
|
+
constructor() {
|
|
291
|
+
|
|
292
|
+
super();
|
|
293
|
+
this.type = 'LineGeometry';
|
|
294
|
+
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
setPositions(array) {
|
|
298
|
+
|
|
299
|
+
// converts [ x1, y1, z1, x2, y2, z2, ... ] to pairs format
|
|
300
|
+
var length = array.length - 3;
|
|
301
|
+
var points = new Float32Array(2 * length);
|
|
302
|
+
|
|
303
|
+
for (var i = 0; i < length; i += 3) {
|
|
304
|
+
|
|
305
|
+
points[2 * i] = array[i];
|
|
306
|
+
points[2 * i + 1] = array[i + 1];
|
|
307
|
+
points[2 * i + 2] = array[i + 2];
|
|
308
|
+
points[2 * i + 3] = array[i + 3];
|
|
309
|
+
points[2 * i + 4] = array[i + 4];
|
|
310
|
+
points[2 * i + 5] = array[i + 5];
|
|
311
|
+
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
super.setPositions(points);
|
|
315
|
+
return this;
|
|
316
|
+
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
setColors(array) {
|
|
320
|
+
|
|
321
|
+
// converts [ r1, g1, b1, r2, g2, b2, ... ] to pairs format
|
|
322
|
+
var length = array.length - 3;
|
|
323
|
+
var colors = new Float32Array(2 * length);
|
|
324
|
+
|
|
325
|
+
for (var i = 0; i < length; i += 3) {
|
|
326
|
+
|
|
327
|
+
colors[2 * i] = array[i];
|
|
328
|
+
colors[2 * i + 1] = array[i + 1];
|
|
329
|
+
colors[2 * i + 2] = array[i + 2];
|
|
330
|
+
colors[2 * i + 3] = array[i + 3];
|
|
331
|
+
colors[2 * i + 4] = array[i + 4];
|
|
332
|
+
colors[2 * i + 5] = array[i + 5];
|
|
333
|
+
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
super.setColors(colors);
|
|
337
|
+
return this;
|
|
338
|
+
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
fromLine(line) {
|
|
342
|
+
|
|
343
|
+
var geometry = line.geometry;
|
|
344
|
+
|
|
345
|
+
if (geometry.isGeometry) {
|
|
346
|
+
|
|
347
|
+
console.error('THREE.LineGeometry no longer supports Geometry. Use THREE.BufferGeometry instead.');
|
|
348
|
+
return;
|
|
349
|
+
|
|
350
|
+
} else if (geometry.isBufferGeometry) {
|
|
351
|
+
|
|
352
|
+
this.setPositions(geometry.attributes.position.array); // assumes non-indexed
|
|
353
|
+
|
|
354
|
+
} // set colors, maybe
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
return this;
|
|
358
|
+
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
LineGeometry.prototype.isLineGeometry = true;
|
|
364
|
+
|
|
365
|
+
THREE.LineGeometry = LineGeometry;
|
|
366
|
+
|
|
367
|
+
})();
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* @author WestLangley / http://github.com/WestLangley
|
|
371
|
+
*
|
|
372
|
+
*/
|
|
373
|
+
|
|
374
|
+
(function () {
|
|
375
|
+
|
|
376
|
+
class WireframeGeometry2 extends THREE.LineSegmentsGeometry {
|
|
377
|
+
|
|
378
|
+
constructor(geometry) {
|
|
379
|
+
|
|
380
|
+
super();
|
|
381
|
+
this.type = 'WireframeGeometry2';
|
|
382
|
+
this.fromWireframeGeometry(new THREE.WireframeGeometry(geometry)); // set colors, maybe
|
|
383
|
+
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
WireframeGeometry2.prototype.isWireframeGeometry2 = true;
|
|
389
|
+
|
|
390
|
+
THREE.WireframeGeometry2 = WireframeGeometry2;
|
|
391
|
+
|
|
392
|
+
})();
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* @author WestLangley / http://github.com/WestLangley
|
|
396
|
+
*
|
|
397
|
+
* parameters = {
|
|
398
|
+
* color: <hex>,
|
|
399
|
+
* linewidth: <float>,
|
|
400
|
+
* dashed: <boolean>,
|
|
401
|
+
* dashScale: <float>,
|
|
402
|
+
* dashSize: <float>,
|
|
403
|
+
* gapSize: <float>,
|
|
404
|
+
* resolution: <Vector2>, // to be set by renderer
|
|
405
|
+
* }
|
|
406
|
+
*/
|
|
407
|
+
|
|
408
|
+
(function () {
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* parameters = {
|
|
412
|
+
* color: <hex>,
|
|
413
|
+
* linewidth: <float>,
|
|
414
|
+
* dashed: <boolean>,
|
|
415
|
+
* dashScale: <float>,
|
|
416
|
+
* dashSize: <float>,
|
|
417
|
+
* gapSize: <float>,
|
|
418
|
+
* resolution: <Vector2>, // to be set by renderer
|
|
419
|
+
* }
|
|
420
|
+
*/
|
|
421
|
+
THREE.UniformsLib.line = {
|
|
422
|
+
worldUnits: {
|
|
423
|
+
value: 1
|
|
424
|
+
},
|
|
425
|
+
linewidth: {
|
|
426
|
+
value: 1
|
|
427
|
+
},
|
|
428
|
+
resolution: {
|
|
429
|
+
value: new THREE.Vector2(1, 1)
|
|
430
|
+
},
|
|
431
|
+
dashScale: {
|
|
432
|
+
value: 1
|
|
433
|
+
},
|
|
434
|
+
dashSize: {
|
|
435
|
+
value: 1
|
|
436
|
+
},
|
|
437
|
+
gapSize: {
|
|
438
|
+
value: 1
|
|
439
|
+
} // todo FIX - maybe change to totalSize
|
|
440
|
+
|
|
441
|
+
};
|
|
442
|
+
THREE.ShaderLib['line'] = {
|
|
443
|
+
uniforms: THREE.UniformsUtils.merge([THREE.UniformsLib.common, THREE.UniformsLib.fog, THREE.UniformsLib.line]),
|
|
444
|
+
vertexShader:
|
|
445
|
+
/* glsl */
|
|
446
|
+
`
|
|
447
|
+
#include <common>
|
|
448
|
+
#include <color_pars_vertex>
|
|
449
|
+
#include <fog_pars_vertex>
|
|
450
|
+
#include <logdepthbuf_pars_vertex>
|
|
451
|
+
#include <clipping_planes_pars_vertex>
|
|
452
|
+
|
|
453
|
+
uniform float linewidth;
|
|
454
|
+
uniform vec2 resolution;
|
|
455
|
+
|
|
456
|
+
attribute vec3 instanceStart;
|
|
457
|
+
attribute vec3 instanceEnd;
|
|
458
|
+
|
|
459
|
+
attribute vec3 instanceColorStart;
|
|
460
|
+
attribute vec3 instanceColorEnd;
|
|
461
|
+
|
|
462
|
+
varying vec2 vUv;
|
|
463
|
+
varying vec4 worldPos;
|
|
464
|
+
varying vec3 worldStart;
|
|
465
|
+
varying vec3 worldEnd;
|
|
466
|
+
|
|
467
|
+
#ifdef USE_DASH
|
|
468
|
+
|
|
469
|
+
uniform float dashScale;
|
|
470
|
+
attribute float instanceDistanceStart;
|
|
471
|
+
attribute float instanceDistanceEnd;
|
|
472
|
+
varying float vLineDistance;
|
|
473
|
+
|
|
474
|
+
#endif
|
|
475
|
+
|
|
476
|
+
void trimSegment( const in vec4 start, inout vec4 end ) {
|
|
477
|
+
|
|
478
|
+
// trim end segment so it terminates between the camera plane and the near plane
|
|
479
|
+
|
|
480
|
+
// conservative estimate of the near plane
|
|
481
|
+
float a = projectionMatrix[ 2 ][ 2 ]; // 3nd entry in 3th column
|
|
482
|
+
float b = projectionMatrix[ 3 ][ 2 ]; // 3nd entry in 4th column
|
|
483
|
+
float nearEstimate = - 0.5 * b / a;
|
|
484
|
+
|
|
485
|
+
float alpha = ( nearEstimate - start.z ) / ( end.z - start.z );
|
|
486
|
+
|
|
487
|
+
end.xyz = mix( start.xyz, end.xyz, alpha );
|
|
488
|
+
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
void main() {
|
|
492
|
+
|
|
493
|
+
#ifdef USE_COLOR
|
|
494
|
+
|
|
495
|
+
vColor.xyz = ( position.y < 0.5 ) ? instanceColorStart : instanceColorEnd;
|
|
496
|
+
|
|
497
|
+
#endif
|
|
498
|
+
|
|
499
|
+
#ifdef USE_DASH
|
|
500
|
+
|
|
501
|
+
vLineDistance = ( position.y < 0.5 ) ? dashScale * instanceDistanceStart : dashScale * instanceDistanceEnd;
|
|
502
|
+
|
|
503
|
+
#endif
|
|
504
|
+
|
|
505
|
+
float aspect = resolution.x / resolution.y;
|
|
506
|
+
|
|
507
|
+
vUv = uv;
|
|
508
|
+
|
|
509
|
+
// camera space
|
|
510
|
+
vec4 start = modelViewMatrix * vec4( instanceStart, 1.0 );
|
|
511
|
+
vec4 end = modelViewMatrix * vec4( instanceEnd, 1.0 );
|
|
512
|
+
|
|
513
|
+
worldStart = start.xyz;
|
|
514
|
+
worldEnd = end.xyz;
|
|
515
|
+
|
|
516
|
+
// special case for perspective projection, and segments that terminate either in, or behind, the camera plane
|
|
517
|
+
// clearly the gpu firmware has a way of addressing this issue when projecting into ndc space
|
|
518
|
+
// but we need to perform ndc-space calculations in the shader, so we must address this issue directly
|
|
519
|
+
// perhaps there is a more elegant solution -- WestLangley
|
|
520
|
+
|
|
521
|
+
bool perspective = ( projectionMatrix[ 2 ][ 3 ] == - 1.0 ); // 4th entry in the 3rd column
|
|
522
|
+
|
|
523
|
+
if ( perspective ) {
|
|
524
|
+
|
|
525
|
+
if ( start.z < 0.0 && end.z >= 0.0 ) {
|
|
526
|
+
|
|
527
|
+
trimSegment( start, end );
|
|
528
|
+
|
|
529
|
+
} else if ( end.z < 0.0 && start.z >= 0.0 ) {
|
|
530
|
+
|
|
531
|
+
trimSegment( end, start );
|
|
532
|
+
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// clip space
|
|
538
|
+
vec4 clipStart = projectionMatrix * start;
|
|
539
|
+
vec4 clipEnd = projectionMatrix * end;
|
|
540
|
+
|
|
541
|
+
// ndc space
|
|
542
|
+
vec3 ndcStart = clipStart.xyz / clipStart.w;
|
|
543
|
+
vec3 ndcEnd = clipEnd.xyz / clipEnd.w;
|
|
544
|
+
|
|
545
|
+
// direction
|
|
546
|
+
vec2 dir = ndcEnd.xy - ndcStart.xy;
|
|
547
|
+
|
|
548
|
+
// account for clip-space aspect ratio
|
|
549
|
+
dir.x *= aspect;
|
|
550
|
+
dir = normalize( dir );
|
|
551
|
+
|
|
552
|
+
#ifdef WORLD_UNITS
|
|
553
|
+
|
|
554
|
+
// get the offset direction as perpendicular to the view vector
|
|
555
|
+
vec3 worldDir = normalize( end.xyz - start.xyz );
|
|
556
|
+
vec3 offset;
|
|
557
|
+
if ( position.y < 0.5 ) {
|
|
558
|
+
|
|
559
|
+
offset = normalize( cross( start.xyz, worldDir ) );
|
|
560
|
+
|
|
561
|
+
} else {
|
|
562
|
+
|
|
563
|
+
offset = normalize( cross( end.xyz, worldDir ) );
|
|
564
|
+
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// sign flip
|
|
568
|
+
if ( position.x < 0.0 ) offset *= - 1.0;
|
|
569
|
+
|
|
570
|
+
float forwardOffset = dot( worldDir, vec3( 0.0, 0.0, 1.0 ) );
|
|
571
|
+
|
|
572
|
+
// don't extend the line if we're rendering dashes because we
|
|
573
|
+
// won't be rendering the endcaps
|
|
574
|
+
#ifndef USE_DASH
|
|
575
|
+
|
|
576
|
+
// extend the line bounds to encompass endcaps
|
|
577
|
+
start.xyz += - worldDir * linewidth * 0.5;
|
|
578
|
+
end.xyz += worldDir * linewidth * 0.5;
|
|
579
|
+
|
|
580
|
+
// shift the position of the quad so it hugs the forward edge of the line
|
|
581
|
+
offset.xy -= dir * forwardOffset;
|
|
582
|
+
offset.z += 0.5;
|
|
583
|
+
|
|
584
|
+
#endif
|
|
585
|
+
|
|
586
|
+
// endcaps
|
|
587
|
+
if ( position.y > 1.0 || position.y < 0.0 ) {
|
|
588
|
+
|
|
589
|
+
offset.xy += dir * 2.0 * forwardOffset;
|
|
590
|
+
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// adjust for linewidth
|
|
594
|
+
offset *= linewidth * 0.5;
|
|
595
|
+
|
|
596
|
+
// set the world position
|
|
597
|
+
worldPos = ( position.y < 0.5 ) ? start : end;
|
|
598
|
+
worldPos.xyz += offset;
|
|
599
|
+
|
|
600
|
+
// project the worldpos
|
|
601
|
+
vec4 clip = projectionMatrix * worldPos;
|
|
602
|
+
|
|
603
|
+
// shift the depth of the projected points so the line
|
|
604
|
+
// segements overlap neatly
|
|
605
|
+
vec3 clipPose = ( position.y < 0.5 ) ? ndcStart : ndcEnd;
|
|
606
|
+
clip.z = clipPose.z * clip.w;
|
|
607
|
+
|
|
608
|
+
#else
|
|
609
|
+
|
|
610
|
+
vec2 offset = vec2( dir.y, - dir.x );
|
|
611
|
+
// undo aspect ratio adjustment
|
|
612
|
+
dir.x /= aspect;
|
|
613
|
+
offset.x /= aspect;
|
|
614
|
+
|
|
615
|
+
// sign flip
|
|
616
|
+
if ( position.x < 0.0 ) offset *= - 1.0;
|
|
617
|
+
|
|
618
|
+
// endcaps
|
|
619
|
+
if ( position.y < 0.0 ) {
|
|
620
|
+
|
|
621
|
+
offset += - dir;
|
|
622
|
+
|
|
623
|
+
} else if ( position.y > 1.0 ) {
|
|
624
|
+
|
|
625
|
+
offset += dir;
|
|
626
|
+
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// adjust for linewidth
|
|
630
|
+
offset *= linewidth;
|
|
631
|
+
|
|
632
|
+
// adjust for clip-space to screen-space conversion // maybe resolution should be based on viewport ...
|
|
633
|
+
offset /= resolution.y;
|
|
634
|
+
|
|
635
|
+
// select end
|
|
636
|
+
vec4 clip = ( position.y < 0.5 ) ? clipStart : clipEnd;
|
|
637
|
+
|
|
638
|
+
// back to clip space
|
|
639
|
+
offset *= clip.w;
|
|
640
|
+
|
|
641
|
+
clip.xy += offset;
|
|
642
|
+
|
|
643
|
+
#endif
|
|
644
|
+
|
|
645
|
+
gl_Position = clip;
|
|
646
|
+
|
|
647
|
+
vec4 mvPosition = ( position.y < 0.5 ) ? start : end; // this is an approximation
|
|
648
|
+
|
|
649
|
+
#include <logdepthbuf_vertex>
|
|
650
|
+
#include <clipping_planes_vertex>
|
|
651
|
+
#include <fog_vertex>
|
|
652
|
+
|
|
653
|
+
}
|
|
654
|
+
`,
|
|
655
|
+
fragmentShader:
|
|
656
|
+
/* glsl */
|
|
657
|
+
`
|
|
658
|
+
uniform vec3 diffuse;
|
|
659
|
+
uniform float opacity;
|
|
660
|
+
uniform float linewidth;
|
|
661
|
+
|
|
662
|
+
#ifdef USE_DASH
|
|
663
|
+
|
|
664
|
+
uniform float dashSize;
|
|
665
|
+
uniform float gapSize;
|
|
666
|
+
|
|
667
|
+
#endif
|
|
668
|
+
|
|
669
|
+
varying float vLineDistance;
|
|
670
|
+
varying vec4 worldPos;
|
|
671
|
+
varying vec3 worldStart;
|
|
672
|
+
varying vec3 worldEnd;
|
|
673
|
+
|
|
674
|
+
#include <common>
|
|
675
|
+
#include <color_pars_fragment>
|
|
676
|
+
#include <fog_pars_fragment>
|
|
677
|
+
#include <logdepthbuf_pars_fragment>
|
|
678
|
+
#include <clipping_planes_pars_fragment>
|
|
679
|
+
|
|
680
|
+
varying vec2 vUv;
|
|
681
|
+
|
|
682
|
+
vec2 closestLineToLine(vec3 p1, vec3 p2, vec3 p3, vec3 p4) {
|
|
683
|
+
|
|
684
|
+
float mua;
|
|
685
|
+
float mub;
|
|
686
|
+
|
|
687
|
+
vec3 p13 = p1 - p3;
|
|
688
|
+
vec3 p43 = p4 - p3;
|
|
689
|
+
|
|
690
|
+
vec3 p21 = p2 - p1;
|
|
691
|
+
|
|
692
|
+
float d1343 = dot( p13, p43 );
|
|
693
|
+
float d4321 = dot( p43, p21 );
|
|
694
|
+
float d1321 = dot( p13, p21 );
|
|
695
|
+
float d4343 = dot( p43, p43 );
|
|
696
|
+
float d2121 = dot( p21, p21 );
|
|
697
|
+
|
|
698
|
+
float denom = d2121 * d4343 - d4321 * d4321;
|
|
699
|
+
|
|
700
|
+
float numer = d1343 * d4321 - d1321 * d4343;
|
|
701
|
+
|
|
702
|
+
mua = numer / denom;
|
|
703
|
+
mua = clamp( mua, 0.0, 1.0 );
|
|
704
|
+
mub = ( d1343 + d4321 * ( mua ) ) / d4343;
|
|
705
|
+
mub = clamp( mub, 0.0, 1.0 );
|
|
706
|
+
|
|
707
|
+
return vec2( mua, mub );
|
|
708
|
+
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
void main() {
|
|
712
|
+
|
|
713
|
+
#include <clipping_planes_fragment>
|
|
714
|
+
|
|
715
|
+
#ifdef USE_DASH
|
|
716
|
+
|
|
717
|
+
if ( vUv.y < - 1.0 || vUv.y > 1.0 ) discard; // discard endcaps
|
|
718
|
+
|
|
719
|
+
if ( mod( vLineDistance, dashSize + gapSize ) > dashSize ) discard; // todo - FIX
|
|
720
|
+
|
|
721
|
+
#endif
|
|
722
|
+
|
|
723
|
+
float alpha = opacity;
|
|
724
|
+
|
|
725
|
+
#ifdef WORLD_UNITS
|
|
726
|
+
|
|
727
|
+
// Find the closest points on the view ray and the line segment
|
|
728
|
+
vec3 rayEnd = normalize( worldPos.xyz ) * 1e5;
|
|
729
|
+
vec3 lineDir = worldEnd - worldStart;
|
|
730
|
+
vec2 params = closestLineToLine( worldStart, worldEnd, vec3( 0.0, 0.0, 0.0 ), rayEnd );
|
|
731
|
+
|
|
732
|
+
vec3 p1 = worldStart + lineDir * params.x;
|
|
733
|
+
vec3 p2 = rayEnd * params.y;
|
|
734
|
+
vec3 delta = p1 - p2;
|
|
735
|
+
float len = length( delta );
|
|
736
|
+
float norm = len / linewidth;
|
|
737
|
+
|
|
738
|
+
#ifndef USE_DASH
|
|
739
|
+
|
|
740
|
+
#ifdef ALPHA_TO_COVERAGE
|
|
741
|
+
|
|
742
|
+
float dnorm = fwidth( norm );
|
|
743
|
+
alpha = 1.0 - smoothstep( 0.5 - dnorm, 0.5 + dnorm, norm );
|
|
744
|
+
|
|
745
|
+
#else
|
|
746
|
+
|
|
747
|
+
if ( norm > 0.5 ) {
|
|
748
|
+
|
|
749
|
+
discard;
|
|
750
|
+
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
#endif
|
|
754
|
+
|
|
755
|
+
#endif
|
|
756
|
+
|
|
757
|
+
#else
|
|
758
|
+
|
|
759
|
+
#ifdef ALPHA_TO_COVERAGE
|
|
760
|
+
|
|
761
|
+
// artifacts appear on some hardware if a derivative is taken within a conditional
|
|
762
|
+
float a = vUv.x;
|
|
763
|
+
float b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;
|
|
764
|
+
float len2 = a * a + b * b;
|
|
765
|
+
float dlen = fwidth( len2 );
|
|
766
|
+
|
|
767
|
+
if ( abs( vUv.y ) > 1.0 ) {
|
|
768
|
+
|
|
769
|
+
alpha = 1.0 - smoothstep( 1.0 - dlen, 1.0 + dlen, len2 );
|
|
770
|
+
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
#else
|
|
774
|
+
|
|
775
|
+
if ( abs( vUv.y ) > 1.0 ) {
|
|
776
|
+
|
|
777
|
+
float a = vUv.x;
|
|
778
|
+
float b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;
|
|
779
|
+
float len2 = a * a + b * b;
|
|
780
|
+
|
|
781
|
+
if ( len2 > 1.0 ) discard;
|
|
782
|
+
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
#endif
|
|
786
|
+
|
|
787
|
+
#endif
|
|
788
|
+
|
|
789
|
+
vec4 diffuseColor = vec4( diffuse, alpha );
|
|
790
|
+
|
|
791
|
+
#include <logdepthbuf_fragment>
|
|
792
|
+
#include <color_fragment>
|
|
793
|
+
|
|
794
|
+
gl_FragColor = vec4( diffuseColor.rgb, alpha );
|
|
795
|
+
|
|
796
|
+
#include <tonemapping_fragment>
|
|
797
|
+
#include <encodings_fragment>
|
|
798
|
+
#include <fog_fragment>
|
|
799
|
+
#include <premultiplied_alpha_fragment>
|
|
800
|
+
|
|
801
|
+
}
|
|
802
|
+
`
|
|
803
|
+
};
|
|
804
|
+
|
|
805
|
+
class LineMaterial extends THREE.ShaderMaterial {
|
|
806
|
+
|
|
807
|
+
constructor(parameters) {
|
|
808
|
+
|
|
809
|
+
super({
|
|
810
|
+
type: 'LineMaterial',
|
|
811
|
+
uniforms: THREE.UniformsUtils.clone(THREE.ShaderLib['line'].uniforms),
|
|
812
|
+
vertexShader: THREE.ShaderLib['line'].vertexShader,
|
|
813
|
+
fragmentShader: THREE.ShaderLib['line'].fragmentShader,
|
|
814
|
+
clipping: true // required for clipping support
|
|
815
|
+
|
|
816
|
+
});
|
|
817
|
+
Object.defineProperties(this, {
|
|
818
|
+
color: {
|
|
819
|
+
enumerable: true,
|
|
820
|
+
get: function () {
|
|
821
|
+
|
|
822
|
+
return this.uniforms.diffuse.value;
|
|
823
|
+
|
|
824
|
+
},
|
|
825
|
+
set: function (value) {
|
|
826
|
+
|
|
827
|
+
this.uniforms.diffuse.value = value;
|
|
828
|
+
|
|
829
|
+
}
|
|
830
|
+
},
|
|
831
|
+
worldUnits: {
|
|
832
|
+
enumerable: true,
|
|
833
|
+
get: function () {
|
|
834
|
+
|
|
835
|
+
return 'WORLD_UNITS' in this.defines;
|
|
836
|
+
|
|
837
|
+
},
|
|
838
|
+
set: function (value) {
|
|
839
|
+
|
|
840
|
+
if (value === true) {
|
|
841
|
+
|
|
842
|
+
this.defines.WORLD_UNITS = '';
|
|
843
|
+
|
|
844
|
+
} else {
|
|
845
|
+
|
|
846
|
+
delete this.defines.WORLD_UNITS;
|
|
847
|
+
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
}
|
|
851
|
+
},
|
|
852
|
+
linewidth: {
|
|
853
|
+
enumerable: true,
|
|
854
|
+
get: function () {
|
|
855
|
+
|
|
856
|
+
return this.uniforms.linewidth.value;
|
|
857
|
+
|
|
858
|
+
},
|
|
859
|
+
set: function (value) {
|
|
860
|
+
|
|
861
|
+
this.uniforms.linewidth.value = value;
|
|
862
|
+
|
|
863
|
+
}
|
|
864
|
+
},
|
|
865
|
+
dashed: {
|
|
866
|
+
enumerable: true,
|
|
867
|
+
get: function () {
|
|
868
|
+
|
|
869
|
+
return Boolean('USE_DASH' in this.defines);
|
|
870
|
+
|
|
871
|
+
},
|
|
872
|
+
|
|
873
|
+
set(value) {
|
|
874
|
+
|
|
875
|
+
if (Boolean(value) !== Boolean('USE_DASH' in this.defines)) {
|
|
876
|
+
|
|
877
|
+
this.needsUpdate = true;
|
|
878
|
+
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
if (value === true) {
|
|
882
|
+
|
|
883
|
+
this.defines.USE_DASH = '';
|
|
884
|
+
|
|
885
|
+
} else {
|
|
886
|
+
|
|
887
|
+
delete this.defines.USE_DASH;
|
|
888
|
+
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
},
|
|
894
|
+
dashScale: {
|
|
895
|
+
enumerable: true,
|
|
896
|
+
get: function () {
|
|
897
|
+
|
|
898
|
+
return this.uniforms.dashScale.value;
|
|
899
|
+
|
|
900
|
+
},
|
|
901
|
+
set: function (value) {
|
|
902
|
+
|
|
903
|
+
this.uniforms.dashScale.value = value;
|
|
904
|
+
|
|
905
|
+
}
|
|
906
|
+
},
|
|
907
|
+
dashSize: {
|
|
908
|
+
enumerable: true,
|
|
909
|
+
get: function () {
|
|
910
|
+
|
|
911
|
+
return this.uniforms.dashSize.value;
|
|
912
|
+
|
|
913
|
+
},
|
|
914
|
+
set: function (value) {
|
|
915
|
+
|
|
916
|
+
this.uniforms.dashSize.value = value;
|
|
917
|
+
|
|
918
|
+
}
|
|
919
|
+
},
|
|
920
|
+
dashOffset: {
|
|
921
|
+
enumerable: true,
|
|
922
|
+
get: function () {
|
|
923
|
+
|
|
924
|
+
return this.uniforms.dashOffset.value;
|
|
925
|
+
|
|
926
|
+
},
|
|
927
|
+
set: function (value) {
|
|
928
|
+
|
|
929
|
+
this.uniforms.dashOffset.value = value;
|
|
930
|
+
|
|
931
|
+
}
|
|
932
|
+
},
|
|
933
|
+
gapSize: {
|
|
934
|
+
enumerable: true,
|
|
935
|
+
get: function () {
|
|
936
|
+
|
|
937
|
+
return this.uniforms.gapSize.value;
|
|
938
|
+
|
|
939
|
+
},
|
|
940
|
+
set: function (value) {
|
|
941
|
+
|
|
942
|
+
this.uniforms.gapSize.value = value;
|
|
943
|
+
|
|
944
|
+
}
|
|
945
|
+
},
|
|
946
|
+
opacity: {
|
|
947
|
+
enumerable: true,
|
|
948
|
+
get: function () {
|
|
949
|
+
|
|
950
|
+
return this.uniforms.opacity.value;
|
|
951
|
+
|
|
952
|
+
},
|
|
953
|
+
set: function (value) {
|
|
954
|
+
|
|
955
|
+
this.uniforms.opacity.value = value;
|
|
956
|
+
|
|
957
|
+
}
|
|
958
|
+
},
|
|
959
|
+
resolution: {
|
|
960
|
+
enumerable: true,
|
|
961
|
+
get: function () {
|
|
962
|
+
|
|
963
|
+
return this.uniforms.resolution.value;
|
|
964
|
+
|
|
965
|
+
},
|
|
966
|
+
set: function (value) {
|
|
967
|
+
|
|
968
|
+
this.uniforms.resolution.value.copy(value);
|
|
969
|
+
|
|
970
|
+
}
|
|
971
|
+
},
|
|
972
|
+
alphaToCoverage: {
|
|
973
|
+
enumerable: true,
|
|
974
|
+
get: function () {
|
|
975
|
+
|
|
976
|
+
return Boolean('ALPHA_TO_COVERAGE' in this.defines);
|
|
977
|
+
|
|
978
|
+
},
|
|
979
|
+
set: function (value) {
|
|
980
|
+
|
|
981
|
+
if (Boolean(value) !== Boolean('ALPHA_TO_COVERAGE' in this.defines)) {
|
|
982
|
+
|
|
983
|
+
this.needsUpdate = true;
|
|
984
|
+
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
if (value === true) {
|
|
988
|
+
|
|
989
|
+
this.defines.ALPHA_TO_COVERAGE = '';
|
|
990
|
+
this.extensions.derivatives = true;
|
|
991
|
+
|
|
992
|
+
} else {
|
|
993
|
+
|
|
994
|
+
delete this.defines.ALPHA_TO_COVERAGE;
|
|
995
|
+
this.extensions.derivatives = false;
|
|
996
|
+
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
});
|
|
1002
|
+
this.setValues(parameters);
|
|
1003
|
+
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
LineMaterial.prototype.isLineMaterial = true;
|
|
1009
|
+
|
|
1010
|
+
THREE.LineMaterial = LineMaterial;
|
|
1011
|
+
|
|
1012
|
+
})();
|
|
1013
|
+
|
|
1014
|
+
/**
|
|
1015
|
+
* @author WestLangley / http://github.com/WestLangley
|
|
1016
|
+
*
|
|
1017
|
+
*/
|
|
1018
|
+
|
|
1019
|
+
(function () {
|
|
1020
|
+
|
|
1021
|
+
const _start = new THREE.Vector3();
|
|
1022
|
+
|
|
1023
|
+
const _end = new THREE.Vector3();
|
|
1024
|
+
|
|
1025
|
+
const _start4 = new THREE.Vector4();
|
|
1026
|
+
|
|
1027
|
+
const _end4 = new THREE.Vector4();
|
|
1028
|
+
|
|
1029
|
+
const _ssOrigin = new THREE.Vector4();
|
|
1030
|
+
|
|
1031
|
+
const _ssOrigin3 = new THREE.Vector3();
|
|
1032
|
+
|
|
1033
|
+
const _mvMatrix = new THREE.Matrix4();
|
|
1034
|
+
|
|
1035
|
+
const _line = new THREE.Line3();
|
|
1036
|
+
|
|
1037
|
+
const _closestPoint = new THREE.Vector3();
|
|
1038
|
+
|
|
1039
|
+
const _box = new THREE.Box3();
|
|
1040
|
+
|
|
1041
|
+
const _sphere = new THREE.Sphere();
|
|
1042
|
+
|
|
1043
|
+
const _clipToWorldVector = new THREE.Vector4();
|
|
1044
|
+
|
|
1045
|
+
class LineSegments2 extends THREE.Mesh {
|
|
1046
|
+
|
|
1047
|
+
constructor(geometry = new THREE.LineSegmentsGeometry(), material = new THREE.LineMaterial({
|
|
1048
|
+
color: Math.random() * 0xffffff
|
|
1049
|
+
})) {
|
|
1050
|
+
|
|
1051
|
+
super(geometry, material);
|
|
1052
|
+
this.type = 'LineSegments2';
|
|
1053
|
+
|
|
1054
|
+
} // for backwards-compatability, but could be a method of THREE.LineSegmentsGeometry...
|
|
1055
|
+
|
|
1056
|
+
|
|
1057
|
+
computeLineDistances() {
|
|
1058
|
+
|
|
1059
|
+
const geometry = this.geometry;
|
|
1060
|
+
const instanceStart = geometry.attributes.instanceStart;
|
|
1061
|
+
const instanceEnd = geometry.attributes.instanceEnd;
|
|
1062
|
+
const lineDistances = new Float32Array(2 * instanceStart.count);
|
|
1063
|
+
|
|
1064
|
+
for (let i = 0, j = 0, l = instanceStart.count; i < l; i++, j += 2) {
|
|
1065
|
+
|
|
1066
|
+
_start.fromBufferAttribute(instanceStart, i);
|
|
1067
|
+
|
|
1068
|
+
_end.fromBufferAttribute(instanceEnd, i);
|
|
1069
|
+
|
|
1070
|
+
lineDistances[j] = j === 0 ? 0 : lineDistances[j - 1];
|
|
1071
|
+
lineDistances[j + 1] = lineDistances[j] + _start.distanceTo(_end);
|
|
1072
|
+
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
const instanceDistanceBuffer = new THREE.InstancedInterleavedBuffer(lineDistances, 2, 1); // d0, d1
|
|
1076
|
+
|
|
1077
|
+
geometry.setAttribute('instanceDistanceStart', new THREE.InterleavedBufferAttribute(instanceDistanceBuffer, 1, 0)); // d0
|
|
1078
|
+
|
|
1079
|
+
geometry.setAttribute('instanceDistanceEnd', new THREE.InterleavedBufferAttribute(instanceDistanceBuffer, 1, 1)); // d1
|
|
1080
|
+
|
|
1081
|
+
return this;
|
|
1082
|
+
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
raycast(raycaster, intersects) {
|
|
1086
|
+
|
|
1087
|
+
if (raycaster.camera === null) {
|
|
1088
|
+
|
|
1089
|
+
console.error('LineSegments2: "Raycaster.camera" needs to be set in order to raycast against LineSegments2.');
|
|
1090
|
+
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
const threshold = raycaster.params.Line2 !== undefined ? raycaster.params.Line2.threshold || 0 : 0;
|
|
1094
|
+
const ray = raycaster.ray;
|
|
1095
|
+
const camera = raycaster.camera;
|
|
1096
|
+
const projectionMatrix = camera.projectionMatrix;
|
|
1097
|
+
const matrixWorld = this.matrixWorld;
|
|
1098
|
+
const geometry = this.geometry;
|
|
1099
|
+
const material = this.material;
|
|
1100
|
+
const resolution = material.resolution;
|
|
1101
|
+
const lineWidth = material.linewidth + threshold;
|
|
1102
|
+
const instanceStart = geometry.attributes.instanceStart;
|
|
1103
|
+
const instanceEnd = geometry.attributes.instanceEnd; // camera forward is negative
|
|
1104
|
+
|
|
1105
|
+
const near = - camera.near; // clip space is [ - 1, 1 ] so multiply by two to get the full
|
|
1106
|
+
// width in clip space
|
|
1107
|
+
|
|
1108
|
+
const ssMaxWidth = 2.0 * Math.max(lineWidth / resolution.width, lineWidth / resolution.height); //
|
|
1109
|
+
// check if we intersect the sphere bounds
|
|
1110
|
+
|
|
1111
|
+
if (geometry.boundingSphere === null) {
|
|
1112
|
+
|
|
1113
|
+
geometry.computeBoundingSphere();
|
|
1114
|
+
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
_sphere.copy(geometry.boundingSphere).applyMatrix4(matrixWorld);
|
|
1118
|
+
|
|
1119
|
+
const distanceToSphere = Math.max(camera.near, _sphere.distanceToPoint(ray.origin)); // get the w component to scale the world space line width
|
|
1120
|
+
|
|
1121
|
+
_clipToWorldVector.set(0, 0, - distanceToSphere, 1.0).applyMatrix4(camera.projectionMatrix);
|
|
1122
|
+
|
|
1123
|
+
_clipToWorldVector.multiplyScalar(1.0 / _clipToWorldVector.w);
|
|
1124
|
+
|
|
1125
|
+
_clipToWorldVector.applyMatrix4(camera.projectionMatrixInverse); // increase the sphere bounds by the worst case line screen space width
|
|
1126
|
+
|
|
1127
|
+
|
|
1128
|
+
const sphereMargin = Math.abs(ssMaxWidth / _clipToWorldVector.w) * 0.5;
|
|
1129
|
+
_sphere.radius += sphereMargin;
|
|
1130
|
+
|
|
1131
|
+
if (raycaster.ray.intersectsSphere(_sphere) === false) {
|
|
1132
|
+
|
|
1133
|
+
return;
|
|
1134
|
+
|
|
1135
|
+
} //
|
|
1136
|
+
// check if we intersect the box bounds
|
|
1137
|
+
|
|
1138
|
+
|
|
1139
|
+
if (geometry.boundingBox === null) {
|
|
1140
|
+
|
|
1141
|
+
geometry.computeBoundingBox();
|
|
1142
|
+
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
_box.copy(geometry.boundingBox).applyMatrix4(matrixWorld);
|
|
1146
|
+
|
|
1147
|
+
const distanceToBox = Math.max(camera.near, _box.distanceToPoint(ray.origin)); // get the w component to scale the world space line width
|
|
1148
|
+
|
|
1149
|
+
_clipToWorldVector.set(0, 0, - distanceToBox, 1.0).applyMatrix4(camera.projectionMatrix);
|
|
1150
|
+
|
|
1151
|
+
_clipToWorldVector.multiplyScalar(1.0 / _clipToWorldVector.w);
|
|
1152
|
+
|
|
1153
|
+
_clipToWorldVector.applyMatrix4(camera.projectionMatrixInverse); // increase the sphere bounds by the worst case line screen space width
|
|
1154
|
+
|
|
1155
|
+
|
|
1156
|
+
const boxMargin = Math.abs(ssMaxWidth / _clipToWorldVector.w) * 0.5;
|
|
1157
|
+
_box.max.x += boxMargin;
|
|
1158
|
+
_box.max.y += boxMargin;
|
|
1159
|
+
_box.max.z += boxMargin;
|
|
1160
|
+
_box.min.x -= boxMargin;
|
|
1161
|
+
_box.min.y -= boxMargin;
|
|
1162
|
+
_box.min.z -= boxMargin;
|
|
1163
|
+
|
|
1164
|
+
if (raycaster.ray.intersectsBox(_box) === false) {
|
|
1165
|
+
|
|
1166
|
+
return;
|
|
1167
|
+
|
|
1168
|
+
} //
|
|
1169
|
+
// pick a point 1 unit out along the ray to avoid the ray origin
|
|
1170
|
+
// sitting at the camera origin which will cause "w" to be 0 when
|
|
1171
|
+
// applying the projection matrix.
|
|
1172
|
+
|
|
1173
|
+
|
|
1174
|
+
ray.at(1, _ssOrigin); // ndc space [ - 1.0, 1.0 ]
|
|
1175
|
+
|
|
1176
|
+
_ssOrigin.w = 1;
|
|
1177
|
+
|
|
1178
|
+
_ssOrigin.applyMatrix4(camera.matrixWorldInverse);
|
|
1179
|
+
|
|
1180
|
+
_ssOrigin.applyMatrix4(projectionMatrix);
|
|
1181
|
+
|
|
1182
|
+
_ssOrigin.multiplyScalar(1 / _ssOrigin.w); // screen space
|
|
1183
|
+
|
|
1184
|
+
|
|
1185
|
+
_ssOrigin.x *= resolution.x / 2;
|
|
1186
|
+
_ssOrigin.y *= resolution.y / 2;
|
|
1187
|
+
_ssOrigin.z = 0;
|
|
1188
|
+
|
|
1189
|
+
_ssOrigin3.copy(_ssOrigin);
|
|
1190
|
+
|
|
1191
|
+
_mvMatrix.multiplyMatrices(camera.matrixWorldInverse, matrixWorld);
|
|
1192
|
+
|
|
1193
|
+
for (let i = 0, l = instanceStart.count; i < l; i++) {
|
|
1194
|
+
|
|
1195
|
+
_start4.fromBufferAttribute(instanceStart, i);
|
|
1196
|
+
|
|
1197
|
+
_end4.fromBufferAttribute(instanceEnd, i);
|
|
1198
|
+
|
|
1199
|
+
_start4.w = 1;
|
|
1200
|
+
_end4.w = 1; // camera space
|
|
1201
|
+
|
|
1202
|
+
_start4.applyMatrix4(_mvMatrix);
|
|
1203
|
+
|
|
1204
|
+
_end4.applyMatrix4(_mvMatrix); // skip the segment if it's entirely behind the camera
|
|
1205
|
+
|
|
1206
|
+
|
|
1207
|
+
var isBehindCameraNear = _start4.z > near && _end4.z > near;
|
|
1208
|
+
|
|
1209
|
+
if (isBehindCameraNear) {
|
|
1210
|
+
|
|
1211
|
+
continue;
|
|
1212
|
+
|
|
1213
|
+
} // trim the segment if it extends behind camera near
|
|
1214
|
+
|
|
1215
|
+
|
|
1216
|
+
if (_start4.z > near) {
|
|
1217
|
+
|
|
1218
|
+
const deltaDist = _start4.z - _end4.z;
|
|
1219
|
+
const t = (_start4.z - near) / deltaDist;
|
|
1220
|
+
|
|
1221
|
+
_start4.lerp(_end4, t);
|
|
1222
|
+
|
|
1223
|
+
} else if (_end4.z > near) {
|
|
1224
|
+
|
|
1225
|
+
const deltaDist = _end4.z - _start4.z;
|
|
1226
|
+
const t = (_end4.z - near) / deltaDist;
|
|
1227
|
+
|
|
1228
|
+
_end4.lerp(_start4, t);
|
|
1229
|
+
|
|
1230
|
+
} // clip space
|
|
1231
|
+
|
|
1232
|
+
|
|
1233
|
+
_start4.applyMatrix4(projectionMatrix);
|
|
1234
|
+
|
|
1235
|
+
_end4.applyMatrix4(projectionMatrix); // ndc space [ - 1.0, 1.0 ]
|
|
1236
|
+
|
|
1237
|
+
|
|
1238
|
+
_start4.multiplyScalar(1 / _start4.w);
|
|
1239
|
+
|
|
1240
|
+
_end4.multiplyScalar(1 / _end4.w); // screen space
|
|
1241
|
+
|
|
1242
|
+
|
|
1243
|
+
_start4.x *= resolution.x / 2;
|
|
1244
|
+
_start4.y *= resolution.y / 2;
|
|
1245
|
+
_end4.x *= resolution.x / 2;
|
|
1246
|
+
_end4.y *= resolution.y / 2; // create 2d segment
|
|
1247
|
+
|
|
1248
|
+
_line.start.copy(_start4);
|
|
1249
|
+
|
|
1250
|
+
_line.start.z = 0;
|
|
1251
|
+
|
|
1252
|
+
_line.end.copy(_end4);
|
|
1253
|
+
|
|
1254
|
+
_line.end.z = 0; // get closest point on ray to segment
|
|
1255
|
+
|
|
1256
|
+
const param = _line.closestPointToPointParameter(_ssOrigin3, true);
|
|
1257
|
+
|
|
1258
|
+
_line.at(param, _closestPoint); // check if the intersection point is within clip space
|
|
1259
|
+
|
|
1260
|
+
|
|
1261
|
+
const zPos = THREE.MathUtils.lerp(_start4.z, _end4.z, param);
|
|
1262
|
+
const isInClipSpace = zPos >= - 1 && zPos <= 1;
|
|
1263
|
+
const isInside = _ssOrigin3.distanceTo(_closestPoint) < lineWidth * 0.5;
|
|
1264
|
+
|
|
1265
|
+
if (isInClipSpace && isInside) {
|
|
1266
|
+
|
|
1267
|
+
_line.start.fromBufferAttribute(instanceStart, i);
|
|
1268
|
+
|
|
1269
|
+
_line.end.fromBufferAttribute(instanceEnd, i);
|
|
1270
|
+
|
|
1271
|
+
_line.start.applyMatrix4(matrixWorld);
|
|
1272
|
+
|
|
1273
|
+
_line.end.applyMatrix4(matrixWorld);
|
|
1274
|
+
|
|
1275
|
+
const pointOnLine = new THREE.Vector3();
|
|
1276
|
+
const point = new THREE.Vector3();
|
|
1277
|
+
ray.distanceSqToSegment(_line.start, _line.end, point, pointOnLine);
|
|
1278
|
+
intersects.push({
|
|
1279
|
+
point: point,
|
|
1280
|
+
pointOnLine: pointOnLine,
|
|
1281
|
+
distance: ray.origin.distanceTo(point),
|
|
1282
|
+
object: this,
|
|
1283
|
+
face: null,
|
|
1284
|
+
faceIndex: i,
|
|
1285
|
+
uv: null,
|
|
1286
|
+
uv2: null
|
|
1287
|
+
});
|
|
1288
|
+
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
LineSegments2.prototype.LineSegments2 = true;
|
|
1298
|
+
|
|
1299
|
+
THREE.LineSegments2 = LineSegments2;
|
|
1300
|
+
|
|
1301
|
+
})();
|
|
1302
|
+
|
|
1303
|
+
/**
|
|
1304
|
+
* @author WestLangley / http://github.com/WestLangley
|
|
1305
|
+
*
|
|
1306
|
+
*/
|
|
1307
|
+
|
|
1308
|
+
(function () {
|
|
1309
|
+
|
|
1310
|
+
class Line2 extends THREE.LineSegments2 {
|
|
1311
|
+
|
|
1312
|
+
constructor(geometry = new THREE.LineGeometry(), material = new THREE.LineMaterial({
|
|
1313
|
+
color: Math.random() * 0xffffff
|
|
1314
|
+
})) {
|
|
1315
|
+
|
|
1316
|
+
super(geometry, material);
|
|
1317
|
+
this.type = 'Line2';
|
|
1318
|
+
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
Line2.prototype.isLine2 = true;
|
|
1324
|
+
|
|
1325
|
+
THREE.Line2 = Line2;
|
|
1326
|
+
|
|
1327
|
+
})();
|
|
1328
|
+
|
|
1329
|
+
/**
|
|
1330
|
+
* @author WestLangley / http://github.com/WestLangley
|
|
1331
|
+
*
|
|
1332
|
+
*/
|
|
1333
|
+
|
|
1334
|
+
(function () {
|
|
1335
|
+
|
|
1336
|
+
const _start = new THREE.Vector3();
|
|
1337
|
+
|
|
1338
|
+
const _end = new THREE.Vector3();
|
|
1339
|
+
|
|
1340
|
+
class Wireframe extends THREE.Mesh {
|
|
1341
|
+
|
|
1342
|
+
constructor(geometry = new THREE.LineSegmentsGeometry(), material = new THREE.LineMaterial({
|
|
1343
|
+
color: Math.random() * 0xffffff
|
|
1344
|
+
})) {
|
|
1345
|
+
|
|
1346
|
+
super(geometry, material);
|
|
1347
|
+
this.type = 'Wireframe';
|
|
1348
|
+
|
|
1349
|
+
} // for backwards-compatability, but could be a method of THREE.LineSegmentsGeometry...
|
|
1350
|
+
|
|
1351
|
+
|
|
1352
|
+
computeLineDistances() {
|
|
1353
|
+
|
|
1354
|
+
const geometry = this.geometry;
|
|
1355
|
+
const instanceStart = geometry.attributes.instanceStart;
|
|
1356
|
+
const instanceEnd = geometry.attributes.instanceEnd;
|
|
1357
|
+
const lineDistances = new Float32Array(2 * instanceStart.count);
|
|
1358
|
+
|
|
1359
|
+
for (let i = 0, j = 0, l = instanceStart.count; i < l; i++, j += 2) {
|
|
1360
|
+
|
|
1361
|
+
_start.fromBufferAttribute(instanceStart, i);
|
|
1362
|
+
|
|
1363
|
+
_end.fromBufferAttribute(instanceEnd, i);
|
|
1364
|
+
|
|
1365
|
+
lineDistances[j] = j === 0 ? 0 : lineDistances[j - 1];
|
|
1366
|
+
lineDistances[j + 1] = lineDistances[j] + _start.distanceTo(_end);
|
|
1367
|
+
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
const instanceDistanceBuffer = new THREE.InstancedInterleavedBuffer(lineDistances, 2, 1); // d0, d1
|
|
1371
|
+
|
|
1372
|
+
geometry.setAttribute('instanceDistanceStart', new THREE.InterleavedBufferAttribute(instanceDistanceBuffer, 1, 0)); // d0
|
|
1373
|
+
|
|
1374
|
+
geometry.setAttribute('instanceDistanceEnd', new THREE.InterleavedBufferAttribute(instanceDistanceBuffer, 1, 1)); // d1
|
|
1375
|
+
|
|
1376
|
+
return this;
|
|
1377
|
+
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
Wireframe.prototype.isWireframe = true;
|
|
1383
|
+
|
|
1384
|
+
THREE.Wireframe = Wireframe;
|
|
1385
|
+
|
|
1386
|
+
})();
|