@babylonjs/core 7.20.0 → 7.20.1

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 (117) hide show
  1. package/Bones/bone.js +3 -3
  2. package/Bones/bone.js.map +1 -1
  3. package/Bones/boneLookController.js +3 -3
  4. package/Bones/boneLookController.js.map +1 -1
  5. package/Compat/compatibilityOptions.d.ts +13 -6
  6. package/Compat/compatibilityOptions.js +20 -4
  7. package/Compat/compatibilityOptions.js.map +1 -1
  8. package/Compat/index.d.ts +1 -1
  9. package/Compat/index.js +1 -1
  10. package/Compat/index.js.map +1 -1
  11. package/Culling/boundingBox.js +5 -5
  12. package/Culling/boundingBox.js.map +1 -1
  13. package/Culling/boundingInfo.js +2 -2
  14. package/Culling/boundingInfo.js.map +1 -1
  15. package/Culling/boundingSphere.js +2 -2
  16. package/Culling/boundingSphere.js.map +1 -1
  17. package/Culling/ray.js +2 -2
  18. package/Culling/ray.js.map +1 -1
  19. package/Debug/debugLayer.d.ts +3 -0
  20. package/Debug/debugLayer.js +15 -0
  21. package/Debug/debugLayer.js.map +1 -1
  22. package/Engines/abstractEngine.js +2 -2
  23. package/Engines/abstractEngine.js.map +1 -1
  24. package/Engines/engine.js +11 -2
  25. package/Engines/engine.js.map +1 -1
  26. package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphDoNBlock.d.ts +2 -2
  27. package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphDoNBlock.js +1 -1
  28. package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphDoNBlock.js.map +1 -1
  29. package/Layers/highlightLayer.js +0 -1
  30. package/Layers/highlightLayer.js.map +1 -1
  31. package/Materials/Textures/Loaders/hdrTextureLoader.js +3 -3
  32. package/Materials/Textures/Loaders/hdrTextureLoader.js.map +1 -1
  33. package/Materials/Textures/hdrCubeTexture.js +2 -2
  34. package/Materials/Textures/hdrCubeTexture.js.map +1 -1
  35. package/Materials/Textures/renderTargetTexture.js +2 -2
  36. package/Materials/Textures/renderTargetTexture.js.map +1 -1
  37. package/Materials/Textures/texture.js +3 -3
  38. package/Materials/Textures/texture.js.map +1 -1
  39. package/Maths/math.color.js +3 -3
  40. package/Maths/math.color.js.map +1 -1
  41. package/Maths/math.vector.js +13 -14
  42. package/Maths/math.vector.js.map +1 -1
  43. package/Meshes/Builders/boxBuilder.js +5 -5
  44. package/Meshes/Builders/boxBuilder.js.map +1 -1
  45. package/Meshes/Builders/capsuleBuilder.js +4 -4
  46. package/Meshes/Builders/capsuleBuilder.js.map +1 -1
  47. package/Meshes/Builders/cylinderBuilder.js +8 -8
  48. package/Meshes/Builders/cylinderBuilder.js.map +1 -1
  49. package/Meshes/Builders/decalBuilder.js +3 -3
  50. package/Meshes/Builders/decalBuilder.js.map +1 -1
  51. package/Meshes/Builders/discBuilder.js +3 -3
  52. package/Meshes/Builders/discBuilder.js.map +1 -1
  53. package/Meshes/Builders/goldbergBuilder.js +2 -2
  54. package/Meshes/Builders/goldbergBuilder.js.map +1 -1
  55. package/Meshes/Builders/groundBuilder.js +2 -2
  56. package/Meshes/Builders/groundBuilder.js.map +1 -1
  57. package/Meshes/Builders/icoSphereBuilder.js +2 -2
  58. package/Meshes/Builders/icoSphereBuilder.js.map +1 -1
  59. package/Meshes/Builders/planeBuilder.js +5 -5
  60. package/Meshes/Builders/planeBuilder.js.map +1 -1
  61. package/Meshes/Builders/polygonBuilder.js +4 -4
  62. package/Meshes/Builders/polygonBuilder.js.map +1 -1
  63. package/Meshes/Builders/polyhedronBuilder.js +3 -3
  64. package/Meshes/Builders/polyhedronBuilder.js.map +1 -1
  65. package/Meshes/Builders/ribbonBuilder.js +4 -4
  66. package/Meshes/Builders/ribbonBuilder.js.map +1 -1
  67. package/Meshes/Builders/sphereBuilder.js +2 -2
  68. package/Meshes/Builders/sphereBuilder.js.map +1 -1
  69. package/Meshes/Builders/tiledBoxBuilder.js +2 -2
  70. package/Meshes/Builders/tiledBoxBuilder.js.map +1 -1
  71. package/Meshes/Builders/torusBuilder.js +2 -2
  72. package/Meshes/Builders/torusBuilder.js.map +1 -1
  73. package/Meshes/Builders/torusKnotBuilder.js +2 -2
  74. package/Meshes/Builders/torusKnotBuilder.js.map +1 -1
  75. package/Meshes/geometry.js +7 -7
  76. package/Meshes/geometry.js.map +1 -1
  77. package/Misc/HighDynamicRange/hdr.d.ts +40 -42
  78. package/Misc/HighDynamicRange/hdr.js +209 -202
  79. package/Misc/HighDynamicRange/hdr.js.map +1 -1
  80. package/Misc/HighDynamicRange/index.d.ts +1 -1
  81. package/Misc/HighDynamicRange/index.js +1 -1
  82. package/Misc/HighDynamicRange/index.js.map +1 -1
  83. package/Misc/arrayTools.d.ts +12 -17
  84. package/Misc/arrayTools.js +18 -23
  85. package/Misc/arrayTools.js.map +1 -1
  86. package/Misc/dumpTools.d.ts +50 -47
  87. package/Misc/dumpTools.js +153 -143
  88. package/Misc/dumpTools.js.map +1 -1
  89. package/Misc/environmentTextureTools.js +2 -2
  90. package/Misc/environmentTextureTools.js.map +1 -1
  91. package/Misc/equirectangularCapture.js +2 -2
  92. package/Misc/equirectangularCapture.js.map +1 -1
  93. package/Misc/index.d.ts +2 -1
  94. package/Misc/index.js +2 -1
  95. package/Misc/index.js.map +1 -1
  96. package/Misc/rgbdTextureTools.js +1 -0
  97. package/Misc/rgbdTextureTools.js.map +1 -1
  98. package/Misc/screenshotTools.js +3 -3
  99. package/Misc/screenshotTools.js.map +1 -1
  100. package/Physics/v1/physicsImpostor.js +2 -2
  101. package/Physics/v1/physicsImpostor.js.map +1 -1
  102. package/Physics/v2/Plugins/havokPlugin.js +2 -2
  103. package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
  104. package/PostProcesses/blurPostProcess.js +0 -1
  105. package/PostProcesses/blurPostProcess.js.map +1 -1
  106. package/PostProcesses/passPostProcess.js +0 -2
  107. package/PostProcesses/passPostProcess.js.map +1 -1
  108. package/PostProcesses/postProcess.d.ts +6 -0
  109. package/PostProcesses/postProcess.js +22 -1
  110. package/PostProcesses/postProcess.js.map +1 -1
  111. package/Shaders/ShadersInclude/pbrDebug.js +1 -1
  112. package/Shaders/ShadersInclude/pbrDebug.js.map +1 -1
  113. package/ShadersWGSL/ShadersInclude/pbrDebug.js +1 -1
  114. package/ShadersWGSL/ShadersInclude/pbrDebug.js.map +1 -1
  115. package/ShadersWGSL/background.fragment.js +1 -1
  116. package/ShadersWGSL/background.fragment.js.map +1 -1
  117. package/package.json +1 -1
@@ -1,23 +1,18 @@
1
1
  import type { Tuple } from "../types";
2
2
  /**
3
- * Class containing a set of static utilities functions for arrays.
3
+ * Returns an array of the given size filled with elements built from the given constructor and the parameters.
4
+ * @param size the number of element to construct and put in the array.
5
+ * @param itemBuilder a callback responsible for creating new instance of item. Called once per array entry.
6
+ * @returns a new array filled with new objects.
4
7
  */
5
- export declare class ArrayTools {
6
- /**
7
- * Returns an array of the given size filled with elements built from the given constructor and the parameters.
8
- * @param size the number of element to construct and put in the array.
9
- * @param itemBuilder a callback responsible for creating new instance of item. Called once per array entry.
10
- * @returns a new array filled with new objects.
11
- */
12
- static BuildArray<T>(size: number, itemBuilder: () => T): Array<T>;
13
- /**
14
- * Returns a tuple of the given size filled with elements built from the given constructor and the parameters.
15
- * @param size he number of element to construct and put in the tuple.
16
- * @param itemBuilder a callback responsible for creating new instance of item. Called once per tuple entry.
17
- * @returns a new tuple filled with new objects.
18
- */
19
- static BuildTuple<T, N extends number>(size: N, itemBuilder: () => T): Tuple<T, N>;
20
- }
8
+ export declare function BuildArray<T>(size: number, itemBuilder: () => T): Array<T>;
9
+ /**
10
+ * Returns a tuple of the given size filled with elements built from the given constructor and the parameters.
11
+ * @param size he number of element to construct and put in the tuple.
12
+ * @param itemBuilder a callback responsible for creating new instance of item. Called once per tuple entry.
13
+ * @returns a new tuple filled with new objects.
14
+ */
15
+ export declare function BuildTuple<T, N extends number>(size: N, itemBuilder: () => T): Tuple<T, N>;
21
16
  /**
22
17
  * Defines the callback type used when an observed array function is triggered.
23
18
  * @internal
@@ -1,30 +1,25 @@
1
1
  /* eslint-disable @typescript-eslint/naming-convention */
2
2
  /**
3
- * Class containing a set of static utilities functions for arrays.
3
+ * Returns an array of the given size filled with elements built from the given constructor and the parameters.
4
+ * @param size the number of element to construct and put in the array.
5
+ * @param itemBuilder a callback responsible for creating new instance of item. Called once per array entry.
6
+ * @returns a new array filled with new objects.
4
7
  */
5
- export class ArrayTools {
6
- /**
7
- * Returns an array of the given size filled with elements built from the given constructor and the parameters.
8
- * @param size the number of element to construct and put in the array.
9
- * @param itemBuilder a callback responsible for creating new instance of item. Called once per array entry.
10
- * @returns a new array filled with new objects.
11
- */
12
- static BuildArray(size, itemBuilder) {
13
- const a = [];
14
- for (let i = 0; i < size; ++i) {
15
- a.push(itemBuilder());
16
- }
17
- return a;
18
- }
19
- /**
20
- * Returns a tuple of the given size filled with elements built from the given constructor and the parameters.
21
- * @param size he number of element to construct and put in the tuple.
22
- * @param itemBuilder a callback responsible for creating new instance of item. Called once per tuple entry.
23
- * @returns a new tuple filled with new objects.
24
- */
25
- static BuildTuple(size, itemBuilder) {
26
- return ArrayTools.BuildArray(size, itemBuilder);
8
+ export function BuildArray(size, itemBuilder) {
9
+ const a = [];
10
+ for (let i = 0; i < size; ++i) {
11
+ a.push(itemBuilder());
27
12
  }
13
+ return a;
14
+ }
15
+ /**
16
+ * Returns a tuple of the given size filled with elements built from the given constructor and the parameters.
17
+ * @param size he number of element to construct and put in the tuple.
18
+ * @param itemBuilder a callback responsible for creating new instance of item. Called once per tuple entry.
19
+ * @returns a new tuple filled with new objects.
20
+ */
21
+ export function BuildTuple(size, itemBuilder) {
22
+ return BuildArray(size, itemBuilder);
28
23
  }
29
24
  /**
30
25
  * Observes a function and calls the given callback when it is called.
@@ -1 +1 @@
1
- {"version":3,"file":"arrayTools.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/arrayTools.ts"],"names":[],"mappings":"AAAA,yDAAyD;AAIzD;;GAEG;AACH,MAAM,OAAO,UAAU;IACn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;QAED,kDAAkD;QAClD,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC;QAE9B,sEAAsE;QACtE,IAAI,IAAI,EAAE;YACN,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC;YACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;SAC5B;QACD,4EAA4E;QAC5E,oCAAoC;aAC/B;YACD,QAAQ,CAAC,IAAI,GAAG,SAAS,CAAC;YAC1B,MAAM,CAAC,YAAY,CAAC,GAAG,QAAQ,CAAC;SACnC;QAED,oDAAoD;QACpD,WAAW,CAAC,IAAI,GAAG,SAAS,CAAC;QAC7B,WAAW,CAAC,QAAQ,GAAG,SAAS,CAAC;IACrC,CAAC,CAAC;AACN,CAAC;AAED;;;GAGG;AACH,MAAM,sBAAsB,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;AAE7E;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAI,KAAU,EAAE,QAA0B;IACnE,4EAA4E;IAC5E,MAAM,kBAAkB,GAAG,sBAAsB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QAC3D,OAAO,qBAAqB,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;IAEH,4DAA4D;IAC5D,OAAO,GAAG,EAAE;QACR,kBAAkB,CAAC,OAAO,CAAC,CAAC,iBAAiB,EAAE,EAAE;YAC7C,iBAAiB,EAAE,EAAE,CAAC;QAC1B,CAAC,CAAC,CAAC;IACP,CAAC,CAAC;AACN,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\n\r\nimport type { Nullable, Tuple } from \"../types\";\r\n\r\n/**\r\n * Class containing a set of static utilities functions for arrays.\r\n */\r\nexport class ArrayTools {\r\n /**\r\n * Returns an array of the given size filled with elements built from the given constructor and the parameters.\r\n * @param size the number of element to construct and put in the array.\r\n * @param itemBuilder a callback responsible for creating new instance of item. Called once per array entry.\r\n * @returns a new array filled with new objects.\r\n */\r\n public static BuildArray<T>(size: number, itemBuilder: () => T): Array<T> {\r\n const a: T[] = [];\r\n for (let i = 0; i < size; ++i) {\r\n a.push(itemBuilder());\r\n }\r\n return a;\r\n }\r\n\r\n /**\r\n * Returns a tuple of the given size filled with elements built from the given constructor and the parameters.\r\n * @param size he number of element to construct and put in the tuple.\r\n * @param itemBuilder a callback responsible for creating new instance of item. Called once per tuple entry.\r\n * @returns a new tuple filled with new objects.\r\n */\r\n public static BuildTuple<T, N extends number>(size: N, itemBuilder: () => T): Tuple<T, N> {\r\n return ArrayTools.BuildArray(size, itemBuilder) as any;\r\n }\r\n}\r\n\r\n/**\r\n * Defines the callback type used when an observed array function is triggered.\r\n * @internal\r\n */\r\nexport type _ObserveCallback = (functionName: string, previousLength: number) => void;\r\n\r\n/**\r\n * Observes a function and calls the given callback when it is called.\r\n * @param object Defines the object the function to observe belongs to.\r\n * @param functionName Defines the name of the function to observe.\r\n * @param callback Defines the callback to call when the function is called.\r\n * @returns A function to call to stop observing\r\n */\r\nfunction _observeArrayfunction(object: { [key: string]: any }, functionName: string, callback: _ObserveCallback): Nullable<() => void> {\r\n // Finds the function to observe\r\n const oldFunction = object[functionName];\r\n if (typeof oldFunction !== \"function\") {\r\n return null;\r\n }\r\n\r\n // Creates a new function that calls the callback and the old function\r\n const newFunction = function () {\r\n const previousLength = object.length;\r\n const returnValue = newFunction.previous.apply(object, arguments);\r\n callback(functionName, previousLength);\r\n return returnValue;\r\n } as any;\r\n\r\n // Doublishly links the new function and the old function\r\n oldFunction.next = newFunction;\r\n newFunction.previous = oldFunction;\r\n\r\n // Replaces the old function with the new function\r\n object[functionName] = newFunction;\r\n\r\n // Returns a function to disable the hook\r\n return () => {\r\n // Only unhook if the function is still hooked\r\n const previous = newFunction.previous;\r\n if (!previous) {\r\n return;\r\n }\r\n\r\n // Finds the ref to the next function in the chain\r\n const next = newFunction.next;\r\n\r\n // If in the middle of the chain, link the previous and next functions\r\n if (next) {\r\n previous.next = next;\r\n next.previous = previous;\r\n }\r\n // If at the end of the chain, remove the reference to the previous function\r\n // and restore the previous function\r\n else {\r\n previous.next = undefined;\r\n object[functionName] = previous;\r\n }\r\n\r\n // Lose reference to the previous and next functions\r\n newFunction.next = undefined;\r\n newFunction.previous = undefined;\r\n };\r\n}\r\n\r\n/**\r\n * Defines the list of functions to proxy when observing an array.\r\n * The scope is currently reduced to the common functions used in the render target render list and the scene cameras.\r\n */\r\nconst observedArrayFunctions = [\"push\", \"splice\", \"pop\", \"shift\", \"unshift\"];\r\n\r\n/**\r\n * Observes an array and notifies the given observer when the array is modified.\r\n * @param array Defines the array to observe\r\n * @param callback Defines the function to call when the array is modified (in the limit of the observed array functions)\r\n * @returns A function to call to stop observing the array\r\n * @internal\r\n */\r\nexport function _ObserveArray<T>(array: T[], callback: _ObserveCallback) {\r\n // Observes all the required array functions and stores the unhook functions\r\n const unObserveFunctions = observedArrayFunctions.map((name) => {\r\n return _observeArrayfunction(array, name, callback);\r\n });\r\n\r\n // Returns a function that unhook all the observed functions\r\n return () => {\r\n unObserveFunctions.forEach((unObserveFunction) => {\r\n unObserveFunction?.();\r\n });\r\n };\r\n}\r\n"]}
1
+ {"version":3,"file":"arrayTools.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/arrayTools.ts"],"names":[],"mappings":"AAAA,yDAAyD;AAIzD;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAI,IAAY,EAAE,WAAoB;IAC5D,MAAM,CAAC,GAAQ,EAAE,CAAC;IAClB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,EAAE;QAC3B,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;KACzB;IACD,OAAO,CAAC,CAAC;AACb,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAsB,IAAO,EAAE,WAAoB;IACzE,OAAO,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AAS,CAAC;QAC7B,WAAW,CAAC,QAAQ,GAAG,SAAS,CAAC;IACrC,CAAC,CAAC;AACN,CAAC;AAED;;;GAGG;AACH,MAAM,sBAAsB,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;AAE7E;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAI,KAAU,EAAE,QAA0B;IACnE,4EAA4E;IAC5E,MAAM,kBAAkB,GAAG,sBAAsB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QAC3D,OAAO,qBAAqB,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;IAEH,4DAA4D;IAC5D,OAAO,GAAG,EAAE;QACR,kBAAkB,CAAC,OAAO,CAAC,CAAC,iBAAiB,EAAE,EAAE;YAC7C,iBAAiB,EAAE,EAAE,CAAC;QAC1B,CAAC,CAAC,CAAC;IACP,CAAC,CAAC;AACN,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\n\r\nimport type { Nullable, Tuple } from \"../types\";\r\n\r\n/**\r\n * Returns an array of the given size filled with elements built from the given constructor and the parameters.\r\n * @param size the number of element to construct and put in the array.\r\n * @param itemBuilder a callback responsible for creating new instance of item. Called once per array entry.\r\n * @returns a new array filled with new objects.\r\n */\r\nexport function BuildArray<T>(size: number, itemBuilder: () => T): Array<T> {\r\n const a: T[] = [];\r\n for (let i = 0; i < size; ++i) {\r\n a.push(itemBuilder());\r\n }\r\n return a;\r\n}\r\n\r\n/**\r\n * Returns a tuple of the given size filled with elements built from the given constructor and the parameters.\r\n * @param size he number of element to construct and put in the tuple.\r\n * @param itemBuilder a callback responsible for creating new instance of item. Called once per tuple entry.\r\n * @returns a new tuple filled with new objects.\r\n */\r\nexport function BuildTuple<T, N extends number>(size: N, itemBuilder: () => T): Tuple<T, N> {\r\n return BuildArray(size, itemBuilder) as any;\r\n}\r\n\r\n/**\r\n * Defines the callback type used when an observed array function is triggered.\r\n * @internal\r\n */\r\nexport type _ObserveCallback = (functionName: string, previousLength: number) => void;\r\n\r\n/**\r\n * Observes a function and calls the given callback when it is called.\r\n * @param object Defines the object the function to observe belongs to.\r\n * @param functionName Defines the name of the function to observe.\r\n * @param callback Defines the callback to call when the function is called.\r\n * @returns A function to call to stop observing\r\n */\r\nfunction _observeArrayfunction(object: { [key: string]: any }, functionName: string, callback: _ObserveCallback): Nullable<() => void> {\r\n // Finds the function to observe\r\n const oldFunction = object[functionName];\r\n if (typeof oldFunction !== \"function\") {\r\n return null;\r\n }\r\n\r\n // Creates a new function that calls the callback and the old function\r\n const newFunction = function () {\r\n const previousLength = object.length;\r\n const returnValue = newFunction.previous.apply(object, arguments);\r\n callback(functionName, previousLength);\r\n return returnValue;\r\n } as any;\r\n\r\n // Doublishly links the new function and the old function\r\n oldFunction.next = newFunction;\r\n newFunction.previous = oldFunction;\r\n\r\n // Replaces the old function with the new function\r\n object[functionName] = newFunction;\r\n\r\n // Returns a function to disable the hook\r\n return () => {\r\n // Only unhook if the function is still hooked\r\n const previous = newFunction.previous;\r\n if (!previous) {\r\n return;\r\n }\r\n\r\n // Finds the ref to the next function in the chain\r\n const next = newFunction.next;\r\n\r\n // If in the middle of the chain, link the previous and next functions\r\n if (next) {\r\n previous.next = next;\r\n next.previous = previous;\r\n }\r\n // If at the end of the chain, remove the reference to the previous function\r\n // and restore the previous function\r\n else {\r\n previous.next = undefined;\r\n object[functionName] = previous;\r\n }\r\n\r\n // Lose reference to the previous and next functions\r\n newFunction.next = undefined;\r\n newFunction.previous = undefined;\r\n };\r\n}\r\n\r\n/**\r\n * Defines the list of functions to proxy when observing an array.\r\n * The scope is currently reduced to the common functions used in the render target render list and the scene cameras.\r\n */\r\nconst observedArrayFunctions = [\"push\", \"splice\", \"pop\", \"shift\", \"unshift\"];\r\n\r\n/**\r\n * Observes an array and notifies the given observer when the array is modified.\r\n * @param array Defines the array to observe\r\n * @param callback Defines the function to call when the array is modified (in the limit of the observed array functions)\r\n * @returns A function to call to stop observing the array\r\n * @internal\r\n */\r\nexport function _ObserveArray<T>(array: T[], callback: _ObserveCallback) {\r\n // Observes all the required array functions and stores the unhook functions\r\n const unObserveFunctions = observedArrayFunctions.map((name) => {\r\n return _observeArrayfunction(array, name, callback);\r\n });\r\n\r\n // Returns a function that unhook all the observed functions\r\n return () => {\r\n unObserveFunctions.forEach((unObserveFunction) => {\r\n unObserveFunction?.();\r\n });\r\n };\r\n}\r\n"]}
@@ -1,50 +1,53 @@
1
1
  import type { AbstractEngine } from "../Engines/abstractEngine";
2
2
  /**
3
- * Class containing a set of static utilities functions to dump data from a canvas
3
+ * Dumps the current bound framebuffer
4
+ * @param width defines the rendering width
5
+ * @param height defines the rendering height
6
+ * @param engine defines the hosting engine
7
+ * @param successCallback defines the callback triggered once the data are available
8
+ * @param mimeType defines the mime type of the result
9
+ * @param fileName defines the filename to download. If present, the result will automatically be downloaded
10
+ * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
11
+ * @returns a void promise
4
12
  */
5
- export declare class DumpTools {
6
- private static _DumpToolsEngine;
7
- private static _CreateDumpRenderer;
8
- /**
9
- * Dumps the current bound framebuffer
10
- * @param width defines the rendering width
11
- * @param height defines the rendering height
12
- * @param engine defines the hosting engine
13
- * @param successCallback defines the callback triggered once the data are available
14
- * @param mimeType defines the mime type of the result
15
- * @param fileName defines the filename to download. If present, the result will automatically be downloaded
16
- * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
17
- * @returns a void promise
18
- */
19
- static DumpFramebuffer(width: number, height: number, engine: AbstractEngine, successCallback?: (data: string) => void, mimeType?: string, fileName?: string, quality?: number): Promise<void>;
20
- /**
21
- * Dumps an array buffer
22
- * @param width defines the rendering width
23
- * @param height defines the rendering height
24
- * @param data the data array
25
- * @param mimeType defines the mime type of the result
26
- * @param fileName defines the filename to download. If present, the result will automatically be downloaded
27
- * @param invertY true to invert the picture in the Y dimension
28
- * @param toArrayBuffer true to convert the data to an ArrayBuffer (encoded as `mimeType`) instead of a base64 string
29
- * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
30
- * @returns a promise that resolve to the final data
31
- */
32
- static DumpDataAsync(width: number, height: number, data: ArrayBufferView, mimeType?: string, fileName?: string, invertY?: boolean, toArrayBuffer?: boolean, quality?: number): Promise<string | ArrayBuffer>;
33
- /**
34
- * Dumps an array buffer
35
- * @param width defines the rendering width
36
- * @param height defines the rendering height
37
- * @param data the data array
38
- * @param successCallback defines the callback triggered once the data are available
39
- * @param mimeType defines the mime type of the result
40
- * @param fileName defines the filename to download. If present, the result will automatically be downloaded
41
- * @param invertY true to invert the picture in the Y dimension
42
- * @param toArrayBuffer true to convert the data to an ArrayBuffer (encoded as `mimeType`) instead of a base64 string
43
- * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
44
- */
45
- static DumpData(width: number, height: number, data: ArrayBufferView, successCallback?: (data: string | ArrayBuffer) => void, mimeType?: string, fileName?: string, invertY?: boolean, toArrayBuffer?: boolean, quality?: number): void;
46
- /**
47
- * Dispose the dump tools associated resources
48
- */
49
- static Dispose(): void;
50
- }
13
+ export declare function DumpFramebuffer(width: number, height: number, engine: AbstractEngine, successCallback?: (data: string) => void, mimeType?: string, fileName?: string, quality?: number): Promise<void>;
14
+ /**
15
+ * Dumps an array buffer
16
+ * @param width defines the rendering width
17
+ * @param height defines the rendering height
18
+ * @param data the data array
19
+ * @param mimeType defines the mime type of the result
20
+ * @param fileName defines the filename to download. If present, the result will automatically be downloaded
21
+ * @param invertY true to invert the picture in the Y dimension
22
+ * @param toArrayBuffer true to convert the data to an ArrayBuffer (encoded as `mimeType`) instead of a base64 string
23
+ * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
24
+ * @returns a promise that resolve to the final data
25
+ */
26
+ export declare function DumpDataAsync(width: number, height: number, data: ArrayBufferView, mimeType?: string, fileName?: string, invertY?: boolean, toArrayBuffer?: boolean, quality?: number): Promise<string | ArrayBuffer>;
27
+ /**
28
+ * Dumps an array buffer
29
+ * @param width defines the rendering width
30
+ * @param height defines the rendering height
31
+ * @param data the data array
32
+ * @param successCallback defines the callback triggered once the data are available
33
+ * @param mimeType defines the mime type of the result
34
+ * @param fileName defines the filename to download. If present, the result will automatically be downloaded
35
+ * @param invertY true to invert the picture in the Y dimension
36
+ * @param toArrayBuffer true to convert the data to an ArrayBuffer (encoded as `mimeType`) instead of a base64 string
37
+ * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
38
+ */
39
+ export declare function DumpData(width: number, height: number, data: ArrayBufferView, successCallback?: (data: string | ArrayBuffer) => void, mimeType?: string, fileName?: string, invertY?: boolean, toArrayBuffer?: boolean, quality?: number): void;
40
+ /**
41
+ * Dispose the dump tools associated resources
42
+ */
43
+ export declare function Dispose(): void;
44
+ /**
45
+ * Object containing a set of static utilities functions to dump data from a canvas
46
+ * @deprecated use functions
47
+ */
48
+ export declare const DumpTools: {
49
+ DumpData: typeof DumpData;
50
+ DumpDataAsync: typeof DumpDataAsync;
51
+ DumpFramebuffer: typeof DumpFramebuffer;
52
+ Dispose: typeof Dispose;
53
+ };
package/Misc/dumpTools.js CHANGED
@@ -5,154 +5,164 @@ import { Tools } from "./tools.js";
5
5
  import { passPixelShader } from "../Shaders/pass.fragment.js";
6
6
  import { Scalar } from "../Maths/math.scalar.js";
7
7
  import { EngineStore } from "../Engines/engineStore.js";
8
+ let _dumpToolsEngine;
9
+ function _CreateDumpRenderer() {
10
+ if (!_dumpToolsEngine) {
11
+ let canvas;
12
+ let engine = null;
13
+ const options = {
14
+ preserveDrawingBuffer: true,
15
+ depth: false,
16
+ stencil: false,
17
+ alpha: true,
18
+ premultipliedAlpha: false,
19
+ antialias: false,
20
+ failIfMajorPerformanceCaveat: false,
21
+ };
22
+ try {
23
+ canvas = new OffscreenCanvas(100, 100); // will be resized later
24
+ engine = new ThinEngine(canvas, false, options);
25
+ }
26
+ catch (e) {
27
+ // The browser either does not support OffscreenCanvas or WebGL context in OffscreenCanvas, fallback on a regular canvas
28
+ canvas = document.createElement("canvas");
29
+ engine = new ThinEngine(canvas, false, options);
30
+ }
31
+ // remove this engine from the list of instances to avoid using it for other purposes
32
+ EngineStore.Instances.pop();
33
+ // However, make sure to dispose it when no other engines are left
34
+ EngineStore.OnEnginesDisposedObservable.add((e) => {
35
+ // guaranteed to run when no other instances are left
36
+ // only dispose if it's not the current engine
37
+ if (engine && e !== engine && !engine.isDisposed && EngineStore.Instances.length === 0) {
38
+ // Dump the engine and the associated resources
39
+ Dispose();
40
+ }
41
+ });
42
+ engine.getCaps().parallelShaderCompile = undefined;
43
+ const renderer = new EffectRenderer(engine);
44
+ const wrapper = new EffectWrapper({
45
+ engine,
46
+ name: passPixelShader.name,
47
+ fragmentShader: passPixelShader.shader,
48
+ samplerNames: ["textureSampler"],
49
+ });
50
+ _dumpToolsEngine = {
51
+ canvas,
52
+ engine,
53
+ renderer,
54
+ wrapper,
55
+ };
56
+ }
57
+ return _dumpToolsEngine;
58
+ }
8
59
  /**
9
- * Class containing a set of static utilities functions to dump data from a canvas
60
+ * Dumps the current bound framebuffer
61
+ * @param width defines the rendering width
62
+ * @param height defines the rendering height
63
+ * @param engine defines the hosting engine
64
+ * @param successCallback defines the callback triggered once the data are available
65
+ * @param mimeType defines the mime type of the result
66
+ * @param fileName defines the filename to download. If present, the result will automatically be downloaded
67
+ * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
68
+ * @returns a void promise
10
69
  */
11
- export class DumpTools {
12
- static _CreateDumpRenderer() {
13
- if (!DumpTools._DumpToolsEngine) {
14
- let canvas;
15
- let engine = null;
16
- const options = {
17
- preserveDrawingBuffer: true,
18
- depth: false,
19
- stencil: false,
20
- alpha: true,
21
- premultipliedAlpha: false,
22
- antialias: false,
23
- failIfMajorPerformanceCaveat: false,
24
- };
25
- try {
26
- canvas = new OffscreenCanvas(100, 100); // will be resized later
27
- engine = new ThinEngine(canvas, false, options);
28
- }
29
- catch (e) {
30
- // The browser either does not support OffscreenCanvas or WebGL context in OffscreenCanvas, fallback on a regular canvas
31
- canvas = document.createElement("canvas");
32
- engine = new ThinEngine(canvas, false, options);
33
- }
34
- // remove this engine from the list of instances to avoid using it for other purposes
35
- EngineStore.Instances.pop();
36
- // However, make sure to dispose it when no other engines are left
37
- EngineStore.OnEnginesDisposedObservable.add((e) => {
38
- // guaranteed to run when no other instances are left
39
- // only dispose if it's not the current engine
40
- if (engine && e !== engine && !engine.isDisposed && EngineStore.Instances.length === 0) {
41
- // Dump the engine and the associated resources
42
- DumpTools.Dispose();
43
- }
44
- });
45
- engine.getCaps().parallelShaderCompile = undefined;
46
- const renderer = new EffectRenderer(engine);
47
- const wrapper = new EffectWrapper({
48
- engine,
49
- name: passPixelShader.name,
50
- fragmentShader: passPixelShader.shader,
51
- samplerNames: ["textureSampler"],
52
- });
53
- DumpTools._DumpToolsEngine = {
54
- canvas,
55
- engine,
56
- renderer,
57
- wrapper,
58
- };
70
+ export async function DumpFramebuffer(width, height, engine, successCallback, mimeType = "image/png", fileName, quality) {
71
+ // Read the contents of the framebuffer
72
+ const bufferView = await engine.readPixels(0, 0, width, height);
73
+ const data = new Uint8Array(bufferView.buffer);
74
+ DumpData(width, height, data, successCallback, mimeType, fileName, true, undefined, quality);
75
+ }
76
+ /**
77
+ * Dumps an array buffer
78
+ * @param width defines the rendering width
79
+ * @param height defines the rendering height
80
+ * @param data the data array
81
+ * @param mimeType defines the mime type of the result
82
+ * @param fileName defines the filename to download. If present, the result will automatically be downloaded
83
+ * @param invertY true to invert the picture in the Y dimension
84
+ * @param toArrayBuffer true to convert the data to an ArrayBuffer (encoded as `mimeType`) instead of a base64 string
85
+ * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
86
+ * @returns a promise that resolve to the final data
87
+ */
88
+ export function DumpDataAsync(width, height, data, mimeType = "image/png", fileName, invertY = false, toArrayBuffer = false, quality) {
89
+ return new Promise((resolve) => {
90
+ DumpData(width, height, data, (result) => resolve(result), mimeType, fileName, invertY, toArrayBuffer, quality);
91
+ });
92
+ }
93
+ /**
94
+ * Dumps an array buffer
95
+ * @param width defines the rendering width
96
+ * @param height defines the rendering height
97
+ * @param data the data array
98
+ * @param successCallback defines the callback triggered once the data are available
99
+ * @param mimeType defines the mime type of the result
100
+ * @param fileName defines the filename to download. If present, the result will automatically be downloaded
101
+ * @param invertY true to invert the picture in the Y dimension
102
+ * @param toArrayBuffer true to convert the data to an ArrayBuffer (encoded as `mimeType`) instead of a base64 string
103
+ * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
104
+ */
105
+ export function DumpData(width, height, data, successCallback, mimeType = "image/png", fileName, invertY = false, toArrayBuffer = false, quality) {
106
+ const renderer = _CreateDumpRenderer();
107
+ renderer.engine.setSize(width, height, true);
108
+ // Convert if data are float32
109
+ if (data instanceof Float32Array) {
110
+ const data2 = new Uint8Array(data.length);
111
+ let n = data.length;
112
+ while (n--) {
113
+ const v = data[n];
114
+ data2[n] = Math.round(Scalar.Clamp(v) * 255);
59
115
  }
60
- return DumpTools._DumpToolsEngine;
61
- }
62
- /**
63
- * Dumps the current bound framebuffer
64
- * @param width defines the rendering width
65
- * @param height defines the rendering height
66
- * @param engine defines the hosting engine
67
- * @param successCallback defines the callback triggered once the data are available
68
- * @param mimeType defines the mime type of the result
69
- * @param fileName defines the filename to download. If present, the result will automatically be downloaded
70
- * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
71
- * @returns a void promise
72
- */
73
- static async DumpFramebuffer(width, height, engine, successCallback, mimeType = "image/png", fileName, quality) {
74
- // Read the contents of the framebuffer
75
- const bufferView = await engine.readPixels(0, 0, width, height);
76
- const data = new Uint8Array(bufferView.buffer);
77
- DumpTools.DumpData(width, height, data, successCallback, mimeType, fileName, true, undefined, quality);
116
+ data = data2;
78
117
  }
79
- /**
80
- * Dumps an array buffer
81
- * @param width defines the rendering width
82
- * @param height defines the rendering height
83
- * @param data the data array
84
- * @param mimeType defines the mime type of the result
85
- * @param fileName defines the filename to download. If present, the result will automatically be downloaded
86
- * @param invertY true to invert the picture in the Y dimension
87
- * @param toArrayBuffer true to convert the data to an ArrayBuffer (encoded as `mimeType`) instead of a base64 string
88
- * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
89
- * @returns a promise that resolve to the final data
90
- */
91
- static DumpDataAsync(width, height, data, mimeType = "image/png", fileName, invertY = false, toArrayBuffer = false, quality) {
92
- return new Promise((resolve) => {
93
- DumpTools.DumpData(width, height, data, (result) => resolve(result), mimeType, fileName, invertY, toArrayBuffer, quality);
94
- });
118
+ // Create the image
119
+ const texture = renderer.engine.createRawTexture(data, width, height, 5, false, !invertY, 1);
120
+ renderer.renderer.setViewport();
121
+ renderer.renderer.applyEffectWrapper(renderer.wrapper);
122
+ renderer.wrapper.effect._bindTexture("textureSampler", texture);
123
+ renderer.renderer.draw();
124
+ if (toArrayBuffer) {
125
+ Tools.ToBlob(renderer.canvas, (blob) => {
126
+ const fileReader = new FileReader();
127
+ fileReader.onload = (event) => {
128
+ const arrayBuffer = event.target.result;
129
+ if (successCallback) {
130
+ successCallback(arrayBuffer);
131
+ }
132
+ };
133
+ fileReader.readAsArrayBuffer(blob);
134
+ }, mimeType, quality);
95
135
  }
96
- /**
97
- * Dumps an array buffer
98
- * @param width defines the rendering width
99
- * @param height defines the rendering height
100
- * @param data the data array
101
- * @param successCallback defines the callback triggered once the data are available
102
- * @param mimeType defines the mime type of the result
103
- * @param fileName defines the filename to download. If present, the result will automatically be downloaded
104
- * @param invertY true to invert the picture in the Y dimension
105
- * @param toArrayBuffer true to convert the data to an ArrayBuffer (encoded as `mimeType`) instead of a base64 string
106
- * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
107
- */
108
- static DumpData(width, height, data, successCallback, mimeType = "image/png", fileName, invertY = false, toArrayBuffer = false, quality) {
109
- const renderer = DumpTools._CreateDumpRenderer();
110
- renderer.engine.setSize(width, height, true);
111
- // Convert if data are float32
112
- if (data instanceof Float32Array) {
113
- const data2 = new Uint8Array(data.length);
114
- let n = data.length;
115
- while (n--) {
116
- const v = data[n];
117
- data2[n] = Math.round(Scalar.Clamp(v) * 255);
118
- }
119
- data = data2;
120
- }
121
- // Create the image
122
- const texture = renderer.engine.createRawTexture(data, width, height, 5, false, !invertY, 1);
123
- renderer.renderer.setViewport();
124
- renderer.renderer.applyEffectWrapper(renderer.wrapper);
125
- renderer.wrapper.effect._bindTexture("textureSampler", texture);
126
- renderer.renderer.draw();
127
- if (toArrayBuffer) {
128
- Tools.ToBlob(renderer.canvas, (blob) => {
129
- const fileReader = new FileReader();
130
- fileReader.onload = (event) => {
131
- const arrayBuffer = event.target.result;
132
- if (successCallback) {
133
- successCallback(arrayBuffer);
134
- }
135
- };
136
- fileReader.readAsArrayBuffer(blob);
137
- }, mimeType, quality);
138
- }
139
- else {
140
- Tools.EncodeScreenshotCanvasData(renderer.canvas, successCallback, mimeType, fileName, quality);
141
- }
142
- texture.dispose();
136
+ else {
137
+ Tools.EncodeScreenshotCanvasData(renderer.canvas, successCallback, mimeType, fileName, quality);
143
138
  }
144
- /**
145
- * Dispose the dump tools associated resources
146
- */
147
- static Dispose() {
148
- if (DumpTools._DumpToolsEngine) {
149
- DumpTools._DumpToolsEngine.wrapper.dispose();
150
- DumpTools._DumpToolsEngine.renderer.dispose();
151
- DumpTools._DumpToolsEngine.engine.dispose();
152
- }
153
- DumpTools._DumpToolsEngine = null;
139
+ texture.dispose();
140
+ }
141
+ /**
142
+ * Dispose the dump tools associated resources
143
+ */
144
+ export function Dispose() {
145
+ if (_dumpToolsEngine) {
146
+ _dumpToolsEngine.wrapper.dispose();
147
+ _dumpToolsEngine.renderer.dispose();
148
+ _dumpToolsEngine.engine.dispose();
154
149
  }
150
+ _dumpToolsEngine = null;
155
151
  }
152
+ /**
153
+ * Object containing a set of static utilities functions to dump data from a canvas
154
+ * @deprecated use functions
155
+ */
156
+ export const DumpTools = {
157
+ // eslint-disable-next-line @typescript-eslint/naming-convention
158
+ DumpData,
159
+ // eslint-disable-next-line @typescript-eslint/naming-convention
160
+ DumpDataAsync,
161
+ // eslint-disable-next-line @typescript-eslint/naming-convention
162
+ DumpFramebuffer,
163
+ // eslint-disable-next-line @typescript-eslint/naming-convention
164
+ Dispose,
165
+ };
156
166
  /**
157
167
  * This will be executed automatically for UMD and es5.
158
168
  * If esm dev wants the side effects to execute they will have to run it manually
@@ -161,9 +171,9 @@ export class DumpTools {
161
171
  */
162
172
  const initSideEffects = () => {
163
173
  // References the dependencies.
164
- Tools.DumpData = DumpTools.DumpData;
165
- Tools.DumpDataAsync = DumpTools.DumpDataAsync;
166
- Tools.DumpFramebuffer = DumpTools.DumpFramebuffer;
174
+ Tools.DumpData = DumpData;
175
+ Tools.DumpDataAsync = DumpDataAsync;
176
+ Tools.DumpFramebuffer = DumpFramebuffer;
167
177
  };
168
178
  initSideEffects();
169
179
  //# sourceMappingURL=dumpTools.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"dumpTools.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/dumpTools.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5E,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAGhC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AASrD;;GAEG;AACH,MAAM,OAAO,SAAS;IAGV,MAAM,CAAC,mBAAmB;QAC9B,IAAI,CAAC,SAAS,CAAC,gBAAgB,EAAE;YAC7B,IAAI,MAA2C,CAAC;YAChD,IAAI,MAAM,GAAyB,IAAI,CAAC;YACxC,MAAM,OAAO,GAAG;gBACZ,qBAAqB,EAAE,IAAI;gBAC3B,KAAK,EAAE,KAAK;gBACZ,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,IAAI;gBACX,kBAAkB,EAAE,KAAK;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,EAAE;oBAC/B,MAAM,WAAW,GAAG,KAAK,CAAC,MAAO,CAAC,MAAqB,CAAC;oBACxD,IAAI,eAAe,EAAE;wBACjB,eAAe,CAAC,WAAW,CAAC,CAAC;qBAChC;gBACL,CAAC,CAAC;gBACF,UAAU,CAAC,iBAAiB,CAAC,IAAK,CAAC,CAAC;YACxC,CAAC,EACD,QAAQ,EACR,OAAO,CACV,CAAC;SACL;aAAM;YACH,KAAK,CAAC,0BAA0B,CAAC,QAAQ,CAAC,MAAM,EAAE,eAAe,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;SACnG;QAED,OAAO,CAAC,OAAO,EAAE,CAAC;IACtB,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,OAAO;QACjB,IAAI,SAAS,CAAC,gBAAgB,EAAE;YAC5B,SAAS,CAAC,gBAAgB,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YAC7C,SAAS,CAAC,gBAAgB,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;YAC9C,SAAS,CAAC,gBAAgB,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;SAC/C;QACD,SAAS,CAAC,gBAAgB,GAAG,IAAI,CAAC;IACtC,CAAC;CACJ;AAED;;;;;GAKG;AACH,MAAM,eAAe,GAAG,GAAG,EAAE;IACzB,+BAA+B;IAC/B,KAAK,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC;IACpC,KAAK,CAAC,aAAa,GAAG,SAAS,CAAC,aAAa,CAAC;IAC9C,KAAK,CAAC,eAAe,GAAG,SAAS,CAAC,eAAe,CAAC;AACtD,CAAC,CAAC;AAEF,eAAe,EAAE,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\r\nimport { _WarnImport } from \"./devTools\";\r\n\r\nimport { ThinEngine } from \"../Engines/thinEngine\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { EffectRenderer, EffectWrapper } from \"../Materials/effectRenderer\";\r\nimport { Tools } from \"./tools\";\r\nimport type { Nullable } from \"../types\";\r\n\r\nimport { passPixelShader } from \"../Shaders/pass.fragment\";\r\nimport { Scalar } from \"../Maths/math.scalar\";\r\nimport type { AbstractEngine } from \"../Engines/abstractEngine\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\n\r\ntype DumpToolsEngine = {\r\n canvas: HTMLCanvasElement | OffscreenCanvas;\r\n engine: ThinEngine;\r\n renderer: EffectRenderer;\r\n wrapper: EffectWrapper;\r\n};\r\n\r\n/**\r\n * Class containing a set of static utilities functions to dump data from a canvas\r\n */\r\nexport class DumpTools {\r\n private static _DumpToolsEngine: Nullable<DumpToolsEngine>;\r\n\r\n private static _CreateDumpRenderer(): DumpToolsEngine {\r\n if (!DumpTools._DumpToolsEngine) {\r\n let canvas: HTMLCanvasElement | OffscreenCanvas;\r\n let engine: Nullable<ThinEngine> = null;\r\n const options = {\r\n preserveDrawingBuffer: true,\r\n depth: false,\r\n stencil: false,\r\n alpha: true,\r\n premultipliedAlpha: false,\r\n antialias: false,\r\n failIfMajorPerformanceCaveat: false,\r\n };\r\n try {\r\n canvas = new OffscreenCanvas(100, 100); // will be resized later\r\n engine = new ThinEngine(canvas, false, options);\r\n } catch (e) {\r\n // The browser either does not support OffscreenCanvas or WebGL context in OffscreenCanvas, fallback on a regular canvas\r\n canvas = document.createElement(\"canvas\");\r\n engine = new ThinEngine(canvas, false, options);\r\n }\r\n // remove this engine from the list of instances to avoid using it for other purposes\r\n EngineStore.Instances.pop();\r\n // However, make sure to dispose it when no other engines are left\r\n EngineStore.OnEnginesDisposedObservable.add((e) => {\r\n // guaranteed to run when no other instances are left\r\n // only dispose if it's not the current engine\r\n if (engine && e !== engine && !engine.isDisposed && EngineStore.Instances.length === 0) {\r\n // Dump the engine and the associated resources\r\n DumpTools.Dispose();\r\n }\r\n });\r\n engine.getCaps().parallelShaderCompile = undefined;\r\n const renderer = new EffectRenderer(engine);\r\n const wrapper = new EffectWrapper({\r\n engine,\r\n name: passPixelShader.name,\r\n fragmentShader: passPixelShader.shader,\r\n samplerNames: [\"textureSampler\"],\r\n });\r\n DumpTools._DumpToolsEngine = {\r\n canvas,\r\n engine,\r\n renderer,\r\n wrapper,\r\n };\r\n }\r\n return DumpTools._DumpToolsEngine;\r\n }\r\n\r\n /**\r\n * Dumps the current bound framebuffer\r\n * @param width defines the rendering width\r\n * @param height defines the rendering height\r\n * @param engine defines the hosting engine\r\n * @param successCallback defines the callback triggered once the data are available\r\n * @param mimeType defines the mime type of the result\r\n * @param fileName defines the filename to download. If present, the result will automatically be downloaded\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @returns a void promise\r\n */\r\n public static async DumpFramebuffer(\r\n width: number,\r\n height: number,\r\n engine: AbstractEngine,\r\n successCallback?: (data: string) => void,\r\n mimeType = \"image/png\",\r\n fileName?: string,\r\n quality?: number\r\n ) {\r\n // Read the contents of the framebuffer\r\n const bufferView = await engine.readPixels(0, 0, width, height);\r\n\r\n const data = new Uint8Array(bufferView.buffer);\r\n\r\n DumpTools.DumpData(width, height, data, successCallback as (data: string | ArrayBuffer) => void, mimeType, fileName, true, undefined, quality);\r\n }\r\n\r\n /**\r\n * Dumps an array buffer\r\n * @param width defines the rendering width\r\n * @param height defines the rendering height\r\n * @param data the data array\r\n * @param mimeType defines the mime type of the result\r\n * @param fileName defines the filename to download. If present, the result will automatically be downloaded\r\n * @param invertY true to invert the picture in the Y dimension\r\n * @param toArrayBuffer true to convert the data to an ArrayBuffer (encoded as `mimeType`) instead of a base64 string\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @returns a promise that resolve to the final data\r\n */\r\n public static DumpDataAsync(\r\n width: number,\r\n height: number,\r\n data: ArrayBufferView,\r\n mimeType = \"image/png\",\r\n fileName?: string,\r\n invertY = false,\r\n toArrayBuffer = false,\r\n quality?: number\r\n ): Promise<string | ArrayBuffer> {\r\n return new Promise((resolve) => {\r\n DumpTools.DumpData(width, height, data, (result) => resolve(result), mimeType, fileName, invertY, toArrayBuffer, quality);\r\n });\r\n }\r\n\r\n /**\r\n * Dumps an array buffer\r\n * @param width defines the rendering width\r\n * @param height defines the rendering height\r\n * @param data the data array\r\n * @param successCallback defines the callback triggered once the data are available\r\n * @param mimeType defines the mime type of the result\r\n * @param fileName defines the filename to download. If present, the result will automatically be downloaded\r\n * @param invertY true to invert the picture in the Y dimension\r\n * @param toArrayBuffer true to convert the data to an ArrayBuffer (encoded as `mimeType`) instead of a base64 string\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n */\r\n public static DumpData(\r\n width: number,\r\n height: number,\r\n data: ArrayBufferView,\r\n successCallback?: (data: string | ArrayBuffer) => void,\r\n mimeType = \"image/png\",\r\n fileName?: string,\r\n invertY = false,\r\n toArrayBuffer = false,\r\n quality?: number\r\n ) {\r\n const renderer = DumpTools._CreateDumpRenderer();\r\n renderer.engine.setSize(width, height, true);\r\n\r\n // Convert if data are float32\r\n if (data instanceof Float32Array) {\r\n const data2 = new Uint8Array(data.length);\r\n let n = data.length;\r\n while (n--) {\r\n const v = data[n];\r\n data2[n] = Math.round(Scalar.Clamp(v) * 255);\r\n }\r\n data = data2;\r\n }\r\n\r\n // Create the image\r\n const texture = renderer.engine.createRawTexture(data, width, height, Constants.TEXTUREFORMAT_RGBA, false, !invertY, Constants.TEXTURE_NEAREST_NEAREST);\r\n\r\n renderer.renderer.setViewport();\r\n renderer.renderer.applyEffectWrapper(renderer.wrapper);\r\n renderer.wrapper.effect._bindTexture(\"textureSampler\", texture);\r\n renderer.renderer.draw();\r\n\r\n if (toArrayBuffer) {\r\n Tools.ToBlob(\r\n renderer.canvas,\r\n (blob) => {\r\n const fileReader = new FileReader();\r\n fileReader.onload = (event: any) => {\r\n const arrayBuffer = event.target!.result as ArrayBuffer;\r\n if (successCallback) {\r\n successCallback(arrayBuffer);\r\n }\r\n };\r\n fileReader.readAsArrayBuffer(blob!);\r\n },\r\n mimeType,\r\n quality\r\n );\r\n } else {\r\n Tools.EncodeScreenshotCanvasData(renderer.canvas, successCallback, mimeType, fileName, quality);\r\n }\r\n\r\n texture.dispose();\r\n }\r\n\r\n /**\r\n * Dispose the dump tools associated resources\r\n */\r\n public static Dispose() {\r\n if (DumpTools._DumpToolsEngine) {\r\n DumpTools._DumpToolsEngine.wrapper.dispose();\r\n DumpTools._DumpToolsEngine.renderer.dispose();\r\n DumpTools._DumpToolsEngine.engine.dispose();\r\n }\r\n DumpTools._DumpToolsEngine = null;\r\n }\r\n}\r\n\r\n/**\r\n * This will be executed automatically for UMD and es5.\r\n * If esm dev wants the side effects to execute they will have to run it manually\r\n * Once we build native modules those need to be exported.\r\n * @internal\r\n */\r\nconst initSideEffects = () => {\r\n // References the dependencies.\r\n Tools.DumpData = DumpTools.DumpData;\r\n Tools.DumpDataAsync = DumpTools.DumpDataAsync;\r\n Tools.DumpFramebuffer = DumpTools.DumpFramebuffer;\r\n};\r\n\r\ninitSideEffects();\r\n"]}
1
+ {"version":3,"file":"dumpTools.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/dumpTools.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5E,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAGhC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC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Q,GAAG,QAAQ,CAAC;IAC1B,KAAK,CAAC,aAAa,GAAG,aAAa,CAAC;IACpC,KAAK,CAAC,eAAe,GAAG,eAAe,CAAC;AAC5C,CAAC,CAAC;AAEF,eAAe,EAAE,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\r\nimport { _WarnImport } from \"./devTools\";\r\n\r\nimport { ThinEngine } from \"../Engines/thinEngine\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { EffectRenderer, EffectWrapper } from \"../Materials/effectRenderer\";\r\nimport { Tools } from \"./tools\";\r\nimport type { Nullable } from \"../types\";\r\n\r\nimport { passPixelShader } from \"../Shaders/pass.fragment\";\r\nimport { Scalar } from \"../Maths/math.scalar\";\r\nimport type { AbstractEngine } from \"../Engines/abstractEngine\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\n\r\ntype DumpToolsEngine = {\r\n canvas: HTMLCanvasElement | OffscreenCanvas;\r\n engine: ThinEngine;\r\n renderer: EffectRenderer;\r\n wrapper: EffectWrapper;\r\n};\r\n\r\nlet _dumpToolsEngine: Nullable<DumpToolsEngine>;\r\n\r\nfunction _CreateDumpRenderer(): DumpToolsEngine {\r\n if (!_dumpToolsEngine) {\r\n let canvas: HTMLCanvasElement | OffscreenCanvas;\r\n let engine: Nullable<ThinEngine> = null;\r\n const options = {\r\n preserveDrawingBuffer: true,\r\n depth: false,\r\n stencil: false,\r\n alpha: true,\r\n premultipliedAlpha: false,\r\n antialias: false,\r\n failIfMajorPerformanceCaveat: false,\r\n };\r\n try {\r\n canvas = new OffscreenCanvas(100, 100); // will be resized later\r\n engine = new ThinEngine(canvas, false, options);\r\n } catch (e) {\r\n // The browser either does not support OffscreenCanvas or WebGL context in OffscreenCanvas, fallback on a regular canvas\r\n canvas = document.createElement(\"canvas\");\r\n engine = new ThinEngine(canvas, false, options);\r\n }\r\n // remove this engine from the list of instances to avoid using it for other purposes\r\n EngineStore.Instances.pop();\r\n // However, make sure to dispose it when no other engines are left\r\n EngineStore.OnEnginesDisposedObservable.add((e) => {\r\n // guaranteed to run when no other instances are left\r\n // only dispose if it's not the current engine\r\n if (engine && e !== engine && !engine.isDisposed && EngineStore.Instances.length === 0) {\r\n // Dump the engine and the associated resources\r\n Dispose();\r\n }\r\n });\r\n engine.getCaps().parallelShaderCompile = undefined;\r\n const renderer = new EffectRenderer(engine);\r\n const wrapper = new EffectWrapper({\r\n engine,\r\n name: passPixelShader.name,\r\n fragmentShader: passPixelShader.shader,\r\n samplerNames: [\"textureSampler\"],\r\n });\r\n _dumpToolsEngine = {\r\n canvas,\r\n engine,\r\n renderer,\r\n wrapper,\r\n };\r\n }\r\n return _dumpToolsEngine;\r\n}\r\n\r\n/**\r\n * Dumps the current bound framebuffer\r\n * @param width defines the rendering width\r\n * @param height defines the rendering height\r\n * @param engine defines the hosting engine\r\n * @param successCallback defines the callback triggered once the data are available\r\n * @param mimeType defines the mime type of the result\r\n * @param fileName defines the filename to download. If present, the result will automatically be downloaded\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @returns a void promise\r\n */\r\nexport async function DumpFramebuffer(\r\n width: number,\r\n height: number,\r\n engine: AbstractEngine,\r\n successCallback?: (data: string) => void,\r\n mimeType = \"image/png\",\r\n fileName?: string,\r\n quality?: number\r\n) {\r\n // Read the contents of the framebuffer\r\n const bufferView = await engine.readPixels(0, 0, width, height);\r\n\r\n const data = new Uint8Array(bufferView.buffer);\r\n\r\n DumpData(width, height, data, successCallback as (data: string | ArrayBuffer) => void, mimeType, fileName, true, undefined, quality);\r\n}\r\n\r\n/**\r\n * Dumps an array buffer\r\n * @param width defines the rendering width\r\n * @param height defines the rendering height\r\n * @param data the data array\r\n * @param mimeType defines the mime type of the result\r\n * @param fileName defines the filename to download. If present, the result will automatically be downloaded\r\n * @param invertY true to invert the picture in the Y dimension\r\n * @param toArrayBuffer true to convert the data to an ArrayBuffer (encoded as `mimeType`) instead of a base64 string\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @returns a promise that resolve to the final data\r\n */\r\nexport function DumpDataAsync(\r\n width: number,\r\n height: number,\r\n data: ArrayBufferView,\r\n mimeType = \"image/png\",\r\n fileName?: string,\r\n invertY = false,\r\n toArrayBuffer = false,\r\n quality?: number\r\n): Promise<string | ArrayBuffer> {\r\n return new Promise((resolve) => {\r\n DumpData(width, height, data, (result) => resolve(result), mimeType, fileName, invertY, toArrayBuffer, quality);\r\n });\r\n}\r\n\r\n/**\r\n * Dumps an array buffer\r\n * @param width defines the rendering width\r\n * @param height defines the rendering height\r\n * @param data the data array\r\n * @param successCallback defines the callback triggered once the data are available\r\n * @param mimeType defines the mime type of the result\r\n * @param fileName defines the filename to download. If present, the result will automatically be downloaded\r\n * @param invertY true to invert the picture in the Y dimension\r\n * @param toArrayBuffer true to convert the data to an ArrayBuffer (encoded as `mimeType`) instead of a base64 string\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n */\r\nexport function DumpData(\r\n width: number,\r\n height: number,\r\n data: ArrayBufferView,\r\n successCallback?: (data: string | ArrayBuffer) => void,\r\n mimeType = \"image/png\",\r\n fileName?: string,\r\n invertY = false,\r\n toArrayBuffer = false,\r\n quality?: number\r\n) {\r\n const renderer = _CreateDumpRenderer();\r\n renderer.engine.setSize(width, height, true);\r\n\r\n // Convert if data are float32\r\n if (data instanceof Float32Array) {\r\n const data2 = new Uint8Array(data.length);\r\n let n = data.length;\r\n while (n--) {\r\n const v = data[n];\r\n data2[n] = Math.round(Scalar.Clamp(v) * 255);\r\n }\r\n data = data2;\r\n }\r\n\r\n // Create the image\r\n const texture = renderer.engine.createRawTexture(data, width, height, Constants.TEXTUREFORMAT_RGBA, false, !invertY, Constants.TEXTURE_NEAREST_NEAREST);\r\n\r\n renderer.renderer.setViewport();\r\n renderer.renderer.applyEffectWrapper(renderer.wrapper);\r\n renderer.wrapper.effect._bindTexture(\"textureSampler\", texture);\r\n renderer.renderer.draw();\r\n\r\n if (toArrayBuffer) {\r\n Tools.ToBlob(\r\n renderer.canvas,\r\n (blob) => {\r\n const fileReader = new FileReader();\r\n fileReader.onload = (event: any) => {\r\n const arrayBuffer = event.target!.result as ArrayBuffer;\r\n if (successCallback) {\r\n successCallback(arrayBuffer);\r\n }\r\n };\r\n fileReader.readAsArrayBuffer(blob!);\r\n },\r\n mimeType,\r\n quality\r\n );\r\n } else {\r\n Tools.EncodeScreenshotCanvasData(renderer.canvas, successCallback, mimeType, fileName, quality);\r\n }\r\n\r\n texture.dispose();\r\n}\r\n\r\n/**\r\n * Dispose the dump tools associated resources\r\n */\r\nexport function Dispose() {\r\n if (_dumpToolsEngine) {\r\n _dumpToolsEngine.wrapper.dispose();\r\n _dumpToolsEngine.renderer.dispose();\r\n _dumpToolsEngine.engine.dispose();\r\n }\r\n _dumpToolsEngine = null;\r\n}\r\n\r\n/**\r\n * Object containing a set of static utilities functions to dump data from a canvas\r\n * @deprecated use functions\r\n */\r\nexport const DumpTools = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n DumpData,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n DumpDataAsync,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n DumpFramebuffer,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n Dispose,\r\n};\r\n\r\n/**\r\n * This will be executed automatically for UMD and es5.\r\n * If esm dev wants the side effects to execute they will have to run it manually\r\n * Once we build native modules those need to be exported.\r\n * @internal\r\n */\r\nconst initSideEffects = () => {\r\n // References the dependencies.\r\n Tools.DumpData = DumpData;\r\n Tools.DumpDataAsync = DumpDataAsync;\r\n Tools.DumpFramebuffer = DumpFramebuffer;\r\n};\r\n\r\ninitSideEffects();\r\n"]}