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.
- package/bin.mjs +28 -6
- package/builtin.d.ts +51 -53
- package/builtin.js +30 -34
- package/common/fullScreenTriangle.d.ts +2 -10
- package/common/fullScreenTriangle.js +20 -28
- package/common/index.d.ts +2 -9
- package/common/index.js +3 -12
- package/common/writeSoA.d.ts +11 -12
- package/common/writeSoA.js +88 -76
- package/core/buffer/buffer.d.ts +79 -62
- package/core/buffer/buffer.js +283 -205
- package/core/buffer/bufferBinding.d.ts +71 -0
- package/core/buffer/bufferBinding.js +154 -0
- package/core/buffer/bufferUsage.d.ts +14 -45
- package/core/buffer/bufferUsage.js +1 -171
- package/core/buffer/laidOutBuffer.d.ts +25 -0
- package/core/buffer/laidOutBuffer.js +55 -0
- package/core/commandEncoder/attachments.d.ts +125 -0
- package/core/commandEncoder/attachments.js +29 -0
- package/core/commandEncoder/commandEncoder.d.ts +53 -0
- package/core/commandEncoder/commandEncoder.js +56 -0
- package/core/commandEncoder/computePass.d.ts +58 -0
- package/core/commandEncoder/computePass.js +63 -0
- package/core/commandEncoder/renderPass.d.ts +121 -0
- package/core/commandEncoder/renderPass.js +196 -0
- package/core/constant/tgpuConstant.d.ts +26 -26
- package/core/constant/tgpuConstant.js +76 -65
- package/core/declare/tgpuDeclare.d.ts +3 -6
- package/core/declare/tgpuDeclare.js +36 -36
- package/core/function/autoIO.d.ts +61 -33
- package/core/function/autoIO.js +68 -73
- package/core/function/comptime.d.ts +11 -13
- package/core/function/comptime.js +60 -52
- package/core/function/createCallableSchema.d.ts +16 -0
- package/core/function/createCallableSchema.js +50 -40
- package/core/function/dualImpl.d.ts +44 -0
- package/core/function/dualImpl.js +71 -50
- package/core/function/entryInputRouter.d.ts +26 -0
- package/core/function/entryInputRouter.js +31 -33
- package/core/function/extractArgs.d.ts +38 -0
- package/core/function/extractArgs.js +202 -200
- package/core/function/fnCore.d.ts +44 -5
- package/core/function/fnCore.js +148 -93
- package/core/function/fnTypes.d.ts +31 -29
- package/core/function/fnTypes.js +1 -0
- package/core/function/ioSchema.d.ts +12 -10
- package/core/function/ioSchema.js +65 -47
- package/core/function/shelllessImpl.d.ts +9 -12
- package/core/function/shelllessImpl.js +17 -22
- package/core/function/templateUtils.d.ts +2 -0
- package/core/function/templateUtils.js +9 -8
- package/core/function/tgpuComputeFn.d.ts +26 -28
- package/core/function/tgpuComputeFn.js +47 -48
- package/core/function/tgpuFn.d.ts +34 -37
- package/core/function/tgpuFn.js +179 -153
- package/core/function/tgpuFragmentFn.d.ts +52 -53
- package/core/function/tgpuFragmentFn.js +63 -56
- package/core/function/tgpuVertexFn.d.ts +36 -39
- package/core/function/tgpuVertexFn.js +56 -53
- package/core/pipeline/computePipeline.d.ts +141 -53
- package/core/pipeline/computePipeline.js +291 -225
- package/core/pipeline/connectAttachmentToShader.d.ts +4 -0
- package/core/pipeline/connectAttachmentToShader.js +25 -22
- package/core/pipeline/connectTargetsToShader.d.ts +3 -0
- package/core/pipeline/connectTargetsToShader.js +29 -27
- package/core/pipeline/drawState.d.ts +52 -0
- package/core/pipeline/drawState.js +225 -0
- package/core/pipeline/performanceTracker.d.ts +14 -0
- package/core/pipeline/performanceTracker.js +34 -0
- package/core/pipeline/pipelineUtils.d.ts +18 -0
- package/core/pipeline/pipelineUtils.js +54 -25
- package/core/pipeline/priors.d.ts +1 -0
- package/core/pipeline/priors.js +12 -0
- package/core/pipeline/renderPipeline.d.ts +246 -261
- package/core/pipeline/renderPipeline.js +487 -480
- package/core/pipeline/timeable.d.ts +28 -18
- package/core/pipeline/timeable.js +90 -52
- package/core/pipeline/typeGuards.d.ts +17 -0
- package/core/pipeline/typeGuards.js +52 -22
- package/core/pipeline/webgpuLimitations.d.ts +10 -0
- package/core/pipeline/webgpuLimitations.js +81 -0
- package/core/querySet/querySet.d.ts +26 -21
- package/core/querySet/querySet.js +127 -103
- package/core/rawCodeSnippet/tgpuRawCodeSnippet.d.ts +13 -18
- package/core/rawCodeSnippet/tgpuRawCodeSnippet.js +89 -90
- package/core/resolve/externals.d.ts +25 -8
- package/core/resolve/externals.js +78 -54
- package/core/resolve/namespace.d.ts +22 -25
- package/core/resolve/namespace.js +16 -21
- package/core/resolve/resolvableString.d.ts +7 -0
- package/core/resolve/resolvableString.js +13 -0
- package/core/resolve/resolveData.d.ts +10 -0
- package/core/resolve/resolveData.js +162 -121
- package/core/resolve/stitch.d.ts +8 -0
- package/core/resolve/stitch.js +23 -21
- package/core/resolve/tgpuResolve.d.ts +55 -53
- package/core/resolve/tgpuResolve.js +106 -53
- package/core/root/configurableImpl.d.ts +10 -0
- package/core/root/configurableImpl.js +17 -19
- package/core/root/init.d.ts +76 -38
- package/core/root/init.js +346 -455
- package/core/root/rootTypes.d.ts +461 -636
- package/core/root/rootTypes.js +1 -0
- package/core/sampler/sampler.d.ts +50 -31
- package/core/sampler/sampler.js +120 -113
- package/core/simulate/tgpuSimulate.d.ts +9 -12
- package/core/simulate/tgpuSimulate.js +68 -71
- package/core/slot/accessor.d.ts +36 -13
- package/core/slot/accessor.js +138 -91
- package/core/slot/internalSlots.d.ts +2 -0
- package/core/slot/internalSlots.js +1 -6
- package/core/slot/lazy.d.ts +2 -6
- package/core/slot/lazy.js +71 -39
- package/core/slot/slot.d.ts +2 -6
- package/core/slot/slot.js +45 -38
- package/core/slot/slotTypes.d.ts +78 -80
- package/core/slot/slotTypes.js +11 -16
- package/core/texture/externalTexture.d.ts +20 -11
- package/core/texture/externalTexture.js +46 -46
- package/core/texture/texture.d.ts +152 -97
- package/core/texture/texture.js +407 -314
- package/core/texture/textureFormats.d.ts +42 -23
- package/core/texture/textureFormats.js +104 -75
- package/core/texture/textureProps.d.ts +7 -10
- package/core/texture/textureProps.js +1 -0
- package/core/texture/textureUtils.d.ts +8 -0
- package/core/texture/textureUtils.js +185 -179
- package/core/texture/usageExtension.d.ts +21 -18
- package/core/texture/usageExtension.js +13 -17
- package/core/unroll/tgpuUnroll.d.ts +20 -19
- package/core/unroll/tgpuUnroll.js +82 -91
- package/core/valueProxyUtils.d.ts +3 -0
- package/core/valueProxyUtils.js +52 -41
- package/core/variable/tgpuVariable.d.ts +26 -27
- package/core/variable/tgpuVariable.js +93 -96
- package/core/vertexLayout/connectAttributesToShader.d.ts +9 -0
- package/core/vertexLayout/connectAttributesToShader.js +61 -56
- package/core/vertexLayout/vertexAttribute.d.ts +21 -17
- package/core/vertexLayout/vertexAttribute.js +1 -0
- package/core/vertexLayout/vertexLayout.d.ts +24 -18
- package/core/vertexLayout/vertexLayout.js +130 -99
- package/core/whitespaces.d.ts +2 -0
- package/core/whitespaces.js +16 -0
- package/data/alignIO.d.ts +7 -0
- package/data/alignIO.js +13 -13
- package/data/alignmentOf.d.ts +5 -8
- package/data/alignmentOf.js +90 -75
- package/data/array.d.ts +17 -9
- package/data/array.js +57 -40
- package/data/atomic.d.ts +2 -7
- package/data/atomic.js +26 -23
- package/data/attributes.d.ts +19 -21
- package/data/attributes.js +192 -132
- package/data/autoStruct.d.ts +36 -3
- package/data/autoStruct.js +84 -81
- package/data/compiledIO.d.ts +5 -0
- package/data/compiledIO.js +231 -215
- package/data/dataIO.d.ts +13 -11
- package/data/dataIO.js +643 -589
- package/data/dataTypes.d.ts +83 -65
- package/data/dataTypes.js +66 -68
- package/data/deepEqual.d.ts +2 -7
- package/data/deepEqual.js +80 -55
- package/data/disarray.d.ts +6 -10
- package/data/disarray.js +52 -46
- package/data/float16Conversion.d.ts +4 -0
- package/data/float16Conversion.js +7 -0
- package/data/generalizeFn.d.ts +25 -0
- package/data/generalizeFn.js +89 -0
- package/data/getLongestContiguousPrefix.d.ts +4 -8
- package/data/getLongestContiguousPrefix.js +6 -11
- package/data/index.d.ts +30 -31
- package/data/index.js +39 -172
- package/data/instanceToSchema.d.ts +24 -27
- package/data/instanceToSchema.js +1 -0
- package/data/isContiguous.d.ts +4 -8
- package/data/isContiguous.js +6 -11
- package/data/matrix.d.ts +21 -21
- package/data/matrix.js +513 -505
- package/data/numberOps.d.ts +5 -0
- package/data/numberOps.js +21 -21
- package/data/numeric.d.ts +21 -12
- package/data/numeric.js +287 -197
- package/data/offsetUtils.d.ts +9 -13
- package/data/offsetUtils.js +204 -144
- package/data/offsets.d.ts +8 -0
- package/data/offsets.js +33 -33
- package/data/partialIO.d.ts +13 -8
- package/data/partialIO.js +124 -113
- package/data/ptr.d.ts +12 -12
- package/data/ptr.js +42 -44
- package/data/ref.d.ts +40 -27
- package/data/ref.js +125 -95
- package/data/sampler.d.ts +99 -101
- package/data/sampler.js +17 -21
- package/data/schemaCallWrapper.d.ts +19 -0
- package/data/schemaCallWrapper.js +31 -26
- package/data/schemaMemoryLayout.d.ts +8 -0
- package/data/schemaMemoryLayout.js +213 -185
- package/data/sizeOf.d.ts +4 -8
- package/data/sizeOf.js +6 -11
- package/data/snippet.d.ts +96 -20
- package/data/snippet.js +75 -86
- package/data/struct.d.ts +4 -7
- package/data/struct.js +51 -39
- package/data/texture.d.ts +253 -250
- package/data/texture.js +238 -200
- package/data/unstruct.d.ts +2 -7
- package/data/unstruct.js +43 -37
- package/data/vector.d.ts +33 -21
- package/data/vector.js +234 -221
- package/data/vectorImpl.d.ts +231 -0
- package/data/vectorImpl.js +563 -515
- package/data/vectorOps.d.ts +25 -0
- package/data/vectorOps.js +118 -669
- package/data/vertexFormatData.d.ts +181 -184
- package/data/vertexFormatData.js +104 -106
- package/data/wgslTypes.d.ts +665 -600
- package/data/wgslTypes.js +220 -198
- package/errors.d.ts +50 -24
- package/errors.js +146 -126
- package/execMode.d.ts +16 -0
- package/execMode.js +47 -40
- package/extension.d.ts +13 -8
- package/extension.js +10 -16
- package/getGPUValue.d.ts +1 -0
- package/getGPUValue.js +2 -7
- package/index.d.ts +28 -68
- package/index.js +8 -28
- package/indexNamedExports.d.ts +69 -42
- package/indexNamedExports.js +25 -0
- package/internal.d.ts +16 -0
- package/internal.js +12 -0
- package/mathUtils.d.ts +5 -0
- package/mathUtils.js +7 -11
- package/memo.d.ts +11 -0
- package/memo.js +20 -22
- package/minify.d.ts +5 -0
- package/minify.js +93 -0
- package/nameUtils.d.ts +29 -0
- package/nameUtils.js +427 -394
- package/package.json +5 -1
- package/resolutionCtx.d.ts +162 -22
- package/resolutionCtx.js +911 -629
- package/serial/registry.d.ts +15 -0
- package/serial/registry.js +106 -0
- package/serial/restore.d.ts +49 -0
- package/serial/restore.js +68 -0
- package/serial/schema.d.ts +58 -0
- package/serial/schema.js +209 -0
- package/serial/types.d.ts +5 -0
- package/serial/types.js +1 -0
- package/shared/env.d.ts +9 -0
- package/shared/env.js +9 -12
- package/shared/generators.d.ts +4 -0
- package/shared/generators.js +10 -12
- package/shared/meta.d.ts +29 -14
- package/shared/meta.js +71 -55
- package/shared/normalizeMetadata.d.ts +32 -27
- package/shared/normalizeMetadata.js +23 -36
- package/shared/repr.d.ts +73 -55
- package/shared/repr.js +1 -0
- package/shared/soul.d.ts +17 -0
- package/shared/soul.js +1 -0
- package/shared/stringify.d.ts +2 -0
- package/shared/stringify.js +29 -20
- package/shared/symbols.d.ts +26 -20
- package/shared/symbols.js +79 -79
- package/shared/tseynit.d.ts +2 -0
- package/shared/tseynit.js +160 -75
- package/shared/utilityTypes.d.ts +30 -14
- package/shared/utilityTypes.js +2 -6
- package/shared/vertexFormat.d.ts +41 -43
- package/shared/vertexFormat.js +59 -62
- package/std/array.d.ts +2 -7
- package/std/array.js +18 -23
- package/std/atomic.d.ts +14 -18
- package/std/atomic.js +96 -95
- package/std/bitcast.d.ts +193 -10
- package/std/bitcast.js +309 -39
- package/std/boolean.d.ts +19 -33
- package/std/boolean.js +296 -292
- package/std/copy.d.ts +2 -7
- package/std/copy.js +27 -24
- package/std/derivative.d.ts +11 -15
- package/std/derivative.js +56 -79
- package/std/discard.d.ts +1 -6
- package/std/discard.js +7 -14
- package/std/environment.d.ts +19 -14
- package/std/environment.js +71 -51
- package/std/extensions.d.ts +2 -8
- package/std/extensions.js +10 -11
- package/std/index.d.ts +20 -24
- package/std/index.js +32 -187
- package/std/matrix.d.ts +6 -12
- package/std/matrix.js +60 -69
- package/std/numeric.d.ts +150 -146
- package/std/numeric.js +771 -727
- package/std/operators.d.ts +19 -27
- package/std/operators.js +195 -194
- package/std/packing.d.ts +5 -11
- package/std/packing.js +67 -75
- package/std/range.d.ts +6 -11
- package/std/range.js +48 -36
- package/std/subgroup.d.ts +33 -37
- package/std/subgroup.js +180 -217
- package/std/texture.d.ts +70 -38
- package/std/texture.js +176 -172
- package/taskQueue.d.ts +6 -0
- package/taskQueue.js +30 -0
- package/tgpu.d.ts +16 -0
- package/tgpu.js +17 -44
- package/tgpuBindGroupLayout.d.ts +132 -152
- package/tgpuBindGroupLayout.js +346 -268
- package/tgpuLogger.d.ts +34 -0
- package/tgpuLogger.js +64 -0
- package/tgpuUnstable.d.ts +16 -22
- package/tgpuUnstable.js +13 -35
- package/tgsl/accessIndex.d.ts +2 -0
- package/tgsl/accessIndex.js +76 -33
- package/tgsl/accessProp.d.ts +2 -0
- package/tgsl/accessProp.js +142 -101
- package/tgsl/accessStructProp.d.ts +5 -0
- package/tgsl/accessStructProp.js +13 -15
- package/tgsl/consoleLog/deserializers.d.ts +13 -0
- package/tgsl/consoleLog/deserializers.js +119 -103
- package/tgsl/consoleLog/logGenerator.d.ts +21 -0
- package/tgsl/consoleLog/logGenerator.js +85 -80
- package/tgsl/consoleLog/serializers.d.ts +21 -0
- package/tgsl/consoleLog/serializers.js +119 -100
- package/tgsl/consoleLog/types.d.ts +40 -39
- package/tgsl/consoleLog/types.js +1 -0
- package/tgsl/conversion.d.ts +33 -0
- package/tgsl/conversion.js +271 -216
- package/tgsl/forOfUtils.d.ts +15 -0
- package/tgsl/forOfUtils.js +85 -70
- package/tgsl/generationHelpers.d.ts +22 -39
- package/tgsl/generationHelpers.js +85 -58
- package/tgsl/infixDispatch.d.ts +70 -0
- package/tgsl/infixDispatch.js +48 -46
- package/tgsl/jsPolyfills.d.ts +16 -19
- package/tgsl/jsPolyfills.js +44 -42
- package/tgsl/makeDereferenceable.d.ts +48 -0
- package/tgsl/makeDereferenceable.js +86 -0
- package/tgsl/makeResolvable.d.ts +22 -0
- package/tgsl/makeResolvable.js +33 -0
- package/tgsl/shaderGenerator.d.ts +77 -17
- package/tgsl/shaderGenerator.js +1 -0
- package/tgsl/shellless.d.ts +6 -9
- package/tgsl/shellless.js +73 -43
- package/tgsl/wgslGenerator.d.ts +66 -59
- package/tgsl/wgslGenerator.js +1345 -760
- package/types.d.ts +287 -222
- package/types.js +61 -44
- package/unwrapper.d.ts +31 -26
- package/unwrapper.js +1 -0
- package/wgslExtensions.d.ts +3 -5
- package/wgslExtensions.js +12 -16
- package/_virtual/rolldown_runtime.js +0 -13
- package/core/buffer/bufferShorthand.d.ts +0 -50
- package/core/buffer/bufferShorthand.js +0 -55
- package/core/pipeline/applyPipelineState.js +0 -37
- package/core/pipeline/limitsOverflow.js +0 -13
- package/package.js +0 -5
- package/tgsl/shaderGenerator_members.d.ts +0 -33
- package/tgsl/shaderGenerator_members.js +0 -12
package/data/matrix.js
CHANGED
|
@@ -1,533 +1,541 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
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 {
|
|
9
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
347
|
-
|
|
348
|
-
|
|
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
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
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
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
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
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
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
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
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
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
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
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
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
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
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
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
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
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
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 };
|