@woosh/meep-engine 2.51.0 → 2.52.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/package.json +1 -1
- package/src/core/NumberFormat.js +0 -71
- package/src/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js +1 -0
- package/src/core/bvh2/bvh3/query/BVHQueryAny.js +16 -0
- package/src/core/bvh2/bvh3/query/bvh_collect_user_data.js +5 -5
- package/src/core/bvh2/bvh3/query/bvh_query_leaves_generic.js +2 -3
- package/src/core/bvh2/bvh3/query/bvh_query_leaves_generic.spec.js +22 -0
- package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray.js +2 -2
- package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray.spec.js +64 -0
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_generic.js +2 -3
- package/src/core/geom/3d/aabb/aabb3_from_threejs_geometry.js +41 -0
- package/src/core/geom/3d/topology/struct/TopoMesh.js +3 -2
- package/src/core/geom/3d/topology/struct/prototypeBinaryTopology.js +4 -4
- package/src/core/geom/Vector2.d.ts +9 -0
- package/src/core/geom/Vector2.js +8 -22
- package/src/core/geom/Vector2.spec.js +153 -0
- package/src/core/model/ModuleRegistry.js +2 -4
- package/src/core/model/ModuleRegistry.spec.js +31 -0
- package/src/core/model/reactive/js/compileReactiveToJS.spec.js +14 -0
- package/src/core/model/reactive/model/logic/ReactiveAnd.spec.js +31 -1
- package/src/core/model/reactive/model/logic/ReactiveOr.spec.js +53 -0
- package/src/core/model/stat/LinearModifier.js +2 -2
- package/src/core/model/stat/LinearModifier.spec.js +62 -0
- package/src/core/model/stat/Stat.js +12 -0
- package/src/core/model/stat/Stat.spec.js +36 -0
- package/src/core/primitives/array/computeStridedIntegerArrayHash.spec.js +28 -0
- package/src/core/primitives/numbers/number_format_by_thousands.js +14 -0
- package/src/core/primitives/numbers/number_pretty_print.js +49 -0
- package/src/core/primitives/strings/computeStringHash.spec.js +12 -5
- package/src/core/process/BaseProcess.js +8 -8
- package/src/engine/Clock.js +30 -29
- package/src/engine/Clock.spec.js +26 -0
- package/src/engine/ecs/EntityBuilder.js +3 -1
- package/src/engine/ecs/EntityBuilder.spec.js +21 -0
- package/src/engine/ecs/gui/GUIElement.js +1 -1
- package/src/engine/ecs/gui/position/ViewportPosition.js +3 -3
- package/src/engine/ecs/terrain/ecs/TerrainClassifier.js +1 -1
- package/src/engine/ecs/terrain/ecs/layers/TerrainLayers.js +1 -1
- package/src/engine/ecs/transform/Transform.js +1 -0
- package/src/engine/graphics/camera/testClippingPlaneComputation.js +0 -4
- package/src/engine/graphics/ecs/animation/animator/graph/AnimationGraph.spec.js +5 -0
- package/src/engine/graphics/ecs/animation/animator/graph/definition/AnimationGraphDefinition.js +24 -25
- package/src/engine/graphics/ecs/animation/animator/graph/definition/AnimationGraphDefinition.spec.js +5 -0
- package/src/engine/graphics/ecs/decal/DecalSystem.js +2 -20
- package/src/engine/graphics/ecs/decal/v2/Decal.js +32 -32
- package/src/engine/graphics/ecs/decal/v2/Decal.spec.js +5 -0
- package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +4 -2
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +4 -33
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +8 -4
- package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMesh.spec.js +5 -0
- package/src/engine/graphics/ecs/mesh-v2/sample/prototypeShadedGeometry.js +0 -12
- package/src/engine/graphics/ecs/path/testPathDisplaySystem.js +0 -2
- package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +0 -4
- package/src/engine/graphics/ecs/water2/shader/testWaterShader.js +0 -2
- package/src/engine/graphics/geometry/buffered/computeBufferAttributeHash.js +1 -1
- package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +0 -2
- package/src/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +0 -4
- package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +0 -4
- package/src/engine/graphics/render/forward_plus/prototype/prototypeLightManager.js +2 -2
- package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +2 -6
- package/src/engine/graphics/sh3/path_tracer/GeometryBVHBatched.js +2 -1
- package/src/engine/graphics/sh3/path_tracer/PathTracer.js +6 -1
- package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +2 -2
- package/src/engine/graphics/shadows/testShadowMapRendering.js +0 -2
- package/src/engine/graphics/texture/sampler/Sampler2D.js +1 -1
- package/src/engine/graphics/three/expand_aabb_by_transformed_three_object.js +3 -23
- package/src/engine/grid/components/GridObstacle.js +45 -25
- package/src/engine/grid/components/GridObstacle.spec.js +130 -1
- package/src/engine/grid/components/GridPosition.js +5 -17
- package/src/engine/grid/components/GridPosition2Transform.js +1 -70
- package/src/engine/grid/components/GridPosition2TransformSerializationAdapter.js +70 -0
- package/src/engine/plugin/EnginePlugin.js +12 -14
- package/src/engine/plugin/EnginePlugin.spec.js +5 -0
- package/src/engine/plugin/EnginePluginManager.js +18 -22
- package/src/engine/scene/transitionToScene.js +12 -1
- package/src/engine/simulation/Ticker.js +1 -1
- package/src/generation/theme/TerrainLayerDescription.js +1 -1
- package/src/view/common/LabelView.js +3 -3
- package/src/engine/ecs/components/AimController.js +0 -18
- package/src/engine/ecs/components/Attacker.js +0 -13
- package/src/engine/ecs/components/MeshCollider.js +0 -15
- package/src/engine/ecs/components/RangedAttack.js +0 -12
- package/src/engine/ecs/components/TargetAI.js +0 -11
- package/src/engine/ecs/components/ViewportMeshProjection.js +0 -18
- package/src/engine/ecs/systems/AimControllerSystem.js +0 -63
- package/src/engine/ecs/systems/AttackerSystem.js +0 -67
- package/src/engine/ecs/systems/MeshColliderSystem.js +0 -47
- package/src/engine/ecs/systems/MonsterAISystem.js +0 -163
- package/src/engine/ecs/systems/MortalitySystem.js +0 -46
- package/src/engine/ecs/systems/RangedAttackSystem.js +0 -132
- package/src/engine/ecs/systems/SerializationMetadataSystem.js +0 -10
- package/src/engine/ecs/systems/TargetAISystem.js +0 -107
- package/src/engine/ecs/systems/ViewportMeshProjectionSystem.js +0 -68
- package/src/engine/graphics/particles/ParticleEmitterLibrary.js +0 -87
- package/src/engine/grid/components/ViewportGridProjection.js +0 -20
- package/src/engine/grid/systems/GridObstacleSystem.js +0 -58
- package/src/engine/grid/systems/ViewportGridProjectionSystem.js +0 -105
- /package/src/{engine → core/primitives/array}/computeStridedIntegerArrayHash.js +0 -0
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 30/06/2014.
|
|
3
|
-
*/
|
|
4
|
-
import { System } from '../System.js';
|
|
5
|
-
import TargetAI from '../components/TargetAI.js';
|
|
6
|
-
import Attacker from '../components/Attacker.js';
|
|
7
|
-
import { Transform } from '../transform/Transform.js';
|
|
8
|
-
import Tag from '../components/Tag.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class TargetAISystem extends System {
|
|
12
|
-
constructor() {
|
|
13
|
-
super();
|
|
14
|
-
|
|
15
|
-
this.dependencies = [TargetAI];
|
|
16
|
-
|
|
17
|
-
this.entityManager = null;
|
|
18
|
-
this.managedTargets = [];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
reset() {
|
|
22
|
-
this.managedTargets = [];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
startup(entityManager, readyCallback, errorCallback) {
|
|
26
|
-
this.entityManager = entityManager;
|
|
27
|
-
const self = this;
|
|
28
|
-
entityManager.on.entityRemoved.add(function (entity) {
|
|
29
|
-
//check if it's a managed entity
|
|
30
|
-
const managedTarget = self.managedTargets[entity];
|
|
31
|
-
if (managedTarget !== void 0) {
|
|
32
|
-
managedTarget.target = null;
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
readyCallback();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
remove(component, entity) {
|
|
39
|
-
if (component.target !== null) {
|
|
40
|
-
delete this.managedTargets[component.target];
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
update(timeDelta) {
|
|
45
|
-
const self = this;
|
|
46
|
-
//go through target pickers
|
|
47
|
-
const em = this.entityManager;
|
|
48
|
-
em.traverseEntities([TargetAI, Attacker, Transform], function (picker, attacker, source, entity) {
|
|
49
|
-
const sourcePosition = source.global.position;
|
|
50
|
-
let targetEntity = attacker.target;
|
|
51
|
-
let targetPosition;
|
|
52
|
-
if (targetEntity !== null) {
|
|
53
|
-
const targetTransform = em.getComponent(targetEntity, Transform);
|
|
54
|
-
if (targetTransform === null) {
|
|
55
|
-
//target entity no longer exists
|
|
56
|
-
loseTarget(em, entity, attacker, self);
|
|
57
|
-
} else {
|
|
58
|
-
targetPosition = targetTransform.global.position;
|
|
59
|
-
const d = targetPosition.distanceTo(sourcePosition);
|
|
60
|
-
if (d > picker.range) {
|
|
61
|
-
//reset target if too far
|
|
62
|
-
loseTarget(em, entity, attacker, self);
|
|
63
|
-
} else {
|
|
64
|
-
//we already have a decent target
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (attacker.target === null) {
|
|
70
|
-
let range = picker.range;
|
|
71
|
-
const tags = picker.tags;
|
|
72
|
-
//find a new nearest target
|
|
73
|
-
em.traverseEntities([Tag, Transform], function (tag, transform, entity) {
|
|
74
|
-
if (!tag.containsOneOf(tags)) {
|
|
75
|
-
//not a tag we care about
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
//check distance
|
|
79
|
-
let d = transform.global.position.distanceTo(sourcePosition);
|
|
80
|
-
if (d < range) {
|
|
81
|
-
range = d; //reduce search radius
|
|
82
|
-
targetEntity = entity;
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
if (targetEntity !== null) {
|
|
86
|
-
gainTarget(em, entity, attacker, targetEntity, self);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
function loseTarget(em, entity, attacker, ts) {
|
|
95
|
-
const oldTarget = attacker.target;
|
|
96
|
-
attacker.target = null;
|
|
97
|
-
em.sendEvent(entity, "target-lost", oldTarget);
|
|
98
|
-
delete ts.managedTargets[oldTarget];
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function gainTarget(em, entity, attacker, target, ts) {
|
|
102
|
-
attacker.target = target;
|
|
103
|
-
em.sendEvent(entity, "target-gained", target);
|
|
104
|
-
ts.managedTargets[target] = attacker;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export default TargetAISystem;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 18/12/2014.
|
|
3
|
-
*/
|
|
4
|
-
import { System } from '../System.js';
|
|
5
|
-
import { Transform } from '../transform/Transform.js';
|
|
6
|
-
import Renderable from '../renderable/Renderable.js';
|
|
7
|
-
import GeometryBVH from '../components/GeometryBVH.js';
|
|
8
|
-
import ViewportMeshProjection from '../components/ViewportMeshProjection.js';
|
|
9
|
-
import { Vector3 as ThreeVector3 } from 'three';
|
|
10
|
-
|
|
11
|
-
class VMPS extends System {
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* @param {GraphicsEngine} graphicsEngine
|
|
15
|
-
* @constructor
|
|
16
|
-
*/
|
|
17
|
-
constructor(graphicsEngine) {
|
|
18
|
-
super();
|
|
19
|
-
this.graphicEngine = graphicsEngine;
|
|
20
|
-
|
|
21
|
-
this.dependencies = [ViewportMeshProjection];
|
|
22
|
-
|
|
23
|
-
//small number
|
|
24
|
-
this.update = (function () {
|
|
25
|
-
const source = new ThreeVector3();
|
|
26
|
-
const target = new ThreeVector3();
|
|
27
|
-
|
|
28
|
-
function update(timeDelta) {
|
|
29
|
-
const ge = this.graphicEngine;
|
|
30
|
-
const em = this.entityManager;
|
|
31
|
-
em.traverseEntities([ViewportMeshProjection, Transform], function (p, t, e) {
|
|
32
|
-
const v2 = p.position;
|
|
33
|
-
const geometryBVH = em.getComponent(p.entity, GeometryBVH);
|
|
34
|
-
if (geometryBVH !== null) {
|
|
35
|
-
//bvh exists
|
|
36
|
-
ge.viewportProjectionRay(v2.x, v2.y, source, target);
|
|
37
|
-
geometryBVH.raycast(source, target, function (point) {
|
|
38
|
-
if (t.position.distanceToSquared(point) > EPSILON) {
|
|
39
|
-
t.position.copy(point);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
} else {
|
|
43
|
-
//no bvh, use mesh directly
|
|
44
|
-
const renderable = em.getComponent(p.entity, Renderable);
|
|
45
|
-
const hits = ge.intersectObjectUnderViewportPoint(v2.x, v2.y, renderable.mesh, true);
|
|
46
|
-
if (hits !== void 0 && hits.length > 0) {
|
|
47
|
-
//take first hit
|
|
48
|
-
const hit = hits[0];
|
|
49
|
-
const point = hit.point;
|
|
50
|
-
if (t.position.distanceToSquared(point) > EPSILON) {
|
|
51
|
-
t.position.copy(point);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return update;
|
|
61
|
-
})();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const EPSILON = 0.00001;
|
|
67
|
-
|
|
68
|
-
export default VMPS;
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { ParticleEmitter } from "./particular/engine/emitter/ParticleEmitter.js";
|
|
2
|
-
import { GameAssetType } from "../../asset/GameAssetType.js";
|
|
3
|
-
import { assert } from "../../../core/assert.js";
|
|
4
|
-
import { JsonAssetLoader } from "../../asset/loaders/JsonAssetLoader.js";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @deprecated Use "Effect" API to achieve the same results
|
|
8
|
-
*/
|
|
9
|
-
export class ParticleEmitterLibrary {
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
* @param {AssetManager} assetManager
|
|
13
|
-
*/
|
|
14
|
-
constructor(assetManager) {
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
17
|
-
* @type {AssetManager}
|
|
18
|
-
*/
|
|
19
|
-
this.assetManager = assetManager;
|
|
20
|
-
|
|
21
|
-
this.data = {};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
*
|
|
26
|
-
* @param {string} path
|
|
27
|
-
* @returns {Promise<void>}
|
|
28
|
-
*/
|
|
29
|
-
async load_from_registry_file(path) {
|
|
30
|
-
|
|
31
|
-
const am = this.assetManager;
|
|
32
|
-
|
|
33
|
-
if (am.getLoaderByType(GameAssetType.JSON) === undefined) {
|
|
34
|
-
// add missing loader
|
|
35
|
-
await am.registerLoader(GameAssetType.JSON, new JsonAssetLoader());
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const asset = await am.promise(path, GameAssetType.JSON)
|
|
39
|
-
const particleSet = asset.create();
|
|
40
|
-
|
|
41
|
-
await this.load(particleSet);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @param {Object} listing
|
|
46
|
-
* @returns {Promise}
|
|
47
|
-
*/
|
|
48
|
-
load(listing) {
|
|
49
|
-
const assetManager = this.assetManager;
|
|
50
|
-
const data = this.data;
|
|
51
|
-
|
|
52
|
-
const promises = [];
|
|
53
|
-
|
|
54
|
-
for (let id in listing) {
|
|
55
|
-
const url = listing[id];
|
|
56
|
-
|
|
57
|
-
assert.typeOf(id, "string", "id");
|
|
58
|
-
assert.typeOf(url, "string", "url");
|
|
59
|
-
|
|
60
|
-
const assetPromise = assetManager.promise(url, GameAssetType.JSON);
|
|
61
|
-
|
|
62
|
-
promises.push(assetPromise);
|
|
63
|
-
|
|
64
|
-
assetPromise.then(asset => {
|
|
65
|
-
const json = asset.create();
|
|
66
|
-
|
|
67
|
-
data[id] = json;
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return Promise.all(promises);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* @param {string} id
|
|
76
|
-
* @returns {ParticleEmitter}
|
|
77
|
-
*/
|
|
78
|
-
create(id) {
|
|
79
|
-
const definition = this.data[id];
|
|
80
|
-
|
|
81
|
-
if (definition === undefined) {
|
|
82
|
-
throw new Error(`No definition found for emitter '${id}'`);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return ParticleEmitter.fromJSON(definition);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 28/01/2015.
|
|
3
|
-
*/
|
|
4
|
-
import { Matrix4 as ThreeMatrix4 } from 'three';
|
|
5
|
-
|
|
6
|
-
const emptyHash = {};
|
|
7
|
-
|
|
8
|
-
function ViewportGridProjection(options) {
|
|
9
|
-
if (options === void 0) {
|
|
10
|
-
options = emptyHash;
|
|
11
|
-
}
|
|
12
|
-
this.x = options.x || 0;
|
|
13
|
-
this.y = options.y || 0;
|
|
14
|
-
this.prevX = void 0;
|
|
15
|
-
this.prevY = void 0;
|
|
16
|
-
this.prevProjectionMatrix = new ThreeMatrix4();
|
|
17
|
-
this.snap = options.snap !== void 0 ? options.snap : true;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export default ViewportGridProjection;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 13/10/2014.
|
|
3
|
-
*/
|
|
4
|
-
import { System } from '../../ecs/System.js';
|
|
5
|
-
import GridPosition from '../components/GridPosition.js';
|
|
6
|
-
import GridObstacle from '../components/GridObstacle.js';
|
|
7
|
-
|
|
8
|
-
class GridObstacleSystem extends System {
|
|
9
|
-
constructor() {
|
|
10
|
-
super();
|
|
11
|
-
|
|
12
|
-
this.dependencies = [GridObstacle, GridPosition];
|
|
13
|
-
|
|
14
|
-
this.pathsNeedUpdate = false;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
startup(entityManager, success, failure) {
|
|
18
|
-
this.entityManager = entityManager;
|
|
19
|
-
|
|
20
|
-
success();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
recalculatePaths() {
|
|
24
|
-
//todo this should be somewhere else
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
*
|
|
29
|
-
* @param {GridObstacle} obstacle
|
|
30
|
-
* @param {GridPosition} p
|
|
31
|
-
* @param {int} entityId
|
|
32
|
-
*/
|
|
33
|
-
link(obstacle, p, entityId) {
|
|
34
|
-
|
|
35
|
-
this.pathsNeedUpdate = true;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
*
|
|
40
|
-
* @param {GridObstacle} obstacle
|
|
41
|
-
* @param {GridPosition} p
|
|
42
|
-
* @param {int} entityId
|
|
43
|
-
*/
|
|
44
|
-
unlink(obstacle, p, entityId) {
|
|
45
|
-
|
|
46
|
-
this.pathsNeedUpdate = true;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
update(timeDelta) {
|
|
50
|
-
if (this.pathsNeedUpdate) {
|
|
51
|
-
this.recalculatePaths();
|
|
52
|
-
this.pathsNeedUpdate = false;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
export default GridObstacleSystem;
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 28/01/2015.
|
|
3
|
-
*/
|
|
4
|
-
import { System } from '../../ecs/System.js';
|
|
5
|
-
import GeometryBVH from '../../ecs/components/GeometryBVH.js';
|
|
6
|
-
import GridPosition from '../components/GridPosition.js';
|
|
7
|
-
import ViewportGridProjection from '../components/ViewportGridProjection.js';
|
|
8
|
-
import Vector2 from "../../../core/geom/Vector2.js";
|
|
9
|
-
import Vector3 from "../../../core/geom/Vector3.js";
|
|
10
|
-
import { obtainTerrain } from "../../ecs/terrain/util/obtainTerrain.js";
|
|
11
|
-
|
|
12
|
-
class ViewportGridProjectionSystem extends System {
|
|
13
|
-
constructor(grid, graphicsEngine) {
|
|
14
|
-
super();
|
|
15
|
-
|
|
16
|
-
this.dependencies = [ViewportGridProjection];
|
|
17
|
-
|
|
18
|
-
this.graphicsEngine = graphicsEngine;
|
|
19
|
-
this.grid = grid;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
add(component, entity) {
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
remove(component, entity) {
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
update(timeDelta) {
|
|
29
|
-
const grid = this.grid;
|
|
30
|
-
const em = this.entityManager;
|
|
31
|
-
const renderer = this.graphicsEngine;
|
|
32
|
-
//
|
|
33
|
-
let terrain = null;
|
|
34
|
-
let terrainEntity = void 0;
|
|
35
|
-
obtainTerrain(em.dataset, function (t, entity) {
|
|
36
|
-
terrain = t;
|
|
37
|
-
terrainEntity = entity;
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
if (terrain === void 0) {
|
|
41
|
-
//terrain failed to bind, can't project
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
//try to get bvh for terrain
|
|
45
|
-
const geometryBVH = em.getComponent(terrainEntity, GeometryBVH);
|
|
46
|
-
|
|
47
|
-
const terrainMesh = terrain.surfaceMesh;
|
|
48
|
-
if (terrainMesh === void 0) {
|
|
49
|
-
//mesh doesn't exist, can't project
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
const v2 = new Vector2();
|
|
53
|
-
em.traverseEntities([ViewportGridProjection, GridPosition], function (p, gridPosition, entity) {
|
|
54
|
-
const worldProjectionMatrix = renderer.camera.projectionMatrix;
|
|
55
|
-
if (p.x === p.prevX && p.y === p.prevY && matricesEqual(worldProjectionMatrix, p.prevProjectionMatrix)) {
|
|
56
|
-
//NOTE: Assumes mesh is static in transform and topology
|
|
57
|
-
//result same as before, do nothing
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
p.prevX = p.x;
|
|
61
|
-
p.prevY = p.y;
|
|
62
|
-
p.prevProjectionMatrix.copy(worldProjectionMatrix);
|
|
63
|
-
v2.set(p.x, p.y);
|
|
64
|
-
renderer.normalizeViewportPoint(v2, v2);
|
|
65
|
-
if (geometryBVH !== null) {
|
|
66
|
-
//see if there's a bvh for this entity
|
|
67
|
-
const source = new Vector3();
|
|
68
|
-
const target = new Vector3();
|
|
69
|
-
renderer.viewportProjectionRay(v2.x, v2.y, source, target);
|
|
70
|
-
geometryBVH.raycast(source, target, function (point) {
|
|
71
|
-
processIntersection(grid, point, p, gridPosition);
|
|
72
|
-
});
|
|
73
|
-
} else {
|
|
74
|
-
const hits = renderer.intersectObjectUnderViewportPoint(v2.x, v2.y, terrainMesh, true);
|
|
75
|
-
if (hits !== void 0 && hits.length > 0) {
|
|
76
|
-
//take first hit
|
|
77
|
-
const hit = hits[0];
|
|
78
|
-
const point = hit.point;
|
|
79
|
-
processIntersection(grid, point, p, gridPosition);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
function matricesEqual(m0, m1) {
|
|
88
|
-
for (let i = 0; i < 16; i++) {
|
|
89
|
-
if (m0.elements[i] !== m1.elements[i]) {
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return true;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function processIntersection(grid, point, p, gridPosition) {
|
|
97
|
-
grid.pointWorld2Grid(point, gridPosition);
|
|
98
|
-
if (p.snap) {
|
|
99
|
-
//snap to grid
|
|
100
|
-
gridPosition.x = Math.round(gridPosition.x);
|
|
101
|
-
gridPosition.y = Math.round(gridPosition.y);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export default ViewportGridProjectionSystem;
|
|
File without changes
|