@yangyongtao/gaea 1.0.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/README.md +158 -67
  2. package/package.json +28 -7
  3. package/public/Gaea.apple-touch-icon.png +0 -0
  4. package/public/Gaea.apple-touch-icon.png.import +35 -0
  5. package/public/Gaea.audio.worklet.js +211 -0
  6. package/public/Gaea.html +245 -0
  7. package/public/Gaea.icon.png +0 -0
  8. package/public/Gaea.icon.png.import +35 -0
  9. package/public/Gaea.js +782 -0
  10. package/public/Gaea.png +0 -0
  11. package/public/Gaea.png.import +35 -0
  12. package/public/Gaea.worker.js +1 -0
  13. package/public/GaeaApp.html +275 -0
  14. package/public/GaeaMethods.js +4342 -0
  15. package/public/GaeaModule.html +276 -0
  16. package/public/config.js +76 -0
  17. package/public/constants.js +185 -0
  18. package/public/favicon.ico +0 -0
  19. package/public/image/1.png +0 -0
  20. package/public/image/12-min-min.gif +0 -0
  21. package/public/image/3.png +0 -0
  22. package/public/image/labelImg//345/217/263/350/276/271.png +0 -0
  23. package/public/image/labelImg//345/267/246/350/276/271.png +0 -0
  24. package/public/image/labelImg//346/260/264/344/275/215.png +0 -0
  25. package/public/image/screenIcon//345/205/266/344/273/226.png +0 -0
  26. package/public/image/screenIcon//345/256/211/345/205/250/347/233/221/346/265/213/350/201/232/345/220/210-/347/272/242.png +0 -0
  27. package/public/image/screenIcon//345/256/211/345/205/250/347/233/221/346/265/213/350/201/232/345/220/210-/347/273/277.png +0 -0
  28. package/public/image/screenIcon//346/212/242/351/231/251/345/215/225/344/275/215.png +0 -0
  29. package/public/image/screenIcon//346/226/255/351/235/242.png +0 -0
  30. package/public/image/screenIcon//346/227/240/344/272/272/346/234/272.png +0 -0
  31. package/public/image/screenIcon//346/227/240/344/272/272/346/234/272/345/237/272/345/234/260.png +0 -0
  32. package/public/image/screenIcon//346/260/264/345/272/223/347/253/231.png +0 -0
  33. package/public/image/screenIcon//346/260/264/346/226/207/346/265/213/347/253/231.png +0 -0
  34. package/public/image/screenIcon//346/260/264/351/227/270.png +0 -0
  35. package/public/image/screenIcon//346/262/263/351/201/223/347/253/231-/346/227/240/346/225/260/346/215/256.png +0 -0
  36. package/public/image/screenIcon//346/262/263/351/201/223/347/253/231-/346/255/243/345/270/270.png +0 -0
  37. package/public/image/screenIcon//346/262/263/351/201/223/347/253/231-/350/266/205/344/277/235.png +0 -0
  38. package/public/image/screenIcon//346/262/263/351/201/223/347/253/231-/350/266/205/350/255/246.png +0 -0
  39. package/public/image/screenIcon//346/263/265/347/253/231-/347/201/260.png +0 -0
  40. package/public/image/screenIcon//346/263/265/347/253/231-/347/273/277.png +0 -0
  41. package/public/image/screenIcon//346/265/201/351/207/217/346/265/213/347/253/231.png +0 -0
  42. package/public/image/screenIcon//346/265/267/345/241/230-1/347/272/247.png +0 -0
  43. package/public/image/screenIcon//346/265/267/345/241/230-2/347/272/247.png +0 -0
  44. package/public/image/screenIcon//346/265/267/345/241/230-3/347/272/247.png +0 -0
  45. package/public/image/screenIcon//346/265/267/345/241/230-4/347/272/247.png +0 -0
  46. package/public/image/screenIcon//346/265/267/345/241/230-5/347/272/247.png +0 -0
  47. package/public/image/screenIcon//346/265/267/345/241/230-/346/251/231.png +0 -0
  48. package/public/image/screenIcon//346/265/267/345/241/230-/347/272/242.png +0 -0
  49. package/public/image/screenIcon//346/265/267/345/241/230-/347/273/277.png +0 -0
  50. package/public/image/screenIcon//346/265/267/345/241/230-/350/247/204/346/250/241/344/273/245/344/270/213.png +0 -0
  51. package/public/image/screenIcon//346/265/267/345/241/230-/351/273/204.png +0 -0
  52. package/public/image/screenIcon//346/265/267/345/241/230.png +0 -0
  53. package/public/image/screenIcon//346/275/256/344/275/215.png +0 -0
  54. package/public/image/screenIcon//346/275/256/344/275/215/347/253/231-/346/227/240/346/225/260/346/215/256.png +0 -0
  55. package/public/image/screenIcon//346/275/256/344/275/215/347/253/231-/346/255/243/345/270/270.png +0 -0
  56. package/public/image/screenIcon//346/275/256/344/275/215/347/253/231-/350/266/205/344/277/235.png +0 -0
  57. package/public/image/screenIcon//346/275/256/344/275/215/347/253/231-/350/266/205/350/255/246.png +0 -0
  58. package/public/image/screenIcon//347/211/251/350/265/204/344/273/223/345/272/223.png +0 -0
  59. package/public/image/screenIcon//347/220/203/346/234/272-/345/205/263.png +0 -0
  60. package/public/image/screenIcon//347/220/203/346/234/272-/345/274/200.png +0 -0
  61. package/public/image/screenIcon//347/220/203/346/234/272-/347/272/242.png +0 -0
  62. package/public/image/screenIcon//350/247/206/351/242/221/347/233/221/346/216/247.png +0 -0
  63. package/public/image/screenIcon//351/227/270/351/227/250-/347/201/260.png +0 -0
  64. package/public/image/screenIcon//351/227/270/351/227/250-/347/273/277.png +0 -0
  65. package/public/image/screenIcon//351/230/262/346/264/252/344/273/223/345/272/223.png +0 -0
  66. package/public/image/screenIcon//351/232/220/346/202/243.png +0 -0
  67. package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/346/265/205/350/223/235.png +0 -0
  68. package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/347/201/260.png +0 -0
  69. package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/347/262/211.png +0 -0
  70. package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/347/272/242.png +0 -0
  71. package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/347/273/277.png +0 -0
  72. package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/350/223/235.png +0 -0
  73. package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/351/273/204.png +0 -0
  74. package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/351/273/221.png +0 -0
  75. package/public/image/screenIcon//351/243/216/351/200/237.png +0 -0
  76. package/public/image/screenIcon//351/243/216/351/200/237/346/265/213/347/253/231.png +0 -0
  77. package/public/image//346/260/264/346/226/207.gif +0 -0
  78. package/public/image//350/211/262/345/270/246.png +0 -0
  79. package/public/index.html +22 -0
  80. package/public/index.js +185662 -0
  81. package/public/jsWebControl-1.0.0.min.js +31 -0
  82. package/public/jsencrypt.min.js +1 -0
  83. package/public/math/Box2.js +203 -0
  84. package/public/math/Box3.js +532 -0
  85. package/public/math/Color.js +605 -0
  86. package/public/math/ColorManagement.js +74 -0
  87. package/public/math/Cylindrical.js +61 -0
  88. package/public/math/EngineUtils.js +81 -0
  89. package/public/math/Euler.js +315 -0
  90. package/public/math/Frustum.js +162 -0
  91. package/public/math/Interpolant.js +241 -0
  92. package/public/math/Line3.js +115 -0
  93. package/public/math/MathUtils.js +345 -0
  94. package/public/math/Matrix3.js +365 -0
  95. package/public/math/Matrix4.js +858 -0
  96. package/public/math/Plane.js +205 -0
  97. package/public/math/Quaternion.js +724 -0
  98. package/public/math/Ray.js +493 -0
  99. package/public/math/Sphere.js +243 -0
  100. package/public/math/Spherical.js +86 -0
  101. package/public/math/SphericalHarmonics3.js +243 -0
  102. package/public/math/Triangle.js +299 -0
  103. package/public/math/Vector2.js +464 -0
  104. package/public/math/Vector3.js +715 -0
  105. package/public/math/Vector4.js +644 -0
  106. package/public/math/interpolants/CubicInterpolant.js +151 -0
  107. package/public/math/interpolants/DiscreteInterpolant.js +26 -0
  108. package/public/math/interpolants/LinearInterpolant.js +38 -0
  109. package/public/math/interpolants/QuaternionLinearInterpolant.js +39 -0
  110. package/public/static/Cloud.png +0 -0
  111. package/public/static/Global2.jpg +0 -0
  112. package/public/static/css/main.css +170 -0
  113. package/public/static/geojson//346/265/267/345/241/230.geojson +99 -0
  114. package/public/static/img/loading.gif +0 -0
  115. package/public/static/js/app.js +359 -0
  116. package/public/static/js/appcontroller.js +207 -0
  117. package/public/static/js/dist/game.dev.js +137 -0
  118. package/public/static/js/env.js +74 -0
  119. package/public/static/js/event/event.js +107 -0
  120. package/public/static/js/init.js +8 -0
  121. package/public/static/js/initcloudmorph.js +1 -0
  122. package/public/static/js/log.js +35 -0
  123. package/public/static/js/network/ajax.js +29 -0
  124. package/public/static/js/network/rtcp.js +172 -0
  125. package/public/static/js/network/socket.js +106 -0
  126. package/public/web-control.min.js +2 -0
  127. package/scripts/postinstall.mjs +127 -0
  128. package/src/GaeaMethods.js +68 -405
  129. package/src/components/FlyAlongRoute.vue +1 -0
  130. package/src/components/WeatherControl.vue +2 -0
  131. package/src/directives/vDrag.js +70 -0
  132. package/src/index.js +1 -8
  133. package/src/plugin.js +16 -0
  134. package/src/utils.js +10 -21
  135. package/src/vite-plugin.js +117 -0
  136. package/public/static/1111.res +0 -0
  137. package/src/config.js +0 -40
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
3
+ *
4
+ * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
5
+ * The azimuthal angle (theta) is measured from the positive z-axis.
6
+ */
7
+
8
+ import * as MathUtils from './MathUtils.js';
9
+
10
+ class Spherical {
11
+
12
+ constructor( radius = 1, phi = 0, theta = 0 ) {
13
+
14
+ this.radius = radius;
15
+ this.phi = phi; // polar angle
16
+ this.theta = theta; // azimuthal angle
17
+
18
+ return this;
19
+
20
+ }
21
+
22
+ set( radius, phi, theta ) {
23
+
24
+ this.radius = radius;
25
+ this.phi = phi;
26
+ this.theta = theta;
27
+
28
+ return this;
29
+
30
+ }
31
+
32
+ copy( other ) {
33
+
34
+ this.radius = other.radius;
35
+ this.phi = other.phi;
36
+ this.theta = other.theta;
37
+
38
+ return this;
39
+
40
+ }
41
+
42
+ // restrict phi to be between EPS and PI-EPS
43
+ makeSafe() {
44
+
45
+ const EPS = 0.000001;
46
+ this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
47
+
48
+ return this;
49
+
50
+ }
51
+
52
+ setFromVector3( v ) {
53
+
54
+ return this.setFromCartesianCoords( v.x, v.y, v.z );
55
+
56
+ }
57
+
58
+ setFromCartesianCoords( x, y, z ) {
59
+
60
+ this.radius = Math.sqrt( x * x + y * y + z * z );
61
+
62
+ if ( this.radius === 0 ) {
63
+
64
+ this.theta = 0;
65
+ this.phi = 0;
66
+
67
+ } else {
68
+
69
+ this.theta = Math.atan2( x, z );
70
+ this.phi = Math.acos( MathUtils.clamp( y / this.radius, - 1, 1 ) );
71
+
72
+ }
73
+
74
+ return this;
75
+
76
+ }
77
+
78
+ clone() {
79
+
80
+ return new this.constructor().copy( this );
81
+
82
+ }
83
+
84
+ }
85
+
86
+ export { Spherical };
@@ -0,0 +1,243 @@
1
+ import { Vector3 } from './Vector3.js';
2
+
3
+ /**
4
+ * Primary reference:
5
+ * https://graphics.stanford.edu/papers/envmap/envmap.pdf
6
+ *
7
+ * Secondary reference:
8
+ * https://www.ppsloan.org/publications/StupidSH36.pdf
9
+ */
10
+
11
+ // 3-band SH defined by 9 coefficients
12
+
13
+ class SphericalHarmonics3 {
14
+
15
+ constructor() {
16
+
17
+ this.isSphericalHarmonics3 = true;
18
+
19
+ this.coefficients = [];
20
+
21
+ for ( let i = 0; i < 9; i ++ ) {
22
+
23
+ this.coefficients.push( new Vector3() );
24
+
25
+ }
26
+
27
+ }
28
+
29
+ set( coefficients ) {
30
+
31
+ for ( let i = 0; i < 9; i ++ ) {
32
+
33
+ this.coefficients[ i ].copy( coefficients[ i ] );
34
+
35
+ }
36
+
37
+ return this;
38
+
39
+ }
40
+
41
+ zero() {
42
+
43
+ for ( let i = 0; i < 9; i ++ ) {
44
+
45
+ this.coefficients[ i ].set( 0, 0, 0 );
46
+
47
+ }
48
+
49
+ return this;
50
+
51
+ }
52
+
53
+ // get the radiance in the direction of the normal
54
+ // target is a Vector3
55
+ getAt( normal, target ) {
56
+
57
+ // normal is assumed to be unit length
58
+
59
+ const x = normal.x, y = normal.y, z = normal.z;
60
+
61
+ const coeff = this.coefficients;
62
+
63
+ // band 0
64
+ target.copy( coeff[ 0 ] ).multiplyScalar( 0.282095 );
65
+
66
+ // band 1
67
+ target.addScaledVector( coeff[ 1 ], 0.488603 * y );
68
+ target.addScaledVector( coeff[ 2 ], 0.488603 * z );
69
+ target.addScaledVector( coeff[ 3 ], 0.488603 * x );
70
+
71
+ // band 2
72
+ target.addScaledVector( coeff[ 4 ], 1.092548 * ( x * y ) );
73
+ target.addScaledVector( coeff[ 5 ], 1.092548 * ( y * z ) );
74
+ target.addScaledVector( coeff[ 6 ], 0.315392 * ( 3.0 * z * z - 1.0 ) );
75
+ target.addScaledVector( coeff[ 7 ], 1.092548 * ( x * z ) );
76
+ target.addScaledVector( coeff[ 8 ], 0.546274 * ( x * x - y * y ) );
77
+
78
+ return target;
79
+
80
+ }
81
+
82
+ // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
83
+ // target is a Vector3
84
+ // https://graphics.stanford.edu/papers/envmap/envmap.pdf
85
+ getIrradianceAt( normal, target ) {
86
+
87
+ // normal is assumed to be unit length
88
+
89
+ const x = normal.x, y = normal.y, z = normal.z;
90
+
91
+ const coeff = this.coefficients;
92
+
93
+ // band 0
94
+ target.copy( coeff[ 0 ] ).multiplyScalar( 0.886227 ); // π * 0.282095
95
+
96
+ // band 1
97
+ target.addScaledVector( coeff[ 1 ], 2.0 * 0.511664 * y ); // ( 2 * π / 3 ) * 0.488603
98
+ target.addScaledVector( coeff[ 2 ], 2.0 * 0.511664 * z );
99
+ target.addScaledVector( coeff[ 3 ], 2.0 * 0.511664 * x );
100
+
101
+ // band 2
102
+ target.addScaledVector( coeff[ 4 ], 2.0 * 0.429043 * x * y ); // ( π / 4 ) * 1.092548
103
+ target.addScaledVector( coeff[ 5 ], 2.0 * 0.429043 * y * z );
104
+ target.addScaledVector( coeff[ 6 ], 0.743125 * z * z - 0.247708 ); // ( π / 4 ) * 0.315392 * 3
105
+ target.addScaledVector( coeff[ 7 ], 2.0 * 0.429043 * x * z );
106
+ target.addScaledVector( coeff[ 8 ], 0.429043 * ( x * x - y * y ) ); // ( π / 4 ) * 0.546274
107
+
108
+ return target;
109
+
110
+ }
111
+
112
+ add( sh ) {
113
+
114
+ for ( let i = 0; i < 9; i ++ ) {
115
+
116
+ this.coefficients[ i ].add( sh.coefficients[ i ] );
117
+
118
+ }
119
+
120
+ return this;
121
+
122
+ }
123
+
124
+ addScaledSH( sh, s ) {
125
+
126
+ for ( let i = 0; i < 9; i ++ ) {
127
+
128
+ this.coefficients[ i ].addScaledVector( sh.coefficients[ i ], s );
129
+
130
+ }
131
+
132
+ return this;
133
+
134
+ }
135
+
136
+ scale( s ) {
137
+
138
+ for ( let i = 0; i < 9; i ++ ) {
139
+
140
+ this.coefficients[ i ].multiplyScalar( s );
141
+
142
+ }
143
+
144
+ return this;
145
+
146
+ }
147
+
148
+ lerp( sh, alpha ) {
149
+
150
+ for ( let i = 0; i < 9; i ++ ) {
151
+
152
+ this.coefficients[ i ].lerp( sh.coefficients[ i ], alpha );
153
+
154
+ }
155
+
156
+ return this;
157
+
158
+ }
159
+
160
+ equals( sh ) {
161
+
162
+ for ( let i = 0; i < 9; i ++ ) {
163
+
164
+ if ( ! this.coefficients[ i ].equals( sh.coefficients[ i ] ) ) {
165
+
166
+ return false;
167
+
168
+ }
169
+
170
+ }
171
+
172
+ return true;
173
+
174
+ }
175
+
176
+ copy( sh ) {
177
+
178
+ return this.set( sh.coefficients );
179
+
180
+ }
181
+
182
+ clone() {
183
+
184
+ return new this.constructor().copy( this );
185
+
186
+ }
187
+
188
+ fromArray( array, offset = 0 ) {
189
+
190
+ const coefficients = this.coefficients;
191
+
192
+ for ( let i = 0; i < 9; i ++ ) {
193
+
194
+ coefficients[ i ].fromArray( array, offset + ( i * 3 ) );
195
+
196
+ }
197
+
198
+ return this;
199
+
200
+ }
201
+
202
+ toArray( array = [], offset = 0 ) {
203
+
204
+ const coefficients = this.coefficients;
205
+
206
+ for ( let i = 0; i < 9; i ++ ) {
207
+
208
+ coefficients[ i ].toArray( array, offset + ( i * 3 ) );
209
+
210
+ }
211
+
212
+ return array;
213
+
214
+ }
215
+
216
+ // evaluate the basis functions
217
+ // shBasis is an Array[ 9 ]
218
+ static getBasisAt( normal, shBasis ) {
219
+
220
+ // normal is assumed to be unit length
221
+
222
+ const x = normal.x, y = normal.y, z = normal.z;
223
+
224
+ // band 0
225
+ shBasis[ 0 ] = 0.282095;
226
+
227
+ // band 1
228
+ shBasis[ 1 ] = 0.488603 * y;
229
+ shBasis[ 2 ] = 0.488603 * z;
230
+ shBasis[ 3 ] = 0.488603 * x;
231
+
232
+ // band 2
233
+ shBasis[ 4 ] = 1.092548 * x * y;
234
+ shBasis[ 5 ] = 1.092548 * y * z;
235
+ shBasis[ 6 ] = 0.315392 * ( 3 * z * z - 1 );
236
+ shBasis[ 7 ] = 1.092548 * x * z;
237
+ shBasis[ 8 ] = 0.546274 * ( x * x - y * y );
238
+
239
+ }
240
+
241
+ }
242
+
243
+ export { SphericalHarmonics3 };
@@ -0,0 +1,299 @@
1
+ import { Vector3 } from './Vector3.js';
2
+
3
+ const _v0 = /*@__PURE__*/ new Vector3();
4
+ const _v1 = /*@__PURE__*/ new Vector3();
5
+ const _v2 = /*@__PURE__*/ new Vector3();
6
+ const _v3 = /*@__PURE__*/ new Vector3();
7
+
8
+ const _vab = /*@__PURE__*/ new Vector3();
9
+ const _vac = /*@__PURE__*/ new Vector3();
10
+ const _vbc = /*@__PURE__*/ new Vector3();
11
+ const _vap = /*@__PURE__*/ new Vector3();
12
+ const _vbp = /*@__PURE__*/ new Vector3();
13
+ const _vcp = /*@__PURE__*/ new Vector3();
14
+
15
+ class Triangle {
16
+
17
+ constructor( a = new Vector3(), b = new Vector3(), c = new Vector3() ) {
18
+
19
+ this.a = a;
20
+ this.b = b;
21
+ this.c = c;
22
+
23
+ }
24
+
25
+ static getNormal( a, b, c, target ) {
26
+
27
+ target.subVectors( c, b );
28
+ _v0.subVectors( a, b );
29
+ target.cross( _v0 );
30
+
31
+ const targetLengthSq = target.lengthSq();
32
+ if ( targetLengthSq > 0 ) {
33
+
34
+ return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
35
+
36
+ }
37
+
38
+ return target.set( 0, 0, 0 );
39
+
40
+ }
41
+
42
+ // static/instance method to calculate barycentric coordinates
43
+ // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
44
+ static getBarycoord( point, a, b, c, target ) {
45
+
46
+ _v0.subVectors( c, a );
47
+ _v1.subVectors( b, a );
48
+ _v2.subVectors( point, a );
49
+
50
+ const dot00 = _v0.dot( _v0 );
51
+ const dot01 = _v0.dot( _v1 );
52
+ const dot02 = _v0.dot( _v2 );
53
+ const dot11 = _v1.dot( _v1 );
54
+ const dot12 = _v1.dot( _v2 );
55
+
56
+ const denom = ( dot00 * dot11 - dot01 * dot01 );
57
+
58
+ // collinear or singular triangle
59
+ if ( denom === 0 ) {
60
+
61
+ // arbitrary location outside of triangle?
62
+ // not sure if this is the best idea, maybe should be returning undefined
63
+ return target.set( - 2, - 1, - 1 );
64
+
65
+ }
66
+
67
+ const invDenom = 1 / denom;
68
+ const u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
69
+ const v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
70
+
71
+ // barycentric coordinates must always sum to 1
72
+ return target.set( 1 - u - v, v, u );
73
+
74
+ }
75
+
76
+ static containsPoint( point, a, b, c ) {
77
+
78
+ this.getBarycoord( point, a, b, c, _v3 );
79
+
80
+ return ( _v3.x >= 0 ) && ( _v3.y >= 0 ) && ( ( _v3.x + _v3.y ) <= 1 );
81
+
82
+ }
83
+
84
+ static getUV( point, p1, p2, p3, uv1, uv2, uv3, target ) {
85
+
86
+ this.getBarycoord( point, p1, p2, p3, _v3 );
87
+
88
+ target.set( 0, 0 );
89
+ target.addScaledVector( uv1, _v3.x );
90
+ target.addScaledVector( uv2, _v3.y );
91
+ target.addScaledVector( uv3, _v3.z );
92
+
93
+ return target;
94
+
95
+ }
96
+
97
+ static isFrontFacing( a, b, c, direction ) {
98
+
99
+ _v0.subVectors( c, b );
100
+ _v1.subVectors( a, b );
101
+
102
+ // strictly front facing
103
+ return ( _v0.cross( _v1 ).dot( direction ) < 0 ) ? true : false;
104
+
105
+ }
106
+
107
+ set( a, b, c ) {
108
+
109
+ this.a.copy( a );
110
+ this.b.copy( b );
111
+ this.c.copy( c );
112
+
113
+ return this;
114
+
115
+ }
116
+
117
+ setFromPointsAndIndices( points, i0, i1, i2 ) {
118
+
119
+ this.a.copy( points[ i0 ] );
120
+ this.b.copy( points[ i1 ] );
121
+ this.c.copy( points[ i2 ] );
122
+
123
+ return this;
124
+
125
+ }
126
+
127
+ setFromAttributeAndIndices( attribute, i0, i1, i2 ) {
128
+
129
+ this.a.fromBufferAttribute( attribute, i0 );
130
+ this.b.fromBufferAttribute( attribute, i1 );
131
+ this.c.fromBufferAttribute( attribute, i2 );
132
+
133
+ return this;
134
+
135
+ }
136
+
137
+ clone() {
138
+
139
+ return new this.constructor().copy( this );
140
+
141
+ }
142
+
143
+ copy( triangle ) {
144
+
145
+ this.a.copy( triangle.a );
146
+ this.b.copy( triangle.b );
147
+ this.c.copy( triangle.c );
148
+
149
+ return this;
150
+
151
+ }
152
+
153
+ getArea() {
154
+
155
+ _v0.subVectors( this.c, this.b );
156
+ _v1.subVectors( this.a, this.b );
157
+
158
+ return _v0.cross( _v1 ).length() * 0.5;
159
+
160
+ }
161
+
162
+ getMidpoint( target ) {
163
+
164
+ return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
165
+
166
+ }
167
+
168
+ getNormal( target ) {
169
+
170
+ return Triangle.getNormal( this.a, this.b, this.c, target );
171
+
172
+ }
173
+
174
+ getPlane( target ) {
175
+
176
+ return target.setFromCoplanarPoints( this.a, this.b, this.c );
177
+
178
+ }
179
+
180
+ getBarycoord( point, target ) {
181
+
182
+ return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
183
+
184
+ }
185
+
186
+ getUV( point, uv1, uv2, uv3, target ) {
187
+
188
+ return Triangle.getUV( point, this.a, this.b, this.c, uv1, uv2, uv3, target );
189
+
190
+ }
191
+
192
+ containsPoint( point ) {
193
+
194
+ return Triangle.containsPoint( point, this.a, this.b, this.c );
195
+
196
+ }
197
+
198
+ isFrontFacing( direction ) {
199
+
200
+ return Triangle.isFrontFacing( this.a, this.b, this.c, direction );
201
+
202
+ }
203
+
204
+ intersectsBox( box ) {
205
+
206
+ return box.intersectsTriangle( this );
207
+
208
+ }
209
+
210
+ closestPointToPoint( p, target ) {
211
+
212
+ const a = this.a, b = this.b, c = this.c;
213
+ let v, w;
214
+
215
+ // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
216
+ // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
217
+ // under the accompanying license; see chapter 5.1.5 for detailed explanation.
218
+ // basically, we're distinguishing which of the voronoi regions of the triangle
219
+ // the point lies in with the minimum amount of redundant computation.
220
+
221
+ _vab.subVectors( b, a );
222
+ _vac.subVectors( c, a );
223
+ _vap.subVectors( p, a );
224
+ const d1 = _vab.dot( _vap );
225
+ const d2 = _vac.dot( _vap );
226
+ if ( d1 <= 0 && d2 <= 0 ) {
227
+
228
+ // vertex region of A; barycentric coords (1, 0, 0)
229
+ return target.copy( a );
230
+
231
+ }
232
+
233
+ _vbp.subVectors( p, b );
234
+ const d3 = _vab.dot( _vbp );
235
+ const d4 = _vac.dot( _vbp );
236
+ if ( d3 >= 0 && d4 <= d3 ) {
237
+
238
+ // vertex region of B; barycentric coords (0, 1, 0)
239
+ return target.copy( b );
240
+
241
+ }
242
+
243
+ const vc = d1 * d4 - d3 * d2;
244
+ if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) {
245
+
246
+ v = d1 / ( d1 - d3 );
247
+ // edge region of AB; barycentric coords (1-v, v, 0)
248
+ return target.copy( a ).addScaledVector( _vab, v );
249
+
250
+ }
251
+
252
+ _vcp.subVectors( p, c );
253
+ const d5 = _vab.dot( _vcp );
254
+ const d6 = _vac.dot( _vcp );
255
+ if ( d6 >= 0 && d5 <= d6 ) {
256
+
257
+ // vertex region of C; barycentric coords (0, 0, 1)
258
+ return target.copy( c );
259
+
260
+ }
261
+
262
+ const vb = d5 * d2 - d1 * d6;
263
+ if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) {
264
+
265
+ w = d2 / ( d2 - d6 );
266
+ // edge region of AC; barycentric coords (1-w, 0, w)
267
+ return target.copy( a ).addScaledVector( _vac, w );
268
+
269
+ }
270
+
271
+ const va = d3 * d6 - d5 * d4;
272
+ if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) {
273
+
274
+ _vbc.subVectors( c, b );
275
+ w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );
276
+ // edge region of BC; barycentric coords (0, 1-w, w)
277
+ return target.copy( b ).addScaledVector( _vbc, w ); // edge region of BC
278
+
279
+ }
280
+
281
+ // face region
282
+ const denom = 1 / ( va + vb + vc );
283
+ // u = va * denom
284
+ v = vb * denom;
285
+ w = vc * denom;
286
+
287
+ return target.copy( a ).addScaledVector( _vab, v ).addScaledVector( _vac, w );
288
+
289
+ }
290
+
291
+ equals( triangle ) {
292
+
293
+ return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
294
+
295
+ }
296
+
297
+ }
298
+
299
+ export { Triangle };