@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.
- package/README.md +158 -67
- package/package.json +28 -7
- package/public/Gaea.apple-touch-icon.png +0 -0
- package/public/Gaea.apple-touch-icon.png.import +35 -0
- package/public/Gaea.audio.worklet.js +211 -0
- package/public/Gaea.html +245 -0
- package/public/Gaea.icon.png +0 -0
- package/public/Gaea.icon.png.import +35 -0
- package/public/Gaea.js +782 -0
- package/public/Gaea.png +0 -0
- package/public/Gaea.png.import +35 -0
- package/public/Gaea.worker.js +1 -0
- package/public/GaeaApp.html +275 -0
- package/public/GaeaMethods.js +4342 -0
- package/public/GaeaModule.html +276 -0
- package/public/config.js +76 -0
- package/public/constants.js +185 -0
- package/public/favicon.ico +0 -0
- package/public/image/1.png +0 -0
- package/public/image/12-min-min.gif +0 -0
- package/public/image/3.png +0 -0
- package/public/image/labelImg//345/217/263/350/276/271.png +0 -0
- package/public/image/labelImg//345/267/246/350/276/271.png +0 -0
- package/public/image/labelImg//346/260/264/344/275/215.png +0 -0
- package/public/image/screenIcon//345/205/266/344/273/226.png +0 -0
- 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
- 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
- package/public/image/screenIcon//346/212/242/351/231/251/345/215/225/344/275/215.png +0 -0
- package/public/image/screenIcon//346/226/255/351/235/242.png +0 -0
- package/public/image/screenIcon//346/227/240/344/272/272/346/234/272.png +0 -0
- package/public/image/screenIcon//346/227/240/344/272/272/346/234/272/345/237/272/345/234/260.png +0 -0
- package/public/image/screenIcon//346/260/264/345/272/223/347/253/231.png +0 -0
- package/public/image/screenIcon//346/260/264/346/226/207/346/265/213/347/253/231.png +0 -0
- package/public/image/screenIcon//346/260/264/351/227/270.png +0 -0
- 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
- package/public/image/screenIcon//346/262/263/351/201/223/347/253/231-/346/255/243/345/270/270.png +0 -0
- package/public/image/screenIcon//346/262/263/351/201/223/347/253/231-/350/266/205/344/277/235.png +0 -0
- package/public/image/screenIcon//346/262/263/351/201/223/347/253/231-/350/266/205/350/255/246.png +0 -0
- package/public/image/screenIcon//346/263/265/347/253/231-/347/201/260.png +0 -0
- package/public/image/screenIcon//346/263/265/347/253/231-/347/273/277.png +0 -0
- package/public/image/screenIcon//346/265/201/351/207/217/346/265/213/347/253/231.png +0 -0
- package/public/image/screenIcon//346/265/267/345/241/230-1/347/272/247.png +0 -0
- package/public/image/screenIcon//346/265/267/345/241/230-2/347/272/247.png +0 -0
- package/public/image/screenIcon//346/265/267/345/241/230-3/347/272/247.png +0 -0
- package/public/image/screenIcon//346/265/267/345/241/230-4/347/272/247.png +0 -0
- package/public/image/screenIcon//346/265/267/345/241/230-5/347/272/247.png +0 -0
- package/public/image/screenIcon//346/265/267/345/241/230-/346/251/231.png +0 -0
- package/public/image/screenIcon//346/265/267/345/241/230-/347/272/242.png +0 -0
- package/public/image/screenIcon//346/265/267/345/241/230-/347/273/277.png +0 -0
- 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
- package/public/image/screenIcon//346/265/267/345/241/230-/351/273/204.png +0 -0
- package/public/image/screenIcon//346/265/267/345/241/230.png +0 -0
- package/public/image/screenIcon//346/275/256/344/275/215.png +0 -0
- 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
- package/public/image/screenIcon//346/275/256/344/275/215/347/253/231-/346/255/243/345/270/270.png +0 -0
- package/public/image/screenIcon//346/275/256/344/275/215/347/253/231-/350/266/205/344/277/235.png +0 -0
- package/public/image/screenIcon//346/275/256/344/275/215/347/253/231-/350/266/205/350/255/246.png +0 -0
- package/public/image/screenIcon//347/211/251/350/265/204/344/273/223/345/272/223.png +0 -0
- package/public/image/screenIcon//347/220/203/346/234/272-/345/205/263.png +0 -0
- package/public/image/screenIcon//347/220/203/346/234/272-/345/274/200.png +0 -0
- package/public/image/screenIcon//347/220/203/346/234/272-/347/272/242.png +0 -0
- package/public/image/screenIcon//350/247/206/351/242/221/347/233/221/346/216/247.png +0 -0
- package/public/image/screenIcon//351/227/270/351/227/250-/347/201/260.png +0 -0
- package/public/image/screenIcon//351/227/270/351/227/250-/347/273/277.png +0 -0
- package/public/image/screenIcon//351/230/262/346/264/252/344/273/223/345/272/223.png +0 -0
- package/public/image/screenIcon//351/232/220/346/202/243.png +0 -0
- package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/346/265/205/350/223/235.png +0 -0
- package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/347/201/260.png +0 -0
- package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/347/262/211.png +0 -0
- package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/347/272/242.png +0 -0
- package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/347/273/277.png +0 -0
- package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/350/223/235.png +0 -0
- package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/351/273/204.png +0 -0
- package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/351/273/221.png +0 -0
- package/public/image/screenIcon//351/243/216/351/200/237.png +0 -0
- package/public/image/screenIcon//351/243/216/351/200/237/346/265/213/347/253/231.png +0 -0
- package/public/image//346/260/264/346/226/207.gif +0 -0
- package/public/image//350/211/262/345/270/246.png +0 -0
- package/public/index.html +22 -0
- package/public/index.js +185662 -0
- package/public/jsWebControl-1.0.0.min.js +31 -0
- package/public/jsencrypt.min.js +1 -0
- package/public/math/Box2.js +203 -0
- package/public/math/Box3.js +532 -0
- package/public/math/Color.js +605 -0
- package/public/math/ColorManagement.js +74 -0
- package/public/math/Cylindrical.js +61 -0
- package/public/math/EngineUtils.js +81 -0
- package/public/math/Euler.js +315 -0
- package/public/math/Frustum.js +162 -0
- package/public/math/Interpolant.js +241 -0
- package/public/math/Line3.js +115 -0
- package/public/math/MathUtils.js +345 -0
- package/public/math/Matrix3.js +365 -0
- package/public/math/Matrix4.js +858 -0
- package/public/math/Plane.js +205 -0
- package/public/math/Quaternion.js +724 -0
- package/public/math/Ray.js +493 -0
- package/public/math/Sphere.js +243 -0
- package/public/math/Spherical.js +86 -0
- package/public/math/SphericalHarmonics3.js +243 -0
- package/public/math/Triangle.js +299 -0
- package/public/math/Vector2.js +464 -0
- package/public/math/Vector3.js +715 -0
- package/public/math/Vector4.js +644 -0
- package/public/math/interpolants/CubicInterpolant.js +151 -0
- package/public/math/interpolants/DiscreteInterpolant.js +26 -0
- package/public/math/interpolants/LinearInterpolant.js +38 -0
- package/public/math/interpolants/QuaternionLinearInterpolant.js +39 -0
- package/public/static/Cloud.png +0 -0
- package/public/static/Global2.jpg +0 -0
- package/public/static/css/main.css +170 -0
- package/public/static/geojson//346/265/267/345/241/230.geojson +99 -0
- package/public/static/img/loading.gif +0 -0
- package/public/static/js/app.js +359 -0
- package/public/static/js/appcontroller.js +207 -0
- package/public/static/js/dist/game.dev.js +137 -0
- package/public/static/js/env.js +74 -0
- package/public/static/js/event/event.js +107 -0
- package/public/static/js/init.js +8 -0
- package/public/static/js/initcloudmorph.js +1 -0
- package/public/static/js/log.js +35 -0
- package/public/static/js/network/ajax.js +29 -0
- package/public/static/js/network/rtcp.js +172 -0
- package/public/static/js/network/socket.js +106 -0
- package/public/web-control.min.js +2 -0
- package/scripts/postinstall.mjs +127 -0
- package/src/GaeaMethods.js +68 -405
- package/src/components/FlyAlongRoute.vue +1 -0
- package/src/components/WeatherControl.vue +2 -0
- package/src/directives/vDrag.js +70 -0
- package/src/index.js +1 -8
- package/src/plugin.js +16 -0
- package/src/utils.js +10 -21
- package/src/vite-plugin.js +117 -0
- package/public/static/1111.res +0 -0
- package/src/config.js +0 -40
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
import { Vector3 } from './Vector3.js';
|
|
2
|
+
|
|
3
|
+
const _vector = /*@__PURE__*/ new Vector3();
|
|
4
|
+
const _segCenter = /*@__PURE__*/ new Vector3();
|
|
5
|
+
const _segDir = /*@__PURE__*/ new Vector3();
|
|
6
|
+
const _diff = /*@__PURE__*/ new Vector3();
|
|
7
|
+
|
|
8
|
+
const _edge1 = /*@__PURE__*/ new Vector3();
|
|
9
|
+
const _edge2 = /*@__PURE__*/ new Vector3();
|
|
10
|
+
const _normal = /*@__PURE__*/ new Vector3();
|
|
11
|
+
|
|
12
|
+
class Ray {
|
|
13
|
+
|
|
14
|
+
constructor( origin = new Vector3(), direction = new Vector3( 0, 0, - 1 ) ) {
|
|
15
|
+
|
|
16
|
+
this.origin = origin;
|
|
17
|
+
this.direction = direction;
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
set( origin, direction ) {
|
|
22
|
+
|
|
23
|
+
this.origin.copy( origin );
|
|
24
|
+
this.direction.copy( direction );
|
|
25
|
+
|
|
26
|
+
return this;
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
copy( ray ) {
|
|
31
|
+
|
|
32
|
+
this.origin.copy( ray.origin );
|
|
33
|
+
this.direction.copy( ray.direction );
|
|
34
|
+
|
|
35
|
+
return this;
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
at( t, target ) {
|
|
40
|
+
|
|
41
|
+
return target.copy( this.direction ).multiplyScalar( t ).add( this.origin );
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
lookAt( v ) {
|
|
46
|
+
|
|
47
|
+
this.direction.copy( v ).sub( this.origin ).normalize();
|
|
48
|
+
|
|
49
|
+
return this;
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
recast( t ) {
|
|
54
|
+
|
|
55
|
+
this.origin.copy( this.at( t, _vector ) );
|
|
56
|
+
|
|
57
|
+
return this;
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
closestPointToPoint( point, target ) {
|
|
62
|
+
|
|
63
|
+
target.subVectors( point, this.origin );
|
|
64
|
+
|
|
65
|
+
const directionDistance = target.dot( this.direction );
|
|
66
|
+
|
|
67
|
+
if ( directionDistance < 0 ) {
|
|
68
|
+
|
|
69
|
+
return target.copy( this.origin );
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return target.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
|
|
74
|
+
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
distanceToPoint( point ) {
|
|
78
|
+
|
|
79
|
+
return Math.sqrt( this.distanceSqToPoint( point ) );
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
distanceSqToPoint( point ) {
|
|
84
|
+
|
|
85
|
+
const directionDistance = _vector.subVectors( point, this.origin ).dot( this.direction );
|
|
86
|
+
|
|
87
|
+
// point behind the ray
|
|
88
|
+
|
|
89
|
+
if ( directionDistance < 0 ) {
|
|
90
|
+
|
|
91
|
+
return this.origin.distanceToSquared( point );
|
|
92
|
+
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
_vector.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
|
|
96
|
+
|
|
97
|
+
return _vector.distanceToSquared( point );
|
|
98
|
+
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
|
|
102
|
+
|
|
103
|
+
// from https://github.com/pmjoniak/GeometricTools/blob/master/GTEngine/Include/Mathematics/GteDistRaySegment.h
|
|
104
|
+
// It returns the min distance between the ray and the segment
|
|
105
|
+
// defined by v0 and v1
|
|
106
|
+
// It can also set two optional targets :
|
|
107
|
+
// - The closest point on the ray
|
|
108
|
+
// - The closest point on the segment
|
|
109
|
+
|
|
110
|
+
_segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
|
|
111
|
+
_segDir.copy( v1 ).sub( v0 ).normalize();
|
|
112
|
+
_diff.copy( this.origin ).sub( _segCenter );
|
|
113
|
+
|
|
114
|
+
const segExtent = v0.distanceTo( v1 ) * 0.5;
|
|
115
|
+
const a01 = - this.direction.dot( _segDir );
|
|
116
|
+
const b0 = _diff.dot( this.direction );
|
|
117
|
+
const b1 = - _diff.dot( _segDir );
|
|
118
|
+
const c = _diff.lengthSq();
|
|
119
|
+
const det = Math.abs( 1 - a01 * a01 );
|
|
120
|
+
let s0, s1, sqrDist, extDet;
|
|
121
|
+
|
|
122
|
+
if ( det > 0 ) {
|
|
123
|
+
|
|
124
|
+
// The ray and segment are not parallel.
|
|
125
|
+
|
|
126
|
+
s0 = a01 * b1 - b0;
|
|
127
|
+
s1 = a01 * b0 - b1;
|
|
128
|
+
extDet = segExtent * det;
|
|
129
|
+
|
|
130
|
+
if ( s0 >= 0 ) {
|
|
131
|
+
|
|
132
|
+
if ( s1 >= - extDet ) {
|
|
133
|
+
|
|
134
|
+
if ( s1 <= extDet ) {
|
|
135
|
+
|
|
136
|
+
// region 0
|
|
137
|
+
// Minimum at interior points of ray and segment.
|
|
138
|
+
|
|
139
|
+
const invDet = 1 / det;
|
|
140
|
+
s0 *= invDet;
|
|
141
|
+
s1 *= invDet;
|
|
142
|
+
sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
|
|
143
|
+
|
|
144
|
+
} else {
|
|
145
|
+
|
|
146
|
+
// region 1
|
|
147
|
+
|
|
148
|
+
s1 = segExtent;
|
|
149
|
+
s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
|
|
150
|
+
sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
|
|
151
|
+
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
} else {
|
|
155
|
+
|
|
156
|
+
// region 5
|
|
157
|
+
|
|
158
|
+
s1 = - segExtent;
|
|
159
|
+
s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
|
|
160
|
+
sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
|
|
161
|
+
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
} else {
|
|
165
|
+
|
|
166
|
+
if ( s1 <= - extDet ) {
|
|
167
|
+
|
|
168
|
+
// region 4
|
|
169
|
+
|
|
170
|
+
s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
|
|
171
|
+
s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
|
|
172
|
+
sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
|
|
173
|
+
|
|
174
|
+
} else if ( s1 <= extDet ) {
|
|
175
|
+
|
|
176
|
+
// region 3
|
|
177
|
+
|
|
178
|
+
s0 = 0;
|
|
179
|
+
s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
|
|
180
|
+
sqrDist = s1 * ( s1 + 2 * b1 ) + c;
|
|
181
|
+
|
|
182
|
+
} else {
|
|
183
|
+
|
|
184
|
+
// region 2
|
|
185
|
+
|
|
186
|
+
s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
|
|
187
|
+
s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
|
|
188
|
+
sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
|
|
189
|
+
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
} else {
|
|
195
|
+
|
|
196
|
+
// Ray and segment are parallel.
|
|
197
|
+
|
|
198
|
+
s1 = ( a01 > 0 ) ? - segExtent : segExtent;
|
|
199
|
+
s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
|
|
200
|
+
sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
|
|
201
|
+
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if ( optionalPointOnRay ) {
|
|
205
|
+
|
|
206
|
+
optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
|
|
207
|
+
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if ( optionalPointOnSegment ) {
|
|
211
|
+
|
|
212
|
+
optionalPointOnSegment.copy( _segDir ).multiplyScalar( s1 ).add( _segCenter );
|
|
213
|
+
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return sqrDist;
|
|
217
|
+
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
intersectSphere( sphere, target ) {
|
|
221
|
+
|
|
222
|
+
_vector.subVectors( sphere.center, this.origin );
|
|
223
|
+
const tca = _vector.dot( this.direction );
|
|
224
|
+
const d2 = _vector.dot( _vector ) - tca * tca;
|
|
225
|
+
const radius2 = sphere.radius * sphere.radius;
|
|
226
|
+
|
|
227
|
+
if ( d2 > radius2 ) return null;
|
|
228
|
+
|
|
229
|
+
const thc = Math.sqrt( radius2 - d2 );
|
|
230
|
+
|
|
231
|
+
// t0 = first intersect point - entrance on front of sphere
|
|
232
|
+
const t0 = tca - thc;
|
|
233
|
+
|
|
234
|
+
// t1 = second intersect point - exit point on back of sphere
|
|
235
|
+
const t1 = tca + thc;
|
|
236
|
+
|
|
237
|
+
// test to see if both t0 and t1 are behind the ray - if so, return null
|
|
238
|
+
if ( t0 < 0 && t1 < 0 ) return null;
|
|
239
|
+
|
|
240
|
+
// test to see if t0 is behind the ray:
|
|
241
|
+
// if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
|
|
242
|
+
// in order to always return an intersect point that is in front of the ray.
|
|
243
|
+
if ( t0 < 0 ) return this.at( t1, target );
|
|
244
|
+
|
|
245
|
+
// else t0 is in front of the ray, so return the first collision point scaled by t0
|
|
246
|
+
return this.at( t0, target );
|
|
247
|
+
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
intersectsSphere( sphere ) {
|
|
251
|
+
|
|
252
|
+
return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius );
|
|
253
|
+
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
distanceToPlane( plane ) {
|
|
257
|
+
|
|
258
|
+
const denominator = plane.normal.dot( this.direction );
|
|
259
|
+
|
|
260
|
+
if ( denominator === 0 ) {
|
|
261
|
+
|
|
262
|
+
// line is coplanar, return origin
|
|
263
|
+
if ( plane.distanceToPoint( this.origin ) === 0 ) {
|
|
264
|
+
|
|
265
|
+
return 0;
|
|
266
|
+
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// Null is preferable to undefined since undefined means.... it is undefined
|
|
270
|
+
|
|
271
|
+
return null;
|
|
272
|
+
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
|
|
276
|
+
|
|
277
|
+
// Return if the ray never intersects the plane
|
|
278
|
+
|
|
279
|
+
return t >= 0 ? t : null;
|
|
280
|
+
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
intersectPlane( plane, target ) {
|
|
284
|
+
|
|
285
|
+
const t = this.distanceToPlane( plane );
|
|
286
|
+
|
|
287
|
+
if ( t === null ) {
|
|
288
|
+
|
|
289
|
+
return null;
|
|
290
|
+
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return this.at( t, target );
|
|
294
|
+
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
intersectsPlane( plane ) {
|
|
298
|
+
|
|
299
|
+
// check if the ray lies on the plane first
|
|
300
|
+
|
|
301
|
+
const distToPoint = plane.distanceToPoint( this.origin );
|
|
302
|
+
|
|
303
|
+
if ( distToPoint === 0 ) {
|
|
304
|
+
|
|
305
|
+
return true;
|
|
306
|
+
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const denominator = plane.normal.dot( this.direction );
|
|
310
|
+
|
|
311
|
+
if ( denominator * distToPoint < 0 ) {
|
|
312
|
+
|
|
313
|
+
return true;
|
|
314
|
+
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// ray origin is behind the plane (and is pointing behind it)
|
|
318
|
+
|
|
319
|
+
return false;
|
|
320
|
+
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
intersectBox( box, target ) {
|
|
324
|
+
|
|
325
|
+
let tmin, tmax, tymin, tymax, tzmin, tzmax;
|
|
326
|
+
|
|
327
|
+
const invdirx = 1 / this.direction.x,
|
|
328
|
+
invdiry = 1 / this.direction.y,
|
|
329
|
+
invdirz = 1 / this.direction.z;
|
|
330
|
+
|
|
331
|
+
const origin = this.origin;
|
|
332
|
+
|
|
333
|
+
if ( invdirx >= 0 ) {
|
|
334
|
+
|
|
335
|
+
tmin = ( box.min.x - origin.x ) * invdirx;
|
|
336
|
+
tmax = ( box.max.x - origin.x ) * invdirx;
|
|
337
|
+
|
|
338
|
+
} else {
|
|
339
|
+
|
|
340
|
+
tmin = ( box.max.x - origin.x ) * invdirx;
|
|
341
|
+
tmax = ( box.min.x - origin.x ) * invdirx;
|
|
342
|
+
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if ( invdiry >= 0 ) {
|
|
346
|
+
|
|
347
|
+
tymin = ( box.min.y - origin.y ) * invdiry;
|
|
348
|
+
tymax = ( box.max.y - origin.y ) * invdiry;
|
|
349
|
+
|
|
350
|
+
} else {
|
|
351
|
+
|
|
352
|
+
tymin = ( box.max.y - origin.y ) * invdiry;
|
|
353
|
+
tymax = ( box.min.y - origin.y ) * invdiry;
|
|
354
|
+
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
|
|
358
|
+
|
|
359
|
+
if ( tymin > tmin || isNaN( tmin ) ) tmin = tymin;
|
|
360
|
+
|
|
361
|
+
if ( tymax < tmax || isNaN( tmax ) ) tmax = tymax;
|
|
362
|
+
|
|
363
|
+
if ( invdirz >= 0 ) {
|
|
364
|
+
|
|
365
|
+
tzmin = ( box.min.z - origin.z ) * invdirz;
|
|
366
|
+
tzmax = ( box.max.z - origin.z ) * invdirz;
|
|
367
|
+
|
|
368
|
+
} else {
|
|
369
|
+
|
|
370
|
+
tzmin = ( box.max.z - origin.z ) * invdirz;
|
|
371
|
+
tzmax = ( box.min.z - origin.z ) * invdirz;
|
|
372
|
+
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
|
|
376
|
+
|
|
377
|
+
if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
|
|
378
|
+
|
|
379
|
+
if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
|
|
380
|
+
|
|
381
|
+
//return point closest to the ray (positive side)
|
|
382
|
+
|
|
383
|
+
if ( tmax < 0 ) return null;
|
|
384
|
+
|
|
385
|
+
return this.at( tmin >= 0 ? tmin : tmax, target );
|
|
386
|
+
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
intersectsBox( box ) {
|
|
390
|
+
|
|
391
|
+
return this.intersectBox( box, _vector ) !== null;
|
|
392
|
+
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
intersectTriangle( a, b, c, backfaceCulling, target ) {
|
|
396
|
+
|
|
397
|
+
// Compute the offset origin, edges, and normal.
|
|
398
|
+
|
|
399
|
+
// from https://github.com/pmjoniak/GeometricTools/blob/master/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
|
|
400
|
+
|
|
401
|
+
_edge1.subVectors( b, a );
|
|
402
|
+
_edge2.subVectors( c, a );
|
|
403
|
+
_normal.crossVectors( _edge1, _edge2 );
|
|
404
|
+
|
|
405
|
+
// Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
|
|
406
|
+
// E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
|
|
407
|
+
// |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
|
|
408
|
+
// |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
|
|
409
|
+
// |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
|
|
410
|
+
let DdN = this.direction.dot( _normal );
|
|
411
|
+
let sign;
|
|
412
|
+
|
|
413
|
+
if ( DdN > 0 ) {
|
|
414
|
+
|
|
415
|
+
if ( backfaceCulling ) return null;
|
|
416
|
+
sign = 1;
|
|
417
|
+
|
|
418
|
+
} else if ( DdN < 0 ) {
|
|
419
|
+
|
|
420
|
+
sign = - 1;
|
|
421
|
+
DdN = - DdN;
|
|
422
|
+
|
|
423
|
+
} else {
|
|
424
|
+
|
|
425
|
+
return null;
|
|
426
|
+
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
_diff.subVectors( this.origin, a );
|
|
430
|
+
const DdQxE2 = sign * this.direction.dot( _edge2.crossVectors( _diff, _edge2 ) );
|
|
431
|
+
|
|
432
|
+
// b1 < 0, no intersection
|
|
433
|
+
if ( DdQxE2 < 0 ) {
|
|
434
|
+
|
|
435
|
+
return null;
|
|
436
|
+
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
const DdE1xQ = sign * this.direction.dot( _edge1.cross( _diff ) );
|
|
440
|
+
|
|
441
|
+
// b2 < 0, no intersection
|
|
442
|
+
if ( DdE1xQ < 0 ) {
|
|
443
|
+
|
|
444
|
+
return null;
|
|
445
|
+
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// b1+b2 > 1, no intersection
|
|
449
|
+
if ( DdQxE2 + DdE1xQ > DdN ) {
|
|
450
|
+
|
|
451
|
+
return null;
|
|
452
|
+
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// Line intersects triangle, check if ray does.
|
|
456
|
+
const QdN = - sign * _diff.dot( _normal );
|
|
457
|
+
|
|
458
|
+
// t < 0, no intersection
|
|
459
|
+
if ( QdN < 0 ) {
|
|
460
|
+
|
|
461
|
+
return null;
|
|
462
|
+
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// Ray intersects triangle.
|
|
466
|
+
return this.at( QdN / DdN, target );
|
|
467
|
+
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
applyMatrix4( matrix4 ) {
|
|
471
|
+
|
|
472
|
+
this.origin.applyMatrix4( matrix4 );
|
|
473
|
+
this.direction.transformDirection( matrix4 );
|
|
474
|
+
|
|
475
|
+
return this;
|
|
476
|
+
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
equals( ray ) {
|
|
480
|
+
|
|
481
|
+
return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
|
|
482
|
+
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
clone() {
|
|
486
|
+
|
|
487
|
+
return new this.constructor().copy( this );
|
|
488
|
+
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
export { Ray };
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { Box3 } from './Box3.js';
|
|
2
|
+
import { Vector3 } from './Vector3.js';
|
|
3
|
+
|
|
4
|
+
const _box = /*@__PURE__*/ new Box3();
|
|
5
|
+
const _v1 = /*@__PURE__*/ new Vector3();
|
|
6
|
+
const _v2 = /*@__PURE__*/ new Vector3();
|
|
7
|
+
|
|
8
|
+
class Sphere {
|
|
9
|
+
|
|
10
|
+
constructor( center = new Vector3(), radius = - 1 ) {
|
|
11
|
+
|
|
12
|
+
this.center = center;
|
|
13
|
+
this.radius = radius;
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
set( center, radius ) {
|
|
18
|
+
|
|
19
|
+
this.center.copy( center );
|
|
20
|
+
this.radius = radius;
|
|
21
|
+
|
|
22
|
+
return this;
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
setFromPoints( points, optionalCenter ) {
|
|
27
|
+
|
|
28
|
+
const center = this.center;
|
|
29
|
+
|
|
30
|
+
if ( optionalCenter !== undefined ) {
|
|
31
|
+
|
|
32
|
+
center.copy( optionalCenter );
|
|
33
|
+
|
|
34
|
+
} else {
|
|
35
|
+
|
|
36
|
+
_box.setFromPoints( points ).getCenter( center );
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let maxRadiusSq = 0;
|
|
41
|
+
|
|
42
|
+
for ( let i = 0, il = points.length; i < il; i ++ ) {
|
|
43
|
+
|
|
44
|
+
maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
this.radius = Math.sqrt( maxRadiusSq );
|
|
49
|
+
|
|
50
|
+
return this;
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
copy( sphere ) {
|
|
55
|
+
|
|
56
|
+
this.center.copy( sphere.center );
|
|
57
|
+
this.radius = sphere.radius;
|
|
58
|
+
|
|
59
|
+
return this;
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
isEmpty() {
|
|
64
|
+
|
|
65
|
+
return ( this.radius < 0 );
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
makeEmpty() {
|
|
70
|
+
|
|
71
|
+
this.center.set( 0, 0, 0 );
|
|
72
|
+
this.radius = - 1;
|
|
73
|
+
|
|
74
|
+
return this;
|
|
75
|
+
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
containsPoint( point ) {
|
|
79
|
+
|
|
80
|
+
return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
distanceToPoint( point ) {
|
|
85
|
+
|
|
86
|
+
return ( point.distanceTo( this.center ) - this.radius );
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
intersectsSphere( sphere ) {
|
|
91
|
+
|
|
92
|
+
const radiusSum = this.radius + sphere.radius;
|
|
93
|
+
|
|
94
|
+
return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
|
|
95
|
+
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
intersectsBox( box ) {
|
|
99
|
+
|
|
100
|
+
return box.intersectsSphere( this );
|
|
101
|
+
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
intersectsPlane( plane ) {
|
|
105
|
+
|
|
106
|
+
return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
clampPoint( point, target ) {
|
|
111
|
+
|
|
112
|
+
const deltaLengthSq = this.center.distanceToSquared( point );
|
|
113
|
+
|
|
114
|
+
target.copy( point );
|
|
115
|
+
|
|
116
|
+
if ( deltaLengthSq > ( this.radius * this.radius ) ) {
|
|
117
|
+
|
|
118
|
+
target.sub( this.center ).normalize();
|
|
119
|
+
target.multiplyScalar( this.radius ).add( this.center );
|
|
120
|
+
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return target;
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
getBoundingBox( target ) {
|
|
128
|
+
|
|
129
|
+
if ( this.isEmpty() ) {
|
|
130
|
+
|
|
131
|
+
// Empty sphere produces empty bounding box
|
|
132
|
+
target.makeEmpty();
|
|
133
|
+
return target;
|
|
134
|
+
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
target.set( this.center, this.center );
|
|
138
|
+
target.expandByScalar( this.radius );
|
|
139
|
+
|
|
140
|
+
return target;
|
|
141
|
+
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
applyMatrix4( matrix ) {
|
|
145
|
+
|
|
146
|
+
this.center.applyMatrix4( matrix );
|
|
147
|
+
this.radius = this.radius * matrix.getMaxScaleOnAxis();
|
|
148
|
+
|
|
149
|
+
return this;
|
|
150
|
+
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
translate( offset ) {
|
|
154
|
+
|
|
155
|
+
this.center.add( offset );
|
|
156
|
+
|
|
157
|
+
return this;
|
|
158
|
+
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
expandByPoint( point ) {
|
|
162
|
+
|
|
163
|
+
if ( this.isEmpty() ) {
|
|
164
|
+
|
|
165
|
+
this.center.copy( point );
|
|
166
|
+
|
|
167
|
+
this.radius = 0;
|
|
168
|
+
|
|
169
|
+
return this;
|
|
170
|
+
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
_v1.subVectors( point, this.center );
|
|
174
|
+
|
|
175
|
+
const lengthSq = _v1.lengthSq();
|
|
176
|
+
|
|
177
|
+
if ( lengthSq > ( this.radius * this.radius ) ) {
|
|
178
|
+
|
|
179
|
+
// calculate the minimal sphere
|
|
180
|
+
|
|
181
|
+
const length = Math.sqrt( lengthSq );
|
|
182
|
+
|
|
183
|
+
const delta = ( length - this.radius ) * 0.5;
|
|
184
|
+
|
|
185
|
+
this.center.addScaledVector( _v1, delta / length );
|
|
186
|
+
|
|
187
|
+
this.radius += delta;
|
|
188
|
+
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return this;
|
|
192
|
+
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
union( sphere ) {
|
|
196
|
+
|
|
197
|
+
if ( sphere.isEmpty() ) {
|
|
198
|
+
|
|
199
|
+
return this;
|
|
200
|
+
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if ( this.isEmpty() ) {
|
|
204
|
+
|
|
205
|
+
this.copy( sphere );
|
|
206
|
+
|
|
207
|
+
return this;
|
|
208
|
+
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if ( this.center.equals( sphere.center ) === true ) {
|
|
212
|
+
|
|
213
|
+
this.radius = Math.max( this.radius, sphere.radius );
|
|
214
|
+
|
|
215
|
+
} else {
|
|
216
|
+
|
|
217
|
+
_v2.subVectors( sphere.center, this.center ).setLength( sphere.radius );
|
|
218
|
+
|
|
219
|
+
this.expandByPoint( _v1.copy( sphere.center ).add( _v2 ) );
|
|
220
|
+
|
|
221
|
+
this.expandByPoint( _v1.copy( sphere.center ).sub( _v2 ) );
|
|
222
|
+
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return this;
|
|
226
|
+
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
equals( sphere ) {
|
|
230
|
+
|
|
231
|
+
return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
|
|
232
|
+
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
clone() {
|
|
236
|
+
|
|
237
|
+
return new this.constructor().copy( this );
|
|
238
|
+
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export { Sphere };
|