@onerjs/core 8.27.3 → 8.27.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.
Files changed (88) hide show
  1. package/Cameras/arcRotateCamera.js +7 -5
  2. package/Cameras/arcRotateCamera.js.map +1 -1
  3. package/Cameras/targetCamera.d.ts +12 -0
  4. package/Cameras/targetCamera.js +19 -5
  5. package/Cameras/targetCamera.js.map +1 -1
  6. package/Engines/abstractEngine.js +2 -2
  7. package/Engines/abstractEngine.js.map +1 -1
  8. package/FrameGraph/Node/Blocks/inputBlock.js +1 -1
  9. package/FrameGraph/Node/Blocks/inputBlock.js.map +1 -1
  10. package/FrameGraph/Node/nodeRenderGraph.d.ts +2 -1
  11. package/FrameGraph/Node/nodeRenderGraph.js +8 -8
  12. package/FrameGraph/Node/nodeRenderGraph.js.map +1 -1
  13. package/FrameGraph/Passes/renderPass.js +3 -3
  14. package/FrameGraph/Passes/renderPass.js.map +1 -1
  15. package/FrameGraph/Tasks/Rendering/taaObjectRendererTask.js +7 -7
  16. package/FrameGraph/Tasks/Rendering/taaObjectRendererTask.js.map +1 -1
  17. package/FrameGraph/Tasks/Texture/clearTextureTask.js +1 -1
  18. package/FrameGraph/Tasks/Texture/clearTextureTask.js.map +1 -1
  19. package/FrameGraph/frameGraph.d.ts +4 -0
  20. package/FrameGraph/frameGraph.js +8 -0
  21. package/FrameGraph/frameGraph.js.map +1 -1
  22. package/FrameGraph/frameGraphRenderContext.d.ts +2 -1
  23. package/FrameGraph/frameGraphRenderContext.js +10 -3
  24. package/FrameGraph/frameGraphRenderContext.js.map +1 -1
  25. package/FrameGraph/frameGraphTextureManager.d.ts +32 -6
  26. package/FrameGraph/frameGraphTextureManager.js +138 -14
  27. package/FrameGraph/frameGraphTextureManager.js.map +1 -1
  28. package/Materials/Background/backgroundMaterial.js +1 -1
  29. package/Materials/Background/backgroundMaterial.js.map +1 -1
  30. package/Materials/PBR/openPbrMaterial.js +1 -1
  31. package/Materials/PBR/openPbrMaterial.js.map +1 -1
  32. package/Materials/PBR/pbrBaseMaterial.js +1 -1
  33. package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
  34. package/Materials/Textures/texture.js +13 -3
  35. package/Materials/Textures/texture.js.map +1 -1
  36. package/Materials/floatingOriginMatrixOverrides.js +11 -6
  37. package/Materials/floatingOriginMatrixOverrides.js.map +1 -1
  38. package/Materials/materialHelper.functions.d.ts +3 -3
  39. package/Materials/materialHelper.functions.js +2 -3
  40. package/Materials/materialHelper.functions.js.map +1 -1
  41. package/Materials/standardMaterial.js +1 -1
  42. package/Materials/standardMaterial.js.map +1 -1
  43. package/Maths/math.vector.functions.d.ts +17 -0
  44. package/Maths/math.vector.functions.js +27 -0
  45. package/Maths/math.vector.functions.js.map +1 -1
  46. package/Meshes/mesh.js +1 -1
  47. package/Meshes/mesh.js.map +1 -1
  48. package/Misc/screenshotTools.d.ts +63 -1
  49. package/Misc/screenshotTools.js +207 -4
  50. package/Misc/screenshotTools.js.map +1 -1
  51. package/Misc/textureTools.d.ts +6 -0
  52. package/Misc/textureTools.js +6 -1
  53. package/Misc/textureTools.js.map +1 -1
  54. package/Particles/Node/Blocks/Emitters/boxShapeBlock.js +1 -0
  55. package/Particles/Node/Blocks/Emitters/boxShapeBlock.js.map +1 -1
  56. package/Particles/Node/Blocks/Emitters/customShapeBlock.js +1 -0
  57. package/Particles/Node/Blocks/Emitters/customShapeBlock.js.map +1 -1
  58. package/Particles/Node/Blocks/Emitters/cylinderShapeBlock.js +1 -0
  59. package/Particles/Node/Blocks/Emitters/cylinderShapeBlock.js.map +1 -1
  60. package/Particles/Node/Blocks/Emitters/meshShapeBlock.js +1 -0
  61. package/Particles/Node/Blocks/Emitters/meshShapeBlock.js.map +1 -1
  62. package/Particles/Node/Blocks/Emitters/pointShapeBlock.js +1 -0
  63. package/Particles/Node/Blocks/Emitters/pointShapeBlock.js.map +1 -1
  64. package/Particles/Node/Blocks/Emitters/sphereShapeBlock.js +1 -0
  65. package/Particles/Node/Blocks/Emitters/sphereShapeBlock.js.map +1 -1
  66. package/Particles/Node/Blocks/index.d.ts +1 -0
  67. package/Particles/Node/Blocks/index.js +1 -0
  68. package/Particles/Node/Blocks/index.js.map +1 -1
  69. package/Particles/Node/Blocks/particleFresnelBlock.d.ts +34 -0
  70. package/Particles/Node/Blocks/particleFresnelBlock.js +74 -0
  71. package/Particles/Node/Blocks/particleFresnelBlock.js.map +1 -0
  72. package/Particles/Node/Blocks/particleInputBlock.js +2 -0
  73. package/Particles/Node/Blocks/particleInputBlock.js.map +1 -1
  74. package/Particles/Node/Blocks/particleLerpBlock.d.ts +1 -1
  75. package/Particles/Node/Blocks/particleLerpBlock.js +1 -1
  76. package/Particles/Node/Blocks/particleLerpBlock.js.map +1 -1
  77. package/Particles/Node/Enums/nodeParticleContextualSources.d.ts +3 -1
  78. package/Particles/Node/Enums/nodeParticleContextualSources.js +2 -0
  79. package/Particles/Node/Enums/nodeParticleContextualSources.js.map +1 -1
  80. package/Particles/Node/Enums/nodeParticleSystemSources.d.ts +3 -1
  81. package/Particles/Node/Enums/nodeParticleSystemSources.js +2 -0
  82. package/Particles/Node/Enums/nodeParticleSystemSources.js.map +1 -1
  83. package/Particles/Node/nodeParticleBuildState.d.ts +1 -1
  84. package/Particles/Node/nodeParticleBuildState.js +4 -0
  85. package/Particles/Node/nodeParticleBuildState.js.map +1 -1
  86. package/node.js +4 -1
  87. package/node.js.map +1 -1
  88. package/package.json +1 -1
@@ -37,10 +37,9 @@ export class FrameGraphTextureManager {
37
37
  * Gets or sets a boolean indicating if debug logs should be shown when applying texture allocation optimization (default: false)
38
38
  */
39
39
  this.showDebugLogsForTextureAllcationOptimization = false;
40
- /** If provided (greater than 0), forces the output screen width for percentage-based textures. If not provided (0), engine.getRenderWidth() will be used */
41
- this.forcedOutputScreenWidth = 0;
42
- /** If provided (greater than 0), forces the output screen height for percentage-based textures. If not provided (0), engine.getRenderHeight() will be used */
43
- this.forcedOutputScreenHeight = 0;
40
+ this._backBufferTextureEntry = null;
41
+ this._backBufferDepthStencilTextureEntry = null;
42
+ this._backBufferTextureOverriden = false;
44
43
  this._addSystemTextures();
45
44
  }
46
45
  /**
@@ -49,6 +48,13 @@ export class FrameGraphTextureManager {
49
48
  * @returns True if the handle is a backbuffer handle
50
49
  */
51
50
  isBackbuffer(handle) {
51
+ if (this._backBufferTextureOverriden) {
52
+ return false;
53
+ }
54
+ return this._isBackbuffer(handle);
55
+ }
56
+ /** @internal */
57
+ _isBackbuffer(handle) {
52
58
  if (handle === backbufferColorTextureHandle || handle === backbufferDepthStencilTextureHandle) {
53
59
  return true;
54
60
  }
@@ -64,6 +70,9 @@ export class FrameGraphTextureManager {
64
70
  * @returns True if the handle is a backbuffer color handle
65
71
  */
66
72
  isBackbufferColor(handle) {
73
+ if (this._backBufferTextureOverriden) {
74
+ return false;
75
+ }
67
76
  if (handle === backbufferColorTextureHandle) {
68
77
  return true;
69
78
  }
@@ -79,6 +88,9 @@ export class FrameGraphTextureManager {
79
88
  * @returns True if the handle is a backbuffer depth/stencil handle
80
89
  */
81
90
  isBackbufferDepthStencil(handle) {
91
+ if (this._backBufferTextureOverriden) {
92
+ return false;
93
+ }
82
94
  if (handle === backbufferDepthStencilTextureHandle) {
83
95
  return true;
84
96
  }
@@ -107,6 +119,7 @@ export class FrameGraphTextureManager {
107
119
  * @returns The creation options of the texture
108
120
  */
109
121
  getTextureCreationOptions(handle) {
122
+ handle = this._textures.get(handle)?.refHandle ?? handle;
110
123
  const entry = this._textures.get(handle);
111
124
  const creationOptions = entry.creationOptions;
112
125
  return {
@@ -152,16 +165,21 @@ export class FrameGraphTextureManager {
152
165
  }
153
166
  /**
154
167
  * Gets a texture from a handle.
155
- * Note that if the texture is a history texture, the read texture for the current frame will be returned.
168
+ * Note that if the texture is a history texture, the read texture for the current frame will be returned, except if historyGetWriteTexture is true.
156
169
  * @param handle The handle of the texture
170
+ * @param historyGetWriteTexture If true and the texture is a history texture, the write texture for the current frame will be returned (default: false)
157
171
  * @returns The texture or null if not found
158
172
  */
159
- getTextureFromHandle(handle) {
160
- const historyEntry = this._historyTextures.get(handle);
173
+ getTextureFromHandle(handle, historyGetWriteTexture) {
174
+ const entry = this._textures.get(handle);
175
+ const refHandle = entry?.refHandle;
176
+ const finalEntry = refHandle !== undefined ? this._textures.get(refHandle) : entry;
177
+ const finalHandle = refHandle !== undefined ? refHandle : handle;
178
+ const historyEntry = this._historyTextures.get(finalHandle);
161
179
  if (historyEntry) {
162
- return historyEntry.textures[historyEntry.index ^ 1]; // gets the read texture
180
+ return historyEntry.textures[historyGetWriteTexture ? historyEntry.index : historyEntry.index ^ 1];
163
181
  }
164
- return this._textures.get(handle).texture;
182
+ return finalEntry.texture;
165
183
  }
166
184
  /**
167
185
  * Imports a texture into the texture manager
@@ -264,6 +282,7 @@ export class FrameGraphTextureManager {
264
282
  if (textureEntry === undefined) {
265
283
  throw new Error(`resolveDanglingHandle: Handle ${handle} does not exist!`);
266
284
  }
285
+ handle = textureEntry.refHandle ?? handle; // gets the refHandle if handle is a (resolved) dangling handle itself
267
286
  this._textures.set(danglingHandle, {
268
287
  texture: textureEntry.texture,
269
288
  refHandle: handle,
@@ -286,8 +305,9 @@ export class FrameGraphTextureManager {
286
305
  * @returns The absolute dimensions of the texture
287
306
  */
288
307
  getAbsoluteDimensions(size, screenWidth, screenHeight) {
289
- screenWidth = this.forcedOutputScreenWidth || this.engine.getRenderWidth(true);
290
- screenHeight = this.forcedOutputScreenHeight || this.engine.getRenderHeight(true);
308
+ const backbufferColorTextureSize = this._textures.get(backbufferColorTextureHandle).creationOptions.size;
309
+ screenWidth = backbufferColorTextureSize.width;
310
+ screenHeight = backbufferColorTextureSize.height;
291
311
  const { width, height } = getDimensionsFromTextureSize(size);
292
312
  return {
293
313
  width: Math.floor((width * screenWidth) / 100),
@@ -304,7 +324,8 @@ export class FrameGraphTextureManager {
304
324
  computeTotalTextureSize(optimizedSize, outputWidth, outputHeight) {
305
325
  let totalSize = 0;
306
326
  this._textures.forEach((entry, handle) => {
307
- if (handle === backbufferColorTextureHandle || handle === backbufferDepthStencilTextureHandle || entry.refHandle !== undefined) {
327
+ if ((!this._backBufferTextureOverriden && (handle === backbufferColorTextureHandle || handle === backbufferDepthStencilTextureHandle)) ||
328
+ entry.refHandle !== undefined) {
308
329
  return;
309
330
  }
310
331
  if (optimizedSize && entry.aliasHandle !== undefined) {
@@ -327,6 +348,105 @@ export class FrameGraphTextureManager {
327
348
  });
328
349
  return totalSize;
329
350
  }
351
+ /**
352
+ * True if the back buffer texture has been overriden by a call to setBackBufferTexture
353
+ */
354
+ get backBufferTextureOverriden() {
355
+ return this._backBufferTextureOverriden;
356
+ }
357
+ /**
358
+ * Overrides the default back buffer color/depth-stencil textures used by the frame graph.
359
+ * Note that if both textureCreationOptions and depthStencilTextureCreationOptions are provided,
360
+ * the engine will use them to create the back buffer color and depth/stencil textures respectively.
361
+ * In that case, width and height are ignored.
362
+ * @param width The width of the back buffer color/depth-stencil texture (if 0, the engine's current back buffer color/depth-stencil texture width will be used)
363
+ * @param height The height of the back buffer color/depth-stencil texture (if 0, the engine's current back buffer color/depth-stencil texture height will be used)
364
+ * @param textureCreationOptions The color texture creation options (optional)
365
+ * @param depthStencilTextureCreationOptions The depth/stencil texture creation options (optional)
366
+ */
367
+ setBackBufferTextures(width, height, textureCreationOptions, depthStencilTextureCreationOptions) {
368
+ if ((width === 0 || height === 0) && (!textureCreationOptions || !depthStencilTextureCreationOptions)) {
369
+ if (this._backBufferTextureOverriden) {
370
+ let entry = this._textures.get(backbufferColorTextureHandle);
371
+ entry.texture?.dispose();
372
+ entry.texture = null;
373
+ entry.debug?.dispose();
374
+ entry.debug = undefined;
375
+ entry = this._textures.get(backbufferDepthStencilTextureHandle);
376
+ entry.texture?.dispose();
377
+ entry.texture = null;
378
+ entry.debug?.dispose();
379
+ entry.debug = undefined;
380
+ }
381
+ this._backBufferTextureEntry = null;
382
+ this._backBufferDepthStencilTextureEntry = null;
383
+ this._backBufferTextureOverriden = false;
384
+ this._addSystemTextures();
385
+ return;
386
+ }
387
+ this._backBufferTextureOverriden = true;
388
+ const size = { width, height };
389
+ this._backBufferTextureEntry = {
390
+ name: "backbuffer color",
391
+ texture: null,
392
+ creationOptions: textureCreationOptions ?? {
393
+ size,
394
+ options: {
395
+ createMipMaps: false,
396
+ samples: this.engine.getCreationOptions().antialias ? 4 : 1,
397
+ types: [0],
398
+ formats: [5],
399
+ useSRGBBuffers: [false],
400
+ creationFlags: [0],
401
+ labels: ["backbuffer color"],
402
+ },
403
+ sizeIsPercentage: false,
404
+ },
405
+ namespace: FrameGraphTextureNamespace.Graph,
406
+ lifespan: {
407
+ firstTask: Number.MAX_VALUE,
408
+ lastTask: 0,
409
+ },
410
+ };
411
+ this._backBufferTextureEntry.textureDescriptionHash = this._createTextureDescriptionHash(this._backBufferTextureEntry.creationOptions);
412
+ this._backBufferDepthStencilTextureEntry = {
413
+ name: "backbuffer depth/stencil",
414
+ texture: null,
415
+ creationOptions: depthStencilTextureCreationOptions ?? {
416
+ size,
417
+ options: {
418
+ createMipMaps: false,
419
+ samples: this.engine.getCreationOptions().antialias ? 4 : 1,
420
+ types: [0],
421
+ formats: [this.engine.isStencilEnable ? 13 : 14],
422
+ useSRGBBuffers: [false],
423
+ creationFlags: [0],
424
+ labels: ["backbuffer depth/stencil"],
425
+ },
426
+ sizeIsPercentage: false,
427
+ },
428
+ namespace: FrameGraphTextureNamespace.Graph,
429
+ lifespan: {
430
+ firstTask: Number.MAX_VALUE,
431
+ lastTask: 0,
432
+ },
433
+ };
434
+ this._backBufferDepthStencilTextureEntry.textureDescriptionHash = this._createTextureDescriptionHash(this._backBufferDepthStencilTextureEntry.creationOptions);
435
+ this._addSystemTextures();
436
+ }
437
+ /**
438
+ * Resets the back buffer color/depth-stencil textures to the default (the engine's current back buffer textures)
439
+ * It has no effect if setBackBufferTextures has not been called before.
440
+ */
441
+ resetBackBufferTextures() {
442
+ this.setBackBufferTextures(0, 0);
443
+ }
444
+ /**
445
+ * Returns true if the texture manager has at least one history texture
446
+ */
447
+ get hasHistoryTextures() {
448
+ return this._historyTextures.size > 0;
449
+ }
330
450
  /** @internal */
331
451
  _dispose() {
332
452
  this._releaseTextures();
@@ -420,6 +540,7 @@ export class FrameGraphTextureManager {
420
540
  entry.texture = null;
421
541
  if (releaseAll || entry.namespace === FrameGraphTextureNamespace.Task) {
422
542
  this._textures.delete(handle);
543
+ this._historyTextures.delete(handle);
423
544
  }
424
545
  });
425
546
  this._historyTextures.forEach((entry) => {
@@ -447,7 +568,7 @@ export class FrameGraphTextureManager {
447
568
  }
448
569
  _addSystemTextures() {
449
570
  const size = { width: this.engine.getRenderWidth(true), height: this.engine.getRenderHeight(true) };
450
- this._textures.set(backbufferColorTextureHandle, {
571
+ this._textures.set(backbufferColorTextureHandle, this._backBufferTextureEntry ?? {
451
572
  name: "backbuffer color",
452
573
  texture: null,
453
574
  creationOptions: {
@@ -465,7 +586,7 @@ export class FrameGraphTextureManager {
465
586
  },
466
587
  namespace: FrameGraphTextureNamespace.External,
467
588
  });
468
- this._textures.set(backbufferDepthStencilTextureHandle, {
589
+ this._textures.set(backbufferDepthStencilTextureHandle, this._backBufferDepthStencilTextureEntry ?? {
469
590
  name: "backbuffer depth/stencil",
470
591
  texture: null,
471
592
  creationOptions: {
@@ -665,6 +786,9 @@ export class FrameGraphTextureManager {
665
786
  const iterator = dependencies.keys();
666
787
  for (let key = iterator.next(); key.done !== true; key = iterator.next()) {
667
788
  const textureHandle = key.value;
789
+ if (this.isBackbuffer(textureHandle)) {
790
+ continue;
791
+ }
668
792
  let textureEntry = this._textures.get(textureHandle);
669
793
  if (!textureEntry) {
670
794
  throw new Error(`FrameGraph._computeTextureLifespan: Texture handle "${textureHandle}" not found in the texture manager.`);