@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.
Files changed (309) hide show
  1. package/Common/Core/Base64.d.ts +14 -2
  2. package/Common/Core/Base64.js +31 -2
  3. package/Common/Core/Math/index.js +3 -3
  4. package/Common/Core/Math.d.ts +128 -128
  5. package/Common/Core/Math.js +1 -1
  6. package/Common/Core/MatrixBuilder.js +39 -41
  7. package/Common/DataModel/ImageData.js +12 -14
  8. package/Common/Transform/LandmarkTransform.js +6 -7
  9. package/Filters/General/PaintFilter/PaintFilter.worker.js +8 -8
  10. package/Filters/General/PaintFilter.js +11 -11
  11. package/Filters/Sources/PlaneSource.js +12 -13
  12. package/IO/Core/BinaryHelper.js +2 -4
  13. package/IO/Core/DataAccessHelper/HtmlDataAccessHelper.js +1 -1
  14. package/IO/Core/DataAccessHelper/HttpDataAccessHelper.js +1 -1
  15. package/IO/Core/DataAccessHelper/JSZipDataAccessHelper.js +2 -2
  16. package/IO/Core/ZipMultiDataSetReader.js +1 -1
  17. package/IO/Core/ZipMultiDataSetWriter.js +1 -1
  18. package/IO/Geometry/STLWriter.js +4 -4
  19. package/IO/Misc/SkyboxReader.js +1 -1
  20. package/IO/XML/XMLReader.js +3 -4
  21. package/IO/XML/XMLWriter.js +5 -6
  22. package/Imaging/Core/ImageReslice.js +18 -19
  23. package/Interaction/Manipulators/MouseCameraAxisRotateManipulator.js +27 -28
  24. package/Interaction/Manipulators/MouseCameraTrackballRollManipulator.js +8 -9
  25. package/Interaction/Manipulators/MouseCameraTrackballRotateManipulator.js +14 -15
  26. package/Interaction/Manipulators/MouseCameraUnicamRotateManipulator.js +12 -13
  27. package/Interaction/Widgets/ImageCroppingRegionsWidget.js +5 -6
  28. package/Interaction/Widgets/PiecewiseGaussianWidget/ComputeHistogram.worker.js +1 -1
  29. package/Interaction/Widgets/PiecewiseGaussianWidget.js +2 -2
  30. package/Interaction/Widgets/ResliceCursor/ResliceCursorRepresentation.js +8 -9
  31. package/Rendering/Core/Actor.js +3 -4
  32. package/Rendering/Core/Camera.js +81 -84
  33. package/Rendering/Core/CellPicker.js +2 -2
  34. package/Rendering/Core/CubeAxesActor.js +32 -33
  35. package/Rendering/Core/Follower.js +20 -21
  36. package/Rendering/Core/Glyph3DMapper.js +30 -32
  37. package/Rendering/Core/ImageMapper.js +2 -2
  38. package/Rendering/Core/ImageSlice.js +5 -6
  39. package/Rendering/Core/Picker.js +5 -6
  40. package/Rendering/Core/PixelSpaceCallbackMapper.js +3 -4
  41. package/Rendering/Core/Prop3D.js +24 -25
  42. package/Rendering/Core/Renderer.js +11 -12
  43. package/Rendering/Core/ScalarBarActor.js +32 -33
  44. package/Rendering/Core/Volume.js +3 -4
  45. package/Rendering/OpenGL/Actor.js +9 -10
  46. package/Rendering/OpenGL/Camera.js +8 -9
  47. package/Rendering/OpenGL/CellArrayBufferObject.js +6 -8
  48. package/Rendering/OpenGL/Glyph3DMapper.js +8 -9
  49. package/Rendering/OpenGL/ImageMapper.js +7 -7
  50. package/Rendering/OpenGL/ImageSlice.js +4 -4
  51. package/Rendering/OpenGL/PolyDataMapper.js +11 -13
  52. package/Rendering/OpenGL/RenderWindow.d.ts +37 -1
  53. package/Rendering/OpenGL/ShaderCache.js +1 -1
  54. package/Rendering/OpenGL/Skybox.js +4 -5
  55. package/Rendering/OpenGL/SphereMapper.js +2 -2
  56. package/Rendering/OpenGL/StickMapper.js +3 -4
  57. package/Rendering/OpenGL/SurfaceLIC/SurfaceLICInterface.js +1 -1
  58. package/Rendering/OpenGL/Volume.js +6 -7
  59. package/Rendering/OpenGL/VolumeMapper.js +47 -49
  60. package/Rendering/OpenGL/glsl/vtkPolyDataFS.glsl.js +1 -1
  61. package/Rendering/WebGPU/Actor.js +8 -8
  62. package/Rendering/WebGPU/Camera.js +8 -8
  63. package/Rendering/WebGPU/ImageMapper.js +18 -19
  64. package/Rendering/WebGPU/ImageSlice.js +9 -9
  65. package/Rendering/WebGPU/PolyDataMapper.js +3 -4
  66. package/Rendering/WebGPU/Renderer.js +6 -7
  67. package/Rendering/WebGPU/Texture.js +10 -9
  68. package/Rendering/WebGPU/Volume.js +3 -3
  69. package/Rendering/WebGPU/VolumePassFSQ.js +10 -10
  70. package/ThirdParty/index.js +2 -2
  71. package/Widgets/Manipulators/TrackballManipulator.js +5 -6
  72. package/Widgets/Representations/ArrowHandleRepresentation.js +10 -12
  73. package/Widgets/Representations/CircleContextRepresentation.js +4 -5
  74. package/Widgets/Representations/RectangleContextRepresentation.js +3 -3
  75. package/Widgets/Widgets3D/EllipseWidget/behavior.js +5 -5
  76. package/Widgets/Widgets3D/ImageCroppingWidget/helpers.js +6 -8
  77. package/Widgets/Widgets3D/PaintWidget/behavior.js +2 -2
  78. package/Widgets/Widgets3D/ResliceCursorWidget.js +6 -7
  79. package/Widgets/Widgets3D/ShapeWidget/behavior.js +10 -10
  80. package/Widgets/Widgets3D/SplineWidget/behavior.js +5 -5
  81. package/_virtual/rollup-plugin-worker-loader__module_Sources/Filters/General/PaintFilter/PaintFilter.worker.js +1 -1
  82. package/_virtual/rollup-plugin-worker-loader__module_Sources/Interaction/Widgets/PiecewiseGaussianWidget/ComputeHistogram.worker.js +1 -1
  83. package/package.json +2 -2
  84. package/vtk.js +2 -2
  85. package/_vendor/base64-js/index.js_commonjs-exports.js +0 -1
  86. package/_vendor/blueimp-md5/js/md5.js_commonjs-module.js +0 -3
  87. package/_vendor/define-properties/index.js_commonjs-proxy.js +0 -1
  88. package/_vendor/globalthis/implementation.browser.js_commonjs-module.js +0 -3
  89. package/_vendor/globalthis/implementation.browser.js_commonjs-proxy.js +0 -1
  90. package/_vendor/globalthis/polyfill.js_commonjs-proxy.js +0 -1
  91. package/_vendor/globalthis/shim.js_commonjs-proxy.js +0 -2
  92. package/_vendor/jszip/dist/jszip.min.js_commonjs-module.js +0 -3
  93. package/_vendor/object-keys/implementation.js_commonjs-proxy.js +0 -1
  94. package/_vendor/object-keys/index.js_commonjs-proxy.js +0 -1
  95. package/_vendor/object-keys/isArguments.js_commonjs-proxy.js +0 -1
  96. package/_vendor/seedrandom/lib/alea.js_commonjs-module.js +0 -3
  97. package/_vendor/seedrandom/lib/alea.js_commonjs-proxy.js +0 -1
  98. package/_vendor/seedrandom/lib/tychei.js_commonjs-module.js +0 -3
  99. package/_vendor/seedrandom/lib/tychei.js_commonjs-proxy.js +0 -1
  100. package/_vendor/seedrandom/lib/xor128.js_commonjs-module.js +0 -3
  101. package/_vendor/seedrandom/lib/xor128.js_commonjs-proxy.js +0 -1
  102. package/_vendor/seedrandom/lib/xor4096.js_commonjs-module.js +0 -3
  103. package/_vendor/seedrandom/lib/xor4096.js_commonjs-proxy.js +0 -1
  104. package/_vendor/seedrandom/lib/xorshift7.js_commonjs-module.js +0 -3
  105. package/_vendor/seedrandom/lib/xorshift7.js_commonjs-proxy.js +0 -1
  106. package/_vendor/seedrandom/lib/xorwow.js_commonjs-module.js +0 -3
  107. package/_vendor/seedrandom/lib/xorwow.js_commonjs-proxy.js +0 -1
  108. package/_vendor/seedrandom/seedrandom.js_commonjs-module.js +0 -3
  109. package/_vendor/seedrandom/seedrandom.js_commonjs-proxy.js +0 -1
  110. package/_vendor/webworker-promise/lib/register.js_commonjs-module.js +0 -3
  111. package/_vendor/webworker-promise/lib/tiny-emitter.js_commonjs-proxy.js +0 -1
  112. package/_vendor/webworker-promise/src/tiny-emitter.js_commonjs-proxy.js +0 -1
  113. package/_vendor/xmlbuilder2/lib/xmlbuilder2.min.js_commonjs-module.js +0 -3
  114. package/_virtual/_rollup_plugin_ignore_empty_module_placeholder_commonjs-proxy.js +0 -6
  115. package/_virtual/commonjsHelpers.js +0 -22
  116. package/_virtual/polyfill-node.buffer.js +0 -1971
  117. package/_virtual/polyfill-node.global.js +0 -5
  118. package/_virtual/rollup_plugin_ignore_empty_module_placeholder.js +0 -8
  119. package/vendor/base64-js/index.js +0 -72
  120. package/vendor/blueimp-md5/js/md5.js +0 -402
  121. package/vendor/d3-array/src/array.js +0 -1
  122. package/vendor/d3-array/src/ascending.js +0 -5
  123. package/vendor/d3-array/src/bin.js +0 -1
  124. package/vendor/d3-array/src/bisect.js +0 -10
  125. package/vendor/d3-array/src/bisector.js +0 -46
  126. package/vendor/d3-array/src/constant.js +0 -1
  127. package/vendor/d3-array/src/count.js +0 -1
  128. package/vendor/d3-array/src/cross.js +0 -1
  129. package/vendor/d3-array/src/cumsum.js +0 -1
  130. package/vendor/d3-array/src/descending.js +0 -1
  131. package/vendor/d3-array/src/deviation.js +0 -1
  132. package/vendor/d3-array/src/difference.js +0 -1
  133. package/vendor/d3-array/src/disjoint.js +0 -1
  134. package/vendor/d3-array/src/every.js +0 -1
  135. package/vendor/d3-array/src/extent.js +0 -1
  136. package/vendor/d3-array/src/filter.js +0 -1
  137. package/vendor/d3-array/src/fsum.js +0 -1
  138. package/vendor/d3-array/src/greatest.js +0 -1
  139. package/vendor/d3-array/src/greatestIndex.js +0 -1
  140. package/vendor/d3-array/src/group.js +0 -1
  141. package/vendor/d3-array/src/groupSort.js +0 -1
  142. package/vendor/d3-array/src/identity.js +0 -1
  143. package/vendor/d3-array/src/index.js +0 -1
  144. package/vendor/d3-array/src/intersection.js +0 -1
  145. package/vendor/d3-array/src/least.js +0 -1
  146. package/vendor/d3-array/src/leastIndex.js +0 -1
  147. package/vendor/d3-array/src/map.js +0 -1
  148. package/vendor/d3-array/src/max.js +0 -1
  149. package/vendor/d3-array/src/maxIndex.js +0 -1
  150. package/vendor/d3-array/src/mean.js +0 -1
  151. package/vendor/d3-array/src/median.js +0 -1
  152. package/vendor/d3-array/src/merge.js +0 -1
  153. package/vendor/d3-array/src/min.js +0 -1
  154. package/vendor/d3-array/src/minIndex.js +0 -1
  155. package/vendor/d3-array/src/mode.js +0 -1
  156. package/vendor/d3-array/src/nice.js +0 -1
  157. package/vendor/d3-array/src/number.js +0 -5
  158. package/vendor/d3-array/src/pairs.js +0 -1
  159. package/vendor/d3-array/src/permute.js +0 -1
  160. package/vendor/d3-array/src/quantile.js +0 -1
  161. package/vendor/d3-array/src/quickselect.js +0 -1
  162. package/vendor/d3-array/src/range.js +0 -1
  163. package/vendor/d3-array/src/reduce.js +0 -1
  164. package/vendor/d3-array/src/reverse.js +0 -1
  165. package/vendor/d3-array/src/scan.js +0 -1
  166. package/vendor/d3-array/src/set.js +0 -1
  167. package/vendor/d3-array/src/shuffle.js +0 -1
  168. package/vendor/d3-array/src/some.js +0 -1
  169. package/vendor/d3-array/src/sort.js +0 -1
  170. package/vendor/d3-array/src/subset.js +0 -1
  171. package/vendor/d3-array/src/sum.js +0 -1
  172. package/vendor/d3-array/src/superset.js +0 -1
  173. package/vendor/d3-array/src/threshold/freedmanDiaconis.js +0 -1
  174. package/vendor/d3-array/src/threshold/scott.js +0 -1
  175. package/vendor/d3-array/src/threshold/sturges.js +0 -1
  176. package/vendor/d3-array/src/ticks.js +0 -56
  177. package/vendor/d3-array/src/transpose.js +0 -1
  178. package/vendor/d3-array/src/union.js +0 -1
  179. package/vendor/d3-array/src/variance.js +0 -1
  180. package/vendor/d3-array/src/zip.js +0 -1
  181. package/vendor/d3-color/src/color.js +0 -373
  182. package/vendor/d3-color/src/cubehelix.js +0 -1
  183. package/vendor/d3-color/src/define.js +0 -12
  184. package/vendor/d3-color/src/index.js +0 -1
  185. package/vendor/d3-color/src/lab.js +0 -1
  186. package/vendor/d3-color/src/math.js +0 -1
  187. package/vendor/d3-format/src/defaultLocale.js +0 -20
  188. package/vendor/d3-format/src/exponent.js +0 -7
  189. package/vendor/d3-format/src/formatDecimal.js +0 -22
  190. package/vendor/d3-format/src/formatGroup.js +0 -20
  191. package/vendor/d3-format/src/formatNumerals.js +0 -9
  192. package/vendor/d3-format/src/formatPrefixAuto.js +0 -18
  193. package/vendor/d3-format/src/formatRounded.js +0 -13
  194. package/vendor/d3-format/src/formatSpecifier.js +0 -49
  195. package/vendor/d3-format/src/formatTrim.js +0 -13
  196. package/vendor/d3-format/src/formatTypes.js +0 -21
  197. package/vendor/d3-format/src/identity.js +0 -5
  198. package/vendor/d3-format/src/index.js +0 -1
  199. package/vendor/d3-format/src/locale.js +0 -150
  200. package/vendor/d3-format/src/precisionFixed.js +0 -7
  201. package/vendor/d3-format/src/precisionPrefix.js +0 -7
  202. package/vendor/d3-format/src/precisionRound.js +0 -8
  203. package/vendor/d3-interpolate/src/array.js +0 -19
  204. package/vendor/d3-interpolate/src/basis.js +0 -1
  205. package/vendor/d3-interpolate/src/basisClosed.js +0 -1
  206. package/vendor/d3-interpolate/src/color.js +0 -26
  207. package/vendor/d3-interpolate/src/constant.js +0 -3
  208. package/vendor/d3-interpolate/src/cubehelix.js +0 -1
  209. package/vendor/d3-interpolate/src/date.js +0 -8
  210. package/vendor/d3-interpolate/src/discrete.js +0 -1
  211. package/vendor/d3-interpolate/src/hcl.js +0 -1
  212. package/vendor/d3-interpolate/src/hsl.js +0 -1
  213. package/vendor/d3-interpolate/src/hue.js +0 -1
  214. package/vendor/d3-interpolate/src/index.js +0 -1
  215. package/vendor/d3-interpolate/src/lab.js +0 -1
  216. package/vendor/d3-interpolate/src/number.js +0 -7
  217. package/vendor/d3-interpolate/src/numberArray.js +0 -16
  218. package/vendor/d3-interpolate/src/object.js +0 -25
  219. package/vendor/d3-interpolate/src/piecewise.js +0 -1
  220. package/vendor/d3-interpolate/src/quantize.js +0 -1
  221. package/vendor/d3-interpolate/src/rgb.js +0 -26
  222. package/vendor/d3-interpolate/src/round.js +0 -7
  223. package/vendor/d3-interpolate/src/string.js +0 -66
  224. package/vendor/d3-interpolate/src/transform/decompose.js +0 -1
  225. package/vendor/d3-interpolate/src/transform/index.js +0 -1
  226. package/vendor/d3-interpolate/src/transform/parse.js +0 -1
  227. package/vendor/d3-interpolate/src/value.js +0 -24
  228. package/vendor/d3-interpolate/src/zoom.js +0 -1
  229. package/vendor/d3-scale/src/band.js +0 -1
  230. package/vendor/d3-scale/src/constant.js +0 -7
  231. package/vendor/d3-scale/src/continuous.js +0 -129
  232. package/vendor/d3-scale/src/diverging.js +0 -1
  233. package/vendor/d3-scale/src/identity.js +0 -1
  234. package/vendor/d3-scale/src/index.js +0 -1
  235. package/vendor/d3-scale/src/init.js +0 -10
  236. package/vendor/d3-scale/src/linear.js +0 -72
  237. package/vendor/d3-scale/src/log.js +0 -1
  238. package/vendor/d3-scale/src/nice.js +0 -1
  239. package/vendor/d3-scale/src/number.js +0 -5
  240. package/vendor/d3-scale/src/ordinal.js +0 -1
  241. package/vendor/d3-scale/src/pow.js +0 -1
  242. package/vendor/d3-scale/src/quantile.js +0 -1
  243. package/vendor/d3-scale/src/quantize.js +0 -1
  244. package/vendor/d3-scale/src/radial.js +0 -1
  245. package/vendor/d3-scale/src/sequential.js +0 -1
  246. package/vendor/d3-scale/src/sequentialQuantile.js +0 -1
  247. package/vendor/d3-scale/src/symlog.js +0 -1
  248. package/vendor/d3-scale/src/threshold.js +0 -1
  249. package/vendor/d3-scale/src/tickFormat.js +0 -35
  250. package/vendor/d3-scale/src/time.js +0 -1
  251. package/vendor/d3-scale/src/utcTime.js +0 -1
  252. package/vendor/d3-time/src/day.js +0 -1
  253. package/vendor/d3-time/src/duration.js +0 -1
  254. package/vendor/d3-time/src/hour.js +0 -1
  255. package/vendor/d3-time/src/index.js +0 -1
  256. package/vendor/d3-time/src/interval.js +0 -1
  257. package/vendor/d3-time/src/millisecond.js +0 -1
  258. package/vendor/d3-time/src/minute.js +0 -1
  259. package/vendor/d3-time/src/month.js +0 -1
  260. package/vendor/d3-time/src/second.js +0 -1
  261. package/vendor/d3-time/src/ticks.js +0 -1
  262. package/vendor/d3-time/src/utcDay.js +0 -1
  263. package/vendor/d3-time/src/utcHour.js +0 -1
  264. package/vendor/d3-time/src/utcMinute.js +0 -1
  265. package/vendor/d3-time/src/utcMonth.js +0 -1
  266. package/vendor/d3-time/src/utcWeek.js +0 -1
  267. package/vendor/d3-time/src/utcYear.js +0 -1
  268. package/vendor/d3-time/src/week.js +0 -1
  269. package/vendor/d3-time/src/year.js +0 -1
  270. package/vendor/d3-time-format/src/defaultLocale.js +0 -1
  271. package/vendor/d3-time-format/src/index.js +0 -1
  272. package/vendor/d3-time-format/src/isoFormat.js +0 -1
  273. package/vendor/d3-time-format/src/isoParse.js +0 -1
  274. package/vendor/d3-time-format/src/locale.js +0 -1
  275. package/vendor/define-properties/index.js +0 -60
  276. package/vendor/gl-matrix/esm/common.js +0 -30
  277. package/vendor/gl-matrix/esm/index.js +0 -1
  278. package/vendor/gl-matrix/esm/mat2.js +0 -1
  279. package/vendor/gl-matrix/esm/mat2d.js +0 -1
  280. package/vendor/gl-matrix/esm/mat3.js +0 -817
  281. package/vendor/gl-matrix/esm/mat4.js +0 -1868
  282. package/vendor/gl-matrix/esm/quat.js +0 -330
  283. package/vendor/gl-matrix/esm/quat2.js +0 -1
  284. package/vendor/gl-matrix/esm/vec2.js +0 -1
  285. package/vendor/gl-matrix/esm/vec3.js +0 -842
  286. package/vendor/gl-matrix/esm/vec4.js +0 -153
  287. package/vendor/globalthis/implementation.browser.js +0 -11
  288. package/vendor/globalthis/index.js +0 -25
  289. package/vendor/globalthis/polyfill.js +0 -14
  290. package/vendor/globalthis/shim.js +0 -25
  291. package/vendor/internmap/src/index.js +0 -1
  292. package/vendor/jszip/dist/jszip.min.js +0 -11
  293. package/vendor/object-keys/implementation.js +0 -124
  294. package/vendor/object-keys/index.js +0 -35
  295. package/vendor/object-keys/isArguments.js +0 -17
  296. package/vendor/pako/dist/pako.esm.mjs.js +0 -6707
  297. package/vendor/seedrandom/index.js +0 -77
  298. package/vendor/seedrandom/lib/alea.js +0 -117
  299. package/vendor/seedrandom/lib/tychei.js +0 -105
  300. package/vendor/seedrandom/lib/xor128.js +0 -84
  301. package/vendor/seedrandom/lib/xor4096.js +0 -150
  302. package/vendor/seedrandom/lib/xorshift7.js +0 -101
  303. package/vendor/seedrandom/lib/xorwow.js +0 -89
  304. package/vendor/seedrandom/seedrandom.js +0 -256
  305. package/vendor/webworker-promise/lib/register.js +0 -158
  306. package/vendor/webworker-promise/lib/tiny-emitter.js +0 -89
  307. package/vendor/webworker-promise/src/index.js +0 -110
  308. package/vendor/webworker-promise/src/tiny-emitter.js +0 -51
  309. package/vendor/xmlbuilder2/lib/xmlbuilder2.min.js +0 -13
@@ -1,1868 +0,0 @@
1
- import { E as EPSILON, A as ARRAY_TYPE } from './common.js';
2
-
3
- /**
4
- * 4x4 Matrix<br>Format: column-major, when typed out it looks like row-major<br>The matrices are being post multiplied.
5
- * @module mat4
6
- */
7
-
8
- /**
9
- * Creates a new identity mat4
10
- *
11
- * @returns {mat4} a new 4x4 matrix
12
- */
13
-
14
- function create() {
15
- var out = new ARRAY_TYPE(16);
16
-
17
- if (ARRAY_TYPE != Float32Array) {
18
- out[1] = 0;
19
- out[2] = 0;
20
- out[3] = 0;
21
- out[4] = 0;
22
- out[6] = 0;
23
- out[7] = 0;
24
- out[8] = 0;
25
- out[9] = 0;
26
- out[11] = 0;
27
- out[12] = 0;
28
- out[13] = 0;
29
- out[14] = 0;
30
- }
31
-
32
- out[0] = 1;
33
- out[5] = 1;
34
- out[10] = 1;
35
- out[15] = 1;
36
- return out;
37
- }
38
- /**
39
- * Creates a new mat4 initialized with values from an existing matrix
40
- *
41
- * @param {ReadonlyMat4} a matrix to clone
42
- * @returns {mat4} a new 4x4 matrix
43
- */
44
-
45
- function clone(a) {
46
- var out = new ARRAY_TYPE(16);
47
- out[0] = a[0];
48
- out[1] = a[1];
49
- out[2] = a[2];
50
- out[3] = a[3];
51
- out[4] = a[4];
52
- out[5] = a[5];
53
- out[6] = a[6];
54
- out[7] = a[7];
55
- out[8] = a[8];
56
- out[9] = a[9];
57
- out[10] = a[10];
58
- out[11] = a[11];
59
- out[12] = a[12];
60
- out[13] = a[13];
61
- out[14] = a[14];
62
- out[15] = a[15];
63
- return out;
64
- }
65
- /**
66
- * Copy the values from one mat4 to another
67
- *
68
- * @param {mat4} out the receiving matrix
69
- * @param {ReadonlyMat4} a the source matrix
70
- * @returns {mat4} out
71
- */
72
-
73
- function copy(out, a) {
74
- out[0] = a[0];
75
- out[1] = a[1];
76
- out[2] = a[2];
77
- out[3] = a[3];
78
- out[4] = a[4];
79
- out[5] = a[5];
80
- out[6] = a[6];
81
- out[7] = a[7];
82
- out[8] = a[8];
83
- out[9] = a[9];
84
- out[10] = a[10];
85
- out[11] = a[11];
86
- out[12] = a[12];
87
- out[13] = a[13];
88
- out[14] = a[14];
89
- out[15] = a[15];
90
- return out;
91
- }
92
- /**
93
- * Create a new mat4 with the given values
94
- *
95
- * @param {Number} m00 Component in column 0, row 0 position (index 0)
96
- * @param {Number} m01 Component in column 0, row 1 position (index 1)
97
- * @param {Number} m02 Component in column 0, row 2 position (index 2)
98
- * @param {Number} m03 Component in column 0, row 3 position (index 3)
99
- * @param {Number} m10 Component in column 1, row 0 position (index 4)
100
- * @param {Number} m11 Component in column 1, row 1 position (index 5)
101
- * @param {Number} m12 Component in column 1, row 2 position (index 6)
102
- * @param {Number} m13 Component in column 1, row 3 position (index 7)
103
- * @param {Number} m20 Component in column 2, row 0 position (index 8)
104
- * @param {Number} m21 Component in column 2, row 1 position (index 9)
105
- * @param {Number} m22 Component in column 2, row 2 position (index 10)
106
- * @param {Number} m23 Component in column 2, row 3 position (index 11)
107
- * @param {Number} m30 Component in column 3, row 0 position (index 12)
108
- * @param {Number} m31 Component in column 3, row 1 position (index 13)
109
- * @param {Number} m32 Component in column 3, row 2 position (index 14)
110
- * @param {Number} m33 Component in column 3, row 3 position (index 15)
111
- * @returns {mat4} A new mat4
112
- */
113
-
114
- function fromValues(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
115
- var out = new ARRAY_TYPE(16);
116
- out[0] = m00;
117
- out[1] = m01;
118
- out[2] = m02;
119
- out[3] = m03;
120
- out[4] = m10;
121
- out[5] = m11;
122
- out[6] = m12;
123
- out[7] = m13;
124
- out[8] = m20;
125
- out[9] = m21;
126
- out[10] = m22;
127
- out[11] = m23;
128
- out[12] = m30;
129
- out[13] = m31;
130
- out[14] = m32;
131
- out[15] = m33;
132
- return out;
133
- }
134
- /**
135
- * Set the components of a mat4 to the given values
136
- *
137
- * @param {mat4} out the receiving matrix
138
- * @param {Number} m00 Component in column 0, row 0 position (index 0)
139
- * @param {Number} m01 Component in column 0, row 1 position (index 1)
140
- * @param {Number} m02 Component in column 0, row 2 position (index 2)
141
- * @param {Number} m03 Component in column 0, row 3 position (index 3)
142
- * @param {Number} m10 Component in column 1, row 0 position (index 4)
143
- * @param {Number} m11 Component in column 1, row 1 position (index 5)
144
- * @param {Number} m12 Component in column 1, row 2 position (index 6)
145
- * @param {Number} m13 Component in column 1, row 3 position (index 7)
146
- * @param {Number} m20 Component in column 2, row 0 position (index 8)
147
- * @param {Number} m21 Component in column 2, row 1 position (index 9)
148
- * @param {Number} m22 Component in column 2, row 2 position (index 10)
149
- * @param {Number} m23 Component in column 2, row 3 position (index 11)
150
- * @param {Number} m30 Component in column 3, row 0 position (index 12)
151
- * @param {Number} m31 Component in column 3, row 1 position (index 13)
152
- * @param {Number} m32 Component in column 3, row 2 position (index 14)
153
- * @param {Number} m33 Component in column 3, row 3 position (index 15)
154
- * @returns {mat4} out
155
- */
156
-
157
- function set(out, m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
158
- out[0] = m00;
159
- out[1] = m01;
160
- out[2] = m02;
161
- out[3] = m03;
162
- out[4] = m10;
163
- out[5] = m11;
164
- out[6] = m12;
165
- out[7] = m13;
166
- out[8] = m20;
167
- out[9] = m21;
168
- out[10] = m22;
169
- out[11] = m23;
170
- out[12] = m30;
171
- out[13] = m31;
172
- out[14] = m32;
173
- out[15] = m33;
174
- return out;
175
- }
176
- /**
177
- * Set a mat4 to the identity matrix
178
- *
179
- * @param {mat4} out the receiving matrix
180
- * @returns {mat4} out
181
- */
182
-
183
- function identity(out) {
184
- out[0] = 1;
185
- out[1] = 0;
186
- out[2] = 0;
187
- out[3] = 0;
188
- out[4] = 0;
189
- out[5] = 1;
190
- out[6] = 0;
191
- out[7] = 0;
192
- out[8] = 0;
193
- out[9] = 0;
194
- out[10] = 1;
195
- out[11] = 0;
196
- out[12] = 0;
197
- out[13] = 0;
198
- out[14] = 0;
199
- out[15] = 1;
200
- return out;
201
- }
202
- /**
203
- * Transpose the values of a mat4
204
- *
205
- * @param {mat4} out the receiving matrix
206
- * @param {ReadonlyMat4} a the source matrix
207
- * @returns {mat4} out
208
- */
209
-
210
- function transpose(out, a) {
211
- // If we are transposing ourselves we can skip a few steps but have to cache some values
212
- if (out === a) {
213
- var a01 = a[1],
214
- a02 = a[2],
215
- a03 = a[3];
216
- var a12 = a[6],
217
- a13 = a[7];
218
- var a23 = a[11];
219
- out[1] = a[4];
220
- out[2] = a[8];
221
- out[3] = a[12];
222
- out[4] = a01;
223
- out[6] = a[9];
224
- out[7] = a[13];
225
- out[8] = a02;
226
- out[9] = a12;
227
- out[11] = a[14];
228
- out[12] = a03;
229
- out[13] = a13;
230
- out[14] = a23;
231
- } else {
232
- out[0] = a[0];
233
- out[1] = a[4];
234
- out[2] = a[8];
235
- out[3] = a[12];
236
- out[4] = a[1];
237
- out[5] = a[5];
238
- out[6] = a[9];
239
- out[7] = a[13];
240
- out[8] = a[2];
241
- out[9] = a[6];
242
- out[10] = a[10];
243
- out[11] = a[14];
244
- out[12] = a[3];
245
- out[13] = a[7];
246
- out[14] = a[11];
247
- out[15] = a[15];
248
- }
249
-
250
- return out;
251
- }
252
- /**
253
- * Inverts a mat4
254
- *
255
- * @param {mat4} out the receiving matrix
256
- * @param {ReadonlyMat4} a the source matrix
257
- * @returns {mat4} out
258
- */
259
-
260
- function invert(out, a) {
261
- var a00 = a[0],
262
- a01 = a[1],
263
- a02 = a[2],
264
- a03 = a[3];
265
- var a10 = a[4],
266
- a11 = a[5],
267
- a12 = a[6],
268
- a13 = a[7];
269
- var a20 = a[8],
270
- a21 = a[9],
271
- a22 = a[10],
272
- a23 = a[11];
273
- var a30 = a[12],
274
- a31 = a[13],
275
- a32 = a[14],
276
- a33 = a[15];
277
- var b00 = a00 * a11 - a01 * a10;
278
- var b01 = a00 * a12 - a02 * a10;
279
- var b02 = a00 * a13 - a03 * a10;
280
- var b03 = a01 * a12 - a02 * a11;
281
- var b04 = a01 * a13 - a03 * a11;
282
- var b05 = a02 * a13 - a03 * a12;
283
- var b06 = a20 * a31 - a21 * a30;
284
- var b07 = a20 * a32 - a22 * a30;
285
- var b08 = a20 * a33 - a23 * a30;
286
- var b09 = a21 * a32 - a22 * a31;
287
- var b10 = a21 * a33 - a23 * a31;
288
- var b11 = a22 * a33 - a23 * a32; // Calculate the determinant
289
-
290
- var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
291
-
292
- if (!det) {
293
- return null;
294
- }
295
-
296
- det = 1.0 / det;
297
- out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
298
- out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
299
- out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
300
- out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
301
- out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
302
- out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
303
- out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
304
- out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
305
- out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
306
- out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
307
- out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
308
- out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
309
- out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
310
- out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
311
- out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
312
- out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
313
- return out;
314
- }
315
- /**
316
- * Calculates the adjugate of a mat4
317
- *
318
- * @param {mat4} out the receiving matrix
319
- * @param {ReadonlyMat4} a the source matrix
320
- * @returns {mat4} out
321
- */
322
-
323
- function adjoint(out, a) {
324
- var a00 = a[0],
325
- a01 = a[1],
326
- a02 = a[2],
327
- a03 = a[3];
328
- var a10 = a[4],
329
- a11 = a[5],
330
- a12 = a[6],
331
- a13 = a[7];
332
- var a20 = a[8],
333
- a21 = a[9],
334
- a22 = a[10],
335
- a23 = a[11];
336
- var a30 = a[12],
337
- a31 = a[13],
338
- a32 = a[14],
339
- a33 = a[15];
340
- out[0] = a11 * (a22 * a33 - a23 * a32) - a21 * (a12 * a33 - a13 * a32) + a31 * (a12 * a23 - a13 * a22);
341
- out[1] = -(a01 * (a22 * a33 - a23 * a32) - a21 * (a02 * a33 - a03 * a32) + a31 * (a02 * a23 - a03 * a22));
342
- out[2] = a01 * (a12 * a33 - a13 * a32) - a11 * (a02 * a33 - a03 * a32) + a31 * (a02 * a13 - a03 * a12);
343
- out[3] = -(a01 * (a12 * a23 - a13 * a22) - a11 * (a02 * a23 - a03 * a22) + a21 * (a02 * a13 - a03 * a12));
344
- out[4] = -(a10 * (a22 * a33 - a23 * a32) - a20 * (a12 * a33 - a13 * a32) + a30 * (a12 * a23 - a13 * a22));
345
- out[5] = a00 * (a22 * a33 - a23 * a32) - a20 * (a02 * a33 - a03 * a32) + a30 * (a02 * a23 - a03 * a22);
346
- out[6] = -(a00 * (a12 * a33 - a13 * a32) - a10 * (a02 * a33 - a03 * a32) + a30 * (a02 * a13 - a03 * a12));
347
- out[7] = a00 * (a12 * a23 - a13 * a22) - a10 * (a02 * a23 - a03 * a22) + a20 * (a02 * a13 - a03 * a12);
348
- out[8] = a10 * (a21 * a33 - a23 * a31) - a20 * (a11 * a33 - a13 * a31) + a30 * (a11 * a23 - a13 * a21);
349
- out[9] = -(a00 * (a21 * a33 - a23 * a31) - a20 * (a01 * a33 - a03 * a31) + a30 * (a01 * a23 - a03 * a21));
350
- out[10] = a00 * (a11 * a33 - a13 * a31) - a10 * (a01 * a33 - a03 * a31) + a30 * (a01 * a13 - a03 * a11);
351
- out[11] = -(a00 * (a11 * a23 - a13 * a21) - a10 * (a01 * a23 - a03 * a21) + a20 * (a01 * a13 - a03 * a11));
352
- out[12] = -(a10 * (a21 * a32 - a22 * a31) - a20 * (a11 * a32 - a12 * a31) + a30 * (a11 * a22 - a12 * a21));
353
- out[13] = a00 * (a21 * a32 - a22 * a31) - a20 * (a01 * a32 - a02 * a31) + a30 * (a01 * a22 - a02 * a21);
354
- out[14] = -(a00 * (a11 * a32 - a12 * a31) - a10 * (a01 * a32 - a02 * a31) + a30 * (a01 * a12 - a02 * a11));
355
- out[15] = a00 * (a11 * a22 - a12 * a21) - a10 * (a01 * a22 - a02 * a21) + a20 * (a01 * a12 - a02 * a11);
356
- return out;
357
- }
358
- /**
359
- * Calculates the determinant of a mat4
360
- *
361
- * @param {ReadonlyMat4} a the source matrix
362
- * @returns {Number} determinant of a
363
- */
364
-
365
- function determinant(a) {
366
- var a00 = a[0],
367
- a01 = a[1],
368
- a02 = a[2],
369
- a03 = a[3];
370
- var a10 = a[4],
371
- a11 = a[5],
372
- a12 = a[6],
373
- a13 = a[7];
374
- var a20 = a[8],
375
- a21 = a[9],
376
- a22 = a[10],
377
- a23 = a[11];
378
- var a30 = a[12],
379
- a31 = a[13],
380
- a32 = a[14],
381
- a33 = a[15];
382
- var b00 = a00 * a11 - a01 * a10;
383
- var b01 = a00 * a12 - a02 * a10;
384
- var b02 = a00 * a13 - a03 * a10;
385
- var b03 = a01 * a12 - a02 * a11;
386
- var b04 = a01 * a13 - a03 * a11;
387
- var b05 = a02 * a13 - a03 * a12;
388
- var b06 = a20 * a31 - a21 * a30;
389
- var b07 = a20 * a32 - a22 * a30;
390
- var b08 = a20 * a33 - a23 * a30;
391
- var b09 = a21 * a32 - a22 * a31;
392
- var b10 = a21 * a33 - a23 * a31;
393
- var b11 = a22 * a33 - a23 * a32; // Calculate the determinant
394
-
395
- return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
396
- }
397
- /**
398
- * Multiplies two mat4s
399
- *
400
- * @param {mat4} out the receiving matrix
401
- * @param {ReadonlyMat4} a the first operand
402
- * @param {ReadonlyMat4} b the second operand
403
- * @returns {mat4} out
404
- */
405
-
406
- function multiply(out, a, b) {
407
- var a00 = a[0],
408
- a01 = a[1],
409
- a02 = a[2],
410
- a03 = a[3];
411
- var a10 = a[4],
412
- a11 = a[5],
413
- a12 = a[6],
414
- a13 = a[7];
415
- var a20 = a[8],
416
- a21 = a[9],
417
- a22 = a[10],
418
- a23 = a[11];
419
- var a30 = a[12],
420
- a31 = a[13],
421
- a32 = a[14],
422
- a33 = a[15]; // Cache only the current line of the second matrix
423
-
424
- var b0 = b[0],
425
- b1 = b[1],
426
- b2 = b[2],
427
- b3 = b[3];
428
- out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
429
- out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
430
- out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
431
- out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
432
- b0 = b[4];
433
- b1 = b[5];
434
- b2 = b[6];
435
- b3 = b[7];
436
- out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
437
- out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
438
- out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
439
- out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
440
- b0 = b[8];
441
- b1 = b[9];
442
- b2 = b[10];
443
- b3 = b[11];
444
- out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
445
- out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
446
- out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
447
- out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
448
- b0 = b[12];
449
- b1 = b[13];
450
- b2 = b[14];
451
- b3 = b[15];
452
- out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
453
- out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
454
- out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
455
- out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
456
- return out;
457
- }
458
- /**
459
- * Translate a mat4 by the given vector
460
- *
461
- * @param {mat4} out the receiving matrix
462
- * @param {ReadonlyMat4} a the matrix to translate
463
- * @param {ReadonlyVec3} v vector to translate by
464
- * @returns {mat4} out
465
- */
466
-
467
- function translate(out, a, v) {
468
- var x = v[0],
469
- y = v[1],
470
- z = v[2];
471
- var a00, a01, a02, a03;
472
- var a10, a11, a12, a13;
473
- var a20, a21, a22, a23;
474
-
475
- if (a === out) {
476
- out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
477
- out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
478
- out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
479
- out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
480
- } else {
481
- a00 = a[0];
482
- a01 = a[1];
483
- a02 = a[2];
484
- a03 = a[3];
485
- a10 = a[4];
486
- a11 = a[5];
487
- a12 = a[6];
488
- a13 = a[7];
489
- a20 = a[8];
490
- a21 = a[9];
491
- a22 = a[10];
492
- a23 = a[11];
493
- out[0] = a00;
494
- out[1] = a01;
495
- out[2] = a02;
496
- out[3] = a03;
497
- out[4] = a10;
498
- out[5] = a11;
499
- out[6] = a12;
500
- out[7] = a13;
501
- out[8] = a20;
502
- out[9] = a21;
503
- out[10] = a22;
504
- out[11] = a23;
505
- out[12] = a00 * x + a10 * y + a20 * z + a[12];
506
- out[13] = a01 * x + a11 * y + a21 * z + a[13];
507
- out[14] = a02 * x + a12 * y + a22 * z + a[14];
508
- out[15] = a03 * x + a13 * y + a23 * z + a[15];
509
- }
510
-
511
- return out;
512
- }
513
- /**
514
- * Scales the mat4 by the dimensions in the given vec3 not using vectorization
515
- *
516
- * @param {mat4} out the receiving matrix
517
- * @param {ReadonlyMat4} a the matrix to scale
518
- * @param {ReadonlyVec3} v the vec3 to scale the matrix by
519
- * @returns {mat4} out
520
- **/
521
-
522
- function scale(out, a, v) {
523
- var x = v[0],
524
- y = v[1],
525
- z = v[2];
526
- out[0] = a[0] * x;
527
- out[1] = a[1] * x;
528
- out[2] = a[2] * x;
529
- out[3] = a[3] * x;
530
- out[4] = a[4] * y;
531
- out[5] = a[5] * y;
532
- out[6] = a[6] * y;
533
- out[7] = a[7] * y;
534
- out[8] = a[8] * z;
535
- out[9] = a[9] * z;
536
- out[10] = a[10] * z;
537
- out[11] = a[11] * z;
538
- out[12] = a[12];
539
- out[13] = a[13];
540
- out[14] = a[14];
541
- out[15] = a[15];
542
- return out;
543
- }
544
- /**
545
- * Rotates a mat4 by the given angle around the given axis
546
- *
547
- * @param {mat4} out the receiving matrix
548
- * @param {ReadonlyMat4} a the matrix to rotate
549
- * @param {Number} rad the angle to rotate the matrix by
550
- * @param {ReadonlyVec3} axis the axis to rotate around
551
- * @returns {mat4} out
552
- */
553
-
554
- function rotate(out, a, rad, axis) {
555
- var x = axis[0],
556
- y = axis[1],
557
- z = axis[2];
558
- var len = Math.hypot(x, y, z);
559
- var s, c, t;
560
- var a00, a01, a02, a03;
561
- var a10, a11, a12, a13;
562
- var a20, a21, a22, a23;
563
- var b00, b01, b02;
564
- var b10, b11, b12;
565
- var b20, b21, b22;
566
-
567
- if (len < EPSILON) {
568
- return null;
569
- }
570
-
571
- len = 1 / len;
572
- x *= len;
573
- y *= len;
574
- z *= len;
575
- s = Math.sin(rad);
576
- c = Math.cos(rad);
577
- t = 1 - c;
578
- a00 = a[0];
579
- a01 = a[1];
580
- a02 = a[2];
581
- a03 = a[3];
582
- a10 = a[4];
583
- a11 = a[5];
584
- a12 = a[6];
585
- a13 = a[7];
586
- a20 = a[8];
587
- a21 = a[9];
588
- a22 = a[10];
589
- a23 = a[11]; // Construct the elements of the rotation matrix
590
-
591
- b00 = x * x * t + c;
592
- b01 = y * x * t + z * s;
593
- b02 = z * x * t - y * s;
594
- b10 = x * y * t - z * s;
595
- b11 = y * y * t + c;
596
- b12 = z * y * t + x * s;
597
- b20 = x * z * t + y * s;
598
- b21 = y * z * t - x * s;
599
- b22 = z * z * t + c; // Perform rotation-specific matrix multiplication
600
-
601
- out[0] = a00 * b00 + a10 * b01 + a20 * b02;
602
- out[1] = a01 * b00 + a11 * b01 + a21 * b02;
603
- out[2] = a02 * b00 + a12 * b01 + a22 * b02;
604
- out[3] = a03 * b00 + a13 * b01 + a23 * b02;
605
- out[4] = a00 * b10 + a10 * b11 + a20 * b12;
606
- out[5] = a01 * b10 + a11 * b11 + a21 * b12;
607
- out[6] = a02 * b10 + a12 * b11 + a22 * b12;
608
- out[7] = a03 * b10 + a13 * b11 + a23 * b12;
609
- out[8] = a00 * b20 + a10 * b21 + a20 * b22;
610
- out[9] = a01 * b20 + a11 * b21 + a21 * b22;
611
- out[10] = a02 * b20 + a12 * b21 + a22 * b22;
612
- out[11] = a03 * b20 + a13 * b21 + a23 * b22;
613
-
614
- if (a !== out) {
615
- // If the source and destination differ, copy the unchanged last row
616
- out[12] = a[12];
617
- out[13] = a[13];
618
- out[14] = a[14];
619
- out[15] = a[15];
620
- }
621
-
622
- return out;
623
- }
624
- /**
625
- * Rotates a matrix by the given angle around the X axis
626
- *
627
- * @param {mat4} out the receiving matrix
628
- * @param {ReadonlyMat4} a the matrix to rotate
629
- * @param {Number} rad the angle to rotate the matrix by
630
- * @returns {mat4} out
631
- */
632
-
633
- function rotateX(out, a, rad) {
634
- var s = Math.sin(rad);
635
- var c = Math.cos(rad);
636
- var a10 = a[4];
637
- var a11 = a[5];
638
- var a12 = a[6];
639
- var a13 = a[7];
640
- var a20 = a[8];
641
- var a21 = a[9];
642
- var a22 = a[10];
643
- var a23 = a[11];
644
-
645
- if (a !== out) {
646
- // If the source and destination differ, copy the unchanged rows
647
- out[0] = a[0];
648
- out[1] = a[1];
649
- out[2] = a[2];
650
- out[3] = a[3];
651
- out[12] = a[12];
652
- out[13] = a[13];
653
- out[14] = a[14];
654
- out[15] = a[15];
655
- } // Perform axis-specific matrix multiplication
656
-
657
-
658
- out[4] = a10 * c + a20 * s;
659
- out[5] = a11 * c + a21 * s;
660
- out[6] = a12 * c + a22 * s;
661
- out[7] = a13 * c + a23 * s;
662
- out[8] = a20 * c - a10 * s;
663
- out[9] = a21 * c - a11 * s;
664
- out[10] = a22 * c - a12 * s;
665
- out[11] = a23 * c - a13 * s;
666
- return out;
667
- }
668
- /**
669
- * Rotates a matrix by the given angle around the Y axis
670
- *
671
- * @param {mat4} out the receiving matrix
672
- * @param {ReadonlyMat4} a the matrix to rotate
673
- * @param {Number} rad the angle to rotate the matrix by
674
- * @returns {mat4} out
675
- */
676
-
677
- function rotateY(out, a, rad) {
678
- var s = Math.sin(rad);
679
- var c = Math.cos(rad);
680
- var a00 = a[0];
681
- var a01 = a[1];
682
- var a02 = a[2];
683
- var a03 = a[3];
684
- var a20 = a[8];
685
- var a21 = a[9];
686
- var a22 = a[10];
687
- var a23 = a[11];
688
-
689
- if (a !== out) {
690
- // If the source and destination differ, copy the unchanged rows
691
- out[4] = a[4];
692
- out[5] = a[5];
693
- out[6] = a[6];
694
- out[7] = a[7];
695
- out[12] = a[12];
696
- out[13] = a[13];
697
- out[14] = a[14];
698
- out[15] = a[15];
699
- } // Perform axis-specific matrix multiplication
700
-
701
-
702
- out[0] = a00 * c - a20 * s;
703
- out[1] = a01 * c - a21 * s;
704
- out[2] = a02 * c - a22 * s;
705
- out[3] = a03 * c - a23 * s;
706
- out[8] = a00 * s + a20 * c;
707
- out[9] = a01 * s + a21 * c;
708
- out[10] = a02 * s + a22 * c;
709
- out[11] = a03 * s + a23 * c;
710
- return out;
711
- }
712
- /**
713
- * Rotates a matrix by the given angle around the Z axis
714
- *
715
- * @param {mat4} out the receiving matrix
716
- * @param {ReadonlyMat4} a the matrix to rotate
717
- * @param {Number} rad the angle to rotate the matrix by
718
- * @returns {mat4} out
719
- */
720
-
721
- function rotateZ(out, a, rad) {
722
- var s = Math.sin(rad);
723
- var c = Math.cos(rad);
724
- var a00 = a[0];
725
- var a01 = a[1];
726
- var a02 = a[2];
727
- var a03 = a[3];
728
- var a10 = a[4];
729
- var a11 = a[5];
730
- var a12 = a[6];
731
- var a13 = a[7];
732
-
733
- if (a !== out) {
734
- // If the source and destination differ, copy the unchanged last row
735
- out[8] = a[8];
736
- out[9] = a[9];
737
- out[10] = a[10];
738
- out[11] = a[11];
739
- out[12] = a[12];
740
- out[13] = a[13];
741
- out[14] = a[14];
742
- out[15] = a[15];
743
- } // Perform axis-specific matrix multiplication
744
-
745
-
746
- out[0] = a00 * c + a10 * s;
747
- out[1] = a01 * c + a11 * s;
748
- out[2] = a02 * c + a12 * s;
749
- out[3] = a03 * c + a13 * s;
750
- out[4] = a10 * c - a00 * s;
751
- out[5] = a11 * c - a01 * s;
752
- out[6] = a12 * c - a02 * s;
753
- out[7] = a13 * c - a03 * s;
754
- return out;
755
- }
756
- /**
757
- * Creates a matrix from a vector translation
758
- * This is equivalent to (but much faster than):
759
- *
760
- * mat4.identity(dest);
761
- * mat4.translate(dest, dest, vec);
762
- *
763
- * @param {mat4} out mat4 receiving operation result
764
- * @param {ReadonlyVec3} v Translation vector
765
- * @returns {mat4} out
766
- */
767
-
768
- function fromTranslation(out, v) {
769
- out[0] = 1;
770
- out[1] = 0;
771
- out[2] = 0;
772
- out[3] = 0;
773
- out[4] = 0;
774
- out[5] = 1;
775
- out[6] = 0;
776
- out[7] = 0;
777
- out[8] = 0;
778
- out[9] = 0;
779
- out[10] = 1;
780
- out[11] = 0;
781
- out[12] = v[0];
782
- out[13] = v[1];
783
- out[14] = v[2];
784
- out[15] = 1;
785
- return out;
786
- }
787
- /**
788
- * Creates a matrix from a vector scaling
789
- * This is equivalent to (but much faster than):
790
- *
791
- * mat4.identity(dest);
792
- * mat4.scale(dest, dest, vec);
793
- *
794
- * @param {mat4} out mat4 receiving operation result
795
- * @param {ReadonlyVec3} v Scaling vector
796
- * @returns {mat4} out
797
- */
798
-
799
- function fromScaling(out, v) {
800
- out[0] = v[0];
801
- out[1] = 0;
802
- out[2] = 0;
803
- out[3] = 0;
804
- out[4] = 0;
805
- out[5] = v[1];
806
- out[6] = 0;
807
- out[7] = 0;
808
- out[8] = 0;
809
- out[9] = 0;
810
- out[10] = v[2];
811
- out[11] = 0;
812
- out[12] = 0;
813
- out[13] = 0;
814
- out[14] = 0;
815
- out[15] = 1;
816
- return out;
817
- }
818
- /**
819
- * Creates a matrix from a given angle around a given axis
820
- * This is equivalent to (but much faster than):
821
- *
822
- * mat4.identity(dest);
823
- * mat4.rotate(dest, dest, rad, axis);
824
- *
825
- * @param {mat4} out mat4 receiving operation result
826
- * @param {Number} rad the angle to rotate the matrix by
827
- * @param {ReadonlyVec3} axis the axis to rotate around
828
- * @returns {mat4} out
829
- */
830
-
831
- function fromRotation(out, rad, axis) {
832
- var x = axis[0],
833
- y = axis[1],
834
- z = axis[2];
835
- var len = Math.hypot(x, y, z);
836
- var s, c, t;
837
-
838
- if (len < EPSILON) {
839
- return null;
840
- }
841
-
842
- len = 1 / len;
843
- x *= len;
844
- y *= len;
845
- z *= len;
846
- s = Math.sin(rad);
847
- c = Math.cos(rad);
848
- t = 1 - c; // Perform rotation-specific matrix multiplication
849
-
850
- out[0] = x * x * t + c;
851
- out[1] = y * x * t + z * s;
852
- out[2] = z * x * t - y * s;
853
- out[3] = 0;
854
- out[4] = x * y * t - z * s;
855
- out[5] = y * y * t + c;
856
- out[6] = z * y * t + x * s;
857
- out[7] = 0;
858
- out[8] = x * z * t + y * s;
859
- out[9] = y * z * t - x * s;
860
- out[10] = z * z * t + c;
861
- out[11] = 0;
862
- out[12] = 0;
863
- out[13] = 0;
864
- out[14] = 0;
865
- out[15] = 1;
866
- return out;
867
- }
868
- /**
869
- * Creates a matrix from the given angle around the X axis
870
- * This is equivalent to (but much faster than):
871
- *
872
- * mat4.identity(dest);
873
- * mat4.rotateX(dest, dest, rad);
874
- *
875
- * @param {mat4} out mat4 receiving operation result
876
- * @param {Number} rad the angle to rotate the matrix by
877
- * @returns {mat4} out
878
- */
879
-
880
- function fromXRotation(out, rad) {
881
- var s = Math.sin(rad);
882
- var c = Math.cos(rad); // Perform axis-specific matrix multiplication
883
-
884
- out[0] = 1;
885
- out[1] = 0;
886
- out[2] = 0;
887
- out[3] = 0;
888
- out[4] = 0;
889
- out[5] = c;
890
- out[6] = s;
891
- out[7] = 0;
892
- out[8] = 0;
893
- out[9] = -s;
894
- out[10] = c;
895
- out[11] = 0;
896
- out[12] = 0;
897
- out[13] = 0;
898
- out[14] = 0;
899
- out[15] = 1;
900
- return out;
901
- }
902
- /**
903
- * Creates a matrix from the given angle around the Y axis
904
- * This is equivalent to (but much faster than):
905
- *
906
- * mat4.identity(dest);
907
- * mat4.rotateY(dest, dest, rad);
908
- *
909
- * @param {mat4} out mat4 receiving operation result
910
- * @param {Number} rad the angle to rotate the matrix by
911
- * @returns {mat4} out
912
- */
913
-
914
- function fromYRotation(out, rad) {
915
- var s = Math.sin(rad);
916
- var c = Math.cos(rad); // Perform axis-specific matrix multiplication
917
-
918
- out[0] = c;
919
- out[1] = 0;
920
- out[2] = -s;
921
- out[3] = 0;
922
- out[4] = 0;
923
- out[5] = 1;
924
- out[6] = 0;
925
- out[7] = 0;
926
- out[8] = s;
927
- out[9] = 0;
928
- out[10] = c;
929
- out[11] = 0;
930
- out[12] = 0;
931
- out[13] = 0;
932
- out[14] = 0;
933
- out[15] = 1;
934
- return out;
935
- }
936
- /**
937
- * Creates a matrix from the given angle around the Z axis
938
- * This is equivalent to (but much faster than):
939
- *
940
- * mat4.identity(dest);
941
- * mat4.rotateZ(dest, dest, rad);
942
- *
943
- * @param {mat4} out mat4 receiving operation result
944
- * @param {Number} rad the angle to rotate the matrix by
945
- * @returns {mat4} out
946
- */
947
-
948
- function fromZRotation(out, rad) {
949
- var s = Math.sin(rad);
950
- var c = Math.cos(rad); // Perform axis-specific matrix multiplication
951
-
952
- out[0] = c;
953
- out[1] = s;
954
- out[2] = 0;
955
- out[3] = 0;
956
- out[4] = -s;
957
- out[5] = c;
958
- out[6] = 0;
959
- out[7] = 0;
960
- out[8] = 0;
961
- out[9] = 0;
962
- out[10] = 1;
963
- out[11] = 0;
964
- out[12] = 0;
965
- out[13] = 0;
966
- out[14] = 0;
967
- out[15] = 1;
968
- return out;
969
- }
970
- /**
971
- * Creates a matrix from a quaternion rotation and vector translation
972
- * This is equivalent to (but much faster than):
973
- *
974
- * mat4.identity(dest);
975
- * mat4.translate(dest, vec);
976
- * let quatMat = mat4.create();
977
- * quat4.toMat4(quat, quatMat);
978
- * mat4.multiply(dest, quatMat);
979
- *
980
- * @param {mat4} out mat4 receiving operation result
981
- * @param {quat4} q Rotation quaternion
982
- * @param {ReadonlyVec3} v Translation vector
983
- * @returns {mat4} out
984
- */
985
-
986
- function fromRotationTranslation(out, q, v) {
987
- // Quaternion math
988
- var x = q[0],
989
- y = q[1],
990
- z = q[2],
991
- w = q[3];
992
- var x2 = x + x;
993
- var y2 = y + y;
994
- var z2 = z + z;
995
- var xx = x * x2;
996
- var xy = x * y2;
997
- var xz = x * z2;
998
- var yy = y * y2;
999
- var yz = y * z2;
1000
- var zz = z * z2;
1001
- var wx = w * x2;
1002
- var wy = w * y2;
1003
- var wz = w * z2;
1004
- out[0] = 1 - (yy + zz);
1005
- out[1] = xy + wz;
1006
- out[2] = xz - wy;
1007
- out[3] = 0;
1008
- out[4] = xy - wz;
1009
- out[5] = 1 - (xx + zz);
1010
- out[6] = yz + wx;
1011
- out[7] = 0;
1012
- out[8] = xz + wy;
1013
- out[9] = yz - wx;
1014
- out[10] = 1 - (xx + yy);
1015
- out[11] = 0;
1016
- out[12] = v[0];
1017
- out[13] = v[1];
1018
- out[14] = v[2];
1019
- out[15] = 1;
1020
- return out;
1021
- }
1022
- /**
1023
- * Creates a new mat4 from a dual quat.
1024
- *
1025
- * @param {mat4} out Matrix
1026
- * @param {ReadonlyQuat2} a Dual Quaternion
1027
- * @returns {mat4} mat4 receiving operation result
1028
- */
1029
-
1030
- function fromQuat2(out, a) {
1031
- var translation = new ARRAY_TYPE(3);
1032
- var bx = -a[0],
1033
- by = -a[1],
1034
- bz = -a[2],
1035
- bw = a[3],
1036
- ax = a[4],
1037
- ay = a[5],
1038
- az = a[6],
1039
- aw = a[7];
1040
- var magnitude = bx * bx + by * by + bz * bz + bw * bw; //Only scale if it makes sense
1041
-
1042
- if (magnitude > 0) {
1043
- translation[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2 / magnitude;
1044
- translation[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2 / magnitude;
1045
- translation[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2 / magnitude;
1046
- } else {
1047
- translation[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2;
1048
- translation[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2;
1049
- translation[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2;
1050
- }
1051
-
1052
- fromRotationTranslation(out, a, translation);
1053
- return out;
1054
- }
1055
- /**
1056
- * Returns the translation vector component of a transformation
1057
- * matrix. If a matrix is built with fromRotationTranslation,
1058
- * the returned vector will be the same as the translation vector
1059
- * originally supplied.
1060
- * @param {vec3} out Vector to receive translation component
1061
- * @param {ReadonlyMat4} mat Matrix to be decomposed (input)
1062
- * @return {vec3} out
1063
- */
1064
-
1065
- function getTranslation(out, mat) {
1066
- out[0] = mat[12];
1067
- out[1] = mat[13];
1068
- out[2] = mat[14];
1069
- return out;
1070
- }
1071
- /**
1072
- * Returns the scaling factor component of a transformation
1073
- * matrix. If a matrix is built with fromRotationTranslationScale
1074
- * with a normalized Quaternion paramter, the returned vector will be
1075
- * the same as the scaling vector
1076
- * originally supplied.
1077
- * @param {vec3} out Vector to receive scaling factor component
1078
- * @param {ReadonlyMat4} mat Matrix to be decomposed (input)
1079
- * @return {vec3} out
1080
- */
1081
-
1082
- function getScaling(out, mat) {
1083
- var m11 = mat[0];
1084
- var m12 = mat[1];
1085
- var m13 = mat[2];
1086
- var m21 = mat[4];
1087
- var m22 = mat[5];
1088
- var m23 = mat[6];
1089
- var m31 = mat[8];
1090
- var m32 = mat[9];
1091
- var m33 = mat[10];
1092
- out[0] = Math.hypot(m11, m12, m13);
1093
- out[1] = Math.hypot(m21, m22, m23);
1094
- out[2] = Math.hypot(m31, m32, m33);
1095
- return out;
1096
- }
1097
- /**
1098
- * Returns a quaternion representing the rotational component
1099
- * of a transformation matrix. If a matrix is built with
1100
- * fromRotationTranslation, the returned quaternion will be the
1101
- * same as the quaternion originally supplied.
1102
- * @param {quat} out Quaternion to receive the rotation component
1103
- * @param {ReadonlyMat4} mat Matrix to be decomposed (input)
1104
- * @return {quat} out
1105
- */
1106
-
1107
- function getRotation(out, mat) {
1108
- var scaling = new ARRAY_TYPE(3);
1109
- getScaling(scaling, mat);
1110
- var is1 = 1 / scaling[0];
1111
- var is2 = 1 / scaling[1];
1112
- var is3 = 1 / scaling[2];
1113
- var sm11 = mat[0] * is1;
1114
- var sm12 = mat[1] * is2;
1115
- var sm13 = mat[2] * is3;
1116
- var sm21 = mat[4] * is1;
1117
- var sm22 = mat[5] * is2;
1118
- var sm23 = mat[6] * is3;
1119
- var sm31 = mat[8] * is1;
1120
- var sm32 = mat[9] * is2;
1121
- var sm33 = mat[10] * is3;
1122
- var trace = sm11 + sm22 + sm33;
1123
- var S = 0;
1124
-
1125
- if (trace > 0) {
1126
- S = Math.sqrt(trace + 1.0) * 2;
1127
- out[3] = 0.25 * S;
1128
- out[0] = (sm23 - sm32) / S;
1129
- out[1] = (sm31 - sm13) / S;
1130
- out[2] = (sm12 - sm21) / S;
1131
- } else if (sm11 > sm22 && sm11 > sm33) {
1132
- S = Math.sqrt(1.0 + sm11 - sm22 - sm33) * 2;
1133
- out[3] = (sm23 - sm32) / S;
1134
- out[0] = 0.25 * S;
1135
- out[1] = (sm12 + sm21) / S;
1136
- out[2] = (sm31 + sm13) / S;
1137
- } else if (sm22 > sm33) {
1138
- S = Math.sqrt(1.0 + sm22 - sm11 - sm33) * 2;
1139
- out[3] = (sm31 - sm13) / S;
1140
- out[0] = (sm12 + sm21) / S;
1141
- out[1] = 0.25 * S;
1142
- out[2] = (sm23 + sm32) / S;
1143
- } else {
1144
- S = Math.sqrt(1.0 + sm33 - sm11 - sm22) * 2;
1145
- out[3] = (sm12 - sm21) / S;
1146
- out[0] = (sm31 + sm13) / S;
1147
- out[1] = (sm23 + sm32) / S;
1148
- out[2] = 0.25 * S;
1149
- }
1150
-
1151
- return out;
1152
- }
1153
- /**
1154
- * Creates a matrix from a quaternion rotation, vector translation and vector scale
1155
- * This is equivalent to (but much faster than):
1156
- *
1157
- * mat4.identity(dest);
1158
- * mat4.translate(dest, vec);
1159
- * let quatMat = mat4.create();
1160
- * quat4.toMat4(quat, quatMat);
1161
- * mat4.multiply(dest, quatMat);
1162
- * mat4.scale(dest, scale)
1163
- *
1164
- * @param {mat4} out mat4 receiving operation result
1165
- * @param {quat4} q Rotation quaternion
1166
- * @param {ReadonlyVec3} v Translation vector
1167
- * @param {ReadonlyVec3} s Scaling vector
1168
- * @returns {mat4} out
1169
- */
1170
-
1171
- function fromRotationTranslationScale(out, q, v, s) {
1172
- // Quaternion math
1173
- var x = q[0],
1174
- y = q[1],
1175
- z = q[2],
1176
- w = q[3];
1177
- var x2 = x + x;
1178
- var y2 = y + y;
1179
- var z2 = z + z;
1180
- var xx = x * x2;
1181
- var xy = x * y2;
1182
- var xz = x * z2;
1183
- var yy = y * y2;
1184
- var yz = y * z2;
1185
- var zz = z * z2;
1186
- var wx = w * x2;
1187
- var wy = w * y2;
1188
- var wz = w * z2;
1189
- var sx = s[0];
1190
- var sy = s[1];
1191
- var sz = s[2];
1192
- out[0] = (1 - (yy + zz)) * sx;
1193
- out[1] = (xy + wz) * sx;
1194
- out[2] = (xz - wy) * sx;
1195
- out[3] = 0;
1196
- out[4] = (xy - wz) * sy;
1197
- out[5] = (1 - (xx + zz)) * sy;
1198
- out[6] = (yz + wx) * sy;
1199
- out[7] = 0;
1200
- out[8] = (xz + wy) * sz;
1201
- out[9] = (yz - wx) * sz;
1202
- out[10] = (1 - (xx + yy)) * sz;
1203
- out[11] = 0;
1204
- out[12] = v[0];
1205
- out[13] = v[1];
1206
- out[14] = v[2];
1207
- out[15] = 1;
1208
- return out;
1209
- }
1210
- /**
1211
- * Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin
1212
- * This is equivalent to (but much faster than):
1213
- *
1214
- * mat4.identity(dest);
1215
- * mat4.translate(dest, vec);
1216
- * mat4.translate(dest, origin);
1217
- * let quatMat = mat4.create();
1218
- * quat4.toMat4(quat, quatMat);
1219
- * mat4.multiply(dest, quatMat);
1220
- * mat4.scale(dest, scale)
1221
- * mat4.translate(dest, negativeOrigin);
1222
- *
1223
- * @param {mat4} out mat4 receiving operation result
1224
- * @param {quat4} q Rotation quaternion
1225
- * @param {ReadonlyVec3} v Translation vector
1226
- * @param {ReadonlyVec3} s Scaling vector
1227
- * @param {ReadonlyVec3} o The origin vector around which to scale and rotate
1228
- * @returns {mat4} out
1229
- */
1230
-
1231
- function fromRotationTranslationScaleOrigin(out, q, v, s, o) {
1232
- // Quaternion math
1233
- var x = q[0],
1234
- y = q[1],
1235
- z = q[2],
1236
- w = q[3];
1237
- var x2 = x + x;
1238
- var y2 = y + y;
1239
- var z2 = z + z;
1240
- var xx = x * x2;
1241
- var xy = x * y2;
1242
- var xz = x * z2;
1243
- var yy = y * y2;
1244
- var yz = y * z2;
1245
- var zz = z * z2;
1246
- var wx = w * x2;
1247
- var wy = w * y2;
1248
- var wz = w * z2;
1249
- var sx = s[0];
1250
- var sy = s[1];
1251
- var sz = s[2];
1252
- var ox = o[0];
1253
- var oy = o[1];
1254
- var oz = o[2];
1255
- var out0 = (1 - (yy + zz)) * sx;
1256
- var out1 = (xy + wz) * sx;
1257
- var out2 = (xz - wy) * sx;
1258
- var out4 = (xy - wz) * sy;
1259
- var out5 = (1 - (xx + zz)) * sy;
1260
- var out6 = (yz + wx) * sy;
1261
- var out8 = (xz + wy) * sz;
1262
- var out9 = (yz - wx) * sz;
1263
- var out10 = (1 - (xx + yy)) * sz;
1264
- out[0] = out0;
1265
- out[1] = out1;
1266
- out[2] = out2;
1267
- out[3] = 0;
1268
- out[4] = out4;
1269
- out[5] = out5;
1270
- out[6] = out6;
1271
- out[7] = 0;
1272
- out[8] = out8;
1273
- out[9] = out9;
1274
- out[10] = out10;
1275
- out[11] = 0;
1276
- out[12] = v[0] + ox - (out0 * ox + out4 * oy + out8 * oz);
1277
- out[13] = v[1] + oy - (out1 * ox + out5 * oy + out9 * oz);
1278
- out[14] = v[2] + oz - (out2 * ox + out6 * oy + out10 * oz);
1279
- out[15] = 1;
1280
- return out;
1281
- }
1282
- /**
1283
- * Calculates a 4x4 matrix from the given quaternion
1284
- *
1285
- * @param {mat4} out mat4 receiving operation result
1286
- * @param {ReadonlyQuat} q Quaternion to create matrix from
1287
- *
1288
- * @returns {mat4} out
1289
- */
1290
-
1291
- function fromQuat(out, q) {
1292
- var x = q[0],
1293
- y = q[1],
1294
- z = q[2],
1295
- w = q[3];
1296
- var x2 = x + x;
1297
- var y2 = y + y;
1298
- var z2 = z + z;
1299
- var xx = x * x2;
1300
- var yx = y * x2;
1301
- var yy = y * y2;
1302
- var zx = z * x2;
1303
- var zy = z * y2;
1304
- var zz = z * z2;
1305
- var wx = w * x2;
1306
- var wy = w * y2;
1307
- var wz = w * z2;
1308
- out[0] = 1 - yy - zz;
1309
- out[1] = yx + wz;
1310
- out[2] = zx - wy;
1311
- out[3] = 0;
1312
- out[4] = yx - wz;
1313
- out[5] = 1 - xx - zz;
1314
- out[6] = zy + wx;
1315
- out[7] = 0;
1316
- out[8] = zx + wy;
1317
- out[9] = zy - wx;
1318
- out[10] = 1 - xx - yy;
1319
- out[11] = 0;
1320
- out[12] = 0;
1321
- out[13] = 0;
1322
- out[14] = 0;
1323
- out[15] = 1;
1324
- return out;
1325
- }
1326
- /**
1327
- * Generates a frustum matrix with the given bounds
1328
- *
1329
- * @param {mat4} out mat4 frustum matrix will be written into
1330
- * @param {Number} left Left bound of the frustum
1331
- * @param {Number} right Right bound of the frustum
1332
- * @param {Number} bottom Bottom bound of the frustum
1333
- * @param {Number} top Top bound of the frustum
1334
- * @param {Number} near Near bound of the frustum
1335
- * @param {Number} far Far bound of the frustum
1336
- * @returns {mat4} out
1337
- */
1338
-
1339
- function frustum(out, left, right, bottom, top, near, far) {
1340
- var rl = 1 / (right - left);
1341
- var tb = 1 / (top - bottom);
1342
- var nf = 1 / (near - far);
1343
- out[0] = near * 2 * rl;
1344
- out[1] = 0;
1345
- out[2] = 0;
1346
- out[3] = 0;
1347
- out[4] = 0;
1348
- out[5] = near * 2 * tb;
1349
- out[6] = 0;
1350
- out[7] = 0;
1351
- out[8] = (right + left) * rl;
1352
- out[9] = (top + bottom) * tb;
1353
- out[10] = (far + near) * nf;
1354
- out[11] = -1;
1355
- out[12] = 0;
1356
- out[13] = 0;
1357
- out[14] = far * near * 2 * nf;
1358
- out[15] = 0;
1359
- return out;
1360
- }
1361
- /**
1362
- * Generates a perspective projection matrix with the given bounds.
1363
- * Passing null/undefined/no value for far will generate infinite projection matrix.
1364
- *
1365
- * @param {mat4} out mat4 frustum matrix will be written into
1366
- * @param {number} fovy Vertical field of view in radians
1367
- * @param {number} aspect Aspect ratio. typically viewport width/height
1368
- * @param {number} near Near bound of the frustum
1369
- * @param {number} far Far bound of the frustum, can be null or Infinity
1370
- * @returns {mat4} out
1371
- */
1372
-
1373
- function perspective(out, fovy, aspect, near, far) {
1374
- var f = 1.0 / Math.tan(fovy / 2),
1375
- nf;
1376
- out[0] = f / aspect;
1377
- out[1] = 0;
1378
- out[2] = 0;
1379
- out[3] = 0;
1380
- out[4] = 0;
1381
- out[5] = f;
1382
- out[6] = 0;
1383
- out[7] = 0;
1384
- out[8] = 0;
1385
- out[9] = 0;
1386
- out[11] = -1;
1387
- out[12] = 0;
1388
- out[13] = 0;
1389
- out[15] = 0;
1390
-
1391
- if (far != null && far !== Infinity) {
1392
- nf = 1 / (near - far);
1393
- out[10] = (far + near) * nf;
1394
- out[14] = 2 * far * near * nf;
1395
- } else {
1396
- out[10] = -1;
1397
- out[14] = -2 * near;
1398
- }
1399
-
1400
- return out;
1401
- }
1402
- /**
1403
- * Generates a perspective projection matrix with the given field of view.
1404
- * This is primarily useful for generating projection matrices to be used
1405
- * with the still experiemental WebVR API.
1406
- *
1407
- * @param {mat4} out mat4 frustum matrix will be written into
1408
- * @param {Object} fov Object containing the following values: upDegrees, downDegrees, leftDegrees, rightDegrees
1409
- * @param {number} near Near bound of the frustum
1410
- * @param {number} far Far bound of the frustum
1411
- * @returns {mat4} out
1412
- */
1413
-
1414
- function perspectiveFromFieldOfView(out, fov, near, far) {
1415
- var upTan = Math.tan(fov.upDegrees * Math.PI / 180.0);
1416
- var downTan = Math.tan(fov.downDegrees * Math.PI / 180.0);
1417
- var leftTan = Math.tan(fov.leftDegrees * Math.PI / 180.0);
1418
- var rightTan = Math.tan(fov.rightDegrees * Math.PI / 180.0);
1419
- var xScale = 2.0 / (leftTan + rightTan);
1420
- var yScale = 2.0 / (upTan + downTan);
1421
- out[0] = xScale;
1422
- out[1] = 0.0;
1423
- out[2] = 0.0;
1424
- out[3] = 0.0;
1425
- out[4] = 0.0;
1426
- out[5] = yScale;
1427
- out[6] = 0.0;
1428
- out[7] = 0.0;
1429
- out[8] = -((leftTan - rightTan) * xScale * 0.5);
1430
- out[9] = (upTan - downTan) * yScale * 0.5;
1431
- out[10] = far / (near - far);
1432
- out[11] = -1.0;
1433
- out[12] = 0.0;
1434
- out[13] = 0.0;
1435
- out[14] = far * near / (near - far);
1436
- out[15] = 0.0;
1437
- return out;
1438
- }
1439
- /**
1440
- * Generates a orthogonal projection matrix with the given bounds
1441
- *
1442
- * @param {mat4} out mat4 frustum matrix will be written into
1443
- * @param {number} left Left bound of the frustum
1444
- * @param {number} right Right bound of the frustum
1445
- * @param {number} bottom Bottom bound of the frustum
1446
- * @param {number} top Top bound of the frustum
1447
- * @param {number} near Near bound of the frustum
1448
- * @param {number} far Far bound of the frustum
1449
- * @returns {mat4} out
1450
- */
1451
-
1452
- function ortho(out, left, right, bottom, top, near, far) {
1453
- var lr = 1 / (left - right);
1454
- var bt = 1 / (bottom - top);
1455
- var nf = 1 / (near - far);
1456
- out[0] = -2 * lr;
1457
- out[1] = 0;
1458
- out[2] = 0;
1459
- out[3] = 0;
1460
- out[4] = 0;
1461
- out[5] = -2 * bt;
1462
- out[6] = 0;
1463
- out[7] = 0;
1464
- out[8] = 0;
1465
- out[9] = 0;
1466
- out[10] = 2 * nf;
1467
- out[11] = 0;
1468
- out[12] = (left + right) * lr;
1469
- out[13] = (top + bottom) * bt;
1470
- out[14] = (far + near) * nf;
1471
- out[15] = 1;
1472
- return out;
1473
- }
1474
- /**
1475
- * Generates a look-at matrix with the given eye position, focal point, and up axis.
1476
- * If you want a matrix that actually makes an object look at another object, you should use targetTo instead.
1477
- *
1478
- * @param {mat4} out mat4 frustum matrix will be written into
1479
- * @param {ReadonlyVec3} eye Position of the viewer
1480
- * @param {ReadonlyVec3} center Point the viewer is looking at
1481
- * @param {ReadonlyVec3} up vec3 pointing up
1482
- * @returns {mat4} out
1483
- */
1484
-
1485
- function lookAt(out, eye, center, up) {
1486
- var x0, x1, x2, y0, y1, y2, z0, z1, z2, len;
1487
- var eyex = eye[0];
1488
- var eyey = eye[1];
1489
- var eyez = eye[2];
1490
- var upx = up[0];
1491
- var upy = up[1];
1492
- var upz = up[2];
1493
- var centerx = center[0];
1494
- var centery = center[1];
1495
- var centerz = center[2];
1496
-
1497
- if (Math.abs(eyex - centerx) < EPSILON && Math.abs(eyey - centery) < EPSILON && Math.abs(eyez - centerz) < EPSILON) {
1498
- return identity(out);
1499
- }
1500
-
1501
- z0 = eyex - centerx;
1502
- z1 = eyey - centery;
1503
- z2 = eyez - centerz;
1504
- len = 1 / Math.hypot(z0, z1, z2);
1505
- z0 *= len;
1506
- z1 *= len;
1507
- z2 *= len;
1508
- x0 = upy * z2 - upz * z1;
1509
- x1 = upz * z0 - upx * z2;
1510
- x2 = upx * z1 - upy * z0;
1511
- len = Math.hypot(x0, x1, x2);
1512
-
1513
- if (!len) {
1514
- x0 = 0;
1515
- x1 = 0;
1516
- x2 = 0;
1517
- } else {
1518
- len = 1 / len;
1519
- x0 *= len;
1520
- x1 *= len;
1521
- x2 *= len;
1522
- }
1523
-
1524
- y0 = z1 * x2 - z2 * x1;
1525
- y1 = z2 * x0 - z0 * x2;
1526
- y2 = z0 * x1 - z1 * x0;
1527
- len = Math.hypot(y0, y1, y2);
1528
-
1529
- if (!len) {
1530
- y0 = 0;
1531
- y1 = 0;
1532
- y2 = 0;
1533
- } else {
1534
- len = 1 / len;
1535
- y0 *= len;
1536
- y1 *= len;
1537
- y2 *= len;
1538
- }
1539
-
1540
- out[0] = x0;
1541
- out[1] = y0;
1542
- out[2] = z0;
1543
- out[3] = 0;
1544
- out[4] = x1;
1545
- out[5] = y1;
1546
- out[6] = z1;
1547
- out[7] = 0;
1548
- out[8] = x2;
1549
- out[9] = y2;
1550
- out[10] = z2;
1551
- out[11] = 0;
1552
- out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);
1553
- out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);
1554
- out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);
1555
- out[15] = 1;
1556
- return out;
1557
- }
1558
- /**
1559
- * Generates a matrix that makes something look at something else.
1560
- *
1561
- * @param {mat4} out mat4 frustum matrix will be written into
1562
- * @param {ReadonlyVec3} eye Position of the viewer
1563
- * @param {ReadonlyVec3} center Point the viewer is looking at
1564
- * @param {ReadonlyVec3} up vec3 pointing up
1565
- * @returns {mat4} out
1566
- */
1567
-
1568
- function targetTo(out, eye, target, up) {
1569
- var eyex = eye[0],
1570
- eyey = eye[1],
1571
- eyez = eye[2],
1572
- upx = up[0],
1573
- upy = up[1],
1574
- upz = up[2];
1575
- var z0 = eyex - target[0],
1576
- z1 = eyey - target[1],
1577
- z2 = eyez - target[2];
1578
- var len = z0 * z0 + z1 * z1 + z2 * z2;
1579
-
1580
- if (len > 0) {
1581
- len = 1 / Math.sqrt(len);
1582
- z0 *= len;
1583
- z1 *= len;
1584
- z2 *= len;
1585
- }
1586
-
1587
- var x0 = upy * z2 - upz * z1,
1588
- x1 = upz * z0 - upx * z2,
1589
- x2 = upx * z1 - upy * z0;
1590
- len = x0 * x0 + x1 * x1 + x2 * x2;
1591
-
1592
- if (len > 0) {
1593
- len = 1 / Math.sqrt(len);
1594
- x0 *= len;
1595
- x1 *= len;
1596
- x2 *= len;
1597
- }
1598
-
1599
- out[0] = x0;
1600
- out[1] = x1;
1601
- out[2] = x2;
1602
- out[3] = 0;
1603
- out[4] = z1 * x2 - z2 * x1;
1604
- out[5] = z2 * x0 - z0 * x2;
1605
- out[6] = z0 * x1 - z1 * x0;
1606
- out[7] = 0;
1607
- out[8] = z0;
1608
- out[9] = z1;
1609
- out[10] = z2;
1610
- out[11] = 0;
1611
- out[12] = eyex;
1612
- out[13] = eyey;
1613
- out[14] = eyez;
1614
- out[15] = 1;
1615
- return out;
1616
- }
1617
- /**
1618
- * Returns a string representation of a mat4
1619
- *
1620
- * @param {ReadonlyMat4} a matrix to represent as a string
1621
- * @returns {String} string representation of the matrix
1622
- */
1623
-
1624
- function str(a) {
1625
- return "mat4(" + a[0] + ", " + a[1] + ", " + a[2] + ", " + a[3] + ", " + a[4] + ", " + a[5] + ", " + a[6] + ", " + a[7] + ", " + a[8] + ", " + a[9] + ", " + a[10] + ", " + a[11] + ", " + a[12] + ", " + a[13] + ", " + a[14] + ", " + a[15] + ")";
1626
- }
1627
- /**
1628
- * Returns Frobenius norm of a mat4
1629
- *
1630
- * @param {ReadonlyMat4} a the matrix to calculate Frobenius norm of
1631
- * @returns {Number} Frobenius norm
1632
- */
1633
-
1634
- function frob(a) {
1635
- return Math.hypot(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15]);
1636
- }
1637
- /**
1638
- * Adds two mat4's
1639
- *
1640
- * @param {mat4} out the receiving matrix
1641
- * @param {ReadonlyMat4} a the first operand
1642
- * @param {ReadonlyMat4} b the second operand
1643
- * @returns {mat4} out
1644
- */
1645
-
1646
- function add(out, a, b) {
1647
- out[0] = a[0] + b[0];
1648
- out[1] = a[1] + b[1];
1649
- out[2] = a[2] + b[2];
1650
- out[3] = a[3] + b[3];
1651
- out[4] = a[4] + b[4];
1652
- out[5] = a[5] + b[5];
1653
- out[6] = a[6] + b[6];
1654
- out[7] = a[7] + b[7];
1655
- out[8] = a[8] + b[8];
1656
- out[9] = a[9] + b[9];
1657
- out[10] = a[10] + b[10];
1658
- out[11] = a[11] + b[11];
1659
- out[12] = a[12] + b[12];
1660
- out[13] = a[13] + b[13];
1661
- out[14] = a[14] + b[14];
1662
- out[15] = a[15] + b[15];
1663
- return out;
1664
- }
1665
- /**
1666
- * Subtracts matrix b from matrix a
1667
- *
1668
- * @param {mat4} out the receiving matrix
1669
- * @param {ReadonlyMat4} a the first operand
1670
- * @param {ReadonlyMat4} b the second operand
1671
- * @returns {mat4} out
1672
- */
1673
-
1674
- function subtract(out, a, b) {
1675
- out[0] = a[0] - b[0];
1676
- out[1] = a[1] - b[1];
1677
- out[2] = a[2] - b[2];
1678
- out[3] = a[3] - b[3];
1679
- out[4] = a[4] - b[4];
1680
- out[5] = a[5] - b[5];
1681
- out[6] = a[6] - b[6];
1682
- out[7] = a[7] - b[7];
1683
- out[8] = a[8] - b[8];
1684
- out[9] = a[9] - b[9];
1685
- out[10] = a[10] - b[10];
1686
- out[11] = a[11] - b[11];
1687
- out[12] = a[12] - b[12];
1688
- out[13] = a[13] - b[13];
1689
- out[14] = a[14] - b[14];
1690
- out[15] = a[15] - b[15];
1691
- return out;
1692
- }
1693
- /**
1694
- * Multiply each element of the matrix by a scalar.
1695
- *
1696
- * @param {mat4} out the receiving matrix
1697
- * @param {ReadonlyMat4} a the matrix to scale
1698
- * @param {Number} b amount to scale the matrix's elements by
1699
- * @returns {mat4} out
1700
- */
1701
-
1702
- function multiplyScalar(out, a, b) {
1703
- out[0] = a[0] * b;
1704
- out[1] = a[1] * b;
1705
- out[2] = a[2] * b;
1706
- out[3] = a[3] * b;
1707
- out[4] = a[4] * b;
1708
- out[5] = a[5] * b;
1709
- out[6] = a[6] * b;
1710
- out[7] = a[7] * b;
1711
- out[8] = a[8] * b;
1712
- out[9] = a[9] * b;
1713
- out[10] = a[10] * b;
1714
- out[11] = a[11] * b;
1715
- out[12] = a[12] * b;
1716
- out[13] = a[13] * b;
1717
- out[14] = a[14] * b;
1718
- out[15] = a[15] * b;
1719
- return out;
1720
- }
1721
- /**
1722
- * Adds two mat4's after multiplying each element of the second operand by a scalar value.
1723
- *
1724
- * @param {mat4} out the receiving vector
1725
- * @param {ReadonlyMat4} a the first operand
1726
- * @param {ReadonlyMat4} b the second operand
1727
- * @param {Number} scale the amount to scale b's elements by before adding
1728
- * @returns {mat4} out
1729
- */
1730
-
1731
- function multiplyScalarAndAdd(out, a, b, scale) {
1732
- out[0] = a[0] + b[0] * scale;
1733
- out[1] = a[1] + b[1] * scale;
1734
- out[2] = a[2] + b[2] * scale;
1735
- out[3] = a[3] + b[3] * scale;
1736
- out[4] = a[4] + b[4] * scale;
1737
- out[5] = a[5] + b[5] * scale;
1738
- out[6] = a[6] + b[6] * scale;
1739
- out[7] = a[7] + b[7] * scale;
1740
- out[8] = a[8] + b[8] * scale;
1741
- out[9] = a[9] + b[9] * scale;
1742
- out[10] = a[10] + b[10] * scale;
1743
- out[11] = a[11] + b[11] * scale;
1744
- out[12] = a[12] + b[12] * scale;
1745
- out[13] = a[13] + b[13] * scale;
1746
- out[14] = a[14] + b[14] * scale;
1747
- out[15] = a[15] + b[15] * scale;
1748
- return out;
1749
- }
1750
- /**
1751
- * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)
1752
- *
1753
- * @param {ReadonlyMat4} a The first matrix.
1754
- * @param {ReadonlyMat4} b The second matrix.
1755
- * @returns {Boolean} True if the matrices are equal, false otherwise.
1756
- */
1757
-
1758
- function exactEquals(a, b) {
1759
- return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3] && a[4] === b[4] && a[5] === b[5] && a[6] === b[6] && a[7] === b[7] && a[8] === b[8] && a[9] === b[9] && a[10] === b[10] && a[11] === b[11] && a[12] === b[12] && a[13] === b[13] && a[14] === b[14] && a[15] === b[15];
1760
- }
1761
- /**
1762
- * Returns whether or not the matrices have approximately the same elements in the same position.
1763
- *
1764
- * @param {ReadonlyMat4} a The first matrix.
1765
- * @param {ReadonlyMat4} b The second matrix.
1766
- * @returns {Boolean} True if the matrices are equal, false otherwise.
1767
- */
1768
-
1769
- function equals(a, b) {
1770
- var a0 = a[0],
1771
- a1 = a[1],
1772
- a2 = a[2],
1773
- a3 = a[3];
1774
- var a4 = a[4],
1775
- a5 = a[5],
1776
- a6 = a[6],
1777
- a7 = a[7];
1778
- var a8 = a[8],
1779
- a9 = a[9],
1780
- a10 = a[10],
1781
- a11 = a[11];
1782
- var a12 = a[12],
1783
- a13 = a[13],
1784
- a14 = a[14],
1785
- a15 = a[15];
1786
- var b0 = b[0],
1787
- b1 = b[1],
1788
- b2 = b[2],
1789
- b3 = b[3];
1790
- var b4 = b[4],
1791
- b5 = b[5],
1792
- b6 = b[6],
1793
- b7 = b[7];
1794
- var b8 = b[8],
1795
- b9 = b[9],
1796
- b10 = b[10],
1797
- b11 = b[11];
1798
- var b12 = b[12],
1799
- b13 = b[13],
1800
- b14 = b[14],
1801
- b15 = b[15];
1802
- 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)) && Math.abs(a3 - b3) <= EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)) && Math.abs(a6 - b6) <= EPSILON * Math.max(1.0, Math.abs(a6), Math.abs(b6)) && Math.abs(a7 - b7) <= EPSILON * Math.max(1.0, Math.abs(a7), Math.abs(b7)) && Math.abs(a8 - b8) <= EPSILON * Math.max(1.0, Math.abs(a8), Math.abs(b8)) && Math.abs(a9 - b9) <= EPSILON * Math.max(1.0, Math.abs(a9), Math.abs(b9)) && Math.abs(a10 - b10) <= EPSILON * Math.max(1.0, Math.abs(a10), Math.abs(b10)) && Math.abs(a11 - b11) <= EPSILON * Math.max(1.0, Math.abs(a11), Math.abs(b11)) && Math.abs(a12 - b12) <= EPSILON * Math.max(1.0, Math.abs(a12), Math.abs(b12)) && Math.abs(a13 - b13) <= EPSILON * Math.max(1.0, Math.abs(a13), Math.abs(b13)) && Math.abs(a14 - b14) <= EPSILON * Math.max(1.0, Math.abs(a14), Math.abs(b14)) && Math.abs(a15 - b15) <= EPSILON * Math.max(1.0, Math.abs(a15), Math.abs(b15));
1803
- }
1804
- /**
1805
- * Alias for {@link mat4.multiply}
1806
- * @function
1807
- */
1808
-
1809
- var mul = multiply;
1810
- /**
1811
- * Alias for {@link mat4.subtract}
1812
- * @function
1813
- */
1814
-
1815
- var sub = subtract;
1816
-
1817
- var mat4 = /*#__PURE__*/Object.freeze({
1818
- __proto__: null,
1819
- create: create,
1820
- clone: clone,
1821
- copy: copy,
1822
- fromValues: fromValues,
1823
- set: set,
1824
- identity: identity,
1825
- transpose: transpose,
1826
- invert: invert,
1827
- adjoint: adjoint,
1828
- determinant: determinant,
1829
- multiply: multiply,
1830
- translate: translate,
1831
- scale: scale,
1832
- rotate: rotate,
1833
- rotateX: rotateX,
1834
- rotateY: rotateY,
1835
- rotateZ: rotateZ,
1836
- fromTranslation: fromTranslation,
1837
- fromScaling: fromScaling,
1838
- fromRotation: fromRotation,
1839
- fromXRotation: fromXRotation,
1840
- fromYRotation: fromYRotation,
1841
- fromZRotation: fromZRotation,
1842
- fromRotationTranslation: fromRotationTranslation,
1843
- fromQuat2: fromQuat2,
1844
- getTranslation: getTranslation,
1845
- getScaling: getScaling,
1846
- getRotation: getRotation,
1847
- fromRotationTranslationScale: fromRotationTranslationScale,
1848
- fromRotationTranslationScaleOrigin: fromRotationTranslationScaleOrigin,
1849
- fromQuat: fromQuat,
1850
- frustum: frustum,
1851
- perspective: perspective,
1852
- perspectiveFromFieldOfView: perspectiveFromFieldOfView,
1853
- ortho: ortho,
1854
- lookAt: lookAt,
1855
- targetTo: targetTo,
1856
- str: str,
1857
- frob: frob,
1858
- add: add,
1859
- subtract: subtract,
1860
- multiplyScalar: multiplyScalar,
1861
- multiplyScalarAndAdd: multiplyScalarAndAdd,
1862
- exactEquals: exactEquals,
1863
- equals: equals,
1864
- mul: mul,
1865
- sub: sub
1866
- });
1867
-
1868
- export { rotateX as a, rotateY as b, rotateZ as c, copy as d, fromTranslation as e, fromRotation as f, invert as g, exactEquals as h, identity as i, transpose as j, fromQuat as k, lookAt as l, multiply as m, getRotation as n, ortho as o, fromRotationTranslationScale as p, mat4 as q, rotate as r, scale as s, translate as t };