@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,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
+ }
@@ -9,13 +9,13 @@ import { Transform } from '../../transform/Transform.js';
9
9
  import ClingToTerrain from './ClingToTerrain.js';
10
10
 
11
11
  import Vector3 from '../../../../core/geom/Vector3.js';
12
- import { obtainTerrain } from "../../../../../model/game/scenes/SceneUtils.js";
13
12
  import Quaternion from "../../../../core/geom/Quaternion.js";
14
- import { EPSILON} from "../../../../core/math/MathUtils.js";
13
+ import { EPSILON } from "../../../../core/math/MathUtils.js";
15
14
  import { Matrix4 } from "three";
16
15
  import { assert } from "../../../../core/assert.js";
17
16
  import { SurfacePoint3 } from "../../../../core/geom/3d/SurfacePoint3.js";
18
17
  import { Deque } from "../../../../core/collection/queue/Deque.js";
18
+ import { obtainTerrain } from "../util/obtainTerrain.js";
19
19
 
20
20
 
21
21
  /**
@@ -909,7 +909,7 @@ class Terrain {
909
909
 
910
910
  worker.setHeightSampler(s.data, s.itemSize, s.width, s.height);
911
911
 
912
- worker.computeHeightRange()
912
+ return worker.computeHeightRange()
913
913
  .then(({ min, max }) => {
914
914
  this.tiles.setHeightRange(min, max);
915
915
  });
@@ -1038,13 +1038,22 @@ class Terrain {
1038
1038
  heightSampler: this.samplerHeight
1039
1039
  });
1040
1040
 
1041
+
1041
1042
  const result = promise.then(() => {
1042
1043
 
1043
- this.material.aoMap = true;
1044
- this.material.needsUpdate = true;
1044
+ const ref = this.__material_reference;
1045
+
1046
+ let mat = this.material;
1047
+
1048
+ if (ref !== null && ref.getValue() !== null) {
1049
+ mat = ref.getValue();
1050
+ }
1051
+
1052
+ mat.aoMap = true;
1053
+ mat.needsUpdate = true;
1045
1054
 
1046
- this.material.uniforms.aoMap.value = texture;
1047
- this.material.uniforms.aoMapIntensity.value = 0.7;
1055
+ mat.uniforms.aoMap.value = texture;
1056
+ mat.uniforms.aoMapIntensity.value = 0.7;
1048
1057
 
1049
1058
  return texture;
1050
1059
  });
@@ -0,0 +1,112 @@
1
+ import TopDownCameraControllerSystem from "../../../graphics/ecs/camera/topdown/TopDownCameraControllerSystem.js";
2
+ import { Camera } from "../../../graphics/ecs/camera/Camera.js";
3
+ import { obtainTerrain } from "./obtainTerrain.js";
4
+ import { assert } from "../../../../core/assert.js";
5
+ import TerrainSystem from "../ecs/TerrainSystem.js";
6
+ import Task from "../../../../core/process/task/Task.js";
7
+ import TaskSignal from "../../../../core/process/task/TaskSignal.js";
8
+
9
+ /**
10
+ *
11
+ * @param {EntityManager} em
12
+ * @param {EntityComponentDataset} ecd
13
+ * @returns {Task}
14
+ */
15
+ export function loadVisibleTerrainTiles(em, ecd) {
16
+
17
+ let totalTiles = 0;
18
+ let loadedTiles = 0;
19
+ let failedTiles = 0;
20
+
21
+ let attempt = 0;
22
+
23
+ let failureFlag = false;
24
+
25
+ function init() {
26
+ const attemptId = attempt;
27
+
28
+ //force update by camera controller, to ensure correct focus is set
29
+ em.getSystem(TopDownCameraControllerSystem).update(0);
30
+
31
+ ecd.traverseComponents(Camera, function (c) {
32
+ c.updateMatrices();
33
+ });
34
+
35
+ const tiles = [];
36
+
37
+ const terrain = obtainTerrain(ecd);
38
+
39
+ assert.notEqual(terrain, null, 'terrain not found');
40
+
41
+ TerrainSystem.traverseVisibleTiles(ecd, terrain, function (tile) {
42
+ tiles.push(tile);
43
+ });
44
+
45
+ totalTiles = tiles.length;
46
+ const tileManager = terrain.tiles;
47
+
48
+ function handleObtainedTile(t) {
49
+ if (attemptId !== attempt) {
50
+ return;
51
+ }
52
+
53
+ loadedTiles++;
54
+ }
55
+
56
+ function handleFailedTile(t) {
57
+ if (attemptId !== attempt) {
58
+ return;
59
+ }
60
+
61
+ attempt++;
62
+
63
+ failedTiles++;
64
+
65
+ if (attempt < 10) {
66
+ init();
67
+ } else {
68
+ failureFlag = true;
69
+ }
70
+ }
71
+
72
+ if (totalTiles !== 0) {
73
+ tiles.forEach(function (tile) {
74
+ tileManager.obtain(tile.gridPosition.x, tile.gridPosition.y).then(handleObtainedTile, handleFailedTile);
75
+ });
76
+ }
77
+ }
78
+
79
+ const task = new Task({
80
+ name: "Building visible terrain tiles",
81
+
82
+ initializer: init,
83
+
84
+ cycleFunction() {
85
+ if (failureFlag) {
86
+ return TaskSignal.EndFailure;
87
+ }
88
+
89
+ if (loadedTiles >= totalTiles) {
90
+ return TaskSignal.EndSuccess;
91
+ } else {
92
+ return TaskSignal.Yield;
93
+ }
94
+ },
95
+
96
+ computeProgress() {
97
+ if (totalTiles === 0) {
98
+ return 0;
99
+ }
100
+
101
+ const f = loadedTiles / totalTiles;
102
+
103
+ if (f >= 1) {
104
+ return 1;
105
+ }
106
+
107
+ return f;
108
+ }
109
+ });
110
+
111
+ return task;
112
+ }
@@ -0,0 +1,23 @@
1
+ import { assert } from "../../../../core/assert.js";
2
+ import Terrain from "../ecs/Terrain.js";
3
+
4
+ /**
5
+ *
6
+ * @param {EntityComponentDataset} ecd
7
+ * @param {function(terrain:Terrain,entity:number)} [callback]
8
+ * @returns {Terrain|null}
9
+ */
10
+ export function obtainTerrain(ecd, callback) {
11
+ assert.notEqual(ecd, null, 'ecd is null');
12
+ assert.notEqual(ecd, undefined, 'ecd is undefined');
13
+
14
+ const object = ecd.getAnyComponent(Terrain);
15
+
16
+ const terrain = object.component;
17
+
18
+ if (terrain !== null && typeof callback === "function") {
19
+ callback(terrain, object.entity);
20
+ }
21
+
22
+ return terrain;
23
+ }
@@ -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();
@@ -585,6 +585,7 @@ GraphicsEngine.prototype.renderOpaque = function () {
585
585
  GraphicsEngine.prototype.renderTransparent = function () {
586
586
  const scene = this.scene;
587
587
 
588
+ // clear background, as transparent pass is drawn on top, the background should already be composited
588
589
  const _background = scene.background;
589
590
  scene.background = null;
590
591
 
@@ -596,8 +597,6 @@ GraphicsEngine.prototype.renderTransparent = function () {
596
597
 
597
598
  // restore background
598
599
  scene.background = _background;
599
-
600
- // TODO render transparent objects into a buffer, to be able to apply post-fx
601
600
  };
602
601
 
603
602
  /**
@@ -8,8 +8,6 @@ import PathFollowingSystem from "../../navigation/ecs/path_following/PathFollowi
8
8
  import SteeringSystem from "../../ecs/systems/SteeringSystem.js";
9
9
  import MotionSystem from "../../ecs/systems/MotionSystem.js";
10
10
  import TagSystem from "../../ecs/systems/TagSystem.js";
11
- import { AttachmentSocketsSystem } from "../../ecs/sockets/AttachmentSocketsSystem.js";
12
- import { AttachmentSystem } from "../../ecs/attachment/AttachmentSystem.js";
13
11
  import { SoundEmitterSystem } from "../../sound/ecs/emitter/SoundEmitterSystem.js";
14
12
  import SoundControllerSystem from "../../sound/ecs/SoundControllerSystem.js";
15
13
  import SoundListenerSystem from "../../sound/ecs/SoundListenerSystem.js";
@@ -84,8 +82,6 @@ function makeConfig(engine) {
84
82
  new SteeringSystem(),
85
83
  new MotionSystem(),
86
84
  new TagSystem(),
87
- new AttachmentSocketsSystem(),
88
- new AttachmentSystem(),
89
85
  new SoundEmitterSystem(assetManager, sound.destination, sound.context),
90
86
  new SoundControllerSystem(),
91
87
  new SoundListenerSystem(sound.context),
@@ -2,11 +2,11 @@ import { clamp } from "../../../../../core/math/clamp.js";
2
2
  import { System } from "../../../../ecs/System.js";
3
3
  import { TopDownCameraLander } from "./TopDownCameraLander.js";
4
4
  import { Cache } from "../../../../../core/cache/Cache.js";
5
- import { obtainTerrain } from "../../../../../../model/game/scenes/SceneUtils.js";
6
5
  import { buildCameraTargetSampler } from "../../../../input/ecs/util/TerrainCameraTargetSampler.js";
7
6
  import TopDownCameraController from "./TopDownCameraController.js";
8
7
  import Vector2 from "../../../../../core/geom/Vector2.js";
9
8
  import { SignalBinding } from "../../../../../core/events/signal/SignalBinding.js";
9
+ import { obtainTerrain } from "../../../../ecs/terrain/util/obtainTerrain.js";
10
10
 
11
11
 
12
12
  /**
@@ -26,7 +26,7 @@ class LightSystem extends AbstractContextSystem {
26
26
  * @param settings
27
27
  * @constructor
28
28
  */
29
- constructor(engine, settings) {
29
+ constructor(engine, settings = {}) {
30
30
  super(LightContext);
31
31
 
32
32
  /**
@@ -39,6 +39,35 @@ export class ShadedGeometry {
39
39
  * @private
40
40
  */
41
41
  this.__bvh_leaf = new LeafNode(this, 0, 0, 0, 0, 0, 0);
42
+
43
+ /**
44
+ * Transient, assigned in the system
45
+ * @type {number}
46
+ * @private
47
+ */
48
+ this.__entity = -1;
49
+ /**
50
+ * Transform matrix
51
+ * Transient, assigned in the system
52
+ * @type {number[]|null}
53
+ * @private
54
+ */
55
+ this.__transform = null;
56
+ }
57
+
58
+ /**
59
+ * Global transform matrix
60
+ * 4x4 matrix
61
+ * @return {null|number[]}
62
+ */
63
+ get transform() {
64
+ if (this.__transform !== null) {
65
+ return this.__transform;
66
+ } else if (this.__cached_object !== null) {
67
+ return this.__cached_object.matrix.elements;
68
+ } else {
69
+ return null;
70
+ }
42
71
  }
43
72
 
44
73
  __build_object() {
@@ -1,6 +1,27 @@
1
1
  import { ShadedGeometry } from "./ShadedGeometry.js";
2
2
  import { Transform } from "../../../ecs/transform/Transform.js";
3
3
  import { System } from "../../../ecs/System.js";
4
+ import { intersectRay } from "../../../../core/bvh2/aabb3/AABB3Math.js";
5
+ import { GeometrySpatialQueryAccelerator } from "../../geometry/buffered/query/GeometrySpatialQueryAccelerator.js";
6
+ import { SurfacePoint3 } from "../../../../core/geom/3d/SurfacePoint3.js";
7
+ import { v3_distance_sqr } from "../../../../core/geom/v3_distance_sqr.js";
8
+ import { mat4 } from "gl-matrix";
9
+ import { returnTrue } from "../../../../core/function/Functions.js";
10
+
11
+ const traversal_stack = [];
12
+ let traversal_cursor = 0;
13
+
14
+ /**
15
+ *
16
+ * @type {SurfacePoint3}
17
+ */
18
+ const scratch_point = new SurfacePoint3();
19
+
20
+ /**
21
+ *
22
+ * @type {Float32Array|mat4}
23
+ */
24
+ const scratch_m4 = new Float32Array(16);
4
25
 
5
26
  export class ShadedGeometrySystem extends System {
6
27
  /**
@@ -49,7 +70,12 @@ export class ShadedGeometrySystem extends System {
49
70
 
50
71
  sg.applyTransform(t);
51
72
 
52
- this.__render_layer.bvh.insertNode(sg.bvh);
73
+ const leaf_node = sg.bvh;
74
+
75
+ // remember entity for lookups
76
+ sg.__entity = entity;
77
+
78
+ this.__render_layer.bvh.insertNode(leaf_node);
53
79
  }
54
80
 
55
81
  /**
@@ -65,4 +91,135 @@ export class ShadedGeometrySystem extends System {
65
91
 
66
92
  sg.bvh.disconnect();
67
93
  }
94
+
95
+ /**
96
+ *
97
+ * @param {SurfacePoint3} contact
98
+ * @param {number} origin_x
99
+ * @param {number} origin_y
100
+ * @param {number} origin_z
101
+ * @param {number} direction_x
102
+ * @param {number} direction_y
103
+ * @param {number} direction_z
104
+ * @param {function(entity:number, mesh:ShadedGeometry)} [filter_function]
105
+ * @param {*} [filter_function_context]
106
+ * @returns {{entity:number, mesh:ShadedGeometry}|undefined}
107
+ */
108
+ raycastNearest(
109
+ contact,
110
+ origin_x, origin_y, origin_z,
111
+ direction_x, direction_y, direction_z,
112
+ filter_function = returnTrue, filter_function_context
113
+ ) {
114
+ const root_bvh = this.__render_layer.bvh;
115
+ const stack_frame_address = traversal_cursor;
116
+
117
+ traversal_stack[traversal_cursor++] = root_bvh;
118
+
119
+ let best_distance = Infinity;
120
+ let found_hit = false;
121
+ let best_result = null;
122
+
123
+ while (traversal_cursor > stack_frame_address) {
124
+ traversal_cursor--;
125
+
126
+ /**
127
+ *
128
+ * @type {BinaryNode|LeafNode<ShadedGeometry>}
129
+ */
130
+ const node = traversal_stack[traversal_cursor];
131
+
132
+ // test node against the ray
133
+ const intersects = intersectRay(
134
+ node.x0, node.y0, node.z0,
135
+ node.x1, node.y1, node.z1,
136
+ origin_x, origin_y, origin_z,
137
+ direction_x, direction_y, direction_z
138
+ );
139
+
140
+ if (!intersects) {
141
+ continue;
142
+ }
143
+
144
+ if (node.isBinaryNode) {
145
+ if (node.right !== null) {
146
+ traversal_stack[traversal_cursor++] = node.right;
147
+ }
148
+ if (node.left !== null) {
149
+ traversal_stack[traversal_cursor++] = node.left;
150
+ }
151
+ } else {
152
+ // leaf node
153
+
154
+ /**
155
+ *
156
+ * @type {ShadedGeometry}
157
+ */
158
+ const sg = node.object;
159
+
160
+ const entity = sg.__entity;
161
+
162
+ if (!filter_function.call(filter_function_context, entity, sg)) {
163
+ // filtered out
164
+ continue;
165
+ }
166
+
167
+ const m4 = sg.transform;
168
+
169
+ // get transform in local space
170
+ mat4.invert(scratch_m4, m4);
171
+
172
+ // transform ray to local space
173
+ const local_origin_x = scratch_m4[0] * origin_x + scratch_m4[4] * origin_y + scratch_m4[8] * origin_z + scratch_m4[12];
174
+ const local_origin_y = scratch_m4[1] * origin_x + scratch_m4[5] * origin_y + scratch_m4[9] * origin_z + scratch_m4[13];
175
+ const local_origin_z = scratch_m4[2] * origin_x + scratch_m4[6] * origin_y + scratch_m4[10] * origin_z + scratch_m4[14];
176
+
177
+ const local_direction_x = scratch_m4[0] * direction_x + scratch_m4[4] * direction_y + scratch_m4[8] * direction_z;
178
+ const local_direction_y = scratch_m4[1] * direction_x + scratch_m4[5] * direction_y + scratch_m4[9] * direction_z;
179
+ const local_direction_z = scratch_m4[2] * direction_x + scratch_m4[6] * direction_y + scratch_m4[10] * direction_z;
180
+ // NOTE: direction is not normalized
181
+
182
+ const geometry_hit_found = GeometrySpatialQueryAccelerator.INSTANCE.queryRaycastNearest_primitive(
183
+ scratch_point,
184
+ sg.geometry,
185
+ local_origin_x, local_origin_y, local_origin_z,
186
+ local_direction_x, local_direction_y, local_direction_z
187
+ );
188
+
189
+ if (!geometry_hit_found) {
190
+ continue;
191
+ }
192
+
193
+ // transform hit contact into global space
194
+ scratch_point.applyMatrix4(m4);
195
+
196
+ found_hit = true;
197
+
198
+ const hit_position = scratch_point.position;
199
+
200
+ const distance_sqr = v3_distance_sqr(
201
+ hit_position.x, hit_position.y, hit_position.z,
202
+ origin_x, origin_y, origin_z
203
+ );
204
+
205
+ if (distance_sqr >= best_distance) {
206
+ // further than best found
207
+ continue;
208
+ }
209
+
210
+ contact.copy(scratch_point);
211
+ best_result = sg;
212
+ }
213
+ }
214
+
215
+ // drop stack frame
216
+ traversal_cursor = stack_frame_address;
217
+
218
+ if (found_hit) {
219
+ return {
220
+ entity: best_result.__entity,
221
+ mesh: best_result
222
+ };
223
+ }
224
+ }
68
225
  }
@@ -19,7 +19,6 @@ import PathFollowingSystem from "../../../navigation/ecs/path_following/PathFoll
19
19
  import SteeringSystem from "../../../ecs/systems/SteeringSystem.js";
20
20
  import MotionSystem from "../../../ecs/systems/MotionSystem.js";
21
21
  import TagSystem from "../../../ecs/systems/TagSystem.js";
22
- import { AttachmentSocketsSystem } from "../../../ecs/sockets/AttachmentSocketsSystem.js";
23
22
  import { AttachmentSystem } from "../../../ecs/attachment/AttachmentSystem.js";
24
23
  import { SoundEmitterSystem } from "../../../sound/ecs/emitter/SoundEmitterSystem.js";
25
24
  import SoundControllerSystem from "../../../sound/ecs/SoundControllerSystem.js";
@@ -95,7 +94,6 @@ function makeConfig(engine) {
95
94
  new SteeringSystem(),
96
95
  new MotionSystem(),
97
96
  new TagSystem(),
98
- new AttachmentSocketsSystem(),
99
97
  new AttachmentSystem(),
100
98
  new SoundEmitterSystem(assetManager, sound.destination, sound.context),
101
99
  new SoundControllerSystem(),
@@ -8,10 +8,10 @@ import { LeafNode } from '../../../../core/bvh2/LeafNode.js';
8
8
  import { buildPlanarRenderLayerClipPlaneComputationMethod } from "../../render/layers/RenderLayerUtils.js";
9
9
  import ThreeFactory from "../../three/ThreeFactory.js";
10
10
  import { RenderPassType } from "../../render/RenderPassType.js";
11
- import { obtainTerrain } from "../../../../../model/game/scenes/SceneUtils.js";
12
11
  import { makeAlexWaterMaterial } from "../water2/shader/AlexWaterShader.js";
13
12
  import { threeUpdateTransform } from "../../util/threeUpdateTransform.js";
14
13
  import { StandardFrameBuffers } from "../../StandardFrameBuffers.js";
14
+ import { obtainTerrain } from "../../../ecs/terrain/util/obtainTerrain.js";
15
15
 
16
16
  const WATER_SIZE = 800;
17
17
 
@@ -1,4 +1,3 @@
1
- import { obtainTerrain } from "../../../../../../model/game/scenes/SceneUtils.js";
2
1
  import { seededRandom } from "../../../../../core/math/random/seededRandom.js";
3
2
  import { EngineConfiguration } from "../../../../EngineConfiguration.js";
4
3
  import ScriptSystem from "../../../../ecs/systems/ScriptSystem.js";
@@ -28,6 +27,7 @@ import { EngineHarness } from "../../../../EngineHarness.js";
28
27
  import Vector2 from "../../../../../core/geom/Vector2.js";
29
28
  import Vector3 from "../../../../../core/geom/Vector3.js";
30
29
  import SimplexNoise from 'simplex-noise';
30
+ import { obtainTerrain } from "../../../../ecs/terrain/util/obtainTerrain.js";
31
31
 
32
32
  const engineHarness = new EngineHarness();
33
33
 
@@ -0,0 +1,8 @@
1
+ import {DataType} from "../../../core/parser/simple/DataType";
2
+
3
+ export class AttributeSpec {
4
+ readonly name: string
5
+ readonly type: DataType
6
+ readonly itemSize: number
7
+ readonly normalized: boolean
8
+ }
@@ -0,0 +1,15 @@
1
+ import {AttributeSpec} from "./AttributeSpec";
2
+
3
+ export class VertexDataSpec {
4
+ readonly attributes: AttributeSpec[]
5
+
6
+ getAttributeByName(name: string): AttributeSpec | undefined
7
+
8
+ add(attribute: AttributeSpec): this
9
+
10
+ setAttributes(attributes: AttributeSpec[]): void
11
+
12
+ equals(other: VertexDataSpec): boolean
13
+
14
+ hash(): number
15
+ }
@@ -0,0 +1,39 @@
1
+ import { BufferAttribute } from "three";
2
+
3
+
4
+ /**
5
+ *
6
+ * @param {THREE.InterleavedBufferAttribute|THREE.BufferAttribute} source_attribute
7
+ * @returns {THREE.BufferAttribute}
8
+ */
9
+ export function deinterleaveBufferAttribute(source_attribute) {
10
+ if (source_attribute.isInterleavedBufferAttribute !== true && source_attribute.isBufferAttribute) {
11
+ return source_attribute;
12
+ }
13
+
14
+ const source_data = source_attribute.data;
15
+ const source_data_array = source_data.array;
16
+ const stride = source_data.stride;
17
+
18
+ const item_count = source_attribute.count;
19
+ const itemSize = source_attribute.itemSize;
20
+ const array_size = item_count * itemSize;
21
+
22
+ const offset = source_attribute.offset;
23
+
24
+ const destination_array = new source_data_array.constructor(array_size);
25
+
26
+ const attribute = new BufferAttribute(destination_array, itemSize);
27
+
28
+ attribute.normalized = source_attribute.normalized;
29
+ attribute.name = source_attribute.name;
30
+
31
+ // copy data
32
+ for (let i = 0; i < item_count; i++) {
33
+ for (let j = 0; j < itemSize; j++) {
34
+ destination_array[i * itemSize + j] = source_data_array[i * stride + offset + j];
35
+ }
36
+ }
37
+
38
+ return attribute;
39
+ }