babylon.quarks 0.20.0 → 0.23.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babylon.quarks",
3
- "version": "0.20.0",
3
+ "version": "0.23.0",
4
4
  "description": "A High-Performance Particle System for Babylon.js",
5
5
  "type": "module",
6
6
  "types": "./dist/types/index.d.ts",
@@ -6,7 +6,16 @@ import {EmitSubParticleSystem, IParticleSystem, Vector3} from 'quarks.core';
6
6
  import {ParticleSystem} from './ParticleSystem';
7
7
  import {SpriteBatch} from './SpriteBatch';
8
8
  import {TrailBatch} from './TrailBatch';
9
- import {RenderMode, StoredBatchSettings, VFXBatch} from './VFXBatch';
9
+ import {
10
+ defaultMeshLighting,
11
+ MeshLighting,
12
+ MeshLightingSettings,
13
+ MeshRim,
14
+ meshRimEqual,
15
+ RenderMode,
16
+ StoredBatchSettings,
17
+ VFXBatch,
18
+ } from './VFXBatch';
10
19
 
11
20
  export interface VFXBatchSettings {
12
21
  instancingGeometry: Float32Array;
@@ -55,6 +64,13 @@ export interface VFXBatchSettings {
55
64
  * y across, and z is unused. Absent or zero: no offset. Meshes ignore it.
56
65
  */
57
66
  pivot?: Vector3;
67
+ /**
68
+ * How mesh particles are lit (`'unlit'`, `'fixed'` or `'scene'`); unset is
69
+ * `'fixed'`. See {@link MeshLighting}. Other render modes ignore it.
70
+ */
71
+ lighting?: MeshLighting;
72
+ /** Rim (Fresnel) term on mesh particles; unset draws none. See {@link MeshRim}. */
73
+ rim?: MeshRim;
58
74
  }
59
75
 
60
76
  export interface AdaptivePerformanceOptions {
@@ -130,6 +146,7 @@ export class BatchedRenderer extends TransformNode {
130
146
  lastFrameCpuMs: 0,
131
147
  };
132
148
  private lastAppliedQuality = Number.NaN;
149
+ private meshLighting: MeshLightingSettings = defaultMeshLighting();
133
150
 
134
151
  constructor(name: string, scene: Scene) {
135
152
  super(name, scene);
@@ -161,7 +178,9 @@ export class BatchedRenderer extends TransformNode {
161
178
  a.instancingGeometry === b.instancingGeometry &&
162
179
  a.renderOrder === b.renderOrder &&
163
180
  a.layerMask === b.layerMask &&
164
- pivotEqual(a.pivot, b.pivot)
181
+ pivotEqual(a.pivot, b.pivot) &&
182
+ (a.lighting ?? 'fixed') === (b.lighting ?? 'fixed') &&
183
+ meshRimEqual(a.rim, b.rim)
165
184
  );
166
185
  }
167
186
 
@@ -209,6 +228,7 @@ export class BatchedRenderer extends TransformNode {
209
228
  if (this.depthTexture) {
210
229
  batch.applyDepthTexture(this.depthTexture);
211
230
  }
231
+ batch.applyMeshLighting(this.meshLighting);
212
232
  batch.addSystem(system);
213
233
  this.batches.push(batch);
214
234
  this.batchEmptyFrames.push(0);
@@ -259,6 +279,43 @@ export class BatchedRenderer extends TransformNode {
259
279
  }
260
280
  }
261
281
 
282
+ /**
283
+ * Sets the light mesh particles with `lighting: 'fixed'` (the default) are
284
+ * lit by, for every mesh batch of this renderer, including ones created
285
+ * later. Fields left out keep their current value. Also the fallback for
286
+ * `'scene'` lighting when the scene has no directional or hemispheric light.
287
+ *
288
+ * @example
289
+ * ```ts
290
+ * renderer.setMeshLighting({direction: new Vector3(-0.3, -1, 0.2), color: new Color3(1, 0.9, 0.75)});
291
+ * ```
292
+ */
293
+ setMeshLighting(lighting: Partial<MeshLightingSettings>): void {
294
+ const current = this.meshLighting;
295
+ if (lighting.direction) {
296
+ current.direction = lighting.direction.clone();
297
+ }
298
+ if (lighting.color) {
299
+ current.color = lighting.color.clone();
300
+ }
301
+ if (lighting.ambient) {
302
+ current.ambient = lighting.ambient.clone();
303
+ }
304
+ for (const batch of this.batches) {
305
+ batch.applyMeshLighting(current);
306
+ }
307
+ }
308
+
309
+ /** A copy of the light set with {@link setMeshLighting}. */
310
+ getMeshLighting(): MeshLightingSettings {
311
+ const current = this.meshLighting;
312
+ return {
313
+ direction: current.direction.clone(),
314
+ color: current.color.clone(),
315
+ ambient: current.ambient.clone(),
316
+ };
317
+ }
318
+
262
319
  configureAdaptivePerformance(options: Partial<AdaptivePerformanceOptions> = {}) {
263
320
  const state = this.adaptivePerformanceState;
264
321
  const minQuality = BatchedRenderer.clamp(options.minQuality ?? state.minQuality, 0.05, 1);