@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.
Files changed (84) 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/collection/table/RowFirstTableSpec.js +8 -4
  18. package/src/core/geom/3d/matrix/MATRIX_4_IDENTITY.spec.js +10 -0
  19. package/src/engine/Engine.spec.js +4 -0
  20. package/src/engine/EngineConfiguration.js +24 -25
  21. package/src/engine/ecs/EntityBlueprint.js +2 -4
  22. package/src/engine/ecs/EntityComponentDataset.js +1 -1
  23. package/src/engine/ecs/EntityComponentDataset.spec.js +77 -0
  24. package/src/engine/ecs/EntityObserver.spec.js +1 -1
  25. package/src/engine/ecs/dynamic_actions/actions/definition/{WhiteToBlackboardActionDescription.js → WriteToBlackboardActionDescription.js} +2 -2
  26. package/src/engine/ecs/dynamic_actions/actions/definition/deserializeActionFromJSON.js +2 -2
  27. package/src/engine/ecs/guid/GUIDSerializationAdapter.spec.js +21 -0
  28. package/src/engine/ecs/parent/EntityNode.js +1 -1
  29. package/src/engine/ecs/parent/EntityNode.spec.js +104 -0
  30. package/src/engine/ecs/speaker/Voice.js +4 -0
  31. package/src/engine/ecs/team/Team.js +0 -44
  32. package/src/engine/ecs/team/TeamSerializationAdapter.js +46 -0
  33. package/src/engine/ecs/terrain/overlay/TerrainOverlay.spec.js +6 -0
  34. package/src/engine/ecs/terrain/tiles/TerrainTile.js +79 -76
  35. package/src/engine/ecs/terrain/tiles/TerrainTile.spec.js +25 -0
  36. package/src/engine/ecs/transform/Transform.js +1 -1
  37. package/src/engine/ecs/transform/Transform.spec.js +24 -0
  38. package/src/engine/graphics/camera/testClippingPlaneComputation.js +2 -2
  39. package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +2 -2
  40. package/src/engine/graphics/ecs/water2/shader/testWaterShader.js +2 -2
  41. package/src/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +2 -2
  42. package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +2 -2
  43. package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +2 -2
  44. package/src/engine/graphics/texture/TextureBackedMemoryRegion.js +4 -1
  45. package/src/engine/graphics/texture/sampler/filter/filter_lanczos3.js +7 -2
  46. package/src/engine/grid/{components → grid2transform}/GridPosition2Transform.js +0 -41
  47. package/src/engine/grid/grid2transform/GridPosition2TransformSerializationUpgrader_0_1.js +40 -0
  48. package/src/engine/grid/{systems → grid2transform}/GridPosition2TransformSystem.js +3 -3
  49. package/src/engine/grid/{components → position}/GridPosition.js +4 -0
  50. package/src/engine/grid/{systems → position}/GridPositionSystem.js +1 -1
  51. package/src/engine/grid/transform2grid/Transform2GridPositionSystem.js +1 -1
  52. package/src/engine/input/devices/PointerDevice.spec.js +5 -0
  53. package/src/engine/navigation/ecs/components/computeCatmullRomSpline.js +5 -1
  54. package/src/engine/navigation/ecs/path_following/PathFollower.js +40 -32
  55. package/src/engine/navigation/ecs/path_following/PathFollower.spec.js +27 -0
  56. package/src/engine/platform/EnginePlatform.js +0 -4
  57. package/src/generation/filtering/CellFilter.js +6 -9
  58. package/src/generation/filtering/boolean/CellFilterLiteralBoolean.js +1 -4
  59. package/src/generation/filtering/core/CellFilterBinaryOperation.js +12 -15
  60. package/src/generation/filtering/core/CellFilterOperationTertiary.js +15 -19
  61. package/src/generation/filtering/numeric/CellFilterLiteralFloat.js +6 -9
  62. package/src/generation/grid/actions/ContinuousGridCellActionSetTerrainObstacle.js +1 -1
  63. package/src/generation/grid/actions/ContinuousGridCellActionWriteObstacle.js +2 -2
  64. package/src/generation/grid/generation/road/GridTaskGenerateRoads.js +1 -1
  65. package/src/generation/markers/actions/MarkerNodeActionEntityPlacement.js +1 -1
  66. package/src/engine/InputEngine.js +0 -94
  67. package/src/engine/PointerLock.js +0 -60
  68. package/src/engine/ecs/terrain/ecs/layers/loadLegacyTerrainLayers.js +0 -99
  69. package/src/engine/ecs/terrain/ecs/splat/loadLegacyTerrainSplats.js +0 -73
  70. package/src/engine/graphics/texture/ExportCanvasAsPNG.js +0 -7
  71. package/src/engine/navigation/PathFinder.js +0 -172
  72. package/src/engine/navigation/PathWorker.js +0 -78
  73. package/src/engine/navigation/ecs/systems/PathFinderSystem.js +0 -63
  74. package/src/engine/navigation/ecs/systems/PathSystem.js +0 -19
  75. package/src/engine/navigation/funnel/Funnel.js +0 -196
  76. package/src/generation/ZoneNode.js +0 -9
  77. /package/{src/generation → samples/generation/grid}/GridTags.js +0 -0
  78. /package/src/engine/grid/{components → grid2transform}/GridPosition2TransformFlags.js +0 -0
  79. /package/src/engine/grid/{components → grid2transform}/GridPosition2TransformSerializationAdapter.js +0 -0
  80. /package/src/engine/grid/{components → obstacle}/GridObstacle.js +0 -0
  81. /package/src/engine/grid/{components → obstacle}/GridObstacle.spec.js +0 -0
  82. /package/src/engine/grid/{components → obstacle}/GridObstacleSerializationAdapter.js +0 -0
  83. /package/src/engine/grid/{components → position}/GridPositionSerializationAdapter.js +0 -0
  84. /package/src/engine/grid/{components → position}/GridPositionSerializationUpdater_0_1.js +0 -0
@@ -19,39 +19,40 @@ const DEFAULT_FLAGS = PathFollowerFlags.Active
19
19
  | PathFollowerFlags.WriteRotationZ
20
20
  ;
21
21
 
22
+ const DEFAULT_MAX_MOVE_DISTANCE = 100000;
23
+
22
24
  class PathFollower {
23
- constructor() {
24
-
25
- /**
26
- * Movement speed along the path in world units per second
27
- * @type {Vector1}
28
- */
29
- this.speed = new Vector1(DEFAULT_SPEED);
30
-
31
- /**
32
- * Speed at which path follower can adjust rotation in Rad/s
33
- * @type {Vector1}
34
- */
35
- this.rotationSpeed = new Vector1(DEFAULT_ROTATION_SPEED);
36
-
37
- /**
38
- *
39
- * @type {number}
40
- */
41
- this.flags = DEFAULT_FLAGS;
42
25
 
43
- /**
44
- * Maximum distance that the follower can move along the path in a single step
45
- * @type {number}
46
- */
47
- this.maxMoveDistance = 100000;
48
-
49
- /**
50
- * Absolute position along the path
51
- * @type {number}
52
- */
53
- this.position = 0;
54
- }
26
+ /**
27
+ * Movement speed along the path in world units per second
28
+ * @type {Vector1}
29
+ */
30
+ speed = new Vector1(DEFAULT_SPEED);
31
+
32
+ /**
33
+ * Speed at which path follower can adjust rotation in Rad/s
34
+ * @type {Vector1}
35
+ */
36
+ rotationSpeed = new Vector1(DEFAULT_ROTATION_SPEED);
37
+
38
+ /**
39
+ *
40
+ * @type {number}
41
+ */
42
+ flags = DEFAULT_FLAGS;
43
+
44
+ /**
45
+ * Maximum distance that the follower can move along the path in a single step
46
+ * @type {number}
47
+ */
48
+ maxMoveDistance = DEFAULT_MAX_MOVE_DISTANCE;
49
+
50
+ /**
51
+ * Absolute position along the path
52
+ * @type {number}
53
+ */
54
+ position = 0;
55
+
55
56
 
56
57
  get rotationAlignment() {
57
58
  throw new Error(`deprecated, use relevant flag instead`);
@@ -138,7 +139,8 @@ class PathFollower {
138
139
 
139
140
  speed: this.speed.toJSON(),
140
141
  rotationSpeed: this.rotationSpeed.toJSON(),
141
- position: this.position
142
+ position: this.position,
143
+ maxMoveDistance: this.maxMoveDistance
142
144
  };
143
145
  }
144
146
 
@@ -176,6 +178,12 @@ class PathFollower {
176
178
  this.rotationSpeed.set(DEFAULT_ROTATION_SPEED);
177
179
  }
178
180
 
181
+ if (typeof json.maxMoveDistance === "number") {
182
+ this.maxMoveDistance = json.maxMoveDistance;
183
+ } else {
184
+ this.maxMoveDistance = DEFAULT_MAX_MOVE_DISTANCE;
185
+ }
186
+
179
187
  if (json.writePositionX !== undefined) {
180
188
  this.writeFlag(PathFollowerFlags.WritePositionX, json.writePositionX);
181
189
  }
@@ -0,0 +1,27 @@
1
+ import PathFollower from "./PathFollower.js";
2
+
3
+ test("constructor does not throw", () => {
4
+ new PathFollower();
5
+ });
6
+
7
+
8
+ test("to/from JSON consistency", () => {
9
+
10
+ const source = new PathFollower();
11
+
12
+ source.speed.set(13);
13
+ source.rotationSpeed.set(17);
14
+ source.flags = 0b1010100101;
15
+ source.maxMoveDistance = 123;
16
+ source.position = 27;
17
+
18
+ const destination = new PathFollower();
19
+
20
+ destination.fromJSON(source.toJSON());
21
+
22
+ expect(destination.speed.getValue()).toEqual(13);
23
+ expect(destination.rotationSpeed.getValue()).toEqual(17);
24
+ expect(destination.flags).toEqual(0b1010100101);
25
+ expect(destination.maxMoveDistance).toEqual(123);
26
+ expect(destination.position).toEqual(27)
27
+ });
@@ -1,8 +1,4 @@
1
1
  export class EnginePlatform {
2
- constructor() {
3
- }
4
-
5
-
6
2
  /**
7
3
  * @returns {Storage}
8
4
  */
@@ -3,15 +3,12 @@ import DataType from "../../core/parser/simple/DataType.js";
3
3
 
4
4
  export class CellFilter {
5
5
 
6
- constructor() {
7
- /**
8
- *
9
- * @type {boolean}
10
- * @protected
11
- */
12
- this.__initialized = false;
13
-
14
- }
6
+ /**
7
+ *
8
+ * @type {boolean}
9
+ * @protected
10
+ */
11
+ __initialized = false;
15
12
 
16
13
  /**
17
14
  *
@@ -3,11 +3,8 @@ import DataType from "../../../core/parser/simple/DataType.js";
3
3
  import { assert } from "../../../core/assert.js";
4
4
 
5
5
  export class CellFilterLiteralBoolean extends CellFilter {
6
- constructor() {
7
- super();
8
6
 
9
- this.value = true;
10
- }
7
+ value = true;
11
8
 
12
9
  /**
13
10
  *
@@ -1,21 +1,18 @@
1
1
  import { CellFilter } from "../CellFilter.js";
2
2
 
3
3
  export class CellFilterBinaryOperation extends CellFilter {
4
- constructor() {
5
- super();
6
-
7
- /**
8
- *
9
- * @type {CellFilter}
10
- */
11
- this.left = null;
12
-
13
- /**
14
- *
15
- * @type {CellFilter}
16
- */
17
- this.right = null;
18
- }
4
+
5
+ /**
6
+ *
7
+ * @type {CellFilter}
8
+ */
9
+ left = null;
10
+
11
+ /**
12
+ *
13
+ * @type {CellFilter}
14
+ */
15
+ right = null;
19
16
 
20
17
  /**
21
18
  * @template T,R
@@ -1,26 +1,22 @@
1
1
  import { CellFilter } from "../CellFilter.js";
2
2
 
3
3
  export class CellFilterOperationTertiary extends CellFilter {
4
- constructor() {
5
- super();
6
-
7
- /**
8
- *
9
- * @type {CellFilter}
10
- */
11
- this.a = null;
12
- /**
13
- *
14
- * @type {CellFilter}
15
- */
16
- this.b = null;
17
- /**
18
- *
19
- * @type {CellFilter}
20
- */
21
- this.c = null;
22
4
 
23
- }
5
+ /**
6
+ *
7
+ * @type {CellFilter}
8
+ */
9
+ a = null;
10
+ /**
11
+ *
12
+ * @type {CellFilter}
13
+ */
14
+ b = null;
15
+ /**
16
+ *
17
+ * @type {CellFilter}
18
+ */
19
+ c = null;
24
20
 
25
21
  /**
26
22
  *
@@ -2,15 +2,12 @@ import { CellFilter } from "../CellFilter.js";
2
2
  import { assert } from "../../../core/assert.js";
3
3
 
4
4
  export class CellFilterLiteralFloat extends CellFilter {
5
- constructor() {
6
- super();
7
-
8
- /**
9
- *
10
- * @type {number}
11
- */
12
- this.value = 1;
13
- }
5
+
6
+ /**
7
+ *
8
+ * @type {number}
9
+ */
10
+ value = 1;
14
11
 
15
12
  /**
16
13
  *
@@ -1,7 +1,7 @@
1
1
  import { ContinuousGridCellAction } from "./ContinuousGridCellAction.js";
2
2
  import Terrain from "../../../engine/ecs/terrain/ecs/Terrain.js";
3
3
  import { assert } from "../../../core/assert.js";
4
- import GridObstacle from "../../../engine/grid/components/GridObstacle.js";
4
+ import GridObstacle from "../../../engine/grid/obstacle/GridObstacle.js";
5
5
  import { CellFilterLiteralFloat } from "../../filtering/numeric/CellFilterLiteralFloat.js";
6
6
 
7
7
  export class ContinuousGridCellActionSetTerrainObstacle extends ContinuousGridCellAction {
@@ -1,8 +1,8 @@
1
1
  import { ContinuousGridCellAction } from "./ContinuousGridCellAction.js";
2
2
  import { CellFilterLiteralFloat } from "../../filtering/numeric/CellFilterLiteralFloat.js";
3
3
  import Terrain from "../../../engine/ecs/terrain/ecs/Terrain.js";
4
- import GridPosition from "../../../engine/grid/components/GridPosition.js";
5
- import GridObstacle from "../../../engine/grid/components/GridObstacle.js";
4
+ import GridPosition from "../../../engine/grid/position/GridPosition.js";
5
+ import GridObstacle from "../../../engine/grid/obstacle/GridObstacle.js";
6
6
 
7
7
 
8
8
  export class ContinuousGridCellActionWriteObstacle extends ContinuousGridCellAction {
@@ -9,7 +9,7 @@ import { BitSet } from "../../../../core/binary/BitSet.js";
9
9
  import { matcher_tag_traversable } from "../../../../../samples/generation/rules/matcher_tag_traversable.js";
10
10
  import { buildPathFromDistanceMap } from "../util/buildPathFromDistanceMap.js";
11
11
  import { GridCellActionPlaceTags } from "../../../placement/action/GridCellActionPlaceTags.js";
12
- import { GridTags } from "../../../GridTags.js";
12
+ import { GridTags } from "../../../../../samples/generation/grid/GridTags.js";
13
13
  import { CellMatcher } from "../../../rules/CellMatcher.js";
14
14
  import { collectIteratorValueToArray } from "../../../../core/collection/collectIteratorValueToArray.js";
15
15
  import { QuadTreeNode } from "../../../../core/geom/2d/quad-tree/QuadTreeNode.js";
@@ -1,5 +1,5 @@
1
1
  import { MarkerNodeAction } from "./MarkerNodeAction.js";
2
- import GridPosition from "../../../engine/grid/components/GridPosition.js";
2
+ import GridPosition from "../../../engine/grid/position/GridPosition.js";
3
3
  import { Transform } from "../../../engine/ecs/transform/Transform.js";
4
4
  import { EntityBlueprint } from "../../../engine/ecs/EntityBlueprint.js";
5
5
 
@@ -1,94 +0,0 @@
1
- /**
2
- * User: Alex Goldring
3
- * Date: 22/6/2014
4
- * Time: 20:15
5
- */
6
- import { KeyCodes } from './input/devices/KeyCodes.js';
7
- import { assert } from "../core/assert.js";
8
-
9
- /**
10
- * @deprecated use PointerDevice and KeyboardDevice respectively
11
- * @param pointerContext
12
- * @param keyContext
13
- * @constructor
14
- */
15
- const InputEngine = function (pointerContext, keyContext) {
16
- assert.defined(pointerContext, 'pointerContext');
17
- assert.defined(keyContext, 'keyContext');
18
-
19
- console.warn('deprecated, use PointerDevice and KeyboardDevice instead');
20
-
21
- const keyMap = [];
22
- const mouseMap = {};
23
-
24
- function obtainBindingByCode(code) {
25
- let binding;
26
- if (typeof (code) === "number") {
27
- if (keyMap[code] === void 0) {
28
- keyMap[code] = {};
29
- }
30
- binding = keyMap[code];
31
- } else {
32
- if (mouseMap[code] === void 0) {
33
- mouseMap[code] = {};
34
- }
35
- binding = mouseMap[code];
36
- }
37
- return binding;
38
- }
39
-
40
- this.mapKey = function (keyCode, config) {
41
- const binding = obtainBindingByCode(keyCode);
42
- if (config.on) {
43
- binding.on = config.on;
44
- }
45
- if (config.off) {
46
- binding.off = config.off;
47
- }
48
- };
49
- this.mapKeyBoolean = function (keyName, context, property) {
50
- const keyCode = KeyCodes[keyName];
51
- const binding = obtainBindingByCode(keyCode);
52
- binding.on = function () {
53
- context[property] = true;
54
- };
55
- binding.off = function () {
56
- context[property] = false;
57
- };
58
- return this;
59
- };
60
- const keyDownHandler = function (event) {
61
- const keyCode = event.keyCode;
62
- //console.log("down", keyCode);
63
- const binding = keyMap[keyCode];
64
- if (binding && binding.on) {
65
- binding.on(event);
66
- }
67
- };
68
- const keyUpHandler = function (event) {
69
- const keyCode = event.keyCode;
70
- const binding = keyMap[keyCode];
71
- if (binding && binding.off) {
72
- binding.off(event);
73
- }
74
- };
75
- const mouseUpHandler = function (event) {
76
- const mouse1 = mouseMap.mouse1;
77
- if (mouse1) {
78
- mouse1.off(event);
79
- }
80
- };
81
- const mouseDownHandler = function (event) {
82
- const mouse1 = mouseMap.mouse1;
83
- if (mouse1) {
84
- mouse1.on(event);
85
- }
86
- };
87
- keyContext.addEventListener("keydown", keyDownHandler);
88
- keyContext.addEventListener("keyup", keyUpHandler);
89
- pointerContext.addEventListener("mousedown", mouseDownHandler);
90
- pointerContext.addEventListener("mouseup", mouseUpHandler);
91
- //
92
-
93
- };
94
- export default InputEngine;
@@ -1,60 +0,0 @@
1
- /**
2
- * Created by Alex on 27/02/14.
3
- */
4
-
5
-
6
-
7
- function getPointerLockElement() {
8
- const pointerLockElement = document.pointerLockElement ||
9
- document.mozPointerLockElement ||
10
- document.webkitPointerLockElement;
11
- return pointerLockElement;
12
- }
13
-
14
- function PointerLock(element) {
15
- this.element = element;
16
- element.requestPointerLock = element.requestPointerLock ||
17
- element.mozRequestPointerLock ||
18
- element.webkitRequestPointerLock;
19
- element.exitPointerLock = element.exitPointerLock ||
20
- element.mozExitPointerLock ||
21
- element.webkitExitPointerLock;
22
- this.pointerLockError = (function (evt) {
23
- console.error("failed to lock pointer", evt);
24
- }).bind(this);
25
- this.pointerLockChange = (function (evt) {
26
- if (this.isBound()) {
27
- this.emit("locked");
28
- } else {
29
- this.unlock();
30
- }
31
- }).bind(this);
32
- }
33
-
34
- PointerLock.prototype = new EventEmitter();
35
- PointerLock.prototype.isBound = function () {
36
- return this.element === getPointerLockElement();
37
- };
38
- PointerLock.prototype.lock = function () {
39
- if (this.isBound()) {
40
- return;
41
- }
42
- document.addEventListener('pointerlockerror', this.pointerLockError, false);
43
- document.addEventListener('mozpointerlockerror', this.pointerLockError, false);
44
- document.addEventListener('webkitpointerlockerror', this.pointerLockError, false);
45
-
46
- document.addEventListener('pointerlockchange', this.pointerLockChange, false);
47
- document.addEventListener('mozpointerlockchange', this.pointerLockChange, false);
48
- document.addEventListener('webkitpointerlockchange', this.pointerLockChange, false);
49
- this.element.requestPointerLock();
50
- };
51
- PointerLock.prototype.unlock = function () {
52
- document.removeEventListener('pointerlockchange', this.pointerLockChange, false);
53
- document.removeEventListener('mozpointerlockchange', this.pointerLockChange, false);
54
- document.removeEventListener('webkitpointerlockchange', this.pointerLockChange, false);
55
- if (this.isBound()) {
56
- this.element.exitPointerLock();
57
- }
58
- this.emit("unlocked");
59
- };
60
- export default PointerLock;
@@ -1,99 +0,0 @@
1
- import { max2 } from "../../../../../core/math/max2.js";
2
- import { TerrainLayer } from "./TerrainLayer.js";
3
- import { Sampler2D } from "../../../../graphics/texture/sampler/Sampler2D.js";
4
-
5
- /**
6
- *
7
- * @param {{repeat:Vector2,textures:{diffuse:string[]}}} description
8
- * @param {TerrainLayers} layers
9
- * @param {AssetManager} am
10
- * @param {Vector2} size
11
- * @param {number} gridScale
12
- * @returns {Promise}
13
- */
14
- export function loadLegacyTerrainLayers(description, layers, am, size, gridScale) {
15
-
16
- /**
17
- *
18
- * @type {string[]}
19
- */
20
- const textures = description.textures.diffuse;
21
-
22
- /**
23
- *
24
- * @param {string} url
25
- * @param {number} layerIndex
26
- * @return {Promise<Asset>}
27
- */
28
- function loadLayer(url, layerIndex) {
29
-
30
- /**
31
- *
32
- * @type {TerrainLayer}
33
- */
34
- const layer = layers.layers.get(layerIndex);
35
-
36
- layer.textureDiffuseURL = url;
37
-
38
- return layer.loadTextureData(am);
39
- }
40
-
41
- const layerCount = textures.length;
42
-
43
- for (let i = 0; i < layerCount; i++) {
44
-
45
- const layer = new TerrainLayer();
46
-
47
-
48
- const nX = gridScale * (size.x / size.y);
49
- const nY = gridScale;
50
-
51
- layer.size.set(nX / description.repeat.x, nY / description.repeat.y);
52
-
53
- layer.diffuse = Sampler2D.uint8(3, layers.resolution.x, layers.resolution.y);
54
-
55
- layers.addLayer(layer);
56
- }
57
-
58
- layers.buildTexture();
59
-
60
- const promises = [];
61
-
62
- for (let i = 0; i < layerCount; i++) {
63
- const url = textures[i];
64
-
65
- const promise = loadLayer(url, i);
66
-
67
- promises.push(promise);
68
- }
69
-
70
- function updateResolution() {
71
-
72
- let size_x = 0;
73
- let size_y = 0;
74
-
75
- for (let i = 0; i < layerCount; i++) {
76
- const layer = layers.get(i);
77
-
78
- size_x = max2(layer.diffuse.width, size_x);
79
- size_y = max2(layer.diffuse.height, size_y);
80
- }
81
-
82
- layers.resolution.set(size_x, size_y);
83
-
84
- layers.buildTexture();
85
- }
86
-
87
- function writeLayers() {
88
-
89
- layers.writeAllLayersDataIntoTexture();
90
- }
91
-
92
-
93
- return Promise.all(promises)
94
- .then(() => {
95
- updateResolution();
96
-
97
- writeLayers();
98
- });
99
- }
@@ -1,73 +0,0 @@
1
- import { GameAssetType } from "../../../../asset/GameAssetType.js";
2
- import { max2 } from "../../../../../core/math/max2.js";
3
- import { Sampler2D } from "../../../../graphics/texture/sampler/Sampler2D.js";
4
-
5
- /**
6
- *
7
- * @param {{textures:{splat:string[]}}} description
8
- * @param {SplatMapping} mapping
9
- * @param {AssetManager} am
10
- * @returns {Promise}
11
- */
12
- export function loadLegacyTerrainSplats(description, mapping, am) {
13
-
14
-
15
- const textures = description.textures.splat;
16
-
17
- const n = textures.length;
18
-
19
- /**
20
- *
21
- * @param {string} url
22
- * @param {number} index
23
- * @return {Promise<Asset>}
24
- */
25
- function loadSplat(url, index) {
26
-
27
- return am.promise(url, GameAssetType.Image)
28
- .then(asset => {
29
-
30
- const image = asset.create();
31
-
32
- // FIXME texture array in three.js doesn't work when texture size is less than 4x4
33
- const width = max2(image.width, 4);
34
- const height = max2(image.height, 4);
35
-
36
- //create a sampler
37
- const source = new Sampler2D(image.data, 4, image.width, image.height);
38
-
39
- mapping.resize(width, height, 4);
40
-
41
- mapping.writeLayerFromSampler(source, index, 0);
42
-
43
- });
44
- }
45
-
46
- const weightPromises = [];
47
-
48
- for (let i = 0; i < n; i++) {
49
- const url = textures[i];
50
-
51
- const promise = loadSplat(url, i);
52
-
53
- weightPromises.push(promise);
54
- }
55
-
56
- return Promise.all(weightPromises)
57
- .then(() => {
58
- const materialData = mapping.materialData;
59
-
60
- const n = materialData.length;
61
-
62
- for (let i = 0; i < n; i += 4) {
63
- materialData[i] = 0;
64
- materialData[i + 1] = 1;
65
- materialData[i + 2] = 2;
66
- materialData[i + 3] = 3;
67
- }
68
-
69
- mapping.materialTexture.needsUpdate = true;
70
- mapping.weightTexture.needsUpdate = true;
71
-
72
- });
73
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * Created by Alex on 26/04/2015.
3
- */
4
- export default function (canvas) {
5
- const dataURL = canvas.toDataURL("image/png;base64;");
6
- window.open(dataURL, "", "width=" + canvas.width + ",height=" + canvas.height);
7
- };