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.
- 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 +1 -1
- package/src/ParticleSystem.ts +21 -10
- package/src/QuarksLoader.ts +3 -0
- package/src/geometryUtil.ts +15 -0
|
@@ -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;
|
|
@@ -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;
|
|
@@ -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(
|
|
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
package/src/ParticleSystem.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
1167
|
-
const
|
|
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
|
|
1170
|
-
indices:
|
|
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
|
};
|
package/src/QuarksLoader.ts
CHANGED
|
@@ -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
|
+
}
|