@woosh/meep-engine 2.46.35 → 2.47.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/build/meep.cjs +112 -86
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +112 -86
- package/package.json +3 -2
- package/src/core/geom/3d/plane/orient3d_fast.js +2 -2
- package/src/core/model/node-graph/NodeGraph.js +4 -0
- package/src/core/model/node-graph/node/NodeDescription.js +55 -4
- package/src/engine/ecs/terrain/ecs/makeTerrainWorkerProxy.js +4 -2
- package/src/engine/graphics/micron/prototypeVirtualGeometry.js +2 -2
- package/src/engine/graphics/texture/sampler/Sampler2D.js +8 -82
- package/src/engine/graphics/texture/sampler/Sampler2D.spec.js +0 -37
- package/src/engine/graphics/texture/sampler/Sampler2D2Canvas.js +2 -2
- package/src/engine/graphics/texture/sampler/resize/sampler2d_downsample_mipmap.js +2 -2
- package/src/engine/graphics/texture/sampler/sampler2d_channel_compute_max.js +51 -0
- package/src/engine/graphics/texture/sampler/sampler2d_channel_compute_max.spec.js +40 -0
- package/src/engine/graphics/texture/sampler/sampler2d_channel_compute_min.js +51 -0
- package/src/engine/graphics/texture/sampler/sampler2d_compute_texel_value_conversion_scale_to_uint8.js +4 -2
- package/src/engine/graphics/texture/sampler/{sampler2D_scale_down_linear.js → sampler2d_scale_down_linear.js} +1 -1
- package/src/engine/graphics/texture/sampler/{downsampleSample2D.spec.js → sampler2d_scale_down_linear.spec.js} +2 -2
- package/src/engine/graphics/texture/sampler/{sample2d_write_to_canvas_raw.js → sampler2d_write_to_canvas_raw.js} +5 -1
- package/src/engine/graphics/texture/sampler/scaleSampler2D.js +2 -2
- package/src/engine/input/ecs/util/TerrainCameraTargetSampler.js +2 -2
package/build/meep.module.js
CHANGED
|
@@ -48165,6 +48165,10 @@ class Sampler2D {
|
|
|
48165
48165
|
throw new Error("data was undefined");
|
|
48166
48166
|
}
|
|
48167
48167
|
|
|
48168
|
+
if (data.length < width * height * itemSize) {
|
|
48169
|
+
throw new Error(`Buffer underflow, data.length(=${data.length}) is too small. Expected at least ${width * height * itemSize}`);
|
|
48170
|
+
}
|
|
48171
|
+
|
|
48168
48172
|
/**
|
|
48169
48173
|
*
|
|
48170
48174
|
* @type {Number}
|
|
@@ -48202,51 +48206,12 @@ class Sampler2D {
|
|
|
48202
48206
|
}
|
|
48203
48207
|
|
|
48204
48208
|
/**
|
|
48209
|
+
* @deprecated
|
|
48205
48210
|
* @param {number} [channel=0]
|
|
48206
48211
|
* @returns {{x: number, index: number, y: number, value: number}}
|
|
48207
48212
|
*/
|
|
48208
48213
|
computeMax(channel = 0) {
|
|
48209
|
-
|
|
48210
|
-
|
|
48211
|
-
assert.typeOf(channel, "number", "channel");
|
|
48212
|
-
assert.ok(channel >= 0, `channel must be >= 0, was ${channel}`);
|
|
48213
|
-
assert.ok(channel < itemSize, `channel must be less than itemSize(=${itemSize}), was ${channel}`);
|
|
48214
|
-
|
|
48215
|
-
const data = this.data;
|
|
48216
|
-
|
|
48217
|
-
const l = data.length;
|
|
48218
|
-
|
|
48219
|
-
if (l === 0) {
|
|
48220
|
-
//no data
|
|
48221
|
-
return undefined;
|
|
48222
|
-
}
|
|
48223
|
-
|
|
48224
|
-
let bestValue = data[channel];
|
|
48225
|
-
let bestIndex = channel;
|
|
48226
|
-
|
|
48227
|
-
for (let i = channel + itemSize; i < l; i += itemSize) {
|
|
48228
|
-
const value = data[i];
|
|
48229
|
-
|
|
48230
|
-
if (bestValue < value) {
|
|
48231
|
-
bestValue = value;
|
|
48232
|
-
bestIndex = i;
|
|
48233
|
-
}
|
|
48234
|
-
|
|
48235
|
-
}
|
|
48236
|
-
|
|
48237
|
-
const width = this.width;
|
|
48238
|
-
|
|
48239
|
-
const itemIndex = (bestIndex / this.itemSize) | 0;
|
|
48240
|
-
|
|
48241
|
-
const x = itemIndex % width;
|
|
48242
|
-
const y = (itemIndex / width) | 0;
|
|
48243
|
-
|
|
48244
|
-
return {
|
|
48245
|
-
index: bestIndex,
|
|
48246
|
-
value: bestValue,
|
|
48247
|
-
x,
|
|
48248
|
-
y
|
|
48249
|
-
};
|
|
48214
|
+
throw new Error("deprecated, use sampler2d_channel_compute_max");
|
|
48250
48215
|
}
|
|
48251
48216
|
|
|
48252
48217
|
/**
|
|
@@ -48299,51 +48264,12 @@ class Sampler2D {
|
|
|
48299
48264
|
}
|
|
48300
48265
|
|
|
48301
48266
|
/**
|
|
48267
|
+
* @deprecated
|
|
48302
48268
|
* @param {number} [channel=0]
|
|
48303
48269
|
* @returns {{x: number, index: number, y: number, value: number}}
|
|
48304
48270
|
*/
|
|
48305
48271
|
computeMin(channel = 0) {
|
|
48306
|
-
|
|
48307
|
-
|
|
48308
|
-
assert.typeOf(channel, "number", "channel");
|
|
48309
|
-
assert.ok(channel >= 0, `channel must be >= 0, was ${channel}`);
|
|
48310
|
-
assert.ok(channel < itemSize, `channel must be less than itemSize(=${itemSize}), was ${channel}`);
|
|
48311
|
-
|
|
48312
|
-
const data = this.data;
|
|
48313
|
-
|
|
48314
|
-
const l = data.length;
|
|
48315
|
-
|
|
48316
|
-
if (l === 0) {
|
|
48317
|
-
//no data
|
|
48318
|
-
return undefined;
|
|
48319
|
-
}
|
|
48320
|
-
|
|
48321
|
-
let bestValue = data[channel];
|
|
48322
|
-
let bestIndex = channel;
|
|
48323
|
-
|
|
48324
|
-
for (let i = channel + itemSize; i < l; i += itemSize) {
|
|
48325
|
-
const value = data[i];
|
|
48326
|
-
|
|
48327
|
-
if (bestValue > value) {
|
|
48328
|
-
bestValue = value;
|
|
48329
|
-
bestIndex = i;
|
|
48330
|
-
}
|
|
48331
|
-
|
|
48332
|
-
}
|
|
48333
|
-
|
|
48334
|
-
const width = this.width;
|
|
48335
|
-
|
|
48336
|
-
const itemIndex = (bestIndex / this.itemSize) | 0;
|
|
48337
|
-
|
|
48338
|
-
const x = itemIndex % width;
|
|
48339
|
-
const y = (itemIndex / width) | 0;
|
|
48340
|
-
|
|
48341
|
-
return {
|
|
48342
|
-
index: bestIndex,
|
|
48343
|
-
value: bestValue,
|
|
48344
|
-
x,
|
|
48345
|
-
y
|
|
48346
|
-
};
|
|
48272
|
+
throw new Error("deprecated, use sampler2d_channel_compute_min");
|
|
48347
48273
|
}
|
|
48348
48274
|
|
|
48349
48275
|
/**
|
|
@@ -54834,7 +54760,7 @@ class ObservedString extends String {
|
|
|
54834
54760
|
* @param {Sampler2D} input
|
|
54835
54761
|
* @param {Sampler2D} output
|
|
54836
54762
|
*/
|
|
54837
|
-
function
|
|
54763
|
+
function sampler2d_scale_down_linear(input, output) {
|
|
54838
54764
|
assert.notEqual(input, undefined, 'input is undefined');
|
|
54839
54765
|
assert.notEqual(output, undefined, 'output is undefined');
|
|
54840
54766
|
|
|
@@ -55047,7 +54973,7 @@ function scaleSampler2D(input, output) {
|
|
|
55047
54973
|
// downscaling
|
|
55048
54974
|
if (Number.isInteger(sourceWidth / targetWidth) && Number.isInteger(sourceHeight / targetHeight)) {
|
|
55049
54975
|
// dimensions are multiples of source/target
|
|
55050
|
-
|
|
54976
|
+
sampler2d_scale_down_linear(input, output);
|
|
55051
54977
|
} else {
|
|
55052
54978
|
// generic downsample
|
|
55053
54979
|
genericResampleSampler2D(input, output);
|
|
@@ -65563,6 +65489,106 @@ WorkerBuilder.prototype.build = function () {
|
|
|
65563
65489
|
return proxy;
|
|
65564
65490
|
};
|
|
65565
65491
|
|
|
65492
|
+
/**
|
|
65493
|
+
*
|
|
65494
|
+
* @param {Sampler2D} sampler
|
|
65495
|
+
* @param {number} [channel=0]
|
|
65496
|
+
* @returns {undefined|{x: number, index:number, y: number, value: number}}
|
|
65497
|
+
*/
|
|
65498
|
+
function sampler2d_channel_compute_max(sampler, channel=0){
|
|
65499
|
+
const itemSize = sampler.itemSize;
|
|
65500
|
+
|
|
65501
|
+
assert.isNumber(channel, "channel");
|
|
65502
|
+
assert.isNonNegativeInteger(channel , 'channel');
|
|
65503
|
+
assert.lessThan(channel, itemSize, `channel must be less than itemSize(=${itemSize}), was ${channel}`);
|
|
65504
|
+
|
|
65505
|
+
const data = sampler.data;
|
|
65506
|
+
|
|
65507
|
+
const l = data.length;
|
|
65508
|
+
|
|
65509
|
+
if (l === 0) {
|
|
65510
|
+
//no data
|
|
65511
|
+
return undefined;
|
|
65512
|
+
}
|
|
65513
|
+
|
|
65514
|
+
let bestValue = data[channel];
|
|
65515
|
+
let bestIndex = channel;
|
|
65516
|
+
|
|
65517
|
+
for (let i = channel + itemSize; i < l; i += itemSize) {
|
|
65518
|
+
const value = data[i];
|
|
65519
|
+
|
|
65520
|
+
if (bestValue < value) {
|
|
65521
|
+
bestValue = value;
|
|
65522
|
+
bestIndex = i;
|
|
65523
|
+
}
|
|
65524
|
+
|
|
65525
|
+
}
|
|
65526
|
+
|
|
65527
|
+
const width = this.width;
|
|
65528
|
+
|
|
65529
|
+
const itemIndex = (bestIndex / itemSize) | 0;
|
|
65530
|
+
|
|
65531
|
+
const x = itemIndex % width;
|
|
65532
|
+
const y = (itemIndex / width) | 0;
|
|
65533
|
+
|
|
65534
|
+
return {
|
|
65535
|
+
index: bestIndex,
|
|
65536
|
+
value: bestValue,
|
|
65537
|
+
x,
|
|
65538
|
+
y
|
|
65539
|
+
};
|
|
65540
|
+
}
|
|
65541
|
+
|
|
65542
|
+
/**
|
|
65543
|
+
*
|
|
65544
|
+
* @param {Sampler2D} sampler
|
|
65545
|
+
* @param {number} [channel=0]
|
|
65546
|
+
* @returns {undefined|{x: number, index:number, y: number, value: number}}
|
|
65547
|
+
*/
|
|
65548
|
+
function sampler2d_channel_compute_min(sampler, channel=0){
|
|
65549
|
+
const itemSize = sampler.itemSize;
|
|
65550
|
+
|
|
65551
|
+
assert.isNumber(channel, "channel");
|
|
65552
|
+
assert.isNonNegativeInteger(channel , 'channel');
|
|
65553
|
+
assert.lessThan(channel, itemSize, `channel must be less than itemSize(=${itemSize}), was ${channel}`);
|
|
65554
|
+
|
|
65555
|
+
const data = sampler.data;
|
|
65556
|
+
|
|
65557
|
+
const l = data.length;
|
|
65558
|
+
|
|
65559
|
+
if (l === 0) {
|
|
65560
|
+
//no data
|
|
65561
|
+
return undefined;
|
|
65562
|
+
}
|
|
65563
|
+
|
|
65564
|
+
let bestValue = data[channel];
|
|
65565
|
+
let bestIndex = channel;
|
|
65566
|
+
|
|
65567
|
+
for (let i = channel + itemSize; i < l; i += itemSize) {
|
|
65568
|
+
const value = data[i];
|
|
65569
|
+
|
|
65570
|
+
if (bestValue > value) {
|
|
65571
|
+
bestValue = value;
|
|
65572
|
+
bestIndex = i;
|
|
65573
|
+
}
|
|
65574
|
+
|
|
65575
|
+
}
|
|
65576
|
+
|
|
65577
|
+
const width = this.width;
|
|
65578
|
+
|
|
65579
|
+
const itemIndex = (bestIndex / itemSize) | 0;
|
|
65580
|
+
|
|
65581
|
+
const x = itemIndex % width;
|
|
65582
|
+
const y = (itemIndex / width) | 0;
|
|
65583
|
+
|
|
65584
|
+
return {
|
|
65585
|
+
index: bestIndex,
|
|
65586
|
+
value: bestValue,
|
|
65587
|
+
x,
|
|
65588
|
+
y
|
|
65589
|
+
};
|
|
65590
|
+
}
|
|
65591
|
+
|
|
65566
65592
|
/**
|
|
65567
65593
|
*
|
|
65568
65594
|
* @return {WorkerProxy}
|
|
@@ -65590,8 +65616,8 @@ function makeTerrainWorkerProxy() {
|
|
|
65590
65616
|
|
|
65591
65617
|
useSampler(function (sampler) {
|
|
65592
65618
|
|
|
65593
|
-
const min = sampler
|
|
65594
|
-
const max = sampler
|
|
65619
|
+
const min = sampler2d_channel_compute_min(sampler);
|
|
65620
|
+
const max = sampler2d_channel_compute_max(sampler);
|
|
65595
65621
|
|
|
65596
65622
|
resolve({
|
|
65597
65623
|
min: min.value,
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"description": "Fully featured ECS game engine written in JavaScript",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"author": "Alexander Goldring",
|
|
8
|
-
"version": "2.
|
|
8
|
+
"version": "2.47.1",
|
|
9
9
|
"main": "build/meep.module.js",
|
|
10
10
|
"module": "build/meep.module.js",
|
|
11
11
|
"exports": {
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"import": "./build/meep.module.js",
|
|
14
14
|
"require": "./build/meep.cjs"
|
|
15
15
|
},
|
|
16
|
-
"./src/*": "./src/*"
|
|
16
|
+
"./src/*": "./src/*",
|
|
17
|
+
"./editor/*": "./editor/*"
|
|
17
18
|
},
|
|
18
19
|
"scripts": {
|
|
19
20
|
"build-module": "rollup -c rollup.config.js",
|
|
@@ -35,11 +35,11 @@ export function orient3d_fast(points, a, b, c, d) {
|
|
|
35
35
|
|
|
36
36
|
const bdx = points[b3] - d_x;
|
|
37
37
|
const bdy = points[b3 + 1] - d_y;
|
|
38
|
-
const
|
|
38
|
+
const bdz = points[b3 + 2] - d_z;
|
|
39
39
|
|
|
40
40
|
const cdx = points[c3] - d_x;
|
|
41
41
|
const cdy = points[c3 + 1] - d_y;
|
|
42
|
-
const
|
|
42
|
+
const cdz = points[c3 + 2] - d_z;
|
|
43
43
|
|
|
44
44
|
return adx * (bdy * cdz - bdz * cdy)
|
|
45
45
|
+ bdx * (cdy * adz - cdz * ady)
|
|
@@ -40,21 +40,25 @@ export class NodeGraph {
|
|
|
40
40
|
*/
|
|
41
41
|
this.on = {
|
|
42
42
|
/**
|
|
43
|
+
* @readonly
|
|
43
44
|
* @type {Signal<NodeInstance,number>}
|
|
44
45
|
*/
|
|
45
46
|
nodeAdded: this.nodes.on.added,
|
|
46
47
|
|
|
47
48
|
/**
|
|
49
|
+
* @readonly
|
|
48
50
|
* @type {Signal<NodeInstance,number>}
|
|
49
51
|
*/
|
|
50
52
|
nodeRemoved: this.nodes.on.removed,
|
|
51
53
|
|
|
52
54
|
/**
|
|
55
|
+
* @readonly
|
|
53
56
|
* @type {Signal<Connection,number>}
|
|
54
57
|
*/
|
|
55
58
|
connectionAdded: this.connections.on.added,
|
|
56
59
|
|
|
57
60
|
/**
|
|
61
|
+
* @readonly
|
|
58
62
|
* @type {Signal<Connection,number>}
|
|
59
63
|
*/
|
|
60
64
|
connectionRemoved: this.connections.on.removed
|
|
@@ -3,6 +3,7 @@ import { NodeParameterDataType } from "./parameter/NodeParameterDataType.js";
|
|
|
3
3
|
import { NodeParameterDescription } from "./parameter/NodeParameterDescription.js";
|
|
4
4
|
import { Port } from "./Port.js";
|
|
5
5
|
import { PortDirection } from "./PortDirection.js";
|
|
6
|
+
import Signal from "../../../events/signal/Signal.js";
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -38,7 +39,7 @@ let node_id_counter = 0;
|
|
|
38
39
|
export class NodeDescription {
|
|
39
40
|
constructor() {
|
|
40
41
|
/**
|
|
41
|
-
*
|
|
42
|
+
* Useful human-readable label
|
|
42
43
|
* @type {string}
|
|
43
44
|
*/
|
|
44
45
|
this.name = "";
|
|
@@ -63,6 +64,22 @@ export class NodeDescription {
|
|
|
63
64
|
* @type {NodeParameterDescription[]}
|
|
64
65
|
*/
|
|
65
66
|
this.parameters = [];
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @readonly
|
|
70
|
+
*/
|
|
71
|
+
this.on = {
|
|
72
|
+
/**
|
|
73
|
+
* @readonly
|
|
74
|
+
* @type {Signal<Port>}
|
|
75
|
+
*/
|
|
76
|
+
portAdded: new Signal(),
|
|
77
|
+
/**
|
|
78
|
+
* @readonly
|
|
79
|
+
* @type {Signal<Port>}
|
|
80
|
+
*/
|
|
81
|
+
portRemoved: new Signal()
|
|
82
|
+
};
|
|
66
83
|
}
|
|
67
84
|
|
|
68
85
|
/**
|
|
@@ -70,7 +87,7 @@ export class NodeDescription {
|
|
|
70
87
|
* @returns {Port[]}
|
|
71
88
|
*/
|
|
72
89
|
get outPorts() {
|
|
73
|
-
return this.
|
|
90
|
+
return this.getPortsByDirection(PortDirection.Out);
|
|
74
91
|
}
|
|
75
92
|
|
|
76
93
|
/**
|
|
@@ -78,7 +95,7 @@ export class NodeDescription {
|
|
|
78
95
|
* @returns {Port[]}
|
|
79
96
|
*/
|
|
80
97
|
get inPorts() {
|
|
81
|
-
return this.
|
|
98
|
+
return this.getPortsByDirection(PortDirection.In);
|
|
82
99
|
}
|
|
83
100
|
|
|
84
101
|
/**
|
|
@@ -165,6 +182,8 @@ export class NodeDescription {
|
|
|
165
182
|
assert.equal(type.isDataType, true, 'type.isDataType !== true');
|
|
166
183
|
|
|
167
184
|
assert.defined(direction, 'direction');
|
|
185
|
+
assert.enum(direction, PortDirection, 'direction');
|
|
186
|
+
|
|
168
187
|
assert.isString(name, 'name');
|
|
169
188
|
|
|
170
189
|
const port = new Port();
|
|
@@ -179,9 +198,38 @@ export class NodeDescription {
|
|
|
179
198
|
|
|
180
199
|
this.ports.push(port);
|
|
181
200
|
|
|
201
|
+
this.on.portAdded.send1(port);
|
|
202
|
+
|
|
182
203
|
return id;
|
|
183
204
|
}
|
|
184
205
|
|
|
206
|
+
/**
|
|
207
|
+
*
|
|
208
|
+
* @param {number} id port ID
|
|
209
|
+
* @returns {boolean} true if port was deleted, false if port wasn't found
|
|
210
|
+
*/
|
|
211
|
+
deletePort(id) {
|
|
212
|
+
assert.defined(id, 'id');
|
|
213
|
+
assert.isNumber(id, 'id');
|
|
214
|
+
assert.isNonNegativeInteger(id, 'id');
|
|
215
|
+
|
|
216
|
+
const ports = this.ports;
|
|
217
|
+
const port_count = ports.length;
|
|
218
|
+
for (let i = 0; i < port_count; i++) {
|
|
219
|
+
const port = ports[i];
|
|
220
|
+
|
|
221
|
+
if (port.id === id) {
|
|
222
|
+
ports.splice(i, 1);
|
|
223
|
+
|
|
224
|
+
this.on.portRemoved.send1(port);
|
|
225
|
+
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
|
|
185
233
|
/**
|
|
186
234
|
*
|
|
187
235
|
* @param {number} id
|
|
@@ -190,7 +238,10 @@ export class NodeDescription {
|
|
|
190
238
|
getPortById(id) {
|
|
191
239
|
assert.isNonNegativeInteger(id, 'id');
|
|
192
240
|
|
|
193
|
-
|
|
241
|
+
const ports = this.ports;
|
|
242
|
+
const port_count = ports.length;
|
|
243
|
+
for (let i = 0; i < port_count; i++) {
|
|
244
|
+
const port = ports[i];
|
|
194
245
|
if (port.id === id) {
|
|
195
246
|
return port;
|
|
196
247
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import WorkerBuilder from "../../../../core/process/worker/WorkerBuilder.js";
|
|
2
|
+
import { sampler2d_channel_compute_max } from "../../../graphics/texture/sampler/sampler2d_channel_compute_max.js";
|
|
3
|
+
import { sampler2d_channel_compute_min } from "../../../graphics/texture/sampler/sampler2d_channel_compute_min.js";
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
*
|
|
@@ -27,8 +29,8 @@ export function makeTerrainWorkerProxy() {
|
|
|
27
29
|
|
|
28
30
|
useSampler(function (sampler) {
|
|
29
31
|
|
|
30
|
-
const min = sampler
|
|
31
|
-
const max = sampler
|
|
32
|
+
const min = sampler2d_channel_compute_min(sampler);
|
|
33
|
+
const max = sampler2d_channel_compute_max(sampler);
|
|
32
34
|
|
|
33
35
|
resolve({
|
|
34
36
|
min: min.value,
|
|
@@ -46,7 +46,7 @@ import { StaticMaterialCache } from "../../asset/loaders/material/StaticMaterial
|
|
|
46
46
|
import convertSampler2D2Canvas from "../texture/sampler/Sampler2D2Canvas.js";
|
|
47
47
|
import { CanvasView } from "../../../view/elements/CanvasView.js";
|
|
48
48
|
import { Sampler2D } from "../texture/sampler/Sampler2D.js";
|
|
49
|
-
import {
|
|
49
|
+
import { sampler2d_scale_down_linear } from "../texture/sampler/sampler2d_scale_down_linear.js";
|
|
50
50
|
import { ShadowMapRenderer } from "../shadows/ShadowMapRenderer.js";
|
|
51
51
|
import { mat4 } from "gl-matrix";
|
|
52
52
|
import { seededRandom } from "../../../core/math/random/seededRandom.js";
|
|
@@ -133,7 +133,7 @@ function debug_shadow_map() {
|
|
|
133
133
|
|
|
134
134
|
const resampled = Sampler2D.uint8(4, 512, 512);
|
|
135
135
|
|
|
136
|
-
|
|
136
|
+
sampler2d_scale_down_linear(sampler, resampled);
|
|
137
137
|
|
|
138
138
|
convertSampler2D2Canvas(resampled, 1, 0, cv.el);
|
|
139
139
|
|
|
@@ -45,6 +45,10 @@ export class Sampler2D {
|
|
|
45
45
|
throw new Error("data was undefined");
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
if (data.length < width * height * itemSize) {
|
|
49
|
+
throw new Error(`Buffer underflow, data.length(=${data.length}) is too small. Expected at least ${width * height * itemSize}`);
|
|
50
|
+
}
|
|
51
|
+
|
|
48
52
|
/**
|
|
49
53
|
*
|
|
50
54
|
* @type {Number}
|
|
@@ -82,51 +86,12 @@ export class Sampler2D {
|
|
|
82
86
|
}
|
|
83
87
|
|
|
84
88
|
/**
|
|
89
|
+
* @deprecated
|
|
85
90
|
* @param {number} [channel=0]
|
|
86
91
|
* @returns {{x: number, index: number, y: number, value: number}}
|
|
87
92
|
*/
|
|
88
93
|
computeMax(channel = 0) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
assert.typeOf(channel, "number", "channel");
|
|
92
|
-
assert.ok(channel >= 0, `channel must be >= 0, was ${channel}`);
|
|
93
|
-
assert.ok(channel < itemSize, `channel must be less than itemSize(=${itemSize}), was ${channel}`);
|
|
94
|
-
|
|
95
|
-
const data = this.data;
|
|
96
|
-
|
|
97
|
-
const l = data.length;
|
|
98
|
-
|
|
99
|
-
if (l === 0) {
|
|
100
|
-
//no data
|
|
101
|
-
return undefined;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
let bestValue = data[channel];
|
|
105
|
-
let bestIndex = channel;
|
|
106
|
-
|
|
107
|
-
for (let i = channel + itemSize; i < l; i += itemSize) {
|
|
108
|
-
const value = data[i];
|
|
109
|
-
|
|
110
|
-
if (bestValue < value) {
|
|
111
|
-
bestValue = value;
|
|
112
|
-
bestIndex = i;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const width = this.width;
|
|
118
|
-
|
|
119
|
-
const itemIndex = (bestIndex / this.itemSize) | 0;
|
|
120
|
-
|
|
121
|
-
const x = itemIndex % width;
|
|
122
|
-
const y = (itemIndex / width) | 0;
|
|
123
|
-
|
|
124
|
-
return {
|
|
125
|
-
index: bestIndex,
|
|
126
|
-
value: bestValue,
|
|
127
|
-
x,
|
|
128
|
-
y
|
|
129
|
-
};
|
|
94
|
+
throw new Error("deprecated, use sampler2d_channel_compute_max");
|
|
130
95
|
}
|
|
131
96
|
|
|
132
97
|
/**
|
|
@@ -179,51 +144,12 @@ export class Sampler2D {
|
|
|
179
144
|
}
|
|
180
145
|
|
|
181
146
|
/**
|
|
147
|
+
* @deprecated
|
|
182
148
|
* @param {number} [channel=0]
|
|
183
149
|
* @returns {{x: number, index: number, y: number, value: number}}
|
|
184
150
|
*/
|
|
185
151
|
computeMin(channel = 0) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
assert.typeOf(channel, "number", "channel");
|
|
189
|
-
assert.ok(channel >= 0, `channel must be >= 0, was ${channel}`);
|
|
190
|
-
assert.ok(channel < itemSize, `channel must be less than itemSize(=${itemSize}), was ${channel}`);
|
|
191
|
-
|
|
192
|
-
const data = this.data;
|
|
193
|
-
|
|
194
|
-
const l = data.length;
|
|
195
|
-
|
|
196
|
-
if (l === 0) {
|
|
197
|
-
//no data
|
|
198
|
-
return undefined;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
let bestValue = data[channel];
|
|
202
|
-
let bestIndex = channel;
|
|
203
|
-
|
|
204
|
-
for (let i = channel + itemSize; i < l; i += itemSize) {
|
|
205
|
-
const value = data[i];
|
|
206
|
-
|
|
207
|
-
if (bestValue > value) {
|
|
208
|
-
bestValue = value;
|
|
209
|
-
bestIndex = i;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const width = this.width;
|
|
215
|
-
|
|
216
|
-
const itemIndex = (bestIndex / this.itemSize) | 0;
|
|
217
|
-
|
|
218
|
-
const x = itemIndex % width;
|
|
219
|
-
const y = (itemIndex / width) | 0;
|
|
220
|
-
|
|
221
|
-
return {
|
|
222
|
-
index: bestIndex,
|
|
223
|
-
value: bestValue,
|
|
224
|
-
x,
|
|
225
|
-
y
|
|
226
|
-
};
|
|
152
|
+
throw new Error("deprecated, use sampler2d_channel_compute_min");
|
|
227
153
|
}
|
|
228
154
|
|
|
229
155
|
/**
|
|
@@ -119,43 +119,6 @@ test('set and get consistency itemSize=4, 2x2', () => {
|
|
|
119
119
|
expect(sample).toEqual([13, 14, 15, 16]);
|
|
120
120
|
});
|
|
121
121
|
|
|
122
|
-
test('computeMax itemSize=1, 0x0', () => {
|
|
123
|
-
const ut = Sampler2D.int8(1, 0, 0);
|
|
124
|
-
|
|
125
|
-
expect(ut.computeMax(0)).toEqual(undefined);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
test('computeMax itemSize=1, 1x1', () => {
|
|
129
|
-
const ut = Sampler2D.int8(1, 1, 1);
|
|
130
|
-
|
|
131
|
-
ut.set(0, 0, [7]);
|
|
132
|
-
|
|
133
|
-
expect(ut.computeMax(0)).toEqual({ value: 7, x: 0, y: 0, index: 0 });
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
test('computeMax itemSize=1, 2x2', () => {
|
|
137
|
-
const ut = Sampler2D.int8(1, 2, 2);
|
|
138
|
-
|
|
139
|
-
ut.set(0, 0, [3]);
|
|
140
|
-
ut.set(1, 0, [-7]);
|
|
141
|
-
ut.set(0, 1, [7]);
|
|
142
|
-
ut.set(1, 1, [4]);
|
|
143
|
-
|
|
144
|
-
expect(ut.computeMax(0)).toEqual({ value: 7, x: 0, y: 1, index: 2 });
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
test('computeMax itemSize=2, 2x2', () => {
|
|
148
|
-
const ut = Sampler2D.int8(2, 2, 2);
|
|
149
|
-
|
|
150
|
-
ut.set(0, 0, [3, 8]);
|
|
151
|
-
ut.set(1, 0, [-7, 13]);
|
|
152
|
-
ut.set(0, 1, [7, 1]);
|
|
153
|
-
ut.set(1, 1, [4, -3]);
|
|
154
|
-
|
|
155
|
-
expect(ut.computeMax(0)).toEqual({ value: 7, x: 0, y: 1, index: 4 });
|
|
156
|
-
|
|
157
|
-
expect(ut.computeMax(1)).toEqual({ value: 13, x: 1, y: 0, index: 3 });
|
|
158
|
-
});
|
|
159
122
|
|
|
160
123
|
test('sampleChannelBilinear 1x1 exact', () => {
|
|
161
124
|
const s = Sampler2D.uint8(1, 1, 1);
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import { Sampler2D } from "./Sampler2D.js";
|
|
7
|
-
import {
|
|
7
|
+
import { sampler2d_write_to_canvas_raw } from "./sampler2d_write_to_canvas_raw.js";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
*
|
|
@@ -85,7 +85,7 @@ function convertSampler2D2Canvas(sampler, scale = 255, offset = 0, canvas, fillD
|
|
|
85
85
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
sampler2d_write_to_canvas_raw(converted_sampler, canvas);
|
|
89
89
|
|
|
90
90
|
return canvas;
|
|
91
91
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Sampler2D } from "../Sampler2D.js";
|
|
2
|
-
import {
|
|
2
|
+
import { sampler2d_scale_down_linear } from "../sampler2d_scale_down_linear.js";
|
|
3
3
|
import { inverseLerp } from "../../../../../core/math/inverseLerp.js";
|
|
4
4
|
import { lerp } from "../../../../../core/math/lerp.js";
|
|
5
5
|
|
|
@@ -24,7 +24,7 @@ export function sampler2d_downsample_mipmap(source, destination) {
|
|
|
24
24
|
|
|
25
25
|
const out = new Sampler2D(new current_mip.data.constructor(new_w * new_h * itemSize), itemSize, new_w, new_h);
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
sampler2d_scale_down_linear(current_mip, out);
|
|
28
28
|
|
|
29
29
|
previous_mip = current_mip;
|
|
30
30
|
current_mip = out;
|