@woosh/meep-engine 2.52.0 → 2.54.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/editor/actions/concrete/WriteGridValueAction.js +1 -1
- package/editor/ecs/component/prototypeObjectEditor.js +1 -1
- package/editor/process/ObstacleGridDisplayProcess.js +2 -2
- package/editor/process/symbolic/makeGridPositionSymbolDisplay.js +1 -1
- package/editor/tools/GridPaintTool.js +2 -2
- package/package.json +4 -3
- package/samples/generation/SampleGenerator0.js +1 -1
- package/samples/generation/generators/interactive/mir_generator_place_buff_objects.js +1 -1
- package/samples/generation/generators/mir_generator_place_bases.js +1 -1
- package/samples/generation/generators/mir_generator_place_road_decorators.js +1 -1
- package/samples/generation/generators/mir_generator_place_starting_point.js +1 -1
- package/samples/generation/main.js +2 -2
- package/samples/generation/rules/matcher_play_area.js +1 -1
- package/samples/generation/rules/matcher_tag_occupied.js +1 -1
- package/samples/generation/rules/matcher_tag_traversable.js +1 -1
- package/samples/generation/themes/SampleTheme0.js +5 -5
- package/src/core/collection/table/RowFirstTableSpec.js +8 -4
- package/src/core/geom/3d/matrix/MATRIX_4_IDENTITY.spec.js +10 -0
- package/src/engine/Engine.spec.js +4 -0
- package/src/engine/EngineConfiguration.js +24 -25
- package/src/engine/ecs/EntityBlueprint.js +2 -4
- package/src/engine/ecs/EntityComponentDataset.js +1 -1
- package/src/engine/ecs/EntityComponentDataset.spec.js +77 -0
- package/src/engine/ecs/EntityObserver.spec.js +1 -1
- package/src/engine/ecs/dynamic_actions/actions/definition/{WhiteToBlackboardActionDescription.js → WriteToBlackboardActionDescription.js} +2 -2
- package/src/engine/ecs/dynamic_actions/actions/definition/deserializeActionFromJSON.js +2 -2
- package/src/engine/ecs/guid/GUIDSerializationAdapter.spec.js +21 -0
- package/src/engine/ecs/parent/EntityNode.js +1 -1
- package/src/engine/ecs/parent/EntityNode.spec.js +104 -0
- package/src/engine/ecs/speaker/Voice.js +4 -0
- package/src/engine/ecs/team/Team.js +0 -44
- package/src/engine/ecs/team/TeamSerializationAdapter.js +46 -0
- package/src/engine/ecs/terrain/overlay/TerrainOverlay.spec.js +6 -0
- package/src/engine/ecs/terrain/tiles/TerrainTile.js +79 -76
- package/src/engine/ecs/terrain/tiles/TerrainTile.spec.js +25 -0
- package/src/engine/ecs/transform/Transform.js +1 -1
- package/src/engine/ecs/transform/Transform.spec.js +24 -0
- package/src/engine/graphics/camera/testClippingPlaneComputation.js +2 -2
- package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +2 -2
- package/src/engine/graphics/ecs/water2/shader/testWaterShader.js +2 -2
- package/src/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +2 -2
- package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +2 -2
- package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +2 -2
- package/src/engine/graphics/texture/TextureBackedMemoryRegion.js +4 -1
- package/src/engine/graphics/texture/sampler/filter/filter_lanczos3.js +7 -2
- package/src/engine/grid/{components → grid2transform}/GridPosition2Transform.js +0 -41
- package/src/engine/grid/grid2transform/GridPosition2TransformSerializationUpgrader_0_1.js +40 -0
- package/src/engine/grid/{systems → grid2transform}/GridPosition2TransformSystem.js +3 -3
- package/src/engine/grid/{components → position}/GridPosition.js +4 -0
- package/src/engine/grid/{systems → position}/GridPositionSystem.js +1 -1
- package/src/engine/grid/transform2grid/Transform2GridPositionSystem.js +1 -1
- package/src/engine/input/devices/PointerDevice.spec.js +5 -0
- package/src/engine/navigation/ecs/components/computeCatmullRomSpline.js +5 -1
- package/src/engine/navigation/ecs/path_following/PathFollower.js +40 -32
- package/src/engine/navigation/ecs/path_following/PathFollower.spec.js +27 -0
- package/src/engine/platform/EnginePlatform.js +0 -4
- package/src/generation/filtering/CellFilter.js +6 -9
- package/src/generation/filtering/boolean/CellFilterLiteralBoolean.js +1 -4
- package/src/generation/filtering/core/CellFilterBinaryOperation.js +12 -15
- package/src/generation/filtering/core/CellFilterOperationTertiary.js +15 -19
- package/src/generation/filtering/numeric/CellFilterLiteralFloat.js +6 -9
- package/src/generation/grid/actions/ContinuousGridCellActionSetTerrainObstacle.js +1 -1
- package/src/generation/grid/actions/ContinuousGridCellActionWriteObstacle.js +2 -2
- package/src/generation/grid/generation/road/GridTaskGenerateRoads.js +1 -1
- package/src/generation/markers/actions/MarkerNodeActionEntityPlacement.js +1 -1
- package/src/engine/InputEngine.js +0 -94
- package/src/engine/PointerLock.js +0 -60
- package/src/engine/ecs/terrain/ecs/layers/loadLegacyTerrainLayers.js +0 -99
- package/src/engine/ecs/terrain/ecs/splat/loadLegacyTerrainSplats.js +0 -73
- package/src/engine/graphics/texture/ExportCanvasAsPNG.js +0 -7
- package/src/engine/navigation/PathFinder.js +0 -172
- package/src/engine/navigation/PathWorker.js +0 -78
- package/src/engine/navigation/ecs/systems/PathFinderSystem.js +0 -63
- package/src/engine/navigation/ecs/systems/PathSystem.js +0 -19
- package/src/engine/navigation/funnel/Funnel.js +0 -196
- package/src/generation/ZoneNode.js +0 -9
- /package/{src/generation → samples/generation/grid}/GridTags.js +0 -0
- /package/src/engine/grid/{components → grid2transform}/GridPosition2TransformFlags.js +0 -0
- /package/src/engine/grid/{components → grid2transform}/GridPosition2TransformSerializationAdapter.js +0 -0
- /package/src/engine/grid/{components → obstacle}/GridObstacle.js +0 -0
- /package/src/engine/grid/{components → obstacle}/GridObstacle.spec.js +0 -0
- /package/src/engine/grid/{components → obstacle}/GridObstacleSerializationAdapter.js +0 -0
- /package/src/engine/grid/{components → position}/GridPositionSerializationAdapter.js +0 -0
- /package/src/engine/grid/{components → position}/GridPositionSerializationUpdater_0_1.js +0 -0
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 03/02/14.
|
|
3
|
-
*/
|
|
4
|
-
import Vector3 from '../physics/Vector3';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* PathFinder uses a worker to allow asynchronous path finding, freeing up resources for rendering and game logic
|
|
9
|
-
* @constructor
|
|
10
|
-
*/
|
|
11
|
-
const PathFinder = function (readyCallback) {
|
|
12
|
-
const self = this;
|
|
13
|
-
this.__pathTimout = 10000;
|
|
14
|
-
const callbacks = this.callbacks = [];
|
|
15
|
-
|
|
16
|
-
this.worker = new Worker("src/model/navigation/PathWorker.js");
|
|
17
|
-
const api = {
|
|
18
|
-
meshBuilt: function (options) {
|
|
19
|
-
console.warn("mesh built");
|
|
20
|
-
self.__pathTimout = 500;
|
|
21
|
-
},
|
|
22
|
-
pathFound: function (options) {
|
|
23
|
-
const data = options.map(function (v) {
|
|
24
|
-
return new Vector3(v.x, 0, v.y);
|
|
25
|
-
});
|
|
26
|
-
//remove first callback from the queue
|
|
27
|
-
const callback = callbacks.shift();
|
|
28
|
-
//invoke the callback
|
|
29
|
-
if (callback) {
|
|
30
|
-
callback(data);
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
workerReady: function () {
|
|
34
|
-
if (readyCallback !== void 0) {
|
|
35
|
-
readyCallback();
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
const onmessage = function onmessage(event) {
|
|
40
|
-
const data = event.data;
|
|
41
|
-
const method = api[data.method];
|
|
42
|
-
if (method) {
|
|
43
|
-
method.call(api, data.options);
|
|
44
|
-
} else {
|
|
45
|
-
console.error("method '" + data.method + "' is not a supported");
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
const onerror = function onerror(event) {
|
|
49
|
-
console.error("PathFinder error: ", event);
|
|
50
|
-
//bail all pending callbacks
|
|
51
|
-
self.callbacks.forEach(function (callback) {
|
|
52
|
-
callback(void 0);
|
|
53
|
-
});
|
|
54
|
-
self.callbacks = [];
|
|
55
|
-
//restart the worker
|
|
56
|
-
self.worker = new Worker("src/model/navigation/PathWorker.js");
|
|
57
|
-
self.worker.onmessage = onmessage;
|
|
58
|
-
self.worker.onerror = onerror;
|
|
59
|
-
//bump up timeout until mesh is built
|
|
60
|
-
self.__pathTimout = 2000;
|
|
61
|
-
self.worker.postMessage({ method: "buildMesh", options: self.__buildMeshData });
|
|
62
|
-
};
|
|
63
|
-
this.worker.onmessage = onmessage;
|
|
64
|
-
this.worker.onerror = onerror;
|
|
65
|
-
|
|
66
|
-
};
|
|
67
|
-
PathFinder.prototype.destroyMesh = function () {
|
|
68
|
-
this.worker.postMessage({ method: "destroyMesh" });
|
|
69
|
-
};
|
|
70
|
-
/**
|
|
71
|
-
* Construct navigation mesh
|
|
72
|
-
* @param {Object} groundSize
|
|
73
|
-
* @param {Walls} walls
|
|
74
|
-
*/
|
|
75
|
-
PathFinder.prototype.buildMesh = function (groundSize, walls) {
|
|
76
|
-
// destroy old mesh
|
|
77
|
-
// this.destroyMesh();
|
|
78
|
-
|
|
79
|
-
function transformTo2D(vertex) {
|
|
80
|
-
return { x: vertex.x, y: vertex.y };
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const constrains = [];
|
|
84
|
-
// walls.shapes.forEach(function (shape) {
|
|
85
|
-
// constrains.push(shape.makeGeometry().vertices.map(function (vertex) {
|
|
86
|
-
// return transformTo2D(vertex);
|
|
87
|
-
// }));
|
|
88
|
-
// });
|
|
89
|
-
walls.paths.forEach(function (path) {
|
|
90
|
-
if (path !== void 0) {
|
|
91
|
-
const points = path.actions.map(function (item) {
|
|
92
|
-
let type = item.action;
|
|
93
|
-
const args = item.args;
|
|
94
|
-
return { x: args[0], y: args[1] };
|
|
95
|
-
});
|
|
96
|
-
constrains.push(points);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
let minX = Number.MAX_VALUE, minY = Number.MAX_VALUE, maxX = Number.MIN_VALUE, maxY = Number.MIN_VALUE;
|
|
100
|
-
constrains.forEach(function (polygon) {
|
|
101
|
-
polygon.forEach(function (point) {
|
|
102
|
-
minX = minX > point.x ? point.x : minX;
|
|
103
|
-
minY = minY > point.y ? point.y : minY;
|
|
104
|
-
maxX = maxX < point.x ? point.x : maxX;
|
|
105
|
-
maxY = maxY < point.y ? point.y : maxY;
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
const buffer = 20; // TODO Calculate the right world map boundary
|
|
109
|
-
minX -= buffer;
|
|
110
|
-
minY -= buffer;
|
|
111
|
-
maxX += buffer;
|
|
112
|
-
maxY += buffer;
|
|
113
|
-
const boundary = [
|
|
114
|
-
{ x: minX, y: minY },
|
|
115
|
-
{ x: minX, y: maxY },
|
|
116
|
-
{ x: maxX, y: maxY },
|
|
117
|
-
{ x: maxX, y: minY }
|
|
118
|
-
];
|
|
119
|
-
|
|
120
|
-
const data = this.__buildMeshData = { boundary: boundary, constrains: constrains };
|
|
121
|
-
//bump up timeout until mesh is built
|
|
122
|
-
this.__pathTimout = 2000;
|
|
123
|
-
this.worker.postMessage({ method: "buildMesh", options: data });
|
|
124
|
-
// Lct.init(data.boundary);
|
|
125
|
-
// Lct.insertPolygons(data.constrains);
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
function vector3to2DJSON(v) {
|
|
129
|
-
// return {x: v.x, y: v.y, z: v.z};
|
|
130
|
-
return { x: v.x, y: v.z };
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
PathFinder.prototype.findPath = function (start, goal, clearance, callback) {
|
|
134
|
-
//start timer so we can bail out if path is not found
|
|
135
|
-
let timer;
|
|
136
|
-
|
|
137
|
-
function wrappedCallback(arg) {
|
|
138
|
-
clearTimeout(timer);
|
|
139
|
-
callback(arg);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const callbacks = this.callbacks;
|
|
143
|
-
callbacks.push(wrappedCallback);
|
|
144
|
-
const options = {
|
|
145
|
-
start: vector3to2DJSON(start),
|
|
146
|
-
goal: vector3to2DJSON(goal),
|
|
147
|
-
clearance: clearance
|
|
148
|
-
};
|
|
149
|
-
this.worker.postMessage({ method: "findPath", options: options });
|
|
150
|
-
//start timer so we can bail out if path is not found
|
|
151
|
-
timer = setTimeout(function bail() {
|
|
152
|
-
const index = callbacks.indexOf(wrappedCallback);
|
|
153
|
-
callbacks.splice(index, 1, function overdue() {
|
|
154
|
-
//the response is overdue, but it has arrived. do nothing
|
|
155
|
-
});
|
|
156
|
-
//call callback with BadNews(tm)
|
|
157
|
-
callback(void 0);
|
|
158
|
-
}, this.__pathTimout);
|
|
159
|
-
|
|
160
|
-
// var startTime = Date.now();
|
|
161
|
-
// var path = Lct.getPath(options.start, options.goal, options.clearance);
|
|
162
|
-
// var endTime = Date.now();
|
|
163
|
-
// console.log("found path in " + (endTime - startTime) + "ms");
|
|
164
|
-
// var data = path.vectors.map(function (v) {
|
|
165
|
-
// return new Vector3(v.x, 0, v.y);
|
|
166
|
-
// });
|
|
167
|
-
// //invoke the callback
|
|
168
|
-
// if (callback) {
|
|
169
|
-
// callback(data);
|
|
170
|
-
// }
|
|
171
|
-
};
|
|
172
|
-
export default PathFinder;
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
importScripts('../../../lib/require.src', '../../../lib/three.src');
|
|
2
|
-
|
|
3
|
-
const onMessageActual = null;
|
|
4
|
-
const deferredMessages = [];
|
|
5
|
-
|
|
6
|
-
require(
|
|
7
|
-
{
|
|
8
|
-
baseUrl: ".",
|
|
9
|
-
paths: {
|
|
10
|
-
model: '../../model',
|
|
11
|
-
lib: '../../../lib'
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
[
|
|
15
|
-
'lib/lct/lct-built'
|
|
16
|
-
],
|
|
17
|
-
function (Lct) {
|
|
18
|
-
|
|
19
|
-
const pathQueue = [];
|
|
20
|
-
const initialized = false;
|
|
21
|
-
const api = {
|
|
22
|
-
destroyMesh: function (options) {
|
|
23
|
-
Lct.reset();
|
|
24
|
-
initialized = false;
|
|
25
|
-
},
|
|
26
|
-
buildMesh: function (initData) {
|
|
27
|
-
Lct.init(initData.boundary);
|
|
28
|
-
Lct.insertPolygons(initData.constrains);
|
|
29
|
-
initialized = true;
|
|
30
|
-
postMessage({ method: "meshBuilt" });
|
|
31
|
-
//execute path finding for all deferred requests
|
|
32
|
-
while (pathQueue.length > 0) {
|
|
33
|
-
const pathArgs = pathQueue.shift();
|
|
34
|
-
api.findPath(pathArgs);
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
findPath: function (options) {
|
|
38
|
-
if (!initialized) {
|
|
39
|
-
//queue up
|
|
40
|
-
pathQueue.push(options);
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
const start = options.start;
|
|
44
|
-
const goal = options.goal;
|
|
45
|
-
const clearance = options.clearance;
|
|
46
|
-
|
|
47
|
-
let startTime = Date.now();
|
|
48
|
-
let path;
|
|
49
|
-
path = Lct.getPath(start, goal, clearance);
|
|
50
|
-
let endTime = Date.now();
|
|
51
|
-
// console.log("found path[" + path.vectors.length + "] from " + JSON.stringify(start) + " to " + JSON.stringify(goal) + " of clearance " + clearance + " in " + (endTime - startTime) + "ms");
|
|
52
|
-
postMessage({ method: "pathFound", options: path.vectors });
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
onMessageActual = function (message) {
|
|
56
|
-
const data = message.data;
|
|
57
|
-
const method = api[data.method];
|
|
58
|
-
if (method) {
|
|
59
|
-
method.call(api, data.options);
|
|
60
|
-
} else {
|
|
61
|
-
console.error("method '" + data.method + "' is not a supported");
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
console.log("path worker started");
|
|
65
|
-
postMessage({ method: "workerReady", options: null });
|
|
66
|
-
//handle deferred messages
|
|
67
|
-
deferredMessages.forEach(onMessageActual);
|
|
68
|
-
}
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
onmessage = function (message) {
|
|
72
|
-
|
|
73
|
-
if (onMessageActual == null) {
|
|
74
|
-
deferredMessages.push(message);
|
|
75
|
-
} else {
|
|
76
|
-
onMessageActual(message);
|
|
77
|
-
}
|
|
78
|
-
};
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 11/08/2014.
|
|
3
|
-
*/
|
|
4
|
-
import { System } from '../../../ecs/System.js';
|
|
5
|
-
import { Transform } from '../../../ecs/transform/Transform.js';
|
|
6
|
-
import PathFinder from '../components/PathFinder.js';
|
|
7
|
-
import Navigator from '../../PathFinder.js';
|
|
8
|
-
import Vector3 from "../../../../core/geom/Vector3.js";
|
|
9
|
-
import Path from "../components/Path.js";
|
|
10
|
-
|
|
11
|
-
const v3 = new Vector3();
|
|
12
|
-
|
|
13
|
-
class PathFinderSystem extends System {
|
|
14
|
-
constructor() {
|
|
15
|
-
super();
|
|
16
|
-
this.dependencies = [PathFinder];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
startup(entityManager, readyCallback, errorCallback) {
|
|
20
|
-
this.entityManager = entityManager;
|
|
21
|
-
this.navigator = new Navigator();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
update(timeDelta) {
|
|
25
|
-
const entityManager = this.entityManager;
|
|
26
|
-
const nav = this.navigator;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
*
|
|
30
|
-
* @param {PathFinder} finder
|
|
31
|
-
* @param {Path} path
|
|
32
|
-
* @param {Transform} transform
|
|
33
|
-
* @param {number} entity
|
|
34
|
-
*/
|
|
35
|
-
function visitEntity(finder, path, transform, entity) {
|
|
36
|
-
|
|
37
|
-
const desination = finder.desination;
|
|
38
|
-
|
|
39
|
-
if (finder.finding === false) {
|
|
40
|
-
path.getPosition(path.getPointCount() - 1, v3);
|
|
41
|
-
|
|
42
|
-
//check if existing path is going to the destination
|
|
43
|
-
if (!v3.equals(desination)) {
|
|
44
|
-
|
|
45
|
-
finder.finding = true;
|
|
46
|
-
|
|
47
|
-
//find path
|
|
48
|
-
nav.findPath(transform.position, desination, 2, function (path) {
|
|
49
|
-
finder.finding = false;
|
|
50
|
-
|
|
51
|
-
path.setPositionsFromVectorArray(path);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
entityManager.traverseEntities([PathFinder, Path, Transform], visitEntity);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
export default PathFinderSystem;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 17/10/2016.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { System } from '../../../ecs/System.js';
|
|
7
|
-
import Path from '../components/Path.js';
|
|
8
|
-
|
|
9
|
-
class PathSystem extends System {
|
|
10
|
-
constructor() {
|
|
11
|
-
super();
|
|
12
|
-
this.dependencies = [Path];
|
|
13
|
-
//
|
|
14
|
-
this.entityManager = null;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export default PathSystem;
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 29/03/2014.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const EPSILON = 0.000001;
|
|
9
|
-
|
|
10
|
-
function triarea2(a, b, c) {
|
|
11
|
-
const ax = b.x - a.x;
|
|
12
|
-
const ay = b.y - a.y;
|
|
13
|
-
const bx = c.x - a.x;
|
|
14
|
-
const by = c.y - a.y;
|
|
15
|
-
|
|
16
|
-
return bx * ay - ax * by;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function vdistsqr(a, b) {
|
|
20
|
-
const x = b.x - a.x;
|
|
21
|
-
const y = b.y - a.y;
|
|
22
|
-
|
|
23
|
-
return x * x + y * y;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function vequal(a, b) {
|
|
27
|
-
return vdistsqr(a, b) < EPSILON;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function counterClockWise2(v0, v1, v2) {
|
|
31
|
-
const vs = [v0, v1, v2];
|
|
32
|
-
let a = 0;
|
|
33
|
-
for (let i = 0; i < 3; i++) {
|
|
34
|
-
const p0 = vs[i];
|
|
35
|
-
const p1 = vs[(i + 1) % 3];
|
|
36
|
-
a += (p1.x - p0.x) * (p1.y + p0.y);
|
|
37
|
-
}
|
|
38
|
-
return a < 0;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function counterClockWise(v0, v1, v2) {
|
|
42
|
-
|
|
43
|
-
const a = (v0.x + v1.x) * (v0.y - v1.y) + (v1.x + v2.x) * (v1.y - v2.y);
|
|
44
|
-
return a < 0;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function getOffsetVertex(prevPoint, currPoint, nextPoint, size) {
|
|
48
|
-
if (prevPoint == currPoint || currPoint == nextPoint) {
|
|
49
|
-
return new THREE.Vector2(currPoint.x, currPoint.y);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Calculate line angles.
|
|
53
|
-
const nextAngle = Math.atan2(nextPoint.y - currPoint.y, nextPoint.x - currPoint.x);
|
|
54
|
-
const prevAngle = Math.atan2(currPoint.y - prevPoint.y, currPoint.x - prevPoint.x);
|
|
55
|
-
|
|
56
|
-
// Calculate minimum distance between line angles.
|
|
57
|
-
let distance = nextAngle - prevAngle;
|
|
58
|
-
|
|
59
|
-
if (Math.abs(distance) > Math.PI) {
|
|
60
|
-
distance -= distance > 0 ? Math.PI * 2 : -Math.PI * 2;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Calculate left perpendicular to average angle.
|
|
64
|
-
const angle = prevAngle + (distance / 2) + (Math.PI / 2);
|
|
65
|
-
const normal = new THREE.Vector2(Math.cos(angle), Math.sin(angle));
|
|
66
|
-
|
|
67
|
-
return normal.multiplyScalar(size).add(new THREE.Vector2(currPoint.x, currPoint.y));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function getPrev(list, currentIndex) {
|
|
71
|
-
let prev = currentIndex;
|
|
72
|
-
|
|
73
|
-
for (let i = prev; i >= 0; i--) {
|
|
74
|
-
if (list[i] != list[prev]) {
|
|
75
|
-
prev = i;
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return prev;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function getNext(list, currentIndex) {
|
|
84
|
-
let next = currentIndex;
|
|
85
|
-
|
|
86
|
-
for (let i = next; i < list.length; i++) {
|
|
87
|
-
if (list[i] != list[next]) {
|
|
88
|
-
next = i;
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return next;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function Channel() {
|
|
97
|
-
this.portals = [];
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
Channel.prototype.push = function (p1, p2) {
|
|
101
|
-
if (p2 === undefined) p2 = p1;
|
|
102
|
-
this.portals.push({ left: p1, right: p2 });
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
Channel.prototype.fixLeftRight = function () {
|
|
106
|
-
for (let i = 1; i < this.portals.length; i++) {
|
|
107
|
-
const previous = this.portals[i - 1];
|
|
108
|
-
const current = this.portals[i];
|
|
109
|
-
let ccw = counterClockWise2(previous.right, current.right, current.left);
|
|
110
|
-
if (!ccw) {
|
|
111
|
-
const t = current.left;
|
|
112
|
-
//swap
|
|
113
|
-
current.left = current.right;
|
|
114
|
-
current.right = t;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
Channel.prototype.stringPull = function (agentSize) {
|
|
120
|
-
const size = agentSize || 0;
|
|
121
|
-
const portals = this.portals;
|
|
122
|
-
const pts = [];
|
|
123
|
-
// Init scan state
|
|
124
|
-
let portalApex, portalLeft, portalRight;
|
|
125
|
-
let apexIndex = 0, leftIndex = 0, rightIndex = 0;
|
|
126
|
-
|
|
127
|
-
portalApex = portals[0].left;
|
|
128
|
-
portalLeft = portals[0].left;
|
|
129
|
-
portalRight = portals[0].right;
|
|
130
|
-
|
|
131
|
-
// Add start point.
|
|
132
|
-
pts.push(portalApex);
|
|
133
|
-
|
|
134
|
-
for (let i = 1; i < portals.length; i++) {
|
|
135
|
-
const left = portals[i].left;
|
|
136
|
-
const right = portals[i].right;
|
|
137
|
-
|
|
138
|
-
// Update right vertex.
|
|
139
|
-
if (triarea2(portalApex, portalRight, right) <= 0.0) {
|
|
140
|
-
if (vequal(portalApex, portalRight) || triarea2(portalApex, portalLeft, right) > 0.0) {
|
|
141
|
-
// Tighten the funnel.
|
|
142
|
-
portalRight = right;
|
|
143
|
-
rightIndex = i;
|
|
144
|
-
} else {
|
|
145
|
-
// Right over left, insert left to path and restart scan from portal left point.
|
|
146
|
-
const offsetLeftVertex = getOffsetVertex(portals[getPrev(portals, leftIndex)].left, portalLeft, portals[getNext(portals, leftIndex)].left, size);
|
|
147
|
-
pts.push({ x: offsetLeftVertex.x, y: offsetLeftVertex.y });
|
|
148
|
-
// Make current left the new apex.
|
|
149
|
-
portalApex = portalLeft;
|
|
150
|
-
apexIndex = leftIndex;
|
|
151
|
-
// Reset portal
|
|
152
|
-
portalLeft = portalApex;
|
|
153
|
-
portalRight = portalApex;
|
|
154
|
-
leftIndex = apexIndex;
|
|
155
|
-
rightIndex = apexIndex;
|
|
156
|
-
// Restart scan
|
|
157
|
-
i = apexIndex;
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// Update left vertex.
|
|
163
|
-
if (triarea2(portalApex, portalLeft, left) >= 0.0) {
|
|
164
|
-
if (vequal(portalApex, portalLeft) || triarea2(portalApex, portalRight, left) < 0.0) {
|
|
165
|
-
// Tighten the funnel.
|
|
166
|
-
portalLeft = left;
|
|
167
|
-
leftIndex = i;
|
|
168
|
-
} else {
|
|
169
|
-
// Left over right, insert right to path and restart scan from portal right point.
|
|
170
|
-
const offsetRightVertex = getOffsetVertex(portals[getPrev(portals, rightIndex)].right, portalRight, portals[getNext(portals, rightIndex)].right, size);
|
|
171
|
-
pts.push({ x: offsetRightVertex.x, y: offsetRightVertex.y });
|
|
172
|
-
// Make current right the new apex.
|
|
173
|
-
portalApex = portalRight;
|
|
174
|
-
apexIndex = rightIndex;
|
|
175
|
-
// Reset portal
|
|
176
|
-
portalLeft = portalApex;
|
|
177
|
-
portalRight = portalApex;
|
|
178
|
-
leftIndex = apexIndex;
|
|
179
|
-
rightIndex = apexIndex;
|
|
180
|
-
// Restart scan
|
|
181
|
-
i = apexIndex;
|
|
182
|
-
continue;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if ((pts.length == 0) || (!vequal(pts[pts.length - 1], portals[portals.length - 1].left))) {
|
|
188
|
-
// Append last point to path.
|
|
189
|
-
pts.push(portals[portals.length - 1].left);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
this.path = pts;
|
|
193
|
-
return pts;
|
|
194
|
-
};
|
|
195
|
-
export default Channel;
|
|
196
|
-
|
|
File without changes
|
|
File without changes
|
/package/src/engine/grid/{components → grid2transform}/GridPosition2TransformSerializationAdapter.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|