babylon.quarks 0.17.3 → 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.
@@ -25,16 +25,35 @@ export interface VFXBatchSettings {
25
25
  texture: Texture | null;
26
26
  layerMask: number;
27
27
  }
28
+ export interface AdaptivePerformanceOptions {
29
+ targetFrameMs: number;
30
+ minQuality: number;
31
+ maxQuality: number;
32
+ decreaseStep: number;
33
+ increaseStep: number;
34
+ }
35
+ export interface AdaptivePerformanceState extends AdaptivePerformanceOptions {
36
+ enabled: boolean;
37
+ currentQuality: number;
38
+ lastFrameCpuMs: number;
39
+ }
28
40
  export declare class BatchedRenderer extends TransformNode {
29
41
  batches: Array<VFXBatch>;
30
42
  systemToBatchIndex: Map<IParticleSystem, number>;
31
43
  depthTexture: BaseTexture | null;
44
+ private adaptivePerformanceState;
45
+ private lastAppliedQuality;
32
46
  constructor(name: string, scene: Scene);
47
+ private static clamp;
33
48
  private static equals;
34
49
  addSystem(system: IParticleSystem): void;
35
50
  deleteSystem(system: IParticleSystem): void;
36
51
  updateSystem(system: IParticleSystem): void;
37
52
  setDepthTexture(depthTexture: BaseTexture | null): void;
53
+ configureAdaptivePerformance(options?: Partial<AdaptivePerformanceOptions>): void;
54
+ disableAdaptivePerformance(resetQuality?: boolean): void;
55
+ getAdaptivePerformanceState(): AdaptivePerformanceState;
56
+ private applyAdaptiveQuality;
38
57
  update(delta: number): void;
39
58
  dispose(): void;
40
59
  }
@@ -162,6 +162,8 @@ export declare class ParticleSystem implements IParticleSystem {
162
162
  private listeners;
163
163
  private readonly layerMaskProxy;
164
164
  private materialRef;
165
+ private qualityFactor;
166
+ private useFastTrailHistory;
165
167
  /** @internal **/
166
168
  _renderer?: BatchedRenderer;
167
169
  set time(time: number);
@@ -198,6 +200,12 @@ export declare class ParticleSystem implements IParticleSystem {
198
200
  pause(): void;
199
201
  play(): void;
200
202
  stop(): void;
203
+ private refreshTrailHistoryMode;
204
+ private ensureTrailHistoryCapacity;
205
+ private resetTrailHistory;
206
+ private getTrailHistoryCount;
207
+ private updateFastTrailHistory;
208
+ setQualityFactor(qualityFactor: number): void;
201
209
  private spawn;
202
210
  endEmit(): void;
203
211
  dispose(): void;
@@ -27,6 +27,7 @@ export declare class SpriteBatch extends VFXBatch {
27
27
  private quaternion3_;
28
28
  private rotationMat_;
29
29
  private rotationMat2_;
30
+ private lastStretchedSpeedFactor;
30
31
  update(): void;
31
32
  dispose(): void;
32
33
  }
@@ -14,6 +14,7 @@ export declare class TrailBatch extends VFXBatch {
14
14
  private nextVB;
15
15
  private sideVB;
16
16
  private widthVB;
17
+ private getTrailHistoryCount;
17
18
  constructor(settings: VFXBatchSettings, scene: Scene);
18
19
  setupBuffers(): void;
19
20
  expandBuffers(target: number): void;
@@ -0,0 +1,2 @@
1
+ /** Sequential 0..N-1 indices for non-indexed triangle-list BufferGeometry (Three.js drawArrays). */
2
+ export declare function ensureTriangleIndices(positions: Float32Array, indices?: Uint32Array | Uint16Array): Uint32Array | Uint16Array;
@@ -1,2 +1,2 @@
1
- declare const _default: "\nattribute vec3 position;\nattribute vec2 uv;\nattribute vec3 normal;\nattribute vec3 offset;\nattribute vec4 color;\nattribute vec3 size;\nattribute vec4 rotation;\nattribute float uvTile;\n\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 projection;\n\n#ifdef UV_TILE\nuniform float tileCountX;\nuniform float tileCountY;\n#endif\n\nvarying vec2 vUV;\nvarying vec4 vColor;\nvarying vec3 vNormal;\nvarying vec3 vWorldPos;\n\n#ifdef SOFT_PARTICLES\nvarying vec4 projPosition;\nvarying float linearDepth;\n#endif\n\nvec3 applyQuaternion(vec3 v, vec4 q) {\n vec3 qVec = q.xyz;\n float qW = q.w;\n vec3 t = 2.0 * cross(qVec, v);\n return v + qW * t + cross(qVec, t);\n}\n\nvoid main() {\n vec3 scaledPosition = position * size;\n vec3 rotatedPosition = applyQuaternion(scaledPosition, rotation);\n vec3 rotatedNormal = normalize(applyQuaternion(normal, rotation));\n vec3 localPos = rotatedPosition + offset;\n\n vec4 worldPos = world * vec4(localPos, 1.0);\n vec4 viewPos = view * worldPos;\n gl_Position = projection * viewPos;\n\n vWorldPos = worldPos.xyz;\n vNormal = normalize((world * vec4(rotatedNormal, 0.0)).xyz);\n\n#ifdef SOFT_PARTICLES\n projPosition = gl_Position;\n linearDepth = -viewPos.z;\n#endif\n\n#ifdef UV_TILE\n vec2 tc = vec2(tileCountX, tileCountY);\n float tileU = mod(uvTile, tc.x) / tc.x;\n float tileV = 1.0 - floor(uvTile / tc.x) / tc.y - 1.0 / tc.y;\n vUV = uv / tc + vec2(tileU, tileV);\n#else\n vUV = uv;\n#endif\n\n vColor = color;\n}\n";
1
+ declare const _default: "\nattribute vec3 position;\nattribute vec2 uv;\nattribute vec3 normal;\nattribute vec3 offset;\nattribute vec4 color;\nattribute vec3 size;\nattribute vec4 rotation;\nattribute float uvTile;\n\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 projection;\n\n#ifdef UV_TILE\nuniform float tileCountX;\nuniform float tileCountY;\n#endif\n\nvarying vec2 vUV;\nvarying vec4 vColor;\nvarying vec3 vNormal;\nvarying vec3 vWorldPos;\n\n#ifdef TILE_BLEND\nvarying vec2 vUV2;\nvarying float vTileBlend;\n#endif\n\n#ifdef SOFT_PARTICLES\nvarying vec4 projPosition;\nvarying float linearDepth;\n#endif\n\nvec3 applyQuaternion(vec3 v, vec4 q) {\n vec3 qVec = q.xyz;\n float qW = q.w;\n vec3 t = 2.0 * cross(qVec, v);\n return v + qW * t + cross(qVec, t);\n}\n\nvoid main() {\n vec3 scaledPosition = position * size;\n vec3 rotatedPosition = applyQuaternion(scaledPosition, rotation);\n vec3 rotatedNormal = normalize(applyQuaternion(normal, rotation));\n vec3 localPos = rotatedPosition + offset;\n\n vec4 worldPos = world * vec4(localPos, 1.0);\n vec4 viewPos = view * worldPos;\n gl_Position = projection * viewPos;\n\n vWorldPos = worldPos.xyz;\n vNormal = normalize((world * vec4(rotatedNormal, 0.0)).xyz);\n\n#ifdef SOFT_PARTICLES\n projPosition = gl_Position;\n linearDepth = -viewPos.z;\n#endif\n\n#ifdef UV_TILE\n vec2 tc = vec2(tileCountX, tileCountY);\n float baseTile = floor(uvTile);\n float tileU = mod(baseTile, tc.x) / tc.x;\n float tileV = 1.0 - floor(baseTile / tc.x) / tc.y - 1.0 / tc.y;\n vUV = uv / tc + vec2(tileU, tileV);\n #ifdef TILE_BLEND\n float nextTile = ceil(uvTile);\n float nextU = mod(nextTile, tc.x) / tc.x;\n float nextV = 1.0 - floor(nextTile / tc.x) / tc.y - 1.0 / tc.y;\n vUV2 = uv / tc + vec2(nextU, nextV);\n vTileBlend = fract(uvTile);\n #endif\n#else\n vUV = uv;\n#endif\n\n vColor = color;\n}\n";
2
2
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babylon.quarks",
3
- "version": "0.17.3",
3
+ "version": "0.17.4",
4
4
  "description": "A High-Performance Particle System for Babylon.js",
5
5
  "type": "module",
6
6
  "types": "./dist/types/index.d.ts",
@@ -41,6 +41,7 @@ import {
41
41
  import {ParticleEmitter} from './ParticleEmitter';
42
42
  import {RenderMode} from './VFXBatch';
43
43
  import {BatchedRenderer, VFXBatchSettings} from './BatchedRenderer';
44
+ import {ensureTriangleIndices} from './geometryUtil';
44
45
 
45
46
  export interface BurstParameters {
46
47
  time: number;
@@ -1142,13 +1143,18 @@ export class ParticleSystem implements IParticleSystem {
1142
1143
  uvs?: Float32Array;
1143
1144
  normals?: Float32Array;
1144
1145
  } {
1145
- if (entry?.positions && entry?.indices) {
1146
+ if (entry?.positions) {
1147
+ const positions =
1148
+ entry.positions instanceof Float32Array ? entry.positions : new Float32Array(entry.positions);
1149
+ const rawIndices =
1150
+ entry.indices instanceof Uint16Array || entry.indices instanceof Uint32Array
1151
+ ? entry.indices
1152
+ : entry.indices
1153
+ ? new Uint32Array(entry.indices)
1154
+ : undefined;
1146
1155
  return {
1147
- positions: entry.positions instanceof Float32Array ? entry.positions : new Float32Array(entry.positions),
1148
- indices:
1149
- entry.indices instanceof Uint16Array || entry.indices instanceof Uint32Array
1150
- ? entry.indices
1151
- : new Uint32Array(entry.indices),
1156
+ positions,
1157
+ indices: ensureTriangleIndices(positions, rawIndices),
1152
1158
  uvs: entry.uvs
1153
1159
  ? entry.uvs instanceof Float32Array
1154
1160
  ? entry.uvs
@@ -1163,11 +1169,16 @@ export class ParticleSystem implements IParticleSystem {
1163
1169
  }
1164
1170
 
1165
1171
  const data = entry?.data ?? entry;
1166
- if (data?.attributes?.position?.array && data?.index?.array) {
1167
- const indexType = data.index.type === 'Uint16Array' ? Uint16Array : Uint32Array;
1172
+ if (data?.attributes?.position?.array) {
1173
+ const positions = new Float32Array(data.attributes.position.array);
1174
+ let indices: Uint32Array | Uint16Array | undefined;
1175
+ if (data.index?.array) {
1176
+ const indexType = data.index.type === 'Uint16Array' ? Uint16Array : Uint32Array;
1177
+ indices = new indexType(data.index.array);
1178
+ }
1168
1179
  return {
1169
- positions: new Float32Array(data.attributes.position.array),
1170
- indices: new indexType(data.index.array),
1180
+ positions,
1181
+ indices: ensureTriangleIndices(positions, indices),
1171
1182
  uvs: data.attributes.uv?.array ? new Float32Array(data.attributes.uv.array) : undefined,
1172
1183
  normals: data.attributes.normal?.array ? new Float32Array(data.attributes.normal.array) : undefined,
1173
1184
  };
@@ -13,6 +13,7 @@ import {
13
13
  import {ParticleSystem} from './ParticleSystem';
14
14
  import {ParticleEmitter} from './ParticleEmitter';
15
15
  import {QuarksPrefab} from './QuarksPrefab';
16
+ import {ensureTriangleIndices} from './geometryUtil';
16
17
 
17
18
  export interface QuarksLoaderOptions {
18
19
  baseUrl?: string;
@@ -219,6 +220,8 @@ export class QuarksLoader {
219
220
  }
220
221
  }
221
222
 
223
+ indices = ensureTriangleIndices(positions, indices);
224
+
222
225
  return {positions, indices, uvs, normals};
223
226
  }
224
227
 
@@ -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
+ }