@openglobus/og 0.14.10 → 0.15.1

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.
Files changed (140) hide show
  1. package/css/og.css +378 -275
  2. package/dist/@openglobus/og.css +1 -1
  3. package/dist/@openglobus/og.esm.js +2 -2
  4. package/dist/@openglobus/og.esm.js.map +1 -1
  5. package/dist/@openglobus/og.umd.js +2 -2
  6. package/dist/@openglobus/og.umd.js.map +1 -1
  7. package/package.json +18 -17
  8. package/src/og/Clock.js +218 -194
  9. package/src/og/Globe.js +5 -5
  10. package/src/og/Object3d.js +104 -145
  11. package/src/og/camera/Camera.js +31 -27
  12. package/src/og/camera/PlanetCamera.js +22 -14
  13. package/src/og/cons.js +107 -107
  14. package/src/og/control/Atmosphere.js +396 -0
  15. package/src/og/control/CompassButton.js +11 -18
  16. package/src/og/control/Control.js +197 -188
  17. package/src/og/control/GeoImageDragControl.js +84 -66
  18. package/src/og/control/LayerSwitcher.js +56 -138
  19. package/src/og/control/Lighting.js +314 -186
  20. package/src/og/control/MouseNavigation.js +2 -2
  21. package/src/og/control/RulerSwitcher.js +24 -19
  22. package/src/og/control/ScaleControl.js +30 -10
  23. package/src/og/control/SimpleSkyBackground.js +210 -0
  24. package/src/og/control/Sun.js +3 -1
  25. package/src/og/control/ZoomControl.js +30 -42
  26. package/src/og/control/index.js +6 -0
  27. package/src/og/control/ruler/RulerScene.js +5 -23
  28. package/src/og/control/selection/Selection.js +99 -0
  29. package/src/og/control/selection/SelectionScene.js +350 -0
  30. package/src/og/control/timeline/TimelineControl.js +99 -0
  31. package/src/og/control/timeline/TimelineModel.js +133 -0
  32. package/src/og/control/timeline/TimelineView.js +449 -0
  33. package/src/og/control/timeline/timelineUtils.js +132 -0
  34. package/src/og/ellipsoid/Ellipsoid.js +120 -93
  35. package/src/og/ellipsoid/wgs84.js +13 -13
  36. package/src/og/entity/Entity.js +36 -9
  37. package/src/og/entity/EntityCollection.js +0 -2
  38. package/src/og/entity/GeoObject.js +72 -56
  39. package/src/og/entity/GeoObjectHandler.js +487 -656
  40. package/src/og/entity/GeometryHandler.js +1341 -1337
  41. package/src/og/entity/Polyline.js +0 -16
  42. package/src/og/entity/Ray.js +0 -10
  43. package/src/og/entity/RayHandler.js +3 -44
  44. package/src/og/entity/Strip.js +1 -6
  45. package/src/og/index.js +13 -7
  46. package/src/og/input/input.js +3 -1
  47. package/src/og/layer/CanvasTiles.js +39 -34
  48. package/src/og/layer/Layer.js +69 -9
  49. package/src/og/layer/Material.js +1 -8
  50. package/src/og/layer/WMS.js +16 -5
  51. package/src/og/light/LightSource.js +2 -0
  52. package/src/og/math/Line3.js +140 -139
  53. package/src/og/math/Plane.js +118 -117
  54. package/src/og/math/Ray.js +242 -239
  55. package/src/og/math/Vec3.js +56 -37
  56. package/src/og/math/Vec4.js +3 -4
  57. package/src/og/math.js +21 -21
  58. package/src/og/quadTree/Node.js +5 -4
  59. package/src/og/quadTree/index.js +12 -0
  60. package/src/og/renderer/Renderer.js +64 -37
  61. package/src/og/renderer/RendererEvents.js +1071 -1065
  62. package/src/og/scene/Planet.js +354 -174
  63. package/src/og/scene/RenderNode.js +27 -12
  64. package/src/og/segment/Segment.js +0 -5
  65. package/src/og/shaders/atmos.js +332 -0
  66. package/src/og/shaders/drawnode.js +475 -109
  67. package/src/og/shaders/geoObject.js +96 -51
  68. package/src/og/shaders/polyline.js +212 -17
  69. package/src/og/shaders/ray.js +13 -6
  70. package/src/og/shaders/toneMapping.js +5 -5
  71. package/src/og/shaders/utils.js +88 -0
  72. package/src/og/terrain/GlobusTerrain.js +5 -4
  73. package/src/og/terrain/MapboxTerrain.js +231 -52
  74. package/src/og/ui/Button.js +106 -0
  75. package/src/og/ui/ButtonGroup.js +57 -0
  76. package/src/og/ui/Dialog.js +242 -0
  77. package/src/og/ui/Slider.js +144 -0
  78. package/src/og/ui/ToggleButton.js +51 -0
  79. package/src/og/{control → ui}/UIhelpers.js +11 -2
  80. package/src/og/ui/View.js +190 -0
  81. package/src/og/utils/shared.js +960 -942
  82. package/src/og/webgl/Framebuffer.js +308 -387
  83. package/src/og/webgl/Handler.js +90 -30
  84. package/src/og/webgl/Multisample.js +8 -0
  85. package/types/Clock.d.ts +7 -2
  86. package/types/Object3d.d.ts +14 -3
  87. package/types/camera/Camera.d.ts +18 -17
  88. package/types/camera/PlanetCamera.d.ts +3 -1
  89. package/types/control/Atmosphere.d.ts +15 -0
  90. package/types/control/CompassButton.d.ts +1 -2
  91. package/types/control/GeoImageDragControl.d.ts +7 -1
  92. package/types/control/LayerSwitcher.d.ts +5 -6
  93. package/types/control/Lighting.d.ts +32 -7
  94. package/types/control/ScaleControl.d.ts +2 -1
  95. package/types/control/SimpleSkyBackground.d.ts +15 -0
  96. package/types/control/ZoomControl.d.ts +0 -1
  97. package/types/control/index.d.ts +4 -1
  98. package/types/control/ruler/RulerScene.d.ts +0 -1
  99. package/types/control/selection/Selection.d.ts +49 -0
  100. package/types/control/selection/SelectionScene.d.ts +34 -0
  101. package/types/ellipsoid/Ellipsoid.d.ts +3 -2
  102. package/types/entity/Entity.d.ts +8 -0
  103. package/types/entity/GeoObject.d.ts +28 -22
  104. package/types/entity/GeoObjectHandler.d.ts +16 -56
  105. package/types/entity/Ray.d.ts +0 -3
  106. package/types/entity/RayHandler.d.ts +0 -4
  107. package/types/index.d.ts +9 -6
  108. package/types/input/input.d.ts +2 -0
  109. package/types/layer/CanvasTiles.d.ts +1 -0
  110. package/types/layer/Layer.d.ts +9 -0
  111. package/types/layer/WMS.d.ts +7 -3
  112. package/types/math/Plane.d.ts +1 -1
  113. package/types/math/Vec3.d.ts +19 -16
  114. package/types/math/Vec4.d.ts +2 -3
  115. package/types/math.d.ts +20 -20
  116. package/types/quadTree/index.d.ts +10 -0
  117. package/types/renderer/Renderer.d.ts +11 -37
  118. package/types/scene/Planet.d.ts +27 -1
  119. package/types/scene/RenderNode.d.ts +2 -1
  120. package/types/segment/Segment.d.ts +1 -1
  121. package/types/shaders/atmos.d.ts +4 -0
  122. package/types/shaders/drawnode.d.ts +3 -2
  123. package/types/shaders/utils.d.ts +1 -0
  124. package/types/terrain/GlobusTerrain.d.ts +1 -1
  125. package/types/terrain/MapboxTerrain.d.ts +2 -1
  126. package/types/ui/Button.d.ts +21 -0
  127. package/types/ui/Dialog.d.ts +41 -0
  128. package/types/ui/Slider.d.ts +30 -0
  129. package/types/ui/ToggleButton.d.ts +10 -0
  130. package/types/{control → ui}/UIhelpers.d.ts +1 -1
  131. package/types/ui/View.d.ts +32 -0
  132. package/types/utils/shared.d.ts +16 -14
  133. package/types/webgl/Framebuffer.d.ts +2 -5
  134. package/types/webgl/Handler.d.ts +15 -10
  135. package/types/webgl/Multisample.d.ts +2 -0
  136. package/src/og/ajax.js +0 -204
  137. package/src/og/entity/Object3d.js +0 -504
  138. package/src/og/utils/quadTreeType.js +0 -11
  139. package/types/ajax.d.ts +0 -24
  140. package/types/utils/quadTreeType.d.ts +0 -8
@@ -1,140 +1,141 @@
1
- 'use strict';
2
-
3
- import * as math from '../math.js';
4
- import { Vec3 } from './Vec3.js';
5
-
6
- export class Line3 {
7
- constructor(p0, p1) {
8
- this.p0 = p0 || new Vec3();
9
- this.p1 = p1 || new Vec3();
10
- }
11
-
12
- getMagnitude() {
13
- return this.p0.distance(this.p1);
14
- }
15
-
16
- getSphereIntersection(sphere) {
17
- var p0 = this.p0,
18
- p1 = this.p1;
19
-
20
- var cx = sphere.x,
21
- cy = sphere.y,
22
- cz = sphere.z;
23
-
24
- var px = p0.x,
25
- py = p0.y,
26
- pz = p0.z;
27
-
28
- var vx = p1.x - px,
29
- vy = p1.y - py,
30
- vz = p1.z - pz;
31
-
32
- var A = vx * vx + vy * vy + vz * vz,
33
- B = 2.0 * (px * vx + py * vy + pz * vz - vx * cx - vy * cy - vz * cz),
34
- C = px * px - 2 * px * cx + cx * cx + py * py - 2 * py * cy + cy * cy +
35
- pz * pz - 2 * pz * cz + cz * cz - sphere.radius * sphere.radius;
36
- var D = B * B - 4 * A * C;
37
-
38
- if (D < 0) {
39
- return null;
40
- }
41
-
42
- var t1 = (-B - Math.Sqrt(D)) / (2.0 * A);
43
-
44
- var solution1 = new Vec3(
45
- p0.x * (1 - t1) + t1 * p1.x,
46
- p0.y * (1 - t1) + t1 * p1.y,
47
- p0.z * (1 - t1) + t1 * p1.z);
48
-
49
- if (D == 0) {
50
- return solution1;
51
- }
52
-
53
- var t2 = (-B + Math.Sqrt(D)) / (2.0 * A);
54
- var solution2 = new Vec3(
55
- p0.x * (1 - t2) + t2 * p1.x,
56
- p0.y * (1 - t2) + t2 * p1.y,
57
- p0.z * (1 - t2) + t2 * p1.z);
58
-
59
- // prefer a solution that's on the line segment itself
60
- if (Math.Abs(t1 - 0.5) < Math.abs(t2 - 0.5)) {
61
- return [solution1, solution2];
62
- }
63
-
64
- return [solution2, solution1];
65
- }
66
-
67
- intersects(line, res, res2) {
68
-
69
- let p13 = this.p0.sub(line.p0),
70
- p43 = line.p1.sub(line.p0);
71
-
72
- if (Math.abs(p43.x) < math.EPSILON10 && Math.abs(p43.y) < math.EPSILON10 && Math.abs(p43.z) < math.EPSILON10) {
73
- return false;
74
- }
75
-
76
- let p21 = this.p1.sub(this.p0);
77
-
78
- if (Math.abs(p21.x) < math.EPSILON10 && Math.abs(p21.y) < math.EPSILON10 && Math.abs(p21.z) < math.EPSILON10) {
79
- return false;
80
- }
81
-
82
- let d1343 = p13.x * p43.x + p13.y * p43.y + p13.z * p43.z,
83
- d4321 = p43.x * p21.x + p43.y * p21.y + p43.z * p21.z,
84
- d1321 = p13.x * p21.x + p13.y * p21.y + p13.z * p21.z,
85
- d4343 = p43.x * p43.x + p43.y * p43.y + p43.z * p43.z,
86
- d2121 = p21.x * p21.x + p21.y * p21.y + p21.z * p21.z;
87
-
88
- let denom = d2121 * d4343 - d4321 * d4321;
89
-
90
- if (Math.abs(denom) < math.EPSILON10) {
91
- return false;
92
- }
93
-
94
- let numer = d1343 * d4321 - d1321 * d4343;
95
-
96
- let mua = numer / denom;
97
-
98
- res.x = this.p0.x + mua * p21.x;
99
- res.y = this.p0.y + mua * p21.y;
100
- res.z = this.p0.z + mua * p21.z;
101
-
102
- if (res2) {
103
-
104
- let mub = (d1343 + d4321 * mua) / d4343;
105
-
106
- res2.x = line.p0.x + mub * p43.x;
107
- res2.y = line.p0.y + mub * p43.y;
108
- res2.z = line.p0.z + mub * p43.z;
109
- }
110
-
111
- return true;
112
- }
113
-
114
- getNearestDistancePoint(point, res) {
115
-
116
- let p0 = this.p0,
117
- p1 = this.p1;
118
-
119
- let mag = this.getMagnitude();
120
-
121
- let u =
122
- (
123
- ((point.x - p0.x) * (p1.x - p0.x)) +
124
- ((point.y - p0.y) * (p1.y - p0.y)) +
125
- ((point.z - p0.z) * (p1.z - p0.z))
126
- ) /
127
- (mag * mag);
128
-
129
- res.x = p0.x + u * (p1.x - p0.x);
130
- res.y = p0.y + u * (p1.y - p0.y);
131
- res.z = p0.z + u * (p1.z - p0.z);
132
-
133
- if (u < 0.0 || u > 1.0) {
134
- return false;
135
- }
136
-
137
- return true;
138
- }
139
-
1
+ 'use strict';
2
+
3
+ import * as math from '../math.js';
4
+ import { EPS10 } from '../math.js';
5
+ import { Vec3 } from './Vec3.js';
6
+
7
+ export class Line3 {
8
+ constructor(p0, p1) {
9
+ this.p0 = p0 || new Vec3();
10
+ this.p1 = p1 || new Vec3();
11
+ }
12
+
13
+ getMagnitude() {
14
+ return this.p0.distance(this.p1);
15
+ }
16
+
17
+ getSphereIntersection(sphere) {
18
+ var p0 = this.p0,
19
+ p1 = this.p1;
20
+
21
+ var cx = sphere.x,
22
+ cy = sphere.y,
23
+ cz = sphere.z;
24
+
25
+ var px = p0.x,
26
+ py = p0.y,
27
+ pz = p0.z;
28
+
29
+ var vx = p1.x - px,
30
+ vy = p1.y - py,
31
+ vz = p1.z - pz;
32
+
33
+ var A = vx * vx + vy * vy + vz * vz,
34
+ B = 2.0 * (px * vx + py * vy + pz * vz - vx * cx - vy * cy - vz * cz),
35
+ C = px * px - 2 * px * cx + cx * cx + py * py - 2 * py * cy + cy * cy +
36
+ pz * pz - 2 * pz * cz + cz * cz - sphere.radius * sphere.radius;
37
+ var D = B * B - 4 * A * C;
38
+
39
+ if (D < 0) {
40
+ return null;
41
+ }
42
+
43
+ var t1 = (-B - Math.Sqrt(D)) / (2.0 * A);
44
+
45
+ var solution1 = new Vec3(
46
+ p0.x * (1 - t1) + t1 * p1.x,
47
+ p0.y * (1 - t1) + t1 * p1.y,
48
+ p0.z * (1 - t1) + t1 * p1.z);
49
+
50
+ if (D == 0) {
51
+ return solution1;
52
+ }
53
+
54
+ var t2 = (-B + Math.Sqrt(D)) / (2.0 * A);
55
+ var solution2 = new Vec3(
56
+ p0.x * (1 - t2) + t2 * p1.x,
57
+ p0.y * (1 - t2) + t2 * p1.y,
58
+ p0.z * (1 - t2) + t2 * p1.z);
59
+
60
+ // prefer a solution that's on the line segment itself
61
+ if (Math.Abs(t1 - 0.5) < Math.abs(t2 - 0.5)) {
62
+ return [solution1, solution2];
63
+ }
64
+
65
+ return [solution2, solution1];
66
+ }
67
+
68
+ intersects(line, res, res2) {
69
+
70
+ let p13 = this.p0.sub(line.p0),
71
+ p43 = line.p1.sub(line.p0);
72
+
73
+ if (Math.abs(p43.x) < EPS10 && Math.abs(p43.y) < EPS10 && Math.abs(p43.z) < EPS10) {
74
+ return false;
75
+ }
76
+
77
+ let p21 = this.p1.sub(this.p0);
78
+
79
+ if (Math.abs(p21.x) < EPS10 && Math.abs(p21.y) < EPS10 && Math.abs(p21.z) < EPS10) {
80
+ return false;
81
+ }
82
+
83
+ let d1343 = p13.x * p43.x + p13.y * p43.y + p13.z * p43.z,
84
+ d4321 = p43.x * p21.x + p43.y * p21.y + p43.z * p21.z,
85
+ d1321 = p13.x * p21.x + p13.y * p21.y + p13.z * p21.z,
86
+ d4343 = p43.x * p43.x + p43.y * p43.y + p43.z * p43.z,
87
+ d2121 = p21.x * p21.x + p21.y * p21.y + p21.z * p21.z;
88
+
89
+ let denom = d2121 * d4343 - d4321 * d4321;
90
+
91
+ if (Math.abs(denom) < EPS10) {
92
+ return false;
93
+ }
94
+
95
+ let numer = d1343 * d4321 - d1321 * d4343;
96
+
97
+ let mua = numer / denom;
98
+
99
+ res.x = this.p0.x + mua * p21.x;
100
+ res.y = this.p0.y + mua * p21.y;
101
+ res.z = this.p0.z + mua * p21.z;
102
+
103
+ if (res2) {
104
+
105
+ let mub = (d1343 + d4321 * mua) / d4343;
106
+
107
+ res2.x = line.p0.x + mub * p43.x;
108
+ res2.y = line.p0.y + mub * p43.y;
109
+ res2.z = line.p0.z + mub * p43.z;
110
+ }
111
+
112
+ return true;
113
+ }
114
+
115
+ getNearestDistancePoint(point, res) {
116
+
117
+ let p0 = this.p0,
118
+ p1 = this.p1;
119
+
120
+ let mag = this.getMagnitude();
121
+
122
+ let u =
123
+ (
124
+ ((point.x - p0.x) * (p1.x - p0.x)) +
125
+ ((point.y - p0.y) * (p1.y - p0.y)) +
126
+ ((point.z - p0.z) * (p1.z - p0.z))
127
+ ) /
128
+ (mag * mag);
129
+
130
+ res.x = p0.x + u * (p1.x - p0.x);
131
+ res.y = p0.y + u * (p1.y - p0.y);
132
+ res.z = p0.z + u * (p1.z - p0.z);
133
+
134
+ if (u < 0.0 || u > 1.0) {
135
+ return false;
136
+ }
137
+
138
+ return true;
139
+ }
140
+
140
141
  }
@@ -1,117 +1,118 @@
1
- "use strict";
2
-
3
- import * as math from "../math.js";
4
- import { Vec3 } from "./Vec3.js";
5
-
6
- /**
7
- * Plane class.
8
- * @constructor
9
- * @param {Vec3} [p] - Plane point.
10
- * @param {Vec3} [n] - Planet normal.
11
- */
12
- class Plane {
13
- constructor(p, n) {
14
- this.p = p ? p.clone() : new Vec3();
15
- this.n = n ? n.clone() : this.p.normal();
16
- }
17
-
18
- set(p, n) {
19
- this.p.copy(p);
20
- this.n.copy(n);
21
- }
22
-
23
- getNormal() {
24
- return this.n.clone();
25
- }
26
-
27
- distance(p) {
28
- let pp = this.getProjection(p);
29
- return p.distance(pp);
30
- }
31
-
32
- getProjection(v, def) {
33
- return Vec3.proj_b_to_plane(v, this.n, def);
34
- }
35
-
36
- getProjectionPoint(p, vh) {
37
- let v = p.sub(this.p),
38
- n = this.n,
39
- dist = v.dot(n);
40
-
41
- if (vh) {
42
- vh.copy(n.scale(dist));
43
- } else {
44
- vh = n.scale(dist);
45
- }
46
- return p.sub(vh);
47
- }
48
-
49
- getIntersection(Pn1, Pn2, L) {
50
- var u = Pn1.n.cross(Pn2.n);
51
-
52
- var ax = u.x >= 0 ? u.x : -u.x;
53
- var ay = u.y >= 0 ? u.y : -u.y;
54
- var az = u.z >= 0 ? u.z : -u.z;
55
-
56
- // test if the two planes are parallel
57
- if (ax + ay + az < math.EPSILON5) {
58
- // Pn1 and Pn2 are near parallel
59
- // test if disjoint or coincide
60
- var v = Pn2.p.sub(Pn1.p);
61
- if (Pn1.n.dot(v) == 0) {
62
- // Pn2.V0 lies in Pn1
63
- return 1; // Pn1 and Pn2 coincide
64
- } else {
65
- return 0; // Pn1 and Pn2 are disjoint
66
- }
67
- }
68
-
69
- // Pn1 and Pn2 intersect in a line
70
- // first determine max abs coordinate of cross product
71
- var maxc; // max coordinate
72
- if (ax > ay) {
73
- if (ax > az) {
74
- maxc = 1;
75
- } else {
76
- maxc = 3;
77
- }
78
- } else {
79
- if (ay > az) {
80
- maxc = 2;
81
- } else {
82
- maxc = 3;
83
- }
84
- }
85
-
86
- // next, to get a point on the intersect line
87
- // zero the max coord, and solve for the other two
88
- var iP = new Vec3(); // intersect point
89
-
90
- var d1, d2; // the constants in the 2 plane equations
91
- d1 = -Pn1.n.dot(Pn1.p); // note: could be pre-stored with plane
92
- d2 = -Pn2.n.dot(Pn2.p); // ditto
93
-
94
- // select max coordinate
95
- if (maxc === 1) {
96
- // intersect with x=0
97
- iP.x = 0;
98
- iP.y = (d2 * Pn1.n.z - d1 * Pn2.n.z) / u.x;
99
- iP.z = (d1 * Pn2.n.y - d2 * Pn1.n.y) / u.x;
100
- } else if (maxc === 2) {
101
- // intersect with y=0
102
- iP.x = (d1 * Pn2.n.z - d2 * Pn1.n.z) / u.y;
103
- iP.y = 0;
104
- iP.z = (d2 * Pn1.n.x - d1 * Pn2.n.x) / u.y;
105
- } else if (maxc === 3) {
106
- // intersect with z=0
107
- iP.x = (d2 * Pn1.n.y - d1 * Pn2.n.y) / u.z;
108
- iP.y = (d1 * Pn2.n.x - d2 * Pn1.n.x) / u.z;
109
- iP.z = 0;
110
- }
111
- L.p0.copy(iP);
112
- L.p1.copy(iP.add(u));
113
- return 2;
114
- }
115
- }
116
-
117
- export { Plane };
1
+ "use strict";
2
+
3
+ import * as math from "../math.js";
4
+ import { EPS5 } from "../math.js";
5
+ import { Vec3 } from "./Vec3.js";
6
+
7
+ /**
8
+ * Plane class.
9
+ * @constructor
10
+ * @param {Vec3} [p] - Plane point.
11
+ * @param {Vec3} [n] - Planet normal.
12
+ */
13
+ class Plane {
14
+ constructor(p, n) {
15
+ this.p = p ? p.clone() : new Vec3();
16
+ this.n = n ? n.clone() : this.p.normal();
17
+ }
18
+
19
+ set(p, n) {
20
+ this.p.copy(p);
21
+ this.n.copy(n);
22
+ }
23
+
24
+ getNormal() {
25
+ return this.n.clone();
26
+ }
27
+
28
+ distance(p) {
29
+ let pp = this.getProjection(p);
30
+ return p.distance(pp);
31
+ }
32
+
33
+ getProjection(v, def) {
34
+ return Vec3.proj_b_to_plane(v, this.n, def);
35
+ }
36
+
37
+ getProjectionPoint(p, vh) {
38
+ let v = p.sub(this.p),
39
+ n = this.n,
40
+ dist = v.dot(n);
41
+
42
+ if (vh) {
43
+ vh.copy(n.scale(dist));
44
+ } else {
45
+ vh = n.scale(dist);
46
+ }
47
+ return p.sub(vh);
48
+ }
49
+
50
+ getIntersection(Pn1, Pn2, L) {
51
+ var u = Pn1.n.cross(Pn2.n);
52
+
53
+ var ax = u.x >= 0 ? u.x : -u.x;
54
+ var ay = u.y >= 0 ? u.y : -u.y;
55
+ var az = u.z >= 0 ? u.z : -u.z;
56
+
57
+ // test if the two planes are parallel
58
+ if (ax + ay + az < EPS5) {
59
+ // Pn1 and Pn2 are near parallel
60
+ // test if disjoint or coincide
61
+ var v = Pn2.p.sub(Pn1.p);
62
+ if (Pn1.n.dot(v) == 0) {
63
+ // Pn2.V0 lies in Pn1
64
+ return 1; // Pn1 and Pn2 coincide
65
+ } else {
66
+ return 0; // Pn1 and Pn2 are disjoint
67
+ }
68
+ }
69
+
70
+ // Pn1 and Pn2 intersect in a line
71
+ // first determine max abs coordinate of cross product
72
+ var maxc; // max coordinate
73
+ if (ax > ay) {
74
+ if (ax > az) {
75
+ maxc = 1;
76
+ } else {
77
+ maxc = 3;
78
+ }
79
+ } else {
80
+ if (ay > az) {
81
+ maxc = 2;
82
+ } else {
83
+ maxc = 3;
84
+ }
85
+ }
86
+
87
+ // next, to get a point on the intersect line
88
+ // zero the max coord, and solve for the other two
89
+ var iP = new Vec3(); // intersect point
90
+
91
+ var d1, d2; // the constants in the 2 plane equations
92
+ d1 = -Pn1.n.dot(Pn1.p); // note: could be pre-stored with plane
93
+ d2 = -Pn2.n.dot(Pn2.p); // ditto
94
+
95
+ // select max coordinate
96
+ if (maxc === 1) {
97
+ // intersect with x=0
98
+ iP.x = 0;
99
+ iP.y = (d2 * Pn1.n.z - d1 * Pn2.n.z) / u.x;
100
+ iP.z = (d1 * Pn2.n.y - d2 * Pn1.n.y) / u.x;
101
+ } else if (maxc === 2) {
102
+ // intersect with y=0
103
+ iP.x = (d1 * Pn2.n.z - d2 * Pn1.n.z) / u.y;
104
+ iP.y = 0;
105
+ iP.z = (d2 * Pn1.n.x - d1 * Pn2.n.x) / u.y;
106
+ } else if (maxc === 3) {
107
+ // intersect with z=0
108
+ iP.x = (d2 * Pn1.n.y - d1 * Pn2.n.y) / u.z;
109
+ iP.y = (d1 * Pn2.n.x - d2 * Pn1.n.x) / u.z;
110
+ iP.z = 0;
111
+ }
112
+ L.p0.copy(iP);
113
+ L.p1.copy(iP.add(u));
114
+ return 2;
115
+ }
116
+ }
117
+
118
+ export { Plane };