@woosh/meep-engine 2.64.0 → 2.66.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 (92) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/build/meep.cjs +33388 -34714
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +33388 -34714
  5. package/editor/ecs/component/editors/ecs/terrain/TerrainEditor.js +4 -10
  6. package/editor/process/symbolic/makeGridPositionSymbolDisplay.js +7 -7
  7. package/editor/tools/SelectionTool.js +6 -95
  8. package/package.json +1 -1
  9. package/src/core/bvh2/BinaryNode.js +14 -14
  10. package/src/core/bvh2/LeafNode.js +4 -4
  11. package/src/core/bvh2/binary/2/BinaryUint32BVH.js +118 -113
  12. package/src/core/bvh2/binary/2/BinaryUint32BVH.spec.js +54 -0
  13. package/src/core/bvh2/binary/2/bvh32_query_user_data_ray.js +98 -0
  14. package/src/core/bvh2/bvh3/{ExplicitBinaryBoundingVolumeHierarchy.d.ts → BVH.d.ts} +1 -1
  15. package/src/core/bvh2/bvh3/{ExplicitBinaryBoundingVolumeHierarchy.js → BVH.js} +2 -2
  16. package/src/core/bvh2/bvh3/{ExplicitBinaryBoundingVolumeHierarchy.spec.js → BVH.spec.js} +20 -20
  17. package/src/core/bvh2/bvh3/BvhClient.d.ts +11 -0
  18. package/src/core/bvh2/bvh3/{EBBVHLeafProxy.js → BvhClient.js} +22 -3
  19. package/src/core/bvh2/bvh3/BvhClient.spec.js +51 -0
  20. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_incremental.js +2 -2
  21. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.js +4 -4
  22. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.spec.js +3 -3
  23. package/src/core/bvh2/bvh3/ebvh_sort_for_traversal_depth_first.js +2 -8
  24. package/src/core/bvh2/bvh3/query/BVHQuery.js +1 -1
  25. package/src/core/bvh2/bvh3/query/bvh_collect_user_data.js +2 -2
  26. package/src/core/bvh2/bvh3/query/bvh_query_leaves_generic.js +2 -2
  27. package/src/core/bvh2/bvh3/query/bvh_query_leaves_generic.spec.js +2 -2
  28. package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray.js +3 -8
  29. package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray.spec.js +2 -2
  30. package/src/core/bvh2/bvh3/query/bvh_query_user_data_generic.js +2 -2
  31. package/src/core/bvh2/bvh3/query/bvh_query_user_data_generic.spec.js +2 -2
  32. package/src/core/bvh2/bvh3/query/bvh_query_user_data_nearest_to_point.js +3 -3
  33. package/src/core/bvh2/bvh3/query/bvh_query_user_data_nearest_to_point.spec.js +3 -3
  34. package/src/core/bvh2/bvh3/query/bvh_query_user_data_overlaps_frustum.js +3 -3
  35. package/src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.js +4 -4
  36. package/src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.spec.js +3 -3
  37. package/src/core/collection/array/array_copy.js +6 -0
  38. package/src/core/geom/3d/aabb/aabb3_array_combine.js +17 -8
  39. package/src/core/geom/3d/aabb/aabb3_array_intersects_ray.js +5 -2
  40. package/src/core/geom/3d/aabb/aabb3_array_set.js +25 -0
  41. package/src/core/geom/3d/aabb/aabb3_compute_half_surface_area.js +3 -0
  42. package/src/core/geom/3d/triangle/computeTriangleRayIntersectionBarycentric.js +8 -1
  43. package/src/engine/EngineHarness.js +23 -25
  44. package/src/engine/ecs/renderable/RenderSystem.js +44 -32
  45. package/src/engine/ecs/renderable/Renderable.d.ts +2 -2
  46. package/src/engine/ecs/renderable/Renderable.js +12 -11
  47. package/src/engine/ecs/terrain/ecs/Terrain.js +83 -87
  48. package/src/engine/ecs/terrain/ecs/TerrainSystem.js +106 -57
  49. package/src/engine/ecs/terrain/ecs/makeTerrainWorkerProxy.js +5 -2
  50. package/src/engine/ecs/terrain/tiles/TerrainTile.js +122 -67
  51. package/src/engine/ecs/terrain/tiles/TerrainTileManager.js +162 -146
  52. package/src/engine/ecs/terrain/tiles/TileBuildWorker.js +16 -5
  53. package/src/engine/graphics/camera/testClippingPlaneComputation.js +3 -6
  54. package/src/engine/graphics/debug/VisualSymbolLine.js +1 -0
  55. package/src/engine/graphics/ecs/camera/CameraSystem.js +9 -9
  56. package/src/engine/graphics/ecs/camera/auto_set_camera_clipping_planes.js +3 -23
  57. package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +22 -24
  58. package/src/engine/graphics/ecs/light/LightSystem.js +12 -48
  59. package/src/engine/graphics/ecs/mesh/Mesh.js +8 -8
  60. package/src/engine/graphics/ecs/mesh/MeshSystem.js +12 -36
  61. package/src/engine/graphics/ecs/mesh/updateNodeByTransformAndBBB.js +3 -43
  62. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +6 -6
  63. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.d.ts +3 -3
  64. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +16 -18
  65. package/src/engine/graphics/ecs/mesh-v2/render/ShadedGeometryRendererContext.js +5 -5
  66. package/src/engine/graphics/ecs/trail2d/Trail2D.js +105 -106
  67. package/src/engine/graphics/ecs/trail2d/Trail2DSystem.js +60 -61
  68. package/src/engine/graphics/ecs/trail2d/makeGradientTrail.js +3 -3
  69. package/src/engine/graphics/ecs/water/WATER_SIZE.js +1 -0
  70. package/src/engine/graphics/ecs/water/Water.js +84 -42
  71. package/src/engine/graphics/ecs/water/WaterSystem.js +53 -105
  72. package/src/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +13 -7
  73. package/src/engine/graphics/geometry/bvh/buffered/bvh32_from_indexed_geometry.js +58 -0
  74. package/src/engine/graphics/particles/ecs/ParticleEmitterSystem.js +32 -62
  75. package/src/engine/graphics/particles/particular/engine/ParticularEngine.js +9 -11
  76. package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +4 -4
  77. package/src/engine/graphics/particles/particular/engine/renderers/billboard/prototypeBillboardRenderer.js +8 -11
  78. package/src/engine/graphics/render/forward_plus/LightManager.js +30 -32
  79. package/src/engine/graphics/render/forward_plus/LightRenderMetadata.js +3 -3
  80. package/src/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +21 -19
  81. package/src/engine/graphics/render/layers/RenderLayer.d.ts +8 -2
  82. package/src/engine/graphics/render/layers/RenderLayer.js +7 -65
  83. package/src/engine/graphics/render/make_bvh_visibility_builder.js +64 -0
  84. package/src/engine/graphics/sh3/LightProbeVolume.js +19 -19
  85. package/src/engine/graphics/sh3/path_tracer/GeometryBVHBatched.js +4 -6
  86. package/src/engine/graphics/sh3/path_tracer/PathTracer.js +17 -19
  87. package/src/engine/graphics/three/expand_aabb_by_transformed_three_object.js +4 -4
  88. package/src/engine/graphics/trail/x/RibbonX.js +26 -5
  89. package/src/engine/sound/ecs/emitter/SoundEmitter.js +18 -16
  90. package/src/engine/sound/ecs/emitter/SoundEmitterSystem.js +3 -5
  91. package/src/core/bvh2/binary/tiny/TinyBVH.js +0 -221
  92. package/src/engine/graphics/ecs/camera/CameraClippingPlaneComputer.js +0 -138
@@ -3,13 +3,13 @@
3
3
  */
4
4
 
5
5
 
6
+ import { BvhClient } from "../../../../core/bvh2/bvh3/BvhClient.js";
6
7
  import Vector3 from "../../../../core/geom/Vector3.js";
7
8
  import Vector4 from "../../../../core/geom/Vector4.js";
9
+ import ThreeFactory from "../../three/ThreeFactory.js";
10
+ import { RibbonX } from "../../trail/x/RibbonX.js";
8
11
  import { RibbonXMaterialSpec } from "../../trail/x/RibbonXMaterialSpec.js";
9
- import { LeafNode } from "../../../../core/bvh2/LeafNode.js";
10
12
  import { makeGradientTrail } from "./makeGradientTrail.js";
11
- import { RibbonX } from "../../trail/x/RibbonX.js";
12
- import ThreeFactory from "../../three/ThreeFactory.js";
13
13
 
14
14
  /**
15
15
  * @readonly
@@ -21,80 +21,80 @@ export const Trail2DFlags = {
21
21
  Built: 4,
22
22
  };
23
23
 
24
+ const DEFAULT_FLAGS = Trail2DFlags.Spawning | Trail2DFlags.Aging;
25
+
26
+ const DEFAULT_MAX_AGE = 5;
27
+
28
+ const DEFAULT_WIDTH = 1;
29
+
24
30
  class Trail2D {
25
- constructor() {
26
-
27
- /**
28
- * Age at which trail segment disappears, in seconds
29
- * @type {number}
30
- */
31
- this.maxAge = 5;
32
-
33
- /**
34
- * Trail width
35
- * @type {number}
36
- */
37
- this.width = 1;
38
-
39
- /**
40
- * Current simulated time since trail birth
41
- * @type {number}
42
- */
43
- this.time = 0;
44
-
45
- /**
46
- *
47
- * @type {number}
48
- */
49
- this.trailingIndex = 0;
50
-
51
- /**
52
- * Time elapsed since last update
53
- * @type {number}
54
- */
55
- this.timeSinceLastUpdate = 0;
56
-
57
- /**
58
- * @readonly
59
- * @type {Vector4}
60
- */
61
- this.color = new Vector4(1, 1, 1, 1);
62
-
63
- /**
64
- * World offset
65
- * @readonly
66
- * @type {Vector3}
67
- */
68
- this.offset = new Vector3();
69
-
70
- /**
71
- * transient
72
- * @type {RibbonX|null}
73
- */
74
- this.ribbon = null;
75
-
76
- /**
77
- * transient
78
- * @type {RibbonXMaterialSpec}
79
- */
80
- this.material = new RibbonXMaterialSpec();
81
-
82
- /**
83
- * transient
84
- * @type {LeafNode|null}
85
- */
86
- this.bvhLeaf = new LeafNode(
87
- this,
88
- 0, 0, 0,
89
- 0, 0, 0
90
- );
91
-
92
- /**
93
- * @private
94
- * @type {Trail2DFlags|number}
95
- */
96
- this.flags = Trail2DFlags.Spawning | Trail2DFlags.Aging;
97
- }
31
+
32
+ /**
33
+ * Age at which trail segment disappears, in seconds
34
+ * @type {number}
35
+ */
36
+ maxAge = DEFAULT_MAX_AGE;
37
+
38
+ /**
39
+ * Trail width
40
+ * @type {number}
41
+ */
42
+ width = DEFAULT_WIDTH;
43
+
44
+ /**
45
+ * Current simulated time since trail birth
46
+ * @type {number}
47
+ */
48
+ time = 0;
49
+
50
+ /**
51
+ *
52
+ * @type {number}
53
+ */
54
+ trailingIndex = 0;
55
+
56
+ /**
57
+ * Time elapsed since last update
58
+ * @type {number}
59
+ */
60
+ timeSinceLastUpdate = 0;
61
+
62
+ /**
63
+ * @readonly
64
+ * @type {Vector4}
65
+ */
66
+ color = new Vector4(1, 1, 1, 1);
67
+
68
+ /**
69
+ * World offset
70
+ * @readonly
71
+ * @type {Vector3}
72
+ */
73
+ offset = new Vector3();
74
+
75
+ /**
76
+ * transient
77
+ * @type {RibbonX|null}
78
+ */
79
+ ribbon = null;
80
+
81
+ /**
82
+ * transient
83
+ * @type {RibbonXMaterialSpec}
84
+ */
85
+ material = new RibbonXMaterialSpec();
86
+
87
+ /**
88
+ * @readonly
89
+ * @type {BvhClient}
90
+ */
91
+ bvh = new BvhClient();
92
+
93
+ /**
94
+ * @private
95
+ * @type {Trail2DFlags|number}
96
+ */
97
+ flags = DEFAULT_FLAGS;
98
98
 
99
99
  dispose() {
100
100
  if (this.ribbon !== null) {
@@ -150,36 +150,10 @@ class Trail2D {
150
150
  return (this.flags & flag) === flag;
151
151
  }
152
152
 
153
- static fromJSON(json) {
154
- const r = new Trail2D();
155
-
156
- r.fromJSON(json);
157
-
158
- return r;
159
- }
160
-
161
- fromJSON(json) {
162
- if (typeof json.maxAge === "number") {
163
- this.maxAge = json.maxAge;
164
- }
165
-
166
- if (typeof json.width === "number") {
167
- this.width = json.width;
168
- }
169
-
170
- if (typeof json.textureURL === "string") {
171
- this.textureURL = json.textureURL;
172
- }
173
-
174
- if (json.offset !== undefined) {
175
- this.offset.fromJSON(json.offset);
176
- }
177
-
178
- if (json.color !== undefined) {
179
- this.color.fromJSON(json.color);
180
- }
181
- }
182
-
153
+ /**
154
+ *
155
+ * @param {number} segment_count
156
+ */
183
157
  build(segment_count) {
184
158
 
185
159
  const ribbon = new RibbonX();
@@ -195,6 +169,31 @@ class Trail2D {
195
169
  this.mesh = mesh;
196
170
  }
197
171
 
172
+ static fromJSON(json) {
173
+ const r = new Trail2D();
174
+
175
+ r.fromJSON(json);
176
+
177
+ return r;
178
+ }
179
+
180
+ fromJSON({
181
+ maxAge = DEFAULT_MAX_AGE,
182
+ width = DEFAULT_WIDTH,
183
+ textureURL,
184
+ offset = Vector3.zero,
185
+ color = { x: 1, y: 1, z: 1, w: 1 }
186
+ }) {
187
+
188
+ this.maxAge = maxAge;
189
+ this.width = width;
190
+ this.textureURL = textureURL;
191
+
192
+ this.offset.fromJSON(offset);
193
+ this.color.fromJSON(color);
194
+ }
195
+
196
+
198
197
  toJSON() {
199
198
  return {
200
199
  maxAge: this.maxAge,
@@ -3,31 +3,66 @@
3
3
  */
4
4
 
5
5
 
6
+ import { assert } from "../../../../core/assert.js";
7
+ import { BVH } from "../../../../core/bvh2/bvh3/BVH.js";
8
+ import Vector3 from '../../../../core/geom/Vector3.js';
6
9
  import { clamp } from "../../../../core/math/clamp.js";
7
10
  import { max2 } from "../../../../core/math/max2.js";
11
+ import { ResourceAccessKind } from "../../../../core/model/ResourceAccessKind.js";
12
+ import { ResourceAccessSpecification } from "../../../../core/model/ResourceAccessSpecification.js";
8
13
  import { System } from '../../../ecs/System.js';
9
14
  import { Transform } from '../../../ecs/transform/Transform.js';
10
- import Vector3 from '../../../../core/geom/Vector3.js';
11
-
12
- import Trail2D, { Trail2DFlags } from './Trail2D.js';
15
+ import { Reference } from "../../../reference/v2/Reference.js";
13
16
  import { GraphicsEngine } from "../../GraphicsEngine.js";
14
- import { RibbonXFixedPhysicsSimulator } from "../../trail/x/simulator/RibbonXFixedPhysicsSimulator.js";
15
- import { RibbonX } from "../../trail/x/RibbonX.js";
17
+ import { make_bvh_visibility_builder } from "../../render/make_bvh_visibility_builder.js";
16
18
  import {
17
19
  RIBBON_ATTRIBUTE_ADDRESS_AGE,
18
20
  RIBBON_ATTRIBUTE_ADDRESS_UV_OFFSET
19
21
  } from "../../trail/x/ribbon_attributes_spec.js";
20
- import { Reference } from "../../../reference/v2/Reference.js";
22
+ import { RibbonX } from "../../trail/x/RibbonX.js";
21
23
  import { RibbonXPlugin } from "../../trail/x/RibbonXPlugin.js";
22
- import { assert } from "../../../../core/assert.js";
23
- import { ResourceAccessSpecification } from "../../../../core/model/ResourceAccessSpecification.js";
24
- import { ResourceAccessKind } from "../../../../core/model/ResourceAccessKind.js";
24
+ import { RibbonXFixedPhysicsSimulator } from "../../trail/x/simulator/RibbonXFixedPhysicsSimulator.js";
25
+
26
+ import Trail2D, { Trail2DFlags } from './Trail2D.js';
25
27
 
26
28
  const v3Temp1 = new Vector3();
27
29
 
28
30
  const v3_array = [];
29
31
 
30
32
  class Trail2DSystem extends System {
33
+ dependencies = [Trail2D, Transform];
34
+
35
+ components_used = [
36
+ ResourceAccessSpecification.from(Trail2D, ResourceAccessKind.Write)
37
+ ];
38
+
39
+ /**
40
+ *
41
+ * @type {RibbonXFixedPhysicsSimulator}
42
+ */
43
+ simulator = new RibbonXFixedPhysicsSimulator();
44
+
45
+ /**
46
+ *
47
+ * @type {Reference<RibbonXPlugin>}
48
+ * @private
49
+ */
50
+ __ribbon_plugin = Reference.NULL;
51
+
52
+
53
+ /**
54
+ *
55
+ * @type {number}
56
+ * @private
57
+ */
58
+ __timeDelta = 0;
59
+
60
+ /**
61
+ * @private
62
+ * @type {BVH}
63
+ */
64
+ bvh = new BVH();
65
+
31
66
  /**
32
67
  * @param {Engine} engine
33
68
  * @constructor
@@ -39,12 +74,6 @@ class Trail2DSystem extends System {
39
74
  assert.notNull(engine, 'engine');
40
75
  assert.equal(engine.isEngine, true, 'engine.isEngine !== true');
41
76
 
42
- this.dependencies = [Trail2D, Transform];
43
-
44
- this.components_used = [
45
- ResourceAccessSpecification.from(Trail2D, ResourceAccessKind.Write)
46
- ];
47
-
48
77
 
49
78
  /**
50
79
  *
@@ -53,13 +82,11 @@ class Trail2DSystem extends System {
53
82
  */
54
83
  this.__engine = engine;
55
84
 
56
- const graphics = engine.graphics;
57
-
58
85
  /**
59
86
  *
60
87
  * @type {GraphicsEngine}
61
88
  */
62
- this.graphics = graphics;
89
+ this.graphics = engine.graphics;
63
90
 
64
91
  /**
65
92
  *
@@ -67,45 +94,21 @@ class Trail2DSystem extends System {
67
94
  */
68
95
  this.renderLayer = null;
69
96
 
70
- /**
71
- *
72
- * @type {BinaryNode}
73
- */
74
- this.bvh = null;
75
-
76
- /**
77
- *
78
- * @type {RibbonXFixedPhysicsSimulator}
79
- */
80
- this.simulator = new RibbonXFixedPhysicsSimulator();
81
97
 
82
- /**
83
- *
84
- * @type {Reference<RibbonXPlugin>}
85
- * @private
86
- */
87
- this.__ribbon_plugin = Reference.NULL;
88
-
89
-
90
- /**
91
- *
92
- * @type {number}
93
- * @private
94
- */
95
- this.__timeDelta = 0;
96
98
  }
97
99
 
98
100
  async startup(entityManager, readyCallback, errorCallback) {
99
101
  this.entityManager = entityManager;
100
102
 
101
103
  this.renderLayer = this.graphics.layers.create('trail-2d-system');
102
- // this.renderLayer.renderPass = RenderPassType.Transparent;
103
-
104
- this.renderLayer.extractRenderable = function (trail) {
105
- return trail.mesh;
106
- };
107
104
 
108
- this.bvh = this.renderLayer.bvh;
105
+ this.renderLayer.buildVisibleSet = make_bvh_visibility_builder(
106
+ this.entityManager, this.bvh,
107
+ (destination, offset, entity, ecd) => {
108
+ destination[offset] = ecd.getComponent(entity, Trail2D).mesh
109
+ return 1;
110
+ }
111
+ );
109
112
 
110
113
  this.__ribbon_plugin = await this.__engine.plugins.acquire(RibbonXPlugin);
111
114
 
@@ -172,9 +175,9 @@ class Trail2DSystem extends System {
172
175
 
173
176
  }
174
177
 
175
- trail.bvhLeaf.resize(
176
- position_x, position_y, position_z,
177
- position_x, position_y, position_z
178
+ trail.bvh.resize(
179
+ position_x,position_y,position_z,
180
+ position_x,position_y,position_z
178
181
  );
179
182
 
180
183
  trail.setFlag(Trail2DFlags.Built);
@@ -196,7 +199,7 @@ class Trail2DSystem extends System {
196
199
  }
197
200
 
198
201
 
199
- this.bvh.insertNode(trail.bvhLeaf);
202
+ trail.bvh.link(this.bvh, entityId);
200
203
  }
201
204
 
202
205
  /**
@@ -207,10 +210,11 @@ class Trail2DSystem extends System {
207
210
  */
208
211
  unlink(component, transform, entity) {
209
212
 
213
+ component.bvh.unlink();
214
+
210
215
  // release resources
211
216
  component.dispose();
212
217
 
213
- component.bvhLeaf.disconnect();
214
218
  }
215
219
 
216
220
  /**
@@ -265,14 +269,9 @@ class Trail2DSystem extends System {
265
269
  ribbon.setPointAttribute_Scalar(head_index, RIBBON_ATTRIBUTE_ADDRESS_AGE, ageOffset);
266
270
 
267
271
  }
268
- const bvh = trail.bvhLeaf;
269
-
270
- ribbon.computeBoundingBox(bvh);
271
-
272
- if (bvh.parentNode !== null) {
273
- bvh.parentNode.bubbleRefit();
274
- }
275
272
 
273
+ ribbon.computeBoundingBox(trail.bvh.bounds);
274
+ trail.bvh.write_bounds();
276
275
 
277
276
  this.simulator.update(ribbon, trail.maxAge, timeDelta);
278
277
  }
@@ -1,11 +1,11 @@
1
- import Trail2D, { Trail2DFlags } from "./Trail2D.js";
1
+ import { assert } from "../../../../core/assert.js";
2
2
  import {
3
3
  RIBBON_ATTRIBUTE_ADDRESS_AGE,
4
4
  RIBBON_ATTRIBUTE_ADDRESS_COLOR,
5
5
  RIBBON_ATTRIBUTE_ADDRESS_THICKNESS,
6
6
  RIBBON_ATTRIBUTE_ADDRESS_UV_OFFSET
7
7
  } from "../../trail/x/ribbon_attributes_spec.js";
8
- import { assert } from "../../../../core/assert.js";
8
+ import Trail2D, { Trail2DFlags } from "./Trail2D.js";
9
9
 
10
10
  /**
11
11
  *
@@ -62,7 +62,7 @@ export function makeGradientTrail({
62
62
  trail2D.clearFlag(Trail2DFlags.Spawning);
63
63
  trail2D.setFlag(Trail2DFlags.Built);
64
64
 
65
- ribbon.computeBoundingBox(trail2D.bvhLeaf);
65
+ ribbon.computeBoundingBox(trail2D.bvh.bounds);
66
66
 
67
67
  return trail2D;
68
68
  }
@@ -0,0 +1 @@
1
+ export const WATER_SIZE = 800;
@@ -3,62 +3,69 @@
3
3
  */
4
4
 
5
5
 
6
- import Vector1 from "../../../../core/geom/Vector1.js";
7
6
  import { ClampToEdgeWrapping, DataTexture, FloatType, LinearFilter, RedFormat } from "three";
8
- import { NumericInterval } from "../../../../core/math/interval/NumericInterval.js";
7
+ import { BvhClient } from "../../../../core/bvh2/bvh3/BvhClient.js";
9
8
  import { Color } from "../../../../core/color/Color.js";
9
+ import Vector1 from "../../../../core/geom/Vector1.js";
10
+ import { NumericInterval } from "../../../../core/math/interval/NumericInterval.js";
11
+ import { threeUpdateTransform } from "../../util/threeUpdateTransform.js";
12
+ import { WATER_SIZE } from "./WATER_SIZE.js";
10
13
 
11
14
  class Water {
12
- constructor(options) {
13
- this.level = new Vector1(0);
15
+ level = new Vector1(0);
16
+ /**
17
+ *
18
+ * @type {Color}
19
+ */
20
+ color = new Color(0, 0.3, 0.5);
14
21
 
15
- if (options !== undefined) {
16
- this.fromJSON(options);
17
- }
18
22
 
19
- /**
20
- *
21
- * @type {Color}
22
- */
23
- this.color = new Color(0, 0.3, 0.5);
23
+ /**
24
+ * Defines what is considered as shore as well as how long is the transition between shore and deep water
25
+ * @type {NumericInterval}
26
+ */
27
+ shoreDepthTransition = new NumericInterval(0.7, 2);
24
28
 
25
29
 
26
- /**
27
- * Defines what is considered as shore as well as how long is the transition between shore and deep water
28
- * @type {NumericInterval}
29
- */
30
- this.shoreDepthTransition = new NumericInterval(0.7, 2);
30
+ /**
31
+ * Color of the water at the shore
32
+ * @type {Color}
33
+ */
34
+ shoreColor = new Color(0.584, 0.792, 0.850);
31
35
 
36
+ /**
37
+ *
38
+ * @type {Vector1}
39
+ */
40
+ waveSpeed = new Vector1(1.8);
32
41
 
33
- /**
34
- * Color of the water at the shore
35
- * @type {Color}
36
- */
37
- this.shoreColor = new Color(0.584, 0.792, 0.850);
42
+ /**
43
+ *
44
+ * @type {Vector1}
45
+ */
46
+ waveAmplitude = new Vector1(0.3);
38
47
 
39
- /**
40
- *
41
- * @type {Vector1}
42
- */
43
- this.waveSpeed = new Vector1(1.8);
48
+ /**
49
+ *
50
+ * @type {Vector1}
51
+ */
52
+ waveFrequency = new Vector1(1);
44
53
 
45
- /**
46
- *
47
- * @type {Vector1}
48
- */
49
- this.waveAmplitude = new Vector1(0.3);
54
+ /**
55
+ * Scattering of light, the higher this value is - the more opaque water will become
56
+ * @type {Vector1}
57
+ */
58
+ scattering = new Vector1(1.2);
50
59
 
51
- /**
52
- *
53
- * @type {Vector1}
54
- */
55
- this.waveFrequency = new Vector1(1);
60
+ bvh = new BvhClient();
61
+
62
+ constructor(options) {
63
+
64
+ if (options !== undefined) {
65
+ console.error('Constructor options are deprecated');
66
+ this.fromJSON(options);
67
+ }
56
68
 
57
- /**
58
- * Scattering of light, the higher this value is - the more opaque water will become
59
- * @type {Vector1}
60
- */
61
- this.scattering = new Vector1(1.2);
62
69
 
63
70
  /**
64
71
  *
@@ -83,6 +90,41 @@ class Water {
83
90
  this.scattering.onChanged.add(this.writeShaderUniforms, this);
84
91
  }
85
92
 
93
+ updateTransform() {
94
+ const width = WATER_SIZE;
95
+ const height = WATER_SIZE;
96
+
97
+ const mesh = this.__threeObject;
98
+
99
+ if (mesh !== null) {
100
+
101
+ mesh.rotation.x = Math.PI * 0.5;
102
+ mesh.position.x = width / 4;
103
+ mesh.position.z = height / 4;
104
+ mesh.position.y = this.level.getValue();
105
+
106
+ threeUpdateTransform(mesh);
107
+ }
108
+
109
+ this.updateBounds();
110
+ }
111
+
112
+ updateBounds() {
113
+ const width = WATER_SIZE;
114
+ const height = WATER_SIZE;
115
+
116
+ const level = this.level.getValue();
117
+
118
+ this.bvh.resize(
119
+ -width / 4,
120
+ level,
121
+ -height / 4,
122
+ width * (3 / 4),
123
+ level,
124
+ height * (3 / 4)
125
+ );
126
+ }
127
+
86
128
  /**
87
129
  *
88
130
  * @param {Terrain} terrain