@woosh/meep-engine 2.39.39 → 2.39.40
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/core/bvh2/bvh3/bvh_query_user_data_nearest_to_point.js +5 -5
- package/core/bvh2/bvh3/bvh_query_user_data_nearest_to_point.spec.js +70 -0
- package/editor/ecs/component/editors/ecs/terrain/TerrainEditor.js +12 -6
- package/engine/ecs/terrain/ecs/layers/TerrainLayers.js +5 -3
- package/engine/graphics/texture/sampler/Sampler2D.js +2 -1
- package/package.json +1 -1
|
@@ -41,7 +41,7 @@ export function bvh_query_user_data_nearest_to_point(bvh, x, y, z, max_distance
|
|
|
41
41
|
traversal_stack[traversal_cursor++] = root;
|
|
42
42
|
|
|
43
43
|
let best_leaf_data = -1;
|
|
44
|
-
let
|
|
44
|
+
let best_distance_sqr = max_distance * max_distance;
|
|
45
45
|
|
|
46
46
|
while (traversal_cursor > stack_frame_address) {
|
|
47
47
|
traversal_cursor--;
|
|
@@ -55,13 +55,13 @@ export function bvh_query_user_data_nearest_to_point(bvh, x, y, z, max_distance
|
|
|
55
55
|
bvh.node_get_aabb(node, scratch_aabb);
|
|
56
56
|
|
|
57
57
|
// compute distance to box
|
|
58
|
-
const
|
|
58
|
+
const distance_sqr = max2(0, aabb3_signed_distance_sqr_to_point(
|
|
59
59
|
scratch_aabb[0], scratch_aabb[1], scratch_aabb[2],
|
|
60
60
|
scratch_aabb[3], scratch_aabb[4], scratch_aabb[5],
|
|
61
61
|
x, y, z
|
|
62
62
|
));
|
|
63
63
|
|
|
64
|
-
if (
|
|
64
|
+
if (distance_sqr > best_distance_sqr) {
|
|
65
65
|
// node is too far
|
|
66
66
|
continue;
|
|
67
67
|
}
|
|
@@ -81,8 +81,8 @@ export function bvh_query_user_data_nearest_to_point(bvh, x, y, z, max_distance
|
|
|
81
81
|
} else {
|
|
82
82
|
|
|
83
83
|
// leaf node
|
|
84
|
-
if (
|
|
85
|
-
|
|
84
|
+
if (distance_sqr < best_distance_sqr) {
|
|
85
|
+
best_distance_sqr = distance_sqr;
|
|
86
86
|
best_leaf_data = bvh.node_get_user_data(node);
|
|
87
87
|
}
|
|
88
88
|
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ExplicitBinaryBoundingVolumeHierarchy } from "./ExplicitBinaryBoundingVolumeHierarchy.js";
|
|
2
|
+
import { bvh_query_user_data_nearest_to_point } from "./bvh_query_user_data_nearest_to_point.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param {number[]} boxes
|
|
7
|
+
* @return {ExplicitBinaryBoundingVolumeHierarchy}
|
|
8
|
+
*/
|
|
9
|
+
function makeBvh(...boxes) {
|
|
10
|
+
const r = new ExplicitBinaryBoundingVolumeHierarchy();
|
|
11
|
+
|
|
12
|
+
for (let i = 0; i < boxes.length; i++) {
|
|
13
|
+
const box = boxes[i];
|
|
14
|
+
|
|
15
|
+
const node = r.allocate_node();
|
|
16
|
+
|
|
17
|
+
r.node_set_aabb(node, box);
|
|
18
|
+
r.node_set_user_data(node, i);
|
|
19
|
+
|
|
20
|
+
r.insert_leaf(node);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return r;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
test('no data, infinite distance', () => {
|
|
27
|
+
const bvh = makeBvh();
|
|
28
|
+
|
|
29
|
+
const result = bvh_query_user_data_nearest_to_point(bvh, 0, 0, 0, Infinity);
|
|
30
|
+
|
|
31
|
+
expect(result).toBe(-1);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('single point, distance too short', () => {
|
|
35
|
+
const bvh = makeBvh([1, 0, 0, 1, 0, 0]);
|
|
36
|
+
|
|
37
|
+
const result = bvh_query_user_data_nearest_to_point(bvh, 0, 0, 0, 0.5);
|
|
38
|
+
|
|
39
|
+
expect(result).toBe(-1);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('single point, distance sufficient', () => {
|
|
43
|
+
const bvh = makeBvh([1, 0, 0, 1, 0, 0]);
|
|
44
|
+
|
|
45
|
+
const result = bvh_query_user_data_nearest_to_point(bvh, 0, 0, 0, 1.5);
|
|
46
|
+
|
|
47
|
+
expect(result).not.toBe(-1);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('two point, distance sufficient to one', () => {
|
|
51
|
+
const bvh = makeBvh(
|
|
52
|
+
[1, 0, 0, 1, 0, 0],
|
|
53
|
+
[2, 0, 0, 2, 0, 0],
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const result = bvh_query_user_data_nearest_to_point(bvh, 0, 0, 0, 1.5);
|
|
57
|
+
|
|
58
|
+
expect(result).toBe(0);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('two point, distance sufficient to both', () => {
|
|
62
|
+
const bvh = makeBvh(
|
|
63
|
+
[1, 0, 0, 1, 0, 0],
|
|
64
|
+
[2, 0, 0, 2, 0, 0],
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const result = bvh_query_user_data_nearest_to_point(bvh, 0, 0, 0, 2.5);
|
|
68
|
+
|
|
69
|
+
expect(result).toBe(0);
|
|
70
|
+
});
|
|
@@ -27,20 +27,26 @@ export class TerrainEditor extends ObjectEditor {
|
|
|
27
27
|
|
|
28
28
|
// splats
|
|
29
29
|
view.bindSignal(terrain.layers.layers.on.added, () => {
|
|
30
|
-
terrain.
|
|
31
|
-
|
|
30
|
+
if (terrain.getFlag(TerrainFlags.Built)) {
|
|
31
|
+
terrain.splat.addWeightLayer();
|
|
32
|
+
updateLayers();
|
|
33
|
+
}
|
|
32
34
|
});
|
|
33
35
|
view.bindSignal(terrain.layers.layers.on.removed, (a, index) => {
|
|
34
|
-
terrain.
|
|
36
|
+
if (terrain.getFlag(TerrainFlags.Built)) {
|
|
37
|
+
terrain.splat.removeWeightLayer(index);
|
|
35
38
|
|
|
36
|
-
|
|
39
|
+
updateLayers();
|
|
40
|
+
}
|
|
37
41
|
});
|
|
38
42
|
|
|
39
43
|
// mapping sizes
|
|
40
44
|
view.bindSignal(terrain.splat.size.onChanged, (x, y) => {
|
|
41
|
-
terrain.
|
|
45
|
+
if (terrain.getFlag(TerrainFlags.Built)) {
|
|
46
|
+
terrain.splat.resize(x, y, terrain.splat.depth);
|
|
42
47
|
|
|
43
|
-
|
|
48
|
+
terrain.updateMaterial();
|
|
49
|
+
}
|
|
44
50
|
});
|
|
45
51
|
}
|
|
46
52
|
|
|
@@ -390,16 +390,18 @@ export class TerrainLayers {
|
|
|
390
390
|
|
|
391
391
|
const resolution = this.resolution;
|
|
392
392
|
|
|
393
|
-
const
|
|
393
|
+
const single_layer_byte_size = resolution.x * resolution.y * 3;
|
|
394
394
|
|
|
395
|
-
if (arrayData.length <
|
|
395
|
+
if (arrayData.length < single_layer_byte_size * index) {
|
|
396
396
|
throw new Error('Texture data is too small, make sure you rebuild texture data before attempting to write');
|
|
397
397
|
}
|
|
398
398
|
|
|
399
|
-
const address =
|
|
399
|
+
const address = single_layer_byte_size * index;
|
|
400
400
|
|
|
401
401
|
const sampler = this.__obtain_layer_data_at_resolution(layer, resolution);
|
|
402
402
|
|
|
403
|
+
assert.equal(sampler.data.length, single_layer_byte_size, 'Incorrect layer data size');
|
|
404
|
+
|
|
403
405
|
arrayData.set(sampler.data, address);
|
|
404
406
|
|
|
405
407
|
//mark texture for update
|
|
@@ -523,6 +523,7 @@ export class Sampler2D {
|
|
|
523
523
|
* @returns {number}
|
|
524
524
|
*/
|
|
525
525
|
sampleChannelBilinear(x, y, channel) {
|
|
526
|
+
assert.isNonNegativeInteger(channel, 'channel');
|
|
526
527
|
|
|
527
528
|
const itemSize = this.itemSize;
|
|
528
529
|
|
|
@@ -1477,7 +1478,7 @@ export class Sampler2D {
|
|
|
1477
1478
|
|
|
1478
1479
|
this.data = new CTOR(data);
|
|
1479
1480
|
|
|
1480
|
-
}else{
|
|
1481
|
+
} else {
|
|
1481
1482
|
|
|
1482
1483
|
throw new Error('Unsupported data format');
|
|
1483
1484
|
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"productName": "Meep",
|
|
6
6
|
"description": "production-ready JavaScript game engine based on Entity Component System Architecture",
|
|
7
7
|
"author": "Alexander Goldring",
|
|
8
|
-
"version": "2.39.
|
|
8
|
+
"version": "2.39.40",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"gl-matrix": "3.4.3",
|
|
11
11
|
"fast-levenshtein": "2.0.6",
|