@woosh/meep-engine 2.51.0 → 2.53.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.
Files changed (160) hide show
  1. package/editor/actions/concrete/WriteGridValueAction.js +1 -1
  2. package/editor/ecs/component/prototypeObjectEditor.js +1 -1
  3. package/editor/process/ObstacleGridDisplayProcess.js +2 -2
  4. package/editor/process/symbolic/makeGridPositionSymbolDisplay.js +1 -1
  5. package/editor/tools/GridPaintTool.js +2 -2
  6. package/package.json +4 -3
  7. package/samples/generation/SampleGenerator0.js +1 -1
  8. package/samples/generation/generators/interactive/mir_generator_place_buff_objects.js +1 -1
  9. package/samples/generation/generators/mir_generator_place_bases.js +1 -1
  10. package/samples/generation/generators/mir_generator_place_road_decorators.js +1 -1
  11. package/samples/generation/generators/mir_generator_place_starting_point.js +1 -1
  12. package/samples/generation/main.js +2 -2
  13. package/samples/generation/rules/matcher_play_area.js +1 -1
  14. package/samples/generation/rules/matcher_tag_occupied.js +1 -1
  15. package/samples/generation/rules/matcher_tag_traversable.js +1 -1
  16. package/samples/generation/themes/SampleTheme0.js +5 -5
  17. package/src/core/NumberFormat.js +0 -71
  18. package/src/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js +1 -0
  19. package/src/core/bvh2/bvh3/query/BVHQueryAny.js +16 -0
  20. package/src/core/bvh2/bvh3/query/bvh_collect_user_data.js +5 -5
  21. package/src/core/bvh2/bvh3/query/bvh_query_leaves_generic.js +2 -3
  22. package/src/core/bvh2/bvh3/query/bvh_query_leaves_generic.spec.js +22 -0
  23. package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray.js +2 -2
  24. package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray.spec.js +64 -0
  25. package/src/core/bvh2/bvh3/query/bvh_query_user_data_generic.js +2 -3
  26. package/src/core/collection/table/RowFirstTableSpec.js +8 -4
  27. package/src/core/geom/3d/aabb/aabb3_from_threejs_geometry.js +41 -0
  28. package/src/core/geom/3d/matrix/MATRIX_4_IDENTITY.spec.js +10 -0
  29. package/src/core/geom/3d/topology/struct/TopoMesh.js +3 -2
  30. package/src/core/geom/3d/topology/struct/prototypeBinaryTopology.js +4 -4
  31. package/src/core/geom/Vector2.d.ts +9 -0
  32. package/src/core/geom/Vector2.js +8 -22
  33. package/src/core/geom/Vector2.spec.js +153 -0
  34. package/src/core/model/ModuleRegistry.js +2 -4
  35. package/src/core/model/ModuleRegistry.spec.js +31 -0
  36. package/src/core/model/reactive/js/compileReactiveToJS.spec.js +14 -0
  37. package/src/core/model/reactive/model/logic/ReactiveAnd.spec.js +31 -1
  38. package/src/core/model/reactive/model/logic/ReactiveOr.spec.js +53 -0
  39. package/src/core/model/stat/LinearModifier.js +2 -2
  40. package/src/core/model/stat/LinearModifier.spec.js +62 -0
  41. package/src/core/model/stat/Stat.js +12 -0
  42. package/src/core/model/stat/Stat.spec.js +36 -0
  43. package/src/core/primitives/array/computeStridedIntegerArrayHash.spec.js +28 -0
  44. package/src/core/primitives/numbers/number_format_by_thousands.js +14 -0
  45. package/src/core/primitives/numbers/number_pretty_print.js +49 -0
  46. package/src/core/primitives/strings/computeStringHash.spec.js +12 -5
  47. package/src/core/process/BaseProcess.js +8 -8
  48. package/src/engine/Clock.js +30 -29
  49. package/src/engine/Clock.spec.js +26 -0
  50. package/src/engine/Engine.spec.js +4 -0
  51. package/src/engine/ecs/EntityBuilder.js +3 -1
  52. package/src/engine/ecs/EntityBuilder.spec.js +21 -0
  53. package/src/engine/ecs/EntityComponentDataset.js +1 -1
  54. package/src/engine/ecs/EntityObserver.spec.js +1 -1
  55. package/src/engine/ecs/dynamic_actions/actions/definition/{WhiteToBlackboardActionDescription.js → WriteToBlackboardActionDescription.js} +2 -2
  56. package/src/engine/ecs/dynamic_actions/actions/definition/deserializeActionFromJSON.js +2 -2
  57. package/src/engine/ecs/gui/GUIElement.js +1 -1
  58. package/src/engine/ecs/gui/position/ViewportPosition.js +3 -3
  59. package/src/engine/ecs/guid/GUIDSerializationAdapter.spec.js +21 -0
  60. package/src/engine/ecs/parent/EntityNode.js +1 -1
  61. package/src/engine/ecs/parent/EntityNode.spec.js +104 -0
  62. package/src/engine/ecs/speaker/Voice.js +4 -0
  63. package/src/engine/ecs/team/Team.js +0 -44
  64. package/src/engine/ecs/team/TeamSerializationAdapter.js +46 -0
  65. package/src/engine/ecs/terrain/ecs/TerrainClassifier.js +1 -1
  66. package/src/engine/ecs/terrain/ecs/layers/TerrainLayers.js +1 -1
  67. package/src/engine/ecs/transform/Transform.js +2 -1
  68. package/src/engine/ecs/transform/Transform.spec.js +24 -0
  69. package/src/engine/graphics/camera/testClippingPlaneComputation.js +2 -6
  70. package/src/engine/graphics/ecs/animation/animator/graph/AnimationGraph.spec.js +5 -0
  71. package/src/engine/graphics/ecs/animation/animator/graph/definition/AnimationGraphDefinition.js +24 -25
  72. package/src/engine/graphics/ecs/animation/animator/graph/definition/AnimationGraphDefinition.spec.js +5 -0
  73. package/src/engine/graphics/ecs/decal/DecalSystem.js +2 -20
  74. package/src/engine/graphics/ecs/decal/v2/Decal.js +32 -32
  75. package/src/engine/graphics/ecs/decal/v2/Decal.spec.js +5 -0
  76. package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +4 -2
  77. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +4 -33
  78. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +8 -4
  79. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMesh.spec.js +5 -0
  80. package/src/engine/graphics/ecs/mesh-v2/sample/prototypeShadedGeometry.js +0 -12
  81. package/src/engine/graphics/ecs/path/testPathDisplaySystem.js +0 -2
  82. package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +2 -6
  83. package/src/engine/graphics/ecs/water2/shader/testWaterShader.js +2 -4
  84. package/src/engine/graphics/geometry/buffered/computeBufferAttributeHash.js +1 -1
  85. package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +0 -2
  86. package/src/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +2 -6
  87. package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +2 -6
  88. package/src/engine/graphics/render/forward_plus/prototype/prototypeLightManager.js +2 -2
  89. package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +4 -8
  90. package/src/engine/graphics/sh3/path_tracer/GeometryBVHBatched.js +2 -1
  91. package/src/engine/graphics/sh3/path_tracer/PathTracer.js +6 -1
  92. package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +2 -2
  93. package/src/engine/graphics/shadows/testShadowMapRendering.js +0 -2
  94. package/src/engine/graphics/texture/TextureBackedMemoryRegion.js +4 -1
  95. package/src/engine/graphics/texture/sampler/Sampler2D.js +1 -1
  96. package/src/engine/graphics/texture/sampler/filter/filter_lanczos3.js +7 -2
  97. package/src/engine/graphics/three/expand_aabb_by_transformed_three_object.js +3 -23
  98. package/src/engine/grid/grid2transform/GridPosition2Transform.js +122 -0
  99. package/src/engine/grid/grid2transform/GridPosition2TransformSerializationAdapter.js +70 -0
  100. package/src/engine/grid/grid2transform/GridPosition2TransformSerializationUpgrader_0_1.js +40 -0
  101. package/src/engine/grid/{systems → grid2transform}/GridPosition2TransformSystem.js +3 -3
  102. package/src/engine/grid/{components → obstacle}/GridObstacle.js +45 -25
  103. package/src/engine/grid/obstacle/GridObstacle.spec.js +175 -0
  104. package/src/engine/grid/{components → position}/GridPosition.js +6 -14
  105. package/src/engine/grid/{systems → position}/GridPositionSystem.js +1 -1
  106. package/src/engine/grid/transform2grid/Transform2GridPositionSystem.js +1 -1
  107. package/src/engine/input/devices/PointerDevice.spec.js +5 -0
  108. package/src/engine/navigation/ecs/components/computeCatmullRomSpline.js +5 -1
  109. package/src/engine/navigation/ecs/path_following/PathFollower.js +40 -32
  110. package/src/engine/navigation/ecs/path_following/PathFollower.spec.js +27 -0
  111. package/src/engine/plugin/EnginePlugin.js +12 -14
  112. package/src/engine/plugin/EnginePlugin.spec.js +5 -0
  113. package/src/engine/plugin/EnginePluginManager.js +18 -22
  114. package/src/engine/scene/transitionToScene.js +12 -1
  115. package/src/engine/simulation/Ticker.js +1 -1
  116. package/src/generation/filtering/CellFilter.js +6 -9
  117. package/src/generation/filtering/boolean/CellFilterLiteralBoolean.js +1 -4
  118. package/src/generation/filtering/core/CellFilterBinaryOperation.js +12 -15
  119. package/src/generation/filtering/core/CellFilterOperationTertiary.js +15 -19
  120. package/src/generation/filtering/numeric/CellFilterLiteralFloat.js +6 -9
  121. package/src/generation/grid/actions/ContinuousGridCellActionSetTerrainObstacle.js +1 -1
  122. package/src/generation/grid/actions/ContinuousGridCellActionWriteObstacle.js +2 -2
  123. package/src/generation/grid/generation/road/GridTaskGenerateRoads.js +1 -1
  124. package/src/generation/markers/actions/MarkerNodeActionEntityPlacement.js +1 -1
  125. package/src/generation/theme/TerrainLayerDescription.js +1 -1
  126. package/src/view/common/LabelView.js +3 -3
  127. package/src/engine/ecs/components/AimController.js +0 -18
  128. package/src/engine/ecs/components/Attacker.js +0 -13
  129. package/src/engine/ecs/components/MeshCollider.js +0 -15
  130. package/src/engine/ecs/components/RangedAttack.js +0 -12
  131. package/src/engine/ecs/components/TargetAI.js +0 -11
  132. package/src/engine/ecs/components/ViewportMeshProjection.js +0 -18
  133. package/src/engine/ecs/systems/AimControllerSystem.js +0 -63
  134. package/src/engine/ecs/systems/AttackerSystem.js +0 -67
  135. package/src/engine/ecs/systems/MeshColliderSystem.js +0 -47
  136. package/src/engine/ecs/systems/MonsterAISystem.js +0 -163
  137. package/src/engine/ecs/systems/MortalitySystem.js +0 -46
  138. package/src/engine/ecs/systems/RangedAttackSystem.js +0 -132
  139. package/src/engine/ecs/systems/SerializationMetadataSystem.js +0 -10
  140. package/src/engine/ecs/systems/TargetAISystem.js +0 -107
  141. package/src/engine/ecs/systems/ViewportMeshProjectionSystem.js +0 -68
  142. package/src/engine/graphics/particles/ParticleEmitterLibrary.js +0 -87
  143. package/src/engine/graphics/texture/ExportCanvasAsPNG.js +0 -7
  144. package/src/engine/grid/components/GridObstacle.spec.js +0 -46
  145. package/src/engine/grid/components/GridPosition2Transform.js +0 -232
  146. package/src/engine/grid/components/ViewportGridProjection.js +0 -20
  147. package/src/engine/grid/systems/GridObstacleSystem.js +0 -58
  148. package/src/engine/grid/systems/ViewportGridProjectionSystem.js +0 -105
  149. package/src/engine/navigation/PathFinder.js +0 -172
  150. package/src/engine/navigation/PathWorker.js +0 -78
  151. package/src/engine/navigation/ecs/systems/PathFinderSystem.js +0 -63
  152. package/src/engine/navigation/ecs/systems/PathSystem.js +0 -19
  153. package/src/engine/navigation/funnel/Funnel.js +0 -196
  154. package/src/generation/ZoneNode.js +0 -9
  155. /package/{src/generation → samples/generation/grid}/GridTags.js +0 -0
  156. /package/src/{engine → core/primitives/array}/computeStridedIntegerArrayHash.js +0 -0
  157. /package/src/engine/grid/{components → grid2transform}/GridPosition2TransformFlags.js +0 -0
  158. /package/src/engine/grid/{components → obstacle}/GridObstacleSerializationAdapter.js +0 -0
  159. /package/src/engine/grid/{components → position}/GridPositionSerializationAdapter.js +0 -0
  160. /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
-
@@ -1,9 +0,0 @@
1
- export class ZoneNode {
2
- constructor() {
3
-
4
- this.tags = [];
5
-
6
- this.area = 0;
7
-
8
- }
9
- }