@pirireis/webglobeplugins 0.8.26 → 0.9.2
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/Math/arc.ts +74 -245
- package/Math/constants.ts +4 -1
- package/Math/frustum/camera.ts +32 -0
- package/Math/frustum/from-globeinfo.ts +63 -0
- package/Math/frustum/types.ts +11 -0
- package/Math/globe-util/horizon-plane.ts +137 -0
- package/Math/juction/arc-plane.ts +90 -0
- package/Math/juction/line-sphere.ts +30 -0
- package/Math/juction/plane-plane.ts +66 -0
- package/Math/line.ts +70 -0
- package/Math/methods.js +29 -1
- package/Math/plane.ts +57 -138
- package/Math/quaternion.ts +108 -144
- package/Math/types.ts +39 -30
- package/Math/vec3.ts +155 -0
- package/altitude-locator/plugin.js +1 -1
- package/bearing-line/plugin.js +1 -1
- package/circle-line-chain/plugin.js +1 -1
- package/globe-types.ts +13 -0
- package/heatwave/plugins/heatwaveglobeshell.js +5 -9
- package/index.js +3 -0
- package/package.json +1 -1
- package/programs/interface.ts +7 -0
- package/programs/line-on-globe/circle-accurate-3d.js +1 -1
- package/programs/line-on-globe/degree-padding-around-circle-3d.js +1 -1
- package/programs/line-on-globe/lines-color-instanced-flat.js +1 -1
- package/programs/line-on-globe/linestrip.ts +228 -0
- package/programs/line-on-globe/naive-accurate-flexible.js +1 -1
- package/programs/line-on-globe/to-the-surface.js +1 -1
- package/programs/picking/pickable-renderer.js +1 -1
- package/programs/point-on-globe/element-globe-surface-glow.js +1 -1
- package/programs/point-on-globe/element-point-glow.js +1 -1
- package/programs/totems/camerauniformblock.js +24 -1
- package/shape-on-terrain/arc/naive/plugin.ts +304 -0
- package/tests/Math/junction/arc-plane.test.ts +129 -0
- package/tests/Math/junction/plane-plane.test.ts +82 -0
- package/tests/Math/plane.test.ts +30 -32
- package/tests/Math/vec3.test.ts +14 -0
- package/timetracks/plugin-line-strip.js +3 -1
- package/{types.js → types.ts} +2 -1
- package/util/account/{index.js → index.ts} +1 -2
- package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +0 -31
- package/util/account/single-attribute-buffer-management/index.ts +13 -0
- package/util/gl-util/buffer/{integrate-buffer.js → attribute-loader.ts} +17 -6
- package/util/gl-util/buffer/index.ts +6 -0
- package/util/gl-util/buffer/types.ts +13 -0
- package/util/gl-util/draw-options/methods.js +4 -4
- package/util/gl-util/draw-options/{types.js → types.ts} +10 -0
- package/util/gl-util/uniform-block/{manager.js → manager.ts} +24 -13
- package/util/gl-util/uniform-block/types.ts +27 -0
- package/util/heatwavedatamanager/pointcoordinatesdatacalculator.js +17 -17
- package/waveparticles/plugin.js +3 -0
- package/wind/plugin.js +39 -52
- package/Math/methodology/arc-part-on-screen.ts +0 -47
- package/Math/ray.ts +0 -101
- package/Math/vector3d.ts +0 -241
- package/shape-on-terrain/tree-search.js +0 -0
- package/surface-cover-shapes/arc/naive/data-manager.ts +0 -0
- package/surface-cover-shapes/arc/naive/plugin.ts +0 -0
- package/tests/Math/arc.test.ts +0 -112
- package/tests/Math/quaternion.test.ts +0 -98
- package/tests/Math/ray-plane.test.ts +0 -176
- package/tests/Math/vector3d.test.ts +0 -104
- package/util/account/single-attribute-buffer-management/index.js +0 -4
- package/util/gl-util/uniform-block/types.js +0 -7
- /package/{shape-on-terrain/intersection.js → Math/matrix4.ts} +0 -0
|
@@ -114,20 +114,20 @@ export default class PointCoordinatesDataCalculator {
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
function test() {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
117
|
+
// function test() {
|
|
118
|
+
// const cp = window.plugin.getPointCoordinatesDataCalculator();
|
|
119
|
+
// const bbox = [-15, 25, 70, 60];
|
|
120
|
+
// cp.registerPoint("left up", -15, 60, (data0, data1, interpolated) => {
|
|
121
|
+
// console.log("left up", data0, data1, interpolated);
|
|
122
|
+
// });
|
|
123
|
+
// cp.registerPoint("right up", 70, 60, (data0, data1, interpolated) => {
|
|
124
|
+
// console.log("right up", data0, data1, interpolated);
|
|
125
|
+
// });
|
|
126
|
+
// cp.registerPoint("left down", -15, 25, (data0, data1, interpolated) => {
|
|
127
|
+
// console.log("right down", data0, data1, interpolated);
|
|
128
|
+
// });
|
|
129
|
+
// cp.registerPoint("right down", 70, 25, (data0, data1, interpolated) => {
|
|
130
|
+
// console.log("right down", data0, data1, interpolated);
|
|
131
|
+
// });
|
|
132
|
+
// return cp;
|
|
133
|
+
// }
|
package/waveparticles/plugin.js
CHANGED
|
@@ -48,6 +48,7 @@ export default class Plugin {
|
|
|
48
48
|
}
|
|
49
49
|
this._stepIndex = 0;
|
|
50
50
|
this._fullCycleStepCount = 3;
|
|
51
|
+
this._isFreed = false;
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
init(globe, gl) {
|
|
@@ -96,6 +97,7 @@ export default class Plugin {
|
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
draw3D() {
|
|
100
|
+
if (this._isFreed) return;
|
|
99
101
|
const { gl, moveParticle, drawParticle, bufferManager, globeShellWiggle, waveUbo, fadeAway, _rgVectorFieldTexture } = this;
|
|
100
102
|
|
|
101
103
|
gl.disable(gl.DEPTH_TEST);
|
|
@@ -168,6 +170,7 @@ export default class Plugin {
|
|
|
168
170
|
// TODO: free all resources
|
|
169
171
|
free() {
|
|
170
172
|
const { gl, fadeAway, globeShellWiggle, _rgVectorFieldTexture, bufferManager, waveUbo, _drawTextures, _frameBuffer } = this;
|
|
173
|
+
this._isFreed = true;
|
|
171
174
|
fadeAway.free();
|
|
172
175
|
globeShellWiggle.free();
|
|
173
176
|
gl.deleteTexture(_rgVectorFieldTexture);
|
package/wind/plugin.js
CHANGED
|
@@ -300,18 +300,6 @@ void main() {
|
|
|
300
300
|
}`;
|
|
301
301
|
|
|
302
302
|
|
|
303
|
-
const reverseDefaultRampColors = [
|
|
304
|
-
[0.0, '#d53e4f'],
|
|
305
|
-
[0.2, '#f46d43'],
|
|
306
|
-
[0.3, '#fdae61'],
|
|
307
|
-
[0.4, '#fee08b'],
|
|
308
|
-
[0.5, '#e6f598'],
|
|
309
|
-
[0.6, '#abdda4'],
|
|
310
|
-
[0.7, '#66c2a5'],
|
|
311
|
-
[0.9, '#3288bd'],
|
|
312
|
-
// 1.0 deep purple
|
|
313
|
-
[1.0, '#5e4fa2']
|
|
314
|
-
];
|
|
315
303
|
|
|
316
304
|
const defaultRampColors = [
|
|
317
305
|
[0.0, '#5e4fa2'],
|
|
@@ -356,7 +344,11 @@ const windyLegendData = {
|
|
|
356
344
|
export default class WindPlugin {
|
|
357
345
|
|
|
358
346
|
/**
|
|
359
|
-
* @param {String} id
|
|
347
|
+
* @param {String} id
|
|
348
|
+
* @param {Object} windDataMeta
|
|
349
|
+
* @param {number} windDataMeta.width - image width
|
|
350
|
+
* @param {number} windDataMeta.height - image height
|
|
351
|
+
* @param {Array} windDataMeta.bbox - bounding box [minLon, minLat, maxLon, maxLat]
|
|
360
352
|
* @param {Object} options
|
|
361
353
|
* @param {number} options.fadeOpacity - how fast the particle trails fade on each frame | between 0 - 1 | default 0.746
|
|
362
354
|
* @param {number} options.speedFactor - how fast the particles move | between 0 - 1 | default 0.6
|
|
@@ -370,25 +362,28 @@ export default class WindPlugin {
|
|
|
370
362
|
* @param {number} numParticles - number of particles | positive integer
|
|
371
363
|
* @param {LegendData} options.legendData - legend data
|
|
372
364
|
*/
|
|
373
|
-
constructor(id,
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
365
|
+
constructor(id,
|
|
366
|
+
windDataMeta,
|
|
367
|
+
{
|
|
368
|
+
fadeOpacity = 0.746,
|
|
369
|
+
speedFactor = 0.6,
|
|
370
|
+
dropRate = 0.007,
|
|
371
|
+
dropRateBump = 0.001,
|
|
372
|
+
baseOpacity = 1.0,
|
|
373
|
+
pointSize = 2.0,
|
|
374
|
+
minSpeed = 0.0,
|
|
375
|
+
maxSpeed = 1000.0,
|
|
376
|
+
height = 0.0,
|
|
377
|
+
numParticles = 40000,
|
|
378
|
+
legendData = windyLegendData
|
|
379
|
+
} = {}) {
|
|
386
380
|
|
|
387
381
|
this.id = id;
|
|
388
|
-
|
|
382
|
+
this._windDataMeta = windDataMeta;
|
|
389
383
|
this.globe = null;
|
|
390
384
|
this.gl = null;
|
|
391
385
|
|
|
386
|
+
|
|
392
387
|
this._screenMoved = false;
|
|
393
388
|
this.projMatrix = null;
|
|
394
389
|
this.modelviewMatrix = null;
|
|
@@ -485,7 +480,6 @@ export default class WindPlugin {
|
|
|
485
480
|
}
|
|
486
481
|
|
|
487
482
|
setColorRampDefault() {
|
|
488
|
-
const { gl } = this;
|
|
489
483
|
const { uMax, uMin, vMax, vMin } = this.windData;
|
|
490
484
|
const maxSpeed = Math.sqrt(
|
|
491
485
|
uMax * uMax + vMax * vMax
|
|
@@ -509,11 +503,11 @@ export default class WindPlugin {
|
|
|
509
503
|
*/
|
|
510
504
|
setLegend(legendData) {
|
|
511
505
|
const { gl } = this;
|
|
512
|
-
if (gl
|
|
506
|
+
if (gl === null) {
|
|
513
507
|
throw new Error("wind plugin. setColorRampFromService is called before plugin is registered.");
|
|
514
508
|
}
|
|
515
509
|
const { thresholds, values } = legendData;
|
|
516
|
-
if (thresholds.length
|
|
510
|
+
if (thresholds.length === 0 || values.length === 0) {
|
|
517
511
|
return;
|
|
518
512
|
}
|
|
519
513
|
thresholds.push(thresholds[thresholds.length - 1]);
|
|
@@ -577,30 +571,29 @@ export default class WindPlugin {
|
|
|
577
571
|
/**
|
|
578
572
|
* @param {Object} windData
|
|
579
573
|
* @param {HTMLImageElement} windData.image - image element
|
|
580
|
-
|
|
581
|
-
* @param {number} windData.height - image height
|
|
574
|
+
|
|
582
575
|
* @param {number} windData.uMin - minimum u value
|
|
583
576
|
* @param {number} windData.vMin - minimum v value
|
|
584
577
|
* @param {number} windData.uMax - maximum u value
|
|
585
578
|
* @param {number} windData.vMax - maximum v value
|
|
586
|
-
* @param {Array} windData.bbox - bounding box [minLon, minLat, maxLon, maxLat]
|
|
587
579
|
*/
|
|
588
580
|
setWind(windData) {
|
|
589
|
-
if (windData
|
|
581
|
+
if (windData === null) {
|
|
590
582
|
return;
|
|
591
583
|
}
|
|
584
|
+
const windDataMeta = this._windDataMeta;
|
|
592
585
|
const gl = this.gl;
|
|
593
586
|
this.windData = windData;
|
|
594
587
|
this.windTexture = util.createTexture(gl, gl.LINEAR, windData.image);
|
|
595
588
|
const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
|
|
596
589
|
gl.useProgram(this.updateProgram.program);
|
|
597
|
-
|
|
590
|
+
|
|
591
|
+
gl.uniform2f(this.updateProgram.u_wind_res, windDataMeta.width, windDataMeta.height);
|
|
598
592
|
gl.uniform2f(this.updateProgram.u_wind_min, this.windData.uMin, this.windData.vMin);
|
|
599
593
|
gl.uniform2f(this.updateProgram.u_wind_max, this.windData.uMax, this.windData.vMax);
|
|
600
594
|
this.setGeometry();
|
|
601
|
-
|
|
602
|
-
const
|
|
603
|
-
const maxXY = this._latLongToPixelXY(windData.bbox[3], windData.bbox[2]);
|
|
595
|
+
const minXY = this._latLongToPixelXY(windDataMeta.bbox[1], windDataMeta.bbox[0]);
|
|
596
|
+
const maxXY = this._latLongToPixelXY(windDataMeta.bbox[3], windDataMeta.bbox[2]);
|
|
604
597
|
this._loadBoundingBoxData(minXY.x, minXY.y, maxXY.x, maxXY.y);
|
|
605
598
|
|
|
606
599
|
gl.useProgram(currentProgram);
|
|
@@ -630,21 +623,15 @@ export default class WindPlugin {
|
|
|
630
623
|
}
|
|
631
624
|
}
|
|
632
625
|
|
|
633
|
-
getPointCoordinatesDataCalculator(
|
|
634
|
-
if (!this.coordinatesDataCalculator) this._createPointCoordinatesDataCalculator(
|
|
626
|
+
getPointCoordinatesDataCalculator() {
|
|
627
|
+
if (!this.coordinatesDataCalculator) this._createPointCoordinatesDataCalculator();
|
|
635
628
|
return this.coordinatesDataCalculator;
|
|
636
629
|
}
|
|
637
630
|
|
|
638
631
|
|
|
639
|
-
_createPointCoordinatesDataCalculator(
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
} else {
|
|
643
|
-
if (!bbox || !width || !height) {
|
|
644
|
-
throw new Error("WindPlugin: windData meta info, bbox, width and height are required to create PointCoordinatesDataCalculator");
|
|
645
|
-
}
|
|
646
|
-
this.coordinatesDataCalculator = new PointCoordinatesDataCalculator(bbox, width, height);
|
|
647
|
-
}
|
|
632
|
+
_createPointCoordinatesDataCalculator() {
|
|
633
|
+
const { bbox, width, height } = this._windDataMeta;
|
|
634
|
+
this.coordinatesDataCalculator = new PointCoordinatesDataCalculator(bbox, width, height);
|
|
648
635
|
this._setCoorcinatesDataCalculatorData();
|
|
649
636
|
}
|
|
650
637
|
|
|
@@ -693,10 +680,10 @@ export default class WindPlugin {
|
|
|
693
680
|
|
|
694
681
|
_doDraw() {
|
|
695
682
|
const globe = this.globe;
|
|
696
|
-
if (this.windData
|
|
683
|
+
if (this.windData === null) {
|
|
697
684
|
return false;
|
|
698
685
|
}
|
|
699
|
-
if (globe.api_IsScreenMoving() || this._lastLOD
|
|
686
|
+
if (globe.api_IsScreenMoving() || this._lastLOD !== globe.api_GetCurrentLODWithDecimal()) {
|
|
700
687
|
if (!this._screenMoved) {
|
|
701
688
|
this._screenMoved = true;
|
|
702
689
|
}
|
|
@@ -850,7 +837,7 @@ export default class WindPlugin {
|
|
|
850
837
|
// globe calls `setGeometry` method on map projection change. FLAT or SPHERE
|
|
851
838
|
|
|
852
839
|
setGeometry() {
|
|
853
|
-
if (this.windData
|
|
840
|
+
if (this.windData === null) {
|
|
854
841
|
return;
|
|
855
842
|
}
|
|
856
843
|
const { globe, gl } = this;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Plane } from "../plane";
|
|
2
|
-
import { Vector3D } from "../vector3d";
|
|
3
|
-
import { Arc } from "../arc";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const Radians = Math.PI / 180;
|
|
8
|
-
|
|
9
|
-
export class ArcPartOnScreen {
|
|
10
|
-
private _oldLookInfo: { CenterLong: number, CenterLat: number, Distance: number, Tilt: number, NorthAng: number };
|
|
11
|
-
private _boundPlane: Plane;
|
|
12
|
-
|
|
13
|
-
constructor() {
|
|
14
|
-
this._boundPlane = new Plane(new Vector3D(0, 0, 0), 0);
|
|
15
|
-
this._oldLookInfo = { CenterLong: 0, CenterLat: -190, Distance: 0, Tilt: 0, NorthAng: 0 };
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
updateBoundPlane(lookInfo): boolean {
|
|
20
|
-
if (this._oldLookInfo && this._oldLookInfo.CenterLong === lookInfo.CenterLong && this._oldLookInfo.CenterLat === lookInfo.CenterLat) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* lookInfo {CenterLong: 47.75355881750585, CenterLat: 42.3417076206803, Distance: 2286603.4020860917, Tilt: 0.05, NorthAng: -13.829359965098265}
|
|
25
|
-
*/
|
|
26
|
-
this._oldLookInfo.CenterLong = lookInfo.CenterLong;
|
|
27
|
-
this._oldLookInfo.CenterLat = lookInfo.CenterLat;
|
|
28
|
-
this._oldLookInfo.Distance = lookInfo.Distance;
|
|
29
|
-
this._oldLookInfo.Tilt = lookInfo.Tilt;
|
|
30
|
-
this._oldLookInfo.NorthAng = lookInfo.NorthAng;
|
|
31
|
-
|
|
32
|
-
Plane.fromGlobeLookInfo(Radians * lookInfo.CenterLong, Radians * lookInfo.CenterLat, lookInfo.Distance, this._boundPlane);
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
getArcPartOnScreen(arc: Arc, target: Arc): boolean {
|
|
39
|
-
// _imaginaryPlane.set(arc.greatCirclePlaneNormalVector, arc.pointA.dot(arc.greatCirclePlaneNormalVector));
|
|
40
|
-
// const intersection = _imaginaryPlane.intersectionPlane(this._boundPlane);
|
|
41
|
-
// if (!(intersection instanceof Ray)) return false;
|
|
42
|
-
// _ray.copy(intersection as Ray);
|
|
43
|
-
// const [point1, point2] = _ray.intersectionSphere(_unitShphereCenter, _unitShphereRadius) as [Vector3D, Vector3D];
|
|
44
|
-
const result = arc.intersectionMedium(this._boundPlane, target);
|
|
45
|
-
return !(result === null);
|
|
46
|
-
}
|
|
47
|
-
}
|
package/Math/ray.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { Vector3D } from './vector3d';
|
|
2
|
-
import { Plane } from './plane';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const _0vector = /*@__PURE__*/ new Vector3D(0, 0, 0);
|
|
6
|
-
const _1vector = /*@__PURE__*/ new Vector3D(0, 0, 0);
|
|
7
|
-
const _3vector = /*@__PURE__*/ new Vector3D(0, 0, 0);
|
|
8
|
-
export class Ray {
|
|
9
|
-
|
|
10
|
-
origin: Vector3D;
|
|
11
|
-
direction: Vector3D;
|
|
12
|
-
|
|
13
|
-
constructor(origin: Vector3D, direction: Vector3D) {
|
|
14
|
-
this.origin = origin;
|
|
15
|
-
this.direction = direction.normalize();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
copy(ray: Ray): Ray {
|
|
19
|
-
this.origin.copy(ray.origin);
|
|
20
|
-
this.direction.copy(ray.direction);
|
|
21
|
-
return this;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
clone(): Ray {
|
|
25
|
-
return new Ray(this.origin.clone(), this.direction.clone());
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
at(distance: number, out: Vector3D): Vector3D {
|
|
30
|
-
return out.copy(this.direction).multiplyByScaler(distance).add(this.origin);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
set(origin: Vector3D, direction: Vector3D): Ray {
|
|
35
|
-
this.origin.copy(origin);
|
|
36
|
-
this.direction.copy(direction).normalize();
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
intersectionSphere(sphereOrigin: Vector3D, sphereRadius: number): [Vector3D, Vector3D] | null {
|
|
41
|
-
|
|
42
|
-
const l = this.direction.clone().normalize();
|
|
43
|
-
const s = this.origin.clone().subtract(sphereOrigin);
|
|
44
|
-
const b = l.dot(s);
|
|
45
|
-
|
|
46
|
-
const c = s.dot(s) - sphereRadius * sphereRadius;
|
|
47
|
-
const d = b * b - c;
|
|
48
|
-
|
|
49
|
-
if (d < 0) {
|
|
50
|
-
return null; // no intersection
|
|
51
|
-
} else {
|
|
52
|
-
const x = Math.sqrt(d);
|
|
53
|
-
const t1 = -b - x;
|
|
54
|
-
const t2 = -b + x;
|
|
55
|
-
// l and s are used as output vectors
|
|
56
|
-
return [this.at(t1, l), this.at(t2, s)];
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
contains(point: Vector3D): boolean {
|
|
62
|
-
const x = this.origin.x - point.x;
|
|
63
|
-
const y = this.origin.y - point.y;
|
|
64
|
-
const z = this.origin.z - point.z;
|
|
65
|
-
const distance = Math.sqrt(x * x + y * y + z * z);
|
|
66
|
-
if (distance < 0.0001) {
|
|
67
|
-
return true; // point is very close to the origin
|
|
68
|
-
}
|
|
69
|
-
return Math.abs(_0vector.set(x / distance, y / distance, z / distance).dot(this.direction)) > 0.9999; // point direction towards origin
|
|
70
|
-
// is very close to the ray direction
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// TODO: Applay this approach to other static methods on other Math classes.
|
|
74
|
-
static fromTwoPlanes(planeA: Plane, planeB: Plane, target: Ray | null = null): Ray | null {
|
|
75
|
-
const intersection = planeA.intersectionPlane(planeB);
|
|
76
|
-
if (intersection === null || intersection instanceof Plane) {
|
|
77
|
-
return null; // planes are parallel
|
|
78
|
-
}
|
|
79
|
-
if (target === null) {
|
|
80
|
-
target = new Ray(intersection.origin, intersection.direction);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
target.set(intersection.origin, intersection.direction);
|
|
84
|
-
}
|
|
85
|
-
return target;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
static fromTwoPoints(pointA: Vector3D, pointB: Vector3D, target: Ray | null = null): Ray {
|
|
90
|
-
if (target === null) {
|
|
91
|
-
target = new Ray(pointA, pointB.clone().subtract(pointA).normalize());
|
|
92
|
-
} else {
|
|
93
|
-
target.set(pointA, pointB.clone().subtract(pointA).normalize());
|
|
94
|
-
}
|
|
95
|
-
return target;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
package/Math/vector3d.ts
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
import { Vector3D as IVector3D, Radians } from "./types";
|
|
2
|
-
import { Quaternion } from "./quaternion";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export class Vector3D implements IVector3D {
|
|
7
|
-
x: number;
|
|
8
|
-
y: number;
|
|
9
|
-
z: number;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
constructor(x: number = 0, y: number = 0, z: number = 0) {
|
|
13
|
-
this.x = x;
|
|
14
|
-
this.y = y;
|
|
15
|
-
this.z = z;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
normalize(): Vector3D {
|
|
21
|
-
this.divideByScaler(this.length() || 1);
|
|
22
|
-
return this;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
dot(other: Vector3D) {
|
|
28
|
-
return this.x * other.x + this.y * other.y + this.z * other.z;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
equals(other: Vector3D, epsilon: number = 0.0000001): boolean {
|
|
34
|
-
// TODO: consider coppying other in case is true to avoid difference accumulation.
|
|
35
|
-
return Math.abs(this.x - other.x) < epsilon &&
|
|
36
|
-
Math.abs(this.y - other.y) < epsilon &&
|
|
37
|
-
Math.abs(this.z - other.z) < epsilon;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
static crossVectors(a: Vector3D, b: Vector3D, c: Vector3D = new Vector3D): Vector3D {
|
|
44
|
-
const x = a.y * b.z - a.z * b.y;
|
|
45
|
-
const y = a.z * b.x - a.x * b.z;
|
|
46
|
-
const z = a.x * b.y - a.y * b.x;
|
|
47
|
-
|
|
48
|
-
c.set(x, y, z);
|
|
49
|
-
|
|
50
|
-
return c;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
cross(other: Vector3D): Vector3D {
|
|
56
|
-
return Vector3D.crossVectors(this, other, this);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
angle(other: Vector3D): number {
|
|
62
|
-
const a = this.length();
|
|
63
|
-
const b = other.length();
|
|
64
|
-
const c = this.dot(other);
|
|
65
|
-
const angle = Math.acos(c / (a * b));
|
|
66
|
-
|
|
67
|
-
return isNaN(angle) ? 0 : angle;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
lerpVectors(a: Vector3D, b: Vector3D, t: number): Vector3D {
|
|
71
|
-
this.x = a.x + (b.x - a.x) * t;
|
|
72
|
-
this.y = a.y + (b.y - a.y) * t;
|
|
73
|
-
this.z = a.z + (b.z - a.z) * t;
|
|
74
|
-
|
|
75
|
-
return this;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
lerp(other: Vector3D, t: number): Vector3D {
|
|
81
|
-
return this.lerpVectors(this, other, t);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
scale(scalar: number): Vector3D {
|
|
87
|
-
this.x *= scalar;
|
|
88
|
-
this.y *= scalar;
|
|
89
|
-
this.z *= scalar;
|
|
90
|
-
|
|
91
|
-
return this;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
dotProduct(other: Vector3D): number {
|
|
95
|
-
return this.x * other.x + this.y * other.y + this.z * other.z;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
dotDivide(other: Vector3D): number {
|
|
100
|
-
return this.x / other.x + this.y / other.y + this.z / other.z;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
add(other: Vector3D): Vector3D {
|
|
105
|
-
this.x += other.x;
|
|
106
|
-
this.y += other.y;
|
|
107
|
-
this.z += other.z;
|
|
108
|
-
|
|
109
|
-
return this;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
negate(): Vector3D {
|
|
115
|
-
this.x = -this.x;
|
|
116
|
-
this.y = -this.y;
|
|
117
|
-
this.z = -this.z;
|
|
118
|
-
|
|
119
|
-
return this;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
length(): number {
|
|
125
|
-
return Math.sqrt(this.x ** 2 + this.y ** 2 + this.z ** 2);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
subtract(other: Vector3D): Vector3D {
|
|
131
|
-
this.x -= other.x;
|
|
132
|
-
this.y -= other.y;
|
|
133
|
-
this.z -= other.z;
|
|
134
|
-
|
|
135
|
-
return this;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
applyQuaternion(q: Quaternion): Vector3D {
|
|
141
|
-
const x = this.x, y = this.y, z = this.z;
|
|
142
|
-
const qx = q.x, qy = q.y, qz = q.z, qw = q.w;
|
|
143
|
-
// calculate quat * vector
|
|
144
|
-
const ix = qw * x + qy * z - qz * y;
|
|
145
|
-
const iy = qw * y + qz * x - qx * z;
|
|
146
|
-
const iz = qw * z + qx * y - qy * x;
|
|
147
|
-
const iw = -qx * x - qy * y - qz * z;
|
|
148
|
-
// calculate result * inverse quat
|
|
149
|
-
this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
|
|
150
|
-
this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
|
|
151
|
-
this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
|
|
152
|
-
return this;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
multiplyByScaler(scalar: number): Vector3D {
|
|
158
|
-
this.x *= scalar;
|
|
159
|
-
this.y *= scalar;
|
|
160
|
-
this.z *= scalar;
|
|
161
|
-
|
|
162
|
-
return this;
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
divideByScaler(scalar: number): Vector3D {
|
|
168
|
-
this.x /= scalar;
|
|
169
|
-
this.y /= scalar;
|
|
170
|
-
this.z /= scalar;
|
|
171
|
-
|
|
172
|
-
return this;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
copy(other: Vector3D): Vector3D {
|
|
178
|
-
this.x = other.x;
|
|
179
|
-
this.y = other.y;
|
|
180
|
-
this.z = other.z;
|
|
181
|
-
|
|
182
|
-
return this
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
set(x: number, y: number, z: number): Vector3D {
|
|
188
|
-
this.x = x;
|
|
189
|
-
this.y = y;
|
|
190
|
-
this.z = z;
|
|
191
|
-
|
|
192
|
-
return this
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
clone(): Vector3D {
|
|
198
|
-
return new Vector3D(this.x, this.y, this.z);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
randomUnit(): Vector3D {
|
|
204
|
-
const x = Math.random() * 2 - 1;
|
|
205
|
-
const y = Math.random() * 2 - 1;
|
|
206
|
-
const z = Math.random() * 2 - 1;
|
|
207
|
-
|
|
208
|
-
return this.set(x, y, z).normalize();
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
setFromLonLat(lon: Radians, lat: Radians): Vector3D {
|
|
214
|
-
const x = Math.cos(lat) * Math.cos(lon);
|
|
215
|
-
const y = Math.cos(lat) * Math.sin(lon);
|
|
216
|
-
const z = Math.sin(lat);
|
|
217
|
-
|
|
218
|
-
return this.set(x, y, z);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
toLonLat(): { lon: Radians, lat: Radians } {
|
|
225
|
-
const len = this.length();
|
|
226
|
-
const x = this.x / len;
|
|
227
|
-
const y = this.y / len;
|
|
228
|
-
const z = this.z / len;
|
|
229
|
-
const lon = Math.atan2(y, x);
|
|
230
|
-
const lat = Math.asin(z);
|
|
231
|
-
|
|
232
|
-
return { lon, lat };
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
static fromLonLatRadians(lon: Radians, lat: Radians): Vector3D {
|
|
238
|
-
return new Vector3D().setFromLonLat(lon, lat);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|