@newkrok/three-particles 2.16.1 → 3.0.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/README.md +20 -0
- package/dist/index.d.ts +58 -6
- package/dist/index.js +187 -84
- package/dist/index.js.map +1 -1
- package/dist/three-particles.min.js +1 -1
- package/dist/three-particles.min.js.map +1 -1
- package/dist/webgpu.js +261 -255
- package/dist/webgpu.js.map +1 -1
- package/llms-full.txt +16 -1
- package/llms.txt +3 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
import Easing from 'easing-functions';
|
|
2
2
|
import * as THREE5 from 'three';
|
|
3
3
|
import { ObjectUtils } from '@newkrok/three-utils';
|
|
4
|
-
import { Gyroscope } from 'three/examples/jsm/misc/Gyroscope.js';
|
|
5
4
|
import { FBM } from 'three-noise/build/three-noise.module.js';
|
|
6
5
|
|
|
6
|
+
// src/js/effects/three-particles/version.ts
|
|
7
|
+
var REVISION = "3.0.0" ;
|
|
8
|
+
if (typeof globalThis !== "undefined") {
|
|
9
|
+
const g = globalThis;
|
|
10
|
+
if (g.__THREE_PARTICLES__ && g.__THREE_PARTICLES__ !== REVISION) {
|
|
11
|
+
console.warn(
|
|
12
|
+
"WARNING: Multiple instances of @newkrok/three-particles being imported."
|
|
13
|
+
);
|
|
14
|
+
} else {
|
|
15
|
+
g.__THREE_PARTICLES__ = REVISION;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/js/effects/three-particles/color-utils.ts
|
|
20
|
+
var sRGBToLinear = (c) => c < 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
|
|
21
|
+
var linearToSRGB = (c) => c < 31308e-7 ? c * 12.92 : 1.055 * Math.pow(c, 1 / 2.4) - 0.055;
|
|
22
|
+
var rgbSRGBToLinear = (c) => ({
|
|
23
|
+
r: sRGBToLinear(c.r ?? 0),
|
|
24
|
+
g: sRGBToLinear(c.g ?? 0),
|
|
25
|
+
b: sRGBToLinear(c.b ?? 0)
|
|
26
|
+
});
|
|
27
|
+
|
|
7
28
|
// src/js/effects/three-particles/three-particles-bezier.ts
|
|
8
29
|
var cache = [];
|
|
9
30
|
var nCr = (n, k) => {
|
|
@@ -643,6 +664,7 @@ var InstancedParticleFragmentShader = `
|
|
|
643
664
|
}
|
|
644
665
|
|
|
645
666
|
#include <logdepthbuf_fragment>
|
|
667
|
+
#include <colorspace_fragment>
|
|
646
668
|
}
|
|
647
669
|
`;
|
|
648
670
|
var instanced_particle_fragment_shader_glsl_default = InstancedParticleFragmentShader;
|
|
@@ -797,6 +819,7 @@ var MeshParticleFragmentShader = `
|
|
|
797
819
|
}
|
|
798
820
|
|
|
799
821
|
#include <logdepthbuf_fragment>
|
|
822
|
+
#include <colorspace_fragment>
|
|
800
823
|
}
|
|
801
824
|
`;
|
|
802
825
|
var mesh_particle_fragment_shader_glsl_default = MeshParticleFragmentShader;
|
|
@@ -957,6 +980,7 @@ var ParticleSystemFragmentShader = `
|
|
|
957
980
|
}
|
|
958
981
|
|
|
959
982
|
#include <logdepthbuf_fragment>
|
|
983
|
+
#include <colorspace_fragment>
|
|
960
984
|
}
|
|
961
985
|
`;
|
|
962
986
|
var particle_system_fragment_shader_glsl_default = ParticleSystemFragmentShader;
|
|
@@ -1057,6 +1081,7 @@ var TrailFragmentShader = `
|
|
|
1057
1081
|
if (discardBackgroundColor && abs(length(gl_FragColor.rgb - backgroundColor.rgb)) < backgroundColorTolerance) discard;
|
|
1058
1082
|
|
|
1059
1083
|
#include <logdepthbuf_fragment>
|
|
1084
|
+
#include <colorspace_fragment>
|
|
1060
1085
|
}
|
|
1061
1086
|
`;
|
|
1062
1087
|
var trail_fragment_shader_glsl_default = TrailFragmentShader;
|
|
@@ -1281,6 +1306,7 @@ var registerTSLMaterialFactory = (factory) => {
|
|
|
1281
1306
|
_tslMaterialFactory = factory;
|
|
1282
1307
|
};
|
|
1283
1308
|
var _subEmitterPosition = new THREE5.Vector3();
|
|
1309
|
+
var _subLocalPosition = new THREE5.Vector3();
|
|
1284
1310
|
var _shadowOrbitalEuler = new THREE5.Euler(0, 0, 0, "XYZ");
|
|
1285
1311
|
var _lastWorldPositionSnapshot = new THREE5.Vector3();
|
|
1286
1312
|
var _localForceFieldPos = new THREE5.Vector3();
|
|
@@ -1543,11 +1569,10 @@ var destroyParticleSystem = (particleSystem) => {
|
|
|
1543
1569
|
createdParticleSystems = createdParticleSystems.filter(
|
|
1544
1570
|
({
|
|
1545
1571
|
particleSystem: savedParticleSystem,
|
|
1546
|
-
wrapper,
|
|
1547
1572
|
trailMesh,
|
|
1548
1573
|
generalData: { particleSystemId }
|
|
1549
1574
|
}) => {
|
|
1550
|
-
if (savedParticleSystem !== particleSystem
|
|
1575
|
+
if (savedParticleSystem !== particleSystem) {
|
|
1551
1576
|
return true;
|
|
1552
1577
|
}
|
|
1553
1578
|
removeBezierCurveFunction(particleSystemId);
|
|
@@ -1564,7 +1589,6 @@ var destroyParticleSystem = (particleSystem) => {
|
|
|
1564
1589
|
else savedParticleSystem.material.dispose();
|
|
1565
1590
|
if (savedParticleSystem.parent)
|
|
1566
1591
|
savedParticleSystem.parent.remove(savedParticleSystem);
|
|
1567
|
-
if (wrapper?.parent) wrapper.parent.remove(wrapper);
|
|
1568
1592
|
return false;
|
|
1569
1593
|
}
|
|
1570
1594
|
);
|
|
@@ -1578,9 +1602,10 @@ var createParticleSystem = (config = DEFAULT_PARTICLE_SYSTEM_CONFIG, externalNow
|
|
|
1578
1602
|
lastWorldPosition: new THREE5.Vector3(-99999),
|
|
1579
1603
|
currentWorldPosition: new THREE5.Vector3(-99999),
|
|
1580
1604
|
worldPositionChange: new THREE5.Vector3(),
|
|
1605
|
+
sourceWorldMatrix: new THREE5.Matrix4(),
|
|
1581
1606
|
worldQuaternion: new THREE5.Quaternion(),
|
|
1582
1607
|
wrapperQuaternion: new THREE5.Quaternion(),
|
|
1583
|
-
|
|
1608
|
+
worldScale: new THREE5.Vector3(1, 1, 1),
|
|
1584
1609
|
worldEuler: new THREE5.Euler(),
|
|
1585
1610
|
gravityVelocity: new THREE5.Vector3(0, 0, 0),
|
|
1586
1611
|
startValues: {},
|
|
@@ -1855,7 +1880,9 @@ var createParticleSystem = (config = DEFAULT_PARTICLE_SYSTEM_CONFIG, externalNow
|
|
|
1855
1880
|
useFPSForFrameIndex: {
|
|
1856
1881
|
value: textureSheetAnimation.timeMode === "FPS" /* FPS */
|
|
1857
1882
|
},
|
|
1858
|
-
backgroundColor
|
|
1883
|
+
// backgroundColor is authored in sRGB; convert to linear so the
|
|
1884
|
+
// fragment comparison against the (now linear) texture sample is valid.
|
|
1885
|
+
backgroundColor: { value: rgbSRGBToLinear(renderer.backgroundColor) },
|
|
1859
1886
|
discardBackgroundColor: { value: renderer.discardBackgroundColor },
|
|
1860
1887
|
backgroundColorTolerance: { value: renderer.backgroundColorTolerance },
|
|
1861
1888
|
...useInstancing ? { viewportHeight: { value: 1 } } : {},
|
|
@@ -1983,9 +2010,15 @@ var createParticleSystem = (config = DEFAULT_PARTICLE_SYSTEM_CONFIG, externalNow
|
|
|
1983
2010
|
scalarArray[base + S_SIZE] = generalData.startValues.startSize[i];
|
|
1984
2011
|
scalarArray[base + S_ROTATION] = 0;
|
|
1985
2012
|
const colorRandomRatio = Math.random();
|
|
1986
|
-
scalarArray[base + S_COLOR_R] =
|
|
1987
|
-
|
|
1988
|
-
|
|
2013
|
+
scalarArray[base + S_COLOR_R] = sRGBToLinear(
|
|
2014
|
+
startColor.min.r + colorRandomRatio * (startColor.max.r - startColor.min.r)
|
|
2015
|
+
);
|
|
2016
|
+
scalarArray[base + S_COLOR_G] = sRGBToLinear(
|
|
2017
|
+
startColor.min.g + colorRandomRatio * (startColor.max.g - startColor.min.g)
|
|
2018
|
+
);
|
|
2019
|
+
scalarArray[base + S_COLOR_B] = sRGBToLinear(
|
|
2020
|
+
startColor.min.b + colorRandomRatio * (startColor.max.b - startColor.min.b)
|
|
2021
|
+
);
|
|
1989
2022
|
scalarArray[base + S_COLOR_A] = 0;
|
|
1990
2023
|
}
|
|
1991
2024
|
const scalarInterleavedBuffer = useInstancedAttributes ? new THREE5.InstancedInterleavedBuffer(scalarArray, SCALAR_STRIDE) : new THREE5.InterleavedBuffer(scalarArray, SCALAR_STRIDE);
|
|
@@ -2119,9 +2152,15 @@ var createParticleSystem = (config = DEFAULT_PARTICLE_SYSTEM_CONFIG, externalNow
|
|
|
2119
2152
|
generalData.noise.offsets[particleIndex] = Math.random() * 100;
|
|
2120
2153
|
const colorRandomRatio = Math.random();
|
|
2121
2154
|
const cfgStartColor = normalizedConfig.startColor;
|
|
2122
|
-
scalarArray[base + S_COLOR_R] =
|
|
2123
|
-
|
|
2124
|
-
|
|
2155
|
+
scalarArray[base + S_COLOR_R] = sRGBToLinear(
|
|
2156
|
+
cfgStartColor.min.r + colorRandomRatio * (cfgStartColor.max.r - cfgStartColor.min.r)
|
|
2157
|
+
);
|
|
2158
|
+
scalarArray[base + S_COLOR_G] = sRGBToLinear(
|
|
2159
|
+
cfgStartColor.min.g + colorRandomRatio * (cfgStartColor.max.g - cfgStartColor.min.g)
|
|
2160
|
+
);
|
|
2161
|
+
scalarArray[base + S_COLOR_B] = sRGBToLinear(
|
|
2162
|
+
cfgStartColor.min.b + colorRandomRatio * (cfgStartColor.max.b - cfgStartColor.min.b)
|
|
2163
|
+
);
|
|
2125
2164
|
generalData.startValues.startColorR[particleIndex] = scalarArray[base + S_COLOR_R];
|
|
2126
2165
|
generalData.startValues.startColorG[particleIndex] = scalarArray[base + S_COLOR_G];
|
|
2127
2166
|
generalData.startValues.startColorB[particleIndex] = scalarArray[base + S_COLOR_B];
|
|
@@ -2176,9 +2215,21 @@ var createParticleSystem = (config = DEFAULT_PARTICLE_SYSTEM_CONFIG, externalNow
|
|
|
2176
2215
|
);
|
|
2177
2216
|
{
|
|
2178
2217
|
const positionIndex = particleIndex * 3;
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2218
|
+
const isWorld = normalizedConfig.simulationSpace === "WORLD" /* WORLD */;
|
|
2219
|
+
const ox = startPositions[particleIndex].x;
|
|
2220
|
+
const oy = startPositions[particleIndex].y;
|
|
2221
|
+
const oz = startPositions[particleIndex].z;
|
|
2222
|
+
if (isWorld) {
|
|
2223
|
+
const m = generalData.sourceWorldMatrix.elements;
|
|
2224
|
+
const s = generalData.worldScale;
|
|
2225
|
+
aPosition.array[positionIndex] = position.x + ox * s.x + m[12];
|
|
2226
|
+
aPosition.array[positionIndex + 1] = position.y + oy * s.y + m[13];
|
|
2227
|
+
aPosition.array[positionIndex + 2] = position.z + oz * s.z + m[14];
|
|
2228
|
+
} else {
|
|
2229
|
+
aPosition.array[positionIndex] = position.x + ox;
|
|
2230
|
+
aPosition.array[positionIndex + 1] = position.y + oy;
|
|
2231
|
+
aPosition.array[positionIndex + 2] = position.z + oz;
|
|
2232
|
+
}
|
|
2182
2233
|
if (!useGPUCompute) {
|
|
2183
2234
|
aPosition.needsUpdate = true;
|
|
2184
2235
|
}
|
|
@@ -2228,14 +2279,20 @@ var createParticleSystem = (config = DEFAULT_PARTICLE_SYSTEM_CONFIG, externalNow
|
|
|
2228
2279
|
}
|
|
2229
2280
|
scalarArray[base + S_LIFETIME] = 0;
|
|
2230
2281
|
if (useGPUCompute && gpuPipeline) {
|
|
2282
|
+
const isWorld = normalizedConfig.simulationSpace === "WORLD" /* WORLD */;
|
|
2283
|
+
const m = generalData.sourceWorldMatrix.elements;
|
|
2284
|
+
const s = generalData.worldScale;
|
|
2285
|
+
const ox = startPositions[particleIndex].x;
|
|
2286
|
+
const oy = startPositions[particleIndex].y;
|
|
2287
|
+
const oz = startPositions[particleIndex].z;
|
|
2231
2288
|
_tslMaterialFactory.writeParticleToModifierBuffers(
|
|
2232
2289
|
gpuPipeline.buffers,
|
|
2233
2290
|
particleIndex,
|
|
2234
2291
|
{
|
|
2235
2292
|
position: {
|
|
2236
|
-
x: position.x +
|
|
2237
|
-
y: position.y +
|
|
2238
|
-
z: position.z +
|
|
2293
|
+
x: position.x + (isWorld ? ox * s.x + m[12] : ox),
|
|
2294
|
+
y: position.y + (isWorld ? oy * s.y + m[13] : oy),
|
|
2295
|
+
z: position.z + (isWorld ? oz * s.z + m[14] : oz)
|
|
2239
2296
|
},
|
|
2240
2297
|
velocity: {
|
|
2241
2298
|
x: velocities[particleIndex].x,
|
|
@@ -2291,8 +2348,7 @@ var createParticleSystem = (config = DEFAULT_PARTICLE_SYSTEM_CONFIG, externalNow
|
|
|
2291
2348
|
const cleanupCompletedInstances = (instances) => {
|
|
2292
2349
|
for (let i = instances.length - 1; i >= 0; i--) {
|
|
2293
2350
|
const sub = instances[i];
|
|
2294
|
-
const
|
|
2295
|
-
const geomAttrs = obj3d?.geometry?.attributes;
|
|
2351
|
+
const geomAttrs = sub.instance.geometry?.attributes;
|
|
2296
2352
|
const isActiveAttr = geomAttrs ? geomAttrs.isActive ?? geomAttrs.instanceIsActive : void 0;
|
|
2297
2353
|
if (!isActiveAttr) {
|
|
2298
2354
|
sub.dispose();
|
|
@@ -2313,6 +2369,12 @@ var createParticleSystem = (config = DEFAULT_PARTICLE_SYSTEM_CONFIG, externalNow
|
|
|
2313
2369
|
}
|
|
2314
2370
|
};
|
|
2315
2371
|
const spawnSubEmitters = (configs, position, velocity, spawnNow) => {
|
|
2372
|
+
const parentObj = particleSystem.parent;
|
|
2373
|
+
_subLocalPosition.copy(position);
|
|
2374
|
+
if (parentObj) {
|
|
2375
|
+
parentObj.updateMatrixWorld();
|
|
2376
|
+
parentObj.worldToLocal(_subLocalPosition);
|
|
2377
|
+
}
|
|
2316
2378
|
for (const subConfig of configs) {
|
|
2317
2379
|
const instances = subEmitterInstancesMap.get(subConfig);
|
|
2318
2380
|
const maxInst = subConfig.maxInstances ?? 32;
|
|
@@ -2330,7 +2392,11 @@ var createParticleSystem = (config = DEFAULT_PARTICLE_SYSTEM_CONFIG, externalNow
|
|
|
2330
2392
|
simulationBackend: "CPU" /* CPU */,
|
|
2331
2393
|
transform: {
|
|
2332
2394
|
...subConfig.config.transform,
|
|
2333
|
-
position: new THREE5.Vector3(
|
|
2395
|
+
position: new THREE5.Vector3(
|
|
2396
|
+
_subLocalPosition.x,
|
|
2397
|
+
_subLocalPosition.y,
|
|
2398
|
+
_subLocalPosition.z
|
|
2399
|
+
)
|
|
2334
2400
|
},
|
|
2335
2401
|
renderer: {
|
|
2336
2402
|
...subConfig.config.renderer ?? {},
|
|
@@ -2342,7 +2408,6 @@ var createParticleSystem = (config = DEFAULT_PARTICLE_SYSTEM_CONFIG, externalNow
|
|
|
2342
2408
|
},
|
|
2343
2409
|
spawnNow
|
|
2344
2410
|
);
|
|
2345
|
-
const parentObj = (wrapper || particleSystem).parent;
|
|
2346
2411
|
if (parentObj) parentObj.add(subSystem.instance);
|
|
2347
2412
|
instances.push(subSystem);
|
|
2348
2413
|
}
|
|
@@ -2420,7 +2485,9 @@ var createParticleSystem = (config = DEFAULT_PARTICLE_SYSTEM_CONFIG, externalNow
|
|
|
2420
2485
|
map: { value: particleMap },
|
|
2421
2486
|
useMap: { value: !!particleMap },
|
|
2422
2487
|
discardBackgroundColor: { value: renderer.discardBackgroundColor },
|
|
2423
|
-
|
|
2488
|
+
// sRGB → linear so the trail fragment comparison matches the
|
|
2489
|
+
// (now linear) texture sample and vertex color.
|
|
2490
|
+
backgroundColor: { value: rgbSRGBToLinear(renderer.backgroundColor) },
|
|
2424
2491
|
backgroundColorTolerance: { value: renderer.backgroundColorTolerance },
|
|
2425
2492
|
softParticlesEnabled: { value: softParticlesEnabled },
|
|
2426
2493
|
softParticlesIntensity: {
|
|
@@ -2517,10 +2584,9 @@ var createParticleSystem = (config = DEFAULT_PARTICLE_SYSTEM_CONFIG, externalNow
|
|
|
2517
2584
|
...useMesh ? { quat: aQuat } : {}
|
|
2518
2585
|
};
|
|
2519
2586
|
const calculatedCreationTime = now + calculateValue(generalData.particleSystemId, startDelay) * 1e3;
|
|
2520
|
-
let wrapper;
|
|
2521
2587
|
if (normalizedConfig.simulationSpace === "WORLD" /* WORLD */) {
|
|
2522
|
-
|
|
2523
|
-
|
|
2588
|
+
particleSystem.matrixWorldAutoUpdate = false;
|
|
2589
|
+
particleSystem.matrixWorld.identity();
|
|
2524
2590
|
}
|
|
2525
2591
|
const hasDeathSubEmitters = deathSubEmitters.length > 0;
|
|
2526
2592
|
const hasBirthSubEmitters = birthSubEmitters.length > 0;
|
|
@@ -2532,6 +2598,7 @@ var createParticleSystem = (config = DEFAULT_PARTICLE_SYSTEM_CONFIG, externalNow
|
|
|
2532
2598
|
positionArr[posIdx + 2]
|
|
2533
2599
|
);
|
|
2534
2600
|
if (simulationSpace === "LOCAL" /* LOCAL */) {
|
|
2601
|
+
particleSystem.updateMatrixWorld();
|
|
2535
2602
|
particleSystem.localToWorld(_subEmitterPosition);
|
|
2536
2603
|
}
|
|
2537
2604
|
spawnSubEmitters(
|
|
@@ -2549,6 +2616,7 @@ var createParticleSystem = (config = DEFAULT_PARTICLE_SYSTEM_CONFIG, externalNow
|
|
|
2549
2616
|
positionArr[posIdx + 2]
|
|
2550
2617
|
);
|
|
2551
2618
|
if (simulationSpace === "LOCAL" /* LOCAL */) {
|
|
2619
|
+
particleSystem.updateMatrixWorld();
|
|
2552
2620
|
particleSystem.localToWorld(_subEmitterPosition);
|
|
2553
2621
|
}
|
|
2554
2622
|
spawnSubEmitters(
|
|
@@ -2560,7 +2628,6 @@ var createParticleSystem = (config = DEFAULT_PARTICLE_SYSTEM_CONFIG, externalNow
|
|
|
2560
2628
|
} : void 0;
|
|
2561
2629
|
const instanceData = {
|
|
2562
2630
|
particleSystem,
|
|
2563
|
-
wrapper,
|
|
2564
2631
|
mappedAttributes,
|
|
2565
2632
|
scalarArray,
|
|
2566
2633
|
scalarInterleavedBuffer,
|
|
@@ -2635,13 +2702,25 @@ var createParticleSystem = (config = DEFAULT_PARTICLE_SYSTEM_CONFIG, externalNow
|
|
|
2635
2702
|
const cfg = instanceData.normalizedConfig;
|
|
2636
2703
|
if (partialConfig.gravity !== void 0) {
|
|
2637
2704
|
instanceData.gravity = cfg.gravity;
|
|
2638
|
-
generalData.lastWorldQuaternion.x = -99999;
|
|
2639
2705
|
}
|
|
2640
2706
|
if (partialConfig.duration !== void 0)
|
|
2641
2707
|
instanceData.duration = cfg.duration;
|
|
2642
2708
|
if (partialConfig.looping !== void 0) instanceData.looping = cfg.looping;
|
|
2643
|
-
if (partialConfig.simulationSpace !== void 0)
|
|
2709
|
+
if (partialConfig.simulationSpace !== void 0 && instanceData.simulationSpace !== cfg.simulationSpace) {
|
|
2710
|
+
for (let i = 0; i < maxParticles; i++) {
|
|
2711
|
+
if (scalarArray[i * SCALAR_STRIDE + S_IS_ACTIVE]) {
|
|
2712
|
+
deactivateParticle(i);
|
|
2713
|
+
}
|
|
2714
|
+
}
|
|
2715
|
+
generalData.lastWorldPosition.set(-99999, -99999, -99999);
|
|
2716
|
+
if (cfg.simulationSpace === "WORLD" /* WORLD */) {
|
|
2717
|
+
particleSystem.matrixWorldAutoUpdate = false;
|
|
2718
|
+
particleSystem.matrixWorld.identity();
|
|
2719
|
+
} else {
|
|
2720
|
+
particleSystem.matrixWorldAutoUpdate = true;
|
|
2721
|
+
}
|
|
2644
2722
|
instanceData.simulationSpace = cfg.simulationSpace;
|
|
2723
|
+
}
|
|
2645
2724
|
if (partialConfig.emission !== void 0)
|
|
2646
2725
|
instanceData.emission = cfg.emission;
|
|
2647
2726
|
if (partialConfig.forceFields !== void 0) {
|
|
@@ -2675,7 +2754,7 @@ var createParticleSystem = (config = DEFAULT_PARTICLE_SYSTEM_CONFIG, externalNow
|
|
|
2675
2754
|
}
|
|
2676
2755
|
};
|
|
2677
2756
|
return {
|
|
2678
|
-
instance:
|
|
2757
|
+
instance: particleSystem,
|
|
2679
2758
|
resumeEmitter,
|
|
2680
2759
|
pauseEmitter,
|
|
2681
2760
|
dispose,
|
|
@@ -2690,7 +2769,6 @@ var updateParticleSystemInstance = (props, { now, delta, elapsed }) => {
|
|
|
2690
2769
|
generalData,
|
|
2691
2770
|
onComplete,
|
|
2692
2771
|
particleSystem,
|
|
2693
|
-
wrapper,
|
|
2694
2772
|
elapsedUniform,
|
|
2695
2773
|
creationTime,
|
|
2696
2774
|
lastEmissionTime,
|
|
@@ -2725,41 +2803,70 @@ var updateParticleSystemInstance = (props, { now, delta, elapsed }) => {
|
|
|
2725
2803
|
lastWorldPosition,
|
|
2726
2804
|
currentWorldPosition,
|
|
2727
2805
|
worldPositionChange,
|
|
2728
|
-
lastWorldQuaternion,
|
|
2729
2806
|
worldQuaternion,
|
|
2730
2807
|
worldEuler,
|
|
2731
2808
|
gravityVelocity,
|
|
2809
|
+
sourceWorldMatrix,
|
|
2732
2810
|
isEnabled
|
|
2733
2811
|
} = generalData;
|
|
2734
|
-
if (wrapper?.parent)
|
|
2735
|
-
generalData.wrapperQuaternion.copy(wrapper.parent.quaternion);
|
|
2736
2812
|
_lastWorldPositionSnapshot.copy(lastWorldPosition);
|
|
2737
2813
|
elapsedUniform.value = elapsed;
|
|
2738
|
-
|
|
2814
|
+
if (simulationSpace === "WORLD" /* WORLD */) {
|
|
2815
|
+
particleSystem.updateMatrix();
|
|
2816
|
+
if (particleSystem.parent) {
|
|
2817
|
+
particleSystem.parent.updateMatrixWorld();
|
|
2818
|
+
sourceWorldMatrix.multiplyMatrices(
|
|
2819
|
+
particleSystem.parent.matrixWorld,
|
|
2820
|
+
particleSystem.matrix
|
|
2821
|
+
);
|
|
2822
|
+
} else {
|
|
2823
|
+
sourceWorldMatrix.copy(particleSystem.matrix);
|
|
2824
|
+
}
|
|
2825
|
+
sourceWorldMatrix.decompose(
|
|
2826
|
+
currentWorldPosition,
|
|
2827
|
+
worldQuaternion,
|
|
2828
|
+
generalData.worldScale
|
|
2829
|
+
);
|
|
2830
|
+
generalData.wrapperQuaternion.copy(worldQuaternion);
|
|
2831
|
+
particleSystem.matrixWorld.identity();
|
|
2832
|
+
} else {
|
|
2833
|
+
particleSystem.updateMatrixWorld();
|
|
2834
|
+
particleSystem.getWorldPosition(currentWorldPosition);
|
|
2835
|
+
particleSystem.getWorldQuaternion(worldQuaternion);
|
|
2836
|
+
particleSystem.getWorldScale(generalData.worldScale);
|
|
2837
|
+
generalData.wrapperQuaternion.identity();
|
|
2838
|
+
}
|
|
2739
2839
|
if (lastWorldPosition.x !== -99999) {
|
|
2740
2840
|
worldPositionChange.set(
|
|
2741
2841
|
currentWorldPosition.x - lastWorldPosition.x,
|
|
2742
2842
|
currentWorldPosition.y - lastWorldPosition.y,
|
|
2743
2843
|
currentWorldPosition.z - lastWorldPosition.z
|
|
2744
2844
|
);
|
|
2845
|
+
} else {
|
|
2846
|
+
worldPositionChange.set(0, 0, 0);
|
|
2745
2847
|
}
|
|
2746
2848
|
if (isEnabled) {
|
|
2747
2849
|
generalData.distanceFromLastEmitByDistance += worldPositionChange.length();
|
|
2748
2850
|
}
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
if (
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
gravityVelocity.set(
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2851
|
+
lastWorldPosition.copy(currentWorldPosition);
|
|
2852
|
+
worldEuler.setFromQuaternion(worldQuaternion);
|
|
2853
|
+
if (simulationSpace === "WORLD" /* WORLD */) {
|
|
2854
|
+
gravityVelocity.set(0, gravity, 0);
|
|
2855
|
+
} else {
|
|
2856
|
+
gravityVelocity.set(0, gravity, 0);
|
|
2857
|
+
_inverseQuat.copy(worldQuaternion).invert();
|
|
2858
|
+
gravityVelocity.applyQuaternion(_inverseQuat);
|
|
2859
|
+
const sx = generalData.worldScale.x || 1;
|
|
2860
|
+
const sy = generalData.worldScale.y || 1;
|
|
2861
|
+
const sz = generalData.worldScale.z || 1;
|
|
2862
|
+
gravityVelocity.x /= sx;
|
|
2863
|
+
gravityVelocity.y /= sy;
|
|
2864
|
+
gravityVelocity.z /= sz;
|
|
2760
2865
|
}
|
|
2761
2866
|
if (hasForceFields) {
|
|
2762
|
-
|
|
2867
|
+
if (simulationSpace === "LOCAL" /* LOCAL */) {
|
|
2868
|
+
_inverseQuat.copy(worldQuaternion).invert();
|
|
2869
|
+
}
|
|
2763
2870
|
_localForceFields.length = normalizedForceFields.length;
|
|
2764
2871
|
for (let i = 0; i < normalizedForceFields.length; i++) {
|
|
2765
2872
|
const src = normalizedForceFields[i];
|
|
@@ -2781,16 +2888,23 @@ var updateParticleSystemInstance = (props, { now, delta, elapsed }) => {
|
|
|
2781
2888
|
dst.strength = src.strength;
|
|
2782
2889
|
dst.range = src.range;
|
|
2783
2890
|
dst.falloff = src.falloff;
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2891
|
+
if (simulationSpace === "WORLD" /* WORLD */) {
|
|
2892
|
+
dst.position.copy(src.position);
|
|
2893
|
+
dst.direction.copy(src.direction);
|
|
2894
|
+
} else {
|
|
2895
|
+
_localForceFieldPos.copy(src.position);
|
|
2896
|
+
particleSystem.worldToLocal(_localForceFieldPos);
|
|
2897
|
+
dst.position.copy(_localForceFieldPos);
|
|
2898
|
+
_localForceFieldDir.copy(src.direction);
|
|
2899
|
+
_localForceFieldDir.applyQuaternion(_inverseQuat);
|
|
2900
|
+
dst.direction.copy(_localForceFieldDir);
|
|
2901
|
+
}
|
|
2790
2902
|
}
|
|
2791
2903
|
}
|
|
2792
2904
|
if (hasCollisionPlanes) {
|
|
2793
|
-
if (!hasForceFields)
|
|
2905
|
+
if (simulationSpace === "LOCAL" /* LOCAL */ && !hasForceFields) {
|
|
2906
|
+
_inverseQuat.copy(worldQuaternion).invert();
|
|
2907
|
+
}
|
|
2794
2908
|
_localCollisionPlanes.length = normalizedCollisionPlanes.length;
|
|
2795
2909
|
for (let i = 0; i < normalizedCollisionPlanes.length; i++) {
|
|
2796
2910
|
const src = normalizedCollisionPlanes[i];
|
|
@@ -2810,12 +2924,17 @@ var updateParticleSystemInstance = (props, { now, delta, elapsed }) => {
|
|
|
2810
2924
|
dst.mode = src.mode;
|
|
2811
2925
|
dst.dampen = src.dampen;
|
|
2812
2926
|
dst.lifetimeLoss = src.lifetimeLoss;
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2927
|
+
if (simulationSpace === "WORLD" /* WORLD */) {
|
|
2928
|
+
dst.position.copy(src.position);
|
|
2929
|
+
dst.normal.copy(src.normal);
|
|
2930
|
+
} else {
|
|
2931
|
+
_localCollisionPlanePos.copy(src.position);
|
|
2932
|
+
particleSystem.worldToLocal(_localCollisionPlanePos);
|
|
2933
|
+
dst.position.copy(_localCollisionPlanePos);
|
|
2934
|
+
_localCollisionPlaneNormal.copy(src.normal);
|
|
2935
|
+
_localCollisionPlaneNormal.applyQuaternion(_inverseQuat);
|
|
2936
|
+
dst.normal.copy(_localCollisionPlaneNormal);
|
|
2937
|
+
}
|
|
2819
2938
|
}
|
|
2820
2939
|
}
|
|
2821
2940
|
const creationTimes = generalData.creationTimes;
|
|
@@ -2832,16 +2951,6 @@ var updateParticleSystemInstance = (props, { now, delta, elapsed }) => {
|
|
|
2832
2951
|
gravityVelocity.y,
|
|
2833
2952
|
gravityVelocity.z
|
|
2834
2953
|
);
|
|
2835
|
-
setUniformVec3(
|
|
2836
|
-
cp.uniforms.worldPositionChange,
|
|
2837
|
-
generalData.worldPositionChange.x,
|
|
2838
|
-
generalData.worldPositionChange.y,
|
|
2839
|
-
generalData.worldPositionChange.z
|
|
2840
|
-
);
|
|
2841
|
-
setUniformFloat(
|
|
2842
|
-
cp.uniforms.simulationSpaceWorld,
|
|
2843
|
-
simulationSpace === "WORLD" /* WORLD */ ? 1 : 0
|
|
2844
|
-
);
|
|
2845
2954
|
const noiseData = generalData.noise;
|
|
2846
2955
|
setUniformFloat(cp.uniforms.noiseStrength, noiseData.strength);
|
|
2847
2956
|
setUniformFloat(
|
|
@@ -2859,7 +2968,9 @@ var updateParticleSystemInstance = (props, { now, delta, elapsed }) => {
|
|
|
2859
2968
|
generalData.normalizedLifetimePercentage
|
|
2860
2969
|
);
|
|
2861
2970
|
const curveArr = cp.buffers.curveData.array;
|
|
2862
|
-
|
|
2971
|
+
const offset = cp.forceFieldInfo.offset;
|
|
2972
|
+
curveArr.set(encodedFF, offset);
|
|
2973
|
+
cp.buffers.curveData.addUpdateRange(offset, encodedFF.length);
|
|
2863
2974
|
cp.buffers.curveData.needsUpdate = true;
|
|
2864
2975
|
setUniformFloat(
|
|
2865
2976
|
cp.forceFieldInfo.countUniform,
|
|
@@ -2871,7 +2982,9 @@ var updateParticleSystemInstance = (props, { now, delta, elapsed }) => {
|
|
|
2871
2982
|
_localCollisionPlanes
|
|
2872
2983
|
);
|
|
2873
2984
|
const curveArr = cp.buffers.curveData.array;
|
|
2874
|
-
|
|
2985
|
+
const offset = cp.collisionPlaneInfo.offset;
|
|
2986
|
+
curveArr.set(encodedCP, offset);
|
|
2987
|
+
cp.buffers.curveData.addUpdateRange(offset, encodedCP.length);
|
|
2875
2988
|
cp.buffers.curveData.needsUpdate = true;
|
|
2876
2989
|
setUniformFloat(
|
|
2877
2990
|
cp.collisionPlaneInfo.countUniform,
|
|
@@ -2907,11 +3020,6 @@ var updateParticleSystemInstance = (props, { now, delta, elapsed }) => {
|
|
|
2907
3020
|
});
|
|
2908
3021
|
}
|
|
2909
3022
|
const positionIndex = index * 3;
|
|
2910
|
-
if (simulationSpace === "WORLD" /* WORLD */) {
|
|
2911
|
-
positionArr[positionIndex] -= worldPositionChange.x;
|
|
2912
|
-
positionArr[positionIndex + 1] -= worldPositionChange.y;
|
|
2913
|
-
positionArr[positionIndex + 2] -= worldPositionChange.z;
|
|
2914
|
-
}
|
|
2915
3023
|
positionArr[positionIndex] += velocity.x * delta;
|
|
2916
3024
|
positionArr[positionIndex + 1] += velocity.y * delta;
|
|
2917
3025
|
positionArr[positionIndex + 2] += velocity.z * delta;
|
|
@@ -2982,13 +3090,8 @@ var updateParticleSystemInstance = (props, { now, delta, elapsed }) => {
|
|
|
2982
3090
|
systemLifetimePercentage: generalData.normalizedLifetimePercentage
|
|
2983
3091
|
});
|
|
2984
3092
|
}
|
|
2985
|
-
if (gravity !== 0 || velocity.x !== 0 || velocity.y !== 0 || velocity.z !== 0
|
|
3093
|
+
if (gravity !== 0 || velocity.x !== 0 || velocity.y !== 0 || velocity.z !== 0) {
|
|
2986
3094
|
const positionIndex = index * 3;
|
|
2987
|
-
if (simulationSpace === "WORLD" /* WORLD */) {
|
|
2988
|
-
positionArr[positionIndex] -= worldPositionChange.x;
|
|
2989
|
-
positionArr[positionIndex + 1] -= worldPositionChange.y;
|
|
2990
|
-
positionArr[positionIndex + 2] -= worldPositionChange.z;
|
|
2991
|
-
}
|
|
2992
3095
|
positionArr[positionIndex] += velocity.x * delta;
|
|
2993
3096
|
positionArr[positionIndex + 1] += velocity.y * delta;
|
|
2994
3097
|
positionArr[positionIndex + 2] += velocity.z * delta;
|
|
@@ -4139,6 +4242,6 @@ function deserializeParticleSystem(json) {
|
|
|
4139
4242
|
return deserializeConfig(raw);
|
|
4140
4243
|
}
|
|
4141
4244
|
|
|
4142
|
-
export { CollisionPlaneMode, CurveFunctionId, EmitFrom, ForceFieldFalloff, ForceFieldType, LifeTimeCurve, RendererType, SCALAR_STRIDE, S_COLOR_A, S_COLOR_B, S_COLOR_G, S_COLOR_R, S_IS_ACTIVE, S_LIFETIME, S_ROTATION, S_SIZE, S_START_FRAME, S_START_LIFETIME, Shape, SimulationBackend, SimulationSpace, SubEmitterTrigger, TimeMode, applyModifiers, blendingMap, calculateRandomPositionAndVelocityOnBox, calculateRandomPositionAndVelocityOnCircle, calculateRandomPositionAndVelocityOnCone, calculateRandomPositionAndVelocityOnRectangle, calculateRandomPositionAndVelocityOnSphere, calculateValue, createBezierCurveFunction, createDefaultMeshTexture, createDefaultParticleTexture, createParticleSystem, curveFunctionIdMap, deserializeParticleSystem, getBezierCacheSize, getCurveFunction, getCurveFunctionFromConfig, getDefaultParticleSystemConfig, isComputeCapableRenderer, isLifeTimeCurve, registerTSLMaterialFactory, removeBezierCurveFunction, resolveSimulationBackend, serializeParticleSystem, updateParticleSystems };
|
|
4245
|
+
export { CollisionPlaneMode, CurveFunctionId, EmitFrom, ForceFieldFalloff, ForceFieldType, LifeTimeCurve, REVISION, RendererType, SCALAR_STRIDE, S_COLOR_A, S_COLOR_B, S_COLOR_G, S_COLOR_R, S_IS_ACTIVE, S_LIFETIME, S_ROTATION, S_SIZE, S_START_FRAME, S_START_LIFETIME, Shape, SimulationBackend, SimulationSpace, SubEmitterTrigger, TimeMode, applyModifiers, blendingMap, calculateRandomPositionAndVelocityOnBox, calculateRandomPositionAndVelocityOnCircle, calculateRandomPositionAndVelocityOnCone, calculateRandomPositionAndVelocityOnRectangle, calculateRandomPositionAndVelocityOnSphere, calculateValue, createBezierCurveFunction, createDefaultMeshTexture, createDefaultParticleTexture, createParticleSystem, curveFunctionIdMap, deserializeParticleSystem, getBezierCacheSize, getCurveFunction, getCurveFunctionFromConfig, getDefaultParticleSystemConfig, isComputeCapableRenderer, isLifeTimeCurve, linearToSRGB, registerTSLMaterialFactory, removeBezierCurveFunction, resolveSimulationBackend, rgbSRGBToLinear, sRGBToLinear, serializeParticleSystem, updateParticleSystems };
|
|
4143
4246
|
//# sourceMappingURL=index.js.map
|
|
4144
4247
|
//# sourceMappingURL=index.js.map
|