@woosh/meep-engine 2.33.60 → 2.33.64

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 (89) hide show
  1. package/core/geom/3d/SurfacePoint3.js +44 -5
  2. package/core/geom/Vector2.d.ts +2 -0
  3. package/core/geom/packing/MaxRectangles.js +13 -4
  4. package/core/math/hash/murmur3_32.js +3 -3
  5. package/ecs/grid/pick.js +44 -0
  6. package/editor/actions/concrete/PaintTerrainOverlayAction.js +1 -1
  7. package/editor/process/ObstacleGridDisplayProcess.js +1 -1
  8. package/editor/process/symbolic/makeGridPositionSymbolDisplay.js +1 -1
  9. package/editor/tools/FoliagePaintTool.js +1 -1
  10. package/editor/tools/GridPaintTool.js +2 -2
  11. package/editor/tools/paint/TerrainPaintTool.js +2 -2
  12. package/editor/tools/paint/TerrainTexturePaintTool.js +1 -1
  13. package/editor/view/EditorView.js +1 -1
  14. package/editor/view/GridPickCoordinateView.js +2 -2
  15. package/engine/asset/loaders/material/computeTextureHash.js +7 -13
  16. package/engine/ecs/animation/InverseKinematicsSystem.js +1 -1
  17. package/engine/ecs/attachment/AttachmentSystem.js +9 -56
  18. package/engine/ecs/evaluation/world/ReadTerrainLayerWeightPointFitness.js +1 -1
  19. package/engine/ecs/fow/FogOfWarRevealerSystem.js +2 -2
  20. package/engine/ecs/grid/HeightMap2NormalMap.js +1 -1
  21. package/engine/ecs/grid/NormalMap2AOMap.js +1 -1
  22. package/engine/ecs/gui/position/ViewportPositionSystem.js +5 -5
  23. package/engine/ecs/parent/EntityNode.d.ts +20 -0
  24. package/engine/ecs/parent/EntityNode.js +284 -0
  25. package/engine/ecs/parent/FaceEditor.js +137 -0
  26. package/engine/ecs/parent/testCompositionEntityNode.js +153 -0
  27. package/engine/ecs/parent/testHuDPerf.js +123 -0
  28. package/engine/ecs/team/Team.js +82 -0
  29. package/engine/ecs/terrain/ecs/ClingToTerrainSystem.js +2 -2
  30. package/engine/ecs/terrain/ecs/Terrain.js +14 -5
  31. package/engine/ecs/terrain/util/loadVisibleTerrainTiles.js +112 -0
  32. package/engine/ecs/terrain/util/obtainTerrain.js +23 -0
  33. package/engine/ecs/tooltip/TooltipComponentSystem.js +1 -1
  34. package/engine/graphics/GraphicsEngine.js +1 -2
  35. package/engine/graphics/camera/testClippingPlaneComputation.js +0 -4
  36. package/engine/graphics/ecs/camera/topdown/TopDownCameraLanderSystem.js +1 -1
  37. package/engine/graphics/ecs/light/LightSystem.js +1 -1
  38. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +29 -0
  39. package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +158 -1
  40. package/engine/graphics/ecs/path/testPathDisplaySystem.js +0 -2
  41. package/engine/graphics/ecs/water/WaterSystem.js +1 -1
  42. package/engine/graphics/ecs/water2/shader/testWaterShader.js +1 -1
  43. package/engine/graphics/geometry/AttributeSpec.d.ts +8 -0
  44. package/engine/graphics/geometry/VertexDataSpec.d.ts +15 -0
  45. package/engine/graphics/geometry/buffered/deinterleaveBufferAttribute.js +39 -0
  46. package/engine/graphics/geometry/buffered/deinterleaveBufferGeometry.js +50 -0
  47. package/engine/graphics/geometry/buffered/query/GeometrySpatialQueryAccelerator.js +55 -11
  48. package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +10 -7
  49. package/engine/graphics/micron/format/MicronGeometry.d.ts +4 -0
  50. package/engine/graphics/micron/render/v1/MaterialContext.js +1 -0
  51. package/engine/graphics/particles/particular/engine/simulator/SimulationStepFixedPhysics.js +19 -3
  52. package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +2 -4
  53. package/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +0 -2
  54. package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +2 -4
  55. package/engine/graphics/render/frame_graph/FrameGraphBuilder.js +36 -0
  56. package/engine/graphics/render/frame_graph/IRenderContext.js +8 -0
  57. package/engine/graphics/render/frame_graph/RenderPass.js +32 -0
  58. package/engine/graphics/render/frame_graph/RenderPassFlags.js +6 -0
  59. package/engine/graphics/render/frame_graph/RenderPassResources.js +15 -0
  60. package/engine/graphics/render/frame_graph/Resource.js +21 -0
  61. package/engine/graphics/render/frame_graph/ResourceReference.js +14 -0
  62. package/engine/graphics/render/frame_graph/TextureDescriptor.js +30 -0
  63. package/engine/graphics/render/frame_graph/UsageModeType.js +5 -0
  64. package/engine/graphics/render/frame_graph/sample/deferred/GBufferDrawPass.js +27 -0
  65. package/engine/graphics/render/frame_graph/sample/deferred/PresentPass.js +17 -0
  66. package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +0 -2
  67. package/engine/graphics/render/webgpu/sample/MeshInstance.js +108 -0
  68. package/engine/graphics/render/webgpu/sample/fragmentDeferredRendering.wgsl +71 -0
  69. package/engine/graphics/render/webgpu/sample/fragmentGBuffersDebugView.wgsl +39 -0
  70. package/engine/graphics/render/webgpu/sample/fragmentWriteGBuffers.wgsl +21 -0
  71. package/engine/graphics/render/webgpu/sample/lightUpdate.wgsl +41 -0
  72. package/engine/graphics/render/webgpu/sample/main.js +604 -0
  73. package/engine/graphics/render/webgpu/sample/vertexTextureQuad.wgsl +9 -0
  74. package/engine/graphics/render/webgpu/sample/vertexWriteGBuffers.wgsl +30 -0
  75. package/engine/graphics/shadows/testShadowMapRendering.js +0 -2
  76. package/engine/{ecs/grid → graphics/texture/sampler}/sampler2DToFloat32Texture.js +1 -1
  77. package/engine/graphics/util/modelHitTest.js +63 -0
  78. package/engine/grid/systems/GridPosition2TransformSystem.js +1 -1
  79. package/engine/grid/systems/ViewportGridProjectionSystem.js +1 -1
  80. package/engine/grid/transform2grid/Transform2GridPositionSystem.js +1 -1
  81. package/engine/scene/transitionToScene.js +1 -1
  82. package/generation/grid/actions/ContinuousGridCellActionSetTerrainHeight.js +1 -1
  83. package/generation/markers/actions/placement/MarkerNodeEntityProcessorClingToTerrain.js +1 -1
  84. package/generation/markers/debug/visualizeMarkers.js +1 -1
  85. package/generation/theme/ThemeEngine.js +1 -1
  86. package/package.json +1 -1
  87. package/samples/terrain/main.js +117 -0
  88. package/view/minimap/Minimap.js +1 -1
  89. package/engine/ecs/sockets/AttachmentSocketsSystem.js +0 -10
@@ -0,0 +1,284 @@
1
+ import { ParentEntity } from "./ParentEntity.js";
2
+ import EntityBuilder from "../EntityBuilder.js";
3
+ import { array_remove_first } from "../../../core/collection/array/array_remove_first.js";
4
+ import { assert } from "../../../core/assert.js";
5
+ import { array_push_if_unique } from "../../../core/collection/array/array_push_if_unique.js";
6
+ import { Attachment } from "../attachment/Attachment.js";
7
+ import { AttachmentSockets } from "../sockets/AttachmentSockets.js";
8
+ import { AttachmentSocket } from "../sockets/AttachmentSocket.js";
9
+ import { Transform } from "../transform/Transform.js";
10
+
11
+ export class EntityNode {
12
+ /**
13
+ *
14
+ * @param {EntityBuilder} [entity] optional entity to be wrapped
15
+ */
16
+ constructor(entity = new EntityBuilder()) {
17
+ /**
18
+ *
19
+ * @type {EntityNode|null}
20
+ * @private
21
+ */
22
+ this.__parent = null;
23
+ /**
24
+ *
25
+ * @type {EntityBuilder}
26
+ * @private
27
+ */
28
+ this.__entity = entity;
29
+ /**
30
+ *
31
+ * @type {EntityNode[]}
32
+ * @private
33
+ */
34
+ this.__children = [];
35
+
36
+ /**
37
+ *
38
+ * @type {Transform}
39
+ * @private
40
+ */
41
+ this.__transform = new Transform();
42
+ }
43
+
44
+ /**
45
+ *
46
+ * @private
47
+ */
48
+ __transform_sync_down() {
49
+
50
+ if (this.__parent === null) {
51
+ const t = this.__entity.getComponent(Transform);
52
+ if (t !== null) {
53
+ t.copy(this.__transform);
54
+ }
55
+ } else {
56
+ this.__safe_get_attachment().transform.copy(this.__transform);
57
+ }
58
+
59
+ }
60
+
61
+ /**
62
+ *
63
+ * @param {*} components
64
+ * @return {EntityNode}
65
+ */
66
+ static fromComponents(...components) {
67
+ const node = new EntityNode();
68
+
69
+ for (let i = 0; i < components.length; i++) {
70
+ const component = components[i];
71
+
72
+ node.entity.add(component);
73
+ }
74
+
75
+ return node;
76
+ }
77
+
78
+ /**
79
+ *
80
+ * @return {Attachment}
81
+ * @private
82
+ */
83
+ __safe_get_attachment() {
84
+ let attachment = this.__entity.getComponent(Attachment);
85
+
86
+ if (attachment === null) {
87
+ attachment = new Attachment();
88
+ attachment.socket = "root";
89
+ attachment.immediate = true;
90
+
91
+ this.__entity.add(attachment);
92
+ }
93
+
94
+ return attachment;
95
+ }
96
+
97
+ /**
98
+ * @returns {Transform}
99
+ */
100
+ get transform() {
101
+ return this.__transform;
102
+ }
103
+
104
+ /**
105
+ *
106
+ * @return {EntityNode|null}
107
+ */
108
+ get parent() {
109
+ return this.__parent;
110
+ }
111
+
112
+ /**
113
+ *
114
+ * @param {EntityNode|null} node
115
+ */
116
+ set parent(node) {
117
+ // check if entity is built
118
+ if (this.__entity.isBuilt) {
119
+ // live re-wiring
120
+ let parent_entity = this.__entity.removeComponent(ParentEntity);
121
+ let attachment = this.__entity.removeComponent(Attachment);
122
+
123
+ if (node !== null) {
124
+
125
+ // handle component ParentEntity
126
+
127
+ if (parent_entity === null) {
128
+ parent_entity = new ParentEntity();
129
+ }
130
+
131
+ const parent_entity_builder = node.entity;
132
+
133
+ if (!parent_entity_builder.isBuilt) {
134
+ throw new Error('Parent entity is not built');
135
+ }
136
+
137
+ const parent_entity_id = parent_entity_builder.entity;
138
+ parent_entity.entity = parent_entity_id;
139
+
140
+ // add component back
141
+ this.__entity.add(parent_entity);
142
+
143
+
144
+ // handle component Attachment
145
+ if (attachment === null) {
146
+ attachment = this.__safe_get_attachment();
147
+ }
148
+
149
+ attachment.parent = parent_entity_id;
150
+ }
151
+ }
152
+
153
+ this.__parent = node;
154
+ }
155
+
156
+ get entity() {
157
+ return this.__entity;
158
+ }
159
+
160
+ /**
161
+ *
162
+ * @param {EntityNode} node
163
+ * @returns {boolean}
164
+ */
165
+ addChild(node) {
166
+ const added = array_push_if_unique(this.__children, node);
167
+
168
+ if (added) {
169
+ if (node.parent !== null) {
170
+ // has a parent already, detach
171
+ node.parent.removeChild(node);
172
+ }
173
+
174
+ node.parent = this;
175
+ }
176
+
177
+ return added;
178
+ }
179
+
180
+ /**
181
+ *
182
+ * @param {EntityNode} node
183
+ * @returns {boolean}
184
+ */
185
+ removeChild(node) {
186
+ const removed = array_remove_first(this.__children, node);
187
+
188
+ if (removed) {
189
+ assert.equal(node.parent, this, 'node is a child, but parent property points to something else instead of this node');
190
+
191
+ node.parent = null;
192
+ }
193
+
194
+ return removed;
195
+ }
196
+
197
+ /**
198
+ *
199
+ * @param {EntityComponentDataset} ecd
200
+ */
201
+ build(ecd) {
202
+
203
+ // assume that parent is built
204
+ const parent = this.__parent;
205
+
206
+ if (parent !== null) {
207
+ /**
208
+ *
209
+ * @type {ParentEntity}
210
+ */
211
+ let parent_entity = this.__entity.getComponent(ParentEntity);
212
+ if (parent_entity === null) {
213
+ parent_entity = new ParentEntity();
214
+ this.__entity.add(parent_entity);
215
+ }
216
+
217
+ const parent_entity_builder = parent.__entity;
218
+
219
+ if (!parent_entity_builder.isBuilt) {
220
+ throw new Error('Parent entity is not built');
221
+ }
222
+
223
+ const parent_entity_id = parent_entity_builder.entity;
224
+ parent_entity.entity = parent_entity_id;
225
+
226
+
227
+ const attachment = this.__safe_get_attachment();
228
+
229
+ attachment.parent = parent_entity_id;
230
+ }
231
+
232
+ // ensure "root" socket exists for transform parenting
233
+ /**
234
+ *
235
+ * @type {AttachmentSockets}
236
+ */
237
+ let sockets = this.__entity.getComponent(AttachmentSockets);
238
+ if (sockets === null) {
239
+ sockets = new AttachmentSockets();
240
+ this.__entity.add(sockets);
241
+ }
242
+
243
+ if (sockets.get("root") === undefined) {
244
+ const socket = new AttachmentSocket();
245
+ socket.id = "root";
246
+
247
+ sockets.add(socket);
248
+ }
249
+
250
+ this.__transform_sync_down();
251
+ this.__transform.position.onChanged.add(this.__transform_sync_down, this);
252
+ this.__transform.scale.onChanged.add(this.__transform_sync_down, this);
253
+ this.__transform.rotation.onChanged.add(this.__transform_sync_down, this);
254
+
255
+ this.__entity.build(ecd);
256
+
257
+ // build children
258
+ const children = this.__children;
259
+ const child_count = children.length;
260
+ for (let i = 0; i < child_count; i++) {
261
+ const child = children[i];
262
+
263
+ child.build(ecd);
264
+ }
265
+ }
266
+
267
+ destroy() {
268
+ this.__transform.position.onChanged.remove(this.__transform_sync_down, this);
269
+ this.__transform.scale.onChanged.remove(this.__transform_sync_down, this);
270
+ this.__transform.rotation.onChanged.remove(this.__transform_sync_down, this);
271
+
272
+ // destroy children first
273
+ const children = this.__children;
274
+ const child_count = children.length;
275
+ for (let i = 0; i < child_count; i++) {
276
+ const child = children[i];
277
+
278
+ child.destroy();
279
+ }
280
+
281
+ // then main entity
282
+ this.__entity.destroy();
283
+ }
284
+ }
@@ -0,0 +1,137 @@
1
+ import { SimpleStateMachineDescription } from "../../../core/fsm/simple/SimpleStateMachineDescription.js";
2
+ import { SimpleStateMachine } from "../../../core/fsm/simple/SimpleStateMachine.js";
3
+ import Vector3 from "../../../core/geom/Vector3.js";
4
+ import { SurfacePoint3 } from "../../../core/geom/3d/SurfacePoint3.js";
5
+
6
+ const smd = new SimpleStateMachineDescription();
7
+
8
+ export const STATE_INITIAL = smd.createState();
9
+ export const STATE_HOVER = smd.createState();
10
+ export const STATE_EDIT = smd.createState();
11
+
12
+ smd.createEdge(STATE_INITIAL, STATE_HOVER);
13
+ smd.createEdge(STATE_HOVER, STATE_EDIT);
14
+ smd.createEdge(STATE_HOVER, STATE_INITIAL);
15
+ smd.createEdge(STATE_EDIT, STATE_HOVER);
16
+
17
+
18
+ export class FaceEditor {
19
+ constructor() {
20
+ /**
21
+ *
22
+ * @type {ShadedGeometry|null}
23
+ * @private
24
+ */
25
+ this.__mesh = null;
26
+
27
+ /**
28
+ *
29
+ * @type {EntityComponentDataset|null}
30
+ * @private
31
+ */
32
+ this.__ecd = null;
33
+
34
+ /**
35
+ *
36
+ * @type {number}
37
+ * @private
38
+ */
39
+ this.__entity = -1;
40
+
41
+ /**
42
+ *
43
+ * @type {Vector3}
44
+ * @private
45
+ */
46
+ this.__edit_anchor_point = new Vector3();
47
+ /**
48
+ *
49
+ * @type {Vector3}
50
+ * @private
51
+ */
52
+ this.__edit_target_point = new Vector3();
53
+
54
+ /**
55
+ *
56
+ * @type {SurfacePoint3}
57
+ * @private
58
+ */
59
+ this.__hover_contact = new SurfacePoint3();
60
+
61
+ this.__sm = new SimpleStateMachine(smd);
62
+ this.__sm.setState(STATE_INITIAL);
63
+
64
+ this.__sm.addEventHandlerStateEntry(STATE_HOVER, () => {
65
+ console.log('+hovering');
66
+ });
67
+
68
+ this.__sm.addEventHandlerStateExit(STATE_HOVER, () => {
69
+ console.log('-hovering');
70
+ });
71
+ }
72
+
73
+ get state() {
74
+ return this.__sm.getState();
75
+ }
76
+
77
+ set state(v) {
78
+ this.__sm.navigateTo(v);
79
+ }
80
+
81
+ /**
82
+ * @param {ShadedGeometry} v
83
+ */
84
+ set mesh(v) {
85
+ this.__mesh = v;
86
+ }
87
+
88
+ get mesh() {
89
+ return this.__mesh;
90
+ }
91
+
92
+ /**
93
+ * @param {EntityComponentDataset} v
94
+ */
95
+ set ecd(v) {
96
+ this.__ecd = v;
97
+ }
98
+
99
+ /**
100
+ * @param {number} v
101
+ */
102
+ set entity(v) {
103
+ this.__entity = v;
104
+ }
105
+
106
+ /**
107
+ *
108
+ * @param {Vector3} v
109
+ */
110
+ set edit_anchor_point(v) {
111
+ this.__edit_anchor_point.copy(v);
112
+ }
113
+
114
+ /**
115
+ *
116
+ * @param {Vector3} v
117
+ */
118
+ set edit_target_point(v) {
119
+ this.__edit_target_point.copy(v);
120
+ }
121
+
122
+ set contact(v) {
123
+ this.__hover_contact.copy(v);
124
+ }
125
+
126
+ get contact() {
127
+ return this.__hover_contact;
128
+ }
129
+
130
+ attach() {
131
+ this.__sm.navigateTo(STATE_INITIAL);
132
+ }
133
+
134
+ detach() {
135
+ this.__sm.navigateTo(STATE_INITIAL);
136
+ }
137
+ }
@@ -0,0 +1,153 @@
1
+ import { EngineHarness } from "../../EngineHarness.js";
2
+ import { ShadedGeometrySystem } from "../../graphics/ecs/mesh-v2/ShadedGeometrySystem.js";
3
+ import { Transform } from "../transform/Transform.js";
4
+ import { ShadedGeometry } from "../../graphics/ecs/mesh-v2/ShadedGeometry.js";
5
+ import { BoxBufferGeometry, MeshLambertMaterial } from "three";
6
+ import { EngineConfiguration } from "../../EngineConfiguration.js";
7
+ import { EntityNode } from "./EntityNode.js";
8
+ import { AttachmentSystem } from "../attachment/AttachmentSystem.js";
9
+ import { SurfacePoint3 } from "../../../core/geom/3d/SurfacePoint3.js";
10
+ import Vector3 from "../../../core/geom/Vector3.js";
11
+ import Vector2 from "../../../core/geom/Vector2.js";
12
+ import { FaceEditor, STATE_EDIT, STATE_HOVER } from "./FaceEditor.js";
13
+
14
+ const eh = new EngineHarness();
15
+
16
+ function makeConfig(engine) {
17
+ const r = new EngineConfiguration();
18
+
19
+ r.addSystem(new ShadedGeometrySystem(engine));
20
+ r.addSystem(new AttachmentSystem())
21
+
22
+ return r;
23
+ }
24
+
25
+ /**
26
+ *
27
+ * @param {Engine} engine
28
+ */
29
+ async function main(engine) {
30
+
31
+
32
+ EngineHarness.buildBasics({ engine, enableWater: false })
33
+
34
+
35
+ const ecd = engine.entityManager.dataset;
36
+
37
+ const block_a = EntityNode.fromComponents(
38
+ ShadedGeometry.from(new BoxBufferGeometry(), new MeshLambertMaterial({
39
+ color: 0xFFFFAA
40
+ })),
41
+ new Transform()
42
+ );
43
+
44
+ block_a.transform.position.set(5, 0.5, 5);
45
+
46
+ const block_b = EntityNode.fromComponents(
47
+ ShadedGeometry.from(new BoxBufferGeometry(), new MeshLambertMaterial({
48
+ color: 0xAAFFFF
49
+ })),
50
+ new Transform()
51
+ );
52
+
53
+ block_b.transform.position.set(1, 1, 1);
54
+ block_a.addChild(block_b);
55
+
56
+ block_a.build(ecd);
57
+
58
+ function pick(x, y) {
59
+ /**
60
+ *
61
+ * @type {ShadedGeometrySystem|null}
62
+ */
63
+ const system = engine.entityManager.getSystem(ShadedGeometrySystem);
64
+
65
+ const contact = new SurfacePoint3();
66
+
67
+ const origin = new Vector3();
68
+ const direction = new Vector3();
69
+
70
+ const p = new Vector2(x, y);
71
+ const point_2 = p.clone();
72
+
73
+ engine.graphics.normalizeViewportPoint(p, point_2);
74
+ engine.graphics.viewportProjectionRay(point_2.x, point_2.y, origin, direction);
75
+
76
+ const hit = system.raycastNearest(contact, origin.x, origin.y, origin.z, direction.x, direction.y, direction.z);
77
+
78
+ if (hit === undefined) {
79
+ return;
80
+ }
81
+
82
+ return Object.assign({ contact }, hit);
83
+ }
84
+
85
+ const editor = new FaceEditor();
86
+
87
+ function update_hover_state(x, y) {
88
+ const hit = pick(x, y);
89
+
90
+ if (hit === undefined) {
91
+ editor.detach();
92
+ } else {
93
+ if (editor.mesh !== hit.mesh) {
94
+ editor.detach();
95
+
96
+ editor.contact = hit.contact;
97
+ editor.mesh = hit.mesh;
98
+ editor.entity = hit.entity;
99
+ editor.ecd = ecd;
100
+
101
+ editor.attach();
102
+ editor.state = STATE_HOVER;
103
+ } else {
104
+ // update contact only
105
+ editor.contact = hit.contact;
106
+ }
107
+
108
+ }
109
+
110
+ }
111
+
112
+ engine.devices.pointer.position.onChanged.add((x, y) => {
113
+ if (editor.state !== STATE_EDIT) {
114
+ update_hover_state(x, y);
115
+
116
+ } else {
117
+
118
+ }
119
+ });
120
+
121
+
122
+ engine.devices.pointer.on.dragStart.add((p) => {
123
+ if (editor.state === STATE_HOVER) {
124
+ editor.edit_anchor_point = editor.contact.position;
125
+ editor.state = STATE_EDIT;
126
+ }
127
+ });
128
+ engine.devices.pointer.on.drag.add(p => {
129
+ editor.edit_target_point = p;
130
+ });
131
+ engine.devices.pointer.on.dragEnd.add(p => {
132
+ if (editor.state === STATE_EDIT) {
133
+ update_hover_state(p.x, p.y);
134
+ }
135
+ });
136
+
137
+ }
138
+
139
+ /**
140
+ *
141
+ * @param {EngineHarness} harness
142
+ */
143
+ async function init(harness) {
144
+ const engine = eh.engine;
145
+
146
+ await makeConfig(engine).apply(engine);
147
+
148
+ await eh.initialize();
149
+
150
+ main(engine);
151
+ }
152
+
153
+ init(eh);
@@ -0,0 +1,123 @@
1
+ import { EngineHarness } from "../../EngineHarness.js";
2
+ import { ShadedGeometrySystem } from "../../graphics/ecs/mesh-v2/ShadedGeometrySystem.js";
3
+ import { Transform } from "../transform/Transform.js";
4
+ import { EngineConfiguration } from "../../EngineConfiguration.js";
5
+ import { AttachmentSystem } from "../attachment/AttachmentSystem.js";
6
+ import { GameAssetType } from "../../asset/GameAssetType.js";
7
+ import { Sampler2D } from "../../graphics/texture/sampler/Sampler2D.js";
8
+ import EntityBuilder from "../EntityBuilder.js";
9
+ import HeadsUpDisplay from "../gui/hud/HeadsUpDisplay.js";
10
+ import ViewportPosition from "../gui/position/ViewportPosition.js";
11
+ import GUIElement from "../gui/GUIElement.js";
12
+ import EmptyView from "../../../view/elements/EmptyView.js";
13
+ import HeadsUpDisplaySystem from "../gui/hud/HeadsUpDisplaySystem.js";
14
+ import ViewportPositionSystem from "../gui/position/ViewportPositionSystem.js";
15
+ import GUIElementSystem from "../gui/GUIElementSystem.js";
16
+ import { ImageRGBADataLoader } from "../../asset/loaders/image/ImageRGBADataLoader.js";
17
+ import LightSystem from "../../graphics/ecs/light/LightSystem.js";
18
+ import { CameraSystem } from "../../graphics/ecs/camera/CameraSystem.js";
19
+
20
+ const eh = new EngineHarness();
21
+
22
+ /**
23
+ *
24
+ * @param {Engine} engine
25
+ * @return {EngineConfiguration}
26
+ */
27
+ function makeConfig(engine) {
28
+ const r = new EngineConfiguration();
29
+
30
+ r.addSystem(new ShadedGeometrySystem(engine));
31
+ r.addSystem(new AttachmentSystem());
32
+ r.addSystem(new HeadsUpDisplaySystem(engine.graphics));
33
+ r.addSystem(new ViewportPositionSystem(engine.gameView.size));
34
+ r.addSystem(new GUIElementSystem(engine.gui.view, engine));
35
+ r.addSystem(new LightSystem(engine, {
36
+ shadowResolution: 1024
37
+ }));
38
+
39
+ r.addLoader(GameAssetType.Image, new ImageRGBADataLoader());
40
+
41
+ return r;
42
+ }
43
+
44
+ /**
45
+ *
46
+ * @param {Engine} engine
47
+ */
48
+ async function main(engine) {
49
+
50
+
51
+ EngineHarness.buildBasics({ engine, enableWater: false })
52
+
53
+
54
+ const ecd = engine.entityManager.dataset;
55
+
56
+ const active_camera = CameraSystem.getFirstActiveCamera(ecd);
57
+ const camera_component = active_camera.component;
58
+
59
+ camera_component.autoClip = false;
60
+ camera_component.object.far = 100;
61
+
62
+ const asset = await engine.assetManager.promise('data/textures/icons/Sci-Fi Ability Icons 1/134.PNG', GameAssetType.Image);
63
+
64
+ const sampler = asset.create();
65
+
66
+ const sampler2D = new Sampler2D(sampler.data, sampler.itemSize, sampler.width, sampler.height);
67
+
68
+ const sample = [];
69
+ const res = 128;
70
+
71
+ const texel_size = 5;
72
+ const grid_size = 18;
73
+
74
+ for (let i = 0; i < res; i++) {
75
+ const u = i / (res - 1);
76
+ for (let j = 0; j < res; j++) {
77
+ const v = j / (res - 1);
78
+
79
+ sampler2D.sampleBicubicUV(u, v, sample);
80
+
81
+ const view = new EmptyView({
82
+ css: {
83
+ background: `rgb(${sample[0]}, ${sample[1]}, ${sample[2]})`,
84
+ height: texel_size + 'px',
85
+ width: texel_size + 'px',
86
+ willChange: 'transform'
87
+ }
88
+ });
89
+
90
+ const transform = new Transform();
91
+
92
+ transform.position.set(
93
+ u * grid_size + 1,
94
+ 1,
95
+ v * grid_size + 1
96
+ );
97
+
98
+ new EntityBuilder()
99
+ .add(transform)
100
+ .add(new HeadsUpDisplay())
101
+ .add(new ViewportPosition())
102
+ .add(GUIElement.fromView(view))
103
+ .build(ecd);
104
+ }
105
+ }
106
+
107
+ }
108
+
109
+ /**
110
+ *
111
+ * @param {EngineHarness} harness
112
+ */
113
+ async function init(harness) {
114
+ const engine = eh.engine;
115
+
116
+ await makeConfig(engine).apply(engine);
117
+
118
+ await eh.initialize();
119
+
120
+ main(engine);
121
+ }
122
+
123
+ init(eh);