typegpu 0.11.9 → 0.12.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 (366) hide show
  1. package/bin.mjs +28 -6
  2. package/builtin.d.ts +51 -53
  3. package/builtin.js +30 -34
  4. package/common/fullScreenTriangle.d.ts +2 -10
  5. package/common/fullScreenTriangle.js +20 -28
  6. package/common/index.d.ts +2 -9
  7. package/common/index.js +3 -12
  8. package/common/writeSoA.d.ts +11 -12
  9. package/common/writeSoA.js +88 -76
  10. package/core/buffer/buffer.d.ts +79 -62
  11. package/core/buffer/buffer.js +283 -205
  12. package/core/buffer/bufferBinding.d.ts +71 -0
  13. package/core/buffer/bufferBinding.js +154 -0
  14. package/core/buffer/bufferUsage.d.ts +14 -45
  15. package/core/buffer/bufferUsage.js +1 -171
  16. package/core/buffer/laidOutBuffer.d.ts +25 -0
  17. package/core/buffer/laidOutBuffer.js +55 -0
  18. package/core/commandEncoder/attachments.d.ts +125 -0
  19. package/core/commandEncoder/attachments.js +29 -0
  20. package/core/commandEncoder/commandEncoder.d.ts +53 -0
  21. package/core/commandEncoder/commandEncoder.js +56 -0
  22. package/core/commandEncoder/computePass.d.ts +58 -0
  23. package/core/commandEncoder/computePass.js +63 -0
  24. package/core/commandEncoder/renderPass.d.ts +121 -0
  25. package/core/commandEncoder/renderPass.js +196 -0
  26. package/core/constant/tgpuConstant.d.ts +26 -26
  27. package/core/constant/tgpuConstant.js +76 -65
  28. package/core/declare/tgpuDeclare.d.ts +3 -6
  29. package/core/declare/tgpuDeclare.js +36 -36
  30. package/core/function/autoIO.d.ts +61 -33
  31. package/core/function/autoIO.js +68 -73
  32. package/core/function/comptime.d.ts +11 -13
  33. package/core/function/comptime.js +60 -52
  34. package/core/function/createCallableSchema.d.ts +16 -0
  35. package/core/function/createCallableSchema.js +50 -40
  36. package/core/function/dualImpl.d.ts +44 -0
  37. package/core/function/dualImpl.js +71 -50
  38. package/core/function/entryInputRouter.d.ts +26 -0
  39. package/core/function/entryInputRouter.js +31 -33
  40. package/core/function/extractArgs.d.ts +38 -0
  41. package/core/function/extractArgs.js +202 -200
  42. package/core/function/fnCore.d.ts +44 -5
  43. package/core/function/fnCore.js +148 -93
  44. package/core/function/fnTypes.d.ts +31 -29
  45. package/core/function/fnTypes.js +1 -0
  46. package/core/function/ioSchema.d.ts +12 -10
  47. package/core/function/ioSchema.js +65 -47
  48. package/core/function/shelllessImpl.d.ts +9 -12
  49. package/core/function/shelllessImpl.js +17 -22
  50. package/core/function/templateUtils.d.ts +2 -0
  51. package/core/function/templateUtils.js +9 -8
  52. package/core/function/tgpuComputeFn.d.ts +26 -28
  53. package/core/function/tgpuComputeFn.js +47 -48
  54. package/core/function/tgpuFn.d.ts +34 -37
  55. package/core/function/tgpuFn.js +179 -153
  56. package/core/function/tgpuFragmentFn.d.ts +52 -53
  57. package/core/function/tgpuFragmentFn.js +63 -56
  58. package/core/function/tgpuVertexFn.d.ts +36 -39
  59. package/core/function/tgpuVertexFn.js +56 -53
  60. package/core/pipeline/computePipeline.d.ts +141 -53
  61. package/core/pipeline/computePipeline.js +291 -225
  62. package/core/pipeline/connectAttachmentToShader.d.ts +4 -0
  63. package/core/pipeline/connectAttachmentToShader.js +25 -22
  64. package/core/pipeline/connectTargetsToShader.d.ts +3 -0
  65. package/core/pipeline/connectTargetsToShader.js +29 -27
  66. package/core/pipeline/drawState.d.ts +52 -0
  67. package/core/pipeline/drawState.js +225 -0
  68. package/core/pipeline/performanceTracker.d.ts +14 -0
  69. package/core/pipeline/performanceTracker.js +34 -0
  70. package/core/pipeline/pipelineUtils.d.ts +18 -0
  71. package/core/pipeline/pipelineUtils.js +54 -25
  72. package/core/pipeline/priors.d.ts +1 -0
  73. package/core/pipeline/priors.js +12 -0
  74. package/core/pipeline/renderPipeline.d.ts +246 -261
  75. package/core/pipeline/renderPipeline.js +487 -480
  76. package/core/pipeline/timeable.d.ts +28 -18
  77. package/core/pipeline/timeable.js +90 -52
  78. package/core/pipeline/typeGuards.d.ts +17 -0
  79. package/core/pipeline/typeGuards.js +52 -22
  80. package/core/pipeline/webgpuLimitations.d.ts +10 -0
  81. package/core/pipeline/webgpuLimitations.js +81 -0
  82. package/core/querySet/querySet.d.ts +26 -21
  83. package/core/querySet/querySet.js +127 -103
  84. package/core/rawCodeSnippet/tgpuRawCodeSnippet.d.ts +13 -18
  85. package/core/rawCodeSnippet/tgpuRawCodeSnippet.js +89 -90
  86. package/core/resolve/externals.d.ts +25 -8
  87. package/core/resolve/externals.js +78 -54
  88. package/core/resolve/namespace.d.ts +22 -25
  89. package/core/resolve/namespace.js +16 -21
  90. package/core/resolve/resolvableString.d.ts +7 -0
  91. package/core/resolve/resolvableString.js +13 -0
  92. package/core/resolve/resolveData.d.ts +10 -0
  93. package/core/resolve/resolveData.js +162 -121
  94. package/core/resolve/stitch.d.ts +8 -0
  95. package/core/resolve/stitch.js +23 -21
  96. package/core/resolve/tgpuResolve.d.ts +55 -53
  97. package/core/resolve/tgpuResolve.js +106 -53
  98. package/core/root/configurableImpl.d.ts +10 -0
  99. package/core/root/configurableImpl.js +17 -19
  100. package/core/root/init.d.ts +76 -38
  101. package/core/root/init.js +346 -455
  102. package/core/root/rootTypes.d.ts +461 -636
  103. package/core/root/rootTypes.js +1 -0
  104. package/core/sampler/sampler.d.ts +50 -31
  105. package/core/sampler/sampler.js +120 -113
  106. package/core/simulate/tgpuSimulate.d.ts +9 -12
  107. package/core/simulate/tgpuSimulate.js +68 -71
  108. package/core/slot/accessor.d.ts +36 -13
  109. package/core/slot/accessor.js +138 -91
  110. package/core/slot/internalSlots.d.ts +2 -0
  111. package/core/slot/internalSlots.js +1 -6
  112. package/core/slot/lazy.d.ts +2 -6
  113. package/core/slot/lazy.js +71 -39
  114. package/core/slot/slot.d.ts +2 -6
  115. package/core/slot/slot.js +45 -38
  116. package/core/slot/slotTypes.d.ts +78 -80
  117. package/core/slot/slotTypes.js +11 -16
  118. package/core/texture/externalTexture.d.ts +20 -11
  119. package/core/texture/externalTexture.js +46 -46
  120. package/core/texture/texture.d.ts +152 -97
  121. package/core/texture/texture.js +407 -314
  122. package/core/texture/textureFormats.d.ts +42 -23
  123. package/core/texture/textureFormats.js +104 -75
  124. package/core/texture/textureProps.d.ts +7 -10
  125. package/core/texture/textureProps.js +1 -0
  126. package/core/texture/textureUtils.d.ts +8 -0
  127. package/core/texture/textureUtils.js +185 -179
  128. package/core/texture/usageExtension.d.ts +21 -18
  129. package/core/texture/usageExtension.js +13 -17
  130. package/core/unroll/tgpuUnroll.d.ts +20 -19
  131. package/core/unroll/tgpuUnroll.js +82 -91
  132. package/core/valueProxyUtils.d.ts +3 -0
  133. package/core/valueProxyUtils.js +52 -41
  134. package/core/variable/tgpuVariable.d.ts +26 -27
  135. package/core/variable/tgpuVariable.js +93 -96
  136. package/core/vertexLayout/connectAttributesToShader.d.ts +9 -0
  137. package/core/vertexLayout/connectAttributesToShader.js +61 -56
  138. package/core/vertexLayout/vertexAttribute.d.ts +21 -17
  139. package/core/vertexLayout/vertexAttribute.js +1 -0
  140. package/core/vertexLayout/vertexLayout.d.ts +24 -18
  141. package/core/vertexLayout/vertexLayout.js +130 -99
  142. package/core/whitespaces.d.ts +2 -0
  143. package/core/whitespaces.js +16 -0
  144. package/data/alignIO.d.ts +7 -0
  145. package/data/alignIO.js +13 -13
  146. package/data/alignmentOf.d.ts +5 -8
  147. package/data/alignmentOf.js +90 -75
  148. package/data/array.d.ts +17 -9
  149. package/data/array.js +57 -40
  150. package/data/atomic.d.ts +2 -7
  151. package/data/atomic.js +26 -23
  152. package/data/attributes.d.ts +19 -21
  153. package/data/attributes.js +192 -132
  154. package/data/autoStruct.d.ts +36 -3
  155. package/data/autoStruct.js +84 -81
  156. package/data/compiledIO.d.ts +5 -0
  157. package/data/compiledIO.js +231 -215
  158. package/data/dataIO.d.ts +13 -11
  159. package/data/dataIO.js +643 -589
  160. package/data/dataTypes.d.ts +83 -65
  161. package/data/dataTypes.js +66 -68
  162. package/data/deepEqual.d.ts +2 -7
  163. package/data/deepEqual.js +80 -55
  164. package/data/disarray.d.ts +6 -10
  165. package/data/disarray.js +52 -46
  166. package/data/float16Conversion.d.ts +4 -0
  167. package/data/float16Conversion.js +7 -0
  168. package/data/generalizeFn.d.ts +25 -0
  169. package/data/generalizeFn.js +89 -0
  170. package/data/getLongestContiguousPrefix.d.ts +4 -8
  171. package/data/getLongestContiguousPrefix.js +6 -11
  172. package/data/index.d.ts +30 -31
  173. package/data/index.js +39 -172
  174. package/data/instanceToSchema.d.ts +24 -27
  175. package/data/instanceToSchema.js +1 -0
  176. package/data/isContiguous.d.ts +4 -8
  177. package/data/isContiguous.js +6 -11
  178. package/data/matrix.d.ts +21 -21
  179. package/data/matrix.js +513 -505
  180. package/data/numberOps.d.ts +5 -0
  181. package/data/numberOps.js +21 -21
  182. package/data/numeric.d.ts +21 -12
  183. package/data/numeric.js +287 -197
  184. package/data/offsetUtils.d.ts +9 -13
  185. package/data/offsetUtils.js +204 -144
  186. package/data/offsets.d.ts +8 -0
  187. package/data/offsets.js +33 -33
  188. package/data/partialIO.d.ts +13 -8
  189. package/data/partialIO.js +124 -113
  190. package/data/ptr.d.ts +12 -12
  191. package/data/ptr.js +42 -44
  192. package/data/ref.d.ts +40 -27
  193. package/data/ref.js +125 -95
  194. package/data/sampler.d.ts +99 -101
  195. package/data/sampler.js +17 -21
  196. package/data/schemaCallWrapper.d.ts +19 -0
  197. package/data/schemaCallWrapper.js +31 -26
  198. package/data/schemaMemoryLayout.d.ts +8 -0
  199. package/data/schemaMemoryLayout.js +213 -185
  200. package/data/sizeOf.d.ts +4 -8
  201. package/data/sizeOf.js +6 -11
  202. package/data/snippet.d.ts +96 -20
  203. package/data/snippet.js +75 -86
  204. package/data/struct.d.ts +4 -7
  205. package/data/struct.js +51 -39
  206. package/data/texture.d.ts +253 -250
  207. package/data/texture.js +238 -200
  208. package/data/unstruct.d.ts +2 -7
  209. package/data/unstruct.js +43 -37
  210. package/data/vector.d.ts +33 -21
  211. package/data/vector.js +234 -221
  212. package/data/vectorImpl.d.ts +231 -0
  213. package/data/vectorImpl.js +563 -515
  214. package/data/vectorOps.d.ts +25 -0
  215. package/data/vectorOps.js +118 -669
  216. package/data/vertexFormatData.d.ts +181 -184
  217. package/data/vertexFormatData.js +104 -106
  218. package/data/wgslTypes.d.ts +665 -600
  219. package/data/wgslTypes.js +220 -198
  220. package/errors.d.ts +50 -24
  221. package/errors.js +146 -126
  222. package/execMode.d.ts +16 -0
  223. package/execMode.js +47 -40
  224. package/extension.d.ts +13 -8
  225. package/extension.js +10 -16
  226. package/getGPUValue.d.ts +1 -0
  227. package/getGPUValue.js +2 -7
  228. package/index.d.ts +28 -68
  229. package/index.js +8 -28
  230. package/indexNamedExports.d.ts +69 -42
  231. package/indexNamedExports.js +25 -0
  232. package/internal.d.ts +16 -0
  233. package/internal.js +12 -0
  234. package/mathUtils.d.ts +5 -0
  235. package/mathUtils.js +7 -11
  236. package/memo.d.ts +11 -0
  237. package/memo.js +20 -22
  238. package/minify.d.ts +5 -0
  239. package/minify.js +93 -0
  240. package/nameUtils.d.ts +29 -0
  241. package/nameUtils.js +427 -394
  242. package/package.json +5 -1
  243. package/resolutionCtx.d.ts +162 -22
  244. package/resolutionCtx.js +911 -629
  245. package/serial/registry.d.ts +15 -0
  246. package/serial/registry.js +106 -0
  247. package/serial/restore.d.ts +49 -0
  248. package/serial/restore.js +68 -0
  249. package/serial/schema.d.ts +58 -0
  250. package/serial/schema.js +209 -0
  251. package/serial/types.d.ts +5 -0
  252. package/serial/types.js +1 -0
  253. package/shared/env.d.ts +9 -0
  254. package/shared/env.js +9 -12
  255. package/shared/generators.d.ts +4 -0
  256. package/shared/generators.js +10 -12
  257. package/shared/meta.d.ts +29 -14
  258. package/shared/meta.js +71 -55
  259. package/shared/normalizeMetadata.d.ts +32 -27
  260. package/shared/normalizeMetadata.js +23 -36
  261. package/shared/repr.d.ts +73 -55
  262. package/shared/repr.js +1 -0
  263. package/shared/soul.d.ts +17 -0
  264. package/shared/soul.js +1 -0
  265. package/shared/stringify.d.ts +2 -0
  266. package/shared/stringify.js +29 -20
  267. package/shared/symbols.d.ts +26 -20
  268. package/shared/symbols.js +79 -79
  269. package/shared/tseynit.d.ts +2 -0
  270. package/shared/tseynit.js +160 -75
  271. package/shared/utilityTypes.d.ts +30 -14
  272. package/shared/utilityTypes.js +2 -6
  273. package/shared/vertexFormat.d.ts +41 -43
  274. package/shared/vertexFormat.js +59 -62
  275. package/std/array.d.ts +2 -7
  276. package/std/array.js +18 -23
  277. package/std/atomic.d.ts +14 -18
  278. package/std/atomic.js +96 -95
  279. package/std/bitcast.d.ts +193 -10
  280. package/std/bitcast.js +309 -39
  281. package/std/boolean.d.ts +19 -33
  282. package/std/boolean.js +296 -292
  283. package/std/copy.d.ts +2 -7
  284. package/std/copy.js +27 -24
  285. package/std/derivative.d.ts +11 -15
  286. package/std/derivative.js +56 -79
  287. package/std/discard.d.ts +1 -6
  288. package/std/discard.js +7 -14
  289. package/std/environment.d.ts +19 -14
  290. package/std/environment.js +71 -51
  291. package/std/extensions.d.ts +2 -8
  292. package/std/extensions.js +10 -11
  293. package/std/index.d.ts +20 -24
  294. package/std/index.js +32 -187
  295. package/std/matrix.d.ts +6 -12
  296. package/std/matrix.js +60 -69
  297. package/std/numeric.d.ts +150 -146
  298. package/std/numeric.js +771 -727
  299. package/std/operators.d.ts +19 -27
  300. package/std/operators.js +195 -194
  301. package/std/packing.d.ts +5 -11
  302. package/std/packing.js +67 -75
  303. package/std/range.d.ts +6 -11
  304. package/std/range.js +48 -36
  305. package/std/subgroup.d.ts +33 -37
  306. package/std/subgroup.js +180 -217
  307. package/std/texture.d.ts +70 -38
  308. package/std/texture.js +176 -172
  309. package/taskQueue.d.ts +6 -0
  310. package/taskQueue.js +30 -0
  311. package/tgpu.d.ts +16 -0
  312. package/tgpu.js +17 -44
  313. package/tgpuBindGroupLayout.d.ts +132 -152
  314. package/tgpuBindGroupLayout.js +346 -268
  315. package/tgpuLogger.d.ts +34 -0
  316. package/tgpuLogger.js +64 -0
  317. package/tgpuUnstable.d.ts +16 -22
  318. package/tgpuUnstable.js +13 -35
  319. package/tgsl/accessIndex.d.ts +2 -0
  320. package/tgsl/accessIndex.js +76 -33
  321. package/tgsl/accessProp.d.ts +2 -0
  322. package/tgsl/accessProp.js +142 -101
  323. package/tgsl/accessStructProp.d.ts +5 -0
  324. package/tgsl/accessStructProp.js +13 -15
  325. package/tgsl/consoleLog/deserializers.d.ts +13 -0
  326. package/tgsl/consoleLog/deserializers.js +119 -103
  327. package/tgsl/consoleLog/logGenerator.d.ts +21 -0
  328. package/tgsl/consoleLog/logGenerator.js +85 -80
  329. package/tgsl/consoleLog/serializers.d.ts +21 -0
  330. package/tgsl/consoleLog/serializers.js +119 -100
  331. package/tgsl/consoleLog/types.d.ts +40 -39
  332. package/tgsl/consoleLog/types.js +1 -0
  333. package/tgsl/conversion.d.ts +33 -0
  334. package/tgsl/conversion.js +271 -216
  335. package/tgsl/forOfUtils.d.ts +15 -0
  336. package/tgsl/forOfUtils.js +85 -70
  337. package/tgsl/generationHelpers.d.ts +22 -39
  338. package/tgsl/generationHelpers.js +85 -58
  339. package/tgsl/infixDispatch.d.ts +70 -0
  340. package/tgsl/infixDispatch.js +48 -46
  341. package/tgsl/jsPolyfills.d.ts +16 -19
  342. package/tgsl/jsPolyfills.js +44 -42
  343. package/tgsl/makeDereferenceable.d.ts +48 -0
  344. package/tgsl/makeDereferenceable.js +86 -0
  345. package/tgsl/makeResolvable.d.ts +22 -0
  346. package/tgsl/makeResolvable.js +33 -0
  347. package/tgsl/shaderGenerator.d.ts +77 -17
  348. package/tgsl/shaderGenerator.js +1 -0
  349. package/tgsl/shellless.d.ts +6 -9
  350. package/tgsl/shellless.js +73 -43
  351. package/tgsl/wgslGenerator.d.ts +66 -59
  352. package/tgsl/wgslGenerator.js +1345 -760
  353. package/types.d.ts +287 -222
  354. package/types.js +61 -44
  355. package/unwrapper.d.ts +31 -26
  356. package/unwrapper.js +1 -0
  357. package/wgslExtensions.d.ts +3 -5
  358. package/wgslExtensions.js +12 -16
  359. package/_virtual/rolldown_runtime.js +0 -13
  360. package/core/buffer/bufferShorthand.d.ts +0 -50
  361. package/core/buffer/bufferShorthand.js +0 -55
  362. package/core/pipeline/applyPipelineState.js +0 -37
  363. package/core/pipeline/limitsOverflow.js +0 -13
  364. package/package.js +0 -5
  365. package/tgsl/shaderGenerator_members.d.ts +0 -33
  366. package/tgsl/shaderGenerator_members.js +0 -12
package/data/matrix.js CHANGED
@@ -1,533 +1,541 @@
1
- import { $internal, $resolve } from "../shared/symbols.js";
2
- import { isVec } from "./wgslTypes.js";
3
- import { stitch } from "../core/resolve/stitch.js";
1
+ import { comptime } from "../core/function/comptime.js";
4
2
  import { callableSchema } from "../core/function/createCallableSchema.js";
5
- import { f32 } from "./numeric.js";
3
+ import { dualImpl } from "../core/function/dualImpl.js";
4
+ import { stitch } from "../core/resolve/stitch.js";
5
+ import { $repr } from "../shared/symbols.js";
6
+ import { $internal, $resolve } from "../shared/symbols.js";
6
7
  import { numericLiteralToSnippet } from "../tgsl/generationHelpers.js";
8
+ import { f32 } from "./numeric.js";
9
+ import {} from "./snippet.js";
7
10
  import { vec2f, vec3f, vec4f } from "./vector.js";
8
- import { dualImpl } from "../core/function/dualImpl.js";
9
- import { comptime } from "../core/function/comptime.js";
10
-
11
- //#region src/data/matrix.ts
12
- var MatBase = class {};
11
+ import { isVec, } from "./wgslTypes.js";
12
+ export class MatBase {
13
+ }
13
14
  function createMatSchema(options) {
14
- const construct = callableSchema({
15
- name: options.type,
16
- schema: () => schema,
17
- normalImpl: (...args) => {
18
- const elements = [];
19
- for (const arg of args) if (typeof arg === "number") elements.push(arg);
20
- else for (let i = 0; i < arg.length; ++i) elements.push(arg[i]);
21
- if (elements.length !== 0 && elements.length !== options.columns * options.rows) throw new Error(`'${options.type}' constructor called with invalid number of arguments.`);
22
- for (let i = elements.length; i < options.columns * options.rows; ++i) elements.push(0);
23
- return new options.MatImpl(...elements);
24
- },
25
- argTypes: (...args) => args.map((arg) => isVec(arg) ? arg : f32),
26
- codegenImpl: (ctx, args) => ctx.gen.typeInstantiation(schema, args)
27
- });
28
- const schema = Object.assign(construct, {
29
- [$internal]: {},
30
- type: options.type,
31
- primitive: f32,
32
- identity: identityFunctions[options.columns],
33
- translation: options.columns === 4 ? translation4 : void 0,
34
- scaling: options.columns === 4 ? scaling4 : void 0,
35
- rotationX: options.columns === 4 ? rotationX4 : void 0,
36
- rotationY: options.columns === 4 ? rotationY4 : void 0,
37
- rotationZ: options.columns === 4 ? rotationZ4 : void 0
38
- });
39
- options.MatImpl.prototype.schema = schema;
40
- return schema;
15
+ const construct = callableSchema({
16
+ name: options.type,
17
+ schema: () => schema,
18
+ normalImpl: (...args) => {
19
+ const elements = [];
20
+ for (const arg of args) {
21
+ if (typeof arg === 'number') {
22
+ elements.push(arg);
23
+ }
24
+ else {
25
+ for (let i = 0; i < arg.length; ++i) {
26
+ elements.push(arg[i]);
27
+ }
28
+ }
29
+ }
30
+ if (elements.length !== 0 && elements.length !== options.columns * options.rows) {
31
+ throw new Error(`'${options.type}' constructor called with invalid number of arguments.`);
32
+ }
33
+ for (let i = elements.length; i < options.columns * options.rows; ++i) {
34
+ elements.push(0);
35
+ }
36
+ return new options.MatImpl(...elements);
37
+ },
38
+ argTypes: (...args) => args.map((arg) => (isVec(arg) ? arg : f32)),
39
+ codegenImpl: (ctx, args) => ctx.gen.typeInstantiation(schema, args),
40
+ });
41
+ const schema = Object.assign(construct, {
42
+ [$internal]: {},
43
+ type: options.type,
44
+ primitive: f32,
45
+ identity: identityFunctions[options.columns],
46
+ translation: options.columns === 4 ? translation4 : undefined,
47
+ scaling: options.columns === 4 ? scaling4 : undefined,
48
+ rotationX: options.columns === 4 ? rotationX4 : undefined,
49
+ rotationY: options.columns === 4 ? rotationY4 : undefined,
50
+ rotationZ: options.columns === 4 ? rotationZ4 : undefined,
51
+ });
52
+ // TODO: Remove workaround
53
+ // it's a workaround for circular dependencies caused by us using schemas in the shader generator
54
+ options.MatImpl.prototype.schema = schema;
55
+ return schema;
56
+ }
57
+ const VALID_MAT2x2_ELEMENTS = [0, 1, 2, 3];
58
+ class mat2x2Impl extends MatBase {
59
+ [$internal] = true;
60
+ columns;
61
+ length = 4;
62
+ constructor(...elements) {
63
+ super();
64
+ this.columns = [
65
+ this.makeColumn(elements[0], elements[1]),
66
+ this.makeColumn(elements[2], elements[3]),
67
+ ];
68
+ }
69
+ get 0() {
70
+ return this.columns[0].x;
71
+ }
72
+ get 1() {
73
+ return this.columns[0].y;
74
+ }
75
+ get 2() {
76
+ return this.columns[1].x;
77
+ }
78
+ get 3() {
79
+ return this.columns[1].y;
80
+ }
81
+ set 0(value) {
82
+ this.columns[0].x = value;
83
+ }
84
+ set 1(value) {
85
+ this.columns[0].y = value;
86
+ }
87
+ set 2(value) {
88
+ this.columns[1].x = value;
89
+ }
90
+ set 3(value) {
91
+ this.columns[1].y = value;
92
+ }
93
+ *[Symbol.iterator]() {
94
+ yield this[0];
95
+ yield this[1];
96
+ yield this[2];
97
+ yield this[3];
98
+ }
99
+ [$resolve](ctx) {
100
+ return ctx.gen.typeInstantiation(mat2x2f,
101
+ // oxlint-disable-next-line typescript-eslint(no-non-null-assertion)
102
+ VALID_MAT2x2_ELEMENTS.map((i) => numericLiteralToSnippet(this[i])));
103
+ }
104
+ toString() {
105
+ return `${this.kind}(${VALID_MAT2x2_ELEMENTS.map((i) => this[i]).join(', ')})`;
106
+ }
107
+ }
108
+ class mat2x2fImpl extends mat2x2Impl {
109
+ kind = 'mat2x2f';
110
+ makeColumn(e0, e1) {
111
+ return vec2f(e0, e1);
112
+ }
113
+ }
114
+ const VALID_MAT3x3_ELEMENTS = [0, 1, 2, 4, 5, 6, 8, 9, 10];
115
+ class mat3x3Impl extends MatBase {
116
+ [$internal] = true;
117
+ columns;
118
+ length = 12;
119
+ constructor(...elements) {
120
+ super();
121
+ this.columns = [
122
+ this.makeColumn(elements[0], elements[1], elements[2]),
123
+ this.makeColumn(elements[3], elements[4], elements[5]),
124
+ this.makeColumn(elements[6], elements[7], elements[8]),
125
+ ];
126
+ }
127
+ get 0() {
128
+ return this.columns[0].x;
129
+ }
130
+ get 1() {
131
+ return this.columns[0].y;
132
+ }
133
+ get 2() {
134
+ return this.columns[0].z;
135
+ }
136
+ get 3() {
137
+ return 0;
138
+ }
139
+ get 4() {
140
+ return this.columns[1].x;
141
+ }
142
+ get 5() {
143
+ return this.columns[1].y;
144
+ }
145
+ get 6() {
146
+ return this.columns[1].z;
147
+ }
148
+ get 7() {
149
+ return 0;
150
+ }
151
+ get 8() {
152
+ return this.columns[2].x;
153
+ }
154
+ get 9() {
155
+ return this.columns[2].y;
156
+ }
157
+ get 10() {
158
+ return this.columns[2].z;
159
+ }
160
+ get 11() {
161
+ return 0;
162
+ }
163
+ set 0(value) {
164
+ this.columns[0].x = value;
165
+ }
166
+ set 1(value) {
167
+ this.columns[0].y = value;
168
+ }
169
+ set 2(value) {
170
+ this.columns[0].z = value;
171
+ }
172
+ set 3(_) { }
173
+ set 4(value) {
174
+ this.columns[1].x = value;
175
+ }
176
+ set 5(value) {
177
+ this.columns[1].y = value;
178
+ }
179
+ set 6(value) {
180
+ this.columns[1].z = value;
181
+ }
182
+ set 7(_) { }
183
+ set 8(value) {
184
+ this.columns[2].x = value;
185
+ }
186
+ set 9(value) {
187
+ this.columns[2].y = value;
188
+ }
189
+ set 10(value) {
190
+ this.columns[2].z = value;
191
+ }
192
+ set 11(_) { }
193
+ *[Symbol.iterator]() {
194
+ for (let i = 0; i < 12; i++) {
195
+ yield this[i];
196
+ }
197
+ }
198
+ [$resolve](ctx) {
199
+ return ctx.gen.typeInstantiation(mat3x3f,
200
+ // oxlint-disable-next-line typescript-eslint(no-non-null-assertion)
201
+ VALID_MAT3x3_ELEMENTS.map((i) => numericLiteralToSnippet(this[i])));
202
+ }
203
+ toString() {
204
+ return `${this.kind}(${VALID_MAT3x3_ELEMENTS.map((i) => this[i]).join(', ')})`;
205
+ }
206
+ }
207
+ class mat3x3fImpl extends mat3x3Impl {
208
+ kind = 'mat3x3f';
209
+ makeColumn(x, y, z) {
210
+ return vec3f(x, y, z);
211
+ }
41
212
  }
42
- const VALID_MAT2x2_ELEMENTS = [
43
- 0,
44
- 1,
45
- 2,
46
- 3
47
- ];
48
- var mat2x2Impl = class extends MatBase {
49
- [$internal] = true;
50
- columns;
51
- length = 4;
52
- constructor(...elements) {
53
- super();
54
- this.columns = [this.makeColumn(elements[0], elements[1]), this.makeColumn(elements[2], elements[3])];
55
- }
56
- get 0() {
57
- return this.columns[0].x;
58
- }
59
- get 1() {
60
- return this.columns[0].y;
61
- }
62
- get 2() {
63
- return this.columns[1].x;
64
- }
65
- get 3() {
66
- return this.columns[1].y;
67
- }
68
- set 0(value) {
69
- this.columns[0].x = value;
70
- }
71
- set 1(value) {
72
- this.columns[0].y = value;
73
- }
74
- set 2(value) {
75
- this.columns[1].x = value;
76
- }
77
- set 3(value) {
78
- this.columns[1].y = value;
79
- }
80
- *[Symbol.iterator]() {
81
- yield this[0];
82
- yield this[1];
83
- yield this[2];
84
- yield this[3];
85
- }
86
- [$resolve](ctx) {
87
- return ctx.gen.typeInstantiation(mat2x2f, VALID_MAT2x2_ELEMENTS.map((i) => numericLiteralToSnippet(this[i])));
88
- }
89
- toString() {
90
- return `${this.kind}(${VALID_MAT2x2_ELEMENTS.map((i) => this[i]).join(", ")})`;
91
- }
92
- };
93
- var mat2x2fImpl = class extends mat2x2Impl {
94
- kind = "mat2x2f";
95
- makeColumn(e0, e1) {
96
- return vec2f(e0, e1);
97
- }
98
- };
99
- const VALID_MAT3x3_ELEMENTS = [
100
- 0,
101
- 1,
102
- 2,
103
- 4,
104
- 5,
105
- 6,
106
- 8,
107
- 9,
108
- 10
109
- ];
110
- var mat3x3Impl = class extends MatBase {
111
- [$internal] = true;
112
- columns;
113
- length = 12;
114
- constructor(...elements) {
115
- super();
116
- this.columns = [
117
- this.makeColumn(elements[0], elements[1], elements[2]),
118
- this.makeColumn(elements[3], elements[4], elements[5]),
119
- this.makeColumn(elements[6], elements[7], elements[8])
120
- ];
121
- }
122
- get 0() {
123
- return this.columns[0].x;
124
- }
125
- get 1() {
126
- return this.columns[0].y;
127
- }
128
- get 2() {
129
- return this.columns[0].z;
130
- }
131
- get 3() {
132
- return 0;
133
- }
134
- get 4() {
135
- return this.columns[1].x;
136
- }
137
- get 5() {
138
- return this.columns[1].y;
139
- }
140
- get 6() {
141
- return this.columns[1].z;
142
- }
143
- get 7() {
144
- return 0;
145
- }
146
- get 8() {
147
- return this.columns[2].x;
148
- }
149
- get 9() {
150
- return this.columns[2].y;
151
- }
152
- get 10() {
153
- return this.columns[2].z;
154
- }
155
- get 11() {
156
- return 0;
157
- }
158
- set 0(value) {
159
- this.columns[0].x = value;
160
- }
161
- set 1(value) {
162
- this.columns[0].y = value;
163
- }
164
- set 2(value) {
165
- this.columns[0].z = value;
166
- }
167
- set 3(_) {}
168
- set 4(value) {
169
- this.columns[1].x = value;
170
- }
171
- set 5(value) {
172
- this.columns[1].y = value;
173
- }
174
- set 6(value) {
175
- this.columns[1].z = value;
176
- }
177
- set 7(_) {}
178
- set 8(value) {
179
- this.columns[2].x = value;
180
- }
181
- set 9(value) {
182
- this.columns[2].y = value;
183
- }
184
- set 10(value) {
185
- this.columns[2].z = value;
186
- }
187
- set 11(_) {}
188
- *[Symbol.iterator]() {
189
- for (let i = 0; i < 12; i++) yield this[i];
190
- }
191
- [$resolve](ctx) {
192
- return ctx.gen.typeInstantiation(mat3x3f, VALID_MAT3x3_ELEMENTS.map((i) => numericLiteralToSnippet(this[i])));
193
- }
194
- toString() {
195
- return `${this.kind}(${VALID_MAT3x3_ELEMENTS.map((i) => this[i]).join(", ")})`;
196
- }
197
- };
198
- var mat3x3fImpl = class extends mat3x3Impl {
199
- kind = "mat3x3f";
200
- makeColumn(x, y, z) {
201
- return vec3f(x, y, z);
202
- }
203
- };
204
213
  const VALID_MAT4x4_ELEMENTS = Array.from({ length: 16 }, (_, i) => i);
205
- var mat4x4Impl = class extends MatBase {
206
- [$internal] = true;
207
- columns;
208
- constructor(...elements) {
209
- super();
210
- this.columns = [
211
- this.makeColumn(elements[0], elements[1], elements[2], elements[3]),
212
- this.makeColumn(elements[4], elements[5], elements[6], elements[7]),
213
- this.makeColumn(elements[8], elements[9], elements[10], elements[11]),
214
- this.makeColumn(elements[12], elements[13], elements[14], elements[15])
215
- ];
216
- }
217
- length = 16;
218
- get 0() {
219
- return this.columns[0].x;
220
- }
221
- get 1() {
222
- return this.columns[0].y;
223
- }
224
- get 2() {
225
- return this.columns[0].z;
226
- }
227
- get 3() {
228
- return this.columns[0].w;
229
- }
230
- get 4() {
231
- return this.columns[1].x;
232
- }
233
- get 5() {
234
- return this.columns[1].y;
235
- }
236
- get 6() {
237
- return this.columns[1].z;
238
- }
239
- get 7() {
240
- return this.columns[1].w;
241
- }
242
- get 8() {
243
- return this.columns[2].x;
244
- }
245
- get 9() {
246
- return this.columns[2].y;
247
- }
248
- get 10() {
249
- return this.columns[2].z;
250
- }
251
- get 11() {
252
- return this.columns[2].w;
253
- }
254
- get 12() {
255
- return this.columns[3].x;
256
- }
257
- get 13() {
258
- return this.columns[3].y;
259
- }
260
- get 14() {
261
- return this.columns[3].z;
262
- }
263
- get 15() {
264
- return this.columns[3].w;
265
- }
266
- set 0(value) {
267
- this.columns[0].x = value;
268
- }
269
- set 1(value) {
270
- this.columns[0].y = value;
271
- }
272
- set 2(value) {
273
- this.columns[0].z = value;
274
- }
275
- set 3(value) {
276
- this.columns[0].w = value;
277
- }
278
- set 4(value) {
279
- this.columns[1].x = value;
280
- }
281
- set 5(value) {
282
- this.columns[1].y = value;
283
- }
284
- set 6(value) {
285
- this.columns[1].z = value;
286
- }
287
- set 7(value) {
288
- this.columns[1].w = value;
289
- }
290
- set 8(value) {
291
- this.columns[2].x = value;
292
- }
293
- set 9(value) {
294
- this.columns[2].y = value;
295
- }
296
- set 10(value) {
297
- this.columns[2].z = value;
298
- }
299
- set 11(value) {
300
- this.columns[2].w = value;
301
- }
302
- set 12(value) {
303
- this.columns[3].x = value;
304
- }
305
- set 13(value) {
306
- this.columns[3].y = value;
307
- }
308
- set 14(value) {
309
- this.columns[3].z = value;
310
- }
311
- set 15(value) {
312
- this.columns[3].w = value;
313
- }
314
- *[Symbol.iterator]() {
315
- for (let i = 0; i < 16; i++) yield this[i];
316
- }
317
- [$resolve](ctx) {
318
- return ctx.gen.typeInstantiation(mat4x4f, VALID_MAT4x4_ELEMENTS.map((i) => numericLiteralToSnippet(this[i])));
319
- }
320
- toString() {
321
- return `${this.kind}(${VALID_MAT4x4_ELEMENTS.map((i) => this[i]).join(", ")})`;
322
- }
323
- };
324
- var mat4x4fImpl = class extends mat4x4Impl {
325
- kind = "mat4x4f";
326
- makeColumn(x, y, z, w) {
327
- return vec4f(x, y, z, w);
328
- }
329
- };
214
+ class mat4x4Impl extends MatBase {
215
+ [$internal] = true;
216
+ columns;
217
+ constructor(...elements) {
218
+ super();
219
+ this.columns = [
220
+ this.makeColumn(elements[0], elements[1], elements[2], elements[3]),
221
+ this.makeColumn(elements[4], elements[5], elements[6], elements[7]),
222
+ this.makeColumn(elements[8], elements[9], elements[10], elements[11]),
223
+ this.makeColumn(elements[12], elements[13], elements[14], elements[15]),
224
+ ];
225
+ }
226
+ length = 16;
227
+ get 0() {
228
+ return this.columns[0].x;
229
+ }
230
+ get 1() {
231
+ return this.columns[0].y;
232
+ }
233
+ get 2() {
234
+ return this.columns[0].z;
235
+ }
236
+ get 3() {
237
+ return this.columns[0].w;
238
+ }
239
+ get 4() {
240
+ return this.columns[1].x;
241
+ }
242
+ get 5() {
243
+ return this.columns[1].y;
244
+ }
245
+ get 6() {
246
+ return this.columns[1].z;
247
+ }
248
+ get 7() {
249
+ return this.columns[1].w;
250
+ }
251
+ get 8() {
252
+ return this.columns[2].x;
253
+ }
254
+ get 9() {
255
+ return this.columns[2].y;
256
+ }
257
+ get 10() {
258
+ return this.columns[2].z;
259
+ }
260
+ get 11() {
261
+ return this.columns[2].w;
262
+ }
263
+ get 12() {
264
+ return this.columns[3].x;
265
+ }
266
+ get 13() {
267
+ return this.columns[3].y;
268
+ }
269
+ get 14() {
270
+ return this.columns[3].z;
271
+ }
272
+ get 15() {
273
+ return this.columns[3].w;
274
+ }
275
+ set 0(value) {
276
+ this.columns[0].x = value;
277
+ }
278
+ set 1(value) {
279
+ this.columns[0].y = value;
280
+ }
281
+ set 2(value) {
282
+ this.columns[0].z = value;
283
+ }
284
+ set 3(value) {
285
+ this.columns[0].w = value;
286
+ }
287
+ set 4(value) {
288
+ this.columns[1].x = value;
289
+ }
290
+ set 5(value) {
291
+ this.columns[1].y = value;
292
+ }
293
+ set 6(value) {
294
+ this.columns[1].z = value;
295
+ }
296
+ set 7(value) {
297
+ this.columns[1].w = value;
298
+ }
299
+ set 8(value) {
300
+ this.columns[2].x = value;
301
+ }
302
+ set 9(value) {
303
+ this.columns[2].y = value;
304
+ }
305
+ set 10(value) {
306
+ this.columns[2].z = value;
307
+ }
308
+ set 11(value) {
309
+ this.columns[2].w = value;
310
+ }
311
+ set 12(value) {
312
+ this.columns[3].x = value;
313
+ }
314
+ set 13(value) {
315
+ this.columns[3].y = value;
316
+ }
317
+ set 14(value) {
318
+ this.columns[3].z = value;
319
+ }
320
+ set 15(value) {
321
+ this.columns[3].w = value;
322
+ }
323
+ *[Symbol.iterator]() {
324
+ for (let i = 0; i < 16; i++) {
325
+ yield this[i];
326
+ }
327
+ }
328
+ [$resolve](ctx) {
329
+ return ctx.gen.typeInstantiation(mat4x4f,
330
+ // oxlint-disable-next-line typescript-eslint(no-non-null-assertion)
331
+ VALID_MAT4x4_ELEMENTS.map((i) => numericLiteralToSnippet(this[i])));
332
+ }
333
+ toString() {
334
+ return `${this.kind}(${VALID_MAT4x4_ELEMENTS.map((i) => this[i]).join(', ')})`;
335
+ }
336
+ }
337
+ class mat4x4fImpl extends mat4x4Impl {
338
+ kind = 'mat4x4f';
339
+ makeColumn(x, y, z, w) {
340
+ return vec4f(x, y, z, w);
341
+ }
342
+ }
343
+ // ----------
344
+ // Matrix ops
345
+ // ----------
330
346
  /**
331
- * Returns a 2-by-2 identity matrix.
332
- * @returns {m2x2f} The result matrix.
333
- */
334
- const identity2 = comptime(() => mat2x2f(1, 0, 0, 1)).$name("identity2");
347
+ * Returns a 2-by-2 identity matrix.
348
+ * @returns {m2x2f} The result matrix.
349
+ */
350
+ export const identity2 = comptime(() => mat2x2f(1, 0, 0, 1)).$name('identity2');
335
351
  /**
336
- * Returns a 3-by-3 identity matrix.
337
- * @returns {m3x3f} The result matrix.
338
- */
339
- const identity3 = comptime(() => mat3x3f(1, 0, 0, 0, 1, 0, 0, 0, 1)).$name("identity3");
352
+ * Returns a 3-by-3 identity matrix.
353
+ * @returns {m3x3f} The result matrix.
354
+ */
355
+ export const identity3 = comptime(() => mat3x3f(1, 0, 0, 0, 1, 0, 0, 0, 1)).$name('identity3');
340
356
  /**
341
- * Returns a 4-by-4 identity matrix.
342
- * @returns {m4x4f} The result matrix.
343
- */
344
- const identity4 = comptime(() => mat4x4f(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)).$name("identity4");
357
+ * Returns a 4-by-4 identity matrix.
358
+ * @returns {m4x4f} The result matrix.
359
+ */
360
+ export const identity4 = comptime(() => mat4x4f(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)).$name('identity4');
345
361
  const identityFunctions = {
346
- 2: identity2,
347
- 3: identity3,
348
- 4: identity4
362
+ 2: identity2,
363
+ 3: identity3,
364
+ 4: identity4,
349
365
  };
350
366
  /**
351
- * Creates a 4-by-4 matrix which translates by the given vector v.
352
- * @param {v3f} vector - The vector by which to translate.
353
- * @returns {m4x4f} The translation matrix.
354
- */
355
- const translation4 = dualImpl({
356
- name: "translation4",
357
- normalImpl: (vector) => mat4x4f(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, vector.x, vector.y, vector.z, 1),
358
- get signature() {
359
- return {
360
- argTypes: [vec3f],
361
- returnType: mat4x4f
362
- };
363
- },
364
- codegenImpl: (_ctx, [v]) => stitch`mat4x4f(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, ${v}.x, ${v}.y, ${v}.z, 1)`
367
+ * Creates a 4-by-4 matrix which translates by the given vector v.
368
+ * @param {v3f} vector - The vector by which to translate.
369
+ * @returns {m4x4f} The translation matrix.
370
+ */
371
+ export const translation4 = dualImpl({
372
+ name: 'translation4',
373
+ normalImpl: (vector) =>
374
+ // oxfmt-ignore
375
+ mat4x4f(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, vector.x, vector.y, vector.z, 1),
376
+ get signature() {
377
+ return { argTypes: [vec3f], returnType: mat4x4f };
378
+ },
379
+ codegenImpl: (_ctx, [v]) => stitch `mat4x4f(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, ${v}.x, ${v}.y, ${v}.z, 1)`,
380
+ sideEffects: false,
365
381
  });
366
382
  /**
367
- * Creates a 4-by-4 matrix which scales in each dimension by an amount given by the corresponding entry in the given vector.
368
- * @param {v3f} vector - A vector of three entries specifying the factor by which to scale in each dimension.
369
- * @returns {m4x4f} The scaling matrix.
370
- */
371
- const scaling4 = dualImpl({
372
- name: "scaling4",
373
- normalImpl: (vector) => mat4x4f(vector.x, 0, 0, 0, 0, vector.y, 0, 0, 0, 0, vector.z, 0, 0, 0, 0, 1),
374
- get signature() {
375
- return {
376
- argTypes: [vec3f],
377
- returnType: mat4x4f
378
- };
379
- },
380
- codegenImpl: (_ctx, [v]) => stitch`mat4x4f(${v}.x, 0, 0, 0, 0, ${v}.y, 0, 0, 0, 0, ${v}.z, 0, 0, 0, 0, 1)`
383
+ * Creates a 4-by-4 matrix which scales in each dimension by an amount given by the corresponding entry in the given vector.
384
+ * @param {v3f} vector - A vector of three entries specifying the factor by which to scale in each dimension.
385
+ * @returns {m4x4f} The scaling matrix.
386
+ */
387
+ export const scaling4 = dualImpl({
388
+ name: 'scaling4',
389
+ normalImpl: (vector) =>
390
+ // oxfmt-ignore
391
+ mat4x4f(vector.x, 0, 0, 0, 0, vector.y, 0, 0, 0, 0, vector.z, 0, 0, 0, 0, 1),
392
+ get signature() {
393
+ return { argTypes: [vec3f], returnType: mat4x4f };
394
+ },
395
+ codegenImpl: (_ctx, [v]) => stitch `mat4x4f(${v}.x, 0, 0, 0, 0, ${v}.y, 0, 0, 0, 0, ${v}.z, 0, 0, 0, 0, 1)`,
396
+ sideEffects: false,
381
397
  });
382
398
  /**
383
- * Creates a 4-by-4 matrix which rotates around the x-axis by the given angle.
384
- * @param {number} angle - The angle by which to rotate (in radians).
385
- * @returns {m4x4f} The rotation matrix.
386
- */
387
- const rotationX4 = dualImpl({
388
- name: "rotationX4",
389
- normalImpl: (a) => mat4x4f(1, 0, 0, 0, 0, Math.cos(a), Math.sin(a), 0, 0, -Math.sin(a), Math.cos(a), 0, 0, 0, 0, 1),
390
- get signature() {
391
- return {
392
- argTypes: [f32],
393
- returnType: mat4x4f
394
- };
395
- },
396
- codegenImpl: (_ctx, [a]) => stitch`mat4x4f(1, 0, 0, 0, 0, cos(${a}), sin(${a}), 0, 0, -sin(${a}), cos(${a}), 0, 0, 0, 0, 1)`
399
+ * Creates a 4-by-4 matrix which rotates around the x-axis by the given angle.
400
+ * @param {number} angle - The angle by which to rotate (in radians).
401
+ * @returns {m4x4f} The rotation matrix.
402
+ */
403
+ export const rotationX4 = dualImpl({
404
+ name: 'rotationX4',
405
+ normalImpl: (a) =>
406
+ // oxfmt-ignore
407
+ mat4x4f(1, 0, 0, 0, 0, Math.cos(a), Math.sin(a), 0, 0, -Math.sin(a), Math.cos(a), 0, 0, 0, 0, 1),
408
+ get signature() {
409
+ return { argTypes: [f32], returnType: mat4x4f };
410
+ },
411
+ codegenImpl: (_ctx, [a]) => stitch `mat4x4f(1, 0, 0, 0, 0, cos(${a}), sin(${a}), 0, 0, -sin(${a}), cos(${a}), 0, 0, 0, 0, 1)`,
412
+ sideEffects: false,
397
413
  });
398
414
  /**
399
- * Creates a 4-by-4 matrix which rotates around the y-axis by the given angle.
400
- * @param {number} angle - The angle by which to rotate (in radians).
401
- * @returns {m4x4f} The rotation matrix.
402
- */
403
- const rotationY4 = dualImpl({
404
- name: "rotationY4",
405
- normalImpl: (a) => mat4x4f(Math.cos(a), 0, -Math.sin(a), 0, 0, 1, 0, 0, Math.sin(a), 0, Math.cos(a), 0, 0, 0, 0, 1),
406
- get signature() {
407
- return {
408
- argTypes: [f32],
409
- returnType: mat4x4f
410
- };
411
- },
412
- codegenImpl: (_ctx, [a]) => stitch`mat4x4f(cos(${a}), 0, -sin(${a}), 0, 0, 1, 0, 0, sin(${a}), 0, cos(${a}), 0, 0, 0, 0, 1)`
415
+ * Creates a 4-by-4 matrix which rotates around the y-axis by the given angle.
416
+ * @param {number} angle - The angle by which to rotate (in radians).
417
+ * @returns {m4x4f} The rotation matrix.
418
+ */
419
+ export const rotationY4 = dualImpl({
420
+ name: 'rotationY4',
421
+ normalImpl: (a) =>
422
+ // oxfmt-ignore
423
+ mat4x4f(Math.cos(a), 0, -Math.sin(a), 0, 0, 1, 0, 0, Math.sin(a), 0, Math.cos(a), 0, 0, 0, 0, 1),
424
+ get signature() {
425
+ return { argTypes: [f32], returnType: mat4x4f };
426
+ },
427
+ codegenImpl: (_ctx, [a]) => stitch `mat4x4f(cos(${a}), 0, -sin(${a}), 0, 0, 1, 0, 0, sin(${a}), 0, cos(${a}), 0, 0, 0, 0, 1)`,
428
+ sideEffects: false,
413
429
  });
414
430
  /**
415
- * Creates a 4-by-4 matrix which rotates around the z-axis by the given angle.
416
- * @param {number} angle - The angle by which to rotate (in radians).
417
- * @returns {m4x4f} The rotation matrix.
418
- */
419
- const rotationZ4 = dualImpl({
420
- name: "rotationZ4",
421
- normalImpl: (a) => mat4x4f(Math.cos(a), Math.sin(a), 0, 0, -Math.sin(a), Math.cos(a), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1),
422
- get signature() {
423
- return {
424
- argTypes: [f32],
425
- returnType: mat4x4f
426
- };
427
- },
428
- codegenImpl: (_ctx, [a]) => stitch`mat4x4f(cos(${a}), sin(${a}), 0, 0, -sin(${a}), cos(${a}), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)`
431
+ * Creates a 4-by-4 matrix which rotates around the z-axis by the given angle.
432
+ * @param {number} angle - The angle by which to rotate (in radians).
433
+ * @returns {m4x4f} The rotation matrix.
434
+ */
435
+ export const rotationZ4 = dualImpl({
436
+ name: 'rotationZ4',
437
+ normalImpl: (a) =>
438
+ // oxfmt-ignore
439
+ mat4x4f(Math.cos(a), Math.sin(a), 0, 0, -Math.sin(a), Math.cos(a), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1),
440
+ get signature() {
441
+ return { argTypes: [f32], returnType: mat4x4f };
442
+ },
443
+ codegenImpl: (_ctx, [a]) => stitch `mat4x4f(cos(${a}), sin(${a}), 0, 0, -sin(${a}), cos(${a}), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)`,
444
+ sideEffects: false,
429
445
  });
446
+ // ----------
447
+ // Public API
448
+ // ----------
430
449
  /**
431
- * Schema representing mat2x2f - a matrix with 2 rows and 2 columns, with elements of type f32.
432
- * Also a constructor function for this matrix type.
433
- *
434
- * @example
435
- * const zero2x2 = mat2x2f(); // filled with zeros
436
- *
437
- * @example
438
- * const mat = mat2x2f(0, 1, 2, 3);
439
- * mat.columns[0] // vec2f(0, 1)
440
- * mat.columns[1] // vec2f(2, 3)
441
- *
442
- * @example
443
- * const mat = mat2x2f(
444
- * vec2f(0, 1), // column 0
445
- * vec2f(1, 2), // column 1
446
- * );
447
- *
448
- * @example
449
- * const buffer = root.createBuffer(d.mat2x2f, d.mat2x2f(0, 1, 2, 3)); // buffer holding a d.mat2x2f value, with an initial value of ((0, 1), (2, 3))
450
- */
451
- const mat2x2f = createMatSchema({
452
- type: "mat2x2f",
453
- rows: 2,
454
- columns: 2,
455
- MatImpl: mat2x2fImpl
450
+ * Schema representing mat2x2f - a matrix with 2 rows and 2 columns, with elements of type f32.
451
+ * Also a constructor function for this matrix type.
452
+ *
453
+ * @example
454
+ * const zero2x2 = mat2x2f(); // filled with zeros
455
+ *
456
+ * @example
457
+ * const mat = mat2x2f(0, 1, 2, 3);
458
+ * mat.columns[0] // vec2f(0, 1)
459
+ * mat.columns[1] // vec2f(2, 3)
460
+ *
461
+ * @example
462
+ * const mat = mat2x2f(
463
+ * vec2f(0, 1), // column 0
464
+ * vec2f(1, 2), // column 1
465
+ * );
466
+ *
467
+ * @example
468
+ * const buffer = root.createBuffer(d.mat2x2f, d.mat2x2f(0, 1, 2, 3)); // buffer holding a d.mat2x2f value, with an initial value of ((0, 1), (2, 3))
469
+ */
470
+ export const mat2x2f = createMatSchema({
471
+ type: 'mat2x2f',
472
+ rows: 2,
473
+ columns: 2,
474
+ MatImpl: mat2x2fImpl,
456
475
  });
457
476
  /**
458
- * Schema representing mat3x3f - a matrix with 3 rows and 3 columns, with elements of type f32.
459
- * Also a constructor function for this matrix type.
460
- *
461
- * @example
462
- * const zero3x3 = mat3x3f(); // filled with zeros
463
- *
464
- * @example
465
- * const mat = mat3x3f(0, 1, 2, 3, 4, 5, 6, 7, 8);
466
- * mat.columns[0] // vec3f(0, 1, 2)
467
- * mat.columns[1] // vec3f(3, 4, 5)
468
- * mat.columns[2] // vec3f(6, 7, 8)
469
- *
470
- * @example
471
- * const mat = mat3x3f(
472
- * vec3f(0, 1, 2), // column 0
473
- * vec3f(2, 3, 4), // column 1
474
- * vec3f(5, 6, 7), // column 2
475
- * );
476
- *
477
- * @example
478
- * const buffer = root.createBuffer(d.mat3x3f, d.mat3x3f()); // buffer holding a d.mat3x3f value, with an initial value of mat3x3f filled with zeros
479
- */
480
- const mat3x3f = createMatSchema({
481
- type: "mat3x3f",
482
- rows: 3,
483
- columns: 3,
484
- MatImpl: mat3x3fImpl
477
+ * Schema representing mat3x3f - a matrix with 3 rows and 3 columns, with elements of type f32.
478
+ * Also a constructor function for this matrix type.
479
+ *
480
+ * @example
481
+ * const zero3x3 = mat3x3f(); // filled with zeros
482
+ *
483
+ * @example
484
+ * const mat = mat3x3f(0, 1, 2, 3, 4, 5, 6, 7, 8);
485
+ * mat.columns[0] // vec3f(0, 1, 2)
486
+ * mat.columns[1] // vec3f(3, 4, 5)
487
+ * mat.columns[2] // vec3f(6, 7, 8)
488
+ *
489
+ * @example
490
+ * const mat = mat3x3f(
491
+ * vec3f(0, 1, 2), // column 0
492
+ * vec3f(2, 3, 4), // column 1
493
+ * vec3f(5, 6, 7), // column 2
494
+ * );
495
+ *
496
+ * @example
497
+ * const buffer = root.createBuffer(d.mat3x3f, d.mat3x3f()); // buffer holding a d.mat3x3f value, with an initial value of mat3x3f filled with zeros
498
+ */
499
+ export const mat3x3f = createMatSchema({
500
+ type: 'mat3x3f',
501
+ rows: 3,
502
+ columns: 3,
503
+ MatImpl: mat3x3fImpl,
485
504
  });
486
505
  /**
487
- * Schema representing mat4x4f - a matrix with 4 rows and 4 columns, with elements of type f32.
488
- * Also a constructor function for this matrix type.
489
- *
490
- * @example
491
- * const zero4x4 = mat4x4f(); // filled with zeros
492
- *
493
- * @example
494
- * const mat = mat4x4f(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
495
- * mat.columns[0] // vec4f(0, 1, 2, 3)
496
- * mat.columns[1] // vec4f(4, 5, 6, 7)
497
- * mat.columns[2] // vec4f(8, 9, 10, 11)
498
- * mat.columns[3] // vec4f(12, 13, 14, 15)
499
- *
500
- * @example
501
- * const mat = mat4x4f(
502
- * vec4f(0, 1, 2, 3), // column 0
503
- * vec4f(4, 5, 6, 7), // column 1
504
- * vec4f(8, 9, 10, 11), // column 2
505
- * vec4f(12, 13, 14, 15), // column 3
506
- * );
507
- *
508
- * @example
509
- * const buffer = root.createBuffer(d.mat4x4f, d.mat4x4f()); // buffer holding a d.mat4x4f value, with an initial value of mat4x4f filled with zeros
510
- */
511
- const mat4x4f = createMatSchema({
512
- type: "mat4x4f",
513
- rows: 4,
514
- columns: 4,
515
- MatImpl: mat4x4fImpl
506
+ * Schema representing mat4x4f - a matrix with 4 rows and 4 columns, with elements of type f32.
507
+ * Also a constructor function for this matrix type.
508
+ *
509
+ * @example
510
+ * const zero4x4 = mat4x4f(); // filled with zeros
511
+ *
512
+ * @example
513
+ * const mat = mat4x4f(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
514
+ * mat.columns[0] // vec4f(0, 1, 2, 3)
515
+ * mat.columns[1] // vec4f(4, 5, 6, 7)
516
+ * mat.columns[2] // vec4f(8, 9, 10, 11)
517
+ * mat.columns[3] // vec4f(12, 13, 14, 15)
518
+ *
519
+ * @example
520
+ * const mat = mat4x4f(
521
+ * vec4f(0, 1, 2, 3), // column 0
522
+ * vec4f(4, 5, 6, 7), // column 1
523
+ * vec4f(8, 9, 10, 11), // column 2
524
+ * vec4f(12, 13, 14, 15), // column 3
525
+ * );
526
+ *
527
+ * @example
528
+ * const buffer = root.createBuffer(d.mat4x4f, d.mat4x4f()); // buffer holding a d.mat4x4f value, with an initial value of mat4x4f filled with zeros
529
+ */
530
+ export const mat4x4f = createMatSchema({
531
+ type: 'mat4x4f',
532
+ rows: 4,
533
+ columns: 4,
534
+ MatImpl: mat4x4fImpl,
516
535
  });
517
- function matToArray(mat) {
518
- if (mat.kind === "mat3x3f") return [
519
- mat[0],
520
- mat[1],
521
- mat[2],
522
- mat[4],
523
- mat[5],
524
- mat[6],
525
- mat[8],
526
- mat[9],
527
- mat[10]
528
- ];
529
- return Array.from({ length: mat.length }).map((_, idx) => mat[idx]);
536
+ export function matToArray(mat) {
537
+ if (mat.kind === 'mat3x3f') {
538
+ return [mat[0], mat[1], mat[2], mat[4], mat[5], mat[6], mat[8], mat[9], mat[10]];
539
+ }
540
+ return Array.from({ length: mat.length }).map((_, idx) => mat[idx]);
530
541
  }
531
-
532
- //#endregion
533
- export { MatBase, identity2, identity3, identity4, mat2x2f, mat3x3f, mat4x4f, matToArray, rotationX4, rotationY4, rotationZ4, scaling4, translation4 };