@woosh/meep-engine 2.39.25 → 2.39.29
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/aabb3/AABB3.js +10 -29
- package/core/bvh2/aabb3/aabb3_signed_distance_sqr_to_point.js +39 -0
- package/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.d.ts +3 -0
- package/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js +40 -0
- package/core/bvh2/bvh3/bvh_query_user_data_generic.js +1 -1
- package/core/bvh2/bvh3/bvh_query_user_data_nearest_to_point.js +96 -0
- package/editor/tools/paint/prototypeTerrainEditor.js +1 -2
- package/editor/tools/v2/BlenderCameraOrientationGizmo.d.ts +34 -1
- package/editor/tools/v2/BlenderCameraOrientationGizmo.js +29 -3
- package/engine/graphics/GraphicsEngine.d.ts +1 -1
- package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.d.ts +3 -0
- package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +10 -2
- package/package.json +1 -1
package/core/bvh2/aabb3/AABB3.js
CHANGED
|
@@ -14,6 +14,7 @@ import { aabb3_intersects_ray } from "./aabb3_intersects_ray.js";
|
|
|
14
14
|
import { aabb3_compute_surface_area } from "./aabb3_compute_surface_area.js";
|
|
15
15
|
import { aabb3_intersects_frustum_array } from "./aabb3_intersects_frustum_array.js";
|
|
16
16
|
import { aabb3_matrix4_project } from "../../geom/3d/aabb/aabb3_matrix4_project.js";
|
|
17
|
+
import { aabb3_signed_distance_sqr_to_point } from "./aabb3_signed_distance_sqr_to_point.js";
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
export class AABB3 {
|
|
@@ -209,35 +210,15 @@ export class AABB3 {
|
|
|
209
210
|
* @returns {number} Squared distance to point, value is negative if the point is inside the box
|
|
210
211
|
*/
|
|
211
212
|
distanceToPoint2(x, y, z) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
const xp1 = x - _x1;
|
|
222
|
-
const yp0 = _y0 - y;
|
|
223
|
-
const yp1 = y - _y1;
|
|
224
|
-
const zp0 = _z0 - z;
|
|
225
|
-
const zp1 = z - _z1;
|
|
226
|
-
|
|
227
|
-
//calculate separation in each axis
|
|
228
|
-
const dx = Math.max(xp0, xp1);
|
|
229
|
-
const dy = Math.max(yp0, yp1);
|
|
230
|
-
const dz = Math.max(zp0, zp1);
|
|
231
|
-
|
|
232
|
-
//straight-line distance
|
|
233
|
-
const distance2 = dx * dx + dy * dy + dz * dz;
|
|
234
|
-
|
|
235
|
-
if (dx < 0 && dy < 0 && dz < 0) {
|
|
236
|
-
//penetration
|
|
237
|
-
return -distance2;
|
|
238
|
-
} else {
|
|
239
|
-
return distance2;
|
|
240
|
-
}
|
|
213
|
+
return aabb3_signed_distance_sqr_to_point(
|
|
214
|
+
this.x0,
|
|
215
|
+
this.y0,
|
|
216
|
+
this.z0,
|
|
217
|
+
this.x1,
|
|
218
|
+
this.y1,
|
|
219
|
+
this.z1,
|
|
220
|
+
x, y, z
|
|
221
|
+
);
|
|
241
222
|
}
|
|
242
223
|
|
|
243
224
|
/**
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { max2 } from "../../math/max2.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Compute squared distance to point, value is negative if the point is inside the box
|
|
5
|
+
* @param {number} x0
|
|
6
|
+
* @param {number} y0
|
|
7
|
+
* @param {number} z0
|
|
8
|
+
* @param {number} x1
|
|
9
|
+
* @param {number} y1
|
|
10
|
+
* @param {number} z1
|
|
11
|
+
* @param {number} point_x
|
|
12
|
+
* @param {number} point_y
|
|
13
|
+
* @param {number} point_z
|
|
14
|
+
* @returns {number}
|
|
15
|
+
*/
|
|
16
|
+
export function aabb3_signed_distance_sqr_to_point(x0, y0, z0, x1, y1, z1, point_x, point_y, point_z) {
|
|
17
|
+
//do projection
|
|
18
|
+
const xp0 = x0 - point_x;
|
|
19
|
+
const xp1 = point_x - x1;
|
|
20
|
+
const yp0 = y0 - point_y;
|
|
21
|
+
const yp1 = point_y - y1;
|
|
22
|
+
const zp0 = z0 - point_z;
|
|
23
|
+
const zp1 = point_z - z1;
|
|
24
|
+
|
|
25
|
+
//calculate separation in each axis
|
|
26
|
+
const dx = max2(xp0, xp1);
|
|
27
|
+
const dy = max2(yp0, yp1);
|
|
28
|
+
const dz = max2(zp0, zp1);
|
|
29
|
+
|
|
30
|
+
//straight-line distance
|
|
31
|
+
const distance_sqr = dx * dx + dy * dy + dz * dz;
|
|
32
|
+
|
|
33
|
+
if (dx < 0 && dy < 0 && dz < 0) {
|
|
34
|
+
//penetration, negative distance
|
|
35
|
+
return -distance_sqr;
|
|
36
|
+
} else {
|
|
37
|
+
return distance_sqr;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -49,6 +49,12 @@ const ELEMENT_WORD_COUNT = 10;
|
|
|
49
49
|
*/
|
|
50
50
|
const INITIAL_CAPACITY = 128;
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
*
|
|
54
|
+
* @type {number[]}
|
|
55
|
+
*/
|
|
56
|
+
const scratch_stack = [];
|
|
57
|
+
|
|
52
58
|
/**
|
|
53
59
|
* Bounding Volume Hierarchy implementation. Stores unsigned integer values at leaves, these are typically IDs or Index values.
|
|
54
60
|
* Highly optimized both in terms of memory usage and CPU. Most of the code inlined. No allocation are performed during usage (except for growing the tree capacity).
|
|
@@ -874,6 +880,40 @@ export class ExplicitBinaryBoundingVolumeHierarchy {
|
|
|
874
880
|
return iA;
|
|
875
881
|
}
|
|
876
882
|
|
|
883
|
+
/**
|
|
884
|
+
* Release all nodes, this essentially resets the tree to empty state
|
|
885
|
+
*/
|
|
886
|
+
release_all() {
|
|
887
|
+
let cursor = 0;
|
|
888
|
+
const stack = scratch_stack;
|
|
889
|
+
|
|
890
|
+
const root = this.__root;
|
|
891
|
+
|
|
892
|
+
if (root !== NULL_NODE) {
|
|
893
|
+
stack[cursor++] = root;
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
const uint32 = this.__data_uint32;
|
|
897
|
+
|
|
898
|
+
while (cursor > 0) {
|
|
899
|
+
cursor--;
|
|
900
|
+
|
|
901
|
+
const node = stack[cursor];
|
|
902
|
+
|
|
903
|
+
const node_address = node * ELEMENT_WORD_COUNT;
|
|
904
|
+
|
|
905
|
+
const child1 = uint32[node_address + COLUMN_CHILD_1];
|
|
906
|
+
const child2 = uint32[node_address + COLUMN_CHILD_2];
|
|
907
|
+
|
|
908
|
+
if (child1 !== NULL_NODE) {
|
|
909
|
+
stack[cursor++] = child2;
|
|
910
|
+
stack[cursor++] = child1;
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
this.release_node(node);
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
|
|
877
917
|
/**
|
|
878
918
|
*
|
|
879
919
|
* @param {(node:number, tree:ExplicitBinaryBoundingVolumeHierarchy)=>void} callback
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { NULL_NODE } from "./ExplicitBinaryBoundingVolumeHierarchy.js";
|
|
2
|
+
import { aabb3_signed_distance_sqr_to_point } from "../aabb3/aabb3_signed_distance_sqr_to_point.js";
|
|
3
|
+
import { max2 } from "../../math/max2.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @type {number[]}
|
|
8
|
+
*/
|
|
9
|
+
const traversal_stack = [];
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @type {number[]}
|
|
14
|
+
*/
|
|
15
|
+
const scratch_aabb = [];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @type {number}
|
|
20
|
+
*/
|
|
21
|
+
let traversal_cursor = 0;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @param {ExplicitBinaryBoundingVolumeHierarchy} bvh
|
|
26
|
+
* @param {number} x
|
|
27
|
+
* @param {number} y
|
|
28
|
+
* @param {number} z
|
|
29
|
+
* @param {number} [max_distance=Infinity] how far to search
|
|
30
|
+
* @returns {number} user data of the leaf, or -1 if not found
|
|
31
|
+
*/
|
|
32
|
+
export function bvh_query_user_data_nearest_to_point(bvh, x, y, z, max_distance = Infinity) {
|
|
33
|
+
const stack_frame_address = traversal_cursor;
|
|
34
|
+
|
|
35
|
+
const root = bvh.root;
|
|
36
|
+
|
|
37
|
+
if (root === NULL_NODE) {
|
|
38
|
+
return -1;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
traversal_stack[traversal_cursor++] = root;
|
|
42
|
+
|
|
43
|
+
let best_leaf_data = -1;
|
|
44
|
+
let best_distance = max_distance;
|
|
45
|
+
|
|
46
|
+
while (traversal_cursor > stack_frame_address) {
|
|
47
|
+
traversal_cursor--;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
* @type {number}
|
|
52
|
+
*/
|
|
53
|
+
const node = traversal_stack[traversal_cursor];
|
|
54
|
+
|
|
55
|
+
bvh.node_get_aabb(node, scratch_aabb);
|
|
56
|
+
|
|
57
|
+
// compute distance to box
|
|
58
|
+
const distance = max2(0, aabb3_signed_distance_sqr_to_point(
|
|
59
|
+
scratch_aabb[0], scratch_aabb[1], scratch_aabb[2],
|
|
60
|
+
scratch_aabb[3], scratch_aabb[4], scratch_aabb[5],
|
|
61
|
+
x, y, z
|
|
62
|
+
));
|
|
63
|
+
|
|
64
|
+
if (distance > best_distance) {
|
|
65
|
+
// node is too far
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const node_is_leaf = bvh.node_is_leaf(node);
|
|
70
|
+
|
|
71
|
+
if (!node_is_leaf) {
|
|
72
|
+
|
|
73
|
+
// read in-order
|
|
74
|
+
const child1 = bvh.node_get_child1(node);
|
|
75
|
+
const child2 = bvh.node_get_child2(node);
|
|
76
|
+
|
|
77
|
+
// write to stack in reverse order, so that fist child ends up being visited first
|
|
78
|
+
traversal_stack[traversal_cursor++] = child1;
|
|
79
|
+
traversal_stack[traversal_cursor++] = child2;
|
|
80
|
+
|
|
81
|
+
} else {
|
|
82
|
+
|
|
83
|
+
// leaf node
|
|
84
|
+
if (distance < best_distance) {
|
|
85
|
+
best_distance = distance;
|
|
86
|
+
best_leaf_data = bvh.node_get_user_data(node);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// drop stack frame
|
|
93
|
+
traversal_cursor = stack_frame_address;
|
|
94
|
+
|
|
95
|
+
return best_leaf_data;
|
|
96
|
+
}
|
|
@@ -13,7 +13,6 @@ import { TerrainLayer } from "../../../engine/ecs/terrain/ecs/layers/TerrainLaye
|
|
|
13
13
|
import Terrain from "../../../engine/ecs/terrain/ecs/Terrain.js";
|
|
14
14
|
import Vector3 from "../../../core/geom/Vector3.js";
|
|
15
15
|
import { BlenderCameraOrientationGizmo } from "../v2/BlenderCameraOrientationGizmo.js";
|
|
16
|
-
import Quaternion from "../../../core/geom/Quaternion.js";
|
|
17
16
|
import { Transform } from "../../../engine/ecs/transform/Transform.js";
|
|
18
17
|
import TopDownCameraController from "../../../engine/graphics/ecs/camera/topdown/TopDownCameraController.js";
|
|
19
18
|
|
|
@@ -69,7 +68,7 @@ async function main(engine) {
|
|
|
69
68
|
|
|
70
69
|
editor_controls.enable();
|
|
71
70
|
|
|
72
|
-
const camera_orientation_gizmo = new BlenderCameraOrientationGizmo(
|
|
71
|
+
const camera_orientation_gizmo = new BlenderCameraOrientationGizmo();
|
|
73
72
|
|
|
74
73
|
camera_orientation_gizmo.css({
|
|
75
74
|
position: 'absolute',
|
|
@@ -6,8 +6,41 @@ interface ISignals extends IViewSignals {
|
|
|
6
6
|
readonly axisSelected: Signal<string>
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
interface IDirectionStyle {
|
|
10
|
+
near_fill?: string
|
|
11
|
+
near_stroke_width?: number
|
|
12
|
+
near_stroke_color?: string
|
|
13
|
+
|
|
14
|
+
far_fill?: string
|
|
15
|
+
far_stroke_width?: number
|
|
16
|
+
far_stroke_color?: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface IOptions {
|
|
20
|
+
size?: number,
|
|
21
|
+
padding?: number,
|
|
22
|
+
bubbleSizePrimary?: number,
|
|
23
|
+
bubbleSizeSecondary?: number,
|
|
24
|
+
lineWidth?: number,
|
|
25
|
+
fontSize?: string,
|
|
26
|
+
fontFamily?: string,
|
|
27
|
+
fontWeight?: string,
|
|
28
|
+
fontColor?: string,
|
|
29
|
+
fontYAdjust?: number,
|
|
30
|
+
selectionFontColor?: string,
|
|
31
|
+
axisStyles?: {
|
|
32
|
+
px?: IDirectionStyle,
|
|
33
|
+
py?: IDirectionStyle,
|
|
34
|
+
pz?: IDirectionStyle,
|
|
35
|
+
|
|
36
|
+
nx?: IDirectionStyle,
|
|
37
|
+
ny?: IDirectionStyle,
|
|
38
|
+
nz?: IDirectionStyle,
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
9
42
|
export class BlenderCameraOrientationGizmo extends View {
|
|
10
|
-
constructor(
|
|
43
|
+
constructor(options?: IOptions)
|
|
11
44
|
|
|
12
45
|
on: ISignals
|
|
13
46
|
|
|
@@ -57,6 +57,30 @@ class DirectionStyle {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
function apply_hierarchical_options(source, target) {
|
|
61
|
+
for (const prop_name in source) {
|
|
62
|
+
if (!target.hasOwnProperty(prop_name)) {
|
|
63
|
+
console.warn(`Property '${prop_name}' doesn't exist, valid properties are : ${Object.keys(target)}`);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const existing_target_value = target[prop_name];
|
|
68
|
+
const source_value = source[prop_name];
|
|
69
|
+
|
|
70
|
+
if (typeof existing_target_value === "object") {
|
|
71
|
+
if (typeof existing_target_value.fromJSON === "function") {
|
|
72
|
+
existing_target_value.fromJSON(source_value);
|
|
73
|
+
} else {
|
|
74
|
+
apply_hierarchical_options(source_value, existing_target_value);
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
target[prop_name] = source_value;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
60
84
|
|
|
61
85
|
/**
|
|
62
86
|
* Modelled on https://github.com/jrj2211/three-orientation-gizmo/blob/master/src/OrientationGizmo.js
|
|
@@ -64,16 +88,15 @@ class DirectionStyle {
|
|
|
64
88
|
export class BlenderCameraOrientationGizmo extends CanvasView {
|
|
65
89
|
/**
|
|
66
90
|
*
|
|
67
|
-
* @param {Quaternion} quaternion
|
|
68
91
|
*/
|
|
69
|
-
constructor(
|
|
92
|
+
constructor(options = {}) {
|
|
70
93
|
super();
|
|
71
94
|
|
|
72
95
|
/**
|
|
73
96
|
*
|
|
74
97
|
* @type {Quaternion}
|
|
75
98
|
*/
|
|
76
|
-
this.orientation =
|
|
99
|
+
this.orientation = null;
|
|
77
100
|
|
|
78
101
|
this.options = {
|
|
79
102
|
size: 100,
|
|
@@ -129,6 +152,9 @@ export class BlenderCameraOrientationGizmo extends CanvasView {
|
|
|
129
152
|
}
|
|
130
153
|
};
|
|
131
154
|
|
|
155
|
+
// read options
|
|
156
|
+
apply_hierarchical_options(options, this.options);
|
|
157
|
+
|
|
132
158
|
// Generate list of axes
|
|
133
159
|
this.bubbles = [
|
|
134
160
|
{
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {PerspectiveCamera, Scene, WebGLRenderer, WebGLRenderTarget} from "three";
|
|
2
2
|
import {RenderLayerManager} from "./render/layers/RenderLayerManager";
|
|
3
3
|
import Vector3 from "../../core/geom/Vector3";
|
|
4
4
|
import Vector2 from "../../core/geom/Vector2";
|
|
@@ -2,10 +2,13 @@ import {System} from "../../../ecs/System";
|
|
|
2
2
|
import Engine from "../../../Engine";
|
|
3
3
|
import {ShadedGeometry} from "./ShadedGeometry";
|
|
4
4
|
import {SurfacePoint3} from "../../../../core/geom/3d/SurfacePoint3";
|
|
5
|
+
import {ExplicitBinaryBoundingVolumeHierarchy} from "../../../../core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy";
|
|
5
6
|
|
|
6
7
|
export class ShadedGeometrySystem extends System<ShadedGeometry> {
|
|
7
8
|
constructor(engine: Engine)
|
|
8
9
|
|
|
10
|
+
readonly bvh: ExplicitBinaryBoundingVolumeHierarchy
|
|
11
|
+
|
|
9
12
|
raycastNearest(
|
|
10
13
|
contact: SurfacePoint3,
|
|
11
14
|
origin_x: number, origin_y: number, origin_z: number,
|
|
@@ -108,6 +108,14 @@ export class ShadedGeometrySystem extends System {
|
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
/**
|
|
112
|
+
*
|
|
113
|
+
* @returns {ExplicitBinaryBoundingVolumeHierarchy}
|
|
114
|
+
*/
|
|
115
|
+
get bvh() {
|
|
116
|
+
return this.__bvh_binary;
|
|
117
|
+
}
|
|
118
|
+
|
|
111
119
|
/**
|
|
112
120
|
* NOTE: DO NOT MODIFY RESULTS
|
|
113
121
|
* @returns {Map<number,number>}
|
|
@@ -386,7 +394,7 @@ export class ShadedGeometrySystem extends System {
|
|
|
386
394
|
direction_x, direction_y, direction_z
|
|
387
395
|
);
|
|
388
396
|
|
|
389
|
-
const geometry_hit_found = sg.query_raycast_nearest(scratch_point,scratch_ray_0,m4);
|
|
397
|
+
const geometry_hit_found = sg.query_raycast_nearest(scratch_point, scratch_ray_0, m4);
|
|
390
398
|
|
|
391
399
|
if (!geometry_hit_found) {
|
|
392
400
|
continue;
|
|
@@ -467,7 +475,7 @@ export class ShadedGeometrySystem extends System {
|
|
|
467
475
|
direction_x, direction_y, direction_z
|
|
468
476
|
);
|
|
469
477
|
|
|
470
|
-
const geometry_hit_found = sg.query_raycast_nearest(scratch_point,scratch_ray_0,m4);
|
|
478
|
+
const geometry_hit_found = sg.query_raycast_nearest(scratch_point, scratch_ray_0, m4);
|
|
471
479
|
|
|
472
480
|
if (!geometry_hit_found) {
|
|
473
481
|
continue;
|
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.29",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"gl-matrix": "3.4.3",
|
|
11
11
|
"fast-levenshtein": "2.0.6",
|