@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.
- package/README.md +1048 -0
- package/build/EmissionShape.d.ts +33 -0
- package/build/EmissionShape.js +129 -0
- package/build/Emitter.d.ts +58 -0
- package/build/Emitter.js +166 -0
- package/build/GpuModule.d.ts +28 -0
- package/build/GpuModule.js +28 -0
- package/build/Module.d.ts +19 -0
- package/build/Module.js +31 -0
- package/build/Particle.d.ts +60 -0
- package/build/Particle.js +52 -0
- package/build/ParticleForceField.d.ts +39 -0
- package/build/ParticleForceField.js +101 -0
- package/build/ParticleForceFieldHelper.d.ts +18 -0
- package/build/ParticleForceFieldHelper.js +103 -0
- package/build/ParticleSystem.d.ts +122 -0
- package/build/ParticleSystem.js +609 -0
- package/build/Renderer.d.ts +15 -0
- package/build/Renderer.js +11 -0
- package/build/assets/images/default.png +0 -0
- package/build/collision/ThreeCollisionBackend.d.ts +47 -0
- package/build/collision/ThreeCollisionBackend.js +340 -0
- package/build/enums/Axis.d.ts +6 -0
- package/build/enums/Axis.js +7 -0
- package/build/enums/DynamicValueType.d.ts +6 -0
- package/build/enums/DynamicValueType.js +7 -0
- package/build/enums/EmissionSource copy.d.ts +7 -0
- package/build/enums/EmissionSource copy.js +7 -0
- package/build/enums/EmissionSource.d.ts +7 -0
- package/build/enums/EmissionSource.js +7 -0
- package/build/enums/EndBehavior.d.ts +6 -0
- package/build/enums/EndBehavior.js +7 -0
- package/build/enums/SimulationSpace.d.ts +5 -0
- package/build/enums/SimulationSpace.js +6 -0
- package/build/enums/SpriteMaterialType.d.ts +5 -0
- package/build/enums/SpriteMaterialType.js +6 -0
- package/build/enums/TagSelectionMethod.d.ts +6 -0
- package/build/enums/TagSelectionMethod.js +7 -0
- package/build/enums/TrailMode copy.d.ts +5 -0
- package/build/enums/TrailMode copy.js +7 -0
- package/build/enums/TrailMode.d.ts +5 -0
- package/build/enums/TrailMode.js +7 -0
- package/build/enums/TrailTextureMode.d.ts +7 -0
- package/build/enums/TrailTextureMode.js +9 -0
- package/build/gpu/GpuDynamicValue.d.ts +9 -0
- package/build/gpu/GpuDynamicValue.js +113 -0
- package/build/gpu/GpuMath.d.ts +3 -0
- package/build/gpu/GpuMath.js +12 -0
- package/build/gpu/GpuParticleContext.d.ts +63 -0
- package/build/gpu/GpuParticleContext.js +291 -0
- package/build/helpers/acceptMultiple.d.ts +2 -0
- package/build/helpers/acceptMultiple.js +6 -0
- package/build/helpers/evaluateDynamic.d.ts +2 -0
- package/build/helpers/evaluateDynamic.js +18 -0
- package/build/helpers/evaluateDynamicColor.d.ts +3 -0
- package/build/helpers/evaluateDynamicColor.js +5 -0
- package/build/helpers/evaluateDynamicNumber.d.ts +2 -0
- package/build/helpers/evaluateDynamicNumber.js +4 -0
- package/build/helpers/evaluateDynamicVector3.d.ts +3 -0
- package/build/helpers/evaluateDynamicVector3.js +5 -0
- package/build/helpers/isPointInMesh.d.ts +2 -0
- package/build/helpers/isPointInMesh.js +8 -0
- package/build/helpers/particleRatio.d.ts +2 -0
- package/build/helpers/particleRatio.js +13 -0
- package/build/helpers/tagsIntersect.d.ts +2 -0
- package/build/helpers/tagsIntersect.js +4 -0
- package/build/index.d.ts +37 -0
- package/build/index.js +34 -0
- package/build/interfaces/ICollisionBackend.d.ts +21 -0
- package/build/interfaces/ICollisionBackend.js +1 -0
- package/build/interfaces/IParticleForceField.d.ts +5 -0
- package/build/interfaces/IParticleForceField.js +1 -0
- package/build/interfaces/InitialParticleValues.d.ts +18 -0
- package/build/interfaces/InitialParticleValues.js +1 -0
- package/build/materials/BasicSprite.d.ts +21 -0
- package/build/materials/BasicSprite.js +46 -0
- package/build/materials/UnlitSprite.d.ts +13 -0
- package/build/materials/UnlitSprite.js +31 -0
- package/build/materials/WebGPUBasicSprite.d.ts +8 -0
- package/build/materials/WebGPUBasicSprite.js +65 -0
- package/build/materials/WebGPUUnlitSprite.d.ts +8 -0
- package/build/materials/WebGPUUnlitSprite.js +49 -0
- package/build/modules/Audio.d.ts +60 -0
- package/build/modules/Audio.js +181 -0
- package/build/modules/Collision.d.ts +40 -0
- package/build/modules/Collision.js +162 -0
- package/build/modules/ColorBySpeed.d.ts +18 -0
- package/build/modules/ColorBySpeed.js +26 -0
- package/build/modules/ColorOverLifetime.d.ts +12 -0
- package/build/modules/ColorOverLifetime.js +17 -0
- package/build/modules/ExternalForces.d.ts +21 -0
- package/build/modules/ExternalForces.js +61 -0
- package/build/modules/ForceOverLifetime.d.ts +11 -0
- package/build/modules/ForceOverLifetime.js +12 -0
- package/build/modules/LimitVelocityOverLifetime.d.ts +16 -0
- package/build/modules/LimitVelocityOverLifetime.js +34 -0
- package/build/modules/MassOverLifetime.d.ts +11 -0
- package/build/modules/MassOverLifetime.js +15 -0
- package/build/modules/NoiseModule.d.ts +23 -0
- package/build/modules/NoiseModule.js +45 -0
- package/build/modules/RotationBySpeed.d.ts +14 -0
- package/build/modules/RotationBySpeed.js +19 -0
- package/build/modules/RotationOverLifetime.d.ts +11 -0
- package/build/modules/RotationOverLifetime.js +12 -0
- package/build/modules/ScaleBySpeed.d.ts +14 -0
- package/build/modules/ScaleBySpeed.js +19 -0
- package/build/modules/ScaleOverLifetime.d.ts +11 -0
- package/build/modules/ScaleOverLifetime.js +11 -0
- package/build/modules/TransformByNoise.d.ts +17 -0
- package/build/modules/TransformByNoise.js +32 -0
- package/build/modules/VelocityOverLifetime.d.ts +15 -0
- package/build/modules/VelocityOverLifetime.js +32 -0
- package/build/renderers/LightRenderer.d.ts +54 -0
- package/build/renderers/LightRenderer.js +141 -0
- package/build/renderers/MeshRenderer.d.ts +27 -0
- package/build/renderers/MeshRenderer.js +70 -0
- package/build/renderers/SpriteRenderer.d.ts +95 -0
- package/build/renderers/SpriteRenderer.js +456 -0
- package/build/renderers/TrailRenderer.d.ts +71 -0
- package/build/renderers/TrailRenderer.js +400 -0
- package/build/shaders/BasicSprite.frag.js +1 -0
- package/build/shaders/BasicSprite.vert.js +1 -0
- package/build/shaders/UnlitSprite.frag.js +1 -0
- package/build/shaders/UnlitSprite.vert.js +1 -0
- package/build/types/DynamicValue.d.ts +2 -0
- package/build/types/DynamicValue.js +1 -0
- package/build/types/EnumStringLiteral.d.ts +1 -0
- package/build/types/EnumStringLiteral.js +1 -0
- package/build/types/Multiple.d.ts +2 -0
- package/build/types/Multiple.js +1 -0
- package/build/types/Tag.d.ts +1 -0
- package/build/types/Tag.js +1 -0
- package/package.json +39 -0
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { Octree } from 'three/examples/jsm/math/Octree.js';
|
|
3
|
+
import { Capsule } from 'three/examples/jsm/math/Capsule.js';
|
|
4
|
+
import ParticleSystem from '../ParticleSystem';
|
|
5
|
+
import { TRAIL_RENDERER_USER_DATA_KEY } from '../renderers/TrailRenderer';
|
|
6
|
+
import { SPRITE_RENDERER_USER_DATA_KEY } from '../renderers/SpriteRenderer';
|
|
7
|
+
var Classification;
|
|
8
|
+
(function (Classification) {
|
|
9
|
+
Classification[Classification["Static"] = 0] = "Static";
|
|
10
|
+
Classification[Classification["Dynamic"] = 1] = "Dynamic";
|
|
11
|
+
Classification[Classification["Auto"] = 2] = "Auto";
|
|
12
|
+
})(Classification || (Classification = {}));
|
|
13
|
+
class ThreeCollisionBackend {
|
|
14
|
+
constructor(options = {}) {
|
|
15
|
+
var _a, _b, _c, _d;
|
|
16
|
+
this.staticOctree = new Octree();
|
|
17
|
+
this.dynamicOctree = new Octree();
|
|
18
|
+
this.trackedObjects = new Map();
|
|
19
|
+
this.elapsedTime = 0;
|
|
20
|
+
this.dynamicUpdateAccumulator = 0;
|
|
21
|
+
this.refreshAccumulator = 0;
|
|
22
|
+
this.world = options.world;
|
|
23
|
+
this.staticObjects = options.staticObjects;
|
|
24
|
+
this.dynamicObjects = options.dynamicObjects;
|
|
25
|
+
this.objectFilter = options.objectFilter;
|
|
26
|
+
this.staticObjectFilter = options.staticObjectFilter;
|
|
27
|
+
this.dynamicObjectFilter = options.dynamicObjectFilter;
|
|
28
|
+
this.staticAfter = (_a = options.staticAfter) !== null && _a !== void 0 ? _a : 2;
|
|
29
|
+
this.timeQuality = THREE.MathUtils.clamp((_b = options.timeQuality) !== null && _b !== void 0 ? _b : 1, Number.EPSILON, 1);
|
|
30
|
+
this.refreshQuality = THREE.MathUtils.clamp((_d = (_c = options.refreshQuality) !== null && _c !== void 0 ? _c : options.timeQuality) !== null && _d !== void 0 ? _d : 1, Number.EPSILON, 1);
|
|
31
|
+
this.initialize();
|
|
32
|
+
}
|
|
33
|
+
update(deltaTime) {
|
|
34
|
+
this.elapsedTime += deltaTime;
|
|
35
|
+
let staticMembershipChanged = false;
|
|
36
|
+
let dynamicMembershipChanged = false;
|
|
37
|
+
this.refreshAccumulator += this.refreshQuality;
|
|
38
|
+
if (this.refreshAccumulator >= 1) {
|
|
39
|
+
this.refreshAccumulator -= 1;
|
|
40
|
+
const changes = this.refreshObjects();
|
|
41
|
+
staticMembershipChanged || (staticMembershipChanged = changes.staticChanged);
|
|
42
|
+
dynamicMembershipChanged || (dynamicMembershipChanged = changes.dynamicChanged);
|
|
43
|
+
}
|
|
44
|
+
for (const tracked of this.trackedObjects.values()) {
|
|
45
|
+
tracked.object.updateWorldMatrix(true, false);
|
|
46
|
+
if (tracked.classification !== Classification.Auto)
|
|
47
|
+
continue;
|
|
48
|
+
const moved = this.matrixChanged(tracked.matrixWorld, tracked.object.matrixWorld);
|
|
49
|
+
if (moved) {
|
|
50
|
+
tracked.matrixWorld.copy(tracked.object.matrixWorld);
|
|
51
|
+
tracked.lastMovedAt = this.elapsedTime;
|
|
52
|
+
if (!tracked.dynamic) {
|
|
53
|
+
tracked.dynamic = true;
|
|
54
|
+
staticMembershipChanged = true;
|
|
55
|
+
dynamicMembershipChanged = true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else if (tracked.dynamic
|
|
59
|
+
&& this.elapsedTime - tracked.lastMovedAt >= this.staticAfter) {
|
|
60
|
+
tracked.dynamic = false;
|
|
61
|
+
staticMembershipChanged = true;
|
|
62
|
+
dynamicMembershipChanged = true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (staticMembershipChanged) {
|
|
66
|
+
this.rebuildStaticOctree();
|
|
67
|
+
}
|
|
68
|
+
if (dynamicMembershipChanged) {
|
|
69
|
+
this.rebuildDynamicOctree();
|
|
70
|
+
this.dynamicUpdateAccumulator = 0;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
this.dynamicUpdateAccumulator += this.timeQuality;
|
|
74
|
+
if (this.dynamicUpdateAccumulator >= 1) {
|
|
75
|
+
this.dynamicUpdateAccumulator -= 1;
|
|
76
|
+
this.rebuildDynamicOctree();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
collide(query) {
|
|
80
|
+
const capsule = new Capsule(query.start.clone(), query.end.clone(), Math.max(query.radius, Number.EPSILON));
|
|
81
|
+
const staticHit = this.staticOctree.capsuleIntersect(capsule);
|
|
82
|
+
const dynamicHit = this.dynamicOctree.capsuleIntersect(capsule);
|
|
83
|
+
if (!staticHit && !dynamicHit)
|
|
84
|
+
return null;
|
|
85
|
+
const collisionVector = new THREE.Vector3();
|
|
86
|
+
if (staticHit) {
|
|
87
|
+
collisionVector.addScaledVector(staticHit.normal, staticHit.depth);
|
|
88
|
+
}
|
|
89
|
+
if (dynamicHit) {
|
|
90
|
+
collisionVector.addScaledVector(dynamicHit.normal, dynamicHit.depth);
|
|
91
|
+
}
|
|
92
|
+
if (collisionVector.lengthSq() === 0)
|
|
93
|
+
return null;
|
|
94
|
+
const normal = collisionVector.clone().normalize();
|
|
95
|
+
const position = query.end
|
|
96
|
+
.clone()
|
|
97
|
+
.add(collisionVector);
|
|
98
|
+
const point = position
|
|
99
|
+
.clone()
|
|
100
|
+
.addScaledVector(normal, -query.radius);
|
|
101
|
+
return {
|
|
102
|
+
point,
|
|
103
|
+
normal,
|
|
104
|
+
position,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
initialize() {
|
|
108
|
+
this.refreshObjects();
|
|
109
|
+
this.rebuildStaticOctree();
|
|
110
|
+
this.rebuildDynamicOctree();
|
|
111
|
+
this.dynamicUpdateAccumulator = 0;
|
|
112
|
+
this.refreshAccumulator = 0;
|
|
113
|
+
}
|
|
114
|
+
refreshObjects() {
|
|
115
|
+
const previous = this.trackedObjects;
|
|
116
|
+
const next = new Map();
|
|
117
|
+
if (this.hasExplicitLists()) {
|
|
118
|
+
this.collectExplicitObjects(next, previous);
|
|
119
|
+
}
|
|
120
|
+
else if (this.world) {
|
|
121
|
+
this.collectWorldObjects(next, previous);
|
|
122
|
+
}
|
|
123
|
+
let staticChanged = false;
|
|
124
|
+
let dynamicChanged = false;
|
|
125
|
+
const ids = new Set([
|
|
126
|
+
...previous.keys(),
|
|
127
|
+
...next.keys(),
|
|
128
|
+
]);
|
|
129
|
+
for (const id of ids) {
|
|
130
|
+
const before = previous.get(id);
|
|
131
|
+
const after = next.get(id);
|
|
132
|
+
if (!before && after) {
|
|
133
|
+
if (after.dynamic)
|
|
134
|
+
dynamicChanged = true;
|
|
135
|
+
else
|
|
136
|
+
staticChanged = true;
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (before && !after) {
|
|
140
|
+
if (before.dynamic)
|
|
141
|
+
dynamicChanged = true;
|
|
142
|
+
else
|
|
143
|
+
staticChanged = true;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (!before || !after)
|
|
147
|
+
continue;
|
|
148
|
+
if (before.dynamic !== after.dynamic) {
|
|
149
|
+
staticChanged = true;
|
|
150
|
+
dynamicChanged = true;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
this.trackedObjects = next;
|
|
154
|
+
return {
|
|
155
|
+
staticChanged,
|
|
156
|
+
dynamicChanged,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
hasExplicitLists() {
|
|
160
|
+
return this.staticObjects !== undefined
|
|
161
|
+
|| this.dynamicObjects !== undefined;
|
|
162
|
+
}
|
|
163
|
+
collectExplicitObjects(target, previous) {
|
|
164
|
+
var _a, _b;
|
|
165
|
+
this.collectRoots((_a = this.staticObjects) !== null && _a !== void 0 ? _a : [], (mesh) => {
|
|
166
|
+
this.trackObject(target, previous, mesh, Classification.Static);
|
|
167
|
+
});
|
|
168
|
+
this.collectRoots((_b = this.dynamicObjects) !== null && _b !== void 0 ? _b : [], (mesh) => {
|
|
169
|
+
this.trackObject(target, previous, mesh, Classification.Dynamic);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
collectWorldObjects(target, previous) {
|
|
173
|
+
if (!this.world)
|
|
174
|
+
return;
|
|
175
|
+
this.world.updateWorldMatrix(true, true);
|
|
176
|
+
this.world.traverse((object) => {
|
|
177
|
+
var _a, _b, _c, _d;
|
|
178
|
+
if (!(object instanceof THREE.Mesh))
|
|
179
|
+
return;
|
|
180
|
+
if (object instanceof ParticleSystem)
|
|
181
|
+
return;
|
|
182
|
+
// Ideally, we ignore all helpers here.
|
|
183
|
+
// Good god, what a mess
|
|
184
|
+
if (object instanceof THREE.BoxHelper)
|
|
185
|
+
return;
|
|
186
|
+
if (object instanceof THREE.Box3Helper)
|
|
187
|
+
return;
|
|
188
|
+
if (object instanceof THREE.AxesHelper)
|
|
189
|
+
return;
|
|
190
|
+
if (object instanceof THREE.GridHelper)
|
|
191
|
+
return;
|
|
192
|
+
if (object instanceof THREE.ArrowHelper)
|
|
193
|
+
return;
|
|
194
|
+
if (object instanceof THREE.PlaneHelper)
|
|
195
|
+
return;
|
|
196
|
+
if (object instanceof THREE.CameraHelper)
|
|
197
|
+
return;
|
|
198
|
+
if (object instanceof THREE.SkeletonHelper)
|
|
199
|
+
return;
|
|
200
|
+
if (object instanceof THREE.PolarGridHelper)
|
|
201
|
+
return;
|
|
202
|
+
if (object instanceof THREE.DirectionalLightHelper)
|
|
203
|
+
return;
|
|
204
|
+
if (object instanceof THREE.HemisphereLightHelper)
|
|
205
|
+
return;
|
|
206
|
+
if (object instanceof THREE.SpotLightHelper)
|
|
207
|
+
return;
|
|
208
|
+
if (object instanceof THREE.PointLightHelper)
|
|
209
|
+
return;
|
|
210
|
+
// Check for renderer object
|
|
211
|
+
if (object.userData[TRAIL_RENDERER_USER_DATA_KEY])
|
|
212
|
+
return;
|
|
213
|
+
if (object.userData[SPRITE_RENDERER_USER_DATA_KEY])
|
|
214
|
+
return;
|
|
215
|
+
if (this.objectFilter
|
|
216
|
+
&& !this.objectFilter(object)) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
const isDynamic = (_b = (_a = this.dynamicObjectFilter) === null || _a === void 0 ? void 0 : _a.call(this, object)) !== null && _b !== void 0 ? _b : false;
|
|
220
|
+
const isStatic = (_d = (_c = this.staticObjectFilter) === null || _c === void 0 ? void 0 : _c.call(this, object)) !== null && _d !== void 0 ? _d : false;
|
|
221
|
+
if (isDynamic) {
|
|
222
|
+
this.trackObject(target, previous, object, Classification.Dynamic);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (isStatic) {
|
|
226
|
+
this.trackObject(target, previous, object, Classification.Static);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
this.trackObject(target, previous, object, Classification.Auto);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
collectRoots(roots, callback) {
|
|
233
|
+
roots.forEach((root) => {
|
|
234
|
+
root.updateWorldMatrix(true, true);
|
|
235
|
+
root.traverse((object) => {
|
|
236
|
+
if (!(object instanceof THREE.Mesh))
|
|
237
|
+
return;
|
|
238
|
+
if (this.objectFilter
|
|
239
|
+
&& !this.objectFilter(object)) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
callback(object);
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
trackObject(target, previous, object, classification) {
|
|
247
|
+
const existing = target.get(object.uuid);
|
|
248
|
+
if ((existing === null || existing === void 0 ? void 0 : existing.classification) === Classification.Dynamic) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
const previousTracked = previous.get(object.uuid);
|
|
252
|
+
object.updateWorldMatrix(true, false);
|
|
253
|
+
if (classification === Classification.Auto
|
|
254
|
+
&& (previousTracked === null || previousTracked === void 0 ? void 0 : previousTracked.classification) === Classification.Auto) {
|
|
255
|
+
target.set(object.uuid, {
|
|
256
|
+
object,
|
|
257
|
+
classification,
|
|
258
|
+
dynamic: previousTracked.dynamic,
|
|
259
|
+
matrixWorld: previousTracked.matrixWorld.clone(),
|
|
260
|
+
lastMovedAt: previousTracked.lastMovedAt,
|
|
261
|
+
});
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
target.set(object.uuid, {
|
|
265
|
+
object,
|
|
266
|
+
classification,
|
|
267
|
+
dynamic: classification === Classification.Dynamic,
|
|
268
|
+
matrixWorld: object.matrixWorld.clone(),
|
|
269
|
+
lastMovedAt: this.elapsedTime,
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
rebuildStaticOctree() {
|
|
273
|
+
const objects = Array.from(this.trackedObjects.values())
|
|
274
|
+
.filter((tracked) => !tracked.dynamic)
|
|
275
|
+
.map((tracked) => tracked.object);
|
|
276
|
+
this.staticOctree = this.buildOctree(objects);
|
|
277
|
+
}
|
|
278
|
+
rebuildDynamicOctree() {
|
|
279
|
+
const objects = Array.from(this.trackedObjects.values())
|
|
280
|
+
.filter((tracked) => tracked.dynamic)
|
|
281
|
+
.map((tracked) => tracked.object);
|
|
282
|
+
this.dynamicOctree = this.buildOctree(objects);
|
|
283
|
+
}
|
|
284
|
+
buildOctree(objects) {
|
|
285
|
+
const octree = new Octree();
|
|
286
|
+
let triangleCount = 0;
|
|
287
|
+
objects.forEach((object) => {
|
|
288
|
+
triangleCount += this.addMeshToOctree(octree, object);
|
|
289
|
+
});
|
|
290
|
+
if (triangleCount > 0) {
|
|
291
|
+
octree.build();
|
|
292
|
+
}
|
|
293
|
+
return octree;
|
|
294
|
+
}
|
|
295
|
+
addMeshToOctree(octree, object) {
|
|
296
|
+
object.updateWorldMatrix(true, false);
|
|
297
|
+
const sourceGeometry = object.geometry;
|
|
298
|
+
if (!(sourceGeometry instanceof THREE.BufferGeometry)) {
|
|
299
|
+
return 0;
|
|
300
|
+
}
|
|
301
|
+
let geometry = sourceGeometry;
|
|
302
|
+
let temporaryGeometry;
|
|
303
|
+
if (sourceGeometry.index !== null) {
|
|
304
|
+
temporaryGeometry = sourceGeometry.toNonIndexed();
|
|
305
|
+
geometry = temporaryGeometry;
|
|
306
|
+
}
|
|
307
|
+
const position = geometry.getAttribute('position');
|
|
308
|
+
if (!position) {
|
|
309
|
+
temporaryGeometry === null || temporaryGeometry === void 0 ? void 0 : temporaryGeometry.dispose();
|
|
310
|
+
return 0;
|
|
311
|
+
}
|
|
312
|
+
let count = 0;
|
|
313
|
+
for (let i = 0; i + 2 < position.count; i += 3) {
|
|
314
|
+
const a = new THREE.Vector3()
|
|
315
|
+
.fromBufferAttribute(position, i)
|
|
316
|
+
.applyMatrix4(object.matrixWorld);
|
|
317
|
+
const b = new THREE.Vector3()
|
|
318
|
+
.fromBufferAttribute(position, i + 1)
|
|
319
|
+
.applyMatrix4(object.matrixWorld);
|
|
320
|
+
const c = new THREE.Vector3()
|
|
321
|
+
.fromBufferAttribute(position, i + 2)
|
|
322
|
+
.applyMatrix4(object.matrixWorld);
|
|
323
|
+
octree.addTriangle(new THREE.Triangle(a, b, c));
|
|
324
|
+
count++;
|
|
325
|
+
}
|
|
326
|
+
temporaryGeometry === null || temporaryGeometry === void 0 ? void 0 : temporaryGeometry.dispose();
|
|
327
|
+
return count;
|
|
328
|
+
}
|
|
329
|
+
matrixChanged(previous, current) {
|
|
330
|
+
const a = previous.elements;
|
|
331
|
+
const b = current.elements;
|
|
332
|
+
for (let i = 0; i < 16; i++) {
|
|
333
|
+
if (Math.abs(a[i] - b[i]) > 1e-6) {
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return false;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
export default ThreeCollisionBackend;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
var DynamicValueType;
|
|
2
|
+
(function (DynamicValueType) {
|
|
3
|
+
DynamicValueType[DynamicValueType["Constant"] = 0] = "Constant";
|
|
4
|
+
DynamicValueType[DynamicValueType["Curve"] = 1] = "Curve";
|
|
5
|
+
DynamicValueType[DynamicValueType["Between"] = 2] = "Between";
|
|
6
|
+
})(DynamicValueType || (DynamicValueType = {}));
|
|
7
|
+
export default DynamicValueType;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
var TagSelectionMethod;
|
|
2
|
+
(function (TagSelectionMethod) {
|
|
3
|
+
TagSelectionMethod["All"] = "all";
|
|
4
|
+
TagSelectionMethod["Random"] = "random";
|
|
5
|
+
TagSelectionMethod["Distribute"] = "distribute";
|
|
6
|
+
})(TagSelectionMethod || (TagSelectionMethod = {}));
|
|
7
|
+
export { TagSelectionMethod };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
var TrailTextureMode;
|
|
2
|
+
(function (TrailTextureMode) {
|
|
3
|
+
TrailTextureMode["Stretch"] = "stretch";
|
|
4
|
+
TrailTextureMode["Tile"] = "tile";
|
|
5
|
+
TrailTextureMode["RepeatPerSegment"] = "repeat";
|
|
6
|
+
TrailTextureMode["DistributePerSegment"] = "distribute";
|
|
7
|
+
})(TrailTextureMode || (TrailTextureMode = {}));
|
|
8
|
+
;
|
|
9
|
+
export { TrailTextureMode };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { DynamicValue, GpuDynamicValueOption } from '../types/DynamicValue';
|
|
3
|
+
export declare const GPU_DYNAMIC_VALUE_SAMPLE_COUNT = 32;
|
|
4
|
+
export declare function isGpuDynamicValue<T>(value: DynamicValue<T> | undefined): boolean;
|
|
5
|
+
export declare function gpuDynamicNumber(value: DynamicValue<number> | undefined, time: any, seed: any, fallback?: number): any;
|
|
6
|
+
export declare function gpuDynamicVector3(value: DynamicValue<THREE.Vector3> | undefined, time: any, seed: any, fallback?: THREE.Vector3): any;
|
|
7
|
+
export declare function gpuDynamicColor(value: DynamicValue<THREE.Color> | undefined, time: any, seed: any, fallback?: THREE.Color): any;
|
|
8
|
+
export declare function gpuDynamicValue<T>(cpu: DynamicValue<T>, tsl: GpuDynamicValueOption<T>['tsl']): GpuDynamicValueOption<T>;
|
|
9
|
+
export declare function gpuDynamicColorAlpha(color: DynamicValue<THREE.Color> | undefined, alpha: DynamicValue<number> | undefined, time: any, seed: any): any;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { clamp, float, mix, select, vec3, vec4, } from 'three/src/nodes/TSL.js';
|
|
3
|
+
import { isGpuDynamicValueOption } from '../types/DynamicValue';
|
|
4
|
+
export const GPU_DYNAMIC_VALUE_SAMPLE_COUNT = 32;
|
|
5
|
+
export function isGpuDynamicValue(value) {
|
|
6
|
+
if (value === undefined)
|
|
7
|
+
return true;
|
|
8
|
+
if (isGpuDynamicValueOption(value))
|
|
9
|
+
return true;
|
|
10
|
+
if (typeof value === 'function') {
|
|
11
|
+
return sampleFunction(value)
|
|
12
|
+
.every((sample) => isGpuDynamicValue(sample));
|
|
13
|
+
}
|
|
14
|
+
if (Array.isArray(value)) {
|
|
15
|
+
return isGpuDynamicValue(value[0]) && isGpuDynamicValue(value[1]);
|
|
16
|
+
}
|
|
17
|
+
if (value instanceof Set) {
|
|
18
|
+
return Array.from(value).every((item) => isGpuDynamicValue(item));
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
export function gpuDynamicNumber(value, time, seed, fallback = 0) {
|
|
23
|
+
if (value === undefined)
|
|
24
|
+
return float(fallback);
|
|
25
|
+
if (isGpuDynamicValueOption(value))
|
|
26
|
+
return gpuDynamicOption(value, time, seed);
|
|
27
|
+
if (typeof value === 'function') {
|
|
28
|
+
return sampleDynamicValue(value, time, seed, fallback, gpuDynamicNumber);
|
|
29
|
+
}
|
|
30
|
+
if (Array.isArray(value)) {
|
|
31
|
+
return mix(gpuDynamicNumber(value[0], time, seed, fallback), gpuDynamicNumber(value[1], time, seed, fallback), seed);
|
|
32
|
+
}
|
|
33
|
+
if (value instanceof Set) {
|
|
34
|
+
return selectFromSet(Array.from(value), time, seed, fallback, gpuDynamicNumber);
|
|
35
|
+
}
|
|
36
|
+
return float(value);
|
|
37
|
+
}
|
|
38
|
+
export function gpuDynamicVector3(value, time, seed, fallback = new THREE.Vector3()) {
|
|
39
|
+
if (value === undefined)
|
|
40
|
+
return vec3(fallback.x, fallback.y, fallback.z);
|
|
41
|
+
if (isGpuDynamicValueOption(value))
|
|
42
|
+
return gpuDynamicOption(value, time, seed);
|
|
43
|
+
if (typeof value === 'function') {
|
|
44
|
+
return sampleDynamicValue(value, time, seed, fallback, gpuDynamicVector3);
|
|
45
|
+
}
|
|
46
|
+
if (Array.isArray(value)) {
|
|
47
|
+
return mix(gpuDynamicVector3(value[0], time, seed, fallback), gpuDynamicVector3(value[1], time, seed, fallback), seed);
|
|
48
|
+
}
|
|
49
|
+
if (value instanceof Set) {
|
|
50
|
+
return selectFromSet(Array.from(value), time, seed, fallback, gpuDynamicVector3);
|
|
51
|
+
}
|
|
52
|
+
return vec3(value.x, value.y, value.z);
|
|
53
|
+
}
|
|
54
|
+
export function gpuDynamicColor(value, time, seed, fallback = new THREE.Color()) {
|
|
55
|
+
if (value === undefined)
|
|
56
|
+
return vec3(fallback.r, fallback.g, fallback.b);
|
|
57
|
+
if (isGpuDynamicValueOption(value))
|
|
58
|
+
return gpuDynamicOption(value, time, seed);
|
|
59
|
+
if (typeof value === 'function') {
|
|
60
|
+
return sampleDynamicValue(value, time, seed, fallback, gpuDynamicColor);
|
|
61
|
+
}
|
|
62
|
+
if (Array.isArray(value)) {
|
|
63
|
+
return mix(gpuDynamicColor(value[0], time, seed, fallback), gpuDynamicColor(value[1], time, seed, fallback), seed);
|
|
64
|
+
}
|
|
65
|
+
if (value instanceof Set) {
|
|
66
|
+
return selectFromSet(Array.from(value), time, seed, fallback, gpuDynamicColor);
|
|
67
|
+
}
|
|
68
|
+
return vec3(value.r, value.g, value.b);
|
|
69
|
+
}
|
|
70
|
+
function sampleDynamicValue(value, time, seed, fallback, evaluate) {
|
|
71
|
+
const samples = sampleFunction(value);
|
|
72
|
+
if (samples.length === 0)
|
|
73
|
+
return evaluate(undefined, time, seed, fallback);
|
|
74
|
+
if (samples.length === 1)
|
|
75
|
+
return evaluate(samples[0], time, seed, fallback);
|
|
76
|
+
const clampedTime = clamp(time, 0, 1);
|
|
77
|
+
let result = evaluate(samples[samples.length - 1], clampedTime, seed, fallback);
|
|
78
|
+
for (let i = samples.length - 2; i >= 0; i -= 1) {
|
|
79
|
+
const segmentStart = i / (samples.length - 1);
|
|
80
|
+
const segmentEnd = (i + 1) / (samples.length - 1);
|
|
81
|
+
const segmentT = clamp(clampedTime.sub(segmentStart).div(segmentEnd - segmentStart), 0, 1);
|
|
82
|
+
result = select(clampedTime.lessThanEqual(segmentEnd), mix(evaluate(samples[i], clampedTime, seed, fallback), evaluate(samples[i + 1], clampedTime, seed, fallback), segmentT), result);
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
function sampleFunction(value) {
|
|
87
|
+
return Array.from({ length: GPU_DYNAMIC_VALUE_SAMPLE_COUNT }, (_, index) => {
|
|
88
|
+
const time = index / (GPU_DYNAMIC_VALUE_SAMPLE_COUNT - 1);
|
|
89
|
+
return value(time);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
export function gpuDynamicValue(cpu, tsl) {
|
|
93
|
+
return { cpu, tsl };
|
|
94
|
+
}
|
|
95
|
+
function gpuDynamicOption(value, time, seed) {
|
|
96
|
+
return typeof value.tsl === 'function'
|
|
97
|
+
? value.tsl(time, seed)
|
|
98
|
+
: value.tsl;
|
|
99
|
+
}
|
|
100
|
+
export function gpuDynamicColorAlpha(color, alpha, time, seed) {
|
|
101
|
+
const rgb = gpuDynamicColor(color, time, seed, new THREE.Color(1, 1, 1));
|
|
102
|
+
const a = gpuDynamicNumber(alpha, time, seed, 1);
|
|
103
|
+
return vec4(rgb.x, rgb.y, rgb.z, a);
|
|
104
|
+
}
|
|
105
|
+
function selectFromSet(values, time, seed, fallback, evaluate) {
|
|
106
|
+
if (values.length === 0)
|
|
107
|
+
return evaluate(undefined, time, seed, fallback);
|
|
108
|
+
let result = evaluate(values[values.length - 1], time, seed, fallback);
|
|
109
|
+
for (let i = values.length - 2; i >= 0; i -= 1) {
|
|
110
|
+
result = select(seed.lessThan((i + 1) / values.length), evaluate(values[i], time, seed, fallback), result);
|
|
111
|
+
}
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { clamp, length, select, } from 'three/src/nodes/TSL.js';
|
|
2
|
+
export function gpuSpeedRangeTime(speed, speedRange) {
|
|
3
|
+
var _a, _b;
|
|
4
|
+
const min = Array.isArray(speedRange) ? speedRange[0] : (_a = speedRange === null || speedRange === void 0 ? void 0 : speedRange.min) !== null && _a !== void 0 ? _a : 0;
|
|
5
|
+
const max = Array.isArray(speedRange) ? speedRange[1] : (_b = speedRange === null || speedRange === void 0 ? void 0 : speedRange.max) !== null && _b !== void 0 ? _b : 1;
|
|
6
|
+
if (max === min)
|
|
7
|
+
return select(speed.greaterThanEqual(max), 1, 0);
|
|
8
|
+
return clamp(speed.sub(min).div(max - min), 0, 1);
|
|
9
|
+
}
|
|
10
|
+
export function gpuVectorLength(value) {
|
|
11
|
+
return length(value);
|
|
12
|
+
}
|