@woosh/meep-engine 2.60.1 → 2.62.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/meep.cjs +20244 -20262
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +20244 -20262
- package/package.json +1 -1
- package/src/core/binary/BitSet.js +1 -1
- package/src/core/bvh2/BinaryNode.js +16 -13
- package/src/core/bvh2/LeafNode.js +6 -3
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_overlaps_sphere.js +81 -0
- package/src/core/geom/3d/aabb/AABB3.js +24 -36
- package/src/core/geom/3d/aabb/aabb3_array_compute_from_sphere.js +22 -0
- package/src/core/geom/3d/aabb/aabb3_array_intersects_sphere.js +22 -0
- package/src/core/geom/3d/aabb/aabb3_array_intersects_sphere_array.js +11 -0
- package/src/core/geom/3d/aabb/aabb3_signed_distance_to_aabb3.js +28 -0
- package/src/core/geom/3d/aabb/serializeAABB3Quantized16Uint.js +19 -10
- package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.js +30 -182
- package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.spec.js +27 -1
- package/src/core/geom/3d/tetrahedra/delaunay/Cavity.js +3 -4
- package/src/core/geom/ConicRay.js +16 -21
- package/src/core/geom/ConicRay.spec.js +24 -0
- package/src/core/geom/packing/miniball/Miniball.js +68 -117
- package/src/core/geom/packing/miniball/Miniball.spec.js +3 -3
- package/src/core/geom/packing/miniball/Subspan.js +47 -34
- package/src/core/geom/packing/miniball/miniball_compute_quality.js +64 -0
- package/src/core/math/bessel_3.js +1 -0
- package/src/core/math/random/randomBytes.js +2 -2
- package/src/core/math/sqr.js +8 -0
- package/src/core/model/node-graph/Connection.js +21 -23
- package/src/core/model/node-graph/DataType.js +16 -17
- package/src/core/model/node-graph/NodeGraph.js +49 -50
- package/src/core/model/node-graph/node/NodeDescription.js +42 -44
- package/src/core/model/node-graph/node/NodeInstance.js +59 -60
- package/src/core/model/node-graph/node/NodeInstancePortReference.js +27 -29
- package/src/core/model/node-graph/node/NodeRegistry.js +16 -18
- package/src/core/model/node-graph/node/Port.js +35 -37
- package/src/core/model/node-graph/node/parameter/NodeParameterDescription.js +27 -13
- package/src/core/path/computePathDirectory.spec.js +8 -0
- package/src/core/process/BaseProcess.d.ts +5 -0
- package/src/core/process/WatchDog.js +76 -75
- package/src/core/process/action/AsynchronousAction.js +24 -22
- package/src/core/process/executor/profile/Profile.js +34 -24
- package/src/core/process/executor/profile/TraceEvent.js +75 -75
- package/src/core/process/worker/OnDemandWorkerManager.js +27 -30
- package/src/core/process/worker/WorkerBuilder.js +149 -149
- package/src/core/process/worker/WorkerProxy.js +25 -21
- package/src/core/process/worker/extractTransferables.js +2 -2
- package/src/engine/Engine.js +58 -53
- package/src/engine/EngineConfiguration.d.ts +4 -4
- package/src/engine/ecs/EntityManager.js +517 -614
- package/src/engine/ecs/System.js +2 -2
- package/src/engine/ecs/foliage/ecs/Foliage2System.js +3 -0
- package/src/engine/ecs/foliage/ecs/InstancedMeshComponent.js +4 -1
- package/src/engine/ecs/foliage/ecs/convertInstancedMeshComponents2Entities.js +64 -0
- package/src/engine/ecs/foliage/ecs/{InstancedMeshUtils.js → optimizeIndividualMeshesEntitiesToInstances.js} +11 -70
- package/src/engine/ecs/transform/Transform.d.ts +7 -5
- package/src/engine/ecs/transform/Transform.js +30 -16
- package/src/engine/ecs/validateSystem.js +89 -0
- package/src/engine/graphics/GraphicsEngine.js +433 -483
- package/src/engine/graphics/camera/testClippingPlaneComputation.js +42 -46
- package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +2 -2
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +2 -2
- package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshSystem.js +2 -2
- package/src/engine/graphics/ecs/path/testPathDisplaySystem.js +49 -52
- package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +52 -56
- package/src/engine/graphics/ecs/water2/shader/testWaterShader.js +20 -22
- package/src/engine/graphics/particles/ecs/ParticleEmitterSystem.js +43 -25
- package/src/engine/graphics/particles/particular/engine/ParticularEngine.js +160 -180
- package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +37 -41
- package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +63 -67
- package/src/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +46 -50
- package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +61 -65
- package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +48 -52
- package/src/engine/graphics/shadows/testShadowMapRendering.js +28 -32
- package/src/engine/graphics/texture/sampler/resize/sampler2d_scale_down_lanczos.spec.js +22 -20
- package/src/engine/graphics/texture/sampler/resize/sampler2d_scale_down_linear.js +10 -13
- package/src/engine/graphics/texture/virtual/VirtualTexture.spec.js +1 -1
- package/src/engine/plugin/EnginePluginManager.d.ts +6 -1
- package/src/engine/sound/dB2Volume.js +8 -0
- package/src/engine/sound/ecs/emitter/SoundEmitter.js +125 -99
- package/src/engine/sound/ecs/emitter/SoundEmitterComponentContext.js +4 -42
- package/src/engine/sound/ecs/emitter/SoundEmitterSystem.js +31 -121
- package/src/engine/sound/volume2dB.js +8 -0
- package/src/generation/theme/ThemeEngine.js +19 -53
- package/src/engine/ecs/components/ClingToHeightMap.js +0 -19
- package/src/engine/ecs/components/SynchronizePosition.js +0 -15
- package/src/engine/ecs/systems/ClingToHeightMapSystem.js +0 -170
- package/src/engine/ecs/systems/SynchronizePositionSystem.js +0 -43
- package/src/engine/graphics/geometry/bvh/buffered/BVHFromBufferGeometry.js +0 -133
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
1
|
+
import {assert} from "../../../../core/assert.js";
|
|
2
|
+
import {
|
|
3
|
+
bvh_query_user_data_overlaps_frustum
|
|
4
|
+
} from "../../../../core/bvh2/bvh3/query/bvh_query_user_data_overlaps_frustum.js";
|
|
5
|
+
import {ResourceAccessKind} from "../../../../core/model/ResourceAccessKind.js";
|
|
6
|
+
import {ResourceAccessSpecification} from "../../../../core/model/ResourceAccessSpecification.js";
|
|
7
|
+
import {ImageRGBADataLoader} from "../../../asset/loaders/image/ImageRGBADataLoader.js";
|
|
8
|
+
import {System} from "../../../ecs/System.js";
|
|
9
|
+
import {Transform} from "../../../ecs/transform/Transform.js";
|
|
10
|
+
import {RenderPassType} from "../../render/RenderPassType.js";
|
|
11
|
+
import {StandardFrameBuffers} from "../../StandardFrameBuffers.js";
|
|
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";
|
|
12
15
|
|
|
13
16
|
/**
|
|
14
17
|
*
|
|
@@ -19,6 +22,7 @@ function extractRenderable(emitter) {
|
|
|
19
22
|
return emitter.mesh;
|
|
20
23
|
}
|
|
21
24
|
|
|
25
|
+
const scratch_array = [];
|
|
22
26
|
|
|
23
27
|
export class ParticleEmitterSystem extends System {
|
|
24
28
|
/**
|
|
@@ -63,19 +67,9 @@ export class ParticleEmitterSystem extends System {
|
|
|
63
67
|
*/
|
|
64
68
|
this.renderLayer = null;
|
|
65
69
|
|
|
66
|
-
/**
|
|
67
|
-
*
|
|
68
|
-
* @type {BinaryNode}
|
|
69
|
-
*/
|
|
70
|
-
this.bvh = null;
|
|
71
|
-
|
|
72
70
|
this.__handlers = [];
|
|
73
71
|
}
|
|
74
72
|
|
|
75
|
-
get componentClass() {
|
|
76
|
-
return ParticleEmitter;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
73
|
async startup(entityManager, readyCallback, errorCallback) {
|
|
80
74
|
const am = this.assetManager;
|
|
81
75
|
|
|
@@ -95,7 +89,32 @@ export class ParticleEmitterSystem extends System {
|
|
|
95
89
|
|
|
96
90
|
renderLayer.renderPass = RenderPassType.Transparent;
|
|
97
91
|
|
|
98
|
-
renderLayer.
|
|
92
|
+
renderLayer.buildVisibleSet = (destination, destination_offset, view) => {
|
|
93
|
+
|
|
94
|
+
const ecd = entityManager.dataset;
|
|
95
|
+
|
|
96
|
+
if (ecd === null) {
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
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
|
+
};
|
|
117
|
+
|
|
99
118
|
renderLayer.visibleSet.onAdded.add((points) => {
|
|
100
119
|
/**
|
|
101
120
|
*
|
|
@@ -121,9 +140,6 @@ export class ParticleEmitterSystem extends System {
|
|
|
121
140
|
// console.log('Removed', emitter, renderLayer.visibleSet.version);
|
|
122
141
|
});
|
|
123
142
|
|
|
124
|
-
this.bvh = renderLayer.bvh;
|
|
125
|
-
this.bvh.insertNode(this.particleEngine.bvh);
|
|
126
|
-
|
|
127
143
|
|
|
128
144
|
const depthBuffer = graphicsEngine.frameBuffers.getById(StandardFrameBuffers.ColorAndDepth);
|
|
129
145
|
|
|
@@ -236,6 +252,8 @@ export class ParticleEmitterSystem extends System {
|
|
|
236
252
|
//initialize emitter as suspended to prevent needless updates
|
|
237
253
|
emitter.setFlag(ParticleEmitterFlag.Sleeping);
|
|
238
254
|
|
|
255
|
+
emitter.id = entity;
|
|
256
|
+
|
|
239
257
|
// emitter.bvhLeaf.entity = entity; //this line makes emitter selectable via bounding box in editor
|
|
240
258
|
|
|
241
259
|
this.particleEngine.add(emitter);
|
|
@@ -1,267 +1,247 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
ExplicitBinaryBoundingVolumeHierarchy
|
|
3
|
+
} from "../../../../../core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js";
|
|
3
4
|
import List from "../../../../../core/collection/list/List.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
* @param {AssetManager} assetManager
|
|
14
|
-
* @param {MaterialManager} material_manager
|
|
15
|
-
* @constructor
|
|
16
|
-
*/
|
|
17
|
-
function ParticularEngine(assetManager, material_manager) {
|
|
18
|
-
this.shaderManager = new ShaderManager(assetManager, material_manager);
|
|
5
|
+
import {ParticleEmitterFlag} from "./emitter/ParticleEmitterFlag.js";
|
|
6
|
+
import {ShaderManager} from "./shader/ShaderManager.js";
|
|
7
|
+
import {SimulationStepApplyForce} from "./simulator/SimulationStepApplyForce.js";
|
|
8
|
+
import {SimulationStepCurlNoiseAcceleration} from "./simulator/SimulationStepCurlNoiseAcceleration.js";
|
|
9
|
+
import {SimulationStepCurlNoiseVelocity} from "./simulator/SimulationStepCurlNoiseVelocity.js";
|
|
10
|
+
import {SimulationStepFixedPhysics} from "./simulator/SimulationStepFixedPhysics.js";
|
|
19
11
|
|
|
12
|
+
|
|
13
|
+
export class ParticularEngine {
|
|
20
14
|
/**
|
|
21
15
|
*
|
|
22
16
|
* @type {THREE.Camera|null}
|
|
23
17
|
*/
|
|
24
|
-
|
|
18
|
+
camera = null;
|
|
25
19
|
|
|
26
20
|
/**
|
|
27
21
|
* Managed emitters
|
|
28
22
|
* @type {List.<ParticleEmitter>}
|
|
29
23
|
*/
|
|
30
|
-
|
|
24
|
+
emitters = new List();
|
|
31
25
|
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
/**
|
|
27
|
+
* @readonly
|
|
28
|
+
* @type {ExplicitBinaryBoundingVolumeHierarchy}
|
|
29
|
+
*/
|
|
30
|
+
bvh = new ExplicitBinaryBoundingVolumeHierarchy();
|
|
34
31
|
|
|
35
32
|
|
|
36
33
|
/**
|
|
37
34
|
*
|
|
38
35
|
* @type {AbstractSimulationStep[]}
|
|
39
36
|
*/
|
|
40
|
-
|
|
37
|
+
steps = [
|
|
41
38
|
new SimulationStepFixedPhysics(),
|
|
42
39
|
new SimulationStepCurlNoiseAcceleration(),
|
|
43
40
|
new SimulationStepCurlNoiseVelocity(),
|
|
44
41
|
new SimulationStepApplyForce()
|
|
45
42
|
];
|
|
46
|
-
}
|
|
47
43
|
|
|
48
|
-
/**
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
44
|
+
/**
|
|
45
|
+
*
|
|
46
|
+
* @param {AssetManager} assetManager
|
|
47
|
+
* @param {MaterialManager} material_manager
|
|
48
|
+
* @constructor
|
|
49
|
+
*/
|
|
50
|
+
constructor(assetManager, material_manager) {
|
|
51
|
+
this.shaderManager = new ShaderManager(assetManager, material_manager);
|
|
55
52
|
}
|
|
56
53
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
* @param {ParticleEmitter} emitter
|
|
57
|
+
*/
|
|
58
|
+
add(emitter) {
|
|
59
|
+
if (!emitter.getFlag(ParticleEmitterFlag.Built)) {
|
|
60
|
+
emitter.build();
|
|
61
|
+
}
|
|
63
62
|
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
//mark sprites for update as their UVs might have changed since last usage
|
|
64
|
+
emitter.setFlag(ParticleEmitterFlag.SpritesNeedUpdate);
|
|
66
65
|
|
|
67
|
-
|
|
68
|
-
*
|
|
69
|
-
* @param {ParticleEmitter} emitter
|
|
70
|
-
*/
|
|
71
|
-
ParticularEngine.prototype.remove = function (emitter) {
|
|
72
|
-
const emitters = this.emitters;
|
|
66
|
+
this.emitters.add(emitter);
|
|
73
67
|
|
|
74
|
-
|
|
68
|
+
this.shaderManager.register(emitter);
|
|
75
69
|
|
|
76
|
-
|
|
77
|
-
emitters.remove(i);
|
|
70
|
+
emitter.bvh_leaf.link(this.bvh, emitter.id);
|
|
78
71
|
}
|
|
79
72
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
73
|
+
/**
|
|
74
|
+
*
|
|
75
|
+
* @param {ParticleEmitter} emitter
|
|
76
|
+
* @returns {boolean}
|
|
77
|
+
*/
|
|
78
|
+
remove(emitter) {
|
|
84
79
|
|
|
85
|
-
|
|
86
|
-
*
|
|
87
|
-
* @param {THREE.Camera} camera
|
|
88
|
-
*/
|
|
89
|
-
ParticularEngine.prototype.setCamera = function (camera) {
|
|
90
|
-
this.camera = camera;
|
|
91
|
-
this.shaderManager.setCamera(camera);
|
|
92
|
-
};
|
|
80
|
+
const removed = this.emitters.removeOneOf(emitter);
|
|
93
81
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
82
|
+
if (!removed) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
97
85
|
|
|
98
|
-
|
|
99
|
-
this.shaderManager.setViewportSize(x, y);
|
|
100
|
-
};
|
|
86
|
+
this.shaderManager.deregister(emitter);
|
|
101
87
|
|
|
102
|
-
|
|
103
|
-
* @private
|
|
104
|
-
* @param {ParticleEmitter} emitter
|
|
105
|
-
* @param {number} timeDelta
|
|
106
|
-
*/
|
|
107
|
-
ParticularEngine.prototype.advanceEmitter = function (emitter, timeDelta) {
|
|
108
|
-
let i, j;
|
|
88
|
+
emitter.bvh_leaf.unlink();
|
|
109
89
|
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
110
92
|
|
|
111
93
|
/**
|
|
112
94
|
*
|
|
113
|
-
* @
|
|
95
|
+
* @param {THREE.Camera} camera
|
|
114
96
|
*/
|
|
115
|
-
|
|
97
|
+
setCamera(camera) {
|
|
98
|
+
this.camera = camera;
|
|
99
|
+
this.shaderManager.setCamera(camera);
|
|
100
|
+
}
|
|
116
101
|
|
|
117
|
-
|
|
102
|
+
setDepthTexture(texture) {
|
|
103
|
+
this.shaderManager.setDepthTexture(texture);
|
|
104
|
+
}
|
|
118
105
|
|
|
119
|
-
|
|
106
|
+
setViewportSize(x, y) {
|
|
107
|
+
this.shaderManager.setViewportSize(x, y);
|
|
108
|
+
}
|
|
120
109
|
|
|
121
|
-
|
|
110
|
+
/**
|
|
111
|
+
* @private
|
|
112
|
+
* @param {ParticleEmitter} emitter
|
|
113
|
+
* @param {number} timeDelta
|
|
114
|
+
*/
|
|
115
|
+
advanceEmitter(emitter, timeDelta) {
|
|
116
|
+
let i, j;
|
|
122
117
|
|
|
123
|
-
for (j = 0; j < layer_count; j++) {
|
|
124
|
-
const particleLayer = layers.get(j);
|
|
125
118
|
|
|
126
|
-
|
|
119
|
+
/**
|
|
120
|
+
*
|
|
121
|
+
* @type {List<ParticleLayer>}
|
|
122
|
+
*/
|
|
123
|
+
const layers = emitter.layers;
|
|
127
124
|
|
|
128
|
-
const
|
|
125
|
+
const layer_count = layers.length;
|
|
129
126
|
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
*
|
|
133
|
-
* @type {SimulationStepDefinition}
|
|
134
|
-
*/
|
|
135
|
-
const stepDefinition = simulationStepDefinitions.get(i);
|
|
127
|
+
let step_mask = 0;
|
|
136
128
|
|
|
137
|
-
|
|
129
|
+
const steps = this.steps;
|
|
138
130
|
|
|
139
|
-
|
|
131
|
+
for (j = 0; j < layer_count; j++) {
|
|
132
|
+
const particleLayer = layers.get(j);
|
|
140
133
|
|
|
141
|
-
const
|
|
134
|
+
const simulationStepDefinitions = particleLayer.steps;
|
|
142
135
|
|
|
143
|
-
|
|
144
|
-
// no step definition
|
|
145
|
-
continue;
|
|
146
|
-
}
|
|
136
|
+
const n = simulationStepDefinitions.length;
|
|
147
137
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
138
|
+
for (i = 0; i < n; i++) {
|
|
139
|
+
/**
|
|
140
|
+
*
|
|
141
|
+
* @type {SimulationStepDefinition}
|
|
142
|
+
*/
|
|
143
|
+
const stepDefinition = simulationStepDefinitions.get(i);
|
|
153
144
|
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// apply simulation steps
|
|
158
|
-
const step_index_limit = steps.length;
|
|
145
|
+
const type = stepDefinition.type;
|
|
159
146
|
|
|
160
|
-
|
|
161
|
-
const m = 1 << i;
|
|
162
|
-
const is_used = (step_mask & m) !== 0;
|
|
147
|
+
step_mask |= 1 << type;
|
|
163
148
|
|
|
164
|
-
|
|
165
|
-
const step = steps[i];
|
|
149
|
+
const step = steps[type];
|
|
166
150
|
|
|
167
|
-
|
|
151
|
+
if (step === undefined) {
|
|
152
|
+
// no step definition
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
168
155
|
|
|
169
|
-
|
|
156
|
+
step.emitter = emitter;
|
|
157
|
+
step.timeDelta = timeDelta;
|
|
158
|
+
step.particles = emitter.particles;
|
|
159
|
+
step.layer_parameters[j] = stepDefinition.parameters;
|
|
160
|
+
step.includeLayer(j);
|
|
170
161
|
|
|
171
|
-
|
|
162
|
+
}
|
|
172
163
|
}
|
|
173
|
-
}
|
|
174
164
|
|
|
175
|
-
|
|
165
|
+
// apply simulation steps
|
|
166
|
+
const step_index_limit = steps.length;
|
|
176
167
|
|
|
177
|
-
|
|
168
|
+
for (i = 0; i < step_index_limit; i++) {
|
|
169
|
+
const m = 1 << i;
|
|
170
|
+
const is_used = (step_mask & m) !== 0;
|
|
178
171
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
* @param {ParticleEmitter} emitter
|
|
182
|
-
* @param {number} timeDelta
|
|
183
|
-
*/
|
|
184
|
-
ParticularEngine.prototype.updateEmitter = function (emitter, timeDelta) {
|
|
185
|
-
if (emitter.getFlag(ParticleEmitterFlag.Sleeping)) {
|
|
186
|
-
emitter.sleepTime += timeDelta;
|
|
187
|
-
} else {
|
|
172
|
+
if (is_used) {
|
|
173
|
+
const step = steps[i];
|
|
188
174
|
|
|
189
|
-
|
|
190
|
-
emitter.initialize();
|
|
191
|
-
}
|
|
175
|
+
step.layer_count = layer_count;
|
|
192
176
|
|
|
193
|
-
|
|
194
|
-
//emitter was sleeping, need to catch up the simulation
|
|
195
|
-
const maxParticleLife = emitter.computeMaxEmittingParticleLife();
|
|
177
|
+
step.execute();
|
|
196
178
|
|
|
197
|
-
|
|
179
|
+
step.clear();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
198
182
|
|
|
199
|
-
|
|
183
|
+
emitter.advance(timeDelta);
|
|
200
184
|
|
|
201
|
-
|
|
185
|
+
}
|
|
202
186
|
|
|
203
|
-
|
|
187
|
+
/**
|
|
188
|
+
* @private
|
|
189
|
+
* @param {ParticleEmitter} emitter
|
|
190
|
+
* @param {number} timeDelta
|
|
191
|
+
*/
|
|
192
|
+
updateEmitter(emitter, timeDelta) {
|
|
193
|
+
if (emitter.getFlag(ParticleEmitterFlag.Sleeping)) {
|
|
194
|
+
emitter.sleepTime += timeDelta;
|
|
195
|
+
} else {
|
|
204
196
|
|
|
205
|
-
|
|
206
|
-
|
|
197
|
+
if (!emitter.getFlag(ParticleEmitterFlag.Initialized)) {
|
|
198
|
+
emitter.initialize();
|
|
199
|
+
}
|
|
207
200
|
|
|
208
|
-
|
|
201
|
+
if (emitter.sleepTime > 0) {
|
|
202
|
+
//emitter was sleeping, need to catch up the simulation
|
|
203
|
+
const maxParticleLife = emitter.computeMaxEmittingParticleLife();
|
|
209
204
|
|
|
210
|
-
wakingTime
|
|
211
|
-
}
|
|
205
|
+
let wakingTime = Math.min(emitter.sleepTime, maxParticleLife - timeDelta);
|
|
212
206
|
|
|
213
|
-
|
|
214
|
-
emitter.sleepTime = 0;
|
|
215
|
-
}
|
|
216
|
-
//advance simulation
|
|
217
|
-
this.advanceEmitter(emitter, timeDelta);
|
|
207
|
+
const minWakingIncrement = 0.15;
|
|
218
208
|
|
|
219
|
-
|
|
220
|
-
emitter.computeBoundingBox();
|
|
221
|
-
}
|
|
222
|
-
};
|
|
209
|
+
const maxWakingSteps = 10;
|
|
223
210
|
|
|
224
|
-
|
|
225
|
-
const emitters = this.emitters;
|
|
211
|
+
const wakingIncrement = Math.max(wakingTime / maxWakingSteps, minWakingIncrement);
|
|
226
212
|
|
|
227
|
-
|
|
213
|
+
while (wakingTime > 0) {
|
|
214
|
+
const wakingStep = Math.min(wakingIncrement, wakingTime);
|
|
228
215
|
|
|
229
|
-
|
|
230
|
-
const emitter = emitters.get(i);
|
|
231
|
-
if (!emitter.getFlag(ParticleEmitterFlag.Sleeping)) {
|
|
216
|
+
this.advanceEmitter(emitter, wakingStep);
|
|
232
217
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
};
|
|
218
|
+
wakingTime -= wakingStep;
|
|
219
|
+
}
|
|
237
220
|
|
|
238
|
-
|
|
239
|
-
|
|
221
|
+
//consume the sleep time
|
|
222
|
+
emitter.sleepTime = 0;
|
|
223
|
+
}
|
|
240
224
|
|
|
241
|
-
|
|
225
|
+
//advance simulation
|
|
226
|
+
this.advanceEmitter(emitter, timeDelta);
|
|
242
227
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
if (!emitter.getFlag(ParticleEmitterFlag.Sleeping) && emitter.getFlag(ParticleEmitterFlag.DepthSorting)) {
|
|
246
|
-
//sort particles by position from camera
|
|
247
|
-
emitter.sort(this.camera);
|
|
228
|
+
//update bounding box
|
|
229
|
+
emitter.computeBoundingBox();
|
|
248
230
|
}
|
|
249
231
|
}
|
|
250
|
-
};
|
|
251
232
|
|
|
252
|
-
/**
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
233
|
+
/**
|
|
234
|
+
*
|
|
235
|
+
* @param {number} timeDelta
|
|
236
|
+
*/
|
|
237
|
+
advance(timeDelta) {
|
|
238
|
+
const emitters = this.emitters;
|
|
258
239
|
|
|
259
|
-
|
|
240
|
+
const numEmitters = emitters.length;
|
|
260
241
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
242
|
+
for (let i = 0; i < numEmitters; i++) {
|
|
243
|
+
const emitter = emitters.get(i);
|
|
244
|
+
this.updateEmitter(emitter, timeDelta);
|
|
245
|
+
}
|
|
264
246
|
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
export { ParticularEngine };
|
|
247
|
+
}
|
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {Box3, BufferGeometry, Frustum, Points, PointsMaterial} from 'three';
|
|
2
|
+
import {assert} from "../../../../../../core/assert.js";
|
|
3
|
+
import {EBBVHLeafProxy} from "../../../../../../core/bvh2/bvh3/EBBVHLeafProxy.js";
|
|
4
|
+
import {computeHashIntegerArray} from "../../../../../../core/collection/array/computeHashIntegerArray.js";
|
|
2
5
|
import List from "../../../../../../core/collection/list/List.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { Box3, BufferGeometry, Frustum, Points, PointsMaterial } from 'three';
|
|
7
|
-
import { ParticlePool } from "./ParticlePool.js";
|
|
8
|
-
import { ParticleParameter } from "../parameter/ParticleParameter.js";
|
|
9
|
-
import { ParameterSet } from "../parameter/ParameterSet.js";
|
|
10
|
-
import { assert } from "../../../../../../core/assert.js";
|
|
11
|
-
import { LeafNode } from "../../../../../../core/bvh2/LeafNode.js";
|
|
12
|
-
import { ParticleLayer } from "./ParticleLayer.js";
|
|
13
|
-
import { ParticleParameters } from "./ParticleParameters.js";
|
|
14
|
-
import { BlendingType } from "../../../../texture/sampler/BlendingType.js";
|
|
6
|
+
import {AABB3} from "../../../../../../core/geom/3d/aabb/AABB3.js";
|
|
7
|
+
import {aabb3_array_combine} from "../../../../../../core/geom/3d/aabb/aabb3_array_combine.js";
|
|
8
|
+
import {compose_matrix4_array} from "../../../../../../core/geom/3d/compose_matrix4_array.js";
|
|
15
9
|
import Quaternion from "../../../../../../core/geom/Quaternion.js";
|
|
16
|
-
import {
|
|
17
|
-
import
|
|
10
|
+
import {v3_dot_array_array} from "../../../../../../core/geom/vec3/v3_dot_array_array.js";
|
|
11
|
+
import Vector3 from "../../../../../../core/geom/Vector3.js";
|
|
12
|
+
import {lerp} from "../../../../../../core/math/lerp.js";
|
|
13
|
+
import {max2} from "../../../../../../core/math/max2.js";
|
|
14
|
+
import {min2} from "../../../../../../core/math/min2.js";
|
|
15
|
+
import {frustum_from_camera} from "../../../../ecs/camera/frustum_from_camera.js";
|
|
16
|
+
import {BlendingType} from "../../../../texture/sampler/BlendingType.js";
|
|
17
|
+
import {ParameterSet} from "../parameter/ParameterSet.js";
|
|
18
|
+
import {ParticleParameter} from "../parameter/ParticleParameter.js";
|
|
19
|
+
import {update_parameters} from "../simulator/update_parameters.js";
|
|
20
|
+
import {computeEmissionFunction} from "./computeEmissionFunction.js";
|
|
18
21
|
import {
|
|
19
22
|
PARTICLE_ATTRIBUTE_AGE,
|
|
20
23
|
PARTICLE_ATTRIBUTE_BLEND,
|
|
@@ -28,13 +31,11 @@ import {
|
|
|
28
31
|
PARTICLE_ATTRIBUTE_UV,
|
|
29
32
|
PARTICLE_ATTRIBUTE_VELOCITY
|
|
30
33
|
} from "./PARTICLE_ATTRIBUTES.js";
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
36
|
-
import { v3_dot_array_array } from "../../../../../../core/geom/vec3/v3_dot_array_array.js";
|
|
37
|
-
import { compose_matrix4_array } from "../../../../../../core/geom/3d/compose_matrix4_array.js";
|
|
34
|
+
import {ParticleEmitterFlag} from "./ParticleEmitterFlag.js";
|
|
35
|
+
import {ParticleLayer} from "./ParticleLayer.js";
|
|
36
|
+
import {ParticleParameters} from "./ParticleParameters.js";
|
|
37
|
+
import {ParticlePool} from "./ParticlePool.js";
|
|
38
|
+
import {PARTICULAR_PARTICLE_SPECIFICATION} from "./PARTICULAR_PARTICLE_SPECIFICATION.js";
|
|
38
39
|
|
|
39
40
|
const EMPTY_GEOMETRY = new BufferGeometry();
|
|
40
41
|
|
|
@@ -111,7 +112,13 @@ function write_particle_patch_uv(patch, particles, ref) {
|
|
|
111
112
|
);
|
|
112
113
|
}
|
|
113
114
|
|
|
115
|
+
let id_counter = 0;
|
|
116
|
+
|
|
114
117
|
export class ParticleEmitter {
|
|
118
|
+
/**
|
|
119
|
+
* @type {number}
|
|
120
|
+
*/
|
|
121
|
+
id = id_counter++;
|
|
115
122
|
|
|
116
123
|
/**
|
|
117
124
|
* @private
|
|
@@ -160,13 +167,14 @@ export class ParticleEmitter {
|
|
|
160
167
|
mesh = null;
|
|
161
168
|
|
|
162
169
|
/**
|
|
163
|
-
*
|
|
164
|
-
* @type {
|
|
170
|
+
* @readonly
|
|
171
|
+
* @type {EBBVHLeafProxy}
|
|
165
172
|
*/
|
|
166
|
-
|
|
173
|
+
bvh_leaf = new EBBVHLeafProxy();
|
|
174
|
+
|
|
167
175
|
|
|
168
176
|
/**
|
|
169
|
-
*
|
|
177
|
+
* Upper-bound of bounds for an individual particle
|
|
170
178
|
* @type {AABB3}
|
|
171
179
|
*/
|
|
172
180
|
particleBounds = new AABB3(Infinity, Infinity, Infinity, -Infinity, -Infinity, -Infinity);
|
|
@@ -542,21 +550,9 @@ export class ParticleEmitter {
|
|
|
542
550
|
const ebb = this.emissionBounds;
|
|
543
551
|
const pbb = this.particleBounds;
|
|
544
552
|
|
|
545
|
-
|
|
546
|
-
const bounds_y0 = min2(ebb.y0, pbb.y0);
|
|
547
|
-
const bounds_z0 = min2(ebb.z0, pbb.z0);
|
|
548
|
-
|
|
549
|
-
const bounds_x1 = max2(ebb.x1, pbb.x1);
|
|
550
|
-
const bounds_y1 = max2(ebb.y1, pbb.y1);
|
|
551
|
-
const bounds_z1 = max2(ebb.z1, pbb.z1);
|
|
553
|
+
aabb3_array_combine(this.bvh_leaf.bounds, ebb, pbb);
|
|
552
554
|
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
bvhLeaf.setBounds(bounds_x0, bounds_y0, bounds_z0, bounds_x1, bounds_y1, bounds_z1);
|
|
556
|
-
|
|
557
|
-
if (bvhLeaf.parentNode !== null) {
|
|
558
|
-
bvhLeaf.parentNode.bubbleRefit();
|
|
559
|
-
}
|
|
555
|
+
this.bvh_leaf.write_bounds();
|
|
560
556
|
|
|
561
557
|
}
|
|
562
558
|
|
|
@@ -1221,7 +1217,7 @@ ParticleEmitter.SERIALIZABLE_FLAGS = SERIALIZABLE_FLAGS;
|
|
|
1221
1217
|
|
|
1222
1218
|
const matrix4 = new Float32Array(16);
|
|
1223
1219
|
|
|
1224
|
-
const defaultPointsMaterial = new PointsMaterial({
|
|
1220
|
+
const defaultPointsMaterial = new PointsMaterial({color: 0xFFFFFF});
|
|
1225
1221
|
|
|
1226
1222
|
const frustum = new Frustum();
|
|
1227
1223
|
|