babylon.quarks 0.17.2 → 0.17.4
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/dist/babylon.quarks.cjs +1 -1
- package/dist/babylon.quarks.cjs.map +1 -1
- package/dist/babylon.quarks.esm.js +1 -1
- package/dist/babylon.quarks.esm.js.map +1 -1
- package/dist/types/BatchedRenderer.d.ts +19 -0
- package/dist/types/ParticleSystem.d.ts +8 -0
- package/dist/types/SpriteBatch.d.ts +1 -0
- package/dist/types/TrailBatch.d.ts +1 -0
- package/dist/types/geometryUtil.d.ts +2 -0
- package/dist/types/shaders/local_particle_physics_vert.glsl.d.ts +1 -1
- package/package.json +2 -1
- package/src/BatchedRenderer.ts +94 -2
- package/src/ParticleSystem.ts +182 -59
- package/src/QuarksLoader.ts +3 -0
- package/src/SpriteBatch.ts +25 -12
- package/src/TrailBatch.ts +167 -93
- package/src/VFXBatch.ts +7 -1
- package/src/geometryUtil.ts +15 -0
- package/src/index.ts +0 -2
package/src/SpriteBatch.ts
CHANGED
|
@@ -111,6 +111,7 @@ export class SpriteBatch extends VFXBatch {
|
|
|
111
111
|
|
|
112
112
|
rebuildMaterial(): void {
|
|
113
113
|
const shaderName = `quarksParticle_${this.settings.renderMode}_${Date.now()}`;
|
|
114
|
+
this.lastStretchedSpeedFactor = Number.NaN;
|
|
114
115
|
let vertexShader: string;
|
|
115
116
|
let fragmentShader: string;
|
|
116
117
|
const defines: string[] = [];
|
|
@@ -247,10 +248,14 @@ export class SpriteBatch extends VFXBatch {
|
|
|
247
248
|
private quaternion3_ = new Quaternion();
|
|
248
249
|
private rotationMat_ = new Matrix3();
|
|
249
250
|
private rotationMat2_ = new Matrix3();
|
|
251
|
+
private lastStretchedSpeedFactor = Number.NaN;
|
|
250
252
|
|
|
251
253
|
update(): void {
|
|
252
254
|
let index = 0;
|
|
253
255
|
let particleCount = 0;
|
|
256
|
+
const renderMode = this.settings.renderMode;
|
|
257
|
+
const isMeshRender = renderMode === RenderMode.Mesh;
|
|
258
|
+
const isStretchedRender = renderMode === RenderMode.StretchedBillBoard;
|
|
254
259
|
|
|
255
260
|
const visibleSystems = this.getVisibleSystems();
|
|
256
261
|
for (const system of visibleSystems) {
|
|
@@ -266,15 +271,19 @@ export class SpriteBatch extends VFXBatch {
|
|
|
266
271
|
const rotation = this.quaternion2_;
|
|
267
272
|
const translation = this.vector2_;
|
|
268
273
|
const scale = this.vector3_;
|
|
274
|
+
const systemWorldSpace = system.worldSpace;
|
|
269
275
|
system.emitter.matrixWorld.decompose(translation, rotation, scale);
|
|
270
276
|
this.rotationMat_.setFromMatrix4(system.emitter.matrixWorld);
|
|
277
|
+
const absScaleX = Math.abs(scale.x);
|
|
278
|
+
const absScaleY = Math.abs(scale.y);
|
|
279
|
+
const absScaleZ = Math.abs(scale.z);
|
|
271
280
|
|
|
272
281
|
for (let j = 0; j < particleNum; j++, index++) {
|
|
273
282
|
const particle = particles[j] as SpriteParticle;
|
|
274
283
|
|
|
275
|
-
if (
|
|
284
|
+
if (isMeshRender) {
|
|
276
285
|
let q: Quaternion;
|
|
277
|
-
if (
|
|
286
|
+
if (systemWorldSpace) {
|
|
278
287
|
q = particle.rotation as Quaternion;
|
|
279
288
|
} else {
|
|
280
289
|
let parentQ: Quaternion;
|
|
@@ -296,7 +305,7 @@ export class SpriteBatch extends VFXBatch {
|
|
|
296
305
|
}
|
|
297
306
|
|
|
298
307
|
let vec: Vector3;
|
|
299
|
-
if (
|
|
308
|
+
if (systemWorldSpace) {
|
|
300
309
|
vec = particle.position;
|
|
301
310
|
} else {
|
|
302
311
|
vec = this.vector_;
|
|
@@ -319,7 +328,7 @@ export class SpriteBatch extends VFXBatch {
|
|
|
319
328
|
this.colorBuffer[ci + 3] = particle.color.w;
|
|
320
329
|
|
|
321
330
|
const si = index * 3;
|
|
322
|
-
if (
|
|
331
|
+
if (systemWorldSpace) {
|
|
323
332
|
this.sizeBuffer[si] = particle.size.x;
|
|
324
333
|
this.sizeBuffer[si + 1] = particle.size.y;
|
|
325
334
|
this.sizeBuffer[si + 2] = particle.size.z;
|
|
@@ -329,20 +338,20 @@ export class SpriteBatch extends VFXBatch {
|
|
|
329
338
|
this.sizeBuffer[si + 1] = particle.size.y;
|
|
330
339
|
this.sizeBuffer[si + 2] = particle.size.z;
|
|
331
340
|
} else {
|
|
332
|
-
this.sizeBuffer[si] = particle.size.x *
|
|
333
|
-
this.sizeBuffer[si + 1] = particle.size.y *
|
|
334
|
-
this.sizeBuffer[si + 2] = particle.size.z *
|
|
341
|
+
this.sizeBuffer[si] = particle.size.x * absScaleX;
|
|
342
|
+
this.sizeBuffer[si + 1] = particle.size.y * absScaleY;
|
|
343
|
+
this.sizeBuffer[si + 2] = particle.size.z * absScaleZ;
|
|
335
344
|
}
|
|
336
345
|
}
|
|
337
346
|
|
|
338
347
|
this.uvTileBuffer[index] = particle.uvTile;
|
|
339
348
|
|
|
340
|
-
if (
|
|
349
|
+
if (isStretchedRender && this.velocityBuffer) {
|
|
341
350
|
let speedFactor = (system.rendererEmitterSettings as StretchedBillBoardSettings).speedFactor;
|
|
342
351
|
if (speedFactor === 0) speedFactor = 0.001;
|
|
343
352
|
const lengthFactor = (system.rendererEmitterSettings as StretchedBillBoardSettings).lengthFactor;
|
|
344
353
|
let vel: Vector3;
|
|
345
|
-
if (
|
|
354
|
+
if (systemWorldSpace) {
|
|
346
355
|
vel = particle.velocity;
|
|
347
356
|
} else {
|
|
348
357
|
vel = this.vector_;
|
|
@@ -362,9 +371,13 @@ export class SpriteBatch extends VFXBatch {
|
|
|
362
371
|
}
|
|
363
372
|
}
|
|
364
373
|
|
|
365
|
-
if (
|
|
374
|
+
if (isStretchedRender && this.mesh.material instanceof ShaderMaterial && visibleSystems.length > 0) {
|
|
366
375
|
const speedFactor = (visibleSystems[0].rendererEmitterSettings as StretchedBillBoardSettings).speedFactor ?? 1.0;
|
|
367
|
-
|
|
376
|
+
const clampedSpeedFactor = speedFactor === 0 ? 0.001 : speedFactor;
|
|
377
|
+
if (clampedSpeedFactor !== this.lastStretchedSpeedFactor) {
|
|
378
|
+
this.mesh.material.setFloat('speedFactor', clampedSpeedFactor);
|
|
379
|
+
this.lastStretchedSpeedFactor = clampedSpeedFactor;
|
|
380
|
+
}
|
|
368
381
|
}
|
|
369
382
|
|
|
370
383
|
this.mesh.forcedInstanceCount = index;
|
|
@@ -376,7 +389,7 @@ export class SpriteBatch extends VFXBatch {
|
|
|
376
389
|
this.colorVB.update(this.colorBuffer);
|
|
377
390
|
this.uvTileVB.update(this.uvTileBuffer);
|
|
378
391
|
this.rotationVB.update(this.rotationBuffer);
|
|
379
|
-
if (
|
|
392
|
+
if (isStretchedRender && this.velocityVB && this.velocityBuffer) {
|
|
380
393
|
this.velocityVB.update(this.velocityBuffer);
|
|
381
394
|
}
|
|
382
395
|
}
|
package/src/TrailBatch.ts
CHANGED
|
@@ -27,6 +27,15 @@ export class TrailBatch extends VFXBatch {
|
|
|
27
27
|
private sideVB!: VertexBuffer;
|
|
28
28
|
private widthVB!: VertexBuffer;
|
|
29
29
|
|
|
30
|
+
private getTrailHistoryCount(particle: TrailParticle): number {
|
|
31
|
+
const trailAny = particle as any;
|
|
32
|
+
const fastHistoryCount = trailAny._trailHistoryCount;
|
|
33
|
+
if (typeof fastHistoryCount === 'number') {
|
|
34
|
+
return fastHistoryCount;
|
|
35
|
+
}
|
|
36
|
+
return particle.previous.length;
|
|
37
|
+
}
|
|
38
|
+
|
|
30
39
|
constructor(settings: VFXBatchSettings, scene: Scene) {
|
|
31
40
|
super(settings, scene);
|
|
32
41
|
this.maxParticles = 10000;
|
|
@@ -61,7 +70,7 @@ export class TrailBatch extends VFXBatch {
|
|
|
61
70
|
this.mesh.setVerticesData(VertexBuffer.PositionKind, this.positionBuffer, true);
|
|
62
71
|
this.mesh.setVerticesData(VertexBuffer.UVKind, this.uvBuffer, true);
|
|
63
72
|
this.mesh.setVerticesData(VertexBuffer.ColorKind, this.colorBuffer, true, 4);
|
|
64
|
-
this.mesh.setIndices(
|
|
73
|
+
this.mesh.setIndices(this.indexBuffer.subarray(0, 6), null, true);
|
|
65
74
|
const engine = this.scene.getEngine();
|
|
66
75
|
this.previousVB = new VertexBuffer(engine, this.previousBuffer, 'previous', true, false, 3, false);
|
|
67
76
|
this.nextVB = new VertexBuffer(engine, this.nextBuffer, 'next', true, false, 3, false);
|
|
@@ -162,7 +171,7 @@ export class TrailBatch extends VFXBatch {
|
|
|
162
171
|
const visibleSystems = this.getVisibleSystems();
|
|
163
172
|
for (const system of visibleSystems) {
|
|
164
173
|
for (let j = 0; j < system.particleNum; j++) {
|
|
165
|
-
particleCount += (system.particles[j] as TrailParticle)
|
|
174
|
+
particleCount += this.getTrailHistoryCount(system.particles[j] as TrailParticle) * 2;
|
|
166
175
|
}
|
|
167
176
|
}
|
|
168
177
|
if (particleCount > this.maxParticles) {
|
|
@@ -185,109 +194,177 @@ export class TrailBatch extends VFXBatch {
|
|
|
185
194
|
const vTileCount = this.settings.vTileCount;
|
|
186
195
|
const tileWidth = 1 / uTileCount;
|
|
187
196
|
const tileHeight = 1 / vTileCount;
|
|
197
|
+
const systemWorldSpace = system.worldSpace;
|
|
198
|
+
const objectScale = (Math.abs(scale.x) + Math.abs(scale.y) + Math.abs(scale.z)) / 3;
|
|
188
199
|
|
|
189
200
|
for (let j = 0; j < particleNum; j++) {
|
|
190
201
|
const particle = particles[j] as TrailParticle;
|
|
202
|
+
const particleAny = particle as any;
|
|
203
|
+
const fastHistoryCount = particleAny._trailHistoryCount as number | undefined;
|
|
204
|
+
const fastHistoryCapacity = particleAny._trailHistoryCapacity as number | undefined;
|
|
205
|
+
const fastHistoryHead = particleAny._trailHistoryHead as number | undefined;
|
|
206
|
+
const fastHistoryPositions = particleAny._trailHistoryPositions as Float32Array | undefined;
|
|
207
|
+
const fastHistorySizes = particleAny._trailHistorySizes as Float32Array | undefined;
|
|
208
|
+
const fastHistoryColors = particleAny._trailHistoryColors as Float32Array | undefined;
|
|
209
|
+
const hasFastHistory =
|
|
210
|
+
typeof fastHistoryCount === 'number' &&
|
|
211
|
+
fastHistoryCount > 0 &&
|
|
212
|
+
typeof fastHistoryCapacity === 'number' &&
|
|
213
|
+
typeof fastHistoryHead === 'number' &&
|
|
214
|
+
fastHistoryPositions instanceof Float32Array &&
|
|
215
|
+
fastHistorySizes instanceof Float32Array &&
|
|
216
|
+
fastHistoryColors instanceof Float32Array;
|
|
217
|
+
const historyCapacity = hasFastHistory ? (fastHistoryCapacity as number) : 0;
|
|
218
|
+
const historyHead = hasFastHistory ? (fastHistoryHead as number) : 0;
|
|
219
|
+
const historyPositions = fastHistoryPositions as Float32Array;
|
|
220
|
+
const historySizes = fastHistorySizes as Float32Array;
|
|
221
|
+
const historyColors = fastHistoryColors as Float32Array;
|
|
222
|
+
const particleHistory = particle.previous;
|
|
223
|
+
const particleHistoryLength = hasFastHistory ? fastHistoryCount : particleHistory.length;
|
|
224
|
+
if (particleHistoryLength === 0) {
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
191
227
|
const col = particle.uvTile % vTileCount;
|
|
192
228
|
const row = Math.floor(particle.uvTile / vTileCount + 0.001);
|
|
193
|
-
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
let
|
|
197
|
-
let
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
let
|
|
208
|
-
|
|
209
|
-
|
|
229
|
+
const particleMatrix = particle.parentMatrix as unknown as Matrix4 | undefined;
|
|
230
|
+
const matrixToUse = particleMatrix ?? system.emitter.matrixWorld;
|
|
231
|
+
|
|
232
|
+
let previousNode = particleHistory.head;
|
|
233
|
+
let currentNode = previousNode;
|
|
234
|
+
let nextNode = currentNode?.next ?? currentNode;
|
|
235
|
+
const oldestFastHistoryIndex = hasFastHistory
|
|
236
|
+
? (historyHead - particleHistoryLength + historyCapacity) % historyCapacity
|
|
237
|
+
: 0;
|
|
238
|
+
|
|
239
|
+
for (let i = 0; i < particleHistoryLength; i++, index += 2) {
|
|
240
|
+
let currentX: number;
|
|
241
|
+
let currentY: number;
|
|
242
|
+
let currentZ: number;
|
|
243
|
+
let currentSize: number;
|
|
244
|
+
let currentColorX: number;
|
|
245
|
+
let currentColorY: number;
|
|
246
|
+
let currentColorZ: number;
|
|
247
|
+
let currentColorW: number;
|
|
248
|
+
let previousX: number;
|
|
249
|
+
let previousY: number;
|
|
250
|
+
let previousZ: number;
|
|
251
|
+
let nextX: number;
|
|
252
|
+
let nextY: number;
|
|
253
|
+
let nextZ: number;
|
|
254
|
+
|
|
255
|
+
if (hasFastHistory) {
|
|
256
|
+
const currentHistoryIndex = (oldestFastHistoryIndex + i) % historyCapacity;
|
|
257
|
+
const previousHistoryIndex = i === 0 ? currentHistoryIndex : (oldestFastHistoryIndex + i - 1) % historyCapacity;
|
|
258
|
+
const nextHistoryIndex =
|
|
259
|
+
i + 1 < particleHistoryLength
|
|
260
|
+
? (oldestFastHistoryIndex + i + 1) % historyCapacity
|
|
261
|
+
: currentHistoryIndex;
|
|
262
|
+
|
|
263
|
+
const currentPosIndex = currentHistoryIndex * 3;
|
|
264
|
+
const previousPosIndex = previousHistoryIndex * 3;
|
|
265
|
+
const nextPosIndex = nextHistoryIndex * 3;
|
|
266
|
+
|
|
267
|
+
currentX = historyPositions[currentPosIndex];
|
|
268
|
+
currentY = historyPositions[currentPosIndex + 1];
|
|
269
|
+
currentZ = historyPositions[currentPosIndex + 2];
|
|
270
|
+
previousX = historyPositions[previousPosIndex];
|
|
271
|
+
previousY = historyPositions[previousPosIndex + 1];
|
|
272
|
+
previousZ = historyPositions[previousPosIndex + 2];
|
|
273
|
+
nextX = historyPositions[nextPosIndex];
|
|
274
|
+
nextY = historyPositions[nextPosIndex + 1];
|
|
275
|
+
nextZ = historyPositions[nextPosIndex + 2];
|
|
276
|
+
|
|
277
|
+
currentSize = historySizes[currentHistoryIndex];
|
|
278
|
+
const currentColorIndex = currentHistoryIndex * 4;
|
|
279
|
+
currentColorX = historyColors[currentColorIndex];
|
|
280
|
+
currentColorY = historyColors[currentColorIndex + 1];
|
|
281
|
+
currentColorZ = historyColors[currentColorIndex + 2];
|
|
282
|
+
currentColorW = historyColors[currentColorIndex + 3];
|
|
210
283
|
} else {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
284
|
+
const previous = previousNode!.data as RecordState;
|
|
285
|
+
const current = currentNode!.data as RecordState;
|
|
286
|
+
const next = nextNode!.data as RecordState;
|
|
287
|
+
currentX = current.position.x;
|
|
288
|
+
currentY = current.position.y;
|
|
289
|
+
currentZ = current.position.z;
|
|
290
|
+
previousX = previous.position.x;
|
|
291
|
+
previousY = previous.position.y;
|
|
292
|
+
previousZ = previous.position.z;
|
|
293
|
+
nextX = next.position.x;
|
|
294
|
+
nextY = next.position.y;
|
|
295
|
+
nextZ = next.position.z;
|
|
296
|
+
currentSize = current.size;
|
|
297
|
+
currentColorX = current.color.x;
|
|
298
|
+
currentColorY = current.color.y;
|
|
299
|
+
currentColorZ = current.color.z;
|
|
300
|
+
currentColorW = current.color.w;
|
|
217
301
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
} else {
|
|
233
|
-
this.vector_.copy(previous.position).applyMatrix4(system.emitter.matrixWorld);
|
|
234
|
-
}
|
|
235
|
-
prevPos = this.vector_;
|
|
236
|
-
}
|
|
237
|
-
this.previousBuffer[pi] = prevPos.x;
|
|
238
|
-
this.previousBuffer[pi + 1] = prevPos.y;
|
|
239
|
-
this.previousBuffer[pi + 2] = prevPos.z;
|
|
240
|
-
this.previousBuffer[pi + 3] = prevPos.x;
|
|
241
|
-
this.previousBuffer[pi + 4] = prevPos.y;
|
|
242
|
-
this.previousBuffer[pi + 5] = prevPos.z;
|
|
243
|
-
|
|
244
|
-
let nextPos: Vector3;
|
|
245
|
-
if (system.worldSpace) {
|
|
246
|
-
nextPos = next.position;
|
|
247
|
-
} else {
|
|
248
|
-
if (particle.parentMatrix) {
|
|
249
|
-
this.vector_.copy(next.position).applyMatrix4(particle.parentMatrix as unknown as Matrix4);
|
|
250
|
-
} else {
|
|
251
|
-
this.vector_.copy(next.position).applyMatrix4(system.emitter.matrixWorld);
|
|
252
|
-
}
|
|
253
|
-
nextPos = this.vector_;
|
|
302
|
+
|
|
303
|
+
if (!systemWorldSpace) {
|
|
304
|
+
this.vector_.set(currentX, currentY, currentZ).applyMatrix4(matrixToUse);
|
|
305
|
+
currentX = this.vector_.x;
|
|
306
|
+
currentY = this.vector_.y;
|
|
307
|
+
currentZ = this.vector_.z;
|
|
308
|
+
this.vector_.set(previousX, previousY, previousZ).applyMatrix4(matrixToUse);
|
|
309
|
+
previousX = this.vector_.x;
|
|
310
|
+
previousY = this.vector_.y;
|
|
311
|
+
previousZ = this.vector_.z;
|
|
312
|
+
this.vector_.set(nextX, nextY, nextZ).applyMatrix4(matrixToUse);
|
|
313
|
+
nextX = this.vector_.x;
|
|
314
|
+
nextY = this.vector_.y;
|
|
315
|
+
nextZ = this.vector_.z;
|
|
254
316
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
this.
|
|
258
|
-
this.
|
|
259
|
-
this.
|
|
260
|
-
this.
|
|
317
|
+
|
|
318
|
+
const pi = index * 3;
|
|
319
|
+
this.positionBuffer[pi] = currentX;
|
|
320
|
+
this.positionBuffer[pi + 1] = currentY;
|
|
321
|
+
this.positionBuffer[pi + 2] = currentZ;
|
|
322
|
+
this.positionBuffer[pi + 3] = currentX;
|
|
323
|
+
this.positionBuffer[pi + 4] = currentY;
|
|
324
|
+
this.positionBuffer[pi + 5] = currentZ;
|
|
325
|
+
|
|
326
|
+
this.previousBuffer[pi] = previousX;
|
|
327
|
+
this.previousBuffer[pi + 1] = previousY;
|
|
328
|
+
this.previousBuffer[pi + 2] = previousZ;
|
|
329
|
+
this.previousBuffer[pi + 3] = previousX;
|
|
330
|
+
this.previousBuffer[pi + 4] = previousY;
|
|
331
|
+
this.previousBuffer[pi + 5] = previousZ;
|
|
332
|
+
|
|
333
|
+
this.nextBuffer[pi] = nextX;
|
|
334
|
+
this.nextBuffer[pi + 1] = nextY;
|
|
335
|
+
this.nextBuffer[pi + 2] = nextZ;
|
|
336
|
+
this.nextBuffer[pi + 3] = nextX;
|
|
337
|
+
this.nextBuffer[pi + 4] = nextY;
|
|
338
|
+
this.nextBuffer[pi + 5] = nextZ;
|
|
261
339
|
|
|
262
340
|
this.sideBuffer[index] = 1;
|
|
263
341
|
this.sideBuffer[index + 1] = -1;
|
|
264
342
|
|
|
265
|
-
if (
|
|
266
|
-
this.widthBuffer[index] =
|
|
267
|
-
this.widthBuffer[index + 1] =
|
|
343
|
+
if (systemWorldSpace || particle.parentMatrix) {
|
|
344
|
+
this.widthBuffer[index] = currentSize;
|
|
345
|
+
this.widthBuffer[index + 1] = currentSize;
|
|
268
346
|
} else {
|
|
269
|
-
|
|
270
|
-
this.widthBuffer[index] =
|
|
271
|
-
this.widthBuffer[index + 1] = current.size * objectScale;
|
|
347
|
+
this.widthBuffer[index] = currentSize * objectScale;
|
|
348
|
+
this.widthBuffer[index + 1] = currentSize * objectScale;
|
|
272
349
|
}
|
|
273
350
|
|
|
274
351
|
const ui = index * 2;
|
|
275
|
-
this.uvBuffer[ui] = (i /
|
|
352
|
+
this.uvBuffer[ui] = (i / particleHistoryLength + col) * tileWidth;
|
|
276
353
|
this.uvBuffer[ui + 1] = (vTileCount - row - 1) * tileHeight;
|
|
277
|
-
this.uvBuffer[ui + 2] = (i /
|
|
354
|
+
this.uvBuffer[ui + 2] = (i / particleHistoryLength + col) * tileWidth;
|
|
278
355
|
this.uvBuffer[ui + 3] = (vTileCount - row) * tileHeight;
|
|
279
356
|
|
|
280
357
|
const cci = index * 4;
|
|
281
|
-
this.colorBuffer[cci] =
|
|
282
|
-
this.colorBuffer[cci + 1] =
|
|
283
|
-
this.colorBuffer[cci + 2] =
|
|
284
|
-
this.colorBuffer[cci + 3] =
|
|
285
|
-
this.colorBuffer[cci + 4] =
|
|
286
|
-
this.colorBuffer[cci + 5] =
|
|
287
|
-
this.colorBuffer[cci + 6] =
|
|
288
|
-
this.colorBuffer[cci + 7] =
|
|
289
|
-
|
|
290
|
-
if (i + 1 <
|
|
358
|
+
this.colorBuffer[cci] = currentColorX;
|
|
359
|
+
this.colorBuffer[cci + 1] = currentColorY;
|
|
360
|
+
this.colorBuffer[cci + 2] = currentColorZ;
|
|
361
|
+
this.colorBuffer[cci + 3] = currentColorW;
|
|
362
|
+
this.colorBuffer[cci + 4] = currentColorX;
|
|
363
|
+
this.colorBuffer[cci + 5] = currentColorY;
|
|
364
|
+
this.colorBuffer[cci + 6] = currentColorZ;
|
|
365
|
+
this.colorBuffer[cci + 7] = currentColorW;
|
|
366
|
+
|
|
367
|
+
if (i + 1 < particleHistoryLength) {
|
|
291
368
|
this.indexBuffer[triangles * 3] = index;
|
|
292
369
|
this.indexBuffer[triangles * 3 + 1] = index + 1;
|
|
293
370
|
this.indexBuffer[triangles * 3 + 2] = index + 2;
|
|
@@ -298,13 +375,10 @@ export class TrailBatch extends VFXBatch {
|
|
|
298
375
|
triangles++;
|
|
299
376
|
}
|
|
300
377
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
if (curIter.value !== undefined) {
|
|
306
|
-
next = curIter.value as RecordState;
|
|
307
|
-
}
|
|
378
|
+
if (!hasFastHistory) {
|
|
379
|
+
previousNode = currentNode;
|
|
380
|
+
currentNode = nextNode;
|
|
381
|
+
nextNode = nextNode?.next ?? nextNode;
|
|
308
382
|
}
|
|
309
383
|
}
|
|
310
384
|
}
|
|
@@ -313,7 +387,7 @@ export class TrailBatch extends VFXBatch {
|
|
|
313
387
|
if (index > 0 && triangles > 0) {
|
|
314
388
|
this.mesh.updateVerticesData(VertexBuffer.PositionKind, this.positionBuffer);
|
|
315
389
|
this.mesh.updateVerticesData(VertexBuffer.UVKind, this.uvBuffer);
|
|
316
|
-
this.mesh.updateIndices(
|
|
390
|
+
this.mesh.updateIndices(this.indexBuffer.subarray(0, triangles * 3));
|
|
317
391
|
this.previousVB.update(this.previousBuffer);
|
|
318
392
|
this.nextVB.update(this.nextBuffer);
|
|
319
393
|
this.sideVB.update(this.sideBuffer);
|
package/src/VFXBatch.ts
CHANGED
|
@@ -81,7 +81,13 @@ export abstract class VFXBatch {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
getVisibleSystems(): IParticleSystem[] {
|
|
84
|
-
|
|
84
|
+
const visibleSystems: IParticleSystem[] = [];
|
|
85
|
+
for (const system of this.systems) {
|
|
86
|
+
if (system.emitter.visible) {
|
|
87
|
+
visibleSystems.push(system);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return visibleSystems;
|
|
85
91
|
}
|
|
86
92
|
|
|
87
93
|
applyDepthTexture(depthTexture: BaseTexture | null): void {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Sequential 0..N-1 indices for non-indexed triangle-list BufferGeometry (Three.js drawArrays). */
|
|
2
|
+
export function ensureTriangleIndices(
|
|
3
|
+
positions: Float32Array,
|
|
4
|
+
indices?: Uint32Array | Uint16Array
|
|
5
|
+
): Uint32Array | Uint16Array {
|
|
6
|
+
if (indices && indices.length > 0) {
|
|
7
|
+
return indices;
|
|
8
|
+
}
|
|
9
|
+
const vertexCount = positions.length / 3;
|
|
10
|
+
const out = new Uint32Array(vertexCount);
|
|
11
|
+
for (let i = 0; i < vertexCount; i++) {
|
|
12
|
+
out[i] = i;
|
|
13
|
+
}
|
|
14
|
+
return out;
|
|
15
|
+
}
|
package/src/index.ts
CHANGED