@woosh/meep-engine 2.33.62 → 2.33.63

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.
@@ -0,0 +1,44 @@
1
+ import { assert } from "../../core/assert.js";
2
+ import Vector3 from "../../core/geom/Vector3.js";
3
+ import { SurfacePoint3 } from "../../core/geom/3d/SurfacePoint3.js";
4
+ import Vector2 from "../../core/geom/Vector2.js";
5
+
6
+ /**
7
+ *
8
+ * @param {number} x
9
+ * @param {number} y
10
+ * @param {GraphicsEngine} graphicsEngine
11
+ * @param {Terrain} terrain
12
+ * @param {function(gridPosition:Vector2,worldPosition:Vector3,normal:Vector3)} callback
13
+ */
14
+ export function pick(x, y, graphicsEngine, terrain, callback) {
15
+
16
+ assert.isNumber(x, 'x');
17
+ assert.isNumber(y, 'y');
18
+
19
+ assert.defined(terrain, 'terrain');
20
+ assert.notNull(terrain, 'terrain');
21
+
22
+ assert.isFunction(callback, 'callback');
23
+
24
+ const vSource = new Vector3(x, y, 0);
25
+ const vTarget = new Vector3();
26
+
27
+ graphicsEngine.normalizeViewportPoint(vSource, vSource);
28
+ graphicsEngine.viewportProjectionRay(vSource.x, vSource.y, vSource, vTarget);
29
+
30
+ const surfacePoint3 = new SurfacePoint3();
31
+
32
+ const hitFound = terrain.raycastFirstSync(surfacePoint3, vSource.x, vSource.y, vSource.z, vTarget.x, vTarget.y, vTarget.z);
33
+
34
+ if (!hitFound) {
35
+ // nothing found
36
+ } else {
37
+
38
+ const gridPosition = new Vector2();
39
+ terrain.mapPointWorld2Grid(surfacePoint3.position, gridPosition);
40
+ gridPosition._add(0.5, 0.5);
41
+ callback(gridPosition, surfacePoint3.position, surfacePoint3.normal);
42
+ }
43
+
44
+ }
@@ -1,7 +1,6 @@
1
1
  import Tool from "./engine/Tool.js";
2
2
  import GridPosition from "../../engine/grid/components/GridPosition.js";
3
3
  import GridObstacle from "../../engine/grid/components/GridObstacle.js";
4
- import { pick } from "../../../model/game/util/ScreenGridPicker.js";
5
4
  import Vector4 from "../../core/geom/Vector4.js";
6
5
  import ObservedValue from "../../core/model/ObservedValue.js";
7
6
  import Vector1 from "../../core/geom/Vector1.js";
@@ -12,6 +11,7 @@ import Vector2 from "../../core/geom/Vector2.js";
12
11
  import TopDownCameraControllerSystem from "../../engine/graphics/ecs/camera/topdown/TopDownCameraControllerSystem.js";
13
12
  import { parseHex } from "../../core/color/parseHex.js";
14
13
  import { obtainTerrain } from "../../engine/ecs/terrain/util/obtainTerrain.js";
14
+ import { pick } from "../../ecs/grid/pick.js";
15
15
 
16
16
  class GridPaintTool extends Tool {
17
17
  constructor() {
@@ -3,12 +3,12 @@ import Tool from "../engine/Tool.js";
3
3
  import { Color } from "../../../core/color/Color.js";
4
4
  import { Sampler2D } from "../../../engine/graphics/texture/sampler/Sampler2D.js";
5
5
  import Vector2 from "../../../core/geom/Vector2.js";
6
- import { pick } from "../../../../model/game/util/ScreenGridPicker.js";
7
6
  import convertSampler2D2Canvas from "../../../engine/graphics/texture/sampler/Sampler2D2Canvas.js";
8
7
  import ObservedString from "../../../core/model/ObservedString.js";
9
8
  import { GameAssetType } from "../../../engine/asset/GameAssetType.js";
10
9
  import Vector1 from "../../../core/geom/Vector1.js";
11
10
  import { obtainTerrain } from "../../../engine/ecs/terrain/util/obtainTerrain.js";
11
+ import { pick } from "../../../ecs/grid/pick.js";
12
12
 
13
13
  export class TerrainPaintTool extends Tool {
14
14
  constructor() {
@@ -1,8 +1,8 @@
1
1
  import View from "../../view/View.js";
2
- import { pick } from "../../../model/game/util/ScreenGridPicker.js";
3
2
  import domify from "../../view/DOM.js";
4
3
  import { PointerDevice } from "../../engine/input/devices/PointerDevice.js";
5
4
  import { obtainTerrain } from "../../engine/ecs/terrain/util/obtainTerrain.js";
5
+ import { pick } from "../../ecs/grid/pick.js";
6
6
 
7
7
  class GridPickCoordinateView extends View {
8
8
  /**
@@ -2,7 +2,7 @@ import { System } from "../System.js";
2
2
  import { FogOfWarRevealer } from "./FogOfWarRevealer.js";
3
3
  import { SignalBinding } from "../../../core/events/signal/SignalBinding.js";
4
4
  import { FogOfWar } from "./FogOfWar.js";
5
- import Team from "../../../../model/game/ecs/component/Team.js";
5
+ import Team from "../team/Team.js";
6
6
  import { Transform } from "../transform/Transform.js";
7
7
  import Vector2 from "../../../core/geom/Vector2.js";
8
8
  import { obtainTerrain } from "../terrain/util/obtainTerrain.js";
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Created by Alex on 13/04/2016.
3
+ */
4
+ import ObservedInteger from "../../../core/model/ObservedInteger.js";
5
+ import { BinaryClassSerializationAdapter } from "../storage/binary/BinaryClassSerializationAdapter.js";
6
+
7
+ class Team extends ObservedInteger {
8
+ /**
9
+ *
10
+ * @param value
11
+ * @constructor
12
+ */
13
+ constructor(value = 0) {
14
+ super(value);
15
+ }
16
+
17
+ clone() {
18
+ return new Team(this.getValue());
19
+ }
20
+
21
+ /**
22
+ *
23
+ * @param {object} json
24
+ * @returns {Team}
25
+ */
26
+ static fromJSON(json) {
27
+ const t = new Team();
28
+
29
+ t.fromJSON(json);
30
+
31
+ return t;
32
+ }
33
+ }
34
+
35
+ Team.typeName = "Team";
36
+
37
+
38
+ export default Team;
39
+
40
+ export class TeamSerializationAdapter extends BinaryClassSerializationAdapter{
41
+ constructor(){
42
+ super();
43
+
44
+ this.klass = Team;
45
+ this.version = 0;
46
+ }
47
+
48
+ /**
49
+ *
50
+ * @param {BinaryBuffer} buffer
51
+ * @param {Team} value
52
+ */
53
+ serialize(buffer, value) {
54
+ const v = value.getValue();
55
+
56
+ if (v === Infinity) {
57
+ buffer.writeInt32(2147483647);
58
+ } else if (v === -Infinity) {
59
+ buffer.writeInt32(-2147483648);
60
+ } else {
61
+ //TODO it's possible to write encoded Infinity values by accident
62
+ buffer.writeInt32(v);
63
+ }
64
+ }
65
+
66
+ /**
67
+ *
68
+ * @param {BinaryBuffer} buffer
69
+ * @param {Team} value
70
+ */
71
+ deserialize(buffer, value) {
72
+ const v = buffer.readInt32();
73
+
74
+ if (v === 2147483647) {
75
+ value.set(Infinity);
76
+ } else if (v === -2147483648) {
77
+ value.set(-Infinity);
78
+ } else {
79
+ value.set(v);
80
+ }
81
+ }
82
+ }
@@ -2,10 +2,10 @@ import { System } from "../System.js";
2
2
  import { TooltipComponent } from "./TooltipComponent.js";
3
3
  import Vector3 from "../../../core/geom/Vector3.js";
4
4
  import { MeshSystem } from "../../graphics/ecs/mesh/MeshSystem.js";
5
- import { modelHitTest } from "../../../../model/game/util/ScreenGridPicker.js";
6
5
  import { SurfacePoint3 } from "../../../core/geom/3d/SurfacePoint3.js";
7
6
  import { VisualTip } from "../../../view/tooltip/VisualTip.js";
8
7
  import Rectangle from "../../../core/geom/Rectangle.js";
8
+ import { modelHitTest } from "../../graphics/util/modelHitTest.js";
9
9
 
10
10
  const ray_source = new Vector3();
11
11
  const ray_direction = new Vector3();
@@ -42,7 +42,6 @@ import { RepeatBehavior } from "../../../../../../intelligence/behavior/decorato
42
42
  import { ActionBehavior } from "../../../../../../intelligence/behavior/primitive/ActionBehavior.js";
43
43
  import { pingpong } from "../../../../../../../core/math/pingpong.js";
44
44
  import { ParameterLookupTable } from "../../parameter/ParameterLookupTable.js";
45
- import { pick } from "../../../../../../../../model/game/util/ScreenGridPicker.js";
46
45
  import GUIElement from "../../../../../../ecs/gui/GUIElement.js";
47
46
  import EmptyView from "../../../../../../../view/elements/EmptyView.js";
48
47
  import HeadsUpDisplay from "../../../../../../ecs/gui/hud/HeadsUpDisplay.js";
@@ -77,6 +76,7 @@ import TopDownCameraController from "../../../../../ecs/camera/topdown/TopDownCa
77
76
  import { randomFloatBetween } from "../../../../../../../core/math/random/randomFloatBetween.js";
78
77
  import { MicronRenderPlugin } from "../../../../../micron/plugin/MicronRenderPlugin.js";
79
78
  import { obtainTerrain } from "../../../../../../ecs/terrain/util/obtainTerrain.js";
79
+ import { pick } from "../../../../../../../ecs/grid/pick.js";
80
80
 
81
81
  const engineHarness = new EngineHarness();
82
82
 
@@ -80,7 +80,7 @@ import { ParticleEmitterSystem } from "../../../particles/ecs/ParticleEmitterSys
80
80
  import { ShadedGeometrySystem } from "../../../ecs/mesh-v2/ShadedGeometrySystem.js";
81
81
  import { FogOfWar } from "../../../../ecs/fow/FogOfWar.js";
82
82
  import { FogOfWarRevealer } from "../../../../ecs/fow/FogOfWarRevealer.js";
83
- import Team from "../../../../../../model/game/ecs/component/Team.js";
83
+ import Team from "../../../../ecs/team/Team.js";
84
84
  import { AmbientOcclusionPostProcessEffect } from "../../buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.js";
85
85
  import { obtainTerrain } from "../../../../ecs/terrain/util/obtainTerrain.js";
86
86
 
@@ -1,5 +1,7 @@
1
1
  import { array_copy } from "../../../../../core/collection/array/copyArray.js";
2
2
 
3
+ const BIND_GROUP_MATERIAL = 1;
4
+
3
5
  export class MeshInstance {
4
6
  constructor() {
5
7
 
@@ -9,6 +11,12 @@ export class MeshInstance {
9
11
  */
10
12
  this.geometry = null;
11
13
 
14
+ /**
15
+ *
16
+ * @type {null}
17
+ */
18
+ this.material = null;
19
+
12
20
  /**
13
21
  *
14
22
  * @type {GPUBuffer|null}
@@ -80,6 +88,10 @@ export class MeshInstance {
80
88
  * @param {GPURenderPassEncoder} pass
81
89
  */
82
90
  draw(pass) {
91
+ // set material bindings
92
+
93
+ // pass.setBindGroup(BIND_GROUP_MATERIAL, {});
94
+
83
95
  pass.setVertexBuffer(0, this.vertex_buffer);
84
96
  pass.setIndexBuffer(this.index_buffer, 'uint32');
85
97
  pass.drawIndexed(this.geometry.getIndex().array.length);
@@ -0,0 +1,63 @@
1
+ import Vector2 from "../../../core/geom/Vector2.js";
2
+ import Mesh from "../ecs/mesh/Mesh.js";
3
+
4
+ const tempPoint = new Vector2();
5
+
6
+ /**
7
+ *
8
+ * @param {SurfacePoint3} result
9
+ * @param {Array.<Number>} entities
10
+ * @param {EntityComponentDataset} ecd
11
+ * @param {GraphicsEngine} ge
12
+ * @param {Number} x
13
+ * @param {Number} y
14
+ * @returns {Number} entity number or -1 in case of failed test
15
+ */
16
+ function modelHitTest(result, entities, ecd, ge, x, y) {
17
+ tempPoint.set(x, y);
18
+
19
+ ge.normalizeViewportPoint(tempPoint, tempPoint);
20
+
21
+ let i = 0;
22
+ const l = entities.length;
23
+
24
+ for (; i < l; i++) {
25
+
26
+ const entity = entities[i];
27
+
28
+ const model = ecd.getComponent(entity, Mesh);
29
+
30
+ if (model === null) {
31
+ //entity no longer exists most likely
32
+ continue;
33
+ }
34
+
35
+ /**
36
+ *
37
+ * @type {Intersection[]}
38
+ */
39
+ const hits = ge.intersectObjectUnderViewportPoint(tempPoint.x, tempPoint.y, model.mesh, true);
40
+
41
+ // get hit
42
+
43
+
44
+ if (hits.length > 0) {
45
+ /**
46
+ *
47
+ * @type {Intersection}
48
+ */
49
+ const hit = hits[0];
50
+
51
+ result.position.copy(hit.point);
52
+
53
+ //TODO extract normal
54
+
55
+ return entity;
56
+ }
57
+
58
+ }
59
+
60
+ return -1;
61
+ }
62
+
63
+ export { modelHitTest };
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.33.62",
8
+ "version": "2.33.63",
9
9
  "dependencies": {
10
10
  "gl-matrix": "3.4.3",
11
11
  "fast-levenshtein": "2.0.6",
@@ -0,0 +1,3 @@
1
+ /**
2
+ * Created by Alex on 13/06/2016.
3
+ */