@kitware/vtk.js 20.1.2 → 20.2.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.
- package/Common/Core/Base64.d.ts +14 -2
- package/Common/Core/Base64.js +31 -2
- package/Common/Core/Math/index.js +3 -3
- package/Common/Core/Math.d.ts +128 -128
- package/Common/Core/Math.js +1 -1
- package/Common/Core/MatrixBuilder.js +39 -41
- package/Common/DataModel/ImageData.js +12 -14
- package/Common/Transform/LandmarkTransform.js +6 -7
- package/Filters/General/PaintFilter/PaintFilter.worker.js +8 -8
- package/Filters/General/PaintFilter.js +11 -11
- package/Filters/Sources/PlaneSource.js +12 -13
- package/IO/Core/BinaryHelper.js +2 -4
- package/IO/Core/DataAccessHelper/HtmlDataAccessHelper.js +1 -1
- package/IO/Core/DataAccessHelper/HttpDataAccessHelper.js +1 -1
- package/IO/Core/DataAccessHelper/JSZipDataAccessHelper.js +2 -2
- package/IO/Core/ZipMultiDataSetReader.js +1 -1
- package/IO/Core/ZipMultiDataSetWriter.js +1 -1
- package/IO/Geometry/STLWriter.js +4 -4
- package/IO/Misc/SkyboxReader.js +1 -1
- package/IO/XML/XMLReader.js +3 -4
- package/IO/XML/XMLWriter.js +5 -6
- package/Imaging/Core/ImageReslice.js +18 -19
- package/Interaction/Manipulators/MouseCameraAxisRotateManipulator.js +27 -28
- package/Interaction/Manipulators/MouseCameraTrackballRollManipulator.js +8 -9
- package/Interaction/Manipulators/MouseCameraTrackballRotateManipulator.js +14 -15
- package/Interaction/Manipulators/MouseCameraUnicamRotateManipulator.js +12 -13
- package/Interaction/Widgets/ImageCroppingRegionsWidget.js +5 -6
- package/Interaction/Widgets/PiecewiseGaussianWidget/ComputeHistogram.worker.js +1 -1
- package/Interaction/Widgets/PiecewiseGaussianWidget.js +2 -2
- package/Interaction/Widgets/ResliceCursor/ResliceCursorRepresentation.js +8 -9
- package/Rendering/Core/Actor.js +3 -4
- package/Rendering/Core/Camera.js +81 -84
- package/Rendering/Core/CellPicker.js +2 -2
- package/Rendering/Core/CubeAxesActor.js +32 -33
- package/Rendering/Core/Follower.js +20 -21
- package/Rendering/Core/Glyph3DMapper.js +30 -32
- package/Rendering/Core/ImageMapper.js +2 -2
- package/Rendering/Core/ImageSlice.js +5 -6
- package/Rendering/Core/Picker.js +5 -6
- package/Rendering/Core/PixelSpaceCallbackMapper.js +3 -4
- package/Rendering/Core/Prop3D.js +24 -25
- package/Rendering/Core/Renderer.js +11 -12
- package/Rendering/Core/ScalarBarActor.js +32 -33
- package/Rendering/Core/Volume.js +3 -4
- package/Rendering/OpenGL/Actor.js +9 -10
- package/Rendering/OpenGL/Camera.js +8 -9
- package/Rendering/OpenGL/CellArrayBufferObject.js +6 -8
- package/Rendering/OpenGL/Glyph3DMapper.js +8 -9
- package/Rendering/OpenGL/ImageMapper.js +7 -7
- package/Rendering/OpenGL/ImageSlice.js +4 -4
- package/Rendering/OpenGL/PolyDataMapper.js +11 -13
- package/Rendering/OpenGL/RenderWindow.d.ts +37 -1
- package/Rendering/OpenGL/ShaderCache.js +1 -1
- package/Rendering/OpenGL/Skybox.js +4 -5
- package/Rendering/OpenGL/SphereMapper.js +2 -2
- package/Rendering/OpenGL/StickMapper.js +3 -4
- package/Rendering/OpenGL/SurfaceLIC/SurfaceLICInterface.js +1 -1
- package/Rendering/OpenGL/Volume.js +6 -7
- package/Rendering/OpenGL/VolumeMapper.js +47 -49
- package/Rendering/OpenGL/glsl/vtkPolyDataFS.glsl.js +1 -1
- package/Rendering/WebGPU/Actor.js +8 -8
- package/Rendering/WebGPU/Camera.js +8 -8
- package/Rendering/WebGPU/ImageMapper.js +18 -19
- package/Rendering/WebGPU/ImageSlice.js +9 -9
- package/Rendering/WebGPU/PolyDataMapper.js +3 -4
- package/Rendering/WebGPU/Renderer.js +6 -7
- package/Rendering/WebGPU/Texture.js +10 -9
- package/Rendering/WebGPU/Volume.js +3 -3
- package/Rendering/WebGPU/VolumePassFSQ.js +10 -10
- package/ThirdParty/index.js +2 -2
- package/Widgets/Manipulators/TrackballManipulator.js +5 -6
- package/Widgets/Representations/ArrowHandleRepresentation.js +10 -12
- package/Widgets/Representations/CircleContextRepresentation.js +4 -5
- package/Widgets/Representations/RectangleContextRepresentation.js +3 -3
- package/Widgets/Widgets3D/EllipseWidget/behavior.js +5 -5
- package/Widgets/Widgets3D/ImageCroppingWidget/helpers.js +6 -8
- package/Widgets/Widgets3D/PaintWidget/behavior.js +2 -2
- package/Widgets/Widgets3D/ResliceCursorWidget.js +6 -7
- package/Widgets/Widgets3D/ShapeWidget/behavior.js +10 -10
- package/Widgets/Widgets3D/SplineWidget/behavior.js +5 -5
- package/_virtual/rollup-plugin-worker-loader__module_Sources/Filters/General/PaintFilter/PaintFilter.worker.js +1 -1
- package/_virtual/rollup-plugin-worker-loader__module_Sources/Interaction/Widgets/PiecewiseGaussianWidget/ComputeHistogram.worker.js +1 -1
- package/package.json +2 -2
- package/vtk.js +2 -2
- package/_vendor/base64-js/index.js_commonjs-exports.js +0 -1
- package/_vendor/blueimp-md5/js/md5.js_commonjs-module.js +0 -3
- package/_vendor/define-properties/index.js_commonjs-proxy.js +0 -1
- package/_vendor/globalthis/implementation.browser.js_commonjs-module.js +0 -3
- package/_vendor/globalthis/implementation.browser.js_commonjs-proxy.js +0 -1
- package/_vendor/globalthis/polyfill.js_commonjs-proxy.js +0 -1
- package/_vendor/globalthis/shim.js_commonjs-proxy.js +0 -2
- package/_vendor/jszip/dist/jszip.min.js_commonjs-module.js +0 -3
- package/_vendor/object-keys/implementation.js_commonjs-proxy.js +0 -1
- package/_vendor/object-keys/index.js_commonjs-proxy.js +0 -1
- package/_vendor/object-keys/isArguments.js_commonjs-proxy.js +0 -1
- package/_vendor/seedrandom/lib/alea.js_commonjs-module.js +0 -3
- package/_vendor/seedrandom/lib/alea.js_commonjs-proxy.js +0 -1
- package/_vendor/seedrandom/lib/tychei.js_commonjs-module.js +0 -3
- package/_vendor/seedrandom/lib/tychei.js_commonjs-proxy.js +0 -1
- package/_vendor/seedrandom/lib/xor128.js_commonjs-module.js +0 -3
- package/_vendor/seedrandom/lib/xor128.js_commonjs-proxy.js +0 -1
- package/_vendor/seedrandom/lib/xor4096.js_commonjs-module.js +0 -3
- package/_vendor/seedrandom/lib/xor4096.js_commonjs-proxy.js +0 -1
- package/_vendor/seedrandom/lib/xorshift7.js_commonjs-module.js +0 -3
- package/_vendor/seedrandom/lib/xorshift7.js_commonjs-proxy.js +0 -1
- package/_vendor/seedrandom/lib/xorwow.js_commonjs-module.js +0 -3
- package/_vendor/seedrandom/lib/xorwow.js_commonjs-proxy.js +0 -1
- package/_vendor/seedrandom/seedrandom.js_commonjs-module.js +0 -3
- package/_vendor/seedrandom/seedrandom.js_commonjs-proxy.js +0 -1
- package/_vendor/webworker-promise/lib/register.js_commonjs-module.js +0 -3
- package/_vendor/webworker-promise/lib/tiny-emitter.js_commonjs-proxy.js +0 -1
- package/_vendor/webworker-promise/src/tiny-emitter.js_commonjs-proxy.js +0 -1
- package/_vendor/xmlbuilder2/lib/xmlbuilder2.min.js_commonjs-module.js +0 -3
- package/_virtual/_rollup_plugin_ignore_empty_module_placeholder_commonjs-proxy.js +0 -6
- package/_virtual/commonjsHelpers.js +0 -22
- package/_virtual/polyfill-node.buffer.js +0 -1971
- package/_virtual/polyfill-node.global.js +0 -5
- package/_virtual/rollup_plugin_ignore_empty_module_placeholder.js +0 -8
- package/vendor/base64-js/index.js +0 -72
- package/vendor/blueimp-md5/js/md5.js +0 -402
- package/vendor/d3-array/src/array.js +0 -1
- package/vendor/d3-array/src/ascending.js +0 -5
- package/vendor/d3-array/src/bin.js +0 -1
- package/vendor/d3-array/src/bisect.js +0 -10
- package/vendor/d3-array/src/bisector.js +0 -46
- package/vendor/d3-array/src/constant.js +0 -1
- package/vendor/d3-array/src/count.js +0 -1
- package/vendor/d3-array/src/cross.js +0 -1
- package/vendor/d3-array/src/cumsum.js +0 -1
- package/vendor/d3-array/src/descending.js +0 -1
- package/vendor/d3-array/src/deviation.js +0 -1
- package/vendor/d3-array/src/difference.js +0 -1
- package/vendor/d3-array/src/disjoint.js +0 -1
- package/vendor/d3-array/src/every.js +0 -1
- package/vendor/d3-array/src/extent.js +0 -1
- package/vendor/d3-array/src/filter.js +0 -1
- package/vendor/d3-array/src/fsum.js +0 -1
- package/vendor/d3-array/src/greatest.js +0 -1
- package/vendor/d3-array/src/greatestIndex.js +0 -1
- package/vendor/d3-array/src/group.js +0 -1
- package/vendor/d3-array/src/groupSort.js +0 -1
- package/vendor/d3-array/src/identity.js +0 -1
- package/vendor/d3-array/src/index.js +0 -1
- package/vendor/d3-array/src/intersection.js +0 -1
- package/vendor/d3-array/src/least.js +0 -1
- package/vendor/d3-array/src/leastIndex.js +0 -1
- package/vendor/d3-array/src/map.js +0 -1
- package/vendor/d3-array/src/max.js +0 -1
- package/vendor/d3-array/src/maxIndex.js +0 -1
- package/vendor/d3-array/src/mean.js +0 -1
- package/vendor/d3-array/src/median.js +0 -1
- package/vendor/d3-array/src/merge.js +0 -1
- package/vendor/d3-array/src/min.js +0 -1
- package/vendor/d3-array/src/minIndex.js +0 -1
- package/vendor/d3-array/src/mode.js +0 -1
- package/vendor/d3-array/src/nice.js +0 -1
- package/vendor/d3-array/src/number.js +0 -5
- package/vendor/d3-array/src/pairs.js +0 -1
- package/vendor/d3-array/src/permute.js +0 -1
- package/vendor/d3-array/src/quantile.js +0 -1
- package/vendor/d3-array/src/quickselect.js +0 -1
- package/vendor/d3-array/src/range.js +0 -1
- package/vendor/d3-array/src/reduce.js +0 -1
- package/vendor/d3-array/src/reverse.js +0 -1
- package/vendor/d3-array/src/scan.js +0 -1
- package/vendor/d3-array/src/set.js +0 -1
- package/vendor/d3-array/src/shuffle.js +0 -1
- package/vendor/d3-array/src/some.js +0 -1
- package/vendor/d3-array/src/sort.js +0 -1
- package/vendor/d3-array/src/subset.js +0 -1
- package/vendor/d3-array/src/sum.js +0 -1
- package/vendor/d3-array/src/superset.js +0 -1
- package/vendor/d3-array/src/threshold/freedmanDiaconis.js +0 -1
- package/vendor/d3-array/src/threshold/scott.js +0 -1
- package/vendor/d3-array/src/threshold/sturges.js +0 -1
- package/vendor/d3-array/src/ticks.js +0 -56
- package/vendor/d3-array/src/transpose.js +0 -1
- package/vendor/d3-array/src/union.js +0 -1
- package/vendor/d3-array/src/variance.js +0 -1
- package/vendor/d3-array/src/zip.js +0 -1
- package/vendor/d3-color/src/color.js +0 -373
- package/vendor/d3-color/src/cubehelix.js +0 -1
- package/vendor/d3-color/src/define.js +0 -12
- package/vendor/d3-color/src/index.js +0 -1
- package/vendor/d3-color/src/lab.js +0 -1
- package/vendor/d3-color/src/math.js +0 -1
- package/vendor/d3-format/src/defaultLocale.js +0 -20
- package/vendor/d3-format/src/exponent.js +0 -7
- package/vendor/d3-format/src/formatDecimal.js +0 -22
- package/vendor/d3-format/src/formatGroup.js +0 -20
- package/vendor/d3-format/src/formatNumerals.js +0 -9
- package/vendor/d3-format/src/formatPrefixAuto.js +0 -18
- package/vendor/d3-format/src/formatRounded.js +0 -13
- package/vendor/d3-format/src/formatSpecifier.js +0 -49
- package/vendor/d3-format/src/formatTrim.js +0 -13
- package/vendor/d3-format/src/formatTypes.js +0 -21
- package/vendor/d3-format/src/identity.js +0 -5
- package/vendor/d3-format/src/index.js +0 -1
- package/vendor/d3-format/src/locale.js +0 -150
- package/vendor/d3-format/src/precisionFixed.js +0 -7
- package/vendor/d3-format/src/precisionPrefix.js +0 -7
- package/vendor/d3-format/src/precisionRound.js +0 -8
- package/vendor/d3-interpolate/src/array.js +0 -19
- package/vendor/d3-interpolate/src/basis.js +0 -1
- package/vendor/d3-interpolate/src/basisClosed.js +0 -1
- package/vendor/d3-interpolate/src/color.js +0 -26
- package/vendor/d3-interpolate/src/constant.js +0 -3
- package/vendor/d3-interpolate/src/cubehelix.js +0 -1
- package/vendor/d3-interpolate/src/date.js +0 -8
- package/vendor/d3-interpolate/src/discrete.js +0 -1
- package/vendor/d3-interpolate/src/hcl.js +0 -1
- package/vendor/d3-interpolate/src/hsl.js +0 -1
- package/vendor/d3-interpolate/src/hue.js +0 -1
- package/vendor/d3-interpolate/src/index.js +0 -1
- package/vendor/d3-interpolate/src/lab.js +0 -1
- package/vendor/d3-interpolate/src/number.js +0 -7
- package/vendor/d3-interpolate/src/numberArray.js +0 -16
- package/vendor/d3-interpolate/src/object.js +0 -25
- package/vendor/d3-interpolate/src/piecewise.js +0 -1
- package/vendor/d3-interpolate/src/quantize.js +0 -1
- package/vendor/d3-interpolate/src/rgb.js +0 -26
- package/vendor/d3-interpolate/src/round.js +0 -7
- package/vendor/d3-interpolate/src/string.js +0 -66
- package/vendor/d3-interpolate/src/transform/decompose.js +0 -1
- package/vendor/d3-interpolate/src/transform/index.js +0 -1
- package/vendor/d3-interpolate/src/transform/parse.js +0 -1
- package/vendor/d3-interpolate/src/value.js +0 -24
- package/vendor/d3-interpolate/src/zoom.js +0 -1
- package/vendor/d3-scale/src/band.js +0 -1
- package/vendor/d3-scale/src/constant.js +0 -7
- package/vendor/d3-scale/src/continuous.js +0 -129
- package/vendor/d3-scale/src/diverging.js +0 -1
- package/vendor/d3-scale/src/identity.js +0 -1
- package/vendor/d3-scale/src/index.js +0 -1
- package/vendor/d3-scale/src/init.js +0 -10
- package/vendor/d3-scale/src/linear.js +0 -72
- package/vendor/d3-scale/src/log.js +0 -1
- package/vendor/d3-scale/src/nice.js +0 -1
- package/vendor/d3-scale/src/number.js +0 -5
- package/vendor/d3-scale/src/ordinal.js +0 -1
- package/vendor/d3-scale/src/pow.js +0 -1
- package/vendor/d3-scale/src/quantile.js +0 -1
- package/vendor/d3-scale/src/quantize.js +0 -1
- package/vendor/d3-scale/src/radial.js +0 -1
- package/vendor/d3-scale/src/sequential.js +0 -1
- package/vendor/d3-scale/src/sequentialQuantile.js +0 -1
- package/vendor/d3-scale/src/symlog.js +0 -1
- package/vendor/d3-scale/src/threshold.js +0 -1
- package/vendor/d3-scale/src/tickFormat.js +0 -35
- package/vendor/d3-scale/src/time.js +0 -1
- package/vendor/d3-scale/src/utcTime.js +0 -1
- package/vendor/d3-time/src/day.js +0 -1
- package/vendor/d3-time/src/duration.js +0 -1
- package/vendor/d3-time/src/hour.js +0 -1
- package/vendor/d3-time/src/index.js +0 -1
- package/vendor/d3-time/src/interval.js +0 -1
- package/vendor/d3-time/src/millisecond.js +0 -1
- package/vendor/d3-time/src/minute.js +0 -1
- package/vendor/d3-time/src/month.js +0 -1
- package/vendor/d3-time/src/second.js +0 -1
- package/vendor/d3-time/src/ticks.js +0 -1
- package/vendor/d3-time/src/utcDay.js +0 -1
- package/vendor/d3-time/src/utcHour.js +0 -1
- package/vendor/d3-time/src/utcMinute.js +0 -1
- package/vendor/d3-time/src/utcMonth.js +0 -1
- package/vendor/d3-time/src/utcWeek.js +0 -1
- package/vendor/d3-time/src/utcYear.js +0 -1
- package/vendor/d3-time/src/week.js +0 -1
- package/vendor/d3-time/src/year.js +0 -1
- package/vendor/d3-time-format/src/defaultLocale.js +0 -1
- package/vendor/d3-time-format/src/index.js +0 -1
- package/vendor/d3-time-format/src/isoFormat.js +0 -1
- package/vendor/d3-time-format/src/isoParse.js +0 -1
- package/vendor/d3-time-format/src/locale.js +0 -1
- package/vendor/define-properties/index.js +0 -60
- package/vendor/gl-matrix/esm/common.js +0 -30
- package/vendor/gl-matrix/esm/index.js +0 -1
- package/vendor/gl-matrix/esm/mat2.js +0 -1
- package/vendor/gl-matrix/esm/mat2d.js +0 -1
- package/vendor/gl-matrix/esm/mat3.js +0 -817
- package/vendor/gl-matrix/esm/mat4.js +0 -1868
- package/vendor/gl-matrix/esm/quat.js +0 -330
- package/vendor/gl-matrix/esm/quat2.js +0 -1
- package/vendor/gl-matrix/esm/vec2.js +0 -1
- package/vendor/gl-matrix/esm/vec3.js +0 -842
- package/vendor/gl-matrix/esm/vec4.js +0 -153
- package/vendor/globalthis/implementation.browser.js +0 -11
- package/vendor/globalthis/index.js +0 -25
- package/vendor/globalthis/polyfill.js +0 -14
- package/vendor/globalthis/shim.js +0 -25
- package/vendor/internmap/src/index.js +0 -1
- package/vendor/jszip/dist/jszip.min.js +0 -11
- package/vendor/object-keys/implementation.js +0 -124
- package/vendor/object-keys/index.js +0 -35
- package/vendor/object-keys/isArguments.js +0 -17
- package/vendor/pako/dist/pako.esm.mjs.js +0 -6707
- package/vendor/seedrandom/index.js +0 -77
- package/vendor/seedrandom/lib/alea.js +0 -117
- package/vendor/seedrandom/lib/tychei.js +0 -105
- package/vendor/seedrandom/lib/xor128.js +0 -84
- package/vendor/seedrandom/lib/xor4096.js +0 -150
- package/vendor/seedrandom/lib/xorshift7.js +0 -101
- package/vendor/seedrandom/lib/xorwow.js +0 -89
- package/vendor/seedrandom/seedrandom.js +0 -256
- package/vendor/webworker-promise/lib/register.js +0 -158
- package/vendor/webworker-promise/lib/tiny-emitter.js +0 -89
- package/vendor/webworker-promise/src/index.js +0 -110
- package/vendor/webworker-promise/src/tiny-emitter.js +0 -51
- package/vendor/xmlbuilder2/lib/xmlbuilder2.min.js +0 -13
|
@@ -1,842 +0,0 @@
|
|
|
1
|
-
import { A as ARRAY_TYPE, E as EPSILON, R as RANDOM } from './common.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 3 Dimensional Vector
|
|
5
|
-
* @module vec3
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Creates a new, empty vec3
|
|
10
|
-
*
|
|
11
|
-
* @returns {vec3} a new 3D vector
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
function create() {
|
|
15
|
-
var out = new ARRAY_TYPE(3);
|
|
16
|
-
|
|
17
|
-
if (ARRAY_TYPE != Float32Array) {
|
|
18
|
-
out[0] = 0;
|
|
19
|
-
out[1] = 0;
|
|
20
|
-
out[2] = 0;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return out;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Creates a new vec3 initialized with values from an existing vector
|
|
27
|
-
*
|
|
28
|
-
* @param {ReadonlyVec3} a vector to clone
|
|
29
|
-
* @returns {vec3} a new 3D vector
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
function clone(a) {
|
|
33
|
-
var out = new ARRAY_TYPE(3);
|
|
34
|
-
out[0] = a[0];
|
|
35
|
-
out[1] = a[1];
|
|
36
|
-
out[2] = a[2];
|
|
37
|
-
return out;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Calculates the length of a vec3
|
|
41
|
-
*
|
|
42
|
-
* @param {ReadonlyVec3} a vector to calculate length of
|
|
43
|
-
* @returns {Number} length of a
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
function length(a) {
|
|
47
|
-
var x = a[0];
|
|
48
|
-
var y = a[1];
|
|
49
|
-
var z = a[2];
|
|
50
|
-
return Math.hypot(x, y, z);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Creates a new vec3 initialized with the given values
|
|
54
|
-
*
|
|
55
|
-
* @param {Number} x X component
|
|
56
|
-
* @param {Number} y Y component
|
|
57
|
-
* @param {Number} z Z component
|
|
58
|
-
* @returns {vec3} a new 3D vector
|
|
59
|
-
*/
|
|
60
|
-
|
|
61
|
-
function fromValues(x, y, z) {
|
|
62
|
-
var out = new ARRAY_TYPE(3);
|
|
63
|
-
out[0] = x;
|
|
64
|
-
out[1] = y;
|
|
65
|
-
out[2] = z;
|
|
66
|
-
return out;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Copy the values from one vec3 to another
|
|
70
|
-
*
|
|
71
|
-
* @param {vec3} out the receiving vector
|
|
72
|
-
* @param {ReadonlyVec3} a the source vector
|
|
73
|
-
* @returns {vec3} out
|
|
74
|
-
*/
|
|
75
|
-
|
|
76
|
-
function copy(out, a) {
|
|
77
|
-
out[0] = a[0];
|
|
78
|
-
out[1] = a[1];
|
|
79
|
-
out[2] = a[2];
|
|
80
|
-
return out;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Set the components of a vec3 to the given values
|
|
84
|
-
*
|
|
85
|
-
* @param {vec3} out the receiving vector
|
|
86
|
-
* @param {Number} x X component
|
|
87
|
-
* @param {Number} y Y component
|
|
88
|
-
* @param {Number} z Z component
|
|
89
|
-
* @returns {vec3} out
|
|
90
|
-
*/
|
|
91
|
-
|
|
92
|
-
function set(out, x, y, z) {
|
|
93
|
-
out[0] = x;
|
|
94
|
-
out[1] = y;
|
|
95
|
-
out[2] = z;
|
|
96
|
-
return out;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Adds two vec3's
|
|
100
|
-
*
|
|
101
|
-
* @param {vec3} out the receiving vector
|
|
102
|
-
* @param {ReadonlyVec3} a the first operand
|
|
103
|
-
* @param {ReadonlyVec3} b the second operand
|
|
104
|
-
* @returns {vec3} out
|
|
105
|
-
*/
|
|
106
|
-
|
|
107
|
-
function add(out, a, b) {
|
|
108
|
-
out[0] = a[0] + b[0];
|
|
109
|
-
out[1] = a[1] + b[1];
|
|
110
|
-
out[2] = a[2] + b[2];
|
|
111
|
-
return out;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Subtracts vector b from vector a
|
|
115
|
-
*
|
|
116
|
-
* @param {vec3} out the receiving vector
|
|
117
|
-
* @param {ReadonlyVec3} a the first operand
|
|
118
|
-
* @param {ReadonlyVec3} b the second operand
|
|
119
|
-
* @returns {vec3} out
|
|
120
|
-
*/
|
|
121
|
-
|
|
122
|
-
function subtract(out, a, b) {
|
|
123
|
-
out[0] = a[0] - b[0];
|
|
124
|
-
out[1] = a[1] - b[1];
|
|
125
|
-
out[2] = a[2] - b[2];
|
|
126
|
-
return out;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Multiplies two vec3's
|
|
130
|
-
*
|
|
131
|
-
* @param {vec3} out the receiving vector
|
|
132
|
-
* @param {ReadonlyVec3} a the first operand
|
|
133
|
-
* @param {ReadonlyVec3} b the second operand
|
|
134
|
-
* @returns {vec3} out
|
|
135
|
-
*/
|
|
136
|
-
|
|
137
|
-
function multiply(out, a, b) {
|
|
138
|
-
out[0] = a[0] * b[0];
|
|
139
|
-
out[1] = a[1] * b[1];
|
|
140
|
-
out[2] = a[2] * b[2];
|
|
141
|
-
return out;
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Divides two vec3's
|
|
145
|
-
*
|
|
146
|
-
* @param {vec3} out the receiving vector
|
|
147
|
-
* @param {ReadonlyVec3} a the first operand
|
|
148
|
-
* @param {ReadonlyVec3} b the second operand
|
|
149
|
-
* @returns {vec3} out
|
|
150
|
-
*/
|
|
151
|
-
|
|
152
|
-
function divide(out, a, b) {
|
|
153
|
-
out[0] = a[0] / b[0];
|
|
154
|
-
out[1] = a[1] / b[1];
|
|
155
|
-
out[2] = a[2] / b[2];
|
|
156
|
-
return out;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Math.ceil the components of a vec3
|
|
160
|
-
*
|
|
161
|
-
* @param {vec3} out the receiving vector
|
|
162
|
-
* @param {ReadonlyVec3} a vector to ceil
|
|
163
|
-
* @returns {vec3} out
|
|
164
|
-
*/
|
|
165
|
-
|
|
166
|
-
function ceil(out, a) {
|
|
167
|
-
out[0] = Math.ceil(a[0]);
|
|
168
|
-
out[1] = Math.ceil(a[1]);
|
|
169
|
-
out[2] = Math.ceil(a[2]);
|
|
170
|
-
return out;
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Math.floor the components of a vec3
|
|
174
|
-
*
|
|
175
|
-
* @param {vec3} out the receiving vector
|
|
176
|
-
* @param {ReadonlyVec3} a vector to floor
|
|
177
|
-
* @returns {vec3} out
|
|
178
|
-
*/
|
|
179
|
-
|
|
180
|
-
function floor(out, a) {
|
|
181
|
-
out[0] = Math.floor(a[0]);
|
|
182
|
-
out[1] = Math.floor(a[1]);
|
|
183
|
-
out[2] = Math.floor(a[2]);
|
|
184
|
-
return out;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Returns the minimum of two vec3's
|
|
188
|
-
*
|
|
189
|
-
* @param {vec3} out the receiving vector
|
|
190
|
-
* @param {ReadonlyVec3} a the first operand
|
|
191
|
-
* @param {ReadonlyVec3} b the second operand
|
|
192
|
-
* @returns {vec3} out
|
|
193
|
-
*/
|
|
194
|
-
|
|
195
|
-
function min(out, a, b) {
|
|
196
|
-
out[0] = Math.min(a[0], b[0]);
|
|
197
|
-
out[1] = Math.min(a[1], b[1]);
|
|
198
|
-
out[2] = Math.min(a[2], b[2]);
|
|
199
|
-
return out;
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Returns the maximum of two vec3's
|
|
203
|
-
*
|
|
204
|
-
* @param {vec3} out the receiving vector
|
|
205
|
-
* @param {ReadonlyVec3} a the first operand
|
|
206
|
-
* @param {ReadonlyVec3} b the second operand
|
|
207
|
-
* @returns {vec3} out
|
|
208
|
-
*/
|
|
209
|
-
|
|
210
|
-
function max(out, a, b) {
|
|
211
|
-
out[0] = Math.max(a[0], b[0]);
|
|
212
|
-
out[1] = Math.max(a[1], b[1]);
|
|
213
|
-
out[2] = Math.max(a[2], b[2]);
|
|
214
|
-
return out;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Math.round the components of a vec3
|
|
218
|
-
*
|
|
219
|
-
* @param {vec3} out the receiving vector
|
|
220
|
-
* @param {ReadonlyVec3} a vector to round
|
|
221
|
-
* @returns {vec3} out
|
|
222
|
-
*/
|
|
223
|
-
|
|
224
|
-
function round(out, a) {
|
|
225
|
-
out[0] = Math.round(a[0]);
|
|
226
|
-
out[1] = Math.round(a[1]);
|
|
227
|
-
out[2] = Math.round(a[2]);
|
|
228
|
-
return out;
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Scales a vec3 by a scalar number
|
|
232
|
-
*
|
|
233
|
-
* @param {vec3} out the receiving vector
|
|
234
|
-
* @param {ReadonlyVec3} a the vector to scale
|
|
235
|
-
* @param {Number} b amount to scale the vector by
|
|
236
|
-
* @returns {vec3} out
|
|
237
|
-
*/
|
|
238
|
-
|
|
239
|
-
function scale(out, a, b) {
|
|
240
|
-
out[0] = a[0] * b;
|
|
241
|
-
out[1] = a[1] * b;
|
|
242
|
-
out[2] = a[2] * b;
|
|
243
|
-
return out;
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Adds two vec3's after scaling the second operand by a scalar value
|
|
247
|
-
*
|
|
248
|
-
* @param {vec3} out the receiving vector
|
|
249
|
-
* @param {ReadonlyVec3} a the first operand
|
|
250
|
-
* @param {ReadonlyVec3} b the second operand
|
|
251
|
-
* @param {Number} scale the amount to scale b by before adding
|
|
252
|
-
* @returns {vec3} out
|
|
253
|
-
*/
|
|
254
|
-
|
|
255
|
-
function scaleAndAdd(out, a, b, scale) {
|
|
256
|
-
out[0] = a[0] + b[0] * scale;
|
|
257
|
-
out[1] = a[1] + b[1] * scale;
|
|
258
|
-
out[2] = a[2] + b[2] * scale;
|
|
259
|
-
return out;
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Calculates the euclidian distance between two vec3's
|
|
263
|
-
*
|
|
264
|
-
* @param {ReadonlyVec3} a the first operand
|
|
265
|
-
* @param {ReadonlyVec3} b the second operand
|
|
266
|
-
* @returns {Number} distance between a and b
|
|
267
|
-
*/
|
|
268
|
-
|
|
269
|
-
function distance(a, b) {
|
|
270
|
-
var x = b[0] - a[0];
|
|
271
|
-
var y = b[1] - a[1];
|
|
272
|
-
var z = b[2] - a[2];
|
|
273
|
-
return Math.hypot(x, y, z);
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* Calculates the squared euclidian distance between two vec3's
|
|
277
|
-
*
|
|
278
|
-
* @param {ReadonlyVec3} a the first operand
|
|
279
|
-
* @param {ReadonlyVec3} b the second operand
|
|
280
|
-
* @returns {Number} squared distance between a and b
|
|
281
|
-
*/
|
|
282
|
-
|
|
283
|
-
function squaredDistance(a, b) {
|
|
284
|
-
var x = b[0] - a[0];
|
|
285
|
-
var y = b[1] - a[1];
|
|
286
|
-
var z = b[2] - a[2];
|
|
287
|
-
return x * x + y * y + z * z;
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* Calculates the squared length of a vec3
|
|
291
|
-
*
|
|
292
|
-
* @param {ReadonlyVec3} a vector to calculate squared length of
|
|
293
|
-
* @returns {Number} squared length of a
|
|
294
|
-
*/
|
|
295
|
-
|
|
296
|
-
function squaredLength(a) {
|
|
297
|
-
var x = a[0];
|
|
298
|
-
var y = a[1];
|
|
299
|
-
var z = a[2];
|
|
300
|
-
return x * x + y * y + z * z;
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Negates the components of a vec3
|
|
304
|
-
*
|
|
305
|
-
* @param {vec3} out the receiving vector
|
|
306
|
-
* @param {ReadonlyVec3} a vector to negate
|
|
307
|
-
* @returns {vec3} out
|
|
308
|
-
*/
|
|
309
|
-
|
|
310
|
-
function negate(out, a) {
|
|
311
|
-
out[0] = -a[0];
|
|
312
|
-
out[1] = -a[1];
|
|
313
|
-
out[2] = -a[2];
|
|
314
|
-
return out;
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Returns the inverse of the components of a vec3
|
|
318
|
-
*
|
|
319
|
-
* @param {vec3} out the receiving vector
|
|
320
|
-
* @param {ReadonlyVec3} a vector to invert
|
|
321
|
-
* @returns {vec3} out
|
|
322
|
-
*/
|
|
323
|
-
|
|
324
|
-
function inverse(out, a) {
|
|
325
|
-
out[0] = 1.0 / a[0];
|
|
326
|
-
out[1] = 1.0 / a[1];
|
|
327
|
-
out[2] = 1.0 / a[2];
|
|
328
|
-
return out;
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
|
-
* Normalize a vec3
|
|
332
|
-
*
|
|
333
|
-
* @param {vec3} out the receiving vector
|
|
334
|
-
* @param {ReadonlyVec3} a vector to normalize
|
|
335
|
-
* @returns {vec3} out
|
|
336
|
-
*/
|
|
337
|
-
|
|
338
|
-
function normalize(out, a) {
|
|
339
|
-
var x = a[0];
|
|
340
|
-
var y = a[1];
|
|
341
|
-
var z = a[2];
|
|
342
|
-
var len = x * x + y * y + z * z;
|
|
343
|
-
|
|
344
|
-
if (len > 0) {
|
|
345
|
-
//TODO: evaluate use of glm_invsqrt here?
|
|
346
|
-
len = 1 / Math.sqrt(len);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
out[0] = a[0] * len;
|
|
350
|
-
out[1] = a[1] * len;
|
|
351
|
-
out[2] = a[2] * len;
|
|
352
|
-
return out;
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* Calculates the dot product of two vec3's
|
|
356
|
-
*
|
|
357
|
-
* @param {ReadonlyVec3} a the first operand
|
|
358
|
-
* @param {ReadonlyVec3} b the second operand
|
|
359
|
-
* @returns {Number} dot product of a and b
|
|
360
|
-
*/
|
|
361
|
-
|
|
362
|
-
function dot(a, b) {
|
|
363
|
-
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
364
|
-
}
|
|
365
|
-
/**
|
|
366
|
-
* Computes the cross product of two vec3's
|
|
367
|
-
*
|
|
368
|
-
* @param {vec3} out the receiving vector
|
|
369
|
-
* @param {ReadonlyVec3} a the first operand
|
|
370
|
-
* @param {ReadonlyVec3} b the second operand
|
|
371
|
-
* @returns {vec3} out
|
|
372
|
-
*/
|
|
373
|
-
|
|
374
|
-
function cross(out, a, b) {
|
|
375
|
-
var ax = a[0],
|
|
376
|
-
ay = a[1],
|
|
377
|
-
az = a[2];
|
|
378
|
-
var bx = b[0],
|
|
379
|
-
by = b[1],
|
|
380
|
-
bz = b[2];
|
|
381
|
-
out[0] = ay * bz - az * by;
|
|
382
|
-
out[1] = az * bx - ax * bz;
|
|
383
|
-
out[2] = ax * by - ay * bx;
|
|
384
|
-
return out;
|
|
385
|
-
}
|
|
386
|
-
/**
|
|
387
|
-
* Performs a linear interpolation between two vec3's
|
|
388
|
-
*
|
|
389
|
-
* @param {vec3} out the receiving vector
|
|
390
|
-
* @param {ReadonlyVec3} a the first operand
|
|
391
|
-
* @param {ReadonlyVec3} b the second operand
|
|
392
|
-
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
|
|
393
|
-
* @returns {vec3} out
|
|
394
|
-
*/
|
|
395
|
-
|
|
396
|
-
function lerp(out, a, b, t) {
|
|
397
|
-
var ax = a[0];
|
|
398
|
-
var ay = a[1];
|
|
399
|
-
var az = a[2];
|
|
400
|
-
out[0] = ax + t * (b[0] - ax);
|
|
401
|
-
out[1] = ay + t * (b[1] - ay);
|
|
402
|
-
out[2] = az + t * (b[2] - az);
|
|
403
|
-
return out;
|
|
404
|
-
}
|
|
405
|
-
/**
|
|
406
|
-
* Performs a hermite interpolation with two control points
|
|
407
|
-
*
|
|
408
|
-
* @param {vec3} out the receiving vector
|
|
409
|
-
* @param {ReadonlyVec3} a the first operand
|
|
410
|
-
* @param {ReadonlyVec3} b the second operand
|
|
411
|
-
* @param {ReadonlyVec3} c the third operand
|
|
412
|
-
* @param {ReadonlyVec3} d the fourth operand
|
|
413
|
-
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
|
|
414
|
-
* @returns {vec3} out
|
|
415
|
-
*/
|
|
416
|
-
|
|
417
|
-
function hermite(out, a, b, c, d, t) {
|
|
418
|
-
var factorTimes2 = t * t;
|
|
419
|
-
var factor1 = factorTimes2 * (2 * t - 3) + 1;
|
|
420
|
-
var factor2 = factorTimes2 * (t - 2) + t;
|
|
421
|
-
var factor3 = factorTimes2 * (t - 1);
|
|
422
|
-
var factor4 = factorTimes2 * (3 - 2 * t);
|
|
423
|
-
out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;
|
|
424
|
-
out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;
|
|
425
|
-
out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;
|
|
426
|
-
return out;
|
|
427
|
-
}
|
|
428
|
-
/**
|
|
429
|
-
* Performs a bezier interpolation with two control points
|
|
430
|
-
*
|
|
431
|
-
* @param {vec3} out the receiving vector
|
|
432
|
-
* @param {ReadonlyVec3} a the first operand
|
|
433
|
-
* @param {ReadonlyVec3} b the second operand
|
|
434
|
-
* @param {ReadonlyVec3} c the third operand
|
|
435
|
-
* @param {ReadonlyVec3} d the fourth operand
|
|
436
|
-
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
|
|
437
|
-
* @returns {vec3} out
|
|
438
|
-
*/
|
|
439
|
-
|
|
440
|
-
function bezier(out, a, b, c, d, t) {
|
|
441
|
-
var inverseFactor = 1 - t;
|
|
442
|
-
var inverseFactorTimesTwo = inverseFactor * inverseFactor;
|
|
443
|
-
var factorTimes2 = t * t;
|
|
444
|
-
var factor1 = inverseFactorTimesTwo * inverseFactor;
|
|
445
|
-
var factor2 = 3 * t * inverseFactorTimesTwo;
|
|
446
|
-
var factor3 = 3 * factorTimes2 * inverseFactor;
|
|
447
|
-
var factor4 = factorTimes2 * t;
|
|
448
|
-
out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;
|
|
449
|
-
out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;
|
|
450
|
-
out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;
|
|
451
|
-
return out;
|
|
452
|
-
}
|
|
453
|
-
/**
|
|
454
|
-
* Generates a random vector with the given scale
|
|
455
|
-
*
|
|
456
|
-
* @param {vec3} out the receiving vector
|
|
457
|
-
* @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned
|
|
458
|
-
* @returns {vec3} out
|
|
459
|
-
*/
|
|
460
|
-
|
|
461
|
-
function random(out, scale) {
|
|
462
|
-
scale = scale || 1.0;
|
|
463
|
-
var r = RANDOM() * 2.0 * Math.PI;
|
|
464
|
-
var z = RANDOM() * 2.0 - 1.0;
|
|
465
|
-
var zScale = Math.sqrt(1.0 - z * z) * scale;
|
|
466
|
-
out[0] = Math.cos(r) * zScale;
|
|
467
|
-
out[1] = Math.sin(r) * zScale;
|
|
468
|
-
out[2] = z * scale;
|
|
469
|
-
return out;
|
|
470
|
-
}
|
|
471
|
-
/**
|
|
472
|
-
* Transforms the vec3 with a mat4.
|
|
473
|
-
* 4th vector component is implicitly '1'
|
|
474
|
-
*
|
|
475
|
-
* @param {vec3} out the receiving vector
|
|
476
|
-
* @param {ReadonlyVec3} a the vector to transform
|
|
477
|
-
* @param {ReadonlyMat4} m matrix to transform with
|
|
478
|
-
* @returns {vec3} out
|
|
479
|
-
*/
|
|
480
|
-
|
|
481
|
-
function transformMat4(out, a, m) {
|
|
482
|
-
var x = a[0],
|
|
483
|
-
y = a[1],
|
|
484
|
-
z = a[2];
|
|
485
|
-
var w = m[3] * x + m[7] * y + m[11] * z + m[15];
|
|
486
|
-
w = w || 1.0;
|
|
487
|
-
out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;
|
|
488
|
-
out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;
|
|
489
|
-
out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;
|
|
490
|
-
return out;
|
|
491
|
-
}
|
|
492
|
-
/**
|
|
493
|
-
* Transforms the vec3 with a mat3.
|
|
494
|
-
*
|
|
495
|
-
* @param {vec3} out the receiving vector
|
|
496
|
-
* @param {ReadonlyVec3} a the vector to transform
|
|
497
|
-
* @param {ReadonlyMat3} m the 3x3 matrix to transform with
|
|
498
|
-
* @returns {vec3} out
|
|
499
|
-
*/
|
|
500
|
-
|
|
501
|
-
function transformMat3(out, a, m) {
|
|
502
|
-
var x = a[0],
|
|
503
|
-
y = a[1],
|
|
504
|
-
z = a[2];
|
|
505
|
-
out[0] = x * m[0] + y * m[3] + z * m[6];
|
|
506
|
-
out[1] = x * m[1] + y * m[4] + z * m[7];
|
|
507
|
-
out[2] = x * m[2] + y * m[5] + z * m[8];
|
|
508
|
-
return out;
|
|
509
|
-
}
|
|
510
|
-
/**
|
|
511
|
-
* Transforms the vec3 with a quat
|
|
512
|
-
* Can also be used for dual quaternions. (Multiply it with the real part)
|
|
513
|
-
*
|
|
514
|
-
* @param {vec3} out the receiving vector
|
|
515
|
-
* @param {ReadonlyVec3} a the vector to transform
|
|
516
|
-
* @param {ReadonlyQuat} q quaternion to transform with
|
|
517
|
-
* @returns {vec3} out
|
|
518
|
-
*/
|
|
519
|
-
|
|
520
|
-
function transformQuat(out, a, q) {
|
|
521
|
-
// benchmarks: https://jsperf.com/quaternion-transform-vec3-implementations-fixed
|
|
522
|
-
var qx = q[0],
|
|
523
|
-
qy = q[1],
|
|
524
|
-
qz = q[2],
|
|
525
|
-
qw = q[3];
|
|
526
|
-
var x = a[0],
|
|
527
|
-
y = a[1],
|
|
528
|
-
z = a[2]; // var qvec = [qx, qy, qz];
|
|
529
|
-
// var uv = vec3.cross([], qvec, a);
|
|
530
|
-
|
|
531
|
-
var uvx = qy * z - qz * y,
|
|
532
|
-
uvy = qz * x - qx * z,
|
|
533
|
-
uvz = qx * y - qy * x; // var uuv = vec3.cross([], qvec, uv);
|
|
534
|
-
|
|
535
|
-
var uuvx = qy * uvz - qz * uvy,
|
|
536
|
-
uuvy = qz * uvx - qx * uvz,
|
|
537
|
-
uuvz = qx * uvy - qy * uvx; // vec3.scale(uv, uv, 2 * w);
|
|
538
|
-
|
|
539
|
-
var w2 = qw * 2;
|
|
540
|
-
uvx *= w2;
|
|
541
|
-
uvy *= w2;
|
|
542
|
-
uvz *= w2; // vec3.scale(uuv, uuv, 2);
|
|
543
|
-
|
|
544
|
-
uuvx *= 2;
|
|
545
|
-
uuvy *= 2;
|
|
546
|
-
uuvz *= 2; // return vec3.add(out, a, vec3.add(out, uv, uuv));
|
|
547
|
-
|
|
548
|
-
out[0] = x + uvx + uuvx;
|
|
549
|
-
out[1] = y + uvy + uuvy;
|
|
550
|
-
out[2] = z + uvz + uuvz;
|
|
551
|
-
return out;
|
|
552
|
-
}
|
|
553
|
-
/**
|
|
554
|
-
* Rotate a 3D vector around the x-axis
|
|
555
|
-
* @param {vec3} out The receiving vec3
|
|
556
|
-
* @param {ReadonlyVec3} a The vec3 point to rotate
|
|
557
|
-
* @param {ReadonlyVec3} b The origin of the rotation
|
|
558
|
-
* @param {Number} rad The angle of rotation in radians
|
|
559
|
-
* @returns {vec3} out
|
|
560
|
-
*/
|
|
561
|
-
|
|
562
|
-
function rotateX(out, a, b, rad) {
|
|
563
|
-
var p = [],
|
|
564
|
-
r = []; //Translate point to the origin
|
|
565
|
-
|
|
566
|
-
p[0] = a[0] - b[0];
|
|
567
|
-
p[1] = a[1] - b[1];
|
|
568
|
-
p[2] = a[2] - b[2]; //perform rotation
|
|
569
|
-
|
|
570
|
-
r[0] = p[0];
|
|
571
|
-
r[1] = p[1] * Math.cos(rad) - p[2] * Math.sin(rad);
|
|
572
|
-
r[2] = p[1] * Math.sin(rad) + p[2] * Math.cos(rad); //translate to correct position
|
|
573
|
-
|
|
574
|
-
out[0] = r[0] + b[0];
|
|
575
|
-
out[1] = r[1] + b[1];
|
|
576
|
-
out[2] = r[2] + b[2];
|
|
577
|
-
return out;
|
|
578
|
-
}
|
|
579
|
-
/**
|
|
580
|
-
* Rotate a 3D vector around the y-axis
|
|
581
|
-
* @param {vec3} out The receiving vec3
|
|
582
|
-
* @param {ReadonlyVec3} a The vec3 point to rotate
|
|
583
|
-
* @param {ReadonlyVec3} b The origin of the rotation
|
|
584
|
-
* @param {Number} rad The angle of rotation in radians
|
|
585
|
-
* @returns {vec3} out
|
|
586
|
-
*/
|
|
587
|
-
|
|
588
|
-
function rotateY(out, a, b, rad) {
|
|
589
|
-
var p = [],
|
|
590
|
-
r = []; //Translate point to the origin
|
|
591
|
-
|
|
592
|
-
p[0] = a[0] - b[0];
|
|
593
|
-
p[1] = a[1] - b[1];
|
|
594
|
-
p[2] = a[2] - b[2]; //perform rotation
|
|
595
|
-
|
|
596
|
-
r[0] = p[2] * Math.sin(rad) + p[0] * Math.cos(rad);
|
|
597
|
-
r[1] = p[1];
|
|
598
|
-
r[2] = p[2] * Math.cos(rad) - p[0] * Math.sin(rad); //translate to correct position
|
|
599
|
-
|
|
600
|
-
out[0] = r[0] + b[0];
|
|
601
|
-
out[1] = r[1] + b[1];
|
|
602
|
-
out[2] = r[2] + b[2];
|
|
603
|
-
return out;
|
|
604
|
-
}
|
|
605
|
-
/**
|
|
606
|
-
* Rotate a 3D vector around the z-axis
|
|
607
|
-
* @param {vec3} out The receiving vec3
|
|
608
|
-
* @param {ReadonlyVec3} a The vec3 point to rotate
|
|
609
|
-
* @param {ReadonlyVec3} b The origin of the rotation
|
|
610
|
-
* @param {Number} rad The angle of rotation in radians
|
|
611
|
-
* @returns {vec3} out
|
|
612
|
-
*/
|
|
613
|
-
|
|
614
|
-
function rotateZ(out, a, b, rad) {
|
|
615
|
-
var p = [],
|
|
616
|
-
r = []; //Translate point to the origin
|
|
617
|
-
|
|
618
|
-
p[0] = a[0] - b[0];
|
|
619
|
-
p[1] = a[1] - b[1];
|
|
620
|
-
p[2] = a[2] - b[2]; //perform rotation
|
|
621
|
-
|
|
622
|
-
r[0] = p[0] * Math.cos(rad) - p[1] * Math.sin(rad);
|
|
623
|
-
r[1] = p[0] * Math.sin(rad) + p[1] * Math.cos(rad);
|
|
624
|
-
r[2] = p[2]; //translate to correct position
|
|
625
|
-
|
|
626
|
-
out[0] = r[0] + b[0];
|
|
627
|
-
out[1] = r[1] + b[1];
|
|
628
|
-
out[2] = r[2] + b[2];
|
|
629
|
-
return out;
|
|
630
|
-
}
|
|
631
|
-
/**
|
|
632
|
-
* Get the angle between two 3D vectors
|
|
633
|
-
* @param {ReadonlyVec3} a The first operand
|
|
634
|
-
* @param {ReadonlyVec3} b The second operand
|
|
635
|
-
* @returns {Number} The angle in radians
|
|
636
|
-
*/
|
|
637
|
-
|
|
638
|
-
function angle(a, b) {
|
|
639
|
-
var ax = a[0],
|
|
640
|
-
ay = a[1],
|
|
641
|
-
az = a[2],
|
|
642
|
-
bx = b[0],
|
|
643
|
-
by = b[1],
|
|
644
|
-
bz = b[2],
|
|
645
|
-
mag1 = Math.sqrt(ax * ax + ay * ay + az * az),
|
|
646
|
-
mag2 = Math.sqrt(bx * bx + by * by + bz * bz),
|
|
647
|
-
mag = mag1 * mag2,
|
|
648
|
-
cosine = mag && dot(a, b) / mag;
|
|
649
|
-
return Math.acos(Math.min(Math.max(cosine, -1), 1));
|
|
650
|
-
}
|
|
651
|
-
/**
|
|
652
|
-
* Set the components of a vec3 to zero
|
|
653
|
-
*
|
|
654
|
-
* @param {vec3} out the receiving vector
|
|
655
|
-
* @returns {vec3} out
|
|
656
|
-
*/
|
|
657
|
-
|
|
658
|
-
function zero(out) {
|
|
659
|
-
out[0] = 0.0;
|
|
660
|
-
out[1] = 0.0;
|
|
661
|
-
out[2] = 0.0;
|
|
662
|
-
return out;
|
|
663
|
-
}
|
|
664
|
-
/**
|
|
665
|
-
* Returns a string representation of a vector
|
|
666
|
-
*
|
|
667
|
-
* @param {ReadonlyVec3} a vector to represent as a string
|
|
668
|
-
* @returns {String} string representation of the vector
|
|
669
|
-
*/
|
|
670
|
-
|
|
671
|
-
function str(a) {
|
|
672
|
-
return "vec3(" + a[0] + ", " + a[1] + ", " + a[2] + ")";
|
|
673
|
-
}
|
|
674
|
-
/**
|
|
675
|
-
* Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===)
|
|
676
|
-
*
|
|
677
|
-
* @param {ReadonlyVec3} a The first vector.
|
|
678
|
-
* @param {ReadonlyVec3} b The second vector.
|
|
679
|
-
* @returns {Boolean} True if the vectors are equal, false otherwise.
|
|
680
|
-
*/
|
|
681
|
-
|
|
682
|
-
function exactEquals(a, b) {
|
|
683
|
-
return a[0] === b[0] && a[1] === b[1] && a[2] === b[2];
|
|
684
|
-
}
|
|
685
|
-
/**
|
|
686
|
-
* Returns whether or not the vectors have approximately the same elements in the same position.
|
|
687
|
-
*
|
|
688
|
-
* @param {ReadonlyVec3} a The first vector.
|
|
689
|
-
* @param {ReadonlyVec3} b The second vector.
|
|
690
|
-
* @returns {Boolean} True if the vectors are equal, false otherwise.
|
|
691
|
-
*/
|
|
692
|
-
|
|
693
|
-
function equals(a, b) {
|
|
694
|
-
var a0 = a[0],
|
|
695
|
-
a1 = a[1],
|
|
696
|
-
a2 = a[2];
|
|
697
|
-
var b0 = b[0],
|
|
698
|
-
b1 = b[1],
|
|
699
|
-
b2 = b[2];
|
|
700
|
-
return Math.abs(a0 - b0) <= EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2));
|
|
701
|
-
}
|
|
702
|
-
/**
|
|
703
|
-
* Alias for {@link vec3.subtract}
|
|
704
|
-
* @function
|
|
705
|
-
*/
|
|
706
|
-
|
|
707
|
-
var sub = subtract;
|
|
708
|
-
/**
|
|
709
|
-
* Alias for {@link vec3.multiply}
|
|
710
|
-
* @function
|
|
711
|
-
*/
|
|
712
|
-
|
|
713
|
-
var mul = multiply;
|
|
714
|
-
/**
|
|
715
|
-
* Alias for {@link vec3.divide}
|
|
716
|
-
* @function
|
|
717
|
-
*/
|
|
718
|
-
|
|
719
|
-
var div = divide;
|
|
720
|
-
/**
|
|
721
|
-
* Alias for {@link vec3.distance}
|
|
722
|
-
* @function
|
|
723
|
-
*/
|
|
724
|
-
|
|
725
|
-
var dist = distance;
|
|
726
|
-
/**
|
|
727
|
-
* Alias for {@link vec3.squaredDistance}
|
|
728
|
-
* @function
|
|
729
|
-
*/
|
|
730
|
-
|
|
731
|
-
var sqrDist = squaredDistance;
|
|
732
|
-
/**
|
|
733
|
-
* Alias for {@link vec3.length}
|
|
734
|
-
* @function
|
|
735
|
-
*/
|
|
736
|
-
|
|
737
|
-
var len = length;
|
|
738
|
-
/**
|
|
739
|
-
* Alias for {@link vec3.squaredLength}
|
|
740
|
-
* @function
|
|
741
|
-
*/
|
|
742
|
-
|
|
743
|
-
var sqrLen = squaredLength;
|
|
744
|
-
/**
|
|
745
|
-
* Perform some operation over an array of vec3s.
|
|
746
|
-
*
|
|
747
|
-
* @param {Array} a the array of vectors to iterate over
|
|
748
|
-
* @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed
|
|
749
|
-
* @param {Number} offset Number of elements to skip at the beginning of the array
|
|
750
|
-
* @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array
|
|
751
|
-
* @param {Function} fn Function to call for each vector in the array
|
|
752
|
-
* @param {Object} [arg] additional argument to pass to fn
|
|
753
|
-
* @returns {Array} a
|
|
754
|
-
* @function
|
|
755
|
-
*/
|
|
756
|
-
|
|
757
|
-
var forEach = function () {
|
|
758
|
-
var vec = create();
|
|
759
|
-
return function (a, stride, offset, count, fn, arg) {
|
|
760
|
-
var i, l;
|
|
761
|
-
|
|
762
|
-
if (!stride) {
|
|
763
|
-
stride = 3;
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
if (!offset) {
|
|
767
|
-
offset = 0;
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
if (count) {
|
|
771
|
-
l = Math.min(count * stride + offset, a.length);
|
|
772
|
-
} else {
|
|
773
|
-
l = a.length;
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
for (i = offset; i < l; i += stride) {
|
|
777
|
-
vec[0] = a[i];
|
|
778
|
-
vec[1] = a[i + 1];
|
|
779
|
-
vec[2] = a[i + 2];
|
|
780
|
-
fn(vec, vec, arg);
|
|
781
|
-
a[i] = vec[0];
|
|
782
|
-
a[i + 1] = vec[1];
|
|
783
|
-
a[i + 2] = vec[2];
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
return a;
|
|
787
|
-
};
|
|
788
|
-
}();
|
|
789
|
-
|
|
790
|
-
var vec3 = /*#__PURE__*/Object.freeze({
|
|
791
|
-
__proto__: null,
|
|
792
|
-
create: create,
|
|
793
|
-
clone: clone,
|
|
794
|
-
length: length,
|
|
795
|
-
fromValues: fromValues,
|
|
796
|
-
copy: copy,
|
|
797
|
-
set: set,
|
|
798
|
-
add: add,
|
|
799
|
-
subtract: subtract,
|
|
800
|
-
multiply: multiply,
|
|
801
|
-
divide: divide,
|
|
802
|
-
ceil: ceil,
|
|
803
|
-
floor: floor,
|
|
804
|
-
min: min,
|
|
805
|
-
max: max,
|
|
806
|
-
round: round,
|
|
807
|
-
scale: scale,
|
|
808
|
-
scaleAndAdd: scaleAndAdd,
|
|
809
|
-
distance: distance,
|
|
810
|
-
squaredDistance: squaredDistance,
|
|
811
|
-
squaredLength: squaredLength,
|
|
812
|
-
negate: negate,
|
|
813
|
-
inverse: inverse,
|
|
814
|
-
normalize: normalize,
|
|
815
|
-
dot: dot,
|
|
816
|
-
cross: cross,
|
|
817
|
-
lerp: lerp,
|
|
818
|
-
hermite: hermite,
|
|
819
|
-
bezier: bezier,
|
|
820
|
-
random: random,
|
|
821
|
-
transformMat4: transformMat4,
|
|
822
|
-
transformMat3: transformMat3,
|
|
823
|
-
transformQuat: transformQuat,
|
|
824
|
-
rotateX: rotateX,
|
|
825
|
-
rotateY: rotateY,
|
|
826
|
-
rotateZ: rotateZ,
|
|
827
|
-
angle: angle,
|
|
828
|
-
zero: zero,
|
|
829
|
-
str: str,
|
|
830
|
-
exactEquals: exactEquals,
|
|
831
|
-
equals: equals,
|
|
832
|
-
sub: sub,
|
|
833
|
-
mul: mul,
|
|
834
|
-
div: div,
|
|
835
|
-
dist: dist,
|
|
836
|
-
sqrDist: sqrDist,
|
|
837
|
-
len: len,
|
|
838
|
-
sqrLen: sqrLen,
|
|
839
|
-
forEach: forEach
|
|
840
|
-
});
|
|
841
|
-
|
|
842
|
-
export { subtract as a, scale as b, cross as c, dot as d, scaleAndAdd as e, negate as f, exactEquals as g, distance as h, copy as i, add as j, equals as k, length as l, inverse as m, normalize as n, divide as o, transformMat3 as p, sub as q, len as r, set as s, transformMat4 as t, create as u, vec3 as v, transformQuat as w, squaredDistance as x, fromValues as y };
|