@woosh/meep-engine 2.65.0 → 2.67.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.
- package/build/bundle-worker-terrain.js +1 -1
- package/build/meep.cjs +51290 -54244
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +51290 -54244
- package/editor/ecs/component/editors/ecs/terrain/TerrainEditor.js +4 -10
- package/editor/process/symbolic/makeGridPositionSymbolDisplay.js +7 -7
- package/editor/tools/SelectionTool.js +6 -95
- package/package.json +1 -1
- package/src/core/bvh2/binary/2/BinaryUint32BVH.js +118 -113
- package/src/core/bvh2/binary/2/BinaryUint32BVH.spec.js +54 -0
- package/src/core/bvh2/binary/2/bvh32_query_user_data_ray.js +98 -0
- package/src/core/bvh2/bvh3/BVH.d.ts +1 -1
- package/src/core/bvh2/bvh3/BvhClient.d.ts +11 -0
- package/src/core/bvh2/bvh3/BvhClient.js +19 -0
- package/src/core/collection/array/array_copy.js +6 -0
- package/src/core/geom/3d/aabb/aabb3_array_combine.js +17 -8
- package/src/core/geom/3d/aabb/aabb3_array_intersects_ray.js +5 -2
- package/src/core/geom/3d/aabb/aabb3_array_set.js +25 -0
- package/src/core/geom/3d/aabb/aabb3_compute_half_surface_area.js +3 -0
- package/src/core/geom/3d/triangle/computeTriangleRayIntersectionBarycentric.js +8 -1
- package/src/engine/EngineHarness.js +23 -25
- package/src/engine/ecs/renderable/RenderSystem.js +44 -32
- package/src/engine/ecs/renderable/Renderable.d.ts +2 -2
- package/src/engine/ecs/renderable/Renderable.js +12 -11
- package/src/engine/ecs/terrain/ecs/Terrain.js +83 -87
- package/src/engine/ecs/terrain/ecs/TerrainSystem.js +106 -57
- package/src/engine/ecs/terrain/ecs/makeTerrainWorkerProxy.js +5 -2
- package/src/engine/ecs/terrain/tiles/TerrainTile.js +122 -67
- package/src/engine/ecs/terrain/tiles/TerrainTileManager.js +162 -146
- package/src/engine/ecs/terrain/tiles/TileBuildWorker.js +16 -5
- package/src/engine/graphics/GraphicsEngine.js +16 -25
- package/src/engine/graphics/camera/testClippingPlaneComputation.js +8 -11
- package/src/engine/graphics/debug/VisualSymbolLine.js +1 -0
- package/src/engine/graphics/ecs/camera/CameraSystem.js +9 -9
- package/src/engine/graphics/ecs/camera/auto_set_camera_clipping_planes.js +3 -23
- package/src/engine/graphics/ecs/compileAllMaterials.js +5 -12
- package/src/engine/graphics/ecs/light/LightSystem.js +12 -48
- package/src/engine/graphics/ecs/mesh/MeshSystem.js +9 -31
- package/src/engine/graphics/ecs/mesh/updateNodeByTransformAndBBB.js +3 -43
- package/src/engine/graphics/ecs/mesh-v2/sample/prototypeShadedGeometry.js +22 -24
- package/src/engine/graphics/ecs/mesh-v2/sample/prototype_sg_raycast.js +21 -23
- package/src/engine/graphics/ecs/trail2d/Trail2D.js +105 -106
- package/src/engine/graphics/ecs/trail2d/Trail2DSystem.js +60 -61
- package/src/engine/graphics/ecs/trail2d/makeGradientTrail.js +3 -3
- package/src/engine/graphics/ecs/water/WATER_SIZE.js +1 -0
- package/src/engine/graphics/ecs/water/Water.js +84 -42
- package/src/engine/graphics/ecs/water/WaterSystem.js +53 -105
- package/src/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +13 -7
- package/src/engine/graphics/geometry/bvh/buffered/bvh32_from_indexed_geometry.js +58 -0
- package/src/engine/graphics/particles/ecs/ParticleEmitterSystem.js +32 -62
- package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +1 -1
- package/src/engine/graphics/particles/particular/engine/renderers/billboard/prototypeBillboardRenderer.js +8 -11
- package/src/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +21 -19
- package/src/engine/graphics/render/layers/RenderLayer.d.ts +4 -3
- package/src/engine/graphics/render/layers/RenderLayer.js +34 -108
- package/src/engine/graphics/render/make_bvh_visibility_builder.js +64 -0
- package/src/engine/graphics/three/expand_aabb_by_transformed_three_object.js +4 -4
- package/src/engine/graphics/trail/x/RibbonX.js +26 -5
- package/src/core/bvh2/binary/tiny/TinyBVH.js +0 -221
- 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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
|
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 {
|
|
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 {
|
|
22
|
+
import { RibbonX } from "../../trail/x/RibbonX.js";
|
|
21
23
|
import { RibbonXPlugin } from "../../trail/x/RibbonXPlugin.js";
|
|
22
|
-
import {
|
|
23
|
-
|
|
24
|
-
import {
|
|
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.
|
|
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.
|
|
176
|
-
position_x,
|
|
177
|
-
position_x,
|
|
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
|
-
|
|
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
|
|
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 {
|
|
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.
|
|
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 {
|
|
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
|
-
|
|
13
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* @type {Vector1}
|
|
45
|
+
*/
|
|
46
|
+
waveAmplitude = new Vector1(0.3);
|
|
38
47
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
/**
|
|
49
|
+
*
|
|
50
|
+
* @type {Vector1}
|
|
51
|
+
*/
|
|
52
|
+
waveFrequency = new Vector1(1);
|
|
44
53
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|