@openglobus/og 0.11.2 → 0.11.7
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/package.json +13 -13
- package/src/og/Clock.js +10 -10
- package/src/og/Events.js +8 -6
- package/src/og/Extent.js +82 -41
- package/src/og/Globe.js +25 -13
- package/src/og/ImageCanvas.js +22 -16
- package/src/og/LonLat.js +16 -13
- package/src/og/Popup.js +21 -14
- package/src/og/QueueArray.js +6 -2
- package/src/og/Rectangle.js +11 -6
- package/src/og/Stack.js +5 -2
- package/src/og/ajax.js +21 -33
- package/src/og/astro/astro.js +5 -5
- package/src/og/astro/earth.js +22 -16
- package/src/og/astro/jd.js +23 -18
- package/src/og/astro/orbit.js +13 -11
- package/src/og/astro/rotation.js +17 -8
- package/src/og/bv/Box.js +7 -3
- package/src/og/bv/Sphere.js +14 -11
- package/src/og/camera/Camera.js +51 -54
- package/src/og/camera/Frustum.js +29 -18
- package/src/og/camera/PlanetCamera.js +32 -23
- package/src/og/control/CompassButton.js +5 -1
- package/src/og/control/Control.js +12 -10
- package/src/og/control/DebugInfo.js +4 -1
- package/src/og/control/EarthCoordinates.js +54 -33
- package/src/og/control/KeyboardNavigation.js +10 -10
- package/src/og/control/LayerSwitcher.js +22 -21
- package/src/og/control/Lighting.js +34 -3
- package/src/og/control/MouseNavigation.js +1 -1
- package/src/og/control/ScaleControl.js +1 -1
- package/src/og/control/SegmentBoundVisualization.js +6 -7
- package/src/og/control/ShowFps.js +13 -8
- package/src/og/control/SimpleNavigation.js +6 -8
- package/src/og/control/Sun.js +25 -15
- package/src/og/control/ToggleWireframe.js +4 -4
- package/src/og/control/TouchNavigation.js +44 -33
- package/src/og/control/ZoomControl.js +41 -25
- package/src/og/ellipsoid/Ellipsoid.js +162 -66
- package/src/og/ellipsoid/wgs84.js +4 -4
- package/src/og/entity/BaseBillboard.js +100 -56
- package/src/og/entity/Billboard.js +14 -10
- package/src/og/entity/BillboardHandler.js +317 -60
- package/src/og/entity/Entity.js +100 -68
- package/src/og/entity/EntityCollection.js +70 -47
- package/src/og/entity/GeoObject.js +228 -0
- package/src/og/entity/GeoObjectHandler.js +910 -0
- package/src/og/entity/Geometry.js +27 -24
- package/src/og/entity/GeometryHandler.js +596 -124
- package/src/og/entity/Label.js +80 -49
- package/src/og/entity/LabelHandler.js +45 -244
- package/src/og/entity/LabelWorker.js +218 -0
- package/src/og/entity/Object3d.js +504 -0
- package/src/og/entity/PointCloud.js +80 -32
- package/src/og/entity/PointCloudHandler.js +8 -8
- package/src/og/entity/Polyline.js +16 -16
- package/src/og/entity/Ray.js +60 -27
- package/src/og/entity/Strip.js +77 -48
- package/src/og/entity/StripHandler.js +26 -26
- package/src/og/entity/index.js +8 -16
- package/src/og/layer/BaseGeoImage.js +54 -23
- package/src/og/layer/CanvasTiles.js +24 -24
- package/src/og/layer/GeoImage.js +9 -9
- package/src/og/layer/GeoVideo.js +3 -3
- package/src/og/layer/KML.js +63 -37
- package/src/og/layer/Layer.js +44 -21
- package/src/og/layer/Material.js +23 -20
- package/src/og/layer/Vector.js +114 -68
- package/src/og/layer/WMS.js +34 -17
- package/src/og/layer/XYZ.js +48 -46
- package/src/og/light/LightSource.js +46 -39
- package/src/og/math/Mat3.js +34 -22
- package/src/og/math/Mat4.js +603 -459
- package/src/og/math/Plane.js +21 -20
- package/src/og/math/Quat.js +182 -139
- package/src/og/math/Ray.js +38 -33
- package/src/og/math/Vec2.js +85 -75
- package/src/og/math/Vec3.js +142 -112
- package/src/og/math/Vec4.js +27 -31
- package/src/og/math/coder.js +10 -10
- package/src/og/math.js +12 -12
- package/src/og/proj/EPSG3857.js +4 -4
- package/src/og/proj/EPSG4326.js +4 -4
- package/src/og/proj/Proj.js +4 -6
- package/src/og/quadTree/Node.js +8 -8
- package/src/og/renderer/Renderer.js +59 -52
- package/src/og/renderer/RendererEvents.js +50 -27
- package/src/og/scene/BaseNode.js +7 -8
- package/src/og/scene/Planet.js +102 -103
- package/src/og/scene/RenderNode.js +28 -21
- package/src/og/segment/Segment.js +26 -21
- package/src/og/segment/SegmentLonLat.js +5 -5
- package/src/og/shaders/drawnode.js +135 -142
- package/src/og/shaders/geoObject.js +211 -0
- package/src/og/shaders/pointCloud.js +41 -41
- package/src/og/shaders/shape.js +12 -18
- package/src/og/shaders/skybox.js +36 -36
- package/src/og/shaders/toneMapping.js +1 -0
- package/src/og/shapes/BaseShape.js +126 -54
- package/src/og/shapes/Icosphere.js +29 -14
- package/src/og/shapes/Sphere.js +12 -15
- package/src/og/terrain/BilTerrain.js +1 -0
- package/src/og/terrain/EmptyTerrain.js +2 -2
- package/src/og/terrain/GlobusTerrain.js +9 -9
- package/src/og/utils/FontAtlas.js +6 -2
- package/src/og/utils/TextureAtlas.js +22 -24
- package/src/og/utils/VectorTileCreator.js +1 -3
- package/src/og/utils/shared.js +16 -16
- package/src/og/webgl/Framebuffer.js +88 -40
- package/src/og/webgl/Handler.js +243 -169
- package/src/og/webgl/Multisample.js +47 -19
- package/src/og/webgl/Program.js +79 -34
- package/src/og/webgl/ProgramController.js +17 -13
- package/src/og/webgl/callbacks.js +8 -8
- package/src/og/inherits.js +0 -8
- package/src/og/utils/polylabel.js +0 -176
- package/types/Clock.d.ts +0 -90
- package/types/Deferred.d.ts +0 -6
- package/types/Events.d.ts +0 -73
- package/types/Extent.d.ts +0 -166
- package/types/Globe.d.ts +0 -75
- package/types/ImageCanvas.d.ts +0 -121
- package/types/Lock.d.ts +0 -12
- package/types/LonLat.d.ts +0 -108
- package/types/Popup.d.ts +0 -38
- package/types/QueueArray.d.ts +0 -15
- package/types/Rectangle.d.ts +0 -74
- package/types/Stack.d.ts +0 -15
- package/types/ajax.d.ts +0 -24
- package/types/arial.d.ts +0 -48
- package/types/astro/astro.d.ts +0 -38
- package/types/astro/earth.d.ts +0 -6
- package/types/astro/jd.d.ts +0 -254
- package/types/bv/Box.d.ts +0 -25
- package/types/bv/Sphere.d.ts +0 -38
- package/types/bv/index.d.ts +0 -3
- package/types/camera/Camera.d.ts +0 -303
- package/types/camera/Frustum.d.ts +0 -129
- package/types/camera/PlanetCamera.d.ts +0 -223
- package/types/camera/index.d.ts +0 -3
- package/types/cons.d.ts +0 -40
- package/types/control/CompassButton.d.ts +0 -18
- package/types/control/Control.d.ts +0 -101
- package/types/control/DebugInfo.d.ts +0 -16
- package/types/control/EarthCoordinates.d.ts +0 -47
- package/types/control/EarthNavigation.d.ts +0 -42
- package/types/control/GeoImageDragControl.d.ts +0 -6
- package/types/control/KeyboardNavigation.d.ts +0 -22
- package/types/control/LayerSwitcher.d.ts +0 -23
- package/types/control/Lighting.d.ts +0 -16
- package/types/control/MouseNavigation.d.ts +0 -51
- package/types/control/ScaleControl.d.ts +0 -22
- package/types/control/ShowFps.d.ts +0 -12
- package/types/control/SimpleNavigation.d.ts +0 -28
- package/types/control/Sun.d.ts +0 -52
- package/types/control/ToggleWireframe.d.ts +0 -12
- package/types/control/TouchNavigation.d.ts +0 -50
- package/types/control/ZoomControl.d.ts +0 -28
- package/types/control/index.d.ts +0 -17
- package/types/ellipsoid/Ellipsoid.d.ts +0 -142
- package/types/ellipsoid/index.d.ts +0 -3
- package/types/ellipsoid/wgs84.d.ts +0 -5
- package/types/entity/BaseBillboard.d.ts +0 -208
- package/types/entity/Billboard.d.ts +0 -94
- package/types/entity/BillboardHandler.d.ts +0 -74
- package/types/entity/Entity.d.ts +0 -331
- package/types/entity/EntityCollection.d.ts +0 -303
- package/types/entity/Geometry.d.ts +0 -73
- package/types/entity/GeometryHandler.d.ts +0 -76
- package/types/entity/Label.d.ts +0 -194
- package/types/entity/LabelHandler.d.ts +0 -24
- package/types/entity/PointCloud.d.ts +0 -174
- package/types/entity/PointCloudHandler.d.ts +0 -38
- package/types/entity/Polyline.d.ts +0 -304
- package/types/entity/PolylineHandler.d.ts +0 -18
- package/types/entity/Ray.d.ts +0 -123
- package/types/entity/RayHandler.d.ts +0 -67
- package/types/entity/ShapeHandler.d.ts +0 -22
- package/types/entity/Strip.d.ts +0 -118
- package/types/entity/StripHandler.d.ts +0 -38
- package/types/entity/index.d.ts +0 -8
- package/types/index.core.d.ts +0 -65
- package/types/index.d.ts +0 -45
- package/types/index.webgl.d.ts +0 -7
- package/types/inherits.d.ts +0 -4
- package/types/input/KeyboardHandler.d.ts +0 -10
- package/types/input/MouseHandler.d.ts +0 -5
- package/types/input/TouchHandler.d.ts +0 -5
- package/types/input/input.d.ts +0 -34
- package/types/layer/BaseGeoImage.d.ts +0 -107
- package/types/layer/CanvasTiles.d.ts +0 -75
- package/types/layer/GeoImage.d.ts +0 -65
- package/types/layer/GeoTexture2d.d.ts +0 -8
- package/types/layer/GeoVideo.d.ts +0 -80
- package/types/layer/KML.d.ts +0 -58
- package/types/layer/Layer.d.ts +0 -321
- package/types/layer/Material.d.ts +0 -48
- package/types/layer/Vector.d.ts +0 -228
- package/types/layer/WMS.d.ts +0 -66
- package/types/layer/XYZ.d.ts +0 -130
- package/types/layer/index.d.ts +0 -10
- package/types/light/LightSource.d.ts +0 -177
- package/types/math/Line2.d.ts +0 -11
- package/types/math/Line3.d.ts +0 -10
- package/types/math/Mat3.d.ts +0 -63
- package/types/math/Mat4.d.ts +0 -173
- package/types/math/Plane.d.ts +0 -17
- package/types/math/Quat.d.ts +0 -376
- package/types/math/Ray.d.ts +0 -81
- package/types/math/Vec2.d.ts +0 -308
- package/types/math/Vec3.d.ts +0 -459
- package/types/math/Vec4.d.ts +0 -161
- package/types/math/coder.d.ts +0 -42
- package/types/math/index.d.ts +0 -11
- package/types/math.d.ts +0 -261
- package/types/mercator.d.ts +0 -92
- package/types/proj/EPSG3857.d.ts +0 -5
- package/types/proj/EPSG4326.d.ts +0 -5
- package/types/proj/Proj.d.ts +0 -42
- package/types/quadTree/EntityCollectionNode.d.ts +0 -34
- package/types/quadTree/Node.d.ts +0 -61
- package/types/quadTree/quadTree.d.ts +0 -40
- package/types/renderer/Renderer.d.ts +0 -296
- package/types/renderer/RendererEvents.d.ts +0 -230
- package/types/res/images.d.ts +0 -3
- package/types/scene/Axes.d.ts +0 -11
- package/types/scene/BaseNode.d.ts +0 -60
- package/types/scene/Planet.d.ts +0 -574
- package/types/scene/RenderNode.d.ts +0 -143
- package/types/scene/SkyBox.d.ts +0 -10
- package/types/scene/index.d.ts +0 -4
- package/types/segment/Segment.d.ts +0 -271
- package/types/segment/SegmentLonLat.d.ts +0 -62
- package/types/segment/segmentHelper.d.ts +0 -13
- package/types/shaders/billboard.d.ts +0 -3
- package/types/shaders/depth.d.ts +0 -2
- package/types/shaders/drawnode.d.ts +0 -7
- package/types/shaders/label.d.ts +0 -4
- package/types/shaders/pointCloud.d.ts +0 -2
- package/types/shaders/polyline.d.ts +0 -3
- package/types/shaders/ray.d.ts +0 -2
- package/types/shaders/screenFrame.d.ts +0 -2
- package/types/shaders/shape.d.ts +0 -4
- package/types/shaders/skybox.d.ts +0 -2
- package/types/shaders/toneMapping.d.ts +0 -2
- package/types/shapes/BaseShape.d.ts +0 -247
- package/types/shapes/Sphere.d.ts +0 -41
- package/types/terrain/BilTerrain.d.ts +0 -8
- package/types/terrain/EmptyTerrain.d.ts +0 -72
- package/types/terrain/Geoid.d.ts +0 -26
- package/types/terrain/GlobusTerrain.d.ts +0 -153
- package/types/terrain/MapboxTerrain.d.ts +0 -8
- package/types/terrain/index.d.ts +0 -5
- package/types/utils/FontAtlas.d.ts +0 -14
- package/types/utils/GeoImageCreator.d.ts +0 -30
- package/types/utils/ImagesCacheManager.d.ts +0 -10
- package/types/utils/Loader.d.ts +0 -25
- package/types/utils/NormalMapCreator.d.ts +0 -39
- package/types/utils/PlainSegmentWorker.d.ts +0 -10
- package/types/utils/TerrainWorker.d.ts +0 -9
- package/types/utils/TextureAtlas.d.ts +0 -111
- package/types/utils/VectorTileCreator.d.ts +0 -16
- package/types/utils/colorTable.d.ts +0 -143
- package/types/utils/earcut.d.ts +0 -6
- package/types/utils/shared.d.ts +0 -230
- package/types/webgl/Framebuffer.d.ts +0 -135
- package/types/webgl/Handler.d.ts +0 -372
- package/types/webgl/Multisample.d.ts +0 -89
- package/types/webgl/Program.d.ts +0 -155
- package/types/webgl/ProgramController.d.ts +0 -84
- package/types/webgl/callbacks.d.ts +0 -1
- package/types/webgl/index.d.ts +0 -6
- package/types/webgl/types.d.ts +0 -2
package/src/og/math/Vec3.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* @module og/math/Vec3
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
"use strict";
|
|
6
6
|
|
|
7
|
-
import { Vec4 } from
|
|
8
|
-
import { Quat } from
|
|
7
|
+
import { Vec4 } from "./Vec4.js";
|
|
8
|
+
import { Quat } from "./Quat.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Class represents a 3d vector.
|
|
@@ -15,9 +15,7 @@ import { Quat } from './Quat.js';
|
|
|
15
15
|
* @param {number} [z] - Third value.
|
|
16
16
|
*/
|
|
17
17
|
export class Vec3 {
|
|
18
|
-
|
|
19
18
|
constructor(x, y, z) {
|
|
20
|
-
|
|
21
19
|
/**
|
|
22
20
|
* @public
|
|
23
21
|
* @type {number}
|
|
@@ -38,25 +36,45 @@ export class Vec3 {
|
|
|
38
36
|
}
|
|
39
37
|
|
|
40
38
|
/** @const */
|
|
41
|
-
static get UP() {
|
|
39
|
+
static get UP() {
|
|
40
|
+
return new Vec3(0, 1, 0);
|
|
41
|
+
}
|
|
42
42
|
/** @const */
|
|
43
|
-
static get DOWN() {
|
|
43
|
+
static get DOWN() {
|
|
44
|
+
return new Vec3(0, -1, 0);
|
|
45
|
+
}
|
|
44
46
|
/** @const */
|
|
45
|
-
static get RIGHT() {
|
|
47
|
+
static get RIGHT() {
|
|
48
|
+
return new Vec3(1, 0, 0);
|
|
49
|
+
}
|
|
46
50
|
/** @const */
|
|
47
|
-
static get LEFT() {
|
|
51
|
+
static get LEFT() {
|
|
52
|
+
return new Vec3(-1, 0, 0);
|
|
53
|
+
}
|
|
48
54
|
/** @const */
|
|
49
|
-
static get FORWARD() {
|
|
55
|
+
static get FORWARD() {
|
|
56
|
+
return new Vec3(0, 0, -1);
|
|
57
|
+
}
|
|
50
58
|
/** @const */
|
|
51
|
-
static get BACKWARD() {
|
|
59
|
+
static get BACKWARD() {
|
|
60
|
+
return new Vec3(0, 0, 1);
|
|
61
|
+
}
|
|
52
62
|
/** @const */
|
|
53
|
-
static get ZERO() {
|
|
63
|
+
static get ZERO() {
|
|
64
|
+
return new Vec3();
|
|
65
|
+
}
|
|
54
66
|
/** @const */
|
|
55
|
-
static get UNIT_X() {
|
|
67
|
+
static get UNIT_X() {
|
|
68
|
+
return new Vec3(1, 0, 0);
|
|
69
|
+
}
|
|
56
70
|
/** @const */
|
|
57
|
-
static get UNIT_Y() {
|
|
71
|
+
static get UNIT_Y() {
|
|
72
|
+
return new Vec3(0, 1, 0);
|
|
73
|
+
}
|
|
58
74
|
/** @const */
|
|
59
|
-
static get UNIT_Z() {
|
|
75
|
+
static get UNIT_Z() {
|
|
76
|
+
return new Vec3(0, 0, 1);
|
|
77
|
+
}
|
|
60
78
|
|
|
61
79
|
/**
|
|
62
80
|
* Separate 63 bit Vec3 to two Vec3 32 bit float values.
|
|
@@ -67,8 +85,9 @@ export class Vec3 {
|
|
|
67
85
|
* @returns {Array.<number>} Encoded array. (exactly 2 entries)
|
|
68
86
|
*/
|
|
69
87
|
static doubleToTwoFloats(v, high, low) {
|
|
70
|
-
|
|
71
|
-
|
|
88
|
+
let x = v.x,
|
|
89
|
+
y = v.y,
|
|
90
|
+
z = v.z;
|
|
72
91
|
|
|
73
92
|
if (x >= 0.0) {
|
|
74
93
|
let doubleHigh = Math.floor(x / 65536.0) * 65536.0;
|
|
@@ -110,8 +129,9 @@ export class Vec3 {
|
|
|
110
129
|
* @returns {Array.<number>} Encoded array. (exactly 2 entries)
|
|
111
130
|
*/
|
|
112
131
|
static doubleToTwoFloat32Array(v, high, low) {
|
|
113
|
-
|
|
114
|
-
|
|
132
|
+
let x = v.x,
|
|
133
|
+
y = v.y,
|
|
134
|
+
z = v.z;
|
|
115
135
|
|
|
116
136
|
if (x >= 0.0) {
|
|
117
137
|
let doubleHigh = Math.floor(x / 65536.0) * 65536.0;
|
|
@@ -148,7 +168,7 @@ export class Vec3 {
|
|
|
148
168
|
* Creates 3d vector from array.
|
|
149
169
|
* @function
|
|
150
170
|
* @param {Array.<number>} arr - Input array (exactly 3 entries)
|
|
151
|
-
* @returns {
|
|
171
|
+
* @returns {Vec3} -
|
|
152
172
|
*/
|
|
153
173
|
static fromVec(arr) {
|
|
154
174
|
return new Vec3(arr[0], arr[1], arr[2]);
|
|
@@ -157,8 +177,8 @@ export class Vec3 {
|
|
|
157
177
|
/**
|
|
158
178
|
* Gets angle between two vectors.
|
|
159
179
|
* @static
|
|
160
|
-
* @param {
|
|
161
|
-
* @param {
|
|
180
|
+
* @param {Vec3} a - First vector.
|
|
181
|
+
* @param {Vec3} b - Second vector.
|
|
162
182
|
* @returns {number} -
|
|
163
183
|
*/
|
|
164
184
|
static angle(a, b) {
|
|
@@ -168,10 +188,10 @@ export class Vec3 {
|
|
|
168
188
|
/**
|
|
169
189
|
* Returns two vectors linear interpolation.
|
|
170
190
|
* @static
|
|
171
|
-
* @param {
|
|
172
|
-
* @param {
|
|
191
|
+
* @param {Vec3} v1 - Start vector.
|
|
192
|
+
* @param {Vec3} v2 - End vector.
|
|
173
193
|
* @param {number} l - Interpolate value.
|
|
174
|
-
* @returns {
|
|
194
|
+
* @returns {Vec3} -
|
|
175
195
|
*/
|
|
176
196
|
static lerp(v1, v2, l) {
|
|
177
197
|
return Vec3(v1.x + (v2.x - v1.x) * l, v1.y + (v2.y - v1.y) * l, v1.z + (v2.z - v1.z) * l);
|
|
@@ -180,9 +200,9 @@ export class Vec3 {
|
|
|
180
200
|
/**
|
|
181
201
|
* Returns summary vector.
|
|
182
202
|
* @static
|
|
183
|
-
* @param {
|
|
184
|
-
* @param {
|
|
185
|
-
* @returns {
|
|
203
|
+
* @param {Vec3} a - First vector.
|
|
204
|
+
* @param {Vec3} b - Second vector.
|
|
205
|
+
* @returns {Vec3} - Summary vector.
|
|
186
206
|
*/
|
|
187
207
|
static add(a, b) {
|
|
188
208
|
var res = new Vec3(a.x, a.y, a.z);
|
|
@@ -193,9 +213,9 @@ export class Vec3 {
|
|
|
193
213
|
/**
|
|
194
214
|
* Returns two vectors subtraction.
|
|
195
215
|
* @static
|
|
196
|
-
* @param {
|
|
197
|
-
* @param {
|
|
198
|
-
* @returns {
|
|
216
|
+
* @param {Vec3} a - First vector.
|
|
217
|
+
* @param {Vec3} b - Second vector.
|
|
218
|
+
* @returns {Vec3} - Vectors subtraction.
|
|
199
219
|
*/
|
|
200
220
|
static sub(a, b) {
|
|
201
221
|
var res = new Vec3(a.x, a.y, a.z);
|
|
@@ -206,9 +226,9 @@ export class Vec3 {
|
|
|
206
226
|
/**
|
|
207
227
|
* Returns scaled vector.
|
|
208
228
|
* @static
|
|
209
|
-
* @param {
|
|
229
|
+
* @param {Vec3} a - Input vector.
|
|
210
230
|
* @param {number} scale - Scale value.
|
|
211
|
-
* @returns {
|
|
231
|
+
* @returns {Vec3} -
|
|
212
232
|
*/
|
|
213
233
|
static scale(a, scale) {
|
|
214
234
|
var res = new Vec3(a.x, a.y, a.z);
|
|
@@ -219,9 +239,9 @@ export class Vec3 {
|
|
|
219
239
|
/**
|
|
220
240
|
* Returns two vectors production.
|
|
221
241
|
* @static
|
|
222
|
-
* @param {
|
|
223
|
-
* @param {
|
|
224
|
-
* @returns {
|
|
242
|
+
* @param {Vec3} a - First vector.
|
|
243
|
+
* @param {Vec3} b - Second vector.
|
|
244
|
+
* @returns {Vec3} -
|
|
225
245
|
*/
|
|
226
246
|
static mul(a, b) {
|
|
227
247
|
var res = new Vec3(a.x, a.y, a.z);
|
|
@@ -232,9 +252,9 @@ export class Vec3 {
|
|
|
232
252
|
/**
|
|
233
253
|
* Returns true if two vectors are non collinear.
|
|
234
254
|
* @public
|
|
235
|
-
* @param {
|
|
236
|
-
* @param {
|
|
237
|
-
* @returns {
|
|
255
|
+
* @param {Vec3} a - First vector.
|
|
256
|
+
* @param {Vec3} b - Second vector.
|
|
257
|
+
* @returns {Vec3} -
|
|
238
258
|
*/
|
|
239
259
|
static noncollinear(a, b) {
|
|
240
260
|
return a.y * b.z - a.z * b.y || a.z * b.x - a.x * b.z || a.x * b.y - a.y * b.z;
|
|
@@ -243,10 +263,10 @@ export class Vec3 {
|
|
|
243
263
|
/**
|
|
244
264
|
* Get projection of the vector to plane where n - normal to the plane.
|
|
245
265
|
* @static
|
|
246
|
-
* @param {
|
|
247
|
-
* @param {
|
|
248
|
-
|
|
249
|
-
* @returns {
|
|
266
|
+
* @param {Vec3} b - Vector to project.
|
|
267
|
+
* @param {Vec3} n - Plane normal.
|
|
268
|
+
* @param {Vec3} [def] - Default value for non existed result.
|
|
269
|
+
* @returns {Vec3} -
|
|
250
270
|
*/
|
|
251
271
|
static proj_b_to_plane(b, n, def) {
|
|
252
272
|
var res = b.sub(n.scaleTo(n.dot(b) / n.dot(n)));
|
|
@@ -259,9 +279,9 @@ export class Vec3 {
|
|
|
259
279
|
/**
|
|
260
280
|
* Get projection of the first vector to the second.
|
|
261
281
|
* @static
|
|
262
|
-
* @param {
|
|
263
|
-
* @param {
|
|
264
|
-
* @returns {
|
|
282
|
+
* @param {Vec3} b - First vector.
|
|
283
|
+
* @param {Vec3} a - Second vector.
|
|
284
|
+
* @returns {Vec3} -
|
|
265
285
|
*/
|
|
266
286
|
static proj_b_to_a(b, a) {
|
|
267
287
|
return a.scaleTo(a.dot(b) / a.dot(a));
|
|
@@ -271,9 +291,9 @@ export class Vec3 {
|
|
|
271
291
|
* Makes vectors normalized and orthogonal to each other.
|
|
272
292
|
* Normalizes normal. Normalizes tangent and makes sure it is orthogonal to normal (that is, angle between them is 90 degrees).
|
|
273
293
|
* @static
|
|
274
|
-
* @param {
|
|
275
|
-
* @param {
|
|
276
|
-
* @returns {
|
|
294
|
+
* @param {Vec3} normal - Normal vector.
|
|
295
|
+
* @param {Vec3} tangent - Tangent vector.
|
|
296
|
+
* @returns {Vec3} -
|
|
277
297
|
*/
|
|
278
298
|
static orthoNormalize(normal, tangent) {
|
|
279
299
|
normal = normal.normal();
|
|
@@ -284,9 +304,9 @@ export class Vec3 {
|
|
|
284
304
|
/**
|
|
285
305
|
* Returns vector components division product one to another.
|
|
286
306
|
* @static
|
|
287
|
-
* @param {
|
|
288
|
-
* @param {
|
|
289
|
-
* @returns {
|
|
307
|
+
* @param {Vec3} a - First vector.
|
|
308
|
+
* @param {Vec3} b - Second vector.
|
|
309
|
+
* @returns {Vec3} -
|
|
290
310
|
*/
|
|
291
311
|
static div(a, b) {
|
|
292
312
|
var res = new Vec3(a.x, a.y, a.z);
|
|
@@ -297,7 +317,7 @@ export class Vec3 {
|
|
|
297
317
|
/**
|
|
298
318
|
* Converts to 4d vector, Fourth value is 1.0.
|
|
299
319
|
* @public
|
|
300
|
-
* @returns {
|
|
320
|
+
* @returns {Vec4} -
|
|
301
321
|
*/
|
|
302
322
|
toVec4() {
|
|
303
323
|
return new Vec4(this.x, this.y, this.z, 1.0);
|
|
@@ -306,7 +326,7 @@ export class Vec3 {
|
|
|
306
326
|
/**
|
|
307
327
|
* Returns clone vector.
|
|
308
328
|
* @public
|
|
309
|
-
* @returns {
|
|
329
|
+
* @returns {Vec3} -
|
|
310
330
|
*/
|
|
311
331
|
clone() {
|
|
312
332
|
return new Vec3(this.x, this.y, this.z);
|
|
@@ -333,8 +353,8 @@ export class Vec3 {
|
|
|
333
353
|
/**
|
|
334
354
|
* Get projection of the first vector to the second.
|
|
335
355
|
* @static
|
|
336
|
-
* @param {
|
|
337
|
-
* @returns {
|
|
356
|
+
* @param {Vec3} a - Project vector.
|
|
357
|
+
* @returns {Vec3} -
|
|
338
358
|
*/
|
|
339
359
|
projToVec(a) {
|
|
340
360
|
return a.scaleTo(a.dot(this) / a.dot(a));
|
|
@@ -343,7 +363,7 @@ export class Vec3 {
|
|
|
343
363
|
/**
|
|
344
364
|
* Compares with vector. Returns true if it equals another.
|
|
345
365
|
* @public
|
|
346
|
-
* @param {
|
|
366
|
+
* @param {Vec3} p - Vector to compare.
|
|
347
367
|
* @returns {boolean} -
|
|
348
368
|
*/
|
|
349
369
|
equal(p) {
|
|
@@ -352,8 +372,8 @@ export class Vec3 {
|
|
|
352
372
|
|
|
353
373
|
/**
|
|
354
374
|
* Copy input vector's values.
|
|
355
|
-
* @param {
|
|
356
|
-
* @returns {
|
|
375
|
+
* @param {Vec3} point3 - Vector to copy.
|
|
376
|
+
* @returns {Vec3} -
|
|
357
377
|
*/
|
|
358
378
|
copy(point3) {
|
|
359
379
|
this.x = point3.x;
|
|
@@ -383,7 +403,7 @@ export class Vec3 {
|
|
|
383
403
|
/**
|
|
384
404
|
* Converts vector's values to a quaternion object.
|
|
385
405
|
* @public
|
|
386
|
-
* @returns {
|
|
406
|
+
* @returns {Quat} -
|
|
387
407
|
*/
|
|
388
408
|
getQuat() {
|
|
389
409
|
return new Quat(this.x, this.y, this.z);
|
|
@@ -392,8 +412,8 @@ export class Vec3 {
|
|
|
392
412
|
/**
|
|
393
413
|
* Adds vector to the current.
|
|
394
414
|
* @public
|
|
395
|
-
* @param {
|
|
396
|
-
* @returns {
|
|
415
|
+
* @param {Vec3} point3 - Point to add.
|
|
416
|
+
* @returns {Vec3} -
|
|
397
417
|
*/
|
|
398
418
|
addA(point3) {
|
|
399
419
|
this.x += point3.x;
|
|
@@ -405,8 +425,8 @@ export class Vec3 {
|
|
|
405
425
|
/**
|
|
406
426
|
* Gets two vectors summarization.
|
|
407
427
|
* @public
|
|
408
|
-
* @param {
|
|
409
|
-
* @returns {
|
|
428
|
+
* @param {Vec3} point3 - Vector to add.
|
|
429
|
+
* @returns {Vec3} Returns a sum vector.
|
|
410
430
|
*/
|
|
411
431
|
add(point3) {
|
|
412
432
|
return new Vec3(this.x + point3.x, this.y + point3.y, this.z + point3.z);
|
|
@@ -415,8 +435,8 @@ export class Vec3 {
|
|
|
415
435
|
/**
|
|
416
436
|
* Subtract vector from the current.
|
|
417
437
|
* @public
|
|
418
|
-
* @param {
|
|
419
|
-
* @returns {
|
|
438
|
+
* @param {Vec3} point3 - Subtract vector.
|
|
439
|
+
* @returns {Vec3} -
|
|
420
440
|
*/
|
|
421
441
|
subA(point3) {
|
|
422
442
|
this.x -= point3.x;
|
|
@@ -428,8 +448,8 @@ export class Vec3 {
|
|
|
428
448
|
/**
|
|
429
449
|
* Gets vector subtraction.
|
|
430
450
|
* @public
|
|
431
|
-
* @param {
|
|
432
|
-
* @return {
|
|
451
|
+
* @param {Vec3} point3 - Subtract vector.
|
|
452
|
+
* @return {Vec3} Returns new instance of a subtraction
|
|
433
453
|
*/
|
|
434
454
|
sub(point3) {
|
|
435
455
|
return new Vec3(this.x - point3.x, this.y - point3.y, this.z - point3.z);
|
|
@@ -439,7 +459,7 @@ export class Vec3 {
|
|
|
439
459
|
* Scale current vector.
|
|
440
460
|
* @public
|
|
441
461
|
* @param {number} scale - Scale value.
|
|
442
|
-
* @returns {
|
|
462
|
+
* @returns {Vec3} -
|
|
443
463
|
*/
|
|
444
464
|
scale(scale) {
|
|
445
465
|
this.x *= scale;
|
|
@@ -452,7 +472,7 @@ export class Vec3 {
|
|
|
452
472
|
* Scale current vector to another instance.
|
|
453
473
|
* @public
|
|
454
474
|
* @param {number} scale - Scale value.
|
|
455
|
-
* @returns {
|
|
475
|
+
* @returns {Vec3} -
|
|
456
476
|
*/
|
|
457
477
|
scaleTo(scale) {
|
|
458
478
|
return new Vec3(this.x * scale, this.y * scale, this.z * scale);
|
|
@@ -461,8 +481,8 @@ export class Vec3 {
|
|
|
461
481
|
/**
|
|
462
482
|
* Multiply current vector object to another and store result in the current instance.
|
|
463
483
|
* @public
|
|
464
|
-
* @param {
|
|
465
|
-
* @returns {
|
|
484
|
+
* @param {Vec3} vec - Multiply vector.
|
|
485
|
+
* @returns {Vec3} -
|
|
466
486
|
*/
|
|
467
487
|
mulA(vec) {
|
|
468
488
|
this.x *= vec.x;
|
|
@@ -474,8 +494,8 @@ export class Vec3 {
|
|
|
474
494
|
/**
|
|
475
495
|
* Multiply current vector object to another and returns new vector instance.
|
|
476
496
|
* @public
|
|
477
|
-
* @param {
|
|
478
|
-
* @returns {
|
|
497
|
+
* @param {Vec3} vec - Multiply vector.
|
|
498
|
+
* @returns {Vec3} -
|
|
479
499
|
*/
|
|
480
500
|
mul(vec) {
|
|
481
501
|
return new Vec3(this.x * vec.x, this.y * vec.y, this.z * vec.z);
|
|
@@ -484,8 +504,8 @@ export class Vec3 {
|
|
|
484
504
|
/**
|
|
485
505
|
* Divide current vector's components to another. Results stores in the current vector object.
|
|
486
506
|
* @public
|
|
487
|
-
* @param {
|
|
488
|
-
* @returns {
|
|
507
|
+
* @param {Vec3} vec - Div vector.
|
|
508
|
+
* @returns {Vec3} -
|
|
489
509
|
*/
|
|
490
510
|
divA(vec) {
|
|
491
511
|
this.x /= vec.x;
|
|
@@ -497,8 +517,8 @@ export class Vec3 {
|
|
|
497
517
|
/**
|
|
498
518
|
* Divide current vector's components to another and returns new vector instance.
|
|
499
519
|
* @public
|
|
500
|
-
* @param {
|
|
501
|
-
* @returns {
|
|
520
|
+
* @param {Vec3} vec - Div vector.
|
|
521
|
+
* @returns {Vec3} -
|
|
502
522
|
*/
|
|
503
523
|
div(vec) {
|
|
504
524
|
return new Vec3(this.x / vec.x, this.y / vec.y, this.z / vec.z);
|
|
@@ -507,7 +527,7 @@ export class Vec3 {
|
|
|
507
527
|
/**
|
|
508
528
|
* Gets vectors dot production.
|
|
509
529
|
* @public
|
|
510
|
-
* @param {
|
|
530
|
+
* @param {Vec3} point3 - Another vector.
|
|
511
531
|
* @returns {number} -
|
|
512
532
|
*/
|
|
513
533
|
dot(point3) {
|
|
@@ -527,8 +547,8 @@ export class Vec3 {
|
|
|
527
547
|
/**
|
|
528
548
|
* Gets vectors cross production.
|
|
529
549
|
* @public
|
|
530
|
-
* @param {
|
|
531
|
-
* @returns {
|
|
550
|
+
* @param {Vec3} point3 - Another vector.
|
|
551
|
+
* @returns {Vec3} -
|
|
532
552
|
*/
|
|
533
553
|
cross(point3) {
|
|
534
554
|
return new Vec3(
|
|
@@ -541,7 +561,7 @@ export class Vec3 {
|
|
|
541
561
|
/**
|
|
542
562
|
* Sets vector to zero.
|
|
543
563
|
* @public
|
|
544
|
-
* @returns {
|
|
564
|
+
* @returns {Vec3} -
|
|
545
565
|
*/
|
|
546
566
|
clear() {
|
|
547
567
|
this.x = this.y = this.z = 0;
|
|
@@ -551,7 +571,7 @@ export class Vec3 {
|
|
|
551
571
|
/**
|
|
552
572
|
* Returns normalized vector.
|
|
553
573
|
* @public
|
|
554
|
-
* @returns {
|
|
574
|
+
* @returns {Vec3} -
|
|
555
575
|
*/
|
|
556
576
|
getNormal() {
|
|
557
577
|
var res = new Vec3();
|
|
@@ -570,7 +590,7 @@ export class Vec3 {
|
|
|
570
590
|
* Returns normalized vector.
|
|
571
591
|
* @deprecated
|
|
572
592
|
* @public
|
|
573
|
-
* @returns {
|
|
593
|
+
* @returns {Vec3} -
|
|
574
594
|
*/
|
|
575
595
|
normal() {
|
|
576
596
|
var res = new Vec3();
|
|
@@ -588,7 +608,7 @@ export class Vec3 {
|
|
|
588
608
|
/**
|
|
589
609
|
* Returns normalized negate vector.
|
|
590
610
|
* @public
|
|
591
|
-
* @returns {
|
|
611
|
+
* @returns {Vec3} -
|
|
592
612
|
*/
|
|
593
613
|
normalNegate() {
|
|
594
614
|
var res = new Vec3();
|
|
@@ -606,7 +626,7 @@ export class Vec3 {
|
|
|
606
626
|
/**
|
|
607
627
|
* Returns normalized negate scale vector.
|
|
608
628
|
* @public
|
|
609
|
-
* @returns {
|
|
629
|
+
* @returns {Vec3} -
|
|
610
630
|
*/
|
|
611
631
|
normalNegateScale(scale) {
|
|
612
632
|
var res = new Vec3();
|
|
@@ -624,7 +644,7 @@ export class Vec3 {
|
|
|
624
644
|
/**
|
|
625
645
|
* Returns normalized scale vector.
|
|
626
646
|
* @public
|
|
627
|
-
* @returns {
|
|
647
|
+
* @returns {Vec3} -
|
|
628
648
|
*/
|
|
629
649
|
normalScale(scale) {
|
|
630
650
|
var res = new Vec3();
|
|
@@ -642,7 +662,7 @@ export class Vec3 {
|
|
|
642
662
|
/**
|
|
643
663
|
* Normalize current vector.
|
|
644
664
|
* @public
|
|
645
|
-
* @returns {
|
|
665
|
+
* @returns {Vec3} -
|
|
646
666
|
*/
|
|
647
667
|
normalize() {
|
|
648
668
|
var length = 1.0 / this.length();
|
|
@@ -676,7 +696,7 @@ export class Vec3 {
|
|
|
676
696
|
/**
|
|
677
697
|
* Gets distance to point.
|
|
678
698
|
* @public
|
|
679
|
-
* @param {
|
|
699
|
+
* @param {Vec3} point3 - Distant point.
|
|
680
700
|
* @returns {number} -
|
|
681
701
|
*/
|
|
682
702
|
distance(point3) {
|
|
@@ -689,7 +709,7 @@ export class Vec3 {
|
|
|
689
709
|
* @param {number} x - Value X.
|
|
690
710
|
* @param {number} y - Value Y.
|
|
691
711
|
* @param {number} z - Value Z.
|
|
692
|
-
* @returns {
|
|
712
|
+
* @returns {Vec3} -
|
|
693
713
|
*/
|
|
694
714
|
set(x, y, z) {
|
|
695
715
|
this.x = x;
|
|
@@ -701,7 +721,7 @@ export class Vec3 {
|
|
|
701
721
|
/**
|
|
702
722
|
* Negate current vector.
|
|
703
723
|
* @public
|
|
704
|
-
* @returns {
|
|
724
|
+
* @returns {Vec3} -
|
|
705
725
|
*/
|
|
706
726
|
negate() {
|
|
707
727
|
this.x = -this.x;
|
|
@@ -713,7 +733,7 @@ export class Vec3 {
|
|
|
713
733
|
/**
|
|
714
734
|
* Negate current vector to another instance.
|
|
715
735
|
* @public
|
|
716
|
-
* @returns {
|
|
736
|
+
* @returns {Vec3} -
|
|
717
737
|
*/
|
|
718
738
|
negateTo() {
|
|
719
739
|
return new Vec3(-this.x, -this.y, -this.z);
|
|
@@ -722,9 +742,9 @@ export class Vec3 {
|
|
|
722
742
|
/**
|
|
723
743
|
* Gets projected point coordinates of the current vector on the ray.
|
|
724
744
|
* @public
|
|
725
|
-
* @param {
|
|
726
|
-
* @param {
|
|
727
|
-
* @returns {
|
|
745
|
+
* @param {Vec3} pos - Ray position.
|
|
746
|
+
* @param {Vec3} direction - Ray direction.
|
|
747
|
+
* @returns {Vec3} -
|
|
728
748
|
*/
|
|
729
749
|
projToRay(pos, direction) {
|
|
730
750
|
var v = Vec3.proj_b_to_a(Vec3.sub(this, pos), direction);
|
|
@@ -735,7 +755,7 @@ export class Vec3 {
|
|
|
735
755
|
/**
|
|
736
756
|
* Gets angle between two vectors.
|
|
737
757
|
* @public
|
|
738
|
-
* @param {
|
|
758
|
+
* @param {Vec3} a - Another vector.
|
|
739
759
|
* @returns {number} -
|
|
740
760
|
*/
|
|
741
761
|
angle(a) {
|
|
@@ -745,37 +765,47 @@ export class Vec3 {
|
|
|
745
765
|
/**
|
|
746
766
|
* Returns two vectors linear interpolation.
|
|
747
767
|
* @public
|
|
748
|
-
* @param {
|
|
768
|
+
* @param {Vec3} v2 - End vector.
|
|
749
769
|
* @param {number} l - Interpolate value.
|
|
750
|
-
* @returns {
|
|
770
|
+
* @returns {Vec3} -
|
|
751
771
|
*/
|
|
752
772
|
lerp(v2, l) {
|
|
753
|
-
return new Vec3(
|
|
773
|
+
return new Vec3(
|
|
774
|
+
this.x + (v2.x - this.x) * l,
|
|
775
|
+
this.y + (v2.y - this.y) * l,
|
|
776
|
+
this.z + (v2.z - this.z) * l
|
|
777
|
+
);
|
|
754
778
|
}
|
|
755
779
|
|
|
756
780
|
/**
|
|
757
781
|
* Returns vector interpolation by v(t) = v1 * t + v2 * (1 - t)
|
|
758
782
|
* @public
|
|
759
|
-
* @param {
|
|
783
|
+
* @param {Vec3} v2 - End vector.
|
|
760
784
|
* @param {number} t - Interpolate value.
|
|
761
|
-
* @returns {
|
|
785
|
+
* @returns {Vec3} -
|
|
762
786
|
*/
|
|
763
787
|
smerp(v2, t) {
|
|
764
788
|
var one_d = 1 - t;
|
|
765
|
-
return new Vec3(
|
|
789
|
+
return new Vec3(
|
|
790
|
+
this.x * t + v2.x * one_d,
|
|
791
|
+
this.y * t + v2.y * one_d,
|
|
792
|
+
this.z * t + v2.z * one_d
|
|
793
|
+
);
|
|
766
794
|
}
|
|
767
795
|
|
|
768
|
-
static get LERP_DELTA() {
|
|
796
|
+
static get LERP_DELTA() {
|
|
797
|
+
return 1e-6;
|
|
798
|
+
}
|
|
769
799
|
|
|
770
800
|
/**
|
|
771
801
|
* Spherically interpolates between two vectors.
|
|
772
|
-
* Interpolates between current and v2 vector by amount t. The difference between this and linear interpolation (aka, "lerp") is that
|
|
773
|
-
* the vectors are treated as directions rather than points in space. The direction of the returned vector is interpolated
|
|
802
|
+
* Interpolates between current and v2 vector by amount t. The difference between this and linear interpolation (aka, "lerp") is that
|
|
803
|
+
* the vectors are treated as directions rather than points in space. The direction of the returned vector is interpolated
|
|
774
804
|
* by the angle and its magnitude is interpolated between the magnitudes of from and to.
|
|
775
805
|
* @public
|
|
776
|
-
* @param {
|
|
806
|
+
* @param {Vec3} v2 -
|
|
777
807
|
* @param {number} t - The parameter t is clamped to the range [0, 1].
|
|
778
|
-
* @returns {
|
|
808
|
+
* @returns {Vec3} -
|
|
779
809
|
*/
|
|
780
810
|
slerp(v2, t) {
|
|
781
811
|
var res = new Vec3();
|
|
@@ -791,7 +821,7 @@ export class Vec3 {
|
|
|
791
821
|
var omega, sinom, scale0, scale1;
|
|
792
822
|
var cosom = this.dot(v2);
|
|
793
823
|
|
|
794
|
-
if (
|
|
824
|
+
if (1.0 - cosom > Vec3.LERP_DELTA) {
|
|
795
825
|
omega = Math.acos(cosom);
|
|
796
826
|
sinom = Math.sin(omega);
|
|
797
827
|
scale0 = Math.sin((1.0 - t) * omega) / sinom;
|
|
@@ -825,14 +855,15 @@ export class Vec3 {
|
|
|
825
855
|
return Quat.IDENTITY.clone();
|
|
826
856
|
}
|
|
827
857
|
|
|
828
|
-
if (d <
|
|
858
|
+
if (d < 1e-6 - 1.0) {
|
|
829
859
|
if (!fallbackAxis.isEqual(Vec3.ZERO)) {
|
|
830
860
|
// rotate 180 degrees about the fallback axis
|
|
831
861
|
return Quat.axisAngleToQuat(Math.PI, fallbackAxis);
|
|
832
862
|
} else {
|
|
833
863
|
// Generate an axis
|
|
834
864
|
let axis = Vec3.UNIT_X.cross(v0);
|
|
835
|
-
if (axis.isZero()) {
|
|
865
|
+
if (axis.isZero()) {
|
|
866
|
+
// pick another if colinear
|
|
836
867
|
axis = Vec3.UNIT_Y.cross(v0);
|
|
837
868
|
}
|
|
838
869
|
axis.normalize();
|
|
@@ -857,9 +888,8 @@ export class Vec3 {
|
|
|
857
888
|
* @param {number} [x] - First cvalue.
|
|
858
889
|
* @param {number} [y] - Second value.
|
|
859
890
|
* @param {number} [z] - Third value.
|
|
860
|
-
* @returns {
|
|
891
|
+
* @returns {Vec3} -
|
|
861
892
|
*/
|
|
862
893
|
export function vec3(x, y, z) {
|
|
863
894
|
return new Vec3(x, y, z);
|
|
864
895
|
}
|
|
865
|
-
|