@woosh/meep-engine 2.75.8 → 2.76.0

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 (107) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/build/meep.cjs +784 -982
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +784 -982
  5. package/editor/actions/concrete/ModifyPatchSampler2DAction.js +6 -3
  6. package/editor/actions/concrete/PatchTerrainTextureAction.js +6 -3
  7. package/editor/process/EditorProcess.js +12 -16
  8. package/editor/process/ProcessEngine.js +9 -10
  9. package/package.json +1 -1
  10. package/src/core/binary/dec2hex.js +1 -1
  11. package/src/{engine/ecs/ik/IKMath.js → core/geom/vec3/v3_computeOffsetVector.js} +1 -1
  12. package/src/core/math/newton_solver_1d.js +13 -4
  13. package/src/{engine/graphics → core/math/random}/generate_halton_jitter.js +2 -2
  14. package/src/core/math/solveQuadratic.js +5 -3
  15. package/src/core/math/spline/catmull_rom_compute_T.js +19 -0
  16. package/src/{engine/navigation/ecs/components → core/math/spline}/computeCatmullRomSpline.js +3 -3
  17. package/src/{engine/navigation/ecs/components → core/math/spline}/computeCatmullRomSplineUniformDistance.js +3 -3
  18. package/src/core/math/spline/computeNonuniformCatmullRomSplineSample.js +109 -0
  19. package/src/core/math/spline/interpolate_bicubic.js +12 -0
  20. package/src/core/math/spline/spline_catmullrom_1d.js +120 -0
  21. package/src/engine/control/ControlContext.js +25 -27
  22. package/src/engine/ecs/EntityManager.js +12 -9
  23. package/src/engine/ecs/EntityObserver.js +26 -22
  24. package/src/engine/ecs/binding/ComponentPropertyPath.js +12 -12
  25. package/src/engine/ecs/components/Motion.js +5 -7
  26. package/src/engine/ecs/components/SerializationMetadata.js +5 -3
  27. package/src/engine/ecs/dynamic_actions/actions/definition/AbstractActionDescription.js +0 -2
  28. package/src/engine/ecs/dynamic_actions/actions/definition/ActionSequenceDescription.js +7 -9
  29. package/src/engine/ecs/dynamic_actions/actions/definition/DelayActionDescription.js +3 -5
  30. package/src/engine/ecs/dynamic_actions/actions/definition/SendRequestActionDescription.js +6 -8
  31. package/src/engine/ecs/dynamic_actions/actions/definition/SpeakLineActionDescription.js +14 -17
  32. package/src/engine/ecs/dynamic_actions/actions/definition/WeightedRandomActionDescription.js +8 -11
  33. package/src/engine/ecs/dynamic_actions/actions/definition/WriteToBlackboardActionDescription.js +15 -18
  34. package/src/engine/ecs/ik/OneBoneSurfaceAlignmentSolver.js +7 -7
  35. package/src/engine/ecs/ik/TwoBoneInverseKinematicsSolver.js +6 -6
  36. package/src/engine/ecs/parent/EntityNode.js +39 -37
  37. package/src/engine/ecs/speaker/VoiceSystem.js +36 -39
  38. package/src/engine/ecs/system/SystemEntityContext.js +25 -23
  39. package/src/engine/ecs/tag/find_entities_with_tag.js +18 -0
  40. package/src/engine/ecs/terrain/TerrainClouds.js +23 -24
  41. package/src/engine/ecs/terrain/ecs/splat/SplatMapMaterialPatch.js +5 -2
  42. package/src/engine/ecs/terrain/overlay/TerrainOverlay.js +15 -14
  43. package/src/engine/ecs/tooltip/TooltipComponent.js +6 -7
  44. package/src/engine/graphics/camera/testClippingPlaneComputation.js +0 -4
  45. package/src/engine/graphics/ecs/path/testPathDisplaySystem.js +1 -5
  46. package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +2 -6
  47. package/src/engine/graphics/ecs/water2/shader/testWaterShader.js +12 -14
  48. package/src/engine/graphics/material/optimization/MaterialOptimizationContext.js +22 -20
  49. package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +3 -4
  50. package/src/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +0 -4
  51. package/src/engine/graphics/render/buffer/simple-fx/taa/TemporalSupersamplingRenderPlugin.js +1 -1
  52. package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +0 -4
  53. package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +0 -4
  54. package/src/engine/graphics/shadows/testShadowMapRendering.js +0 -2
  55. package/src/engine/graphics/texture/atlas/TextureAtlas.js +13 -11
  56. package/src/engine/graphics/texture/sampler/Sampler2D.js +15 -366
  57. package/src/engine/graphics/texture/sampler/Sampler2D.spec.js +0 -31
  58. package/src/engine/graphics/texture/sampler/sampler2d_copy_with_margins.js +166 -0
  59. package/src/engine/graphics/texture/sampler/sampler2d_copy_with_margins.spec.js +31 -0
  60. package/src/engine/graphics/texture/sampler/sampler2d_paint.js +81 -0
  61. package/src/engine/graphics/texture/sampler/sampler2d_sub_copy_same_item_size.js +50 -0
  62. package/src/engine/graphics/texture/virtual/VirtualTextureUsageUpdater.js +1 -1
  63. package/src/engine/navigation/ecs/components/Path.js +10 -9
  64. package/src/engine/physics/computeInterceptPoint.js +44 -0
  65. package/src/engine/plugin/EnginePlugin.js +1 -2
  66. package/src/engine/ecs/components/AlignToVelocity.js +0 -9
  67. package/src/engine/ecs/components/CharacterController.js +0 -31
  68. package/src/engine/ecs/components/PhysicalBody.js +0 -51
  69. package/src/engine/ecs/components/Steering.js +0 -111
  70. package/src/engine/ecs/components/SteeringSerializationAdapter.js +0 -34
  71. package/src/engine/ecs/systems/AlignToVelocitySystem.js +0 -51
  72. package/src/engine/ecs/systems/CharacterControlSystem.js +0 -134
  73. package/src/engine/ecs/systems/PhysicsSystem.js +0 -89
  74. package/src/engine/ecs/systems/PropertySetSystem.js +0 -18
  75. package/src/engine/ecs/systems/SteeringSystem.js +0 -171
  76. package/src/engine/ecs/systems/TagSystem.d.ts +0 -5
  77. package/src/engine/ecs/systems/TagSystem.js +0 -31
  78. package/src/engine/graphics/CanvasBlur.js +0 -599
  79. package/src/engine/graphics/material/LoadMaterial.js +0 -199
  80. package/src/engine/graphics/material/getTextureImmediate.js +0 -21
  81. package/src/engine/graphics/render/buffer/RenderGraph.js +0 -177
  82. package/src/engine/graphics/render/buffer/RenderGraphUtils.js +0 -32
  83. package/src/engine/graphics/render/buffer/buffers/DepthFrameBuffer.js +0 -101
  84. package/src/engine/graphics/render/buffer/conection/ProgramValueSlotConnection.js +0 -43
  85. package/src/engine/graphics/render/buffer/conection/ProgramValueSlotConnectionEndpoint.js +0 -39
  86. package/src/engine/graphics/render/buffer/conection/ProgramValueSlotConnectionValidator.js +0 -30
  87. package/src/engine/graphics/render/buffer/executor/FrameBufferPool.js +0 -127
  88. package/src/engine/graphics/render/buffer/executor/RenderGraphExecutor.js +0 -261
  89. package/src/engine/graphics/render/buffer/executor/RenderProgramCommandType.js +0 -5
  90. package/src/engine/graphics/render/buffer/node/DeferredRenderProgramDefinition.js +0 -142
  91. package/src/engine/graphics/render/buffer/node/RenderProgramDefinition.js +0 -21
  92. package/src/engine/graphics/render/buffer/node/RenderProgramInstance.js +0 -30
  93. package/src/engine/graphics/render/buffer/node/ScreenSpaceRenderProgramDefinition.js +0 -118
  94. package/src/engine/graphics/render/staged/PostProcessingEffect.js +0 -32
  95. package/src/engine/graphics/render/staged/PostProcessingEffectInputCoupling.js +0 -41
  96. package/src/engine/graphics/render/staged/PostProcessingStack.js +0 -29
  97. package/src/engine/graphics/render/staged/StagedRenderer.js +0 -161
  98. package/src/engine/graphics/render/staged/StandardRenderOutputs.js +0 -20
  99. package/src/engine/graphics/texture/CanvasClone.js +0 -28
  100. package/src/engine/graphics/texture/sampler/bicubic.js +0 -59
  101. package/src/engine/graphics/texture/sampler/bicubic.spec.js +0 -13
  102. package/src/engine/graphics/texture/sampler/differenceSampler.js +0 -36
  103. package/src/engine/graphics/texture/sampler/loadSampler2D.js +0 -41
  104. package/src/engine/graphics/texture/sampler/mergeSampler2D.js +0 -96
  105. package/src/engine/graphics/texture/sampler/rgbaData2valueSampler2D.js +0 -38
  106. package/src/engine/navigation/ecs/components/computeNonuniformCatmullRomSplineSample.js +0 -242
  107. /package/src/{engine/graphics/texture → core/math/noise}/noise_octaves.js +0 -0
@@ -1,32 +0,0 @@
1
- import { PostProcessingEffectInputCoupling } from "./PostProcessingEffectInputCoupling.js";
2
-
3
- class PostProcessingEffect {
4
- /**
5
- *
6
- * @param {RenderProgramInstance} node
7
- */
8
- constructor({ node }) {
9
- /**
10
- *
11
- * @type {RenderProgramInstance}
12
- */
13
- this.node = node;
14
- /**
15
- *
16
- * @type {PostProcessingEffectInputCoupling[]}
17
- */
18
- this.inputWiring = [];
19
- }
20
-
21
- /**
22
- *
23
- * @param {string} outputName
24
- * @param {ProgramValueType} outputType
25
- * @param {ProgramValueSlotDefinition} input
26
- */
27
- couple(outputName, outputType, input) {
28
- const inputCoupling = new PostProcessingEffectInputCoupling({ outputType, outputName, input });
29
-
30
- this.inputWiring.push(inputCoupling);
31
- }
32
- }
@@ -1,41 +0,0 @@
1
- import { ProgramValueDirectionKind } from "../buffer/slot/ProgramValueDirectionKind.js";
2
- import { assert } from "../../../../core/assert.js";
3
-
4
- export class PostProcessingEffectInputCoupling {
5
- /**
6
- *
7
- * @param {string} outputName
8
- * @param {ProgramValueType} outputType
9
- * @param {ProgramValueSlotDefinition} input
10
- */
11
- constructor({ outputName, outputType, input }) {
12
- assert.notEqual(input.direction, ProgramValueDirectionKind.Out, `Supplied input slot has OUT direction (not an input slot)`);
13
-
14
- /**
15
- *
16
- * @type {ProgramValueSlotDefinition}
17
- */
18
- this.input = input;
19
- /**
20
- *
21
- * @type {string}
22
- */
23
- this.outputName = outputName;
24
- /**
25
- *
26
- * @type {ProgramValueType}
27
- */
28
- this.outputType = outputType;
29
- }
30
-
31
- /**
32
- *
33
- * @param {ProgramValueSlotDefinition} output
34
- * @returns {boolean}
35
- */
36
- matchOutput(output) {
37
- return (output.direction !== ProgramValueDirectionKind.In)
38
- && output.type === this.outputType
39
- && output.name === this.outputName;
40
- }
41
- }
@@ -1,29 +0,0 @@
1
- import List from "../../../../core/collection/list/List.js";
2
-
3
- export class PostProcessingStack {
4
- constructor() {
5
- /**
6
- *
7
- * @type {List<RenderProgramInstance>}
8
- */
9
- this.effects = new List();
10
- }
11
-
12
- /**
13
- *
14
- * @return {Set<string>}
15
- */
16
- getRequiredBuffers() {
17
- const result = new Set();
18
-
19
- this.effects.forEach(e => {
20
- e.getRequiredBuffers().forEach(b => result.add(b));
21
- });
22
-
23
- return result;
24
- }
25
-
26
- isEmpty() {
27
- this.effects.isEmpty();
28
- }
29
- }
@@ -1,161 +0,0 @@
1
- import List from "../../../../core/collection/list/List.js";
2
- import { RenderGraph } from "../buffer/RenderGraph.js";
3
- import { RenderProgramDefinition } from "../buffer/node/RenderProgramDefinition.js";
4
- import { ProgramValueSlotConnection } from "../buffer/conection/ProgramValueSlotConnection.js";
5
- import { ProgramValueSlotConnectionEndpoint } from "../buffer/conection/ProgramValueSlotConnectionEndpoint.js";
6
- import { ProgramValueType } from "../buffer/slot/ProgramValueType.js";
7
- import { ProgramValueDirectionKind } from "../buffer/slot/ProgramValueDirectionKind.js";
8
- import { RenderGraphExecutor } from "../buffer/executor/RenderGraphExecutor.js";
9
- import { DeferredRenderProgramDefinition } from "../buffer/node/DeferredRenderProgramDefinition.js";
10
-
11
-
12
- /**
13
- *
14
- * @param {PostProcessingEffectInputCoupling} coupling
15
- * @param {RenderGraph} graph
16
- * @returns {ProgramValueSlotConnectionEndpoint}
17
- */
18
- function satisfyPostProcessCoupling(coupling, graph) {
19
- let bestSlot = null;
20
- let bestNode = null;
21
- let bestDepth = Number.NEGATIVE_INFINITY;
22
-
23
- graph.traverseNodes(n => {
24
- /**
25
- *
26
- * @type {RenderProgramDefinition}
27
- */
28
- const definition = n.definition;
29
-
30
- const matchingSlot = definition.slots.find(s => coupling.matchOutput(s));
31
-
32
- if (matchingSlot !== undefined) {
33
-
34
- const depth = graph.computeNodeDepth(n);
35
-
36
- if (depth > bestDepth) {
37
- //get slot on the node with the longest chain
38
- bestDepth = depth;
39
- bestSlot = matchingSlot;
40
- bestNode = n;
41
- }
42
-
43
- }
44
- });
45
-
46
-
47
- if (bestSlot === null) {
48
- //no matching slot found
49
- return null;
50
- }
51
-
52
- return new ProgramValueSlotConnectionEndpoint({
53
- node: bestNode,
54
- slot: bestSlot
55
- });
56
- }
57
-
58
- /**
59
- *
60
- * @param {PostProcessingEffect} effect
61
- * @param {RenderGraph} graph
62
- */
63
- function buildWiringForPostProcessEffect(effect, graph) {
64
- const node = effect.node;
65
- const inputWiring = effect.inputWiring;
66
-
67
- const connections = inputWiring.map(c => {
68
-
69
- const sourceEndpoint = satisfyPostProcessCoupling(c);
70
-
71
- if (sourceEndpoint === null) {
72
- throw new Error(`Input Coupling ${c} of effect ${effect} could not be satisfied`);
73
- }
74
-
75
- const targetEndpoint = new ProgramValueSlotConnectionEndpoint({
76
- node: node,
77
- slot: c.input
78
- });
79
-
80
- const connection = new ProgramValueSlotConnection({
81
- source: sourceEndpoint,
82
- target: targetEndpoint
83
- });
84
-
85
- return connection;
86
- });
87
-
88
- return connections;
89
- }
90
-
91
- export class StagedRenderer {
92
- constructor() {
93
- /**
94
- *
95
- * @type {List<PostProcessingEffect>}
96
- */
97
- this.postprocess = new List();
98
-
99
- const self = this;
100
-
101
- function update() {
102
- self.graphNeedsUpdate = true;
103
- }
104
-
105
- this.postprocess.on.added.add(update);
106
- this.postprocess.on.removed.add(update);
107
-
108
- this.graphNeedsUpdate = true;
109
- this.graphExecutor = new RenderGraphExecutor();
110
- }
111
-
112
- buildGraph() {
113
- const graph = new RenderGraph();
114
-
115
- const pDeferred = new DeferredRenderProgramDefinition();
116
-
117
-
118
- const piDeferred = graph.createNode(pDeferred);
119
-
120
- if (this.postprocess.isEmpty()) {
121
- graph.setFinalOutput(piDeferred, DeferredRenderProgramDefinition.OutputColor);
122
- } else {
123
- this.postprocess.forEach(function (effect) {
124
- const connections = buildWiringForPostProcessEffect(effect, graph);
125
-
126
- //add effect node to the graph
127
- graph.addNode(effect.node);
128
-
129
- //add connections to the graph
130
- connections.forEach(connection => graph.addConnection(connection));
131
- });
132
-
133
- const lastNode = this.postprocess.last().node;
134
- const outputSlot = lastNode.definition.slots.find(s => s.type === ProgramValueType.FrameBuffer && s.direction === ProgramValueDirectionKind.Out);
135
-
136
- graph.setFinalOutput(lastNode, outputSlot);
137
- }
138
-
139
- //attach graph to the executor
140
- this.graphExecutor.initialize(graph);
141
- }
142
-
143
- /**
144
- *
145
- * @param {WebGLRenderer} renderer
146
- * @param {PerspectiveCamera|OrthographicCamera} camera
147
- * @param {Scene} scene
148
- */
149
- render(renderer, camera, scene) {
150
- renderer.gammaInput = true;
151
- renderer.gammaOutput = true;
152
- renderer.autoClear = true;
153
- renderer.clearAlpha = 0;
154
-
155
- if (this.graphNeedsUpdate) {
156
- this.buildGraph();
157
- this.graphNeedsUpdate = false;
158
- }
159
- this.graphExecutor.execute(renderer, scene, camera);
160
- }
161
- }
@@ -1,20 +0,0 @@
1
- import { ProgramValueSlotDefinition } from "../buffer/slot/ProgramValueSlotDefinition.js";
2
- import { ProgramValueDirectionKind } from "../buffer/slot/ProgramValueDirectionKind.js";
3
- import { ProgramValueType } from "../buffer/slot/ProgramValueType.js";
4
-
5
- /**
6
- *
7
- * @enum {ProgramValueSlotDefinition}
8
- */
9
- export const StandardRenderOutputs = {
10
- DepthBuffer: new ProgramValueSlotDefinition({
11
- name: 'output',
12
- direction: ProgramValueDirectionKind.Out,
13
- type: ProgramValueType.FrameBuffer
14
- }),
15
- ColorBuffer: new ProgramValueSlotDefinition({
16
- name: 'output',
17
- direction: ProgramValueDirectionKind.Out,
18
- type: ProgramValueType.FrameBuffer
19
- })
20
- };
@@ -1,28 +0,0 @@
1
- /**
2
- * Created by Alex on 15/11/2014.
3
- */
4
-
5
-
6
- /**
7
- *
8
- * @param {HTMLCanvasElement} oldCanvas
9
- * @return {HTMLCanvasElement}
10
- */
11
- function cloneCanvas(oldCanvas) {
12
-
13
- //create a new canvas
14
- const newCanvas = document.createElement('canvas');
15
- const context = newCanvas.getContext('2d');
16
-
17
- //set dimensions
18
- newCanvas.width = oldCanvas.width;
19
- newCanvas.height = oldCanvas.height;
20
-
21
- //apply the old canvas to the new one
22
- context.drawImage(oldCanvas, 0, 0);
23
-
24
- //return the new canvas
25
- return newCanvas;
26
- }
27
-
28
- export default cloneCanvas;
@@ -1,59 +0,0 @@
1
- /**
2
- * @see https://github.com/hughsk/bicubic/blob/master/index.js
3
- * @param {number} xf
4
- * @param {number} yf
5
- * @param {number} p00
6
- * @param {number} p01
7
- * @param {number} p02
8
- * @param {number} p03
9
- * @param {number} p10
10
- * @param {number} p11
11
- * @param {number} p12
12
- * @param {number} p13
13
- * @param {number} p20
14
- * @param {number} p21
15
- * @param {number} p22
16
- * @param {number} p23
17
- * @param {number} p30
18
- * @param {number} p31
19
- * @param {number} p32
20
- * @param {number} p33
21
- * @returns {number}
22
- */
23
- export function bicubic(
24
- xf, yf
25
- , p00, p01, p02, p03
26
- , p10, p11, p12, p13
27
- , p20, p21, p22, p23
28
- , p30, p31, p32, p33
29
- ) {
30
- var yf2 = yf * yf
31
- var xf2 = xf * xf
32
- var xf3 = xf * xf2
33
-
34
- var x00 = p03 - p02 - p00 + p01
35
- var x01 = p00 - p01 - x00
36
- var x02 = p02 - p00
37
- var x0 = x00 * xf3 + x01 * xf2 + x02 * xf + p01
38
-
39
- var x10 = p13 - p12 - p10 + p11
40
- var x11 = p10 - p11 - x10
41
- var x12 = p12 - p10
42
- var x1 = x10 * xf3 + x11 * xf2 + x12 * xf + p11
43
-
44
- var x20 = p23 - p22 - p20 + p21
45
- var x21 = p20 - p21 - x20
46
- var x22 = p22 - p20
47
- var x2 = x20 * xf3 + x21 * xf2 + x22 * xf + p21
48
-
49
- var x30 = p33 - p32 - p30 + p31
50
- var x31 = p30 - p31 - x30
51
- var x32 = p32 - p30
52
- var x3 = x30 * xf3 + x31 * xf2 + x32 * xf + p31
53
-
54
- var y0 = x3 - x2 - x0 + x1
55
- var y1 = x0 - x1 - y0
56
- var y2 = x2 - x0
57
-
58
- return y0 * yf * yf2 + y1 * yf2 + y2 * yf + x1
59
- }
@@ -1,13 +0,0 @@
1
- import { bicubic } from "./bicubic.js";
2
-
3
- test("sanity", () => {
4
-
5
- expect(bicubic(
6
- 0.5, 0.5,
7
- 3, 3, 3, 3,
8
- 3, 3, 3, 3,
9
- 3, 3, 3, 3,
10
- 3, 3, 3, 3,
11
- )).toBeCloseTo(3);
12
-
13
- });
@@ -1,36 +0,0 @@
1
- import { Sampler2D } from "./Sampler2D.js";
2
- import { vector_nd_normalize } from "../../../../core/math/vector_nd_normalize.js";
3
- import { vector_nd_dot } from "../../../../core/math/vector_nd_dot.js";
4
-
5
- /**
6
- * NOTE: treats samplers as normal maps
7
- * @param {Sampler2D} sampler0
8
- * @param {Sampler2D} sampler1
9
- * @returns {Sampler2D}
10
- */
11
- export function differenceSampler(sampler0, sampler1) {
12
- const dimension_count = sampler0.itemSize;
13
-
14
- const v0 = new Float64Array(dimension_count);
15
- const v1 = new Float64Array(dimension_count);
16
- //
17
- const width = sampler0.width;
18
- const height = sampler0.height;
19
- //
20
- const difference = new Float32Array(width * height);
21
- for (let y = 0; y < height; y++) {
22
- for (let x = 0; x < width; x++) {
23
- sampler0.sampleBilinear(x, y, v0);
24
- sampler1.sampleBilinear(x, y, v1);
25
-
26
- vector_nd_normalize(v0, v0, dimension_count);
27
- vector_nd_normalize(v1, v1, dimension_count);
28
-
29
- //check distance
30
- difference[x + y * width] = 1 - vector_nd_dot(v0, v1, dimension_count);
31
- }
32
- }
33
- //
34
- const sampleD = new Sampler2D(difference, 1, width, height);
35
- return sampleD;
36
- }
@@ -1,41 +0,0 @@
1
- /**
2
- * Created by Alex on 30/10/2014.
3
- */
4
- import { Sampler2D } from './Sampler2D.js';
5
- import { GameAssetType } from "../../../asset/GameAssetType.js";
6
-
7
-
8
- /**
9
- *
10
- * @param {string} url
11
- * @param {AssetManager} assetManager
12
- * @returns {Promise<Sampler2D>}
13
- */
14
- export default function loadSampler2D(url, assetManager) {
15
- return new Promise(function (resolve, reject) {
16
- assetManager.get({
17
- path: url,
18
- type: GameAssetType.Image,
19
- callback: (asset) => {
20
- const imageData = asset.create();
21
-
22
- const width = imageData.width;
23
- const height = imageData.height;
24
-
25
- const data = imageData.data;
26
-
27
- //
28
- const bufferSize = width * height;
29
- const buffer = new Float32Array(bufferSize);
30
- //
31
- for (let i = 0; i < bufferSize; i++) {
32
- const j = (i * 4);
33
- buffer[i] = (data[j] + data[j + 1] + data[j + 2]) / 765;
34
- }
35
- const sampler2D = new Sampler2D(buffer, 1, width, height);
36
- resolve(sampler2D);
37
- },
38
- failure: reject
39
- });
40
- });
41
- };
@@ -1,96 +0,0 @@
1
- /**
2
- * Created by Alex on 03/08/2016.
3
- */
4
-
5
-
6
- import { Sampler2D } from './Sampler2D.js';
7
-
8
- /**
9
- *
10
- * @param {Array.<Sampler2D>} inputs
11
- * @returns {Sampler2D}
12
- */
13
- function mergeSampler2D(inputs) {
14
- if (inputs.length > 4) {
15
- throw new Error("Can not merge more than 4 samplers");
16
- } else if (inputs.length === 0) {
17
- throw new Error("No samplers to merge");
18
- }
19
-
20
- const width = inputs[0].width;
21
- const height = inputs[0].height;
22
-
23
- //check dimensions of other inputs
24
- for (let i = 1; i < inputs.length; i++) {
25
- if (inputs[i].width !== width && inputs[i].height !== height) {
26
- console.warn('dimensions of ' + i + " input don't match");
27
- }
28
- }
29
-
30
- const uint8Array = new Uint8Array(width * height * 4);
31
- const result = new Sampler2D(uint8Array, 4, width, height);
32
-
33
- for (let i = 0, l = inputs.length; i < l; i++) {
34
- const sampler = inputs[i];
35
- mergeIntoChannel(sampler, result, i);
36
- }
37
-
38
- return result;
39
- }
40
-
41
- /**
42
- *
43
- * @param {Sampler2D} source
44
- * @param {Sampler2D} target
45
- * @param {int} targetChannelIndex
46
- */
47
- function mergeIntoChannel(source, target, targetChannelIndex) {
48
- let sample = 0;
49
- let index = 0;
50
-
51
- const sW = source.width;
52
- const sH = source.height;
53
-
54
- const tW = target.width;
55
- const tH = target.height;
56
-
57
- let x, y;
58
-
59
- const tData = target.data;
60
- const tItemSize = target.itemSize;
61
-
62
- if (tW === sW && tH === sH) {
63
- //dimensions match exactly, no re-sampling is required
64
-
65
- const count = sW * sH;
66
- const sData = source.data;
67
-
68
- for (index = 0; index < count; index++) {
69
- sample = sData[index];
70
-
71
- tData[index * tItemSize + targetChannelIndex] = sample * 255;
72
- }
73
-
74
- } else {
75
- //dimensions don't match, use re-sampling
76
-
77
- //to account for 1-pixel size we force divisor to be at least 1
78
- const vDivisor = Math.max(1, target.height - 1);
79
- const uDivisor = Math.max(1, target.width - 1);
80
-
81
- for (y = 0; y < tH; y++) {
82
- const v = y / vDivisor;
83
- for (x = 0; x < tW; x++) {
84
- const u = x / uDivisor;
85
- sample = source.sample(u, v, sample);
86
- //
87
- tData[index + targetChannelIndex] = sample * 255;
88
-
89
- index += tItemSize;
90
- }
91
- }
92
-
93
- }
94
- }
95
-
96
- export { mergeSampler2D };
@@ -1,38 +0,0 @@
1
- /**
2
- * Created by Alex on 11/11/2014.
3
- */
4
- import { Sampler2D } from './Sampler2D.js';
5
-
6
- /**
7
- *
8
- * @param {ArrayLike} data
9
- * @param {number} width
10
- * @param {number} height
11
- * @param {number} [scale=1]
12
- * @param {number} [offset=0]
13
- * @returns {Sampler2D}
14
- */
15
- function convert(data, width, height, scale, offset) {
16
- scale = scale || 1;
17
- offset = offset || 0;
18
- const bufferSize = width * height;
19
- const buffer = new Float32Array(bufferSize);
20
-
21
- const multiplier = scale / 765;
22
-
23
- for (let i = 0; i < bufferSize; i++) {
24
-
25
- const j = (i * 4);
26
-
27
- const r = data[j];
28
- const g = data[j + 1];
29
- const b = data[j + 2];
30
-
31
- buffer[i] = (r + g + b) * multiplier + offset;
32
-
33
- }
34
-
35
- return new Sampler2D(buffer, 1, width, height);
36
- }
37
-
38
- export default convert;