@lightningjs/renderer 3.0.0-beta2 → 3.0.0-beta4

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 (387) hide show
  1. package/COPYING +1 -0
  2. package/LICENSE +202 -202
  3. package/NOTICE +3 -3
  4. package/README.md +147 -147
  5. package/dist/exports/index.d.ts +1 -0
  6. package/dist/exports/index.js +1 -0
  7. package/dist/exports/index.js.map +1 -1
  8. package/dist/src/core/CoreNode.d.ts +3 -2
  9. package/dist/src/core/CoreNode.js +13 -7
  10. package/dist/src/core/CoreNode.js.map +1 -1
  11. package/dist/src/core/CoreShaderManager.d.ts +3 -5
  12. package/dist/src/core/CoreShaderManager.js.map +1 -1
  13. package/dist/src/core/CoreTextNode.d.ts +2 -0
  14. package/dist/src/core/CoreTextNode.js +7 -0
  15. package/dist/src/core/CoreTextNode.js.map +1 -1
  16. package/dist/src/core/CoreTextureManager.d.ts +2 -0
  17. package/dist/src/core/CoreTextureManager.js +7 -5
  18. package/dist/src/core/CoreTextureManager.js.map +1 -1
  19. package/dist/src/core/Stage.d.ts +5 -0
  20. package/dist/src/core/Stage.js +10 -5
  21. package/dist/src/core/Stage.js.map +1 -1
  22. package/dist/src/core/lib/validateImageBitmap.d.ts +2 -1
  23. package/dist/src/core/lib/validateImageBitmap.js +4 -4
  24. package/dist/src/core/lib/validateImageBitmap.js.map +1 -1
  25. package/dist/src/core/platforms/Platform.d.ts +37 -0
  26. package/dist/src/{main-api/IRenderDriver.js → core/platforms/Platform.js} +4 -2
  27. package/dist/src/core/platforms/Platform.js.map +1 -0
  28. package/dist/src/core/platforms/web/WebPlatform.d.ts +9 -0
  29. package/dist/src/core/platforms/web/WebPlatform.js +58 -0
  30. package/dist/src/core/platforms/web/WebPlatform.js.map +1 -0
  31. package/dist/src/core/renderers/CoreRenderer.d.ts +3 -1
  32. package/dist/src/core/renderers/CoreRenderer.js.map +1 -1
  33. package/dist/src/core/renderers/CoreShaderNode.d.ts +1 -1
  34. package/dist/src/core/renderers/CoreShaderNode.js.map +1 -1
  35. package/dist/src/core/renderers/canvas/CanvasRenderer.js.map +1 -1
  36. package/dist/src/core/renderers/webgl/WebGlRenderer.d.ts +3 -1
  37. package/dist/src/core/renderers/webgl/WebGlRenderer.js +86 -60
  38. package/dist/src/core/renderers/webgl/WebGlRenderer.js.map +1 -1
  39. package/dist/src/core/renderers/webgl/internal/ShaderUtils.js +35 -35
  40. package/dist/src/core/renderers/webgl/shaders/DefaultShader.js +45 -45
  41. package/dist/src/core/renderers/webgl/shaders/DefaultShaderBatched.js +61 -61
  42. package/dist/src/core/renderers/webgl/shaders/DynamicShader.js +93 -93
  43. package/dist/src/core/renderers/webgl/shaders/RoundedRectangle.js +63 -63
  44. package/dist/src/core/renderers/webgl/shaders/SdfShader.js +62 -62
  45. package/dist/src/core/renderers/webgl/shaders/effects/BorderBottomEffect.js +15 -15
  46. package/dist/src/core/renderers/webgl/shaders/effects/BorderEffect.js +6 -6
  47. package/dist/src/core/renderers/webgl/shaders/effects/BorderLeftEffect.js +15 -15
  48. package/dist/src/core/renderers/webgl/shaders/effects/BorderRightEffect.js +15 -15
  49. package/dist/src/core/renderers/webgl/shaders/effects/BorderTopEffect.js +15 -15
  50. package/dist/src/core/renderers/webgl/shaders/effects/FadeOutEffect.js +42 -42
  51. package/dist/src/core/renderers/webgl/shaders/effects/GlitchEffect.js +44 -44
  52. package/dist/src/core/renderers/webgl/shaders/effects/GrayscaleEffect.js +3 -3
  53. package/dist/src/core/renderers/webgl/shaders/effects/HolePunchEffect.js +22 -22
  54. package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.js +28 -28
  55. package/dist/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.js +10 -10
  56. package/dist/src/core/renderers/webgl/shaders/effects/RadialProgressEffect.js +37 -37
  57. package/dist/src/core/renderers/webgl/shaders/effects/RadiusEffect.js +19 -19
  58. package/dist/src/core/shaders/webgl/Border.js +59 -59
  59. package/dist/src/core/shaders/webgl/Default.js +47 -47
  60. package/dist/src/core/shaders/webgl/DefaultBatched.js +61 -61
  61. package/dist/src/core/shaders/webgl/HolePunch.js +32 -32
  62. package/dist/src/core/shaders/webgl/LinearGradient.js +36 -36
  63. package/dist/src/core/shaders/webgl/RadialGradient.js +33 -33
  64. package/dist/src/core/shaders/webgl/Rounded.js +71 -71
  65. package/dist/src/core/shaders/webgl/RoundedWithBorder.js +66 -66
  66. package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js +79 -79
  67. package/dist/src/core/shaders/webgl/RoundedWithShadow.js +54 -54
  68. package/dist/src/core/shaders/webgl/SdfShader.js +62 -62
  69. package/dist/src/core/shaders/webgl/Shadow.js +83 -83
  70. package/dist/src/core/temp.js +77 -0
  71. package/dist/src/core/temp.js.map +1 -0
  72. package/dist/src/core/text-rendering/renderers/CanvasTextRenderer.js +5 -0
  73. package/dist/src/core/text-rendering/renderers/CanvasTextRenderer.js.map +1 -1
  74. package/dist/src/core/text-rendering/renderers/LightningTextTextureRenderer.d.ts +1 -1
  75. package/dist/src/core/text-rendering/renderers/LightningTextTextureRenderer.js +50 -2
  76. package/dist/src/core/text-rendering/renderers/LightningTextTextureRenderer.js.map +1 -1
  77. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.js +6 -2
  78. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.js.map +1 -1
  79. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText.d.ts +1 -1
  80. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText.js +66 -8
  81. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText.js.map +1 -1
  82. package/dist/src/core/text-rendering/renderers/TextRenderer.d.ts +13 -0
  83. package/dist/src/core/text-rendering/renderers/TextRenderer.js +3 -0
  84. package/dist/src/core/text-rendering/renderers/TextRenderer.js.map +1 -1
  85. package/dist/src/core/textures/ImageTexture.d.ts +1 -0
  86. package/dist/src/core/textures/ImageTexture.js +5 -3
  87. package/dist/src/core/textures/ImageTexture.js.map +1 -1
  88. package/dist/src/core/textures/Texture.d.ts +9 -2
  89. package/dist/src/core/textures/Texture.js +18 -6
  90. package/dist/src/core/textures/Texture.js.map +1 -1
  91. package/dist/src/main-api/INode.d.ts +2 -2
  92. package/dist/src/main-api/Renderer.d.ts +13 -1
  93. package/dist/src/main-api/Renderer.js +14 -2
  94. package/dist/src/main-api/Renderer.js.map +1 -1
  95. package/dist/tsconfig.dist.tsbuildinfo +1 -1
  96. package/exports/canvas-shaders.ts +28 -28
  97. package/exports/canvas.ts +45 -45
  98. package/exports/index.ts +90 -89
  99. package/exports/inspector.ts +24 -24
  100. package/exports/utils.ts +44 -44
  101. package/exports/webgl-shaders.ts +28 -28
  102. package/exports/webgl.ts +50 -50
  103. package/package.json +2 -3
  104. package/scripts/please-use-pnpm.js +13 -13
  105. package/src/common/CommonTypes.ts +146 -146
  106. package/src/common/EventEmitter.ts +77 -77
  107. package/src/common/IAnimationController.ts +92 -92
  108. package/src/common/IEventEmitter.ts +28 -28
  109. package/src/core/CoreNode.test.ts +203 -203
  110. package/src/core/CoreNode.ts +2494 -2486
  111. package/src/core/CoreShaderManager.ts +188 -193
  112. package/src/core/CoreTextNode.ts +448 -439
  113. package/src/core/CoreTextureManager.ts +601 -597
  114. package/src/core/Stage.ts +754 -738
  115. package/src/core/TextureMemoryManager.ts +395 -395
  116. package/src/core/animations/AnimationManager.ts +38 -38
  117. package/src/core/animations/CoreAnimation.ts +284 -284
  118. package/src/core/animations/CoreAnimationController.ts +157 -157
  119. package/src/core/lib/ContextSpy.ts +41 -41
  120. package/src/core/lib/ImageWorker.ts +280 -280
  121. package/src/core/lib/Matrix3d.ts +244 -244
  122. package/src/core/lib/RenderCoords.ts +71 -71
  123. package/src/core/lib/WebGlContextWrapper.ts +1374 -1374
  124. package/src/core/lib/textureCompression.ts +152 -152
  125. package/src/core/lib/textureSvg.ts +78 -78
  126. package/src/core/lib/utils.ts +386 -386
  127. package/src/core/lib/validateImageBitmap.ts +87 -76
  128. package/src/core/platform.ts +64 -64
  129. package/src/core/platforms/Platform.ts +77 -0
  130. package/src/core/platforms/web/WebPlatform.ts +84 -0
  131. package/src/core/renderers/CoreContextTexture.ts +43 -43
  132. package/src/core/renderers/CoreRenderOp.ts +22 -22
  133. package/src/core/renderers/CoreRenderer.ts +109 -107
  134. package/src/core/renderers/CoreShaderNode.ts +165 -167
  135. package/src/core/renderers/CoreShaderProgram.ts +23 -23
  136. package/src/core/renderers/canvas/CanvasRenderer.ts +298 -298
  137. package/src/core/renderers/canvas/CanvasShaderNode.ts +99 -99
  138. package/src/core/renderers/canvas/CanvasTexture.ts +156 -156
  139. package/src/core/renderers/canvas/internal/C2DShaderUtils.ts +220 -220
  140. package/src/core/renderers/canvas/internal/ColorUtils.ts +85 -85
  141. package/src/core/renderers/webgl/WebGlCtxRenderTexture.ts +86 -86
  142. package/src/core/renderers/webgl/WebGlCtxSubTexture.ts +50 -50
  143. package/src/core/renderers/webgl/WebGlCtxTexture.ts +301 -301
  144. package/src/core/renderers/webgl/WebGlRenderOp.ts +161 -161
  145. package/src/core/renderers/webgl/WebGlRenderer.ts +750 -720
  146. package/src/core/renderers/webgl/WebGlShaderNode.ts +437 -437
  147. package/src/core/renderers/webgl/WebGlShaderProgram.ts +318 -318
  148. package/src/core/renderers/webgl/internal/BufferCollection.ts +54 -54
  149. package/src/core/renderers/webgl/internal/RendererUtils.ts +155 -155
  150. package/src/core/renderers/webgl/internal/ShaderUtils.ts +281 -281
  151. package/src/core/renderers/webgl/internal/WebGlUtils.ts +35 -35
  152. package/src/core/shaders/canvas/Border.ts +78 -78
  153. package/src/core/shaders/canvas/HolePunch.ts +62 -62
  154. package/src/core/shaders/canvas/LinearGradient.ts +69 -69
  155. package/src/core/shaders/canvas/RadialGradient.ts +113 -113
  156. package/src/core/shaders/canvas/Rounded.ts +55 -55
  157. package/src/core/shaders/canvas/RoundedWithBorder.ts +68 -68
  158. package/src/core/shaders/canvas/RoundedWithBorderAndShadow.ts +88 -88
  159. package/src/core/shaders/canvas/RoundedWithShadow.ts +69 -69
  160. package/src/core/shaders/canvas/Shadow.ts +52 -52
  161. package/src/core/shaders/canvas/utils/render.ts +151 -151
  162. package/src/core/shaders/templates/BorderTemplate.ts +115 -115
  163. package/src/core/shaders/templates/HolePunchTemplate.ts +82 -82
  164. package/src/core/shaders/templates/LinearGradientTemplate.ts +71 -71
  165. package/src/core/shaders/templates/RadialGradientTemplate.ts +81 -81
  166. package/src/core/shaders/templates/RoundedTemplate.ts +98 -98
  167. package/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.ts +38 -38
  168. package/src/core/shaders/templates/RoundedWithBorderTemplate.ts +35 -35
  169. package/src/core/shaders/templates/RoundedWithShadowTemplate.ts +35 -35
  170. package/src/core/shaders/templates/ShadowTemplate.ts +106 -106
  171. package/src/core/shaders/templates/shaderUtils.ts +47 -47
  172. package/src/core/shaders/webgl/Border.ts +96 -96
  173. package/src/core/shaders/webgl/Default.ts +89 -89
  174. package/src/core/shaders/webgl/DefaultBatched.ts +129 -129
  175. package/src/core/shaders/webgl/HolePunch.ts +78 -78
  176. package/src/core/shaders/webgl/LinearGradient.ts +81 -81
  177. package/src/core/shaders/webgl/RadialGradient.ts +84 -84
  178. package/src/core/shaders/webgl/Rounded.ts +117 -117
  179. package/src/core/shaders/webgl/RoundedWithBorder.ts +114 -114
  180. package/src/core/shaders/webgl/RoundedWithBorderAndShadow.ts +133 -133
  181. package/src/core/shaders/webgl/RoundedWithShadow.ts +98 -98
  182. package/src/core/shaders/webgl/SdfShader.ts +134 -134
  183. package/src/core/shaders/webgl/Shadow.ts +115 -115
  184. package/src/core/text-rendering/TextRenderingUtils.ts +36 -36
  185. package/src/core/text-rendering/TextTextureRendererUtils.ts +263 -263
  186. package/src/core/text-rendering/TrFontManager.ts +183 -183
  187. package/src/core/text-rendering/font-face-types/SdfTrFontFace/SdfTrFontFace.ts +176 -176
  188. package/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/FontShaper.ts +139 -139
  189. package/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/SdfFontShaper.test.ts +173 -173
  190. package/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/SdfFontShaper.ts +171 -171
  191. package/src/core/text-rendering/font-face-types/TrFontFace.ts +187 -187
  192. package/src/core/text-rendering/font-face-types/WebTrFontFace.ts +94 -94
  193. package/src/core/text-rendering/font-face-types/utils.ts +39 -39
  194. package/src/core/text-rendering/renderers/CanvasTextRenderer.ts +514 -509
  195. package/src/core/text-rendering/renderers/LightningTextTextureRenderer.ts +863 -815
  196. package/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.ts +846 -840
  197. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/PeekableGenerator.test.ts +48 -48
  198. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/PeekableGenerator.ts +66 -66
  199. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/SpecialCodepoints.ts +52 -52
  200. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/constants.ts +32 -32
  201. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/getStartConditions.ts +117 -117
  202. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/getUnicodeCodepoints.test.ts +133 -133
  203. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/getUnicodeCodepoints.ts +38 -38
  204. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText.ts +497 -408
  205. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/measureText.test.ts +49 -49
  206. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/measureText.ts +52 -52
  207. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/setRenderWindow.test.ts +205 -205
  208. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/setRenderWindow.ts +93 -93
  209. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/util.ts +40 -40
  210. package/src/core/text-rendering/renderers/TextRenderer.ts +567 -550
  211. package/src/core/textures/ColorTexture.ts +102 -102
  212. package/src/core/textures/ImageTexture.ts +410 -399
  213. package/src/core/textures/NoiseTexture.ts +104 -104
  214. package/src/core/textures/RenderTexture.ts +85 -85
  215. package/src/core/textures/SubTexture.ts +205 -205
  216. package/src/core/textures/Texture.ts +358 -337
  217. package/src/core/utils.ts +227 -227
  218. package/src/env.d.ts +7 -7
  219. package/src/main-api/INode.ts +100 -99
  220. package/src/main-api/Inspector.ts +522 -522
  221. package/src/main-api/Renderer.ts +675 -649
  222. package/src/main-api/utils.ts +45 -45
  223. package/src/utils.ts +267 -267
  224. package/dist/exports/core-api.d.ts +0 -74
  225. package/dist/exports/core-api.js +0 -96
  226. package/dist/exports/core-api.js.map +0 -1
  227. package/dist/exports/main-api.d.ts +0 -30
  228. package/dist/exports/main-api.js +0 -45
  229. package/dist/exports/main-api.js.map +0 -1
  230. package/dist/src/core/CoreExtension.d.ts +0 -12
  231. package/dist/src/core/CoreExtension.js +0 -29
  232. package/dist/src/core/CoreExtension.js.map +0 -1
  233. package/dist/src/core/CoreStuff.js +0 -138
  234. package/dist/src/core/CoreStuff.js.map +0 -1
  235. package/dist/src/core/CoreTexturizer.d.ts +0 -14
  236. package/dist/src/core/CoreTexturizer.js +0 -47
  237. package/dist/src/core/CoreTexturizer.js.map +0 -1
  238. package/dist/src/core/LngNode.d.ts +0 -736
  239. package/dist/src/core/LngNode.js +0 -1174
  240. package/dist/src/core/LngNode.js.map +0 -1
  241. package/dist/src/core/Matrix2DContext.d.ts +0 -15
  242. package/dist/src/core/Matrix2DContext.js +0 -45
  243. package/dist/src/core/Matrix2DContext.js.map +0 -1
  244. package/dist/src/core/ShaderNode.d.ts +0 -10
  245. package/dist/src/core/ShaderNode.js +0 -30
  246. package/dist/src/core/ShaderNode.js.map +0 -1
  247. package/dist/src/core/TextNode.d.ts +0 -103
  248. package/dist/src/core/TextNode.js +0 -331
  249. package/dist/src/core/TextNode.js.map +0 -1
  250. package/dist/src/core/lib/Coords.d.ts +0 -14
  251. package/dist/src/core/lib/Coords.js +0 -55
  252. package/dist/src/core/lib/Coords.js.map +0 -1
  253. package/dist/src/core/lib/glm/common.d.ts +0 -162
  254. package/dist/src/core/lib/glm/common.js +0 -81
  255. package/dist/src/core/lib/glm/common.js.map +0 -1
  256. package/dist/src/core/lib/glm/index.d.ts +0 -11
  257. package/dist/src/core/lib/glm/index.js +0 -30
  258. package/dist/src/core/lib/glm/index.js.map +0 -1
  259. package/dist/src/core/lib/glm/mat2.d.ts +0 -219
  260. package/dist/src/core/lib/glm/mat2.js +0 -396
  261. package/dist/src/core/lib/glm/mat2.js.map +0 -1
  262. package/dist/src/core/lib/glm/mat2d.d.ts +0 -237
  263. package/dist/src/core/lib/glm/mat2d.js +0 -442
  264. package/dist/src/core/lib/glm/mat2d.js.map +0 -1
  265. package/dist/src/core/lib/glm/mat3.d.ts +0 -283
  266. package/dist/src/core/lib/glm/mat3.js +0 -680
  267. package/dist/src/core/lib/glm/mat3.js.map +0 -1
  268. package/dist/src/core/lib/glm/mat4.d.ts +0 -550
  269. package/dist/src/core/lib/glm/mat4.js +0 -1802
  270. package/dist/src/core/lib/glm/mat4.js.map +0 -1
  271. package/dist/src/core/lib/glm/quat.d.ts +0 -363
  272. package/dist/src/core/lib/glm/quat.js +0 -693
  273. package/dist/src/core/lib/glm/quat.js.map +0 -1
  274. package/dist/src/core/lib/glm/quat2.d.ts +0 -356
  275. package/dist/src/core/lib/glm/quat2.js +0 -754
  276. package/dist/src/core/lib/glm/quat2.js.map +0 -1
  277. package/dist/src/core/lib/glm/vec2.d.ts +0 -365
  278. package/dist/src/core/lib/glm/vec2.js +0 -569
  279. package/dist/src/core/lib/glm/vec2.js.map +0 -1
  280. package/dist/src/core/lib/glm/vec3.d.ts +0 -406
  281. package/dist/src/core/lib/glm/vec3.js +0 -720
  282. package/dist/src/core/lib/glm/vec3.js.map +0 -1
  283. package/dist/src/core/lib/glm/vec4.d.ts +0 -330
  284. package/dist/src/core/lib/glm/vec4.js +0 -608
  285. package/dist/src/core/lib/glm/vec4.js.map +0 -1
  286. package/dist/src/core/renderers/CoreShaderManager.d.ts +0 -19
  287. package/dist/src/core/renderers/CoreShaderManager.js +0 -33
  288. package/dist/src/core/renderers/CoreShaderManager.js.map +0 -1
  289. package/dist/src/core/renderers/webgl/WebGlCoreShaderManager.d.ts +0 -27
  290. package/dist/src/core/renderers/webgl/WebGlCoreShaderManager.js +0 -82
  291. package/dist/src/core/renderers/webgl/WebGlCoreShaderManager.js.map +0 -1
  292. package/dist/src/core/renderers/webgl/WebGlCoreShaderProgram.d.ts +0 -11
  293. package/dist/src/core/renderers/webgl/WebGlCoreShaderProgram.js +0 -34
  294. package/dist/src/core/renderers/webgl/WebGlCoreShaderProgram.js.map +0 -1
  295. package/dist/src/core/scene/Scene.d.ts +0 -59
  296. package/dist/src/core/scene/Scene.js +0 -106
  297. package/dist/src/core/scene/Scene.js.map +0 -1
  298. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/makeRenderWindow.d.ts +0 -20
  299. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/makeRenderWindow.js +0 -55
  300. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/makeRenderWindow.js.map +0 -1
  301. package/dist/src/main-api/ICoreDriver.d.ts +0 -27
  302. package/dist/src/main-api/ICoreDriver.js +0 -20
  303. package/dist/src/main-api/ICoreDriver.js.map +0 -1
  304. package/dist/src/main-api/IRenderDriver.d.ts +0 -20
  305. package/dist/src/main-api/IRenderDriver.js.map +0 -1
  306. package/dist/src/main-api/IShaderController.d.ts +0 -14
  307. package/dist/src/main-api/IShaderController.js +0 -30
  308. package/dist/src/main-api/IShaderController.js.map +0 -1
  309. package/dist/src/main-api/IShaderNode.d.ts +0 -17
  310. package/dist/src/main-api/IShaderNode.js +0 -19
  311. package/dist/src/main-api/IShaderNode.js.map +0 -1
  312. package/dist/src/main-api/RendererMain.d.ts +0 -375
  313. package/dist/src/main-api/RendererMain.js +0 -365
  314. package/dist/src/main-api/RendererMain.js.map +0 -1
  315. package/dist/src/main-api/texture-usage-trackers/FinalizationRegistryTextureUsageTracker.d.ts +0 -9
  316. package/dist/src/main-api/texture-usage-trackers/FinalizationRegistryTextureUsageTracker.js +0 -38
  317. package/dist/src/main-api/texture-usage-trackers/FinalizationRegistryTextureUsageTracker.js.map +0 -1
  318. package/dist/src/main-api/texture-usage-trackers/ManualCountTextureUsageTracker.d.ts +0 -56
  319. package/dist/src/main-api/texture-usage-trackers/ManualCountTextureUsageTracker.js +0 -101
  320. package/dist/src/main-api/texture-usage-trackers/ManualCountTextureUsageTracker.js.map +0 -1
  321. package/dist/src/main-api/texture-usage-trackers/TextureUsageTracker.d.ts +0 -32
  322. package/dist/src/main-api/texture-usage-trackers/TextureUsageTracker.js +0 -28
  323. package/dist/src/main-api/texture-usage-trackers/TextureUsageTracker.js.map +0 -1
  324. package/dist/src/render-drivers/main/MainCoreDriver.d.ts +0 -24
  325. package/dist/src/render-drivers/main/MainCoreDriver.js +0 -118
  326. package/dist/src/render-drivers/main/MainCoreDriver.js.map +0 -1
  327. package/dist/src/render-drivers/main/MainOnlyNode.d.ts +0 -99
  328. package/dist/src/render-drivers/main/MainOnlyNode.js +0 -396
  329. package/dist/src/render-drivers/main/MainOnlyNode.js.map +0 -1
  330. package/dist/src/render-drivers/main/MainOnlyShaderController.d.ts +0 -6
  331. package/dist/src/render-drivers/main/MainOnlyShaderController.js +0 -15
  332. package/dist/src/render-drivers/main/MainOnlyShaderController.js.map +0 -1
  333. package/dist/src/render-drivers/main/MainOnlyShaderNode.d.ts +0 -7
  334. package/dist/src/render-drivers/main/MainOnlyShaderNode.js +0 -34
  335. package/dist/src/render-drivers/main/MainOnlyShaderNode.js.map +0 -1
  336. package/dist/src/render-drivers/main/MainOnlyTextNode.d.ts +0 -47
  337. package/dist/src/render-drivers/main/MainOnlyTextNode.js +0 -205
  338. package/dist/src/render-drivers/main/MainOnlyTextNode.js.map +0 -1
  339. package/dist/src/render-drivers/main/MainRenderDriver.d.ts +0 -17
  340. package/dist/src/render-drivers/main/MainRenderDriver.js +0 -88
  341. package/dist/src/render-drivers/main/MainRenderDriver.js.map +0 -1
  342. package/dist/src/render-drivers/threadx/NodeStruct.d.ts +0 -90
  343. package/dist/src/render-drivers/threadx/NodeStruct.js +0 -281
  344. package/dist/src/render-drivers/threadx/NodeStruct.js.map +0 -1
  345. package/dist/src/render-drivers/threadx/SharedNode.d.ts +0 -39
  346. package/dist/src/render-drivers/threadx/SharedNode.js +0 -60
  347. package/dist/src/render-drivers/threadx/SharedNode.js.map +0 -1
  348. package/dist/src/render-drivers/threadx/TextNodeStruct.d.ts +0 -44
  349. package/dist/src/render-drivers/threadx/TextNodeStruct.js +0 -201
  350. package/dist/src/render-drivers/threadx/TextNodeStruct.js.map +0 -1
  351. package/dist/src/render-drivers/threadx/ThreadXCoreDriver.d.ts +0 -28
  352. package/dist/src/render-drivers/threadx/ThreadXCoreDriver.js +0 -234
  353. package/dist/src/render-drivers/threadx/ThreadXCoreDriver.js.map +0 -1
  354. package/dist/src/render-drivers/threadx/ThreadXMainAnimationController.d.ts +0 -20
  355. package/dist/src/render-drivers/threadx/ThreadXMainAnimationController.js +0 -84
  356. package/dist/src/render-drivers/threadx/ThreadXMainAnimationController.js.map +0 -1
  357. package/dist/src/render-drivers/threadx/ThreadXMainNode.d.ts +0 -44
  358. package/dist/src/render-drivers/threadx/ThreadXMainNode.js +0 -154
  359. package/dist/src/render-drivers/threadx/ThreadXMainNode.js.map +0 -1
  360. package/dist/src/render-drivers/threadx/ThreadXMainShaderController.d.ts +0 -6
  361. package/dist/src/render-drivers/threadx/ThreadXMainShaderController.js +0 -16
  362. package/dist/src/render-drivers/threadx/ThreadXMainShaderController.js.map +0 -1
  363. package/dist/src/render-drivers/threadx/ThreadXMainShaderNode.d.ts +0 -7
  364. package/dist/src/render-drivers/threadx/ThreadXMainShaderNode.js +0 -15
  365. package/dist/src/render-drivers/threadx/ThreadXMainShaderNode.js.map +0 -1
  366. package/dist/src/render-drivers/threadx/ThreadXMainTextNode.d.ts +0 -28
  367. package/dist/src/render-drivers/threadx/ThreadXMainTextNode.js +0 -55
  368. package/dist/src/render-drivers/threadx/ThreadXMainTextNode.js.map +0 -1
  369. package/dist/src/render-drivers/threadx/ThreadXRenderDriver.d.ts +0 -21
  370. package/dist/src/render-drivers/threadx/ThreadXRenderDriver.js +0 -198
  371. package/dist/src/render-drivers/threadx/ThreadXRenderDriver.js.map +0 -1
  372. package/dist/src/render-drivers/threadx/ThreadXRendererMessage.d.ts +0 -70
  373. package/dist/src/render-drivers/threadx/ThreadXRendererMessage.js +0 -32
  374. package/dist/src/render-drivers/threadx/ThreadXRendererMessage.js.map +0 -1
  375. package/dist/src/render-drivers/threadx/worker/ThreadXRendererNode.d.ts +0 -19
  376. package/dist/src/render-drivers/threadx/worker/ThreadXRendererNode.js +0 -177
  377. package/dist/src/render-drivers/threadx/worker/ThreadXRendererNode.js.map +0 -1
  378. package/dist/src/render-drivers/threadx/worker/ThreadXRendererTextNode.d.ts +0 -27
  379. package/dist/src/render-drivers/threadx/worker/ThreadXRendererTextNode.js +0 -108
  380. package/dist/src/render-drivers/threadx/worker/ThreadXRendererTextNode.js.map +0 -1
  381. package/dist/src/render-drivers/threadx/worker/renderer.d.ts +0 -1
  382. package/dist/src/render-drivers/threadx/worker/renderer.js +0 -145
  383. package/dist/src/render-drivers/threadx/worker/renderer.js.map +0 -1
  384. package/dist/src/render-drivers/utils.d.ts +0 -12
  385. package/dist/src/render-drivers/utils.js +0 -69
  386. package/dist/src/render-drivers/utils.js.map +0 -1
  387. /package/dist/src/core/{CoreStuff.d.ts → temp.d.ts} +0 -0
@@ -1,1802 +0,0 @@
1
- /*
2
- * If not stated otherwise in this file or this component's LICENSE file the
3
- * following copyright and licenses apply:
4
- *
5
- * Copyright 2023 Comcast Cable Communications Management, LLC.
6
- *
7
- * Licensed under the Apache License, Version 2.0 (the License);
8
- * you may not use this file except in compliance with the License.
9
- * You may obtain a copy of the License at
10
- *
11
- * http://www.apache.org/licenses/LICENSE-2.0
12
- *
13
- * Unless required by applicable law or agreed to in writing, software
14
- * distributed under the License is distributed on an "AS IS" BASIS,
15
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- * See the License for the specific language governing permissions and
17
- * limitations under the License.
18
- */
19
- import { getMatrixArrayType, EPSILON, } from './common.js';
20
- /**
21
- * Creates a new identity Mat4
22
- *
23
- * @returns {Mat4} a new 4x4 matrix
24
- */
25
- export function create() {
26
- const out = getMatrixArrayType(16);
27
- if (!(out instanceof Float32Array)) {
28
- out[1] = 0;
29
- out[2] = 0;
30
- out[3] = 0;
31
- out[4] = 0;
32
- out[6] = 0;
33
- out[7] = 0;
34
- out[8] = 0;
35
- out[9] = 0;
36
- out[11] = 0;
37
- out[12] = 0;
38
- out[13] = 0;
39
- out[14] = 0;
40
- }
41
- out[0] = 1;
42
- out[5] = 1;
43
- out[10] = 1;
44
- out[15] = 1;
45
- return out;
46
- }
47
- /**
48
- * Creates a new Mat4 initialized with values from an existing matrix
49
- *
50
- * @param {Mat4} a matrix to clone
51
- * @returns {Mat4} a new 4x4 matrix
52
- */
53
- export function clone(a) {
54
- const out = getMatrixArrayType(16);
55
- out[0] = a[0];
56
- out[1] = a[1];
57
- out[2] = a[2];
58
- out[3] = a[3];
59
- out[4] = a[4];
60
- out[5] = a[5];
61
- out[6] = a[6];
62
- out[7] = a[7];
63
- out[8] = a[8];
64
- out[9] = a[9];
65
- out[10] = a[10];
66
- out[11] = a[11];
67
- out[12] = a[12];
68
- out[13] = a[13];
69
- out[14] = a[14];
70
- out[15] = a[15];
71
- return out;
72
- }
73
- /**
74
- * Copy the values from one Mat4 to another
75
- *
76
- * @param {Mat4} out the receiving matrix
77
- * @param {Mat4} a the source matrix
78
- * @returns {Mat4} out
79
- */
80
- export function copy(out, a) {
81
- out[0] = a[0];
82
- out[1] = a[1];
83
- out[2] = a[2];
84
- out[3] = a[3];
85
- out[4] = a[4];
86
- out[5] = a[5];
87
- out[6] = a[6];
88
- out[7] = a[7];
89
- out[8] = a[8];
90
- out[9] = a[9];
91
- out[10] = a[10];
92
- out[11] = a[11];
93
- out[12] = a[12];
94
- out[13] = a[13];
95
- out[14] = a[14];
96
- out[15] = a[15];
97
- return out;
98
- }
99
- /**
100
- * Create a new Mat4 with the given values
101
- *
102
- * @param {Number} m00 Component in column 0, row 0 position (index 0)
103
- * @param {Number} m01 Component in column 0, row 1 position (index 1)
104
- * @param {Number} m02 Component in column 0, row 2 position (index 2)
105
- * @param {Number} m03 Component in column 0, row 3 position (index 3)
106
- * @param {Number} m10 Component in column 1, row 0 position (index 4)
107
- * @param {Number} m11 Component in column 1, row 1 position (index 5)
108
- * @param {Number} m12 Component in column 1, row 2 position (index 6)
109
- * @param {Number} m13 Component in column 1, row 3 position (index 7)
110
- * @param {Number} m20 Component in column 2, row 0 position (index 8)
111
- * @param {Number} m21 Component in column 2, row 1 position (index 9)
112
- * @param {Number} m22 Component in column 2, row 2 position (index 10)
113
- * @param {Number} m23 Component in column 2, row 3 position (index 11)
114
- * @param {Number} m30 Component in column 3, row 0 position (index 12)
115
- * @param {Number} m31 Component in column 3, row 1 position (index 13)
116
- * @param {Number} m32 Component in column 3, row 2 position (index 14)
117
- * @param {Number} m33 Component in column 3, row 3 position (index 15)
118
- * @returns {Mat4} A new Mat4
119
- */
120
- export function fromValues(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
121
- const out = getMatrixArrayType(16);
122
- out[0] = m00;
123
- out[1] = m01;
124
- out[2] = m02;
125
- out[3] = m03;
126
- out[4] = m10;
127
- out[5] = m11;
128
- out[6] = m12;
129
- out[7] = m13;
130
- out[8] = m20;
131
- out[9] = m21;
132
- out[10] = m22;
133
- out[11] = m23;
134
- out[12] = m30;
135
- out[13] = m31;
136
- out[14] = m32;
137
- out[15] = m33;
138
- return out;
139
- }
140
- /**
141
- * Set the components of a Mat4 to the given values
142
- *
143
- * @param {Mat4} out the receiving matrix
144
- * @param {Number} m00 Component in column 0, row 0 position (index 0)
145
- * @param {Number} m01 Component in column 0, row 1 position (index 1)
146
- * @param {Number} m02 Component in column 0, row 2 position (index 2)
147
- * @param {Number} m03 Component in column 0, row 3 position (index 3)
148
- * @param {Number} m10 Component in column 1, row 0 position (index 4)
149
- * @param {Number} m11 Component in column 1, row 1 position (index 5)
150
- * @param {Number} m12 Component in column 1, row 2 position (index 6)
151
- * @param {Number} m13 Component in column 1, row 3 position (index 7)
152
- * @param {Number} m20 Component in column 2, row 0 position (index 8)
153
- * @param {Number} m21 Component in column 2, row 1 position (index 9)
154
- * @param {Number} m22 Component in column 2, row 2 position (index 10)
155
- * @param {Number} m23 Component in column 2, row 3 position (index 11)
156
- * @param {Number} m30 Component in column 3, row 0 position (index 12)
157
- * @param {Number} m31 Component in column 3, row 1 position (index 13)
158
- * @param {Number} m32 Component in column 3, row 2 position (index 14)
159
- * @param {Number} m33 Component in column 3, row 3 position (index 15)
160
- * @returns {Mat4} out
161
- */
162
- export function set(out, m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
163
- out[0] = m00;
164
- out[1] = m01;
165
- out[2] = m02;
166
- out[3] = m03;
167
- out[4] = m10;
168
- out[5] = m11;
169
- out[6] = m12;
170
- out[7] = m13;
171
- out[8] = m20;
172
- out[9] = m21;
173
- out[10] = m22;
174
- out[11] = m23;
175
- out[12] = m30;
176
- out[13] = m31;
177
- out[14] = m32;
178
- out[15] = m33;
179
- return out;
180
- }
181
- /**
182
- * Set a Mat4 to the identity matrix
183
- *
184
- * @param {Mat4} out the receiving matrix
185
- * @returns {Mat4} out
186
- */
187
- export function identity(out) {
188
- out[0] = 1;
189
- out[1] = 0;
190
- out[2] = 0;
191
- out[3] = 0;
192
- out[4] = 0;
193
- out[5] = 1;
194
- out[6] = 0;
195
- out[7] = 0;
196
- out[8] = 0;
197
- out[9] = 0;
198
- out[10] = 1;
199
- out[11] = 0;
200
- out[12] = 0;
201
- out[13] = 0;
202
- out[14] = 0;
203
- out[15] = 1;
204
- return out;
205
- }
206
- /**
207
- * Transpose the values of a Mat4
208
- *
209
- * @param {Mat4} out the receiving matrix
210
- * @param {Mat4} a the source matrix
211
- * @returns {Mat4} out
212
- */
213
- export function transpose(out, a) {
214
- // If we are transposing ourselves we can skip a few steps but have to cache some values
215
- if (out === a) {
216
- const a01 = a[1], a02 = a[2], a03 = a[3];
217
- const a12 = a[6], a13 = a[7];
218
- const 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
- }
232
- else {
233
- out[0] = a[0];
234
- out[1] = a[4];
235
- out[2] = a[8];
236
- out[3] = a[12];
237
- out[4] = a[1];
238
- out[5] = a[5];
239
- out[6] = a[9];
240
- out[7] = a[13];
241
- out[8] = a[2];
242
- out[9] = a[6];
243
- out[10] = a[10];
244
- out[11] = a[14];
245
- out[12] = a[3];
246
- out[13] = a[7];
247
- out[14] = a[11];
248
- out[15] = a[15];
249
- }
250
- return out;
251
- }
252
- /**
253
- * Inverts a Mat4
254
- *
255
- * @param {Mat4} out the receiving matrix
256
- * @param {Mat4} a the source matrix
257
- * @returns {Mat4} out
258
- */
259
- export function invert(out, a) {
260
- const a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3];
261
- const a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7];
262
- const a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11];
263
- const a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
264
- const b00 = a00 * a11 - a01 * a10;
265
- const b01 = a00 * a12 - a02 * a10;
266
- const b02 = a00 * a13 - a03 * a10;
267
- const b03 = a01 * a12 - a02 * a11;
268
- const b04 = a01 * a13 - a03 * a11;
269
- const b05 = a02 * a13 - a03 * a12;
270
- const b06 = a20 * a31 - a21 * a30;
271
- const b07 = a20 * a32 - a22 * a30;
272
- const b08 = a20 * a33 - a23 * a30;
273
- const b09 = a21 * a32 - a22 * a31;
274
- const b10 = a21 * a33 - a23 * a31;
275
- const b11 = a22 * a33 - a23 * a32; // Calculate the determinant
276
- let det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
277
- if (!det) {
278
- return null;
279
- }
280
- det = 1.0 / det;
281
- out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
282
- out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
283
- out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
284
- out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
285
- out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
286
- out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
287
- out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
288
- out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
289
- out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
290
- out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
291
- out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
292
- out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
293
- out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
294
- out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
295
- out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
296
- out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
297
- return out;
298
- }
299
- /**
300
- * Calculates the adjugate of a Mat4
301
- *
302
- * @param {Mat4} out the receiving matrix
303
- * @param {Mat4} a the source matrix
304
- * @returns {Mat4} out
305
- */
306
- export function adjoint(out, a) {
307
- const a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3];
308
- const a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7];
309
- const a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11];
310
- const a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
311
- const b00 = a00 * a11 - a01 * a10;
312
- const b01 = a00 * a12 - a02 * a10;
313
- const b02 = a00 * a13 - a03 * a10;
314
- const b03 = a01 * a12 - a02 * a11;
315
- const b04 = a01 * a13 - a03 * a11;
316
- const b05 = a02 * a13 - a03 * a12;
317
- const b06 = a20 * a31 - a21 * a30;
318
- const b07 = a20 * a32 - a22 * a30;
319
- const b08 = a20 * a33 - a23 * a30;
320
- const b09 = a21 * a32 - a22 * a31;
321
- const b10 = a21 * a33 - a23 * a31;
322
- const b11 = a22 * a33 - a23 * a32;
323
- out[0] = a11 * b11 - a12 * b10 + a13 * b09;
324
- out[1] = a02 * b10 - a01 * b11 - a03 * b09;
325
- out[2] = a31 * b05 - a32 * b04 + a33 * b03;
326
- out[3] = a22 * b04 - a21 * b05 - a23 * b03;
327
- out[4] = a12 * b08 - a10 * b11 - a13 * b07;
328
- out[5] = a00 * b11 - a02 * b08 + a03 * b07;
329
- out[6] = a32 * b02 - a30 * b05 - a33 * b01;
330
- out[7] = a20 * b05 - a22 * b02 + a23 * b01;
331
- out[8] = a10 * b10 - a11 * b08 + a13 * b06;
332
- out[9] = a01 * b08 - a00 * b10 - a03 * b06;
333
- out[10] = a30 * b04 - a31 * b02 + a33 * b00;
334
- out[11] = a21 * b02 - a20 * b04 - a23 * b00;
335
- out[12] = a11 * b07 - a10 * b09 - a12 * b06;
336
- out[13] = a00 * b09 - a01 * b07 + a02 * b06;
337
- out[14] = a31 * b01 - a30 * b03 - a32 * b00;
338
- out[15] = a20 * b03 - a21 * b01 + a22 * b00;
339
- return out;
340
- }
341
- /**
342
- * Calculates the determinant of a Mat4
343
- *
344
- * @param {Mat4} a the source matrix
345
- * @returns {Number} determinant of a
346
- */
347
- export function determinant(a) {
348
- const a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3];
349
- const a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7];
350
- const a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11];
351
- const a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
352
- const b0 = a00 * a11 - a01 * a10;
353
- const b1 = a00 * a12 - a02 * a10;
354
- const b2 = a01 * a12 - a02 * a11;
355
- const b3 = a20 * a31 - a21 * a30;
356
- const b4 = a20 * a32 - a22 * a30;
357
- const b5 = a21 * a32 - a22 * a31;
358
- const b6 = a00 * b5 - a01 * b4 + a02 * b3;
359
- const b7 = a10 * b5 - a11 * b4 + a12 * b3;
360
- const b8 = a20 * b2 - a21 * b1 + a22 * b0;
361
- const b9 = a30 * b2 - a31 * b1 + a32 * b0; // Calculate the determinant
362
- return a13 * b6 - a03 * b7 + a33 * b8 - a23 * b9;
363
- }
364
- /**
365
- * Multiplies two Mat4s
366
- *
367
- * @param {Mat4} out the receiving matrix
368
- * @param {Mat4} a the first operand
369
- * @param {Mat4} b the second operand
370
- * @returns {Mat4} out
371
- */
372
- export function multiply(out, a, b) {
373
- const a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3];
374
- const a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7];
375
- const a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11];
376
- const a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15]; // Cache only the current line of the second matrix
377
- let b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
378
- out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
379
- out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
380
- out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
381
- out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
382
- b0 = b[4];
383
- b1 = b[5];
384
- b2 = b[6];
385
- b3 = b[7];
386
- out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
387
- out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
388
- out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
389
- out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
390
- b0 = b[8];
391
- b1 = b[9];
392
- b2 = b[10];
393
- b3 = b[11];
394
- out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
395
- out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
396
- out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
397
- out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
398
- b0 = b[12];
399
- b1 = b[13];
400
- b2 = b[14];
401
- b3 = b[15];
402
- out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
403
- out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
404
- out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
405
- out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
406
- return out;
407
- }
408
- /**
409
- * Translate a Mat4 by the given vector
410
- *
411
- * @param {Mat4} out the receiving matrix
412
- * @param {Mat4} a the matrix to translate
413
- * @param {Vec3} v vector to translate by
414
- * @returns {Mat4} out
415
- */
416
- export function translate(out, a, v) {
417
- const x = v[0], y = v[1], z = v[2];
418
- let a00, a01, a02, a03;
419
- let a10, a11, a12, a13;
420
- let a20, a21, a22, a23;
421
- if (a === out) {
422
- out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
423
- out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
424
- out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
425
- out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
426
- }
427
- else {
428
- a00 = a[0];
429
- a01 = a[1];
430
- a02 = a[2];
431
- a03 = a[3];
432
- a10 = a[4];
433
- a11 = a[5];
434
- a12 = a[6];
435
- a13 = a[7];
436
- a20 = a[8];
437
- a21 = a[9];
438
- a22 = a[10];
439
- a23 = a[11];
440
- out[0] = a00;
441
- out[1] = a01;
442
- out[2] = a02;
443
- out[3] = a03;
444
- out[4] = a10;
445
- out[5] = a11;
446
- out[6] = a12;
447
- out[7] = a13;
448
- out[8] = a20;
449
- out[9] = a21;
450
- out[10] = a22;
451
- out[11] = a23;
452
- out[12] = a00 * x + a10 * y + a20 * z + a[12];
453
- out[13] = a01 * x + a11 * y + a21 * z + a[13];
454
- out[14] = a02 * x + a12 * y + a22 * z + a[14];
455
- out[15] = a03 * x + a13 * y + a23 * z + a[15];
456
- }
457
- return out;
458
- }
459
- /**
460
- * Scales the Mat4 by the dimensions in the given Vec3 not using vectorization
461
- *
462
- * @param {Mat4} out the receiving matrix
463
- * @param {Mat4} a the matrix to scale
464
- * @param {Vec3} v the Vec3 to scale the matrix by
465
- * @returns {Mat4} out
466
- **/
467
- export function scale(out, a, v) {
468
- const x = v[0], y = v[1], z = v[2];
469
- out[0] = a[0] * x;
470
- out[1] = a[1] * x;
471
- out[2] = a[2] * x;
472
- out[3] = a[3] * x;
473
- out[4] = a[4] * y;
474
- out[5] = a[5] * y;
475
- out[6] = a[6] * y;
476
- out[7] = a[7] * y;
477
- out[8] = a[8] * z;
478
- out[9] = a[9] * z;
479
- out[10] = a[10] * z;
480
- out[11] = a[11] * z;
481
- out[12] = a[12];
482
- out[13] = a[13];
483
- out[14] = a[14];
484
- out[15] = a[15];
485
- return out;
486
- }
487
- /**
488
- * Rotates a Mat4 by the given angle around the given axis
489
- *
490
- * @param {Mat4} out the receiving matrix
491
- * @param {Mat4} a the matrix to rotate
492
- * @param {Number} rad the angle to rotate the matrix by
493
- * @param {Vec3} axis the axis to rotate around
494
- * @returns {Mat4} out
495
- */
496
- export function rotate(out, a, rad, axis) {
497
- let x = axis[0], y = axis[1], z = axis[2];
498
- let len = Math.hypot(x, y, z);
499
- const s = Math.sin(rad), c = Math.cos(rad), t = 1 - c, a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11]; // Construct the elements of the rotation matrix
500
- if (len < EPSILON) {
501
- return null;
502
- }
503
- len = 1 / len;
504
- x *= len;
505
- y *= len;
506
- z *= len;
507
- const b00 = x * x * t + c, b01 = y * x * t + z * s, b02 = z * x * t - y * s, b10 = x * y * t - z * s, b11 = y * y * t + c, b12 = z * y * t + x * s, b20 = x * z * t + y * s, b21 = y * z * t - x * s, b22 = z * z * t + c; // Perform rotation-specific matrix multiplication
508
- out[0] = a00 * b00 + a10 * b01 + a20 * b02;
509
- out[1] = a01 * b00 + a11 * b01 + a21 * b02;
510
- out[2] = a02 * b00 + a12 * b01 + a22 * b02;
511
- out[3] = a03 * b00 + a13 * b01 + a23 * b02;
512
- out[4] = a00 * b10 + a10 * b11 + a20 * b12;
513
- out[5] = a01 * b10 + a11 * b11 + a21 * b12;
514
- out[6] = a02 * b10 + a12 * b11 + a22 * b12;
515
- out[7] = a03 * b10 + a13 * b11 + a23 * b12;
516
- out[8] = a00 * b20 + a10 * b21 + a20 * b22;
517
- out[9] = a01 * b20 + a11 * b21 + a21 * b22;
518
- out[10] = a02 * b20 + a12 * b21 + a22 * b22;
519
- out[11] = a03 * b20 + a13 * b21 + a23 * b22;
520
- if (a !== out) {
521
- // If the source and destination differ, copy the unchanged last row
522
- out[12] = a[12];
523
- out[13] = a[13];
524
- out[14] = a[14];
525
- out[15] = a[15];
526
- }
527
- return out;
528
- }
529
- /**
530
- * Rotates a matrix by the given angle around the X axis
531
- *
532
- * @param {Mat4} out the receiving matrix
533
- * @param {Mat4} a the matrix to rotate
534
- * @param {Number} rad the angle to rotate the matrix by
535
- * @returns {Mat4} out
536
- */
537
- export function rotateX(out, a, rad) {
538
- const s = Math.sin(rad);
539
- const c = Math.cos(rad);
540
- const a10 = a[4];
541
- const a11 = a[5];
542
- const a12 = a[6];
543
- const a13 = a[7];
544
- const a20 = a[8];
545
- const a21 = a[9];
546
- const a22 = a[10];
547
- const a23 = a[11];
548
- if (a !== out) {
549
- // If the source and destination differ, copy the unchanged rows
550
- out[0] = a[0];
551
- out[1] = a[1];
552
- out[2] = a[2];
553
- out[3] = a[3];
554
- out[12] = a[12];
555
- out[13] = a[13];
556
- out[14] = a[14];
557
- out[15] = a[15];
558
- } // Perform axis-specific matrix multiplication
559
- out[4] = a10 * c + a20 * s;
560
- out[5] = a11 * c + a21 * s;
561
- out[6] = a12 * c + a22 * s;
562
- out[7] = a13 * c + a23 * s;
563
- out[8] = a20 * c - a10 * s;
564
- out[9] = a21 * c - a11 * s;
565
- out[10] = a22 * c - a12 * s;
566
- out[11] = a23 * c - a13 * s;
567
- return out;
568
- }
569
- /**
570
- * Rotates a matrix by the given angle around the Y axis
571
- *
572
- * @param {Mat4} out the receiving matrix
573
- * @param {Mat4} a the matrix to rotate
574
- * @param {Number} rad the angle to rotate the matrix by
575
- * @returns {Mat4} out
576
- */
577
- export function rotateY(out, a, rad) {
578
- const s = Math.sin(rad);
579
- const c = Math.cos(rad);
580
- const a00 = a[0];
581
- const a01 = a[1];
582
- const a02 = a[2];
583
- const a03 = a[3];
584
- const a20 = a[8];
585
- const a21 = a[9];
586
- const a22 = a[10];
587
- const a23 = a[11];
588
- if (a !== out) {
589
- // If the source and destination differ, copy the unchanged rows
590
- out[4] = a[4];
591
- out[5] = a[5];
592
- out[6] = a[6];
593
- out[7] = a[7];
594
- out[12] = a[12];
595
- out[13] = a[13];
596
- out[14] = a[14];
597
- out[15] = a[15];
598
- } // Perform axis-specific matrix multiplication
599
- out[0] = a00 * c - a20 * s;
600
- out[1] = a01 * c - a21 * s;
601
- out[2] = a02 * c - a22 * s;
602
- out[3] = a03 * c - a23 * s;
603
- out[8] = a00 * s + a20 * c;
604
- out[9] = a01 * s + a21 * c;
605
- out[10] = a02 * s + a22 * c;
606
- out[11] = a03 * s + a23 * c;
607
- return out;
608
- }
609
- /**
610
- * Rotates a matrix by the given angle around the Z axis
611
- *
612
- * @param {Mat4} out the receiving matrix
613
- * @param {Mat4} a the matrix to rotate
614
- * @param {Number} rad the angle to rotate the matrix by
615
- * @returns {Mat4} out
616
- */
617
- export function rotateZ(out, a, rad) {
618
- const s = Math.sin(rad);
619
- const c = Math.cos(rad);
620
- const a00 = a[0];
621
- const a01 = a[1];
622
- const a02 = a[2];
623
- const a03 = a[3];
624
- const a10 = a[4];
625
- const a11 = a[5];
626
- const a12 = a[6];
627
- const a13 = a[7];
628
- if (a !== out) {
629
- // If the source and destination differ, copy the unchanged last row
630
- out[8] = a[8];
631
- out[9] = a[9];
632
- out[10] = a[10];
633
- out[11] = a[11];
634
- out[12] = a[12];
635
- out[13] = a[13];
636
- out[14] = a[14];
637
- out[15] = a[15];
638
- } // Perform axis-specific matrix multiplication
639
- out[0] = a00 * c + a10 * s;
640
- out[1] = a01 * c + a11 * s;
641
- out[2] = a02 * c + a12 * s;
642
- out[3] = a03 * c + a13 * s;
643
- out[4] = a10 * c - a00 * s;
644
- out[5] = a11 * c - a01 * s;
645
- out[6] = a12 * c - a02 * s;
646
- out[7] = a13 * c - a03 * s;
647
- return out;
648
- }
649
- /**
650
- * Creates a matrix from a vector translation
651
- * This is equivalent to (but much faster than):
652
- *
653
- * Mat4.identity(dest);
654
- * Mat4.translate(dest, dest, vec);
655
- *
656
- * @param {Mat4} out Mat4 receiving operation result
657
- * @param {Vec3} v Translation vector
658
- * @returns {Mat4} out
659
- */
660
- export function fromTranslation(out, v) {
661
- out[0] = 1;
662
- out[1] = 0;
663
- out[2] = 0;
664
- out[3] = 0;
665
- out[4] = 0;
666
- out[5] = 1;
667
- out[6] = 0;
668
- out[7] = 0;
669
- out[8] = 0;
670
- out[9] = 0;
671
- out[10] = 1;
672
- out[11] = 0;
673
- out[12] = v[0];
674
- out[13] = v[1];
675
- out[14] = v[2];
676
- out[15] = 1;
677
- return out;
678
- }
679
- /**
680
- * Creates a matrix from a vector scaling
681
- * This is equivalent to (but much faster than):
682
- *
683
- * Mat4.identity(dest);
684
- * Mat4.scale(dest, dest, vec);
685
- *
686
- * @param {Mat4} out Mat4 receiving operation result
687
- * @param {Vec3} v Scaling vector
688
- * @returns {Mat4} out
689
- */
690
- export function fromScaling(out, v) {
691
- out[0] = v[0];
692
- out[1] = 0;
693
- out[2] = 0;
694
- out[3] = 0;
695
- out[4] = 0;
696
- out[5] = v[1];
697
- out[6] = 0;
698
- out[7] = 0;
699
- out[8] = 0;
700
- out[9] = 0;
701
- out[10] = v[2];
702
- out[11] = 0;
703
- out[12] = 0;
704
- out[13] = 0;
705
- out[14] = 0;
706
- out[15] = 1;
707
- return out;
708
- }
709
- /**
710
- * Creates a matrix from a given angle around a given axis
711
- * This is equivalent to (but much faster than):
712
- *
713
- * Mat4.identity(dest);
714
- * Mat4.rotate(dest, dest, rad, axis);
715
- *
716
- * @param {Mat4} out Mat4 receiving operation result
717
- * @param {Number} rad the angle to rotate the matrix by
718
- * @param {Vec3} axis the axis to rotate around
719
- * @returns {Mat4} out
720
- */
721
- export function fromRotation(out, rad, axis) {
722
- let x = axis[0], y = axis[1], z = axis[2];
723
- let len = Math.hypot(x, y, z);
724
- const s = Math.sin(rad), c = Math.cos(rad), t = 1 - c; // Perform rotation-specific matrix multiplication
725
- if (len < EPSILON) {
726
- return null;
727
- }
728
- len = 1 / len;
729
- x *= len;
730
- y *= len;
731
- z *= len;
732
- out[0] = x * x * t + c;
733
- out[1] = y * x * t + z * s;
734
- out[2] = z * x * t - y * s;
735
- out[3] = 0;
736
- out[4] = x * y * t - z * s;
737
- out[5] = y * y * t + c;
738
- out[6] = z * y * t + x * s;
739
- out[7] = 0;
740
- out[8] = x * z * t + y * s;
741
- out[9] = y * z * t - x * s;
742
- out[10] = z * z * t + c;
743
- out[11] = 0;
744
- out[12] = 0;
745
- out[13] = 0;
746
- out[14] = 0;
747
- out[15] = 1;
748
- return out;
749
- }
750
- /**
751
- * Creates a matrix from the given angle around the X axis
752
- * This is equivalent to (but much faster than):
753
- *
754
- * Mat4.identity(dest);
755
- * Mat4.rotateX(dest, dest, rad);
756
- *
757
- * @param {Mat4} out Mat4 receiving operation result
758
- * @param {Number} rad the angle to rotate the matrix by
759
- * @returns {Mat4} out
760
- */
761
- export function fromXRotation(out, rad) {
762
- const s = Math.sin(rad);
763
- const c = Math.cos(rad); // Perform axis-specific matrix multiplication
764
- out[0] = 1;
765
- out[1] = 0;
766
- out[2] = 0;
767
- out[3] = 0;
768
- out[4] = 0;
769
- out[5] = c;
770
- out[6] = s;
771
- out[7] = 0;
772
- out[8] = 0;
773
- out[9] = -s;
774
- out[10] = c;
775
- out[11] = 0;
776
- out[12] = 0;
777
- out[13] = 0;
778
- out[14] = 0;
779
- out[15] = 1;
780
- return out;
781
- }
782
- /**
783
- * Creates a matrix from the given angle around the Y axis
784
- * This is equivalent to (but much faster than):
785
- *
786
- * Mat4.identity(dest);
787
- * Mat4.rotateY(dest, dest, rad);
788
- *
789
- * @param {Mat4} out Mat4 receiving operation result
790
- * @param {Number} rad the angle to rotate the matrix by
791
- * @returns {Mat4} out
792
- */
793
- export function fromYRotation(out, rad) {
794
- const s = Math.sin(rad);
795
- const c = Math.cos(rad); // Perform axis-specific matrix multiplication
796
- out[0] = c;
797
- out[1] = 0;
798
- out[2] = -s;
799
- out[3] = 0;
800
- out[4] = 0;
801
- out[5] = 1;
802
- out[6] = 0;
803
- out[7] = 0;
804
- out[8] = s;
805
- out[9] = 0;
806
- out[10] = c;
807
- out[11] = 0;
808
- out[12] = 0;
809
- out[13] = 0;
810
- out[14] = 0;
811
- out[15] = 1;
812
- return out;
813
- }
814
- /**
815
- * Creates a matrix from the given angle around the Z axis
816
- * This is equivalent to (but much faster than):
817
- *
818
- * Mat4.identity(dest);
819
- * Mat4.rotateZ(dest, dest, rad);
820
- *
821
- * @param {Mat4} out Mat4 receiving operation result
822
- * @param {Number} rad the angle to rotate the matrix by
823
- * @returns {Mat4} out
824
- */
825
- export function fromZRotation(out, rad) {
826
- const s = Math.sin(rad);
827
- const c = Math.cos(rad); // Perform axis-specific matrix multiplication
828
- out[0] = c;
829
- out[1] = s;
830
- out[2] = 0;
831
- out[3] = 0;
832
- out[4] = -s;
833
- out[5] = c;
834
- out[6] = 0;
835
- out[7] = 0;
836
- out[8] = 0;
837
- out[9] = 0;
838
- out[10] = 1;
839
- out[11] = 0;
840
- out[12] = 0;
841
- out[13] = 0;
842
- out[14] = 0;
843
- out[15] = 1;
844
- return out;
845
- }
846
- /**
847
- * Creates a matrix from a quaternion rotation and vector translation
848
- * This is equivalent to (but much faster than):
849
- *
850
- * Mat4.identity(dest);
851
- * Mat4.translate(dest, vec);
852
- * let quatMat = Mat4.create();
853
- * quat4.toMat4(quat, quatMat);
854
- * Mat4.multiply(dest, quatMat);
855
- *
856
- * @param {Mat4} out Mat4 receiving operation result
857
- * @param {quat4} q Rotation quaternion
858
- * @param {Vec3} v Translation vector
859
- * @returns {Mat4} out
860
- */
861
- export function fromRotationTranslation(out, q, v) {
862
- // Quaternion math
863
- const x = q[0], y = q[1], z = q[2], w = q[3];
864
- const x2 = x + x;
865
- const y2 = y + y;
866
- const z2 = z + z;
867
- const xx = x * x2;
868
- const xy = x * y2;
869
- const xz = x * z2;
870
- const yy = y * y2;
871
- const yz = y * z2;
872
- const zz = z * z2;
873
- const wx = w * x2;
874
- const wy = w * y2;
875
- const wz = w * z2;
876
- out[0] = 1 - (yy + zz);
877
- out[1] = xy + wz;
878
- out[2] = xz - wy;
879
- out[3] = 0;
880
- out[4] = xy - wz;
881
- out[5] = 1 - (xx + zz);
882
- out[6] = yz + wx;
883
- out[7] = 0;
884
- out[8] = xz + wy;
885
- out[9] = yz - wx;
886
- out[10] = 1 - (xx + yy);
887
- out[11] = 0;
888
- out[12] = v[0];
889
- out[13] = v[1];
890
- out[14] = v[2];
891
- out[15] = 1;
892
- return out;
893
- }
894
- /**
895
- * Creates a new Mat4 from a dual quat.
896
- *
897
- * @param {Mat4} out Matrix
898
- * @param {Quat2} a Dual Quaternion
899
- * @returns {Mat4} Mat4 receiving operation result
900
- */
901
- export function fromQuat2(out, a) {
902
- const translation = getMatrixArrayType(3);
903
- const bx = -a[0], by = -a[1], bz = -a[2], bw = a[3], ax = a[4], ay = a[5], az = a[6], aw = a[7];
904
- const magnitude = bx * bx + by * by + bz * bz + bw * bw; //Only scale if it makes sense
905
- if (magnitude > 0) {
906
- translation[0] = ((ax * bw + aw * bx + ay * bz - az * by) * 2) / magnitude;
907
- translation[1] = ((ay * bw + aw * by + az * bx - ax * bz) * 2) / magnitude;
908
- translation[2] = ((az * bw + aw * bz + ax * by - ay * bx) * 2) / magnitude;
909
- }
910
- else {
911
- translation[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2;
912
- translation[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2;
913
- translation[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2;
914
- }
915
- fromRotationTranslation(out, a, translation);
916
- return out;
917
- }
918
- /**
919
- * Returns the translation vector component of a transformation
920
- * matrix. If a matrix is built with fromRotationTranslation,
921
- * the returned vector will be the same as the translation vector
922
- * originally supplied.
923
- * @param {Vec3} out Vector to receive translation component
924
- * @param {Mat4} mat Matrix to be decomposed (input)
925
- * @return {Vec3} out
926
- */
927
- export function getTranslation(out, mat) {
928
- out[0] = mat[12];
929
- out[1] = mat[13];
930
- out[2] = mat[14];
931
- return out;
932
- }
933
- /**
934
- * Returns the scaling factor component of a transformation
935
- * matrix. If a matrix is built with fromRotationTranslationScale
936
- * with a normalized Quaternion paramter, the returned vector will be
937
- * the same as the scaling vector
938
- * originally supplied.
939
- * @param {Vec3} out Vector to receive scaling factor component
940
- * @param {Mat4} mat Matrix to be decomposed (input)
941
- * @return {Vec3} out
942
- */
943
- export function getScaling(out, mat) {
944
- const m11 = mat[0];
945
- const m12 = mat[1];
946
- const m13 = mat[2];
947
- const m21 = mat[4];
948
- const m22 = mat[5];
949
- const m23 = mat[6];
950
- const m31 = mat[8];
951
- const m32 = mat[9];
952
- const m33 = mat[10];
953
- out[0] = Math.hypot(m11, m12, m13);
954
- out[1] = Math.hypot(m21, m22, m23);
955
- out[2] = Math.hypot(m31, m32, m33);
956
- return out;
957
- }
958
- /**
959
- * Returns a quaternion representing the rotational component
960
- * of a transformation matrix. If a matrix is built with
961
- * fromRotationTranslation, the returned quaternion will be the
962
- * same as the quaternion originally supplied.
963
- * @param {quat} out Quaternion to receive the rotation component
964
- * @param {Mat4} mat Matrix to be decomposed (input)
965
- * @return {quat} out
966
- */
967
- export function getRotation(out, mat) {
968
- const scaling = getMatrixArrayType(3);
969
- getScaling(scaling, mat);
970
- const is1 = 1 / scaling[0];
971
- const is2 = 1 / scaling[1];
972
- const is3 = 1 / scaling[2];
973
- const sm11 = mat[0] * is1;
974
- const sm12 = mat[1] * is2;
975
- const sm13 = mat[2] * is3;
976
- const sm21 = mat[4] * is1;
977
- const sm22 = mat[5] * is2;
978
- const sm23 = mat[6] * is3;
979
- const sm31 = mat[8] * is1;
980
- const sm32 = mat[9] * is2;
981
- const sm33 = mat[10] * is3;
982
- const trace = sm11 + sm22 + sm33;
983
- let S = 0;
984
- if (trace > 0) {
985
- S = Math.sqrt(trace + 1.0) * 2;
986
- out[3] = 0.25 * S;
987
- out[0] = (sm23 - sm32) / S;
988
- out[1] = (sm31 - sm13) / S;
989
- out[2] = (sm12 - sm21) / S;
990
- }
991
- else if (sm11 > sm22 && sm11 > sm33) {
992
- S = Math.sqrt(1.0 + sm11 - sm22 - sm33) * 2;
993
- out[3] = (sm23 - sm32) / S;
994
- out[0] = 0.25 * S;
995
- out[1] = (sm12 + sm21) / S;
996
- out[2] = (sm31 + sm13) / S;
997
- }
998
- else if (sm22 > sm33) {
999
- S = Math.sqrt(1.0 + sm22 - sm11 - sm33) * 2;
1000
- out[3] = (sm31 - sm13) / S;
1001
- out[0] = (sm12 + sm21) / S;
1002
- out[1] = 0.25 * S;
1003
- out[2] = (sm23 + sm32) / S;
1004
- }
1005
- else {
1006
- S = Math.sqrt(1.0 + sm33 - sm11 - sm22) * 2;
1007
- out[3] = (sm12 - sm21) / S;
1008
- out[0] = (sm31 + sm13) / S;
1009
- out[1] = (sm23 + sm32) / S;
1010
- out[2] = 0.25 * S;
1011
- }
1012
- return out;
1013
- }
1014
- /**
1015
- * Decomposes a transformation matrix into its rotation, translation
1016
- * and scale components. Returns only the rotation component
1017
- * @param {quat} out_r Quaternion to receive the rotation component
1018
- * @param {Vec3} out_t Vector to receive the translation vector
1019
- * @param {Vec3} out_s Vector to receive the scaling factor
1020
- * @param {Mat4} mat Matrix to be decomposed (input)
1021
- * @returns {quat} out_r
1022
- */
1023
- export function decompose(out_r, out_t, out_s, mat) {
1024
- out_t[0] = mat[12];
1025
- out_t[1] = mat[13];
1026
- out_t[2] = mat[14];
1027
- const m11 = mat[0];
1028
- const m12 = mat[1];
1029
- const m13 = mat[2];
1030
- const m21 = mat[4];
1031
- const m22 = mat[5];
1032
- const m23 = mat[6];
1033
- const m31 = mat[8];
1034
- const m32 = mat[9];
1035
- const m33 = mat[10];
1036
- out_s[0] = Math.hypot(m11, m12, m13);
1037
- out_s[1] = Math.hypot(m21, m22, m23);
1038
- out_s[2] = Math.hypot(m31, m32, m33);
1039
- const is1 = 1 / out_s[0];
1040
- const is2 = 1 / out_s[1];
1041
- const is3 = 1 / out_s[2];
1042
- const sm11 = m11 * is1;
1043
- const sm12 = m12 * is2;
1044
- const sm13 = m13 * is3;
1045
- const sm21 = m21 * is1;
1046
- const sm22 = m22 * is2;
1047
- const sm23 = m23 * is3;
1048
- const sm31 = m31 * is1;
1049
- const sm32 = m32 * is2;
1050
- const sm33 = m33 * is3;
1051
- const trace = sm11 + sm22 + sm33;
1052
- let S = 0;
1053
- if (trace > 0) {
1054
- S = Math.sqrt(trace + 1.0) * 2;
1055
- out_r[3] = 0.25 * S;
1056
- out_r[0] = (sm23 - sm32) / S;
1057
- out_r[1] = (sm31 - sm13) / S;
1058
- out_r[2] = (sm12 - sm21) / S;
1059
- }
1060
- else if (sm11 > sm22 && sm11 > sm33) {
1061
- S = Math.sqrt(1.0 + sm11 - sm22 - sm33) * 2;
1062
- out_r[3] = (sm23 - sm32) / S;
1063
- out_r[0] = 0.25 * S;
1064
- out_r[1] = (sm12 + sm21) / S;
1065
- out_r[2] = (sm31 + sm13) / S;
1066
- }
1067
- else if (sm22 > sm33) {
1068
- S = Math.sqrt(1.0 + sm22 - sm11 - sm33) * 2;
1069
- out_r[3] = (sm31 - sm13) / S;
1070
- out_r[0] = (sm12 + sm21) / S;
1071
- out_r[1] = 0.25 * S;
1072
- out_r[2] = (sm23 + sm32) / S;
1073
- }
1074
- else {
1075
- S = Math.sqrt(1.0 + sm33 - sm11 - sm22) * 2;
1076
- out_r[3] = (sm12 - sm21) / S;
1077
- out_r[0] = (sm31 + sm13) / S;
1078
- out_r[1] = (sm23 + sm32) / S;
1079
- out_r[2] = 0.25 * S;
1080
- }
1081
- return out_r;
1082
- }
1083
- /**
1084
- * Creates a matrix from a quaternion rotation, vector translation and vector scale
1085
- * This is equivalent to (but much faster than):
1086
- *
1087
- * Mat4.identity(dest);
1088
- * Mat4.translate(dest, vec);
1089
- * let quatMat = Mat4.create();
1090
- * quat4.toMat4(quat, quatMat);
1091
- * Mat4.multiply(dest, quatMat);
1092
- * Mat4.scale(dest, scale)
1093
- *
1094
- * @param {Mat4} out Mat4 receiving operation result
1095
- * @param {quat4} q Rotation quaternion
1096
- * @param {Vec3} v Translation vector
1097
- * @param {Vec3} s Scaling vector
1098
- * @returns {Mat4} out
1099
- */
1100
- export function fromRotationTranslationScale(out, q, v, s) {
1101
- // Quaternion math
1102
- const x = q[0], y = q[1], z = q[2], w = q[3];
1103
- const x2 = x + x;
1104
- const y2 = y + y;
1105
- const z2 = z + z;
1106
- const xx = x * x2;
1107
- const xy = x * y2;
1108
- const xz = x * z2;
1109
- const yy = y * y2;
1110
- const yz = y * z2;
1111
- const zz = z * z2;
1112
- const wx = w * x2;
1113
- const wy = w * y2;
1114
- const wz = w * z2;
1115
- const sx = s[0];
1116
- const sy = s[1];
1117
- const sz = s[2];
1118
- out[0] = (1 - (yy + zz)) * sx;
1119
- out[1] = (xy + wz) * sx;
1120
- out[2] = (xz - wy) * sx;
1121
- out[3] = 0;
1122
- out[4] = (xy - wz) * sy;
1123
- out[5] = (1 - (xx + zz)) * sy;
1124
- out[6] = (yz + wx) * sy;
1125
- out[7] = 0;
1126
- out[8] = (xz + wy) * sz;
1127
- out[9] = (yz - wx) * sz;
1128
- out[10] = (1 - (xx + yy)) * sz;
1129
- out[11] = 0;
1130
- out[12] = v[0];
1131
- out[13] = v[1];
1132
- out[14] = v[2];
1133
- out[15] = 1;
1134
- return out;
1135
- }
1136
- /**
1137
- * Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin
1138
- * This is equivalent to (but much faster than):
1139
- *
1140
- * Mat4.identity(dest);
1141
- * Mat4.translate(dest, vec);
1142
- * Mat4.translate(dest, origin);
1143
- * let quatMat = Mat4.create();
1144
- * quat4.toMat4(quat, quatMat);
1145
- * Mat4.multiply(dest, quatMat);
1146
- * Mat4.scale(dest, scale)
1147
- * Mat4.translate(dest, negativeOrigin);
1148
- *
1149
- * @param {Mat4} out Mat4 receiving operation result
1150
- * @param {quat4} q Rotation quaternion
1151
- * @param {Vec3} v Translation vector
1152
- * @param {Vec3} s Scaling vector
1153
- * @param {Vec3} o The origin vector around which to scale and rotate
1154
- * @returns {Mat4} out
1155
- */
1156
- export function fromRotationTranslationScaleOrigin(out, q, v, s, o) {
1157
- // Quaternion math
1158
- const x = q[0], y = q[1], z = q[2], w = q[3];
1159
- const x2 = x + x;
1160
- const y2 = y + y;
1161
- const z2 = z + z;
1162
- const xx = x * x2;
1163
- const xy = x * y2;
1164
- const xz = x * z2;
1165
- const yy = y * y2;
1166
- const yz = y * z2;
1167
- const zz = z * z2;
1168
- const wx = w * x2;
1169
- const wy = w * y2;
1170
- const wz = w * z2;
1171
- const sx = s[0];
1172
- const sy = s[1];
1173
- const sz = s[2];
1174
- const ox = o[0];
1175
- const oy = o[1];
1176
- const oz = o[2];
1177
- const out0 = (1 - (yy + zz)) * sx;
1178
- const out1 = (xy + wz) * sx;
1179
- const out2 = (xz - wy) * sx;
1180
- const out4 = (xy - wz) * sy;
1181
- const out5 = (1 - (xx + zz)) * sy;
1182
- const out6 = (yz + wx) * sy;
1183
- const out8 = (xz + wy) * sz;
1184
- const out9 = (yz - wx) * sz;
1185
- const out10 = (1 - (xx + yy)) * sz;
1186
- out[0] = out0;
1187
- out[1] = out1;
1188
- out[2] = out2;
1189
- out[3] = 0;
1190
- out[4] = out4;
1191
- out[5] = out5;
1192
- out[6] = out6;
1193
- out[7] = 0;
1194
- out[8] = out8;
1195
- out[9] = out9;
1196
- out[10] = out10;
1197
- out[11] = 0;
1198
- out[12] = v[0] + ox - (out0 * ox + out4 * oy + out8 * oz);
1199
- out[13] = v[1] + oy - (out1 * ox + out5 * oy + out9 * oz);
1200
- out[14] = v[2] + oz - (out2 * ox + out6 * oy + out10 * oz);
1201
- out[15] = 1;
1202
- return out;
1203
- }
1204
- /**
1205
- * Calculates a 4x4 matrix from the given quaternion
1206
- *
1207
- * @param {Mat4} out Mat4 receiving operation result
1208
- * @param {Quat} q Quaternion to create matrix from
1209
- *
1210
- * @returns {Mat4} out
1211
- */
1212
- export function fromQuat(out, q) {
1213
- const x = q[0], y = q[1], z = q[2], w = q[3];
1214
- const x2 = x + x;
1215
- const y2 = y + y;
1216
- const z2 = z + z;
1217
- const xx = x * x2;
1218
- const yx = y * x2;
1219
- const yy = y * y2;
1220
- const zx = z * x2;
1221
- const zy = z * y2;
1222
- const zz = z * z2;
1223
- const wx = w * x2;
1224
- const wy = w * y2;
1225
- const wz = w * z2;
1226
- out[0] = 1 - yy - zz;
1227
- out[1] = yx + wz;
1228
- out[2] = zx - wy;
1229
- out[3] = 0;
1230
- out[4] = yx - wz;
1231
- out[5] = 1 - xx - zz;
1232
- out[6] = zy + wx;
1233
- out[7] = 0;
1234
- out[8] = zx + wy;
1235
- out[9] = zy - wx;
1236
- out[10] = 1 - xx - yy;
1237
- out[11] = 0;
1238
- out[12] = 0;
1239
- out[13] = 0;
1240
- out[14] = 0;
1241
- out[15] = 1;
1242
- return out;
1243
- }
1244
- /**
1245
- * Generates a frustum matrix with the given bounds
1246
- *
1247
- * @param {Mat4} out Mat4 frustum matrix will be written into
1248
- * @param {Number} left Left bound of the frustum
1249
- * @param {Number} right Right bound of the frustum
1250
- * @param {Number} bottom Bottom bound of the frustum
1251
- * @param {Number} top Top bound of the frustum
1252
- * @param {Number} near Near bound of the frustum
1253
- * @param {Number} far Far bound of the frustum
1254
- * @returns {Mat4} out
1255
- */
1256
- export function frustum(out, left, right, bottom, top, near, far) {
1257
- const rl = 1 / (right - left);
1258
- const tb = 1 / (top - bottom);
1259
- const nf = 1 / (near - far);
1260
- out[0] = near * 2 * rl;
1261
- out[1] = 0;
1262
- out[2] = 0;
1263
- out[3] = 0;
1264
- out[4] = 0;
1265
- out[5] = near * 2 * tb;
1266
- out[6] = 0;
1267
- out[7] = 0;
1268
- out[8] = (right + left) * rl;
1269
- out[9] = (top + bottom) * tb;
1270
- out[10] = (far + near) * nf;
1271
- out[11] = -1;
1272
- out[12] = 0;
1273
- out[13] = 0;
1274
- out[14] = far * near * 2 * nf;
1275
- out[15] = 0;
1276
- return out;
1277
- }
1278
- /**
1279
- * Generates a perspective projection matrix with the given bounds.
1280
- * The near/far clip planes correspond to a normalized device coordinate Z range of [-1, 1],
1281
- * which matches WebGL/OpenGL's clip volume.
1282
- * Passing null/undefined/no value for far will generate infinite projection matrix.
1283
- *
1284
- * @param {Mat4} out Mat4 frustum matrix will be written into
1285
- * @param {number} fovy Vertical field of view in radians
1286
- * @param {number} aspect Aspect ratio. typically viewport width/height
1287
- * @param {number} near Near bound of the frustum
1288
- * @param {number} far Far bound of the frustum, can be null or Infinity
1289
- * @returns {Mat4} out
1290
- */
1291
- export function perspectiveNO(out, fovy, aspect, near, far) {
1292
- const f = 1.0 / Math.tan(fovy / 2);
1293
- out[0] = f / aspect;
1294
- out[1] = 0;
1295
- out[2] = 0;
1296
- out[3] = 0;
1297
- out[4] = 0;
1298
- out[5] = f;
1299
- out[6] = 0;
1300
- out[7] = 0;
1301
- out[8] = 0;
1302
- out[9] = 0;
1303
- out[11] = -1;
1304
- out[12] = 0;
1305
- out[13] = 0;
1306
- out[15] = 0;
1307
- if (far != null && far !== Infinity) {
1308
- const nf = 1 / (near - far);
1309
- out[10] = (far + near) * nf;
1310
- out[14] = 2 * far * near * nf;
1311
- }
1312
- else {
1313
- out[10] = -1;
1314
- out[14] = -2 * near;
1315
- }
1316
- return out;
1317
- }
1318
- /**
1319
- * Alias for {@link perspectiveNO}
1320
- * @function
1321
- */
1322
- export const perspective = perspectiveNO;
1323
- /**
1324
- * Generates a perspective projection matrix suitable for WebGPU with the given bounds.
1325
- * The near/far clip planes correspond to a normalized device coordinate Z range of [0, 1],
1326
- * which matches WebGPU/Vulkan/DirectX/Metal's clip volume.
1327
- * Passing null/undefined/no value for far will generate infinite projection matrix.
1328
- *
1329
- * @param {Mat4} out Mat4 frustum matrix will be written into
1330
- * @param {number} fovy Vertical field of view in radians
1331
- * @param {number} aspect Aspect ratio. typically viewport width/height
1332
- * @param {number} near Near bound of the frustum
1333
- * @param {number} far Far bound of the frustum, can be null or Infinity
1334
- * @returns {Mat4} out
1335
- */
1336
- export function perspectiveZO(out, fovy, aspect, near, far) {
1337
- const f = 1.0 / Math.tan(fovy / 2);
1338
- out[0] = f / aspect;
1339
- out[1] = 0;
1340
- out[2] = 0;
1341
- out[3] = 0;
1342
- out[4] = 0;
1343
- out[5] = f;
1344
- out[6] = 0;
1345
- out[7] = 0;
1346
- out[8] = 0;
1347
- out[9] = 0;
1348
- out[11] = -1;
1349
- out[12] = 0;
1350
- out[13] = 0;
1351
- out[15] = 0;
1352
- if (far != null && far !== Infinity) {
1353
- const nf = 1 / (near - far);
1354
- out[10] = far * nf;
1355
- out[14] = far * near * nf;
1356
- }
1357
- else {
1358
- out[10] = -1;
1359
- out[14] = -near;
1360
- }
1361
- return out;
1362
- }
1363
- /**
1364
- * Generates a perspective projection matrix with the given field of view.
1365
- * This is primarily useful for generating projection matrices to be used
1366
- * with the still experiemental WebVR API.
1367
- *
1368
- * @param {Mat4} out Mat4 frustum matrix will be written into
1369
- * @param {Object} fov Object containing the following values: upDegrees, downDegrees, leftDegrees, rightDegrees
1370
- * @param {number} near Near bound of the frustum
1371
- * @param {number} far Far bound of the frustum
1372
- * @returns {Mat4} out
1373
- */
1374
- export function perspectiveFromFieldOfView(out, fov, near, far) {
1375
- const upTan = Math.tan((fov.upDegrees * Math.PI) / 180.0);
1376
- const downTan = Math.tan((fov.downDegrees * Math.PI) / 180.0);
1377
- const leftTan = Math.tan((fov.leftDegrees * Math.PI) / 180.0);
1378
- const rightTan = Math.tan((fov.rightDegrees * Math.PI) / 180.0);
1379
- const xScale = 2.0 / (leftTan + rightTan);
1380
- const yScale = 2.0 / (upTan + downTan);
1381
- out[0] = xScale;
1382
- out[1] = 0.0;
1383
- out[2] = 0.0;
1384
- out[3] = 0.0;
1385
- out[4] = 0.0;
1386
- out[5] = yScale;
1387
- out[6] = 0.0;
1388
- out[7] = 0.0;
1389
- out[8] = -((leftTan - rightTan) * xScale * 0.5);
1390
- out[9] = (upTan - downTan) * yScale * 0.5;
1391
- out[10] = far / (near - far);
1392
- out[11] = -1.0;
1393
- out[12] = 0.0;
1394
- out[13] = 0.0;
1395
- out[14] = (far * near) / (near - far);
1396
- out[15] = 0.0;
1397
- return out;
1398
- }
1399
- /**
1400
- * Generates a orthogonal projection matrix with the given bounds.
1401
- * The near/far clip planes correspond to a normalized device coordinate Z range of [-1, 1],
1402
- * which matches WebGL/OpenGL's clip volume.
1403
- *
1404
- * @param {Mat4} out Mat4 frustum matrix will be written into
1405
- * @param {number} left Left bound of the frustum
1406
- * @param {number} right Right bound of the frustum
1407
- * @param {number} bottom Bottom bound of the frustum
1408
- * @param {number} top Top bound of the frustum
1409
- * @param {number} near Near bound of the frustum
1410
- * @param {number} far Far bound of the frustum
1411
- * @returns {Mat4} out
1412
- */
1413
- export function orthoNO(out, left, right, bottom, top, near, far) {
1414
- const lr = 1 / (left - right);
1415
- const bt = 1 / (bottom - top);
1416
- const nf = 1 / (near - far);
1417
- out[0] = -2 * lr;
1418
- out[1] = 0;
1419
- out[2] = 0;
1420
- out[3] = 0;
1421
- out[4] = 0;
1422
- out[5] = -2 * bt;
1423
- out[6] = 0;
1424
- out[7] = 0;
1425
- out[8] = 0;
1426
- out[9] = 0;
1427
- out[10] = 2 * nf;
1428
- out[11] = 0;
1429
- out[12] = (left + right) * lr;
1430
- out[13] = (top + bottom) * bt;
1431
- out[14] = (far + near) * nf;
1432
- out[15] = 1;
1433
- return out;
1434
- }
1435
- /**
1436
- * Alias for {@link orthoNO}
1437
- * @function
1438
- */
1439
- export const ortho = orthoNO;
1440
- /**
1441
- * Generates a orthogonal projection matrix with the given bounds.
1442
- * The near/far clip planes correspond to a normalized device coordinate Z range of [0, 1],
1443
- * which matches WebGPU/Vulkan/DirectX/Metal's clip volume.
1444
- *
1445
- * @param {Mat4} out Mat4 frustum matrix will be written into
1446
- * @param {number} left Left bound of the frustum
1447
- * @param {number} right Right bound of the frustum
1448
- * @param {number} bottom Bottom bound of the frustum
1449
- * @param {number} top Top bound of the frustum
1450
- * @param {number} near Near bound of the frustum
1451
- * @param {number} far Far bound of the frustum
1452
- * @returns {Mat4} out
1453
- */
1454
- export function orthoZO(out, left, right, bottom, top, near, far) {
1455
- const lr = 1 / (left - right);
1456
- const bt = 1 / (bottom - top);
1457
- const nf = 1 / (near - far);
1458
- out[0] = -2 * lr;
1459
- out[1] = 0;
1460
- out[2] = 0;
1461
- out[3] = 0;
1462
- out[4] = 0;
1463
- out[5] = -2 * bt;
1464
- out[6] = 0;
1465
- out[7] = 0;
1466
- out[8] = 0;
1467
- out[9] = 0;
1468
- out[10] = nf;
1469
- out[11] = 0;
1470
- out[12] = (left + right) * lr;
1471
- out[13] = (top + bottom) * bt;
1472
- out[14] = near * nf;
1473
- out[15] = 1;
1474
- return out;
1475
- }
1476
- /**
1477
- * Generates a look-at matrix with the given eye position, focal point, and up axis.
1478
- * If you want a matrix that actually makes an object look at another object, you should use targetTo instead.
1479
- *
1480
- * @param {Mat4} out Mat4 frustum matrix will be written into
1481
- * @param {Vec3} eye Position of the viewer
1482
- * @param {Vec3} center Point the viewer is looking at
1483
- * @param {Vec3} up Vec3 pointing up
1484
- * @returns {Mat4} out
1485
- */
1486
- export function lookAt(out, eye, center, up) {
1487
- let x0, x1, x2, y0, y1, y2, z0, z1, z2, len;
1488
- const eyex = eye[0];
1489
- const eyey = eye[1];
1490
- const eyez = eye[2];
1491
- const upx = up[0];
1492
- const upy = up[1];
1493
- const upz = up[2];
1494
- const centerx = center[0];
1495
- const centery = center[1];
1496
- const centerz = center[2];
1497
- if (Math.abs(eyex - centerx) < EPSILON &&
1498
- Math.abs(eyey - centery) < EPSILON &&
1499
- Math.abs(eyez - centerz) < EPSILON) {
1500
- return identity(out);
1501
- }
1502
- z0 = eyex - centerx;
1503
- z1 = eyey - centery;
1504
- z2 = eyez - centerz;
1505
- len = 1 / Math.hypot(z0, z1, z2);
1506
- z0 *= len;
1507
- z1 *= len;
1508
- z2 *= len;
1509
- x0 = upy * z2 - upz * z1;
1510
- x1 = upz * z0 - upx * z2;
1511
- x2 = upx * z1 - upy * z0;
1512
- len = Math.hypot(x0, x1, x2);
1513
- if (!len) {
1514
- x0 = 0;
1515
- x1 = 0;
1516
- x2 = 0;
1517
- }
1518
- else {
1519
- len = 1 / len;
1520
- x0 *= len;
1521
- x1 *= len;
1522
- x2 *= len;
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
- if (!len) {
1529
- y0 = 0;
1530
- y1 = 0;
1531
- y2 = 0;
1532
- }
1533
- else {
1534
- len = 1 / len;
1535
- y0 *= len;
1536
- y1 *= len;
1537
- y2 *= len;
1538
- }
1539
- out[0] = x0;
1540
- out[1] = y0;
1541
- out[2] = z0;
1542
- out[3] = 0;
1543
- out[4] = x1;
1544
- out[5] = y1;
1545
- out[6] = z1;
1546
- out[7] = 0;
1547
- out[8] = x2;
1548
- out[9] = y2;
1549
- out[10] = z2;
1550
- out[11] = 0;
1551
- out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);
1552
- out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);
1553
- out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);
1554
- out[15] = 1;
1555
- return out;
1556
- }
1557
- /**
1558
- * Generates a matrix that makes something look at something else.
1559
- *
1560
- * @param {Mat4} out Mat4 frustum matrix will be written into
1561
- * @param {Vec3} eye Position of the viewer
1562
- * @param {Vec3} center Point the viewer is looking at
1563
- * @param {Vec3} up Vec3 pointing up
1564
- * @returns {Mat4} out
1565
- */
1566
- export function targetTo(out, eye, target, up) {
1567
- const eyex = eye[0], eyey = eye[1], eyez = eye[2], upx = up[0], upy = up[1], upz = up[2];
1568
- let z0 = eyex - target[0], z1 = eyey - target[1], z2 = eyez - target[2];
1569
- let len = z0 * z0 + z1 * z1 + z2 * z2;
1570
- if (len > 0) {
1571
- len = 1 / Math.sqrt(len);
1572
- z0 *= len;
1573
- z1 *= len;
1574
- z2 *= len;
1575
- }
1576
- let x0 = upy * z2 - upz * z1, x1 = upz * z0 - upx * z2, x2 = upx * z1 - upy * z0;
1577
- len = x0 * x0 + x1 * x1 + x2 * x2;
1578
- if (len > 0) {
1579
- len = 1 / Math.sqrt(len);
1580
- x0 *= len;
1581
- x1 *= len;
1582
- x2 *= len;
1583
- }
1584
- out[0] = x0;
1585
- out[1] = x1;
1586
- out[2] = x2;
1587
- out[3] = 0;
1588
- out[4] = z1 * x2 - z2 * x1;
1589
- out[5] = z2 * x0 - z0 * x2;
1590
- out[6] = z0 * x1 - z1 * x0;
1591
- out[7] = 0;
1592
- out[8] = z0;
1593
- out[9] = z1;
1594
- out[10] = z2;
1595
- out[11] = 0;
1596
- out[12] = eyex;
1597
- out[13] = eyey;
1598
- out[14] = eyez;
1599
- out[15] = 1;
1600
- return out;
1601
- }
1602
- /**
1603
- * Returns a string representation of a Mat4
1604
- *
1605
- * @param {Mat4} a matrix to represent as a string
1606
- * @returns {String} string representation of the matrix
1607
- */
1608
- export function str(a) {
1609
- 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]})`;
1610
- }
1611
- /**
1612
- * Returns Frobenius norm of a Mat4
1613
- *
1614
- * @param {Mat4} a the matrix to calculate Frobenius norm of
1615
- * @returns {Number} Frobenius norm
1616
- */
1617
- export function frob(a) {
1618
- 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]);
1619
- }
1620
- /**
1621
- * Adds two Mat4's
1622
- *
1623
- * @param {Mat4} out the receiving matrix
1624
- * @param {Mat4} a the first operand
1625
- * @param {Mat4} b the second operand
1626
- * @returns {Mat4} out
1627
- */
1628
- export function add(out, a, b) {
1629
- out[0] = a[0] + b[0];
1630
- out[1] = a[1] + b[1];
1631
- out[2] = a[2] + b[2];
1632
- out[3] = a[3] + b[3];
1633
- out[4] = a[4] + b[4];
1634
- out[5] = a[5] + b[5];
1635
- out[6] = a[6] + b[6];
1636
- out[7] = a[7] + b[7];
1637
- out[8] = a[8] + b[8];
1638
- out[9] = a[9] + b[9];
1639
- out[10] = a[10] + b[10];
1640
- out[11] = a[11] + b[11];
1641
- out[12] = a[12] + b[12];
1642
- out[13] = a[13] + b[13];
1643
- out[14] = a[14] + b[14];
1644
- out[15] = a[15] + b[15];
1645
- return out;
1646
- }
1647
- /**
1648
- * Subtracts matrix b from matrix a
1649
- *
1650
- * @param {Mat4} out the receiving matrix
1651
- * @param {Mat4} a the first operand
1652
- * @param {Mat4} b the second operand
1653
- * @returns {Mat4} out
1654
- */
1655
- export function subtract(out, a, b) {
1656
- out[0] = a[0] - b[0];
1657
- out[1] = a[1] - b[1];
1658
- out[2] = a[2] - b[2];
1659
- out[3] = a[3] - b[3];
1660
- out[4] = a[4] - b[4];
1661
- out[5] = a[5] - b[5];
1662
- out[6] = a[6] - b[6];
1663
- out[7] = a[7] - b[7];
1664
- out[8] = a[8] - b[8];
1665
- out[9] = a[9] - b[9];
1666
- out[10] = a[10] - b[10];
1667
- out[11] = a[11] - b[11];
1668
- out[12] = a[12] - b[12];
1669
- out[13] = a[13] - b[13];
1670
- out[14] = a[14] - b[14];
1671
- out[15] = a[15] - b[15];
1672
- return out;
1673
- }
1674
- /**
1675
- * Multiply each element of the matrix by a scalar.
1676
- *
1677
- * @param {Mat4} out the receiving matrix
1678
- * @param {Mat4} a the matrix to scale
1679
- * @param {Number} b amount to scale the matrix's elements by
1680
- * @returns {Mat4} out
1681
- */
1682
- export function multiplyScalar(out, a, b) {
1683
- out[0] = a[0] * b;
1684
- out[1] = a[1] * b;
1685
- out[2] = a[2] * b;
1686
- out[3] = a[3] * b;
1687
- out[4] = a[4] * b;
1688
- out[5] = a[5] * b;
1689
- out[6] = a[6] * b;
1690
- out[7] = a[7] * b;
1691
- out[8] = a[8] * b;
1692
- out[9] = a[9] * b;
1693
- out[10] = a[10] * b;
1694
- out[11] = a[11] * b;
1695
- out[12] = a[12] * b;
1696
- out[13] = a[13] * b;
1697
- out[14] = a[14] * b;
1698
- out[15] = a[15] * b;
1699
- return out;
1700
- }
1701
- /**
1702
- * Adds two Mat4's after multiplying each element of the second operand by a scalar value.
1703
- *
1704
- * @param {Mat4} out the receiving vector
1705
- * @param {Mat4} a the first operand
1706
- * @param {Mat4} b the second operand
1707
- * @param {Number} scale the amount to scale b's elements by before adding
1708
- * @returns {Mat4} out
1709
- */
1710
- export function multiplyScalarAndAdd(out, a, b, scale) {
1711
- out[0] = a[0] + b[0] * scale;
1712
- out[1] = a[1] + b[1] * scale;
1713
- out[2] = a[2] + b[2] * scale;
1714
- out[3] = a[3] + b[3] * scale;
1715
- out[4] = a[4] + b[4] * scale;
1716
- out[5] = a[5] + b[5] * scale;
1717
- out[6] = a[6] + b[6] * scale;
1718
- out[7] = a[7] + b[7] * scale;
1719
- out[8] = a[8] + b[8] * scale;
1720
- out[9] = a[9] + b[9] * scale;
1721
- out[10] = a[10] + b[10] * scale;
1722
- out[11] = a[11] + b[11] * scale;
1723
- out[12] = a[12] + b[12] * scale;
1724
- out[13] = a[13] + b[13] * scale;
1725
- out[14] = a[14] + b[14] * scale;
1726
- out[15] = a[15] + b[15] * scale;
1727
- return out;
1728
- }
1729
- /**
1730
- * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)
1731
- *
1732
- * @param {Mat4} a The first matrix.
1733
- * @param {Mat4} b The second matrix.
1734
- * @returns {Boolean} True if the matrices are equal, false otherwise.
1735
- */
1736
- export function exactEquals(a, b) {
1737
- return (a[0] === b[0] &&
1738
- a[1] === b[1] &&
1739
- a[2] === b[2] &&
1740
- a[3] === b[3] &&
1741
- a[4] === b[4] &&
1742
- a[5] === b[5] &&
1743
- a[6] === b[6] &&
1744
- a[7] === b[7] &&
1745
- a[8] === b[8] &&
1746
- a[9] === b[9] &&
1747
- a[10] === b[10] &&
1748
- a[11] === b[11] &&
1749
- a[12] === b[12] &&
1750
- a[13] === b[13] &&
1751
- a[14] === b[14] &&
1752
- a[15] === b[15]);
1753
- }
1754
- /**
1755
- * Returns whether or not the matrices have approximately the same elements in the same position.
1756
- *
1757
- * @param {Mat4} a The first matrix.
1758
- * @param {Mat4} b The second matrix.
1759
- * @returns {Boolean} True if the matrices are equal, false otherwise.
1760
- */
1761
- export function equals(a, b) {
1762
- const a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];
1763
- const a4 = a[4], a5 = a[5], a6 = a[6], a7 = a[7];
1764
- const a8 = a[8], a9 = a[9], a10 = a[10], a11 = a[11];
1765
- const a12 = a[12], a13 = a[13], a14 = a[14], a15 = a[15];
1766
- const b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
1767
- const b4 = b[4], b5 = b[5], b6 = b[6], b7 = b[7];
1768
- const b8 = b[8], b9 = b[9], b10 = b[10], b11 = b[11];
1769
- const b12 = b[12], b13 = b[13], b14 = b[14], b15 = b[15];
1770
- return (Math.abs(a0 - b0) <= EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&
1771
- Math.abs(a1 - b1) <= EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) &&
1772
- Math.abs(a2 - b2) <= EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) &&
1773
- Math.abs(a3 - b3) <= EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) &&
1774
- Math.abs(a4 - b4) <= EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) &&
1775
- Math.abs(a5 - b5) <= EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)) &&
1776
- Math.abs(a6 - b6) <= EPSILON * Math.max(1.0, Math.abs(a6), Math.abs(b6)) &&
1777
- Math.abs(a7 - b7) <= EPSILON * Math.max(1.0, Math.abs(a7), Math.abs(b7)) &&
1778
- Math.abs(a8 - b8) <= EPSILON * Math.max(1.0, Math.abs(a8), Math.abs(b8)) &&
1779
- Math.abs(a9 - b9) <= EPSILON * Math.max(1.0, Math.abs(a9), Math.abs(b9)) &&
1780
- Math.abs(a10 - b10) <=
1781
- EPSILON * Math.max(1.0, Math.abs(a10), Math.abs(b10)) &&
1782
- Math.abs(a11 - b11) <=
1783
- EPSILON * Math.max(1.0, Math.abs(a11), Math.abs(b11)) &&
1784
- Math.abs(a12 - b12) <=
1785
- EPSILON * Math.max(1.0, Math.abs(a12), Math.abs(b12)) &&
1786
- Math.abs(a13 - b13) <=
1787
- EPSILON * Math.max(1.0, Math.abs(a13), Math.abs(b13)) &&
1788
- Math.abs(a14 - b14) <=
1789
- EPSILON * Math.max(1.0, Math.abs(a14), Math.abs(b14)) &&
1790
- Math.abs(a15 - b15) <= EPSILON * Math.max(1.0, Math.abs(a15), Math.abs(b15)));
1791
- }
1792
- /**
1793
- * Alias for {@link multiply}
1794
- * @function
1795
- */
1796
- export const mul = multiply;
1797
- /**
1798
- * Alias for {@link subtract}
1799
- * @function
1800
- */
1801
- export const sub = subtract;
1802
- //# sourceMappingURL=mat4.js.map