@woosh/meep-engine 2.65.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.
- package/build/bundle-worker-terrain.js +1 -1
- package/build/meep.cjs +52474 -53800
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +52474 -53800
- 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/camera/testClippingPlaneComputation.js +3 -6
- 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/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/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 +8 -2
- package/src/engine/graphics/render/layers/RenderLayer.js +7 -65
- 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
|
@@ -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
|
|
@@ -1,21 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Created by Alex on 17/02/2017.
|
|
3
3
|
*/
|
|
4
|
-
import { BackSide,
|
|
4
|
+
import { BackSide, PlaneBufferGeometry } from 'three';
|
|
5
|
+
import { BVH } from "../../../../core/bvh2/bvh3/BVH.js";
|
|
5
6
|
import { System } from '../../../ecs/System.js';
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { obtainTerrain } from "../../../ecs/terrain/util/obtainTerrain.js";
|
|
8
|
+
import { make_bvh_visibility_builder } from "../../render/make_bvh_visibility_builder.js";
|
|
9
|
+
import { StandardFrameBuffers } from "../../StandardFrameBuffers.js";
|
|
9
10
|
import ThreeFactory from "../../three/ThreeFactory.js";
|
|
10
|
-
import { RenderPassType } from "../../render/RenderPassType.js";
|
|
11
11
|
import { makeAlexWaterMaterial } from "../water2/shader/AlexWaterShader.js";
|
|
12
|
-
import
|
|
13
|
-
import {
|
|
14
|
-
import { obtainTerrain } from "../../../ecs/terrain/util/obtainTerrain.js";
|
|
15
|
-
|
|
16
|
-
const WATER_SIZE = 800;
|
|
12
|
+
import Water from './Water.js';
|
|
13
|
+
import { WATER_SIZE } from "./WATER_SIZE.js";
|
|
17
14
|
|
|
18
15
|
class WaterSystem extends System {
|
|
16
|
+
dependencies = [Water];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @readonly
|
|
20
|
+
* @type {BVH}
|
|
21
|
+
*/
|
|
22
|
+
bvh = new BVH();
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
cleaup = [];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @type {Water[]}
|
|
30
|
+
*/
|
|
31
|
+
updateQueue = [];
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @type {number}
|
|
36
|
+
* @private
|
|
37
|
+
*/
|
|
38
|
+
__time_delta = 0;
|
|
39
|
+
|
|
19
40
|
/**
|
|
20
41
|
*
|
|
21
42
|
* @param {GraphicsEngine} graphics
|
|
@@ -24,7 +45,6 @@ class WaterSystem extends System {
|
|
|
24
45
|
constructor(graphics) {
|
|
25
46
|
super();
|
|
26
47
|
|
|
27
|
-
this.dependencies = [Water];
|
|
28
48
|
|
|
29
49
|
this.graphicsEngine = graphics;
|
|
30
50
|
|
|
@@ -34,29 +54,6 @@ class WaterSystem extends System {
|
|
|
34
54
|
*/
|
|
35
55
|
this.renderLayer = null;
|
|
36
56
|
|
|
37
|
-
/**
|
|
38
|
-
*
|
|
39
|
-
* @type {BinaryNode}
|
|
40
|
-
*/
|
|
41
|
-
this.bvh = null;
|
|
42
|
-
|
|
43
|
-
//TODO override "computeFrustumClippingPlanes", this is a hack to get camera system to work as indeded when computing clipping planes
|
|
44
|
-
//TODO come up with a less convoluted design
|
|
45
|
-
|
|
46
|
-
this.cleaup = [];
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
*
|
|
50
|
-
* @type {Water[]}
|
|
51
|
-
*/
|
|
52
|
-
this.updateQueue = [];
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
*
|
|
56
|
-
* @type {number}
|
|
57
|
-
* @private
|
|
58
|
-
*/
|
|
59
|
-
this.__time_delta = 0;
|
|
60
57
|
}
|
|
61
58
|
|
|
62
59
|
|
|
@@ -81,43 +78,21 @@ class WaterSystem extends System {
|
|
|
81
78
|
|
|
82
79
|
const viewport_size = graphicsEngine.viewport.size;
|
|
83
80
|
|
|
84
|
-
this.renderLayer.
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
this.renderLayer.buildVisibleSet = make_bvh_visibility_builder(
|
|
82
|
+
this.entityManager, this.bvh,
|
|
83
|
+
(destination, offset, entity, ecd) => {
|
|
84
|
+
const component = ecd.getComponent(entity, Water);
|
|
87
85
|
|
|
88
|
-
|
|
86
|
+
const mesh = component.__threeObject;
|
|
89
87
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
* @param {function(near:number, far:number)} visitor
|
|
94
|
-
*/
|
|
95
|
-
this.renderLayer.computeNearFarClippingPlanes = buildPlanarRenderLayerClipPlaneComputationMethod(function (visitor) {
|
|
88
|
+
if (mesh === null) {
|
|
89
|
+
return 0
|
|
90
|
+
}
|
|
96
91
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
* @type {EntityComponentDataset}
|
|
100
|
-
*/
|
|
101
|
-
const dataset = entityManager.dataset;
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
*
|
|
105
|
-
* @param {Water} water
|
|
106
|
-
* @param entity
|
|
107
|
-
*/
|
|
108
|
-
function componentVisitor(water, entity) {
|
|
109
|
-
|
|
110
|
-
//determinate the plane
|
|
111
|
-
const plane = new Plane(new ThreeVector3(0, 1, 0), water.level.getValue());
|
|
112
|
-
|
|
113
|
-
visitor(plane);
|
|
92
|
+
destination[offset] = mesh;
|
|
93
|
+
return 1;
|
|
114
94
|
}
|
|
115
|
-
|
|
116
|
-
dataset.traverseComponents(Water, componentVisitor);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
this.bvh = this.renderLayer.bvh;
|
|
95
|
+
)
|
|
121
96
|
|
|
122
97
|
|
|
123
98
|
const self = this;
|
|
@@ -191,64 +166,37 @@ class WaterSystem extends System {
|
|
|
191
166
|
|
|
192
167
|
water.side = BackSide;
|
|
193
168
|
|
|
194
|
-
/**
|
|
195
|
-
* @type {Object3D}
|
|
196
|
-
*/
|
|
197
|
-
let mesh;
|
|
198
169
|
if (component.__threeObject === null) {
|
|
199
170
|
const geometry = new PlaneBufferGeometry(width, height, 1, 1);
|
|
200
171
|
|
|
201
|
-
mesh = ThreeFactory.createMesh(
|
|
172
|
+
const mesh = ThreeFactory.createMesh(
|
|
202
173
|
geometry,
|
|
203
174
|
water
|
|
204
175
|
);
|
|
205
176
|
|
|
206
|
-
|
|
207
177
|
component.__threeObject = mesh;
|
|
208
|
-
} else {
|
|
209
|
-
mesh = component.__threeObject;
|
|
210
178
|
}
|
|
211
179
|
|
|
212
|
-
|
|
213
|
-
mesh.position.x = width / 4;
|
|
214
|
-
mesh.position.z = height / 4;
|
|
215
|
-
mesh.position.y = component.level.getValue();
|
|
216
|
-
|
|
217
|
-
threeUpdateTransform(mesh);
|
|
180
|
+
component.updateTransform();
|
|
218
181
|
|
|
219
|
-
|
|
220
|
-
component,
|
|
182
|
+
component.level.onChanged.add(component.updateTransform, component);
|
|
221
183
|
|
|
222
|
-
|
|
223
|
-
component.level.getValue(),
|
|
224
|
-
-height / 4,
|
|
225
|
-
width * (3 / 4),
|
|
226
|
-
component.level.getValue(),
|
|
227
|
-
height * (3 / 4)
|
|
228
|
-
);
|
|
229
|
-
|
|
230
|
-
component.bvh = leafNode;
|
|
231
|
-
|
|
232
|
-
function processLevelValue(v, oldV) {
|
|
233
|
-
mesh.position.y = v;
|
|
234
|
-
threeUpdateTransform(mesh);
|
|
235
|
-
|
|
236
|
-
leafNode.move(0, 0, v - oldV);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
component.level.onChanged.add(processLevelValue);
|
|
240
|
-
|
|
241
|
-
this.bvh.insertNode(leafNode);
|
|
184
|
+
component.bvh.link(this.bvh, entity);
|
|
242
185
|
|
|
243
186
|
this.cleaup[entity] = function () {
|
|
244
|
-
component.level.onChanged.remove(
|
|
187
|
+
component.level.onChanged.remove(component.updateTransform, component);
|
|
245
188
|
};
|
|
246
189
|
|
|
247
190
|
this.updateQueue.push(component);
|
|
248
191
|
}
|
|
249
192
|
|
|
193
|
+
/**
|
|
194
|
+
*
|
|
195
|
+
* @param {Water} component
|
|
196
|
+
* @param {number} entity
|
|
197
|
+
*/
|
|
250
198
|
unlink(component, entity) {
|
|
251
|
-
component.bvh.
|
|
199
|
+
component.bvh.unlink();
|
|
252
200
|
|
|
253
201
|
const cleaup = this.cleaup[entity];
|
|
254
202
|
cleaup();
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { mat4 } from "gl-matrix";
|
|
2
2
|
|
|
3
3
|
import { Vector3 as ThreeVector3 } from 'three';
|
|
4
|
-
import { rayTriangleIntersection } from "../../../../../core/geom/3d/triangle/rayTriangleIntersection.js";
|
|
5
|
-
import { SurfacePoint3 } from "../../../../../core/geom/3d/SurfacePoint3.js";
|
|
6
4
|
import { assert } from "../../../../../core/assert.js";
|
|
7
|
-
import { v3_length } from "../../../../../core/geom/vec3/v3_length.js";
|
|
8
|
-
import { ray3_array_apply_matrix4 } from "../../../../../core/geom/3d/ray/ray3_array_apply_matrix4.js";
|
|
9
|
-
import { mat4 } from "gl-matrix";
|
|
10
|
-
import { ray3_array_compose } from "../../../../../core/geom/3d/ray/ray3_array_compose.js";
|
|
11
5
|
import { array_copy } from "../../../../../core/collection/array/array_copy.js";
|
|
12
6
|
import { MATRIX_4_IDENTITY } from "../../../../../core/geom/3d/matrix/MATRIX_4_IDENTITY.js";
|
|
7
|
+
import { ray3_array_apply_matrix4 } from "../../../../../core/geom/3d/ray/ray3_array_apply_matrix4.js";
|
|
8
|
+
import { ray3_array_compose } from "../../../../../core/geom/3d/ray/ray3_array_compose.js";
|
|
9
|
+
import { SurfacePoint3 } from "../../../../../core/geom/3d/SurfacePoint3.js";
|
|
10
|
+
import { rayTriangleIntersection } from "../../../../../core/geom/3d/triangle/rayTriangleIntersection.js";
|
|
11
|
+
import { v3_length } from "../../../../../core/geom/vec3/v3_length.js";
|
|
12
|
+
import Vector3 from "../../../../../core/geom/Vector3.js";
|
|
13
13
|
|
|
14
14
|
const hit = new ThreeVector3();
|
|
15
15
|
|
|
@@ -42,6 +42,12 @@ function bindGeometryFace(indices, vertices, index) {
|
|
|
42
42
|
|
|
43
43
|
const vNormal = new Vector3();
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @param {number[]} indices
|
|
48
|
+
* @param {number[]} normals
|
|
49
|
+
* @param {number} index
|
|
50
|
+
*/
|
|
45
51
|
function bindGeometryFaceNormal(indices, normals, index) {
|
|
46
52
|
|
|
47
53
|
const index3 = index * 3;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { max3 } from "../../../../../core/math/max3.js";
|
|
2
|
+
import { min3 } from "../../../../../core/math/min3.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param {BinaryUint32BVH} bvh
|
|
7
|
+
* @param {Float32Array} vertices
|
|
8
|
+
* @param {Uint32Array} indices
|
|
9
|
+
*/
|
|
10
|
+
export function bvh32_from_indexed_geometry(bvh, vertices, indices) {
|
|
11
|
+
|
|
12
|
+
const triangle_count = indices.length / 3;
|
|
13
|
+
|
|
14
|
+
bvh.setLeafCount(triangle_count);
|
|
15
|
+
bvh.initialize_structure();
|
|
16
|
+
|
|
17
|
+
for (let i = 0; i < triangle_count; i++) {
|
|
18
|
+
|
|
19
|
+
const index3 = i * 3;
|
|
20
|
+
|
|
21
|
+
// read triangle vertex indices
|
|
22
|
+
const iA = indices[index3];
|
|
23
|
+
const iB = indices[index3 + 1];
|
|
24
|
+
const iC = indices[index3 + 2];
|
|
25
|
+
|
|
26
|
+
const a = iA * 3;
|
|
27
|
+
const b = iB * 3;
|
|
28
|
+
const c = iC * 3;
|
|
29
|
+
|
|
30
|
+
// read actual positions of each vertex
|
|
31
|
+
const aX = vertices[a];
|
|
32
|
+
const aY = vertices[a + 1];
|
|
33
|
+
const aZ = vertices[a + 2];
|
|
34
|
+
|
|
35
|
+
const bX = vertices[b];
|
|
36
|
+
const bY = vertices[b + 1];
|
|
37
|
+
const bZ = vertices[b + 2];
|
|
38
|
+
|
|
39
|
+
const cX = vertices[c];
|
|
40
|
+
const cY = vertices[c + 1];
|
|
41
|
+
const cZ = vertices[c + 2];
|
|
42
|
+
|
|
43
|
+
// compute bounds of the triangle
|
|
44
|
+
const x0 = min3(aX, bX, cX);
|
|
45
|
+
const y0 = min3(aY, bY, cY);
|
|
46
|
+
const z0 = min3(aZ, bZ, cZ);
|
|
47
|
+
|
|
48
|
+
const x1 = max3(aX, bX, cX);
|
|
49
|
+
const y1 = max3(aY, bY, cY);
|
|
50
|
+
const z1 = max3(aZ, bZ, cZ);
|
|
51
|
+
|
|
52
|
+
bvh.setLeafData(i, i, x0, y0, z0, x1, y1, z1)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// finalize build
|
|
56
|
+
// bvh.sort_morton(MATRIX_4_IDENTITY);
|
|
57
|
+
bvh.build();
|
|
58
|
+
}
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import {assert} from "../../../../core/assert.js";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
} from "
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {ParticleEmitter} from "../particular/engine/emitter/ParticleEmitter.js";
|
|
13
|
-
import {ParticleEmitterFlag} from "../particular/engine/emitter/ParticleEmitterFlag.js";
|
|
14
|
-
import {ParticularEngine} from "../particular/engine/ParticularEngine.js";
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
* @param {ParticleEmitter} emitter
|
|
19
|
-
* @returns {Group|Object3D}
|
|
20
|
-
*/
|
|
21
|
-
function extractRenderable(emitter) {
|
|
22
|
-
return emitter.mesh;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const scratch_array = [];
|
|
1
|
+
import { assert } from "../../../../core/assert.js";
|
|
2
|
+
import { ResourceAccessKind } from "../../../../core/model/ResourceAccessKind.js";
|
|
3
|
+
import { ResourceAccessSpecification } from "../../../../core/model/ResourceAccessSpecification.js";
|
|
4
|
+
import { ImageRGBADataLoader } from "../../../asset/loaders/image/ImageRGBADataLoader.js";
|
|
5
|
+
import { System } from "../../../ecs/System.js";
|
|
6
|
+
import { Transform } from "../../../ecs/transform/Transform.js";
|
|
7
|
+
import { make_bvh_visibility_builder } from "../../render/make_bvh_visibility_builder.js";
|
|
8
|
+
import { StandardFrameBuffers } from "../../StandardFrameBuffers.js";
|
|
9
|
+
import { ParticleEmitter } from "../particular/engine/emitter/ParticleEmitter.js";
|
|
10
|
+
import { ParticleEmitterFlag } from "../particular/engine/emitter/ParticleEmitterFlag.js";
|
|
11
|
+
import { ParticularEngine } from "../particular/engine/ParticularEngine.js";
|
|
26
12
|
|
|
27
13
|
export class ParticleEmitterSystem extends System {
|
|
14
|
+
dependencies = [ParticleEmitter, Transform];
|
|
15
|
+
|
|
16
|
+
components_used = [
|
|
17
|
+
ResourceAccessSpecification.from(ParticleEmitter, ResourceAccessKind.Read | ResourceAccessKind.Write)
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @type {RenderLayer|null}
|
|
23
|
+
*/
|
|
24
|
+
renderLayer = null;
|
|
25
|
+
|
|
26
|
+
__handlers = [];
|
|
27
|
+
|
|
28
28
|
/**
|
|
29
29
|
*
|
|
30
30
|
* @extends {System.<ParticleEmitter>}
|
|
@@ -37,12 +37,6 @@ export class ParticleEmitterSystem extends System {
|
|
|
37
37
|
assert.defined(engine, 'engine');
|
|
38
38
|
assert.equal(engine.isEngine, true, 'engine.isEngine !== true');
|
|
39
39
|
|
|
40
|
-
this.dependencies = [ParticleEmitter, Transform];
|
|
41
|
-
|
|
42
|
-
this.components_used = [
|
|
43
|
-
ResourceAccessSpecification.from(ParticleEmitter, ResourceAccessKind.Read | ResourceAccessKind.Write)
|
|
44
|
-
];
|
|
45
|
-
|
|
46
40
|
/**
|
|
47
41
|
*
|
|
48
42
|
* @type {GraphicsEngine}
|
|
@@ -61,13 +55,6 @@ export class ParticleEmitterSystem extends System {
|
|
|
61
55
|
*/
|
|
62
56
|
this.particleEngine = new ParticularEngine(engine.assetManager, engine.graphics.getMaterialManager());
|
|
63
57
|
|
|
64
|
-
/**
|
|
65
|
-
*
|
|
66
|
-
* @type {RenderLayer|null}
|
|
67
|
-
*/
|
|
68
|
-
this.renderLayer = null;
|
|
69
|
-
|
|
70
|
-
this.__handlers = [];
|
|
71
58
|
}
|
|
72
59
|
|
|
73
60
|
async startup(entityManager, readyCallback, errorCallback) {
|
|
@@ -87,33 +74,16 @@ export class ParticleEmitterSystem extends System {
|
|
|
87
74
|
|
|
88
75
|
this.renderLayer = renderLayer;
|
|
89
76
|
|
|
90
|
-
renderLayer.
|
|
91
|
-
|
|
92
|
-
|
|
77
|
+
renderLayer.buildVisibleSet = make_bvh_visibility_builder(
|
|
78
|
+
this.entityManager, this.particleEngine.bvh,
|
|
79
|
+
(destination, offset, entity, ecd) => {
|
|
80
|
+
const component = ecd.getComponent(entity, ParticleEmitter);
|
|
93
81
|
|
|
94
|
-
const ecd = entityManager.dataset;
|
|
95
82
|
|
|
96
|
-
|
|
97
|
-
return
|
|
83
|
+
destination[offset] = component.mesh;
|
|
84
|
+
return 1;
|
|
98
85
|
}
|
|
99
|
-
|
|
100
|
-
const view_frustum = view.frustum;
|
|
101
|
-
|
|
102
|
-
const hit_count = bvh_query_user_data_overlaps_frustum(scratch_array, 0, this.particleEngine.bvh, view_frustum);
|
|
103
|
-
|
|
104
|
-
for (let i = 0; i < hit_count; i++) {
|
|
105
|
-
const id = scratch_array[i];
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* @type {ParticleEmitter}
|
|
109
|
-
*/
|
|
110
|
-
const emitter = ecd.getComponent(id, ParticleEmitter);
|
|
111
|
-
|
|
112
|
-
destination[destination_offset + i] = emitter.mesh;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return hit_count;
|
|
116
|
-
};
|
|
86
|
+
);
|
|
117
87
|
|
|
118
88
|
renderLayer.visibleSet.onAdded.add((points) => {
|
|
119
89
|
/**
|
|
@@ -516,7 +516,7 @@ export class ParticleEmitter {
|
|
|
516
516
|
const ebb = this.emissionBounds;
|
|
517
517
|
const pbb = this.particleBounds;
|
|
518
518
|
|
|
519
|
-
aabb3_array_combine(this.bvh_leaf.bounds, ebb, pbb);
|
|
519
|
+
aabb3_array_combine(this.bvh_leaf.bounds,0, ebb,0, pbb,0);
|
|
520
520
|
|
|
521
521
|
this.bvh_leaf.write_bounds();
|
|
522
522
|
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import { EngineHarness } from "../../../../../../EngineHarness.js";
|
|
2
|
-
import { ParticlePool } from "../../emitter/ParticlePool.js";
|
|
3
|
-
import { make_particle_billboard_shader } from "./ParticleBillboardMaterial.js";
|
|
4
1
|
import { DataTexture, LinearFilter, LinearMipMapLinearFilter, Matrix4, Points } from "three";
|
|
5
|
-
import
|
|
6
|
-
import { writeSample2DDataToDataTexture } from "../../../../../texture/sampler/writeSampler2DDataToDataTexture.js";
|
|
2
|
+
import Vector3 from "../../../../../../../core/geom/Vector3.js";
|
|
7
3
|
import { ImageRGBADataLoader } from "../../../../../../asset/loaders/image/ImageRGBADataLoader.js";
|
|
8
|
-
import { EngineConfiguration } from "../../../../../../EngineConfiguration.js";
|
|
9
|
-
import { MeshSystem } from "../../../../../ecs/mesh/MeshSystem.js";
|
|
10
4
|
import Entity from "../../../../../../ecs/Entity.js";
|
|
11
5
|
import { Transform } from "../../../../../../ecs/transform/Transform.js";
|
|
6
|
+
import { EngineConfiguration } from "../../../../../../EngineConfiguration.js";
|
|
7
|
+
import { EngineHarness } from "../../../../../../EngineHarness.js";
|
|
12
8
|
import Mesh from "../../../../../ecs/mesh/Mesh.js";
|
|
13
|
-
import
|
|
14
|
-
import { RenderPassType } from "../../../../../render/RenderPassType.js";
|
|
9
|
+
import { MeshSystem } from "../../../../../ecs/mesh/MeshSystem.js";
|
|
15
10
|
import { StandardFrameBuffers } from "../../../../../StandardFrameBuffers.js";
|
|
11
|
+
import { ManagedAtlas } from "../../../../../texture/atlas/ManagedTextureAtlas.js";
|
|
12
|
+
import { writeSample2DDataToDataTexture } from "../../../../../texture/sampler/writeSampler2DDataToDataTexture.js";
|
|
13
|
+
import { ParticlePool } from "../../emitter/ParticlePool.js";
|
|
16
14
|
import {
|
|
17
15
|
BILLBOARD_PARTICLE_ATTRIBUTE_BLEND,
|
|
18
16
|
BILLBOARD_PARTICLE_ATTRIBUTE_COLOR,
|
|
@@ -21,6 +19,7 @@ import {
|
|
|
21
19
|
BILLBOARD_PARTICLE_ATTRIBUTE_UV,
|
|
22
20
|
BILLBOARD_PARTICLE_SPECIFICATION
|
|
23
21
|
} from "./BILLBOARD_PARTICLE_SPECIFICATION.js";
|
|
22
|
+
import { make_particle_billboard_shader } from "./ParticleBillboardMaterial.js";
|
|
24
23
|
|
|
25
24
|
|
|
26
25
|
const engineHarness = new EngineHarness();
|
|
@@ -113,8 +112,6 @@ async function main(engine) {
|
|
|
113
112
|
layer.visibleSet.push(points);
|
|
114
113
|
layer.visibleSet.finalizeUpdate();
|
|
115
114
|
|
|
116
|
-
layer.renderPass = RenderPassType.Transparent;
|
|
117
|
-
|
|
118
115
|
engine.graphics.on.visibilityConstructionStarted.add((renderer, camera, scene) => {
|
|
119
116
|
renderer.getSize(shaderMaterial.uniforms.resolution.value);
|
|
120
117
|
|