@woosh/meep-engine 2.43.1 → 2.43.4

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 (138) hide show
  1. package/core/binary/BinaryBuffer.js +13 -1
  2. package/core/binary/BitSet.js +2 -2
  3. package/core/bvh2/aabb3/aabb3_array_combine.js +2 -2
  4. package/core/collection/RingBuffer.js +4 -2
  5. package/core/collection/RingBuffer.spec.js +59 -0
  6. package/core/collection/array/ArrayIteratorRandom.js +1 -1
  7. package/core/collection/{ArrayUtils.spec.js → array/arrayPickBestElement.spec.js} +1 -1
  8. package/core/collection/array/arrayPickBestElements.js +51 -0
  9. package/core/collection/array/arrayPickMinElement.js +43 -0
  10. package/core/collection/array/arrayQuickSort.js +1 -1
  11. package/core/collection/array/arraySetSortingDiff.js +1 -1
  12. package/core/collection/array/arraySwapElements.js +12 -0
  13. package/core/collection/array/array_range_equal_strict.js +22 -0
  14. package/core/collection/array/groupArrayBy.js +42 -0
  15. package/core/collection/array/isArrayEqual.js +50 -0
  16. package/core/collection/array/randomMultipleFromArray.js +34 -0
  17. package/core/collection/array/randomizeArrayElementOrder.js +23 -0
  18. package/core/color/sRGB_to_linear.js +9 -4
  19. package/core/geom/2d/convex-hull/convex_hull_monotone_2d.js +1 -1
  20. package/core/geom/3d/aabb/aabb3_build_frustum.js +1 -1
  21. package/core/geom/3d/aabb/compute_aabb_from_points.js +1 -1
  22. package/core/geom/3d/frustum/frustum3_computeNearestPointToPoint.js +3 -1
  23. package/core/geom/3d/morton/v3_morton_encode_transformed.spec.js +20 -0
  24. package/core/geom/3d/plane/orient3d_fast.js +11 -10
  25. package/core/geom/3d/plane/orient3d_robust.js +41 -0
  26. package/core/geom/3d/plane/plane_computeConvex3PlaneIntersection.js +0 -23
  27. package/core/geom/3d/plane/plane_three_compute_convex3_plane_intersection.js +24 -0
  28. package/core/geom/3d/shape/UnionShape3D.js +1 -1
  29. package/core/geom/3d/sphere/harmonics/README.md +15 -0
  30. package/core/geom/3d/sphere/harmonics/sh3_add.js +21 -0
  31. package/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.js +618 -0
  32. package/core/geom/3d/sphere/harmonics/sh3_sample_by_direction.js +49 -0
  33. package/core/geom/3d/sphere/harmonics/sh3_sample_irradiance_by_direction.js +53 -0
  34. package/core/geom/3d/tetrahedra/README.md +10 -1
  35. package/core/geom/3d/tetrahedra/TetrahedralMesh.js +650 -0
  36. package/core/geom/3d/tetrahedra/TetrahedralMesh.spec.js +233 -0
  37. package/core/geom/3d/tetrahedra/build_tetrahedral_mesh_buffer_geometry.js +75 -0
  38. package/core/geom/3d/tetrahedra/compute_bounding_simplex_3d.js +2 -2
  39. package/core/geom/3d/tetrahedra/compute_bounding_simplex_3d.spec.js +4 -4
  40. package/core/geom/3d/tetrahedra/delaunay/Cavity.js +49 -7
  41. package/core/geom/3d/tetrahedra/delaunay/compute_delaunay_tetrahedral_mesh.js +51 -17
  42. package/core/geom/3d/tetrahedra/delaunay/debug_validate_mesh.js +19 -0
  43. package/core/geom/3d/tetrahedra/delaunay/fill_in_a_cavity.js +191 -0
  44. package/core/geom/3d/tetrahedra/delaunay/push_boundary_with_validation.js +27 -0
  45. package/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_compute_cavity.js +59 -43
  46. package/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_compute_sub_determinant.js +77 -0
  47. package/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_compute_sub_determinant.spec.js +30 -0
  48. package/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_walk_towards_containing_tetrahedron.js +58 -0
  49. package/core/geom/3d/tetrahedra/delaunay/validate_cavity_boundary.js +60 -0
  50. package/core/geom/3d/tetrahedra/{point_in_tetrahedron_circumsphere.js → in_sphere_fast.js} +11 -13
  51. package/core/geom/3d/tetrahedra/in_sphere_robust.js +53 -0
  52. package/core/geom/3d/tetrahedra/prototypeTetrahedraBuilder.js +44 -35
  53. package/core/geom/3d/tetrahedra/tetrahedron_compute_signed_volume.js +83 -0
  54. package/core/geom/3d/tetrahedra/tetrahedron_compute_signed_volume.spec.js +24 -0
  55. package/core/geom/3d/tetrahedra/tetrahedron_contains_point.spec.js +66 -0
  56. package/core/geom/3d/tetrahedra/validate_tetrahedral_mesh.js +166 -0
  57. package/core/geom/3d/util/make_justified_point_grid.js +31 -0
  58. package/core/geom/Bezier.js +0 -27
  59. package/core/geom/Plane.js +0 -4
  60. package/core/geom/packing/miniball/Subspan.js +2 -2
  61. package/core/geom/v3_lerp.js +6 -1
  62. package/core/math/isqrt.js +28 -0
  63. package/core/math/isqrt.spec.js +9 -0
  64. package/core/math/max.spec.js +25 -0
  65. package/core/math/min2.spec.js +25 -0
  66. package/core/model/node-graph/node/NodeInstance.js +3 -3
  67. package/core/primitives/strings/prefixTree/PrefixTreeLeaf.js +1 -1
  68. package/core/process/delay.js +5 -0
  69. package/core/process/task/util/randomCountTask.js +1 -1
  70. package/editor/Editor.js +3 -0
  71. package/editor/ecs/component/editors/ecs/ParameterLookupTableEditor.js +195 -11
  72. package/editor/ecs/component/editors/ecs/ParameterTrackSetEditor.js +16 -0
  73. package/editor/ecs/component/editors/ecs/ParticleEmitterLayerEditor.js +4 -0
  74. package/editor/ecs/component/editors/primitive/ArrayEditor.js +1 -1
  75. package/editor/tools/v2/BlenderCameraOrientationGizmo.js +6 -0
  76. package/editor/view/ecs/components/common/AutoCanvasView.js +13 -25
  77. package/engine/EngineHarness.js +11 -5
  78. package/engine/asset/AssetManager.d.ts +5 -1
  79. package/engine/asset/AssetManager.js +50 -15
  80. package/engine/asset/AssetManager.spec.js +17 -11
  81. package/engine/asset/AssetRequest.js +57 -0
  82. package/engine/asset/loaders/ArrayBufferLoader.js +22 -0
  83. package/engine/asset/loaders/AssetLoader.js +1 -1
  84. package/engine/ecs/System.js +1 -1
  85. package/engine/ecs/dynamic_actions/DynamicActorSystem.js +1 -1
  86. package/engine/ecs/terrain/ecs/TerrainSystem.js +7 -1
  87. package/engine/ecs/transform/copy_three_transform.js +15 -0
  88. package/engine/graphics/FrameRunner.js +5 -9
  89. package/engine/graphics/ecs/animation/animator/AnimationClipDefinition.js +1 -1
  90. package/engine/graphics/ecs/animation/animator/graph/definition/AnimationGraphDefinition.js +1 -1
  91. package/engine/graphics/ecs/camera/Camera.js +1 -10
  92. package/engine/graphics/ecs/camera/CameraSystem.js +8 -8
  93. package/engine/graphics/ecs/camera/ProjectionType.js +9 -0
  94. package/engine/graphics/ecs/camera/build_three_camera_object.js +3 -3
  95. package/engine/graphics/ecs/decal/v2/prototypeDecalSystem.js +59 -4
  96. package/engine/graphics/ecs/light/Light.js +6 -1
  97. package/engine/graphics/ecs/light/LightSystem.d.ts +1 -1
  98. package/engine/graphics/ecs/mesh-v2/three_object_to_entity_composition.js +2 -17
  99. package/engine/graphics/geometry/VertexDataSpec.js +1 -1
  100. package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +2 -2
  101. package/engine/graphics/impostors/octahedral/prototypeBaker.js +3 -3
  102. package/engine/graphics/micron/plugin/GLTFAssetTransformer.js +1 -1
  103. package/engine/graphics/micron/plugin/MicronRenderPlugin.js +3 -1
  104. package/engine/graphics/particles/node-based/codegen/modules/FunctionSignature.js +1 -1
  105. package/engine/graphics/render/forward_plus/LightManager.js +1 -1
  106. package/engine/graphics/render/forward_plus/LightManager.spec.js +4 -0
  107. package/engine/graphics/render/forward_plus/computeFrustumCorners.js +4 -2
  108. package/engine/graphics/render/forward_plus/prototype/prototypeLightManager.js +2 -2
  109. package/engine/graphics/render/layers/RenderLayerUtils.js +2 -2
  110. package/engine/graphics/sh3/LightProbeVolume.js +595 -0
  111. package/engine/graphics/sh3/SH3VisualisationMaterial.js +79 -0
  112. package/engine/graphics/sh3/prototypeSH3Probe.js +427 -0
  113. package/engine/graphics/sh3/visualise_probe.js +40 -0
  114. package/engine/graphics/shaders/DenoiseShader.js +1 -1
  115. package/engine/graphics/texture/atlas/AtlasPatch.js +11 -3
  116. package/engine/graphics/texture/atlas/CachingTextureAtlas.js +2 -2
  117. package/engine/graphics/texture/atlas/TextureAtlas.js +22 -4
  118. package/engine/graphics/texture/atlas/TextureAtlas.spec.js +22 -0
  119. package/engine/graphics/texture/sampler/Sampler2D.js +0 -64
  120. package/engine/graphics/texture/sampler/Sampler2D.spec.js +2 -1
  121. package/engine/graphics/texture/sampler/sampler2d_combine.js +67 -0
  122. package/engine/intelligence/behavior/ecs/BehaviorSystem.spec.js +0 -3
  123. package/engine/intelligence/blackboard/AbstractBlackboard.d.ts +1 -1
  124. package/engine/network/PriorityFetch.js +192 -0
  125. package/engine/simulation/DormandPrince.js +1 -1
  126. package/engine/ui/DraggableAspect.js +0 -1
  127. package/generation/grid/generation/road/GridTaskGenerateRoads.js +1 -1
  128. package/package.json +2 -1
  129. package/samples/terrain/from_image_2.js +127 -82
  130. package/view/elements/CanvasView.js +7 -1
  131. package/view/elements/image/HTMLElementCacheKey.js +1 -1
  132. package/view/util/DomSizeObserver.js +3 -5
  133. package/core/collection/ArrayUtils.js +0 -263
  134. package/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_walk_toward_cavity.js +0 -48
  135. package/core/geom/3d/tetrahedra/hxt/a.js +0 -524
  136. package/core/geom/3d/tetrahedra/hxt/hxt.js +0 -140
  137. package/core/geom/3d/tetrahedra/hxt/hxt.wasm +0 -0
  138. package/core/geom/3d/tetrahedra/tetrahedra_collection.js +0 -383
@@ -1,4 +1,5 @@
1
1
  import { Sampler2D } from "./Sampler2D.js";
2
+ import { sampler2d_combine } from "./sampler2d_combine.js";
2
3
 
3
4
  test("constructor arguments", () => {
4
5
  const uint8Array = new Uint8Array(24);
@@ -217,7 +218,7 @@ test('Sampler2.combine ADD', () => {
217
218
 
218
219
  const ut = new Sampler2D(new Array(8), 2, 2, 2);
219
220
 
220
- Sampler2D.combine(s0, s1, ut, function (arg0, arg1, res, index) {
221
+ sampler2d_combine(s0, s1, ut, function (arg0, arg1, res, index) {
221
222
  res[0] = arg0[0] + arg1[0];
222
223
  res[1] = arg0[1] + arg1[1];
223
224
  });
@@ -0,0 +1,67 @@
1
+ import { assert } from "../../../../core/assert.js";
2
+
3
+
4
+ /**
5
+ * Execute a binary operation with 2 input samplers and an output
6
+ * @param {Sampler2D} input0
7
+ * @param {Sampler2D} input1
8
+ * @param {Sampler2D} result
9
+ * @param {function( value0 : number[], value1 : number[], result : number[], index : number) : void} operation
10
+ */
11
+ export function sampler2d_combine(input0, input1, result, operation) {
12
+ assert.notEqual(input0, undefined, "input0 is undefined");
13
+ assert.notEqual(input1, undefined, "input1 is undefined");
14
+ assert.notEqual(result, undefined, "result is undefined");
15
+
16
+ assert.typeOf(operation, "function", "operation");
17
+
18
+ assert.equal(input0.width, input1.width, `input0.width(=${input0.width}) is not equal to input1.width(=${input1.width})`);
19
+ assert.equal(input0.height, input1.height, `input0.height(=${input0.height}) is not equal to input1.height(=${input1.height})`);
20
+
21
+ assert.equal(input0.width, result.width, `input width(=${input0.width}) is not equal to result.width(=${result.width})`);
22
+ assert.equal(input0.height, result.height, `input height(=${input0.height}) is not equal to result.height(=${result.height})`);
23
+
24
+ const width = input0.width;
25
+ const height = input0.height;
26
+
27
+ const length = width * height;
28
+
29
+ const arg0 = [];
30
+ const arg1 = [];
31
+ const res = [];
32
+
33
+ const itemSize0 = input0.itemSize;
34
+ const itemSize1 = input1.itemSize;
35
+ const itemSizeR = result.itemSize;
36
+
37
+ const data0 = input0.data;
38
+ const data1 = input1.data;
39
+ const dataR = result.data;
40
+
41
+
42
+ let i, j;
43
+
44
+ for (i = 0; i < length; i++) {
45
+
46
+ // read input 0
47
+ for (j = 0; j < itemSize0; j++) {
48
+ arg0[j] = data0[j + i * itemSize0];
49
+ }
50
+
51
+ // read input 1
52
+ for (j = 0; j < itemSize0; j++) {
53
+ arg1[j] = data1[j + i * itemSize1];
54
+ }
55
+
56
+ //perform operation
57
+ operation(arg0, arg1, res, i);
58
+
59
+ //write result
60
+ for (j = 0; j < itemSizeR; j++) {
61
+ dataR[j + i * itemSizeR] = res[j];
62
+ }
63
+
64
+ }
65
+
66
+ result.version++;
67
+ }
@@ -1,7 +1,6 @@
1
1
  import { BehaviorSystem } from "./BehaviorSystem.js";
2
2
  import { BehaviorComponent } from "./BehaviorComponent.js";
3
3
  import { Behavior } from "../Behavior.js";
4
- import { BehaviorStatus } from "../BehaviorStatus.js";
5
4
  import { EntityComponentDataset } from "../../../ecs/EntityComponentDataset.js";
6
5
  import { EntityManager } from "../../../ecs/EntityManager.js";
7
6
  import { noop } from "../../../../core/function/Functions.js";
@@ -44,7 +43,6 @@ test("unlinking finalizes behavior if it is running", () => {
44
43
 
45
44
  const behavior = new Behavior();
46
45
  behavior.finalize = jest.fn();
47
- behavior.setStatus(BehaviorStatus.Running);
48
46
 
49
47
  s.unlink(BehaviorComponent.fromOne(behavior), 0);
50
48
 
@@ -56,7 +54,6 @@ test("update ticks behavior with the time delta", () => {
56
54
 
57
55
  const behavior = new Behavior();
58
56
  behavior.tick = jest.fn();
59
- behavior.setStatus(BehaviorStatus.Running);
60
57
 
61
58
  const behaviorComponent = BehaviorComponent.fromOne(behavior);
62
59
 
@@ -1,5 +1,5 @@
1
1
  import ObservedBoolean from "../../../core/model/ObservedBoolean";
2
- import {Vector1} from "../../../core/geom/Vector1";
2
+ import Vector1 from "../../../core/geom/Vector1";
3
3
  import ObservedString from "../../../core/model/ObservedString";
4
4
 
5
5
  export class AbstractBlackboard {
@@ -0,0 +1,192 @@
1
+ import FastBinaryHeap from "../../core/collection/heap/FastBinaryHeap.js";
2
+ import { noop } from "../../core/function/Functions.js";
3
+ import { assert } from "../../core/assert.js";
4
+
5
+ /**
6
+ * @readonly
7
+ * @type {{high: number, auto: number, low: number}}
8
+ */
9
+ const priority_value_map = {
10
+ "high": 10,
11
+ "low": -1,
12
+ "auto": 0
13
+ };
14
+
15
+ /**
16
+ *
17
+ * @param {string|undefined} p
18
+ * @return {number}
19
+ */
20
+ function extract_priority_from_resource(p) {
21
+
22
+ let v = 0;
23
+
24
+ if (typeof p === "string") {
25
+ v = priority_value_map[p];
26
+
27
+ if (v === undefined) {
28
+ console.warn(`Unsupported request priority value '${p}', defaulting to 'auto'`);
29
+ }
30
+
31
+ v = priority_value_map['auto'];
32
+ }
33
+
34
+ return v;
35
+
36
+ }
37
+
38
+ class FetchRequest {
39
+ /**
40
+ *
41
+ * @param {Request|string} resource
42
+ * @param {{}} options
43
+ */
44
+ constructor(resource, options) {
45
+ let priority = 0;
46
+
47
+ this.__resource = resource;
48
+ this.__options = options;
49
+
50
+ if (typeof this.__resource === "object" && typeof this.__resource.priority !== "undefined") {
51
+ priority = extract_priority_from_resource(this.__resource.priority);
52
+ }
53
+
54
+ this.__priority = priority;
55
+
56
+ this.fulfillment = {
57
+ resolve: null, reject: null
58
+ };
59
+
60
+ this.promise = new Promise((resolve, reject) => {
61
+ this.fulfillment.resolve = resolve;
62
+ this.fulfillment.reject = reject;
63
+ });
64
+ }
65
+ }
66
+
67
+ /**
68
+ *
69
+ * @param {FetchRequest} request
70
+ * @returns {number}
71
+ */
72
+ function get_priority_score(request) {
73
+ return -request.__priority;
74
+ }
75
+
76
+ /**
77
+ * @readonly
78
+ * @type {number}
79
+ */
80
+ const DEFAULT_CONCURRENCY = Infinity;
81
+
82
+ /**
83
+ * Wraps {@link fetch} api and adds concurrency management to it by queueing requests,
84
+ * as well as prioritization in that queue
85
+ */
86
+ export class PriorityFetch {
87
+ constructor({
88
+ adapter = noop,
89
+ concurrency = DEFAULT_CONCURRENCY
90
+ }) {
91
+ /**
92
+ *
93
+ * @type {number}
94
+ * @private
95
+ */
96
+ this.__concurrency = concurrency;
97
+
98
+ /**
99
+ *
100
+ * @type {BinaryHeap<FetchRequest>}
101
+ * @private
102
+ */
103
+ this.__queue = new FastBinaryHeap(get_priority_score);
104
+
105
+ /**
106
+ *
107
+ * @type {Set<FetchRequest>}
108
+ * @private
109
+ */
110
+ this.__pending_set = new Set();
111
+
112
+ /**
113
+ *
114
+ * @type {null}
115
+ * @private
116
+ */
117
+ this.__adapter = adapter;
118
+ }
119
+
120
+ /**
121
+ *
122
+ * @param {function} v
123
+ */
124
+ set adapter(v) {
125
+ this.__adapter = v;
126
+ }
127
+
128
+ /**
129
+ *
130
+ * @param {number} v
131
+ */
132
+ set concurrency(v) {
133
+ assert.isNumber(v, 'v');
134
+ assert.notNaN(v, 'v');
135
+ assert.greaterThan(v, 0, 'concurrency must be greater than 0');
136
+
137
+ this.__concurrency = v;
138
+ }
139
+
140
+ /**
141
+ *
142
+ * @return {number}
143
+ */
144
+ get concurrency() {
145
+ return this.__concurrency;
146
+ }
147
+
148
+ /**
149
+ *
150
+ * @param {FetchRequest} req
151
+ * @private
152
+ */
153
+ __dispatch(req) {
154
+ const promise = this.__adapter(req.__resource, req.__options);
155
+
156
+ promise.finally(() => {
157
+ this.__pending_set.delete(req);
158
+
159
+ this.__prod();
160
+ });
161
+
162
+ promise
163
+ .then(
164
+ (v) => {
165
+ req.fulfillment.resolve(v);
166
+ },
167
+ (reason) => {
168
+ req.fulfillment.reject(reason);
169
+ }
170
+ );
171
+ }
172
+
173
+ __prod() {
174
+ if (this.__pending_set.size < this.__concurrency && !this.__queue.isEmpty()) {
175
+ const req = this.__queue.pop();
176
+
177
+ this.__dispatch(req);
178
+ }
179
+ }
180
+
181
+ fetch(resource, options) {
182
+ const req = new FetchRequest(resource, options);
183
+
184
+ if (this.__pending_set.size < this.__concurrency) {
185
+ this.__dispatch(req);
186
+ } else {
187
+ this.__queue.push(req);
188
+ }
189
+
190
+ return req.promise;
191
+ }
192
+ }
@@ -166,7 +166,7 @@ function computeStepSize(fxy, x, y, suggestedStepSize, tolerance, maxIterations,
166
166
  * @param {number} hmax max step size
167
167
  * @param {number} hmin min step size
168
168
  * @param {number} max_iteration maximum number of iterations
169
- * @returns {*[]}
169
+ * @returns {Array.<number>}
170
170
  */
171
171
  function odedopri(fxy, x0, y0, x1, tol, hmax, hmin, max_iteration) {
172
172
 
@@ -34,7 +34,6 @@ export class DraggableAspect {
34
34
  const pointerGlobal = this.pointerGlobal = new PointerDevice(window);
35
35
 
36
36
  const dragOriginalPosition = new Vector2();
37
- const delta = new Vector2();
38
37
  const pointer_position_last = new Vector2();
39
38
 
40
39
  if (stopPropagation) {
@@ -11,7 +11,6 @@ import { buildPathFromDistanceMap } from "../util/buildPathFromDistanceMap.js";
11
11
  import { GridCellActionPlaceTags } from "../../../placement/action/GridCellActionPlaceTags.js";
12
12
  import { GridTags } from "../../../GridTags.js";
13
13
  import { CellMatcher } from "../../../rules/CellMatcher.js";
14
- import { groupArrayBy } from "../../../../core/collection/ArrayUtils.js";
15
14
  import { collectIteratorValueToArray } from "../../../../core/collection/IteratorUtils.js";
16
15
  import { QuadTreeNode } from "../../../../core/geom/2d/quad-tree/QuadTreeNode.js";
17
16
  import AABB2 from "../../../../core/geom/AABB2.js";
@@ -24,6 +23,7 @@ import { RoadConnectionNetwork } from "./RoadConnectionNetwork.js";
24
23
  import { MirGridLayers } from "../../../example/grid/MirGridLayers.js";
25
24
  import { actionTask } from "../../../../core/process/task/util/actionTask.js";
26
25
  import { countTask } from "../../../../core/process/task/util/countTask.js";
26
+ import { groupArrayBy } from "../../../../core/collection/array/groupArrayBy.js";
27
27
 
28
28
  const NODE_TYPE_ROAD_CONNECTOR = 'Road Connector';
29
29
 
package/package.json CHANGED
@@ -5,12 +5,13 @@
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.43.1",
8
+ "version": "2.43.4",
9
9
  "dependencies": {
10
10
  "gl-matrix": "3.4.3",
11
11
  "fast-levenshtein": "2.0.6",
12
12
  "opentype.js": "1.3.3",
13
13
  "simplex-noise": "2.4.0",
14
+ "robust-predicates": "3.0.1",
14
15
  "three": "^0.135.0"
15
16
  },
16
17
  "devDependencies": {
@@ -7,7 +7,6 @@ import EntityBuilder from "../../engine/ecs/EntityBuilder.js";
7
7
  import Terrain from "../../engine/ecs/terrain/ecs/Terrain.js";
8
8
  import { ImageRGBADataLoader } from "../../engine/asset/loaders/image/ImageRGBADataLoader.js";
9
9
  import TerrainSystem from "../../engine/ecs/terrain/ecs/TerrainSystem.js";
10
- import WaterSystem from "../../engine/graphics/ecs/water/WaterSystem.js";
11
10
  import Water from "../../engine/graphics/ecs/water/Water.js";
12
11
  import {
13
12
  AmbientOcclusionPostProcessEffect
@@ -16,73 +15,42 @@ import { TerrainLayer } from "../../engine/ecs/terrain/ecs/layers/TerrainLayer.j
16
15
  import Mesh from "../../engine/graphics/ecs/mesh/Mesh.js";
17
16
  import { Transform } from "../../engine/ecs/transform/Transform.js";
18
17
  import { MeshSystem } from "../../engine/graphics/ecs/mesh/MeshSystem.js";
19
- import { enableEditor } from "../../editor/enableEditor.js";
20
- import "../../../../../css/main.scss";
21
- import '../../../../../css/editor/EntityEditorView.scss';
22
- import '../../../../../css/editor/EditorView.scss';
23
- import { initializeEditor } from "../../../model/game/initializeEditor.js";
18
+ import ButtonView from "../../view/elements/button/ButtonView.js";
19
+ import { downloadAsFile } from "../../core/binary/ByteArrayTools.js";
24
20
 
25
21
  const HEIGHT_RANGE = 64;
26
22
 
27
23
  const eh = new EngineHarness();
28
24
 
29
- /**
30
- *
31
- * @param {Engine} engine
32
- * @return {EngineConfiguration}
33
- */
34
- function makeConfig(engine) {
35
- const r = new EngineConfiguration();
36
-
37
- // configure engine here, add systems, loaders etc.
38
- r.addLoader(GameAssetType.Texture, new TextureAssetLoader());
39
- r.addLoader(GameAssetType.Image, new ImageRGBADataLoader());
40
-
41
-
42
- r.addSystem(new TerrainSystem(engine.graphics, engine.assetManager));
43
- r.addSystem(new WaterSystem(engine.graphics));
44
- r.addSystem(new MeshSystem(engine));
45
-
46
- r.addPlugin(AmbientOcclusionPostProcessEffect);
47
-
48
- return r;
49
- }
50
25
 
51
26
  /**
52
27
  *
53
- * @param {string} path
54
- * @param {AssetManager} am
28
+ * @param {Sampler2D} source
29
+ * @param {Terrain} terrain
55
30
  */
56
- async function load_sampler(path, am) {
57
-
58
- const asset = await am.promise(path, 'image');
31
+ function scale_terrain_heights(source, terrain) {
32
+ const source_height_data = source.data;
33
+ const sampler_pixel_count = source_height_data.length;
34
+ const terrain_height_data = terrain.samplerHeight.data;
59
35
 
60
- /**
61
- *
62
- * @type {Sampler2D}
63
- */
64
- const sampler = asset.create();
36
+ let divisor;
37
+ if (source_height_data instanceof Uint8Array) {
38
+ divisor = 255;
39
+ } else if (source_height_data instanceof Uint16Array) {
40
+ divisor = 65536 - 1;
41
+ }
65
42
 
66
- return sampler;
67
- }
43
+ for (let i = 0; i < sampler_pixel_count; i++) {
44
+ const source_v = source_height_data[i];
68
45
 
69
- /**
70
- *
71
- * @param {string} path
72
- * @param {Engine} engine
73
- * @param {Transform} transform
74
- */
75
- async function load_gltf(path, engine, transform) {
76
- const em = engine.entityManager;
46
+ const b0 = source_v & 0xFF;
47
+ const b1 = (source_v >> 8) & 0xFF;
77
48
 
78
- const ecd = em.dataset;
49
+ let rotated_v;
50
+ rotated_v = b1 | (b0 << 8);
79
51
 
80
- new EntityBuilder()
81
- .add(Mesh.fromJSON({
82
- url: path
83
- }))
84
- .add(transform)
85
- .build(ecd);
52
+ terrain_height_data[i] = (rotated_v / divisor) * HEIGHT_RANGE
53
+ }
86
54
  }
87
55
 
88
56
  /**
@@ -139,43 +107,22 @@ async function main(engine) {
139
107
  await load_splat_layer("moicon/23_Nov_21_Skogplanter/01/splat_stone.png", 2);
140
108
 
141
109
  terrain.samplerHeight.resize(sampler.width, sampler.height);
142
- const source_height_data = sampler.data;
143
- const sampler_pixel_count = source_height_data.length;
144
- const terrain_height_data = terrain.samplerHeight.data;
145
-
146
- let divisor;
147
- if (source_height_data instanceof Uint8Array) {
148
- divisor = 255;
149
- } else if (source_height_data instanceof Uint16Array) {
150
- divisor = 65536 - 1;
151
- }
152
-
153
- for (let i = 0; i < sampler_pixel_count; i++) {
154
- const source_v = source_height_data[i];
155
-
156
- const b0 = source_v & 0xFF;
157
- const b1 = (source_v >> 8) & 0xFF;
158
-
159
- let rotated_v;
160
- rotated_v = b1 | (b0 << 8);
161
-
162
- terrain_height_data[i] = (rotated_v / divisor) * HEIGHT_RANGE
163
- }
110
+ scale_terrain_heights(sampler, terrain);
164
111
 
165
112
  terrain.layers.resolution.set(1024, 1024);
166
113
 
167
114
  terrain.layers.addLayer(TerrainLayer.from(
168
- "data/textures/materials/terrain_township_set/Grass_2.png",
115
+ "moicon/23_Nov_21_Skogplanter/01/textures/Grass_2.png",
169
116
  20,
170
117
  20
171
118
  ));
172
119
  terrain.layers.addLayer(TerrainLayer.from(
173
- "data/textures/materials/terrain_township_set/1024/Ground_1_dark.png",
120
+ "moicon/23_Nov_21_Skogplanter/01/textures/Ground_1_dark.png",
174
121
  20,
175
122
  20
176
123
  ));
177
124
  terrain.layers.addLayer(TerrainLayer.from(
178
- "data/textures/materials/Sci-Fi Planet/Sand_01.png",
125
+ "moicon/23_Nov_21_Skogplanter/01/textures/Sand_01.png",
179
126
  20,
180
127
  20
181
128
  ));
@@ -188,7 +135,8 @@ async function main(engine) {
188
135
  water.shoreDepthTransition.set(0.1, 0.3);
189
136
  water.scattering.set(3);
190
137
 
191
- new EntityBuilder()
138
+ const terrain_builder = new EntityBuilder();
139
+ terrain_builder
192
140
  .add(terrain)
193
141
  // .add(water)
194
142
  .build(ecd);
@@ -204,6 +152,47 @@ async function main(engine) {
204
152
  load_gltf("moicon/23_Nov_21_Skogplanter/02/model.gltf", engine, transform);
205
153
  // load_gltf("moicon/23_Nov_21_Skogplanter/03/model.gltf", engine, transform);
206
154
  // load_gltf("moicon/23_Nov_21_Skogplanter/04/model.gltf", engine, transform);
155
+
156
+ engine.gui.view.addChild(new ButtonView({
157
+ name: 'Download',
158
+ action() {
159
+ // we wrap the terrain data into "component json" format that meep editor recognizes to make this compatible with the standalone terrain editor
160
+ const json_payload = {
161
+ type: "Terrain",
162
+ data: terrain.toJSON()
163
+ };
164
+
165
+ downloadAsFile(
166
+ JSON.stringify(json_payload),
167
+ 'terrain.json'
168
+ );
169
+ },
170
+ css: {
171
+ bottom: '4px',
172
+ left: '4px',
173
+ position: 'absolute',
174
+ background: 'white',
175
+ border: '1px solid black',
176
+ padding: '2px',
177
+ pointerEvents: 'auto'
178
+ }
179
+ }));
180
+
181
+ engine.gui.view.addChild(new ButtonView({
182
+ name: 'Remove',
183
+ action() {
184
+ engine.entityManager.dataset.removeEntity(terrain_builder.entity);
185
+ },
186
+ css: {
187
+ bottom: '4px',
188
+ left: '104px',
189
+ position: 'absolute',
190
+ background: 'white',
191
+ border: '1px solid black',
192
+ padding: '2px',
193
+ pointerEvents: 'auto'
194
+ }
195
+ }));
207
196
  }
208
197
 
209
198
  /**
@@ -215,11 +204,67 @@ async function init(harness) {
215
204
 
216
205
  await makeConfig(engine).apply(engine);
217
206
 
218
- enableEditor(engine,initializeEditor);
219
-
220
207
  await eh.initialize();
221
208
 
222
209
  main(engine);
223
210
  }
224
211
 
225
212
  init(eh);
213
+
214
+ /**
215
+ *
216
+ * @param {Engine} engine
217
+ * @return {EngineConfiguration}
218
+ */
219
+ function makeConfig(engine) {
220
+ const r = new EngineConfiguration();
221
+
222
+ // configure engine here, add systems, loaders etc.
223
+ r.addLoader(GameAssetType.Texture, new TextureAssetLoader());
224
+ r.addLoader(GameAssetType.Image, new ImageRGBADataLoader());
225
+
226
+
227
+ r.addSystem(new TerrainSystem(engine.graphics, engine.assetManager));
228
+ r.addSystem(new MeshSystem(engine));
229
+
230
+ r.addPlugin(AmbientOcclusionPostProcessEffect);
231
+
232
+ return r;
233
+ }
234
+
235
+ /**
236
+ *
237
+ * @param {string} path
238
+ * @param {AssetManager} am
239
+ */
240
+ async function load_sampler(path, am) {
241
+
242
+ const asset = await am.promise(path, 'image');
243
+
244
+ /**
245
+ *
246
+ * @type {Sampler2D}
247
+ */
248
+ const sampler = asset.create();
249
+
250
+ return sampler;
251
+ }
252
+
253
+ /**
254
+ *
255
+ * @param {string} path
256
+ * @param {Engine} engine
257
+ * @param {Transform} transform
258
+ */
259
+ async function load_gltf(path, engine, transform) {
260
+ const em = engine.entityManager;
261
+
262
+ const ecd = em.dataset;
263
+
264
+ new EntityBuilder()
265
+ .add(Mesh.fromJSON({
266
+ url: path
267
+ }))
268
+ .add(transform)
269
+ .build(ecd);
270
+ }
@@ -1,6 +1,8 @@
1
1
  import View from "../View.js";
2
2
 
3
-
3
+ /**
4
+ * Wrapper around {@link HTMLCanvasElement}, exposes {@link CanvasRenderingContext2D}
5
+ */
4
6
  export class CanvasView extends View {
5
7
  constructor() {
6
8
  super();
@@ -8,6 +10,10 @@ export class CanvasView extends View {
8
10
  const canvas = document.createElement('canvas');
9
11
  this.el = canvas;
10
12
 
13
+ /**
14
+ *
15
+ * @type {CanvasRenderingContext2D}
16
+ */
11
17
  this.context2d = canvas.getContext('2d');
12
18
 
13
19
  this.size.onChanged.add(this.__handleSizeChange, this);
@@ -1,8 +1,8 @@
1
- import { isArrayEqual } from "../../../core/collection/ArrayUtils.js";
2
1
  import { KeyValuePair } from "../../../core/collection/KeyValuePair.js";
3
2
  import { computeStringHash } from "../../../core/primitives/strings/computeStringHash.js";
4
3
  import { computeHashArray } from "../../../core/collection/array/computeHashArray.js";
5
4
  import { computeHashIntegerArray } from "../../../core/collection/array/computeHashIntegerArray.js";
5
+ import { isArrayEqual } from "../../../core/collection/array/isArrayEqual.js";
6
6
 
7
7
  /**
8
8
  *