@woosh/meep-engine 2.46.36 → 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 +108 -86
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +108 -86
- package/package.json +3 -2
- 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 +4 -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
|
@@ -48206,51 +48206,12 @@ class Sampler2D {
|
|
|
48206
48206
|
}
|
|
48207
48207
|
|
|
48208
48208
|
/**
|
|
48209
|
+
* @deprecated
|
|
48209
48210
|
* @param {number} [channel=0]
|
|
48210
48211
|
* @returns {{x: number, index: number, y: number, value: number}}
|
|
48211
48212
|
*/
|
|
48212
48213
|
computeMax(channel = 0) {
|
|
48213
|
-
|
|
48214
|
-
|
|
48215
|
-
assert.isNumber(channel, "channel");
|
|
48216
|
-
assert.isNonNegativeInteger(channel , 'channel');
|
|
48217
|
-
assert.lessThan(channel, itemSize, `channel must be less than itemSize(=${itemSize}), was ${channel}`);
|
|
48218
|
-
|
|
48219
|
-
const data = this.data;
|
|
48220
|
-
|
|
48221
|
-
const l = data.length;
|
|
48222
|
-
|
|
48223
|
-
if (l === 0) {
|
|
48224
|
-
//no data
|
|
48225
|
-
return undefined;
|
|
48226
|
-
}
|
|
48227
|
-
|
|
48228
|
-
let bestValue = data[channel];
|
|
48229
|
-
let bestIndex = channel;
|
|
48230
|
-
|
|
48231
|
-
for (let i = channel + itemSize; i < l; i += itemSize) {
|
|
48232
|
-
const value = data[i];
|
|
48233
|
-
|
|
48234
|
-
if (bestValue < value) {
|
|
48235
|
-
bestValue = value;
|
|
48236
|
-
bestIndex = i;
|
|
48237
|
-
}
|
|
48238
|
-
|
|
48239
|
-
}
|
|
48240
|
-
|
|
48241
|
-
const width = this.width;
|
|
48242
|
-
|
|
48243
|
-
const itemIndex = (bestIndex / this.itemSize) | 0;
|
|
48244
|
-
|
|
48245
|
-
const x = itemIndex % width;
|
|
48246
|
-
const y = (itemIndex / width) | 0;
|
|
48247
|
-
|
|
48248
|
-
return {
|
|
48249
|
-
index: bestIndex,
|
|
48250
|
-
value: bestValue,
|
|
48251
|
-
x,
|
|
48252
|
-
y
|
|
48253
|
-
};
|
|
48214
|
+
throw new Error("deprecated, use sampler2d_channel_compute_max");
|
|
48254
48215
|
}
|
|
48255
48216
|
|
|
48256
48217
|
/**
|
|
@@ -48303,51 +48264,12 @@ class Sampler2D {
|
|
|
48303
48264
|
}
|
|
48304
48265
|
|
|
48305
48266
|
/**
|
|
48267
|
+
* @deprecated
|
|
48306
48268
|
* @param {number} [channel=0]
|
|
48307
48269
|
* @returns {{x: number, index: number, y: number, value: number}}
|
|
48308
48270
|
*/
|
|
48309
48271
|
computeMin(channel = 0) {
|
|
48310
|
-
|
|
48311
|
-
|
|
48312
|
-
assert.typeOf(channel, "number", "channel");
|
|
48313
|
-
assert.ok(channel >= 0, `channel must be >= 0, was ${channel}`);
|
|
48314
|
-
assert.ok(channel < itemSize, `channel must be less than itemSize(=${itemSize}), was ${channel}`);
|
|
48315
|
-
|
|
48316
|
-
const data = this.data;
|
|
48317
|
-
|
|
48318
|
-
const l = data.length;
|
|
48319
|
-
|
|
48320
|
-
if (l === 0) {
|
|
48321
|
-
//no data
|
|
48322
|
-
return undefined;
|
|
48323
|
-
}
|
|
48324
|
-
|
|
48325
|
-
let bestValue = data[channel];
|
|
48326
|
-
let bestIndex = channel;
|
|
48327
|
-
|
|
48328
|
-
for (let i = channel + itemSize; i < l; i += itemSize) {
|
|
48329
|
-
const value = data[i];
|
|
48330
|
-
|
|
48331
|
-
if (bestValue > value) {
|
|
48332
|
-
bestValue = value;
|
|
48333
|
-
bestIndex = i;
|
|
48334
|
-
}
|
|
48335
|
-
|
|
48336
|
-
}
|
|
48337
|
-
|
|
48338
|
-
const width = this.width;
|
|
48339
|
-
|
|
48340
|
-
const itemIndex = (bestIndex / this.itemSize) | 0;
|
|
48341
|
-
|
|
48342
|
-
const x = itemIndex % width;
|
|
48343
|
-
const y = (itemIndex / width) | 0;
|
|
48344
|
-
|
|
48345
|
-
return {
|
|
48346
|
-
index: bestIndex,
|
|
48347
|
-
value: bestValue,
|
|
48348
|
-
x,
|
|
48349
|
-
y
|
|
48350
|
-
};
|
|
48272
|
+
throw new Error("deprecated, use sampler2d_channel_compute_min");
|
|
48351
48273
|
}
|
|
48352
48274
|
|
|
48353
48275
|
/**
|
|
@@ -54838,7 +54760,7 @@ class ObservedString extends String {
|
|
|
54838
54760
|
* @param {Sampler2D} input
|
|
54839
54761
|
* @param {Sampler2D} output
|
|
54840
54762
|
*/
|
|
54841
|
-
function
|
|
54763
|
+
function sampler2d_scale_down_linear(input, output) {
|
|
54842
54764
|
assert.notEqual(input, undefined, 'input is undefined');
|
|
54843
54765
|
assert.notEqual(output, undefined, 'output is undefined');
|
|
54844
54766
|
|
|
@@ -55051,7 +54973,7 @@ function scaleSampler2D(input, output) {
|
|
|
55051
54973
|
// downscaling
|
|
55052
54974
|
if (Number.isInteger(sourceWidth / targetWidth) && Number.isInteger(sourceHeight / targetHeight)) {
|
|
55053
54975
|
// dimensions are multiples of source/target
|
|
55054
|
-
|
|
54976
|
+
sampler2d_scale_down_linear(input, output);
|
|
55055
54977
|
} else {
|
|
55056
54978
|
// generic downsample
|
|
55057
54979
|
genericResampleSampler2D(input, output);
|
|
@@ -65567,6 +65489,106 @@ WorkerBuilder.prototype.build = function () {
|
|
|
65567
65489
|
return proxy;
|
|
65568
65490
|
};
|
|
65569
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
|
+
|
|
65570
65592
|
/**
|
|
65571
65593
|
*
|
|
65572
65594
|
* @return {WorkerProxy}
|
|
@@ -65594,8 +65616,8 @@ function makeTerrainWorkerProxy() {
|
|
|
65594
65616
|
|
|
65595
65617
|
useSampler(function (sampler) {
|
|
65596
65618
|
|
|
65597
|
-
const min = sampler
|
|
65598
|
-
const max = sampler
|
|
65619
|
+
const min = sampler2d_channel_compute_min(sampler);
|
|
65620
|
+
const max = sampler2d_channel_compute_max(sampler);
|
|
65599
65621
|
|
|
65600
65622
|
resolve({
|
|
65601
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",
|
|
@@ -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
|
|
|
@@ -86,51 +86,12 @@ export class Sampler2D {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
/**
|
|
89
|
+
* @deprecated
|
|
89
90
|
* @param {number} [channel=0]
|
|
90
91
|
* @returns {{x: number, index: number, y: number, value: number}}
|
|
91
92
|
*/
|
|
92
93
|
computeMax(channel = 0) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
assert.isNumber(channel, "channel");
|
|
96
|
-
assert.isNonNegativeInteger(channel , 'channel');
|
|
97
|
-
assert.lessThan(channel, itemSize, `channel must be less than itemSize(=${itemSize}), was ${channel}`);
|
|
98
|
-
|
|
99
|
-
const data = this.data;
|
|
100
|
-
|
|
101
|
-
const l = data.length;
|
|
102
|
-
|
|
103
|
-
if (l === 0) {
|
|
104
|
-
//no data
|
|
105
|
-
return undefined;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
let bestValue = data[channel];
|
|
109
|
-
let bestIndex = channel;
|
|
110
|
-
|
|
111
|
-
for (let i = channel + itemSize; i < l; i += itemSize) {
|
|
112
|
-
const value = data[i];
|
|
113
|
-
|
|
114
|
-
if (bestValue < value) {
|
|
115
|
-
bestValue = value;
|
|
116
|
-
bestIndex = i;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const width = this.width;
|
|
122
|
-
|
|
123
|
-
const itemIndex = (bestIndex / this.itemSize) | 0;
|
|
124
|
-
|
|
125
|
-
const x = itemIndex % width;
|
|
126
|
-
const y = (itemIndex / width) | 0;
|
|
127
|
-
|
|
128
|
-
return {
|
|
129
|
-
index: bestIndex,
|
|
130
|
-
value: bestValue,
|
|
131
|
-
x,
|
|
132
|
-
y
|
|
133
|
-
};
|
|
94
|
+
throw new Error("deprecated, use sampler2d_channel_compute_max");
|
|
134
95
|
}
|
|
135
96
|
|
|
136
97
|
/**
|
|
@@ -183,51 +144,12 @@ export class Sampler2D {
|
|
|
183
144
|
}
|
|
184
145
|
|
|
185
146
|
/**
|
|
147
|
+
* @deprecated
|
|
186
148
|
* @param {number} [channel=0]
|
|
187
149
|
* @returns {{x: number, index: number, y: number, value: number}}
|
|
188
150
|
*/
|
|
189
151
|
computeMin(channel = 0) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
assert.typeOf(channel, "number", "channel");
|
|
193
|
-
assert.ok(channel >= 0, `channel must be >= 0, was ${channel}`);
|
|
194
|
-
assert.ok(channel < itemSize, `channel must be less than itemSize(=${itemSize}), was ${channel}`);
|
|
195
|
-
|
|
196
|
-
const data = this.data;
|
|
197
|
-
|
|
198
|
-
const l = data.length;
|
|
199
|
-
|
|
200
|
-
if (l === 0) {
|
|
201
|
-
//no data
|
|
202
|
-
return undefined;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
let bestValue = data[channel];
|
|
206
|
-
let bestIndex = channel;
|
|
207
|
-
|
|
208
|
-
for (let i = channel + itemSize; i < l; i += itemSize) {
|
|
209
|
-
const value = data[i];
|
|
210
|
-
|
|
211
|
-
if (bestValue > value) {
|
|
212
|
-
bestValue = value;
|
|
213
|
-
bestIndex = i;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
const width = this.width;
|
|
219
|
-
|
|
220
|
-
const itemIndex = (bestIndex / this.itemSize) | 0;
|
|
221
|
-
|
|
222
|
-
const x = itemIndex % width;
|
|
223
|
-
const y = (itemIndex / width) | 0;
|
|
224
|
-
|
|
225
|
-
return {
|
|
226
|
-
index: bestIndex,
|
|
227
|
-
value: bestValue,
|
|
228
|
-
x,
|
|
229
|
-
y
|
|
230
|
-
};
|
|
152
|
+
throw new Error("deprecated, use sampler2d_channel_compute_min");
|
|
231
153
|
}
|
|
232
154
|
|
|
233
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;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { assert } from "../../../../core/assert.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {Sampler2D} sampler
|
|
6
|
+
* @param {number} [channel=0]
|
|
7
|
+
* @returns {undefined|{x: number, index:number, y: number, value: number}}
|
|
8
|
+
*/
|
|
9
|
+
export function sampler2d_channel_compute_max(sampler, channel=0){
|
|
10
|
+
const itemSize = sampler.itemSize;
|
|
11
|
+
|
|
12
|
+
assert.isNumber(channel, "channel");
|
|
13
|
+
assert.isNonNegativeInteger(channel , 'channel');
|
|
14
|
+
assert.lessThan(channel, itemSize, `channel must be less than itemSize(=${itemSize}), was ${channel}`);
|
|
15
|
+
|
|
16
|
+
const data = sampler.data;
|
|
17
|
+
|
|
18
|
+
const l = data.length;
|
|
19
|
+
|
|
20
|
+
if (l === 0) {
|
|
21
|
+
//no data
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let bestValue = data[channel];
|
|
26
|
+
let bestIndex = channel;
|
|
27
|
+
|
|
28
|
+
for (let i = channel + itemSize; i < l; i += itemSize) {
|
|
29
|
+
const value = data[i];
|
|
30
|
+
|
|
31
|
+
if (bestValue < value) {
|
|
32
|
+
bestValue = value;
|
|
33
|
+
bestIndex = i;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const width = this.width;
|
|
39
|
+
|
|
40
|
+
const itemIndex = (bestIndex / itemSize) | 0;
|
|
41
|
+
|
|
42
|
+
const x = itemIndex % width;
|
|
43
|
+
const y = (itemIndex / width) | 0;
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
index: bestIndex,
|
|
47
|
+
value: bestValue,
|
|
48
|
+
x,
|
|
49
|
+
y
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Sampler2D } from "./Sampler2D.js";
|
|
2
|
+
import { sampler2d_channel_compute_max } from "./sampler2d_channel_compute_max.js";
|
|
3
|
+
|
|
4
|
+
test('computeMax itemSize=1, 0x0', () => {
|
|
5
|
+
const ut = Sampler2D.int8(1, 0, 0);
|
|
6
|
+
|
|
7
|
+
expect(sampler2d_channel_compute_max(ut,0)).toEqual(undefined);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test('computeMax itemSize=1, 1x1', () => {
|
|
11
|
+
const ut = Sampler2D.int8(1, 1, 1);
|
|
12
|
+
|
|
13
|
+
ut.set(0, 0, [7]);
|
|
14
|
+
|
|
15
|
+
expect(sampler2d_channel_compute_max(ut,0)).toEqual({ value: 7, x: 0, y: 0, index: 0 });
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('computeMax itemSize=1, 2x2', () => {
|
|
19
|
+
const ut = Sampler2D.int8(1, 2, 2);
|
|
20
|
+
|
|
21
|
+
ut.set(0, 0, [3]);
|
|
22
|
+
ut.set(1, 0, [-7]);
|
|
23
|
+
ut.set(0, 1, [7]);
|
|
24
|
+
ut.set(1, 1, [4]);
|
|
25
|
+
|
|
26
|
+
expect(sampler2d_channel_compute_max(ut,0)).toEqual({ value: 7, x: 0, y: 1, index: 2 });
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('computeMax itemSize=2, 2x2', () => {
|
|
30
|
+
const ut = Sampler2D.int8(2, 2, 2);
|
|
31
|
+
|
|
32
|
+
ut.set(0, 0, [3, 8]);
|
|
33
|
+
ut.set(1, 0, [-7, 13]);
|
|
34
|
+
ut.set(0, 1, [7, 1]);
|
|
35
|
+
ut.set(1, 1, [4, -3]);
|
|
36
|
+
|
|
37
|
+
expect(sampler2d_channel_compute_max(ut,0)).toEqual({ value: 7, x: 0, y: 1, index: 4 });
|
|
38
|
+
|
|
39
|
+
expect(sampler2d_channel_compute_max(ut,1)).toEqual({ value: 13, x: 1, y: 0, index: 3 });
|
|
40
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { assert } from "../../../../core/assert.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {Sampler2D} sampler
|
|
6
|
+
* @param {number} [channel=0]
|
|
7
|
+
* @returns {undefined|{x: number, index:number, y: number, value: number}}
|
|
8
|
+
*/
|
|
9
|
+
export function sampler2d_channel_compute_min(sampler, channel=0){
|
|
10
|
+
const itemSize = sampler.itemSize;
|
|
11
|
+
|
|
12
|
+
assert.isNumber(channel, "channel");
|
|
13
|
+
assert.isNonNegativeInteger(channel , 'channel');
|
|
14
|
+
assert.lessThan(channel, itemSize, `channel must be less than itemSize(=${itemSize}), was ${channel}`);
|
|
15
|
+
|
|
16
|
+
const data = sampler.data;
|
|
17
|
+
|
|
18
|
+
const l = data.length;
|
|
19
|
+
|
|
20
|
+
if (l === 0) {
|
|
21
|
+
//no data
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let bestValue = data[channel];
|
|
26
|
+
let bestIndex = channel;
|
|
27
|
+
|
|
28
|
+
for (let i = channel + itemSize; i < l; i += itemSize) {
|
|
29
|
+
const value = data[i];
|
|
30
|
+
|
|
31
|
+
if (bestValue > value) {
|
|
32
|
+
bestValue = value;
|
|
33
|
+
bestIndex = i;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const width = this.width;
|
|
39
|
+
|
|
40
|
+
const itemIndex = (bestIndex / itemSize) | 0;
|
|
41
|
+
|
|
42
|
+
const x = itemIndex % width;
|
|
43
|
+
const y = (itemIndex / width) | 0;
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
index: bestIndex,
|
|
47
|
+
value: bestValue,
|
|
48
|
+
x,
|
|
49
|
+
y
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -3,6 +3,8 @@ import { min2 } from "../../../../core/math/min2.js";
|
|
|
3
3
|
import { max2 } from "../../../../core/math/max2.js";
|
|
4
4
|
import { isTypedArray } from "../../../../core/collection/array/typed/isTypedArray.js";
|
|
5
5
|
import { typedArrayToDataType } from "../../../../core/collection/array/typedArrayToDataType.js";
|
|
6
|
+
import { sampler2d_channel_compute_max } from "./sampler2d_channel_compute_max.js";
|
|
7
|
+
import { sampler2d_channel_compute_min } from "./sampler2d_channel_compute_min.js";
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
*
|
|
@@ -31,8 +33,8 @@ export function sampler2d_compute_texel_value_conversion_scale_to_uint8(sampler)
|
|
|
31
33
|
max = -Infinity;
|
|
32
34
|
for (let i = 0; i < sampler.itemSize; i++) {
|
|
33
35
|
|
|
34
|
-
min = min2(min,
|
|
35
|
-
max = max2(min, sampler
|
|
36
|
+
min = min2(min,sampler2d_channel_compute_min(sampler,i).value)
|
|
37
|
+
max = max2(min, sampler2d_channel_compute_max(sampler,i).value)
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
|
|
@@ -5,7 +5,7 @@ import { assert } from "../../../../core/assert.js";
|
|
|
5
5
|
* @param {Sampler2D} input
|
|
6
6
|
* @param {Sampler2D} output
|
|
7
7
|
*/
|
|
8
|
-
export function
|
|
8
|
+
export function sampler2d_scale_down_linear(input, output) {
|
|
9
9
|
assert.notEqual(input, undefined, 'input is undefined');
|
|
10
10
|
assert.notEqual(output, undefined, 'output is undefined');
|
|
11
11
|
|
|
@@ -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
|
|
|
4
4
|
test('2x2 -> 1x1 2x channel', () => {
|
|
5
5
|
const input = Sampler2D.float32(2, 2, 2);
|
|
@@ -10,7 +10,7 @@ test('2x2 -> 1x1 2x channel', () => {
|
|
|
10
10
|
input.set(0, 1, [11, 13]);
|
|
11
11
|
input.set(1, 1, [17, 19]);
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
sampler2d_scale_down_linear(input, output);
|
|
14
14
|
|
|
15
15
|
expect(output.data[0]).toEqual(8.5);
|
|
16
16
|
expect(output.data[1]).toEqual(10.5);
|