@rzmps/rzmps 1.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.
Files changed (133) hide show
  1. package/README.md +1048 -0
  2. package/build/EmissionShape.d.ts +33 -0
  3. package/build/EmissionShape.js +129 -0
  4. package/build/Emitter.d.ts +58 -0
  5. package/build/Emitter.js +166 -0
  6. package/build/GpuModule.d.ts +28 -0
  7. package/build/GpuModule.js +28 -0
  8. package/build/Module.d.ts +19 -0
  9. package/build/Module.js +31 -0
  10. package/build/Particle.d.ts +60 -0
  11. package/build/Particle.js +52 -0
  12. package/build/ParticleForceField.d.ts +39 -0
  13. package/build/ParticleForceField.js +101 -0
  14. package/build/ParticleForceFieldHelper.d.ts +18 -0
  15. package/build/ParticleForceFieldHelper.js +103 -0
  16. package/build/ParticleSystem.d.ts +122 -0
  17. package/build/ParticleSystem.js +609 -0
  18. package/build/Renderer.d.ts +15 -0
  19. package/build/Renderer.js +11 -0
  20. package/build/assets/images/default.png +0 -0
  21. package/build/collision/ThreeCollisionBackend.d.ts +47 -0
  22. package/build/collision/ThreeCollisionBackend.js +340 -0
  23. package/build/enums/Axis.d.ts +6 -0
  24. package/build/enums/Axis.js +7 -0
  25. package/build/enums/DynamicValueType.d.ts +6 -0
  26. package/build/enums/DynamicValueType.js +7 -0
  27. package/build/enums/EmissionSource copy.d.ts +7 -0
  28. package/build/enums/EmissionSource copy.js +7 -0
  29. package/build/enums/EmissionSource.d.ts +7 -0
  30. package/build/enums/EmissionSource.js +7 -0
  31. package/build/enums/EndBehavior.d.ts +6 -0
  32. package/build/enums/EndBehavior.js +7 -0
  33. package/build/enums/SimulationSpace.d.ts +5 -0
  34. package/build/enums/SimulationSpace.js +6 -0
  35. package/build/enums/SpriteMaterialType.d.ts +5 -0
  36. package/build/enums/SpriteMaterialType.js +6 -0
  37. package/build/enums/TagSelectionMethod.d.ts +6 -0
  38. package/build/enums/TagSelectionMethod.js +7 -0
  39. package/build/enums/TrailMode copy.d.ts +5 -0
  40. package/build/enums/TrailMode copy.js +7 -0
  41. package/build/enums/TrailMode.d.ts +5 -0
  42. package/build/enums/TrailMode.js +7 -0
  43. package/build/enums/TrailTextureMode.d.ts +7 -0
  44. package/build/enums/TrailTextureMode.js +9 -0
  45. package/build/gpu/GpuDynamicValue.d.ts +9 -0
  46. package/build/gpu/GpuDynamicValue.js +113 -0
  47. package/build/gpu/GpuMath.d.ts +3 -0
  48. package/build/gpu/GpuMath.js +12 -0
  49. package/build/gpu/GpuParticleContext.d.ts +63 -0
  50. package/build/gpu/GpuParticleContext.js +291 -0
  51. package/build/helpers/acceptMultiple.d.ts +2 -0
  52. package/build/helpers/acceptMultiple.js +6 -0
  53. package/build/helpers/evaluateDynamic.d.ts +2 -0
  54. package/build/helpers/evaluateDynamic.js +18 -0
  55. package/build/helpers/evaluateDynamicColor.d.ts +3 -0
  56. package/build/helpers/evaluateDynamicColor.js +5 -0
  57. package/build/helpers/evaluateDynamicNumber.d.ts +2 -0
  58. package/build/helpers/evaluateDynamicNumber.js +4 -0
  59. package/build/helpers/evaluateDynamicVector3.d.ts +3 -0
  60. package/build/helpers/evaluateDynamicVector3.js +5 -0
  61. package/build/helpers/isPointInMesh.d.ts +2 -0
  62. package/build/helpers/isPointInMesh.js +8 -0
  63. package/build/helpers/particleRatio.d.ts +2 -0
  64. package/build/helpers/particleRatio.js +13 -0
  65. package/build/helpers/tagsIntersect.d.ts +2 -0
  66. package/build/helpers/tagsIntersect.js +4 -0
  67. package/build/index.d.ts +37 -0
  68. package/build/index.js +34 -0
  69. package/build/interfaces/ICollisionBackend.d.ts +21 -0
  70. package/build/interfaces/ICollisionBackend.js +1 -0
  71. package/build/interfaces/IParticleForceField.d.ts +5 -0
  72. package/build/interfaces/IParticleForceField.js +1 -0
  73. package/build/interfaces/InitialParticleValues.d.ts +18 -0
  74. package/build/interfaces/InitialParticleValues.js +1 -0
  75. package/build/materials/BasicSprite.d.ts +21 -0
  76. package/build/materials/BasicSprite.js +46 -0
  77. package/build/materials/UnlitSprite.d.ts +13 -0
  78. package/build/materials/UnlitSprite.js +31 -0
  79. package/build/materials/WebGPUBasicSprite.d.ts +8 -0
  80. package/build/materials/WebGPUBasicSprite.js +65 -0
  81. package/build/materials/WebGPUUnlitSprite.d.ts +8 -0
  82. package/build/materials/WebGPUUnlitSprite.js +49 -0
  83. package/build/modules/Audio.d.ts +60 -0
  84. package/build/modules/Audio.js +181 -0
  85. package/build/modules/Collision.d.ts +40 -0
  86. package/build/modules/Collision.js +162 -0
  87. package/build/modules/ColorBySpeed.d.ts +18 -0
  88. package/build/modules/ColorBySpeed.js +26 -0
  89. package/build/modules/ColorOverLifetime.d.ts +12 -0
  90. package/build/modules/ColorOverLifetime.js +17 -0
  91. package/build/modules/ExternalForces.d.ts +21 -0
  92. package/build/modules/ExternalForces.js +61 -0
  93. package/build/modules/ForceOverLifetime.d.ts +11 -0
  94. package/build/modules/ForceOverLifetime.js +12 -0
  95. package/build/modules/LimitVelocityOverLifetime.d.ts +16 -0
  96. package/build/modules/LimitVelocityOverLifetime.js +34 -0
  97. package/build/modules/MassOverLifetime.d.ts +11 -0
  98. package/build/modules/MassOverLifetime.js +15 -0
  99. package/build/modules/NoiseModule.d.ts +23 -0
  100. package/build/modules/NoiseModule.js +45 -0
  101. package/build/modules/RotationBySpeed.d.ts +14 -0
  102. package/build/modules/RotationBySpeed.js +19 -0
  103. package/build/modules/RotationOverLifetime.d.ts +11 -0
  104. package/build/modules/RotationOverLifetime.js +12 -0
  105. package/build/modules/ScaleBySpeed.d.ts +14 -0
  106. package/build/modules/ScaleBySpeed.js +19 -0
  107. package/build/modules/ScaleOverLifetime.d.ts +11 -0
  108. package/build/modules/ScaleOverLifetime.js +11 -0
  109. package/build/modules/TransformByNoise.d.ts +17 -0
  110. package/build/modules/TransformByNoise.js +32 -0
  111. package/build/modules/VelocityOverLifetime.d.ts +15 -0
  112. package/build/modules/VelocityOverLifetime.js +32 -0
  113. package/build/renderers/LightRenderer.d.ts +54 -0
  114. package/build/renderers/LightRenderer.js +141 -0
  115. package/build/renderers/MeshRenderer.d.ts +27 -0
  116. package/build/renderers/MeshRenderer.js +70 -0
  117. package/build/renderers/SpriteRenderer.d.ts +95 -0
  118. package/build/renderers/SpriteRenderer.js +456 -0
  119. package/build/renderers/TrailRenderer.d.ts +71 -0
  120. package/build/renderers/TrailRenderer.js +400 -0
  121. package/build/shaders/BasicSprite.frag.js +1 -0
  122. package/build/shaders/BasicSprite.vert.js +1 -0
  123. package/build/shaders/UnlitSprite.frag.js +1 -0
  124. package/build/shaders/UnlitSprite.vert.js +1 -0
  125. package/build/types/DynamicValue.d.ts +2 -0
  126. package/build/types/DynamicValue.js +1 -0
  127. package/build/types/EnumStringLiteral.d.ts +1 -0
  128. package/build/types/EnumStringLiteral.js +1 -0
  129. package/build/types/Multiple.d.ts +2 -0
  130. package/build/types/Multiple.js +1 -0
  131. package/build/types/Tag.d.ts +1 -0
  132. package/build/types/Tag.js +1 -0
  133. package/package.json +39 -0
@@ -0,0 +1,63 @@
1
+ import * as THREE from 'three';
2
+ import Particle from '../Particle';
3
+ import { DynamicValue } from '../types/DynamicValue';
4
+ export type GpuCapableRenderer = {
5
+ compute?: (nodes: any, dispatchSize?: number | number[]) => Promise<void> | undefined;
6
+ computeAsync?: (nodes: any, dispatchSize?: number | number[]) => Promise<void>;
7
+ getArrayBufferAsync?: (attribute: THREE.BufferAttribute, target?: null, offset?: number, count?: number) => Promise<ArrayBuffer>;
8
+ };
9
+ export interface GpuParticleUpdateOptions {
10
+ deltaTime: number;
11
+ gravity: THREE.Vector3;
12
+ }
13
+ export declare const GPU_PREVIOUS_POSITION_KEY = "__rmps_collision_prevPosition";
14
+ export declare class GpuParticleContext {
15
+ capacity: number;
16
+ count: number;
17
+ position: any;
18
+ previousPosition: any;
19
+ rotation: any;
20
+ scale: any;
21
+ velocity: any;
22
+ angularVelocity: any;
23
+ scalarVelocity: any;
24
+ acceleration: any;
25
+ angularAcceleration: any;
26
+ scalarAcceleration: any;
27
+ color: any;
28
+ meta: any;
29
+ mass: any;
30
+ seed: any;
31
+ startPosition: any;
32
+ startRotation: any;
33
+ startScale: any;
34
+ startVelocity: any;
35
+ startAngularVelocity: any;
36
+ startScalarVelocity: any;
37
+ startAcceleration: any;
38
+ startAngularAcceleration: any;
39
+ startScalarAcceleration: any;
40
+ startColor: any;
41
+ startMeta: any;
42
+ startMass: any;
43
+ private noiseBuffers;
44
+ readonly deltaTime: import("three/src/nodes/Nodes.js").UniformNode<"float", number>;
45
+ readonly gravity: import("three/src/nodes/Nodes.js").UniformNode<"vec3", THREE.Vector3>;
46
+ ensureCapacity(count: number): void;
47
+ updateUniforms(options: GpuParticleUpdateOptions): void;
48
+ upload(particles: Particle[]): void;
49
+ download(renderer: GpuCapableRenderer, particles: Particle[]): Promise<void>;
50
+ buildCoreUpdateNodes(gravityModifier: DynamicValue<number>): any[];
51
+ buildCoreUpdateNode(gravityModifier: DynamicValue<number>): any;
52
+ clear(): void;
53
+ private read;
54
+ private markNeedsUpdate;
55
+ getNoise(key: string): any;
56
+ private writeVec3;
57
+ private writeColor;
58
+ private writeMeta;
59
+ private readVec3;
60
+ private storageStride;
61
+ private writeStride;
62
+ private readStride;
63
+ }
@@ -0,0 +1,291 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import * as THREE from 'three';
11
+ import { Fn, instanceIndex, instancedArray, uniform, } from 'three/src/nodes/TSL.js';
12
+ import seedrandom from 'seedrandom';
13
+ import { gpuDynamicNumber } from './GpuDynamicValue';
14
+ export const GPU_PREVIOUS_POSITION_KEY = '__rmps_collision_prevPosition';
15
+ export class GpuParticleContext {
16
+ constructor() {
17
+ this.capacity = 0;
18
+ this.count = 0;
19
+ this.noiseBuffers = new Map();
20
+ this.deltaTime = uniform(0);
21
+ this.gravity = uniform(new THREE.Vector3(), 'vec3');
22
+ }
23
+ ensureCapacity(count) {
24
+ if (count <= this.capacity) {
25
+ this.count = count;
26
+ return;
27
+ }
28
+ this.capacity = Math.max(1, count);
29
+ this.count = count;
30
+ this.noiseBuffers.clear();
31
+ this.position = instancedArray(this.capacity, 'vec3').setName('RmpsPosition');
32
+ this.previousPosition = instancedArray(this.capacity, 'vec3').setName('RmpsPreviousPosition');
33
+ this.rotation = instancedArray(this.capacity, 'vec3').setName('RmpsRotation');
34
+ this.scale = instancedArray(this.capacity, 'vec3').setName('RmpsScale');
35
+ this.velocity = instancedArray(this.capacity, 'vec3').setName('RmpsVelocity');
36
+ this.angularVelocity = instancedArray(this.capacity, 'vec3').setName('RmpsAngularVelocity');
37
+ this.scalarVelocity = instancedArray(this.capacity, 'vec3').setName('RmpsScalarVelocity');
38
+ this.acceleration = instancedArray(this.capacity, 'vec3').setName('RmpsAcceleration');
39
+ this.angularAcceleration = instancedArray(this.capacity, 'vec3').setName('RmpsAngularAcceleration');
40
+ this.scalarAcceleration = instancedArray(this.capacity, 'vec3').setName('RmpsScalarAcceleration');
41
+ this.color = instancedArray(this.capacity, 'vec4').setName('RmpsColor');
42
+ this.meta = instancedArray(this.capacity, 'vec4').setName('RmpsMeta');
43
+ this.mass = instancedArray(this.capacity, 'float').setName('RmpsMass');
44
+ this.seed = instancedArray(this.capacity, 'float').setName('RmpsSeed');
45
+ this.startPosition = instancedArray(this.capacity, 'vec3').setName('RmpsStartPosition');
46
+ this.startRotation = instancedArray(this.capacity, 'vec3').setName('RmpsStartRotation');
47
+ this.startScale = instancedArray(this.capacity, 'vec3').setName('RmpsStartScale');
48
+ this.startVelocity = instancedArray(this.capacity, 'vec3').setName('RmpsStartVelocity');
49
+ this.startAngularVelocity = instancedArray(this.capacity, 'vec3').setName('RmpsStartAngularVelocity');
50
+ this.startScalarVelocity = instancedArray(this.capacity, 'vec3').setName('RmpsStartScalarVelocity');
51
+ this.startAcceleration = instancedArray(this.capacity, 'vec3').setName('RmpsStartAcceleration');
52
+ this.startAngularAcceleration = instancedArray(this.capacity, 'vec3').setName('RmpsStartAngularAcceleration');
53
+ this.startScalarAcceleration = instancedArray(this.capacity, 'vec3').setName('RmpsStartScalarAcceleration');
54
+ this.startColor = instancedArray(this.capacity, 'vec4').setName('RmpsStartColor');
55
+ this.startMeta = instancedArray(this.capacity, 'vec4').setName('RmpsStartMeta');
56
+ this.startMass = instancedArray(this.capacity, 'float').setName('RmpsStartMass');
57
+ }
58
+ updateUniforms(options) {
59
+ this.deltaTime.value = options.deltaTime;
60
+ this.gravity.value.copy(options.gravity);
61
+ }
62
+ upload(particles) {
63
+ this.ensureCapacity(particles.length);
64
+ particles.forEach((particle, index) => {
65
+ this.writeVec3(this.position, index, particle.position);
66
+ this.writeVec3(this.previousPosition, index, particle.position);
67
+ this.writeVec3(this.rotation, index, particle.rotation);
68
+ this.writeVec3(this.scale, index, particle.scale);
69
+ this.writeVec3(this.velocity, index, particle.velocity);
70
+ this.writeVec3(this.angularVelocity, index, particle.angularVelocity);
71
+ this.writeVec3(this.scalarVelocity, index, particle.scalarVelocity);
72
+ this.writeVec3(this.acceleration, index, particle.acceleration);
73
+ this.writeVec3(this.angularAcceleration, index, particle.angularAcceleration);
74
+ this.writeVec3(this.scalarAcceleration, index, particle.scalarAcceleration);
75
+ this.writeColor(this.color.value.array, index, particle.color, particle.alpha);
76
+ this.writeMeta(this.meta.value.array, index, particle.time, particle.realtime, particle.lifetime, particle.speed);
77
+ this.mass.value.array[index] = particle.mass;
78
+ this.seed.value.array[index] = seedrandom(particle.id).quick();
79
+ this.writeVec3(this.startPosition, index, particle.start.position);
80
+ this.writeVec3(this.startRotation, index, particle.start.rotation);
81
+ this.writeVec3(this.startScale, index, particle.start.scale);
82
+ this.writeVec3(this.startVelocity, index, particle.start.velocity);
83
+ this.writeVec3(this.startAngularVelocity, index, particle.start.angularVelocity);
84
+ this.writeVec3(this.startScalarVelocity, index, particle.start.scalarVelocity);
85
+ this.writeVec3(this.startAcceleration, index, particle.start.acceleration);
86
+ this.writeVec3(this.startAngularAcceleration, index, particle.start.angularAcceleration);
87
+ this.writeVec3(this.startScalarAcceleration, index, particle.start.scalarAcceleration);
88
+ this.writeColor(this.startColor.value.array, index, particle.start.color, particle.start.alpha);
89
+ this.writeMeta(this.startMeta.value.array, index, 0, 0, particle.start.lifetime, particle.start.speed);
90
+ this.startMass.value.array[index] = particle.start.mass;
91
+ this.noiseBuffers.forEach((node, key) => {
92
+ var _a, _b;
93
+ const noise = particle.noise[key];
94
+ const offset = index * 2;
95
+ node.value.array[offset] = (_a = noise === null || noise === void 0 ? void 0 : noise.noise) !== null && _a !== void 0 ? _a : 0;
96
+ node.value.array[offset + 1] = (_b = noise === null || noise === void 0 ? void 0 : noise.noise4d) !== null && _b !== void 0 ? _b : 0;
97
+ });
98
+ });
99
+ this.markNeedsUpdate();
100
+ }
101
+ download(renderer, particles) {
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ if (!renderer.getArrayBufferAsync || this.count === 0)
104
+ return;
105
+ const [position, previousPosition, rotation, scale, velocity, angularVelocity, scalarVelocity, acceleration, angularAcceleration, scalarAcceleration, color, meta, mass,] = yield Promise.all([
106
+ this.read(renderer, this.position),
107
+ this.read(renderer, this.previousPosition),
108
+ this.read(renderer, this.rotation),
109
+ this.read(renderer, this.scale),
110
+ this.read(renderer, this.velocity),
111
+ this.read(renderer, this.angularVelocity),
112
+ this.read(renderer, this.scalarVelocity),
113
+ this.read(renderer, this.acceleration),
114
+ this.read(renderer, this.angularAcceleration),
115
+ this.read(renderer, this.scalarAcceleration),
116
+ this.read(renderer, this.color),
117
+ this.read(renderer, this.meta),
118
+ this.read(renderer, this.mass),
119
+ ]);
120
+ particles.forEach((particle, index) => {
121
+ this.readVec3(position, this.position, index, particle.position);
122
+ particle.data[GPU_PREVIOUS_POSITION_KEY] = new THREE.Vector3();
123
+ this.readVec3(previousPosition, this.previousPosition, index, particle.data[GPU_PREVIOUS_POSITION_KEY]);
124
+ this.readVec3(rotation, this.rotation, index, particle.rotation);
125
+ this.readVec3(scale, this.scale, index, particle.scale);
126
+ this.readVec3(velocity, this.velocity, index, particle.velocity);
127
+ this.readVec3(angularVelocity, this.angularVelocity, index, particle.angularVelocity);
128
+ this.readVec3(scalarVelocity, this.scalarVelocity, index, particle.scalarVelocity);
129
+ this.readVec3(acceleration, this.acceleration, index, particle.acceleration);
130
+ this.readVec3(angularAcceleration, this.angularAcceleration, index, particle.angularAcceleration);
131
+ this.readVec3(scalarAcceleration, this.scalarAcceleration, index, particle.scalarAcceleration);
132
+ const colorOffset = index * 4;
133
+ particle.color.setRGB(color[colorOffset], color[colorOffset + 1], color[colorOffset + 2]);
134
+ particle.alpha = color[colorOffset + 3];
135
+ const metaOffset = index * 4;
136
+ particle.time = meta[metaOffset];
137
+ particle.realtime = meta[metaOffset + 1];
138
+ particle.mass = mass[index];
139
+ });
140
+ });
141
+ }
142
+ buildCoreUpdateNodes(gravityModifier) {
143
+ const updatePosition = Fn(() => {
144
+ const index = instanceIndex;
145
+ const position = this.position.element(index);
146
+ const previousPosition = this.previousPosition.element(index);
147
+ const velocity = this.velocity.element(index);
148
+ const acceleration = this.acceleration.element(index);
149
+ const meta = this.meta.element(index);
150
+ const seed = this.seed.element(index);
151
+ const gravityMultiplier = gpuDynamicNumber(gravityModifier, meta.x, seed, 0);
152
+ previousPosition.assign(position);
153
+ velocity.addAssign(this.gravity.mul(this.deltaTime.mul(gravityMultiplier)));
154
+ meta.y.addAssign(this.deltaTime);
155
+ meta.x.assign(meta.y.div(meta.z));
156
+ position.addAssign(velocity.mul(this.deltaTime.mul(meta.w)));
157
+ velocity.addAssign(acceleration.mul(this.deltaTime.mul(meta.w)));
158
+ })().compute(this.count);
159
+ const updateRotation = Fn(() => {
160
+ const index = instanceIndex;
161
+ const rotation = this.rotation.element(index);
162
+ const angularVelocity = this.angularVelocity.element(index);
163
+ const angularAcceleration = this.angularAcceleration.element(index);
164
+ const meta = this.meta.element(index);
165
+ rotation.addAssign(angularVelocity.mul(this.deltaTime.mul(meta.w)));
166
+ angularVelocity.addAssign(angularAcceleration.mul(this.deltaTime.mul(meta.w)));
167
+ })().compute(this.count);
168
+ const updateScale = Fn(() => {
169
+ const index = instanceIndex;
170
+ const scale = this.scale.element(index);
171
+ const scalarVelocity = this.scalarVelocity.element(index);
172
+ const scalarAcceleration = this.scalarAcceleration.element(index);
173
+ const meta = this.meta.element(index);
174
+ scale.addAssign(scalarVelocity.mul(this.deltaTime.mul(meta.w)));
175
+ scalarVelocity.addAssign(scalarAcceleration.mul(this.deltaTime.mul(meta.w)));
176
+ })().compute(this.count);
177
+ const keepReadbackBuffersResident = Fn(() => {
178
+ const index = instanceIndex;
179
+ const color = this.color.element(index);
180
+ const mass = this.mass.element(index);
181
+ color.assign(color);
182
+ mass.assign(mass);
183
+ })().compute(this.count);
184
+ return [
185
+ updatePosition,
186
+ updateRotation,
187
+ updateScale,
188
+ keepReadbackBuffersResident,
189
+ ];
190
+ }
191
+ buildCoreUpdateNode(gravityModifier) {
192
+ return this.buildCoreUpdateNodes(gravityModifier);
193
+ }
194
+ clear() {
195
+ this.count = 0;
196
+ }
197
+ read(renderer, node) {
198
+ return __awaiter(this, void 0, void 0, function* () {
199
+ const buffer = yield renderer.getArrayBufferAsync(node.value, null, 0, this.count * this.storageStride(node) * 4);
200
+ return new Float32Array(buffer);
201
+ });
202
+ }
203
+ markNeedsUpdate() {
204
+ [
205
+ this.position,
206
+ this.previousPosition,
207
+ this.rotation,
208
+ this.scale,
209
+ this.velocity,
210
+ this.angularVelocity,
211
+ this.scalarVelocity,
212
+ this.acceleration,
213
+ this.angularAcceleration,
214
+ this.scalarAcceleration,
215
+ this.color,
216
+ this.meta,
217
+ this.mass,
218
+ this.seed,
219
+ this.startPosition,
220
+ this.startRotation,
221
+ this.startScale,
222
+ this.startVelocity,
223
+ this.startAngularVelocity,
224
+ this.startScalarVelocity,
225
+ this.startAcceleration,
226
+ this.startAngularAcceleration,
227
+ this.startScalarAcceleration,
228
+ this.startColor,
229
+ this.startMeta,
230
+ this.startMass,
231
+ ...Array.from(this.noiseBuffers.values()),
232
+ ].forEach((node) => {
233
+ if (node === null || node === void 0 ? void 0 : node.value)
234
+ node.value.needsUpdate = true;
235
+ });
236
+ }
237
+ getNoise(key) {
238
+ let node = this.noiseBuffers.get(key);
239
+ if (!node) {
240
+ node = instancedArray(this.capacity, 'vec2').setName(`RmpsNoise_${key.replace(/[^a-zA-Z0-9_]/g, '_')}`);
241
+ this.noiseBuffers.set(key, node);
242
+ }
243
+ return node;
244
+ }
245
+ writeVec3(node, index, value) {
246
+ const array = node.value.array;
247
+ const offset = index * this.writeStride(node);
248
+ array[offset] = value.x;
249
+ array[offset + 1] = value.y;
250
+ array[offset + 2] = value.z;
251
+ }
252
+ writeColor(array, index, color, alpha) {
253
+ const offset = index * 4;
254
+ array[offset] = color.r;
255
+ array[offset + 1] = color.g;
256
+ array[offset + 2] = color.b;
257
+ array[offset + 3] = alpha;
258
+ }
259
+ writeMeta(array, index, time, realtime, lifetime, speed) {
260
+ const offset = index * 4;
261
+ array[offset] = time;
262
+ array[offset + 1] = realtime;
263
+ array[offset + 2] = lifetime;
264
+ array[offset + 3] = speed;
265
+ }
266
+ readVec3(array, node, index, target) {
267
+ const offset = index * this.readStride(array, node);
268
+ target.set(array[offset], array[offset + 1], array[offset + 2]);
269
+ }
270
+ storageStride(node) {
271
+ var _a, _b, _c;
272
+ return ((_a = node === null || node === void 0 ? void 0 : node.value) === null || _a === void 0 ? void 0 : _a.itemSize) === 3 ? 4 : (_c = (_b = node === null || node === void 0 ? void 0 : node.value) === null || _b === void 0 ? void 0 : _b.itemSize) !== null && _c !== void 0 ? _c : 1;
273
+ }
274
+ writeStride(node) {
275
+ var _a, _b;
276
+ const itemSize = (_b = (_a = node === null || node === void 0 ? void 0 : node.value) === null || _a === void 0 ? void 0 : _a.itemSize) !== null && _b !== void 0 ? _b : 1;
277
+ if (itemSize !== 3)
278
+ return itemSize;
279
+ const array = node.value.array;
280
+ return array.length >= this.capacity * 4 ? 4 : 3;
281
+ }
282
+ readStride(array, node) {
283
+ var _a, _b;
284
+ const itemSize = (_b = (_a = node === null || node === void 0 ? void 0 : node.value) === null || _a === void 0 ? void 0 : _a.itemSize) !== null && _b !== void 0 ? _b : 1;
285
+ if (itemSize !== 3)
286
+ return itemSize;
287
+ if (this.count <= 0)
288
+ return 4;
289
+ return array.length >= this.count * 4 ? 4 : 3;
290
+ }
291
+ }
@@ -0,0 +1,2 @@
1
+ import { Multiple } from '../types/Multiple';
2
+ export default function acceptMultiple<T>(param?: Multiple<T>): NonNullable<T>[] | undefined;
@@ -0,0 +1,6 @@
1
+ export default function acceptMultiple(param) {
2
+ if (!param)
3
+ return;
4
+ const arr = [];
5
+ return arr.concat(param).filter((e) => e != null);
6
+ }
@@ -0,0 +1,2 @@
1
+ import { DynamicValue } from '../types/DynamicValue';
2
+ export default function evaluateDynamic<T>(value: DynamicValue<T>, interpolate: (a: T, b: T, t: number) => T, time?: number, seed?: string | undefined): T;
@@ -0,0 +1,18 @@
1
+ import seedrandom from 'seedrandom';
2
+ export default function evaluateDynamic(value, interpolate, time = 0, seed = undefined) {
3
+ if (typeof value === 'function') {
4
+ return evaluateDynamic(value(time), interpolate, time, seed);
5
+ }
6
+ else if (Array.isArray(value)) {
7
+ const interpTime = seed == undefined ? Math.random() : seedrandom(seed).quick();
8
+ const min = evaluateDynamic(value[0], interpolate, time, seed);
9
+ const max = evaluateDynamic(value[1], interpolate, time, seed);
10
+ return interpolate(min, max, interpTime);
11
+ }
12
+ else if (value instanceof Set) {
13
+ const indexSelector = seed == undefined ? Math.random() : seedrandom(seed).quick();
14
+ const item = Array.from(value)[Math.floor(value.size * indexSelector)];
15
+ return evaluateDynamic(item, interpolate, time, seed);
16
+ }
17
+ return value;
18
+ }
@@ -0,0 +1,3 @@
1
+ import * as THREE from 'three';
2
+ import { DynamicValue } from '../types/DynamicValue';
3
+ export default function evaluateDynamicColor(value?: DynamicValue<THREE.Color>, time?: number, seed?: string | undefined): THREE.Color;
@@ -0,0 +1,5 @@
1
+ import * as THREE from 'three';
2
+ import evaluateDynamic from './evaluateDynamic';
3
+ export default function evaluateDynamicColor(value = new THREE.Color(), time = 0, seed = undefined) {
4
+ return evaluateDynamic(value, (a, b, t) => (a.clone().add((b.clone().sub(a).multiplyScalar(t)))), time, seed).clone();
5
+ }
@@ -0,0 +1,2 @@
1
+ import { DynamicValue } from '../types/DynamicValue';
2
+ export default function evaluateDynamicNumber(value?: DynamicValue<number>, time?: number, seed?: string | undefined): number;
@@ -0,0 +1,4 @@
1
+ import evaluateDynamic from './evaluateDynamic';
2
+ export default function evaluateDynamicNumber(value = 0, time = 0, seed = undefined) {
3
+ return evaluateDynamic(value, (a, b, t) => (a + (b - a) * t), time, seed);
4
+ }
@@ -0,0 +1,3 @@
1
+ import * as THREE from 'three';
2
+ import { DynamicValue } from '../types/DynamicValue';
3
+ export default function evaluateDynamicVector(value?: DynamicValue<THREE.Vector3>, time?: number, seed?: string | undefined): THREE.Vector3;
@@ -0,0 +1,5 @@
1
+ import * as THREE from 'three';
2
+ import evaluateDynamic from './evaluateDynamic';
3
+ export default function evaluateDynamicVector(value = new THREE.Vector3(), time = 0, seed = undefined) {
4
+ return evaluateDynamic(value, (a, b, t) => (a.clone().add((b.clone().sub(a).multiplyScalar(t)))), time, seed);
5
+ }
@@ -0,0 +1,2 @@
1
+ import * as THREE from 'three';
2
+ export default function isPointInMesh(point: THREE.Vector3, mesh: THREE.Mesh): boolean;
@@ -0,0 +1,8 @@
1
+ import * as THREE from 'three';
2
+ const raycaster = new THREE.Raycaster();
3
+ const rayDirection = new THREE.Vector3(1, 0.371, 0.529).normalize();
4
+ export default function isPointInMesh(point, mesh) {
5
+ raycaster.set(point, rayDirection);
6
+ const intersects = raycaster.intersectObject(mesh, false);
7
+ return intersects.length % 2 === 1;
8
+ }
@@ -0,0 +1,2 @@
1
+ import Particle from "../Particle";
2
+ export default function particleRatio(particle: Particle, ratio: number): boolean;
@@ -0,0 +1,13 @@
1
+ export default function particleRatio(particle, ratio) {
2
+ if (ratio <= 0)
3
+ return false;
4
+ if (ratio >= 1)
5
+ return true;
6
+ let hash = 0;
7
+ for (let i = 0; i < particle.id.length; i += 1) {
8
+ // eslint-disable-next-line no-bitwise
9
+ hash = (hash * 31 + particle.id.charCodeAt(i)) >>> 0;
10
+ }
11
+ const value = hash / 0xffffffff;
12
+ return value < ratio;
13
+ }
@@ -0,0 +1,2 @@
1
+ import { Tag } from "../types/Tag";
2
+ export default function tagsIntersect(a: Tag[], b: Tag[]): boolean;
@@ -0,0 +1,4 @@
1
+ export default function tagsIntersect(a, b) {
2
+ const intersection = new Set(a).intersection(new Set(b));
3
+ return intersection.size !== 0;
4
+ }
@@ -0,0 +1,37 @@
1
+ export { default as ParticleSystem } from './ParticleSystem';
2
+ export { default as Particle } from './Particle';
3
+ export { EndBehavior } from './enums/EndBehavior';
4
+ export { SimulationSpace } from './enums/SimulationSpace';
5
+ export { default as EmissionShape } from './EmissionShape';
6
+ export { default as Emitter } from './Emitter';
7
+ export { EmissionSource } from './enums/EmissionSource';
8
+ export { TagSelectionMethod } from './enums/TagSelectionMethod';
9
+ export { default as Renderer } from './Renderer';
10
+ export { default as LightRenderer } from './renderers/LightRenderer';
11
+ export { default as MeshRenderer } from './renderers/MeshRenderer';
12
+ export { default as SpriteRenderer } from './renderers/SpriteRenderer';
13
+ export { SpriteMaterialType } from './enums/SpriteMaterialType';
14
+ export { default as TrailRenderer } from './renderers/TrailRenderer';
15
+ export { TrailMode } from './enums/TrailMode';
16
+ export { TrailTextureMode } from './enums/TrailTextureMode';
17
+ export { default as Module, ModuleOptions } from './Module';
18
+ export { default as NoiseModule } from './modules/NoiseModule';
19
+ export { default as VelocityOverLifetime } from './modules/VelocityOverLifetime';
20
+ export { default as ForceOverLifetime } from './modules/ForceOverLifetime';
21
+ export { default as LimitVelocityOverLifetime } from './modules/LimitVelocityOverLifetime';
22
+ export { default as TransformByNoise } from './modules/TransformByNoise';
23
+ export { default as ColorOverLifetime } from './modules/ColorOverLifetime';
24
+ export { default as ColorBySpeed } from './modules/ColorBySpeed';
25
+ export { default as ScaleOverLifetime } from './modules/ScaleOverLifetime';
26
+ export { default as ScaleBySpeed } from './modules/ScaleBySpeed';
27
+ export { default as RotationOverLifetime } from './modules/RotationOverLifetime';
28
+ export { default as RotationBySpeed } from './modules/RotationBySpeed';
29
+ export { default as ExternalForces } from './modules/ExternalForces';
30
+ export { default as Collision } from './modules/Collision';
31
+ export { default as Audio } from './modules/Audio';
32
+ export { IParticleForceField } from './interfaces/IParticleForceField';
33
+ export { default as ParticleForceField } from './ParticleForceField';
34
+ export { default as ParticleForceFieldHelper } from './ParticleForceFieldHelper';
35
+ export { ICollisionBackend, CollisionHit, CollisionQuery } from './interfaces/ICollisionBackend';
36
+ export { default as ThreeCollisionBackend } from './collision/ThreeCollisionBackend';
37
+ export { DynamicValue } from './types/DynamicValue';
package/build/index.js ADDED
@@ -0,0 +1,34 @@
1
+ export { default as ParticleSystem } from './ParticleSystem';
2
+ export { default as Particle } from './Particle';
3
+ export { EndBehavior } from './enums/EndBehavior';
4
+ export { SimulationSpace } from './enums/SimulationSpace';
5
+ export { default as EmissionShape } from './EmissionShape';
6
+ export { default as Emitter } from './Emitter';
7
+ export { EmissionSource } from './enums/EmissionSource';
8
+ export { TagSelectionMethod } from './enums/TagSelectionMethod';
9
+ export { default as Renderer } from './Renderer';
10
+ export { default as LightRenderer } from './renderers/LightRenderer';
11
+ export { default as MeshRenderer } from './renderers/MeshRenderer';
12
+ export { default as SpriteRenderer } from './renderers/SpriteRenderer';
13
+ export { SpriteMaterialType } from './enums/SpriteMaterialType';
14
+ export { default as TrailRenderer } from './renderers/TrailRenderer';
15
+ export { TrailMode } from './enums/TrailMode';
16
+ export { TrailTextureMode } from './enums/TrailTextureMode';
17
+ export { default as Module } from './Module';
18
+ export { default as NoiseModule } from './modules/NoiseModule';
19
+ export { default as VelocityOverLifetime } from './modules/VelocityOverLifetime';
20
+ export { default as ForceOverLifetime } from './modules/ForceOverLifetime';
21
+ export { default as LimitVelocityOverLifetime } from './modules/LimitVelocityOverLifetime';
22
+ export { default as TransformByNoise } from './modules/TransformByNoise';
23
+ export { default as ColorOverLifetime } from './modules/ColorOverLifetime';
24
+ export { default as ColorBySpeed } from './modules/ColorBySpeed';
25
+ export { default as ScaleOverLifetime } from './modules/ScaleOverLifetime';
26
+ export { default as ScaleBySpeed } from './modules/ScaleBySpeed';
27
+ export { default as RotationOverLifetime } from './modules/RotationOverLifetime';
28
+ export { default as RotationBySpeed } from './modules/RotationBySpeed';
29
+ export { default as ExternalForces } from './modules/ExternalForces';
30
+ export { default as Collision } from './modules/Collision';
31
+ export { default as Audio } from './modules/Audio';
32
+ export { default as ParticleForceField } from './ParticleForceField';
33
+ export { default as ParticleForceFieldHelper } from './ParticleForceFieldHelper';
34
+ export { default as ThreeCollisionBackend } from './collision/ThreeCollisionBackend';
@@ -0,0 +1,21 @@
1
+ import * as THREE from 'three';
2
+ import Particle from '../Particle';
3
+ export interface CollisionQuery {
4
+ particle: Particle;
5
+ start: THREE.Vector3;
6
+ end: THREE.Vector3;
7
+ radius: number;
8
+ }
9
+ export interface CollisionHit {
10
+ point: THREE.Vector3;
11
+ normal: THREE.Vector3;
12
+ position?: THREE.Vector3;
13
+ object?: THREE.Object3D;
14
+ backendData?: unknown;
15
+ }
16
+ export interface ICollisionBackend {
17
+ update?(deltaTime: number): void;
18
+ collide(query: CollisionQuery): CollisionHit | null;
19
+ applyImpulse?(hit: CollisionHit, impulse: THREE.Vector3): void;
20
+ destroy?(): void;
21
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import * as THREE from 'three';
2
+ import Particle from '../Particle';
3
+ export interface IParticleForceField {
4
+ getForce(particle: Particle, deltaTime: number): THREE.Vector3;
5
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ import * as THREE from 'three';
2
+ import { DynamicValue } from '../types/DynamicValue';
3
+ export interface InitialParticleValues {
4
+ lifetime: DynamicValue<number>;
5
+ speed: DynamicValue<number>;
6
+ position: DynamicValue<THREE.Vector3>;
7
+ rotation: DynamicValue<THREE.Vector3>;
8
+ scale: DynamicValue<THREE.Vector3>;
9
+ velocity: DynamicValue<THREE.Vector3>;
10
+ angularVelocity: DynamicValue<THREE.Vector3>;
11
+ scalarVelocity: DynamicValue<THREE.Vector3>;
12
+ acceleration: DynamicValue<THREE.Vector3>;
13
+ angularAcceleration: DynamicValue<THREE.Vector3>;
14
+ scalarAcceleration: DynamicValue<THREE.Vector3>;
15
+ color: DynamicValue<THREE.Color>;
16
+ alpha: DynamicValue<number>;
17
+ mass: DynamicValue<number>;
18
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ import * as THREE from 'three';
2
+ export interface BasicSpriteOptions extends THREE.ShaderMaterialParameters {
3
+ gridSize: {
4
+ x: number;
5
+ y: number;
6
+ };
7
+ frames: number;
8
+ alphaMap: THREE.Texture;
9
+ normalMap: THREE.Texture;
10
+ normalStrength: number;
11
+ normalLighting: number;
12
+ sphericalNormals: boolean;
13
+ roughness: number;
14
+ roughnessMap: THREE.Texture;
15
+ envMap: THREE.Texture;
16
+ envIntensity: number;
17
+ softParticles: boolean;
18
+ softParticleDistance: number;
19
+ }
20
+ declare const BasicSprite: (texture: THREE.Texture, options?: Partial<BasicSpriteOptions>) => THREE.ShaderMaterial;
21
+ export default BasicSprite;