@woosh/meep-engine 2.76.4 → 2.78.0
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 +236 -616
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +236 -616
- package/editor/view/ecs/components/TerrainController.js +9 -16
- package/package.json +1 -1
- package/src/core/collection/heap/Uint32Heap.js +10 -1
- package/src/core/graph/Edge.js +20 -0
- package/src/core/graph/SquareMatrix.js +4 -2
- package/src/core/graph/WeightedEdge.js +5 -9
- package/src/core/graph/coloring/colorizeGraphGreedy.spec.js +1 -1
- package/src/core/graph/coloring/validateGraphColoring.js +1 -1
- package/src/core/graph/eigen/matrix_eigenvalues_in_place.js +21 -0
- package/src/core/graph/eigen/{eigen.spec.js → matrix_eigenvalues_in_place.spec.js} +2 -2
- package/src/core/graph/eigen/matrix_householder_in_place.js +92 -0
- package/src/core/graph/eigen/{eigen.js → matrix_qr_in_place.js} +2 -113
- package/src/core/graph/layout/CircleLayout.js +6 -11
- package/src/core/graph/v2/Graph.js +39 -9
- package/src/core/graph/v2/NodeContainer.js +136 -22
- package/src/engine/ecs/storage/binary/BinarySerializationRegistry.js +8 -6
- package/src/engine/graphics/particles/node-based/codegen/modules/FunctionModuleRegistry.js +1 -1
- package/src/engine/navigation/grid/find_path_on_grid_astar.js +25 -22
- package/src/engine/navigation/grid/find_path_on_grid_astar.spec.js +2 -2
- package/src/generation/grid/generation/road/GridTaskGenerateRoads.js +17 -33
- package/src/core/graph/Graph.js +0 -564
- package/src/core/graph/GraphUtils.js +0 -284
- package/src/engine/ecs/terrain/ecs/splat/SplatMapMaterialPatch.js +0 -464
- package/src/engine/ecs/terrain/ecs/splat/SplatMapOptimizer.js +0 -622
- package/src/engine/ecs/terrain/ecs/splat/SplatMapOptimizerDebugger.js +0 -383
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 05/02/14.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
line_segment_compute_line_segment_intersection_vectors_array_2d
|
|
8
|
-
} from "../geom/2d/line/line_segment_compute_line_segment_intersection_vectors_array_2d.js";
|
|
9
|
-
|
|
10
|
-
const Utils = {};
|
|
11
|
-
|
|
12
|
-
function pointBetweenEdges(edge1, edge2, node, thickness) {
|
|
13
|
-
const other1 = edge1.other(node);
|
|
14
|
-
const other2 = edge2.other(node);
|
|
15
|
-
const delta1 = other1.clone().sub(node);
|
|
16
|
-
const delta2 = other2.clone().sub(node);
|
|
17
|
-
const sum = delta2.normalize().clone().add(delta1.normalize());
|
|
18
|
-
let angle = edge2.angle() - edge1.angle();
|
|
19
|
-
if (angle < 0) {
|
|
20
|
-
angle += Math.PI * 2;
|
|
21
|
-
}
|
|
22
|
-
// console.log(angle * (57.295));
|
|
23
|
-
if (angle === 0) {
|
|
24
|
-
//parallel edges
|
|
25
|
-
sum.set(delta1.y, delta1.x);
|
|
26
|
-
sum.multiplyScalar(thickness / 2);
|
|
27
|
-
console.log(">");
|
|
28
|
-
} else {
|
|
29
|
-
const scalar = (thickness / 2) * (1 + sum.length() / 4);
|
|
30
|
-
sum.normalize().multiplyScalar(scalar);
|
|
31
|
-
if (angle > Math.PI) {
|
|
32
|
-
console.log("<");
|
|
33
|
-
sum.negate();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return sum;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function angleDifference(edge1, edge2) {
|
|
40
|
-
return edge1.angle() - edge2.angle();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function trace2(graph, thickness) {
|
|
44
|
-
//clone graph
|
|
45
|
-
const g = graph.clone();
|
|
46
|
-
let closedNodes = [];
|
|
47
|
-
let closedEdges = [];
|
|
48
|
-
//edge needs to be covered twice to be closed
|
|
49
|
-
let prevEdge, prevNode,
|
|
50
|
-
currentEdge, currentNode;
|
|
51
|
-
while (g.edges.length > 0) {
|
|
52
|
-
//pick next edge
|
|
53
|
-
const node = prevEdge.other(prevNode);
|
|
54
|
-
const neighbours = g.getAttachedEdges(node);
|
|
55
|
-
neighbours.sort(angleDifference);
|
|
56
|
-
let index = neighbours.indexOf(prevEdge);
|
|
57
|
-
index = (index + 1) % neighbours.length;
|
|
58
|
-
const edge = neighbours[index];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function makeCap(node, edge, thickness, type) {
|
|
63
|
-
const result = [];
|
|
64
|
-
//get direction
|
|
65
|
-
const other = edge.other(node);
|
|
66
|
-
const first = node.clone();
|
|
67
|
-
const second = other.clone();
|
|
68
|
-
const delta = second.clone().sub(first);
|
|
69
|
-
const inverseDelta = delta.clone();
|
|
70
|
-
//
|
|
71
|
-
inverseDelta.x = delta.y;
|
|
72
|
-
inverseDelta.y = -delta.x;
|
|
73
|
-
|
|
74
|
-
inverseDelta.normalize();
|
|
75
|
-
//projecting cap
|
|
76
|
-
if (type === "projecting") {
|
|
77
|
-
const half_thickness = thickness / 2;
|
|
78
|
-
const sid = inverseDelta.clone().multiplyScalar(half_thickness);
|
|
79
|
-
//projecting offset
|
|
80
|
-
const offset = delta.clone().normalize().multiplyScalar(half_thickness);
|
|
81
|
-
const anchor = node.clone().sub(offset);
|
|
82
|
-
result.push(sid.clone().add(anchor));
|
|
83
|
-
result.push(sid.negate().add(anchor));
|
|
84
|
-
}
|
|
85
|
-
return result;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function makeJoint2(node, edges, thickness) {
|
|
89
|
-
const result = [];
|
|
90
|
-
//sort edges by angle
|
|
91
|
-
edges.sort(angleDifference);
|
|
92
|
-
|
|
93
|
-
for (let i = 0; i < edges.length; i++) {
|
|
94
|
-
const j = (i + 1) % edges.length;
|
|
95
|
-
const edge1 = edges[i];
|
|
96
|
-
const edge2 = edges[j];
|
|
97
|
-
const sum = pointBetweenEdges(edge1, edge2, node, thickness);
|
|
98
|
-
result.push({
|
|
99
|
-
point: sum,
|
|
100
|
-
edges: [edge1, edge2]
|
|
101
|
-
})
|
|
102
|
-
}
|
|
103
|
-
result.forEach(function (element) {
|
|
104
|
-
element.point.add(node);
|
|
105
|
-
});
|
|
106
|
-
return result;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function graph2paths(graph, thickness) {
|
|
110
|
-
const points = [];
|
|
111
|
-
const nodes = graph.nodes;
|
|
112
|
-
//generating outline points
|
|
113
|
-
for (let i = 0; i < nodes.length; i++) {
|
|
114
|
-
const node = nodes[i];
|
|
115
|
-
const attachedEdges = graph.getAttachedEdges(node);
|
|
116
|
-
const length = attachedEdges.length;
|
|
117
|
-
if (length === 0) {
|
|
118
|
-
//this node is not attached to any edge
|
|
119
|
-
console.warn("unconnected node, not representable");
|
|
120
|
-
} else if (length === 1) {
|
|
121
|
-
//this is an end point
|
|
122
|
-
const attachedEdge = attachedEdges[0];
|
|
123
|
-
const cap = makeCap(node, attachedEdge, thickness, "projecting");
|
|
124
|
-
cap.forEach(function (point) {
|
|
125
|
-
points.push({ node: node, edges: [attachedEdge], position: point });
|
|
126
|
-
});
|
|
127
|
-
} else if (length > 1) {
|
|
128
|
-
//this is a joint
|
|
129
|
-
const joint = makeJoint2(node, attachedEdges, thickness, null);
|
|
130
|
-
joint.forEach(function (data) {
|
|
131
|
-
points.push({ node: node, edges: data.edges, position: data.point })
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
let path;
|
|
136
|
-
|
|
137
|
-
function getCommonEdge(point1, point2) {
|
|
138
|
-
const edges1 = point1.edges;
|
|
139
|
-
const edges2 = point2.edges;
|
|
140
|
-
const l1 = edges1.length;
|
|
141
|
-
const l2 = edges2.length;
|
|
142
|
-
for (let i = 0; i < l1; i++) {
|
|
143
|
-
const edge1 = edges1[i];
|
|
144
|
-
for (let j = 0; j < l2; j++) {
|
|
145
|
-
const edge2 = edges2[j];
|
|
146
|
-
if (edge1 === edge2) {
|
|
147
|
-
return edge1;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
return null;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function lineIntersectsGraph(from, to, graph) {
|
|
155
|
-
const edges = graph.edges;
|
|
156
|
-
let i = 0;
|
|
157
|
-
const l = edges.length;
|
|
158
|
-
for (; i < l; i++) {
|
|
159
|
-
const edge = edges[i];
|
|
160
|
-
if (line_segment_compute_line_segment_intersection_vectors_array_2d(from, to, edge.first, edge.second)) {
|
|
161
|
-
return true;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return false;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function getNextPoint2(from) {
|
|
168
|
-
//filter points based on common edge
|
|
169
|
-
const edges0 = from.edges;
|
|
170
|
-
const l0 = edges0.length;
|
|
171
|
-
const candidates = [];
|
|
172
|
-
points.forEach(function (point, index) {
|
|
173
|
-
const edges1 = point.edges;
|
|
174
|
-
const l1 = edges1.length;
|
|
175
|
-
for (let i = 0; i < l0; i++) {
|
|
176
|
-
const e0 = edges0[i];
|
|
177
|
-
for (let j = 0; j < l1; j++) {
|
|
178
|
-
const e1 = edges1[j];
|
|
179
|
-
if (e0 === e1) {
|
|
180
|
-
//now filter out those that cross the graph
|
|
181
|
-
if (!lineIntersectsGraph(from.position, point.position, graph)) {
|
|
182
|
-
candidates.push(index);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
if (candidates.length > 0) {
|
|
189
|
-
const index = candidates[0];
|
|
190
|
-
const point = points[index];
|
|
191
|
-
points.splice(index, 1);
|
|
192
|
-
return point;
|
|
193
|
-
} else {
|
|
194
|
-
console.warn("No next point from ", from);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function getNextPoint(from) {
|
|
200
|
-
for (let i = 0; i < points.length; i++) {
|
|
201
|
-
const p = points[i];
|
|
202
|
-
const commonEdge = getCommonEdge(p, from);
|
|
203
|
-
if (commonEdge != null) {
|
|
204
|
-
//make sure line would not intersect the edge
|
|
205
|
-
// var intersects = getLineIntersection(p.position, from.position, commonEdge.first, commonEdge.second);
|
|
206
|
-
const intersects = lineIntersectsGraph(p.position, from.position, graph);
|
|
207
|
-
if (intersects) {
|
|
208
|
-
continue;
|
|
209
|
-
}
|
|
210
|
-
points.splice(i, 1);
|
|
211
|
-
return p;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
console.warn("No next point from", from);
|
|
215
|
-
return null;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
function trace() {
|
|
219
|
-
//pick a point
|
|
220
|
-
let currentPoint = points.pop();
|
|
221
|
-
let nextPoint;
|
|
222
|
-
path.moveTo(currentPoint.position.x, currentPoint.position.y);
|
|
223
|
-
// console.log("path.moveTo("+currentPoint.position.x+","+currentPoint.position.y+");");
|
|
224
|
-
const firstPoint = currentPoint;
|
|
225
|
-
for (nextPoint = getNextPoint2(currentPoint); nextPoint != null; nextPoint = getNextPoint2(currentPoint)) {
|
|
226
|
-
path.lineTo(nextPoint.position.x, nextPoint.position.y);
|
|
227
|
-
// console.log("path.lineTo("+nextPoint.position.x+","+nextPoint.position.y+");");
|
|
228
|
-
currentPoint = nextPoint;
|
|
229
|
-
}
|
|
230
|
-
path.lineTo(firstPoint.position.x, firstPoint.position.y);
|
|
231
|
-
// console.log("path.lineTo("+firstPoint.position.x+","+firstPoint.position.y+");");
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
const paths = [];
|
|
235
|
-
while (points.length > 0) {
|
|
236
|
-
path = new THREE.Path();
|
|
237
|
-
trace();
|
|
238
|
-
paths.push(path);
|
|
239
|
-
}
|
|
240
|
-
return paths;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
function graph2rects(graph, thickness) {
|
|
244
|
-
const edges = graph.edges;
|
|
245
|
-
const paths = [];
|
|
246
|
-
for (let i = 0; i < edges.length; i++) {
|
|
247
|
-
const path = new THREE.Path();
|
|
248
|
-
const edge = edges[i];
|
|
249
|
-
//outline edge
|
|
250
|
-
const cap1 = makeCap(edge.first, edge, thickness, "projecting");
|
|
251
|
-
const cap2 = makeCap(edge.second, edge, thickness, "projecting");
|
|
252
|
-
const points = cap1.concat(cap2);
|
|
253
|
-
let point = points[0];
|
|
254
|
-
path.moveTo(point.x, point.y);
|
|
255
|
-
let j = 1;
|
|
256
|
-
const l = points.length;
|
|
257
|
-
for (; j < l + 1; j++) {
|
|
258
|
-
point = points[j % l];
|
|
259
|
-
path.lineTo(point.x, point.y);
|
|
260
|
-
}
|
|
261
|
-
paths.push(path);
|
|
262
|
-
}
|
|
263
|
-
return paths;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
Utils.makeJoint2 = makeJoint2;
|
|
267
|
-
|
|
268
|
-
Utils.paths2shapes = function (paths) {
|
|
269
|
-
const shapes = [];
|
|
270
|
-
paths.forEach(function (path) {
|
|
271
|
-
const r = path.toShapes();
|
|
272
|
-
Array.prototype.push.apply(shapes, r);
|
|
273
|
-
});
|
|
274
|
-
return shapes;
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
Utils.graph2shapes = function (graph, thickness) {
|
|
278
|
-
const paths = Utils.graph2paths(graph, thickness);
|
|
279
|
-
return Utils.paths2shapes(paths);
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
Utils.graph2paths = graph2paths;
|
|
283
|
-
|
|
284
|
-
export default Utils;
|