@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
|
@@ -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);
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { Sampler2D } from "./Sampler2D.js";
|
|
2
2
|
import { sampler2d_to_uint8_RGBA } from "./sampler2d_to_uint8_RGBA.js";
|
|
3
|
+
import { assert } from "../../../../core/assert.js";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
*
|
|
6
7
|
* @param {Sampler2D} sampler
|
|
7
8
|
* @param {HTMLCanvasElement} canvas
|
|
8
9
|
*/
|
|
9
|
-
export function
|
|
10
|
+
export function sampler2d_write_to_canvas_raw(sampler, canvas) {
|
|
11
|
+
|
|
12
|
+
assert.defined(sampler, 'sampler');
|
|
13
|
+
assert.defined(canvas, 'canvas');
|
|
10
14
|
|
|
11
15
|
const width = sampler.width;
|
|
12
16
|
const height = sampler.height;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assert } from "../../../../core/assert.js";
|
|
2
|
-
import {
|
|
2
|
+
import { sampler2d_scale_down_linear } from "./sampler2d_scale_down_linear.js";
|
|
3
3
|
import { Sampler2D } from "./Sampler2D.js";
|
|
4
4
|
import { upsampleSampler2D } from "./upsampleSampler2D.js";
|
|
5
5
|
import { genericResampleSampler2D } from "./genericResampleSampler2D.js";
|
|
@@ -29,7 +29,7 @@ export function scaleSampler2D(input, output) {
|
|
|
29
29
|
// downscaling
|
|
30
30
|
if (Number.isInteger(sourceWidth / targetWidth) && Number.isInteger(sourceHeight / targetHeight)) {
|
|
31
31
|
// dimensions are multiples of source/target
|
|
32
|
-
|
|
32
|
+
sampler2d_scale_down_linear(input, output);
|
|
33
33
|
} else {
|
|
34
34
|
// generic downsample
|
|
35
35
|
genericResampleSampler2D(input, output, 3);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Sampler2D } from "../../../graphics/texture/sampler/Sampler2D.js";
|
|
2
|
-
import {
|
|
2
|
+
import { sampler2d_scale_down_linear } from "../../../graphics/texture/sampler/sampler2d_scale_down_linear.js";
|
|
3
3
|
import { computeWholeDivisorLow } from "../../../../core/math/computeWholeDivisorLow.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -20,7 +20,7 @@ export function buildCameraTargetSampler({ heightSampler }) {
|
|
|
20
20
|
|
|
21
21
|
const result = Sampler2D.float32(1, s(heightSampler.width), s(heightSampler.height));
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
sampler2d_scale_down_linear(heightSampler, result);
|
|
24
24
|
|
|
25
25
|
return result;
|
|
26
26
|
}
|