@woosh/meep-engine 2.33.19 → 2.33.23
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/core/assert.js +3 -1
- package/core/bvh2/traversal/__detailed_box_volume_intersection.js +11 -8
- package/core/collection/HashMap.js +66 -22
- package/core/geom/3d/CircleMath.js +4 -4
- package/core/geom/3d/cone/computeConeBoundingBox.js +4 -4
- package/core/geom/3d/{compute_bounding_cone_of_2_cones.js → cone/compute_bounding_cone_of_2_cones.js} +3 -3
- package/core/geom/3d/{compute_bounding_cone_of_2_cones.spec.js → cone/compute_bounding_cone_of_2_cones.spec.js} +1 -1
- package/core/geom/3d/frustum/array_setFromProjectionMatrix.js +1 -1
- package/core/geom/3d/frustum/frustum3_computeNearestPointToPoint.js +10 -2
- package/core/geom/3d/{encode_unit3_hemioct.js → normal/hemioct/encode_unit3_hemioct.js} +0 -0
- package/core/geom/3d/{unit_hemioct.spec.js → normal/hemioct/unit_hemioct.spec.js} +1 -1
- package/core/geom/3d/normal/lamber_azimuth/transform.js +61 -0
- package/core/geom/3d/normal/spherical/sphere_map_transform.js +77 -0
- package/core/geom/3d/{lerp_planes_to_array.js → plane/lerp_planes_to_array.js} +1 -3
- package/core/geom/3d/plane/plane3_lerp.js +3 -1
- package/core/geom/3d/plane/plane3_slerp.js +4 -1
- package/core/geom/3d/{plane_computeConvex3PlaneIntersection.js → plane/plane_computeConvex3PlaneIntersection.js} +14 -16
- package/core/geom/3d/topology/TopoTriangle.js +1 -1
- package/core/geom/3d/topology/TopoVertex.js +1 -1
- package/core/geom/3d/topology/bounds/computeTraingleClusterNormalBoundingCone.js +2 -2
- package/core/geom/3d/topology/simplify/compute_face_normal_change_dot_product.js +1 -1
- package/core/geom/3d/topology/simplify/quadratic/Quadratic3.js +1 -1
- package/core/geom/3d/triangle/computeTrianglePlaneSide.js +1 -1
- package/core/geom/3d/triangle/computeTriangleRayIntersection.js +1 -1
- package/core/geom/3d/voxel/DenseBitVolume3D.js +87 -0
- package/core/geom/3d/voxel/buildVolumeFromProjectedGeometry.js +23 -0
- package/core/geom/LineSegment.js +3 -1
- package/core/geom/Matrix4.js +2 -1
- package/core/geom/Plane.js +15 -10
- package/core/geom/Quaternion.js +2 -1
- package/core/geom/Vector3.d.ts +2 -0
- package/core/geom/Vector3.js +33 -158
- package/core/geom/Vector3.spec.js +2 -1
- package/core/geom/v3_angle_between.js +31 -0
- package/core/geom/v3_distance.js +16 -0
- package/core/geom/v3_distance_sqr.js +17 -0
- package/core/geom/v3_dot.js +13 -0
- package/core/geom/v3_length.js +5 -0
- package/core/geom/v3_length_sqr.js +10 -0
- package/core/geom/v3_lerp.js +21 -0
- package/core/geom/v3_slerp.js +48 -0
- package/core/primitives/array/computeIntegerArrayHash.js +6 -1
- package/engine/asset/loaders/material/computeImageBitmapEquality.js +11 -0
- package/engine/asset/loaders/material/computeImageBitmapHash.js +22 -28
- package/engine/asset/loaders/material/computeMaterialHash.js +1 -2
- package/engine/asset/loaders/material/computeTextureEquality.js +13 -5
- package/engine/ecs/animation/OneBoneSurfaceAlignmentSolver.js +3 -1
- package/engine/ecs/animation/TwoBoneInverseKinematicsSolver.js +3 -1
- package/engine/ecs/fow/FogOfWar.js +2 -3
- package/engine/ecs/gui/hud/HeadsUpDisplaySystem.js +1 -1
- package/engine/ecs/systems/SteeringSystem.js +2 -1
- package/engine/ecs/terrain/ecs/Terrain.js +6 -0
- package/engine/ecs/terrain/ecs/layers/TerrainLayers.js +5 -0
- package/engine/ecs/terrain/ecs/splat/SplatMapping.js +5 -0
- package/engine/ecs/util/hideEntityGracefully.js +18 -0
- package/engine/graphics/GraphicsEngine.js +1 -0
- package/engine/graphics/camera/testClippingPlaneComputation.js +2 -2
- package/engine/graphics/ecs/camera/CameraClippingPlaneComputer.js +1 -1
- package/engine/graphics/ecs/highlight/renderer/OutlineRenderer.js +0 -53
- package/engine/graphics/ecs/path/testPathDisplaySystem.js +98 -98
- package/engine/graphics/ecs/trail2d/Trail2D.js +17 -4
- package/engine/graphics/ecs/trail2d/Trail2DSystem.d.ts +2 -3
- package/engine/graphics/ecs/trail2d/Trail2DSystem.js +34 -118
- package/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +2 -1
- package/engine/graphics/micron/build/clustering/computeFaceCurvatureScore.js +1 -1
- package/engine/graphics/micron/build/clustering/compute_face_connection_weight.js +1 -1
- package/engine/graphics/micron/build/hierarchy/computePatchMergeScore.js +1 -1
- package/engine/graphics/micron/build/hierarchy/patch_combine.js +1 -1
- package/engine/graphics/micron/render/refinement/is_patch_facing_back.js +2 -2
- package/engine/graphics/particles/particular/engine/ParticularEngine.js +4 -2
- package/engine/graphics/particles/particular/engine/emitter/PARTICULAR_PARTICLE_SPECIFICATION.js +20 -0
- package/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +40 -97
- package/engine/graphics/particles/particular/engine/emitter/ParticleLayer.js +12 -2
- package/engine/graphics/particles/particular/engine/emitter/computeEmissionFunction.js +37 -0
- package/engine/graphics/particles/particular/engine/emitter/distance_to_camera.js +25 -0
- package/engine/graphics/particles/particular/engine/shader/ShaderManager.js +7 -25
- package/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +2 -2
- package/engine/graphics/render/forward_plus/LightManager.js +10 -2
- package/engine/graphics/render/forward_plus/computeFrustumCorners.js +15 -33
- package/engine/graphics/render/forward_plus/plugin/MaterialTransformer.js +12 -2
- package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +1 -1
- package/engine/graphics/render/forward_plus/prototypeLightManager.js +96 -95
- package/engine/graphics/render/forward_plus/queryBVH_Frustum.js +18 -6
- package/engine/graphics/render/layers/RenderLayerUtils.js +8 -5
- package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +1 -1
- package/engine/graphics/texture/atlas/AtlasPatch.js +7 -2
- package/engine/graphics/texture/atlas/TextureAtlas.js +18 -14
- package/engine/graphics/texture/sampler/Sampler2D.js +8 -7
- package/engine/graphics/texture/sampler/scaleSampler2D.js +7 -10
- package/engine/graphics/trail/x/RibbonMaterialX.js +3 -3
- package/engine/graphics/trail/x/RibbonX.js +17 -2
- package/engine/graphics/trail/x/RibbonXPlugin.js +51 -1
- package/engine/graphics/util/projectSphere.js +1 -1
- package/engine/grid/components/GridObstacle.js +2 -9
- package/engine/navigation/ecs/components/Path.js +2 -1
- package/engine/network/convertPathToURL.js +2 -2
- package/engine/reference/v2/Reference.js +6 -0
- package/generation/filtering/numeric/complex/CellFilterAngleToNormal.js +3 -2
- package/generation/markers/GridCellActionPlaceMarker.js +13 -1
- package/generation/markers/MarkerNode.js +6 -0
- package/generation/theme/ThemeEngine.js +4 -1
- package/package.json +3 -3
- package/view/View.js +4 -2
- package/view/minimap/gl/MinimapMarkersGL.js +13 -1
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import Vector3 from "../../../../core/geom/Vector3.js";
|
|
7
7
|
import Vector4 from "../../../../core/geom/Vector4.js";
|
|
8
|
+
import { RibbonXMaterialSpec } from "../../trail/x/RibbonXMaterialSpec.js";
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* @readonly
|
|
@@ -24,8 +25,6 @@ class Trail2D {
|
|
|
24
25
|
*/
|
|
25
26
|
this.maxAge = 5;
|
|
26
27
|
|
|
27
|
-
this.textureURL = null;
|
|
28
|
-
|
|
29
28
|
/**
|
|
30
29
|
* Trail width
|
|
31
30
|
* @type {number}
|
|
@@ -65,9 +64,9 @@ class Trail2D {
|
|
|
65
64
|
|
|
66
65
|
/**
|
|
67
66
|
* transient
|
|
68
|
-
* @type {
|
|
67
|
+
* @type {RibbonXMaterialSpec}
|
|
69
68
|
*/
|
|
70
|
-
this.material =
|
|
69
|
+
this.material = new RibbonXMaterialSpec();
|
|
71
70
|
|
|
72
71
|
/**
|
|
73
72
|
* transient
|
|
@@ -82,6 +81,20 @@ class Trail2D {
|
|
|
82
81
|
this.flags = Trail2DFlags.Spawning | Trail2DFlags.Aging;
|
|
83
82
|
}
|
|
84
83
|
|
|
84
|
+
dispose() {
|
|
85
|
+
if (this.ribbon !== null) {
|
|
86
|
+
this.ribbon.dispose();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
get textureURL() {
|
|
91
|
+
return this.material.diffuse;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
set textureURL(v) {
|
|
95
|
+
this.material.diffuse = v;
|
|
96
|
+
}
|
|
97
|
+
|
|
85
98
|
/**
|
|
86
99
|
*
|
|
87
100
|
* @param {number|Trail2DFlags} flag
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {System} from "../../../ecs/System";
|
|
2
|
-
import
|
|
3
|
-
import {AssetManager} from "../../../asset/AssetManager";
|
|
2
|
+
import Engine from "../../../Engine";
|
|
4
3
|
|
|
5
4
|
export default class Trail2DSystem extends System {
|
|
6
|
-
constructor(
|
|
5
|
+
constructor(engine: Engine)
|
|
7
6
|
}
|
|
@@ -8,25 +8,21 @@ import { max2 } from "../../../../core/math/max2.js";
|
|
|
8
8
|
import { System } from '../../../ecs/System.js';
|
|
9
9
|
import { Transform } from '../../../ecs/transform/Transform.js';
|
|
10
10
|
import Vector3 from '../../../../core/geom/Vector3.js';
|
|
11
|
-
import { computeHashFloat, computeHashIntegerArray } from '../../../../core/math/MathUtils.js';
|
|
12
11
|
|
|
13
12
|
import Trail2D, { Trail2DFlags } from './Trail2D.js';
|
|
14
|
-
import { ClampToEdgeWrapping, DoubleSide, LinearFilter, TextureLoader } from 'three';
|
|
15
13
|
|
|
16
14
|
import { LeafNode } from '../../../../core/bvh2/LeafNode.js';
|
|
17
15
|
import ThreeFactory from '../../three/ThreeFactory.js';
|
|
18
16
|
import { GraphicsEngine } from "../../GraphicsEngine.js";
|
|
19
|
-
import { ReferenceManager } from "../../../reference/v1/ReferenceManager.js";
|
|
20
|
-
import { AssetManager } from "../../../asset/AssetManager.js";
|
|
21
|
-
import { Cache } from "../../../../core/cache/Cache.js";
|
|
22
17
|
import { RibbonXFixedPhysicsSimulator } from "../../trail/x/simulator/RibbonXFixedPhysicsSimulator.js";
|
|
23
18
|
import { RibbonX } from "../../trail/x/RibbonX.js";
|
|
24
19
|
import {
|
|
25
20
|
RIBBON_ATTRIBUTE_ADDRESS_AGE,
|
|
26
21
|
RIBBON_ATTRIBUTE_ADDRESS_UV_OFFSET
|
|
27
22
|
} from "../../trail/x/ribbon_attributes_spec.js";
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
23
|
+
import { Reference } from "../../../reference/v2/Reference.js";
|
|
24
|
+
import { RibbonXPlugin } from "../../trail/x/RibbonXPlugin.js";
|
|
25
|
+
import { assert } from "../../../../core/assert.js";
|
|
30
26
|
|
|
31
27
|
const v3Temp1 = new Vector3();
|
|
32
28
|
|
|
@@ -34,69 +30,32 @@ const v3_array = [];
|
|
|
34
30
|
|
|
35
31
|
class Trail2DSystem extends System {
|
|
36
32
|
/**
|
|
37
|
-
*
|
|
38
|
-
* @param {GraphicsEngine} graphics
|
|
39
|
-
* @param {AssetManager} assetManager
|
|
33
|
+
* @param {Engine} engine
|
|
40
34
|
* @constructor
|
|
41
35
|
*/
|
|
42
|
-
constructor(
|
|
36
|
+
constructor(engine) {
|
|
43
37
|
super();
|
|
44
38
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
throw new Error("'renderer' must be of type GraphicsEngine");
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (!(assetManager instanceof AssetManager)) {
|
|
52
|
-
throw new Error("'assetManager' must be of type AssetManager");
|
|
53
|
-
}
|
|
39
|
+
assert.defined(engine, 'engine');
|
|
40
|
+
assert.notNull(engine, 'engine');
|
|
41
|
+
assert.equal(engine.isEngine, true, 'engine.isEngine !== true');
|
|
54
42
|
|
|
55
|
-
|
|
56
|
-
*
|
|
57
|
-
* @type {GraphicsEngine}
|
|
58
|
-
*/
|
|
59
|
-
this.graphics = graphics;
|
|
43
|
+
this.dependencies = [Trail2D, Transform];
|
|
60
44
|
|
|
61
45
|
/**
|
|
62
46
|
*
|
|
63
|
-
* @type {
|
|
47
|
+
* @type {Engine}
|
|
48
|
+
* @private
|
|
64
49
|
*/
|
|
65
|
-
this.
|
|
66
|
-
|
|
67
|
-
function constructTexture(url) {
|
|
68
|
-
const assetPromise = assetManager.promise(url, "texture");
|
|
69
|
-
|
|
70
|
-
const texturePromise = assetPromise
|
|
71
|
-
.then(function (asset) {
|
|
72
|
-
|
|
73
|
-
const texture = asset.create();
|
|
74
|
-
|
|
75
|
-
texture.wrapS = ClampToEdgeWrapping;
|
|
76
|
-
texture.wrapT = ClampToEdgeWrapping;
|
|
77
|
-
|
|
78
|
-
texture.magFilter = LinearFilter;
|
|
79
|
-
texture.minFilter = LinearFilter;
|
|
50
|
+
this.__engine = engine;
|
|
80
51
|
|
|
81
|
-
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
return texturePromise;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function destructTexture(url, texturePromise) {
|
|
88
|
-
texturePromise.then(function (t) {
|
|
89
|
-
//release used resourced
|
|
90
|
-
t.dispose();
|
|
91
|
-
});
|
|
92
|
-
}
|
|
52
|
+
const graphics = engine.graphics;
|
|
93
53
|
|
|
94
54
|
/**
|
|
95
55
|
*
|
|
96
|
-
* @type {
|
|
56
|
+
* @type {GraphicsEngine}
|
|
97
57
|
*/
|
|
98
|
-
this.
|
|
99
|
-
|
|
58
|
+
this.graphics = graphics;
|
|
100
59
|
|
|
101
60
|
/**
|
|
102
61
|
*
|
|
@@ -117,28 +76,11 @@ class Trail2DSystem extends System {
|
|
|
117
76
|
this.simulator = new RibbonXFixedPhysicsSimulator();
|
|
118
77
|
|
|
119
78
|
/**
|
|
79
|
+
*
|
|
80
|
+
* @type {Reference<RibbonXPlugin>}
|
|
120
81
|
* @private
|
|
121
|
-
* @readonly
|
|
122
|
-
* @type {Cache<Trail2D, Material>}
|
|
123
82
|
*/
|
|
124
|
-
this.
|
|
125
|
-
maxWeight: 100,
|
|
126
|
-
keyHashFunction(trail) {
|
|
127
|
-
return computeHashIntegerArray(
|
|
128
|
-
computeStringHash(trail.textureURL),
|
|
129
|
-
computeHashFloat(trail.width),
|
|
130
|
-
computeHashFloat(trail.maxAge),
|
|
131
|
-
trail.color.hash()
|
|
132
|
-
);
|
|
133
|
-
},
|
|
134
|
-
keyEqualityFunction(a, b) {
|
|
135
|
-
return a.textureURL === b.textureURL
|
|
136
|
-
&& a.width === b.width
|
|
137
|
-
&& a.maxAge === b.maxAge
|
|
138
|
-
&& a.color.equals(b.color)
|
|
139
|
-
;
|
|
140
|
-
}
|
|
141
|
-
});
|
|
83
|
+
this.__ribbon_plugin = Reference.NULL;
|
|
142
84
|
|
|
143
85
|
|
|
144
86
|
/**
|
|
@@ -149,7 +91,7 @@ class Trail2DSystem extends System {
|
|
|
149
91
|
this.__timeDelta = 0;
|
|
150
92
|
}
|
|
151
93
|
|
|
152
|
-
startup(entityManager, readyCallback, errorCallback) {
|
|
94
|
+
async startup(entityManager, readyCallback, errorCallback) {
|
|
153
95
|
this.entityManager = entityManager;
|
|
154
96
|
|
|
155
97
|
this.renderLayer = this.graphics.layers.create('trail-2d-system');
|
|
@@ -161,19 +103,7 @@ class Trail2DSystem extends System {
|
|
|
161
103
|
|
|
162
104
|
this.bvh = this.renderLayer.bvh;
|
|
163
105
|
|
|
164
|
-
|
|
165
|
-
this.graphics.viewport.size.onChanged.add((x, y) => {
|
|
166
|
-
const ecd = this.entityManager.dataset;
|
|
167
|
-
|
|
168
|
-
if (ecd === null) {
|
|
169
|
-
// no dataset attached
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
ecd.traverseComponents(Trail2D, trail => {
|
|
174
|
-
trail.material.uniforms.resolution.value.set(x, y);
|
|
175
|
-
});
|
|
176
|
-
});
|
|
106
|
+
this.__ribbon_plugin = await this.__engine.plugins.acquire(RibbonXPlugin);
|
|
177
107
|
|
|
178
108
|
readyCallback();
|
|
179
109
|
}
|
|
@@ -181,32 +111,9 @@ class Trail2DSystem extends System {
|
|
|
181
111
|
shutdown(entityManager, readyCallback, errorCallback) {
|
|
182
112
|
this.graphics.layers.remove(this.renderLayer);
|
|
183
113
|
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
*
|
|
189
|
-
* @param {Trail2D} trail
|
|
190
|
-
* @returns {Material}
|
|
191
|
-
*/
|
|
192
|
-
obtainMaterial(trail) {
|
|
193
|
-
|
|
194
|
-
const material = new RibbonMaterialX({
|
|
195
|
-
transparent: true,
|
|
196
|
-
depthWrite: false,
|
|
197
|
-
wireframe: false,
|
|
198
|
-
side: DoubleSide,
|
|
199
|
-
defines: {
|
|
200
|
-
USE_TEXTURE: false
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
if (trail.textureURL !== null) {
|
|
205
|
-
material.uniforms.uDiffuse.value = new TextureLoader().load(trail.textureURL);
|
|
206
|
-
material.defines.USE_TEXTURE = true;
|
|
207
|
-
}
|
|
114
|
+
this.__ribbon_plugin.release();
|
|
208
115
|
|
|
209
|
-
|
|
116
|
+
readyCallback();
|
|
210
117
|
}
|
|
211
118
|
|
|
212
119
|
/**
|
|
@@ -231,9 +138,9 @@ class Trail2DSystem extends System {
|
|
|
231
138
|
|
|
232
139
|
const geometry = ribbon.getGeometry();
|
|
233
140
|
|
|
234
|
-
const
|
|
141
|
+
const ribbons = this.__ribbon_plugin.getValue();
|
|
235
142
|
|
|
236
|
-
material.
|
|
143
|
+
const material = ribbons.obtain_material_x(trail.material);
|
|
237
144
|
|
|
238
145
|
const mesh = ThreeFactory.createMesh(geometry, material);
|
|
239
146
|
|
|
@@ -274,12 +181,21 @@ class Trail2DSystem extends System {
|
|
|
274
181
|
);
|
|
275
182
|
|
|
276
183
|
trail.bvhLeaf = leafNode;
|
|
277
|
-
trail.material = material;
|
|
278
184
|
|
|
279
185
|
this.bvh.insertNode(leafNode);
|
|
280
186
|
}
|
|
281
187
|
|
|
188
|
+
/**
|
|
189
|
+
*
|
|
190
|
+
* @param {Trail2D} component
|
|
191
|
+
* @param {Transform} transform
|
|
192
|
+
* @param {number} entity
|
|
193
|
+
*/
|
|
282
194
|
unlink(component, transform, entity) {
|
|
195
|
+
|
|
196
|
+
// release resources
|
|
197
|
+
component.dispose();
|
|
198
|
+
|
|
283
199
|
component.bvhLeaf.disconnect();
|
|
284
200
|
}
|
|
285
201
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import Vector3
|
|
1
|
+
import Vector3 from "../../../../../core/geom/Vector3.js";
|
|
2
2
|
|
|
3
3
|
import { Vector3 as ThreeVector3 } from 'three';
|
|
4
4
|
import { rayTriangleIntersection } from "../../../../../core/geom/GeometryMath.js";
|
|
5
5
|
import { SurfacePoint3 } from "../../../../../core/geom/3d/SurfacePoint3.js";
|
|
6
6
|
import { assert } from "../../../../../core/assert.js";
|
|
7
|
+
import { v3_length } from "../../../../../core/geom/v3_length.js";
|
|
7
8
|
|
|
8
9
|
const hit = new ThreeVector3();
|
|
9
10
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ConicRay } from "../../../../../core/geom/ConicRay.js";
|
|
2
|
-
import { compute_bounding_cone_of_2_cones } from "../../../../../core/geom/3d/compute_bounding_cone_of_2_cones.js";
|
|
2
|
+
import { compute_bounding_cone_of_2_cones } from "../../../../../core/geom/3d/cone/compute_bounding_cone_of_2_cones.js";
|
|
3
3
|
import { compute_patches_shared_vertex_count } from "./compute_patches_shared_vertex_count.js";
|
|
4
4
|
import { compute_bounding_sphere_of_2_spheres } from "../../../../../core/geom/3d/compute_bounding_sphere_of_2_spheres.js";
|
|
5
5
|
import { max2 } from "../../../../../core/math/max2.js";
|
|
@@ -5,7 +5,7 @@ import { array_remove_first } from "../../../../../core/collection/array/array_r
|
|
|
5
5
|
import { max2 } from "../../../../../core/math/max2.js";
|
|
6
6
|
import { array_push_if_unique } from "../../../../../core/collection/array/array_push_if_unique.js";
|
|
7
7
|
import { compute_bounding_sphere_of_2_spheres } from "../../../../../core/geom/3d/compute_bounding_sphere_of_2_spheres.js";
|
|
8
|
-
import { compute_bounding_cone_of_2_cones } from "../../../../../core/geom/3d/compute_bounding_cone_of_2_cones.js";
|
|
8
|
+
import { compute_bounding_cone_of_2_cones } from "../../../../../core/geom/3d/cone/compute_bounding_cone_of_2_cones.js";
|
|
9
9
|
import { ConicRay } from "../../../../../core/geom/ConicRay.js";
|
|
10
10
|
import { passThrough } from "../../../../../core/function/Functions.js";
|
|
11
11
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PI_HALF } from "../../../../../core/math/MathUtils.js";
|
|
2
|
-
import {
|
|
2
|
+
import { v3_angle_between } from "../../../../../core/geom/v3_angle_between.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
*
|
|
@@ -28,7 +28,7 @@ function is_patch_facing_back(refinement_spec, patch) {
|
|
|
28
28
|
// compute view angle of the bounding sphere
|
|
29
29
|
const normal_cone_direction = normal_cone.direction;
|
|
30
30
|
|
|
31
|
-
const angle =
|
|
31
|
+
const angle = v3_angle_between(
|
|
32
32
|
view_direction_x, view_direction_y, view_direction_z,
|
|
33
33
|
normal_cone_direction.x, normal_cone_direction.y, normal_cone_direction.z
|
|
34
34
|
);
|
|
@@ -63,10 +63,12 @@ ParticularEngine.prototype.add = function (emitter) {
|
|
|
63
63
|
* @param {ParticleEmitter} emitter
|
|
64
64
|
*/
|
|
65
65
|
ParticularEngine.prototype.remove = function (emitter) {
|
|
66
|
-
const
|
|
66
|
+
const emitters = this.emitters;
|
|
67
|
+
|
|
68
|
+
const i = emitters.indexOf(emitter);
|
|
67
69
|
|
|
68
70
|
if (i !== -1) {
|
|
69
|
-
|
|
71
|
+
emitters.remove(i);
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
this.shaderManager.deregister(emitter);
|
package/engine/graphics/particles/particular/engine/emitter/PARTICULAR_PARTICLE_SPECIFICATION.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//build particle spec
|
|
2
|
+
import { ParticleSpecification } from "../../group/ParticleSpecification.js";
|
|
3
|
+
import { ParticleAttribute } from "../../group/ParticleAttribute.js";
|
|
4
|
+
import { ParticleAttributeType, ParticleDataType } from "../../group/ParticleGroup.js";
|
|
5
|
+
|
|
6
|
+
export const PARTICULAR_PARTICLE_SPECIFICATION = new ParticleSpecification();
|
|
7
|
+
|
|
8
|
+
PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('position', ParticleAttributeType.Vector3, ParticleDataType.Float32));
|
|
9
|
+
PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('age', ParticleAttributeType.Scalar, ParticleDataType.Float32));
|
|
10
|
+
PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('deathAge', ParticleAttributeType.Scalar, ParticleDataType.Float32));
|
|
11
|
+
PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('atlasPatch', ParticleAttributeType.Vector4, ParticleDataType.Float32));
|
|
12
|
+
PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('size', ParticleAttributeType.Scalar, ParticleDataType.Float32));
|
|
13
|
+
PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('layerPosition', ParticleAttributeType.Scalar, ParticleDataType.Float32));
|
|
14
|
+
PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('velocity', ParticleAttributeType.Vector3, ParticleDataType.Float32));
|
|
15
|
+
PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('rotation', ParticleAttributeType.Scalar, ParticleDataType.Float32));
|
|
16
|
+
PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('rotationSpeed', ParticleAttributeType.Scalar, ParticleDataType.Float32));
|
|
17
|
+
PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('color', ParticleAttributeType.Vector4, ParticleDataType.Float32));
|
|
18
|
+
PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('blending', ParticleAttributeType.Scalar, ParticleDataType.Uint8));
|
|
19
|
+
PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('size_initial', ParticleAttributeType.Scalar, ParticleDataType.Float32));
|
|
20
|
+
|
|
@@ -3,7 +3,6 @@ import List from "../../../../../../core/collection/list/List.js";
|
|
|
3
3
|
import { lerp } from "../../../../../../core/math/lerp.js";
|
|
4
4
|
import { max2 } from "../../../../../../core/math/max2.js";
|
|
5
5
|
import { min2 } from "../../../../../../core/math/min2.js";
|
|
6
|
-
import { ParticleAttributeType, ParticleDataType } from "../../group/ParticleGroup.js";
|
|
7
6
|
import { Box3, BufferGeometry, Frustum, Matrix4, Points, PointsMaterial } from 'three';
|
|
8
7
|
import { frustumFromCamera } from "../../../../ecs/camera/CameraSystem.js";
|
|
9
8
|
import { ParticlePool } from "./ParticlePool.js";
|
|
@@ -16,8 +15,6 @@ import { ParticleParameters } from "./ParticleParameters.js";
|
|
|
16
15
|
import { BlendingType } from "../../../../texture/sampler/BlendingType.js";
|
|
17
16
|
import Quaternion from "../../../../../../core/geom/Quaternion.js";
|
|
18
17
|
import { computeHashIntegerArray } from "../../../../../../core/math/MathUtils.js";
|
|
19
|
-
import { ParticleSpecification } from "../../group/ParticleSpecification.js";
|
|
20
|
-
import { ParticleAttribute } from "../../group/ParticleAttribute.js";
|
|
21
18
|
import { ParticleEmitterFlag } from "./ParticleEmitterFlag.js";
|
|
22
19
|
import { AABB3 } from "../../../../../../core/bvh2/aabb3/AABB3.js";
|
|
23
20
|
import {
|
|
@@ -34,14 +31,10 @@ import {
|
|
|
34
31
|
PARTICLE_ATTRIBUTE_VELOCITY
|
|
35
32
|
} from "./PARTICLE_ATTRIBUTES.js";
|
|
36
33
|
import { composeMatrix4 } from "../../../../util/composeMatrix4.js";
|
|
37
|
-
import { randomPointInPoint } from "../../../../../../core/geom/random/randomPointInPoint.js";
|
|
38
|
-
import { randomPointInSphere } from "../../../../../../core/geom/random/randomPointInSphere.js";
|
|
39
|
-
import { randomPointOnSphere } from "../../../../../../core/geom/random/randomPointOnSphere.js";
|
|
40
|
-
import { randomPointInBox } from "../../../../../../core/geom/random/randomPointInBox.js";
|
|
41
|
-
import { randomPointOnBox } from "../../../../../../core/geom/random/randomPointOnBox.js";
|
|
42
|
-
import { EmissionFromType } from "./EmissionFromType.js";
|
|
43
|
-
import { EmissionShapeType } from "./EmissionShapeType.js";
|
|
44
34
|
import { update_parameters } from "../simulator/update_parameters.js";
|
|
35
|
+
import { distance_to_camera } from "./distance_to_camera.js";
|
|
36
|
+
import { computeEmissionFunction } from "./computeEmissionFunction.js";
|
|
37
|
+
import { PARTICULAR_PARTICLE_SPECIFICATION } from "./PARTICULAR_PARTICLE_SPECIFICATION.js";
|
|
45
38
|
|
|
46
39
|
const EMPTY_GEOMETRY = new BufferGeometry();
|
|
47
40
|
|
|
@@ -66,60 +59,6 @@ const corners = new Float64Array(24);
|
|
|
66
59
|
*/
|
|
67
60
|
const scratch_array = [];
|
|
68
61
|
|
|
69
|
-
/**
|
|
70
|
-
*
|
|
71
|
-
* @param {EmissionFromType} emissionType
|
|
72
|
-
* @param {EmissionShapeType} emissionShape
|
|
73
|
-
* @returns {function(random: function, result:Vector3):void}
|
|
74
|
-
*/
|
|
75
|
-
function computeEmissionFunction(emissionType, emissionShape) {
|
|
76
|
-
if (emissionShape === EmissionShapeType.Point) {
|
|
77
|
-
return randomPointInPoint;
|
|
78
|
-
} else if (emissionShape === EmissionShapeType.Sphere) {
|
|
79
|
-
if (emissionType === EmissionFromType.Volume) {
|
|
80
|
-
return randomPointInSphere;
|
|
81
|
-
} else if (emissionType === EmissionFromType.Shell) {
|
|
82
|
-
return randomPointOnSphere;
|
|
83
|
-
} else {
|
|
84
|
-
throw new TypeError(`Unsupported EmissionFrom Type`);
|
|
85
|
-
}
|
|
86
|
-
} else if (emissionShape === EmissionShapeType.Box) {
|
|
87
|
-
if (emissionType === EmissionFromType.Volume) {
|
|
88
|
-
return randomPointInBox;
|
|
89
|
-
} else if (emissionType === EmissionFromType.Shell) {
|
|
90
|
-
return randomPointOnBox;
|
|
91
|
-
} else {
|
|
92
|
-
throw new TypeError(`Unsupported EmissionFrom Type`);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
*
|
|
99
|
-
* @param {number} index
|
|
100
|
-
* @param {number[]|Float32Array} positionArray
|
|
101
|
-
* @param {Vector3} planeNormal
|
|
102
|
-
* @return {number}
|
|
103
|
-
*/
|
|
104
|
-
function distanceToCamera(index, positionArray, planeNormal) {
|
|
105
|
-
const address = index * 3;
|
|
106
|
-
|
|
107
|
-
// extract position components of the particle
|
|
108
|
-
const x = positionArray[address];
|
|
109
|
-
const y = positionArray[address + 1];
|
|
110
|
-
const z = positionArray[address + 2];
|
|
111
|
-
|
|
112
|
-
const planeNormalX = planeNormal.x;
|
|
113
|
-
const planeNormalY = planeNormal.y;
|
|
114
|
-
const planeNormalZ = planeNormal.z;
|
|
115
|
-
|
|
116
|
-
// compute dot product
|
|
117
|
-
const dot = x * planeNormalX + y * planeNormalY + z * planeNormalZ;
|
|
118
|
-
|
|
119
|
-
// use dot product instead of the actual distance to save computation. Difference is going to be constant
|
|
120
|
-
return dot;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
62
|
/**
|
|
124
63
|
*
|
|
125
64
|
* @param {ParameterSet} parameters
|
|
@@ -411,7 +350,12 @@ export class ParticleEmitter {
|
|
|
411
350
|
|
|
412
351
|
let removeCount = 0;
|
|
413
352
|
|
|
414
|
-
for (
|
|
353
|
+
for (
|
|
354
|
+
let i = occupancy.nextSetBit(0);
|
|
355
|
+
i !== -1;
|
|
356
|
+
i = occupancy.nextSetBit(i + 1)
|
|
357
|
+
) {
|
|
358
|
+
|
|
415
359
|
const layerPosition = particles.readAttributeScalar(i, PARTICLE_ATTRIBUTE_LAYER_POSITION);
|
|
416
360
|
|
|
417
361
|
const layerIndex = Math.round(layerPosition * numLayers);
|
|
@@ -425,6 +369,7 @@ export class ParticleEmitter {
|
|
|
425
369
|
occupancy.set(i, false);
|
|
426
370
|
|
|
427
371
|
removeCount++;
|
|
372
|
+
|
|
428
373
|
}
|
|
429
374
|
|
|
430
375
|
if (removeCount > 0) {
|
|
@@ -489,7 +434,10 @@ export class ParticleEmitter {
|
|
|
489
434
|
}
|
|
490
435
|
}
|
|
491
436
|
|
|
492
|
-
this.emisionBounds.setBounds(
|
|
437
|
+
this.emisionBounds.setBounds(
|
|
438
|
+
bounds_x0, bounds_y0, bounds_z0,
|
|
439
|
+
bounds_x1, bounds_y1, bounds_z1
|
|
440
|
+
);
|
|
493
441
|
|
|
494
442
|
this.clearFlag(ParticleEmitterFlag.BaseBoundsNeedUpdate);
|
|
495
443
|
}
|
|
@@ -708,8 +656,8 @@ export class ParticleEmitter {
|
|
|
708
656
|
}
|
|
709
657
|
|
|
710
658
|
computeHash() {
|
|
711
|
-
const
|
|
712
|
-
const
|
|
659
|
+
const parameters_hash = this.parameters.hash();
|
|
660
|
+
const layers_hash = this.layers.hash();
|
|
713
661
|
|
|
714
662
|
/**
|
|
715
663
|
* Extract relevant flags
|
|
@@ -717,7 +665,12 @@ export class ParticleEmitter {
|
|
|
717
665
|
*/
|
|
718
666
|
const flags = this.flags & (SERIALIZABLE_FLAGS);
|
|
719
667
|
|
|
720
|
-
return computeHashIntegerArray(
|
|
668
|
+
return computeHashIntegerArray(
|
|
669
|
+
parameters_hash,
|
|
670
|
+
layers_hash,
|
|
671
|
+
this.blendingMode,
|
|
672
|
+
flags
|
|
673
|
+
);
|
|
721
674
|
}
|
|
722
675
|
|
|
723
676
|
hash() {
|
|
@@ -799,14 +752,19 @@ export class ParticleEmitter {
|
|
|
799
752
|
|
|
800
753
|
const pivotIndex = (left + right) >> 1;
|
|
801
754
|
|
|
802
|
-
const pivot =
|
|
755
|
+
const pivot = distance_to_camera(pivotIndex, positionArray, nearPlaneNormal);
|
|
803
756
|
|
|
804
757
|
/* partition */
|
|
805
758
|
while (i <= j) {
|
|
806
|
-
|
|
759
|
+
|
|
760
|
+
while (distance_to_camera(i, positionArray, nearPlaneNormal) > pivot) {
|
|
807
761
|
i++;
|
|
808
|
-
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
while (distance_to_camera(j, positionArray, nearPlaneNormal) < pivot) {
|
|
809
765
|
j--;
|
|
766
|
+
}
|
|
767
|
+
|
|
810
768
|
if (i <= j) {
|
|
811
769
|
|
|
812
770
|
if (i !== j) {
|
|
@@ -1032,7 +990,7 @@ export class ParticleEmitter {
|
|
|
1032
990
|
|
|
1033
991
|
update_parameters(ref, particles, layer, initialAge / deathAge);
|
|
1034
992
|
|
|
1035
|
-
particles.writeAttributeScalar(ref,PARTICLE_ATTRIBUTE_BLEND,this.blendingMode);
|
|
993
|
+
particles.writeAttributeScalar(ref, PARTICLE_ATTRIBUTE_BLEND, this.blendingMode);
|
|
1036
994
|
}
|
|
1037
995
|
|
|
1038
996
|
//update time buffer
|
|
@@ -1051,9 +1009,11 @@ export class ParticleEmitter {
|
|
|
1051
1009
|
return;
|
|
1052
1010
|
}
|
|
1053
1011
|
|
|
1054
|
-
|
|
1012
|
+
const layers = this.layers;
|
|
1055
1013
|
|
|
1056
|
-
|
|
1014
|
+
assert.ok(layerIndex < layers.length && layerIndex >= 0, `layerIndex[=${layerIndex}] is out of bounds`);
|
|
1015
|
+
|
|
1016
|
+
const layer = layers.get(layerIndex);
|
|
1057
1017
|
|
|
1058
1018
|
const random = Math.random;
|
|
1059
1019
|
|
|
@@ -1065,7 +1025,7 @@ export class ParticleEmitter {
|
|
|
1065
1025
|
|
|
1066
1026
|
const emissionFunction = computeEmissionFunction(layer.emissionFrom, layer.emissionShape);
|
|
1067
1027
|
|
|
1068
|
-
const layerPosition = layerIndex /
|
|
1028
|
+
const layerPosition = layerIndex / layers.length;
|
|
1069
1029
|
|
|
1070
1030
|
//compute transform matrix of the emitter
|
|
1071
1031
|
composeMatrix4(matrix4, this.position, this.rotation, this.scale);
|
|
@@ -1159,7 +1119,7 @@ export class ParticleEmitter {
|
|
|
1159
1119
|
|
|
1160
1120
|
update_parameters(ref, particles, layer, initialAge / deathAge);
|
|
1161
1121
|
|
|
1162
|
-
particles.writeAttributeScalar(ref,PARTICLE_ATTRIBUTE_BLEND,this.blendingMode);
|
|
1122
|
+
particles.writeAttributeScalar(ref, PARTICLE_ATTRIBUTE_BLEND, this.blendingMode);
|
|
1163
1123
|
}
|
|
1164
1124
|
|
|
1165
1125
|
if (spritesNeedUpdate) {
|
|
@@ -1197,7 +1157,9 @@ export class ParticleEmitter {
|
|
|
1197
1157
|
continue;
|
|
1198
1158
|
}
|
|
1199
1159
|
|
|
1200
|
-
const
|
|
1160
|
+
const particleLife = layer.particleLife;
|
|
1161
|
+
|
|
1162
|
+
const averageLifetime = (particleLife.max + particleLife.min) / 2;
|
|
1201
1163
|
|
|
1202
1164
|
//emitting more than averageLifetime lifetime is unproductive, so we'll crop the emission
|
|
1203
1165
|
let emissionDelta;
|
|
@@ -1260,27 +1222,8 @@ const matrix4 = new Matrix4();
|
|
|
1260
1222
|
|
|
1261
1223
|
const defaultPointsMaterial = new PointsMaterial({ color: 0xFFFFFF });
|
|
1262
1224
|
|
|
1263
|
-
|
|
1264
|
-
//build particle spec
|
|
1265
|
-
export const PARTICULAR_PARTICLE_SPECIFICATION = new ParticleSpecification();
|
|
1266
|
-
|
|
1267
|
-
PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('position', ParticleAttributeType.Vector3, ParticleDataType.Float32));
|
|
1268
|
-
PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('age', ParticleAttributeType.Scalar, ParticleDataType.Float32));
|
|
1269
|
-
PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('deathAge', ParticleAttributeType.Scalar, ParticleDataType.Float32));
|
|
1270
|
-
PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('atlasPatch', ParticleAttributeType.Vector4, ParticleDataType.Float32));
|
|
1271
|
-
PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('size', ParticleAttributeType.Scalar, ParticleDataType.Float32));
|
|
1272
|
-
PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('layerPosition', ParticleAttributeType.Scalar, ParticleDataType.Float32));
|
|
1273
|
-
PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('velocity', ParticleAttributeType.Vector3, ParticleDataType.Float32));
|
|
1274
|
-
PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('rotation', ParticleAttributeType.Scalar, ParticleDataType.Float32));
|
|
1275
|
-
PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('rotationSpeed', ParticleAttributeType.Scalar, ParticleDataType.Float32));
|
|
1276
|
-
PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('color', ParticleAttributeType.Vector4, ParticleDataType.Float32));
|
|
1277
|
-
PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('blending', ParticleAttributeType.Scalar, ParticleDataType.Uint8));
|
|
1278
|
-
PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('size_initial', ParticleAttributeType.Scalar, ParticleDataType.Float32));
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
1225
|
const frustum = new Frustum();
|
|
1282
1226
|
|
|
1283
|
-
const velocity = [];
|
|
1284
1227
|
const position = [];
|
|
1285
1228
|
|
|
1286
1229
|
const v3position = new Vector3();
|