@babylonjs/core 6.0.0 → 6.1.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.
Files changed (48) hide show
  1. package/Animations/animatable.js +4 -0
  2. package/Animations/animatable.js.map +1 -1
  3. package/Animations/runtimeAnimation.d.ts +0 -1
  4. package/Animations/runtimeAnimation.js +0 -1
  5. package/Animations/runtimeAnimation.js.map +1 -1
  6. package/Engines/Extensions/engine.cubeTexture.js +1 -1
  7. package/Engines/Extensions/engine.cubeTexture.js.map +1 -1
  8. package/Engines/Extensions/engine.multiRender.js +1 -1
  9. package/Engines/Extensions/engine.multiRender.js.map +1 -1
  10. package/Engines/engine.d.ts +7 -20
  11. package/Engines/thinEngine.d.ts +7 -1
  12. package/Engines/thinEngine.js +36 -19
  13. package/Engines/thinEngine.js.map +1 -1
  14. package/Layers/effectLayer.d.ts +15 -0
  15. package/Layers/effectLayer.js +21 -0
  16. package/Layers/effectLayer.js.map +1 -1
  17. package/Materials/Node/Blocks/index.d.ts +1 -0
  18. package/Materials/Node/Blocks/index.js +1 -0
  19. package/Materials/Node/Blocks/index.js.map +1 -1
  20. package/Materials/Node/Blocks/meshAttributeExistsBlock.d.ts +52 -0
  21. package/Materials/Node/Blocks/meshAttributeExistsBlock.js +199 -0
  22. package/Materials/Node/Blocks/meshAttributeExistsBlock.js.map +1 -0
  23. package/Materials/Node/nodeMaterial.d.ts +1 -0
  24. package/Materials/Node/nodeMaterial.js +5 -1
  25. package/Materials/Node/nodeMaterial.js.map +1 -1
  26. package/Materials/Textures/equiRectangularCubeTexture.d.ts +3 -1
  27. package/Materials/Textures/equiRectangularCubeTexture.js +3 -2
  28. package/Materials/Textures/equiRectangularCubeTexture.js.map +1 -1
  29. package/Materials/Textures/hdrCubeTexture.d.ts +2 -1
  30. package/Materials/Textures/hdrCubeTexture.js +3 -2
  31. package/Materials/Textures/hdrCubeTexture.js.map +1 -1
  32. package/Misc/HighDynamicRange/hdr.d.ts +1 -1
  33. package/Misc/HighDynamicRange/hdr.js +2 -2
  34. package/Misc/HighDynamicRange/hdr.js.map +1 -1
  35. package/Misc/HighDynamicRange/panoramaToCubemap.d.ts +1 -1
  36. package/Misc/HighDynamicRange/panoramaToCubemap.js +31 -23
  37. package/Misc/HighDynamicRange/panoramaToCubemap.js.map +1 -1
  38. package/Physics/v2/physicsBody.d.ts +2 -1
  39. package/Physics/v2/physicsBody.js.map +1 -1
  40. package/Rendering/prePassRenderer.d.ts +2 -0
  41. package/Rendering/prePassRenderer.js +12 -1
  42. package/Rendering/prePassRenderer.js.map +1 -1
  43. package/Shaders/ShadersInclude/screenSpaceRayTrace.js +1 -1
  44. package/Shaders/ShadersInclude/screenSpaceRayTrace.js.map +1 -1
  45. package/Shaders/glowMapGeneration.fragment.js +2 -2
  46. package/Shaders/glowMapGeneration.fragment.js.map +1 -1
  47. package/package.json +1 -1
  48. package/readme.md +2 -6
@@ -13,6 +13,8 @@ export declare class EquiRectangularCubeTexture extends BaseTexture {
13
13
  private _onError;
14
14
  /** The size of the cubemap. */
15
15
  private _size;
16
+ /** Whether to supersample the input image */
17
+ private _supersample;
16
18
  /** The buffer of the image. */
17
19
  private _buffer;
18
20
  /** The width of the input image. */
@@ -32,7 +34,7 @@ export declare class EquiRectangularCubeTexture extends BaseTexture {
32
34
  * @param onLoad — defines a callback called when texture is loaded
33
35
  * @param onError — defines a callback called if there is an error
34
36
  */
35
- constructor(url: string, scene: Scene, size: number, noMipmap?: boolean, gammaSpace?: boolean, onLoad?: Nullable<() => void>, onError?: Nullable<(message?: string, exception?: any) => void>);
37
+ constructor(url: string, scene: Scene, size: number, noMipmap?: boolean, gammaSpace?: boolean, onLoad?: Nullable<() => void>, onError?: Nullable<(message?: string, exception?: any) => void>, supersample?: boolean);
36
38
  /**
37
39
  * Load the image data, by putting the image on a canvas and extracting its buffer.
38
40
  * @param loadTextureCallback
@@ -20,7 +20,7 @@ export class EquiRectangularCubeTexture extends BaseTexture {
20
20
  * @param onLoad — defines a callback called when texture is loaded
21
21
  * @param onError — defines a callback called if there is an error
22
22
  */
23
- constructor(url, scene, size, noMipmap = false, gammaSpace = true, onLoad = null, onError = null) {
23
+ constructor(url, scene, size, noMipmap = false, gammaSpace = true, onLoad = null, onError = null, supersample = false) {
24
24
  super(scene);
25
25
  this._onLoad = null;
26
26
  this._onError = null;
@@ -31,6 +31,7 @@ export class EquiRectangularCubeTexture extends BaseTexture {
31
31
  this.name = url;
32
32
  this.url = url;
33
33
  this._size = size;
34
+ this._supersample = supersample;
34
35
  this._noMipmap = noMipmap;
35
36
  this.gammaSpace = gammaSpace;
36
37
  this._onLoad = onLoad;
@@ -87,7 +88,7 @@ export class EquiRectangularCubeTexture extends BaseTexture {
87
88
  const callback = () => {
88
89
  const imageData = this._getFloat32ArrayFromArrayBuffer(this._buffer);
89
90
  // Extract the raw linear data.
90
- const data = PanoramaToCubeMapTools.ConvertPanoramaToCubemap(imageData, this._width, this._height, this._size);
91
+ const data = PanoramaToCubeMapTools.ConvertPanoramaToCubemap(imageData, this._width, this._height, this._size, this._supersample);
91
92
  const results = [];
92
93
  // Push each faces.
93
94
  for (let i = 0; i < 6; i++) {
@@ -1 +1 @@
1
- {"version":3,"file":"equiRectangularCubeTexture.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Materials/Textures/equiRectangularCubeTexture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,+CAA+C,CAAC;AACvF,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,4CAA4C,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD;;GAEG;AACH,MAAM,OAAO,0BAA2B,SAAQ,WAAW;I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AC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC","sourcesContent":["import { PanoramaToCubeMapTools } from \"../../Misc/HighDynamicRange/panoramaToCubemap\";\r\nimport { BaseTexture } from \"./baseTexture\";\r\nimport { Texture } from \"./texture\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport \"../../Engines/Extensions/engine.rawTexture\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { LoadImage } from \"../../Misc/fileTools\";\r\n\r\n/**\r\n * This represents a texture coming from an equirectangular image supported by the web browser canvas.\r\n */\r\nexport class EquiRectangularCubeTexture extends BaseTexture {\r\n /** The six faces of the cube. */\r\n private static _FacesMapping = [\"right\", \"left\", \"up\", \"down\", \"front\", \"back\"];\r\n\r\n private _noMipmap: boolean;\r\n private _onLoad: Nullable<() => void> = null;\r\n private _onError: Nullable<() => void> = null;\r\n\r\n /** The size of the cubemap. */\r\n private _size: number;\r\n\r\n /** The buffer of the image. */\r\n private _buffer: ArrayBuffer;\r\n\r\n /** The width of the input image. */\r\n private _width: number;\r\n\r\n /** The height of the input image. */\r\n private _height: number;\r\n\r\n /** The URL to the image. */\r\n public url: string;\r\n\r\n /**\r\n * Instantiates an EquiRectangularCubeTexture from the following parameters.\r\n * @param url The location of the image\r\n * @param scene The scene the texture will be used in\r\n * @param size The cubemap desired size (the more it increases the longer the generation will be)\r\n * @param noMipmap Forces to not generate the mipmap if true\r\n * @param gammaSpace Specifies if the texture will be used in gamma or linear space\r\n * (the PBR material requires those textures in linear space, but the standard material would require them in Gamma space)\r\n * @param onLoad — defines a callback called when texture is loaded\r\n * @param onError — defines a callback called if there is an error\r\n */\r\n constructor(\r\n url: string,\r\n scene: Scene,\r\n size: number,\r\n noMipmap: boolean = false,\r\n gammaSpace: boolean = true,\r\n onLoad: Nullable<() => void> = null,\r\n onError: Nullable<(message?: string, exception?: any) => void> = null\r\n ) {\r\n super(scene);\r\n\r\n if (!url) {\r\n throw new Error(\"Image url is not set\");\r\n }\r\n\r\n this._coordinatesMode = Texture.CUBIC_MODE;\r\n this.name = url;\r\n this.url = url;\r\n this._size = size;\r\n this._noMipmap = noMipmap;\r\n this.gammaSpace = gammaSpace;\r\n this._onLoad = onLoad;\r\n this._onError = onError;\r\n\r\n this.hasAlpha = false;\r\n this.isCube = true;\r\n\r\n this._texture = this._getFromCache(url, this._noMipmap, undefined, undefined, undefined, this.isCube);\r\n\r\n if (!this._texture) {\r\n if (!scene.useDelayedTextureLoading) {\r\n this._loadImage(this._loadTexture.bind(this), this._onError);\r\n } else {\r\n this.delayLoadState = Constants.DELAYLOADSTATE_NOTLOADED;\r\n }\r\n } else if (onLoad) {\r\n if (this._texture.isReady) {\r\n Tools.SetImmediate(() => onLoad());\r\n } else {\r\n this._texture.onLoadedObservable.add(onLoad);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Load the image data, by putting the image on a canvas and extracting its buffer.\r\n * @param loadTextureCallback\r\n * @param onError\r\n */\r\n private _loadImage(loadTextureCallback: () => void, onError: Nullable<(message?: string, exception?: any) => void>): void {\r\n const canvas = document.createElement(\"canvas\");\r\n LoadImage(\r\n this.url,\r\n (image) => {\r\n this._width = image.width;\r\n this._height = image.height;\r\n canvas.width = this._width;\r\n canvas.height = this._height;\r\n\r\n const ctx = canvas.getContext(\"2d\") as CanvasRenderingContext2D;\r\n ctx.drawImage(image, 0, 0);\r\n\r\n const imageData = ctx.getImageData(0, 0, image.width, image.height);\r\n this._buffer = imageData.data.buffer as ArrayBuffer;\r\n\r\n canvas.remove();\r\n loadTextureCallback();\r\n },\r\n (_, e) => {\r\n if (onError) {\r\n onError(`${this.getClassName()} could not be loaded`, e);\r\n }\r\n },\r\n null\r\n );\r\n }\r\n\r\n /**\r\n * Convert the image buffer into a cubemap and create a CubeTexture.\r\n */\r\n private _loadTexture(): void {\r\n const scene = this.getScene();\r\n const callback = (): Nullable<ArrayBufferView[]> => {\r\n const imageData = this._getFloat32ArrayFromArrayBuffer(this._buffer);\r\n\r\n // Extract the raw linear data.\r\n const data = PanoramaToCubeMapTools.ConvertPanoramaToCubemap(imageData, this._width, this._height, this._size);\r\n\r\n const results = [];\r\n\r\n // Push each faces.\r\n for (let i = 0; i < 6; i++) {\r\n const dataFace = (data as any)[EquiRectangularCubeTexture._FacesMapping[i]];\r\n results.push(dataFace);\r\n }\r\n\r\n return results;\r\n };\r\n\r\n if (!scene) {\r\n return;\r\n }\r\n this._texture = scene\r\n .getEngine()\r\n .createRawCubeTextureFromUrl(\r\n this.url,\r\n scene,\r\n this._size,\r\n Constants.TEXTUREFORMAT_RGB,\r\n scene.getEngine().getCaps().textureFloat ? Constants.TEXTURETYPE_FLOAT : Constants.TEXTURETYPE_UNSIGNED_INTEGER,\r\n this._noMipmap,\r\n callback,\r\n null,\r\n this._onLoad,\r\n this._onError\r\n );\r\n }\r\n\r\n /**\r\n * Convert the ArrayBuffer into a Float32Array and drop the transparency channel.\r\n * @param buffer The ArrayBuffer that should be converted.\r\n * @returns The buffer as Float32Array.\r\n */\r\n private _getFloat32ArrayFromArrayBuffer(buffer: ArrayBuffer): Float32Array {\r\n const dataView = new DataView(buffer);\r\n const floatImageData = new Float32Array((buffer.byteLength * 3) / 4);\r\n\r\n let k = 0;\r\n for (let i = 0; i < buffer.byteLength; i++) {\r\n // We drop the transparency channel, because we do not need/want it\r\n if ((i + 1) % 4 !== 0) {\r\n floatImageData[k++] = dataView.getUint8(i) / 255;\r\n }\r\n }\r\n\r\n return floatImageData;\r\n }\r\n\r\n /**\r\n * Get the current class name of the texture useful for serialization or dynamic coding.\r\n * @returns \"EquiRectangularCubeTexture\"\r\n */\r\n public getClassName(): string {\r\n return \"EquiRectangularCubeTexture\";\r\n }\r\n\r\n /**\r\n * Create a clone of the current EquiRectangularCubeTexture and return it.\r\n * @returns A clone of the current EquiRectangularCubeTexture.\r\n */\r\n public clone(): EquiRectangularCubeTexture {\r\n const scene = this.getScene();\r\n if (!scene) {\r\n return this;\r\n }\r\n\r\n const newTexture = new EquiRectangularCubeTexture(this.url, scene, this._size, this._noMipmap, this.gammaSpace);\r\n\r\n // Base texture\r\n newTexture.level = this.level;\r\n newTexture.wrapU = this.wrapU;\r\n newTexture.wrapV = this.wrapV;\r\n newTexture.coordinatesIndex = this.coordinatesIndex;\r\n newTexture.coordinatesMode = this.coordinatesMode;\r\n\r\n return newTexture;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"equiRectangularCubeTexture.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Materials/Textures/equiRectangularCubeTexture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,+CAA+C,CAAC;AACvF,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,4CAA4C,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD;;GAEG;AACH,MAAM,OAAO,0BAA2B,SAAQ,WAAW;IA0BvD;;;;;;;;;;OAUG;IACH,YACI,GAAW,EACX,KAAY,EACZ,IAAY,EACZ,WAAoB,KAAK,EACzB,aAAsB,IAAI,EAC1B,SAA+B,IAAI,EACnC,UAAiE,IAAI,EACrE,WAAW,GAAG,KAAK;QAEnB,KAAK,CAAC,KAAK,CAAC,CAAC;QA1CT,YAAO,GAAyB,IAAI,CAAC;QACrC,aAAQ,GAAyB,IAAI,CAAC;QA2C1C,IAAI,CAAC,GAAG,EAAE;YACN,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;SAC3C;QAED,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC;QAC3C,IAAI,CAAC,IA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,KAAK,CAAC,EAAE;gBACnB,cAAc,CAAC,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;aACpD;SACJ;QAED,OAAO,cAAc,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACI,YAAY;QACf,OAAO,4BAA4B,CAAC;IACxC,CAAC;IAED;;;OAGG;IACI,KAAK;QACR,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;QAC9B,IAAI,CAAC,KAAK,EAAE;YACR,OAAO,IAAI,CAAC;SACf;QAED,MAAM,UAAU,GAAG,IAAI,0BAA0B,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAEhH,eAAe;QACf,UAAU,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QAC9B,UAAU,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QAC9B,UAAU,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QAC9B,UAAU,CAAC,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,CAAC;QACpD,UAAU,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;QAElD,OAAO,UAAU,CAAC;IACtB,CAAC;;AA5MD,iCAAiC;AAClB,wCAAa,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC","sourcesContent":["import { PanoramaToCubeMapTools } from \"../../Misc/HighDynamicRange/panoramaToCubemap\";\r\nimport { BaseTexture } from \"./baseTexture\";\r\nimport { Texture } from \"./texture\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport \"../../Engines/Extensions/engine.rawTexture\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { LoadImage } from \"../../Misc/fileTools\";\r\n\r\n/**\r\n * This represents a texture coming from an equirectangular image supported by the web browser canvas.\r\n */\r\nexport class EquiRectangularCubeTexture extends BaseTexture {\r\n /** The six faces of the cube. */\r\n private static _FacesMapping = [\"right\", \"left\", \"up\", \"down\", \"front\", \"back\"];\r\n\r\n private _noMipmap: boolean;\r\n private _onLoad: Nullable<() => void> = null;\r\n private _onError: Nullable<() => void> = null;\r\n\r\n /** The size of the cubemap. */\r\n private _size: number;\r\n\r\n /** Whether to supersample the input image */\r\n private _supersample: boolean;\r\n\r\n /** The buffer of the image. */\r\n private _buffer: ArrayBuffer;\r\n\r\n /** The width of the input image. */\r\n private _width: number;\r\n\r\n /** The height of the input image. */\r\n private _height: number;\r\n\r\n /** The URL to the image. */\r\n public url: string;\r\n\r\n /**\r\n * Instantiates an EquiRectangularCubeTexture from the following parameters.\r\n * @param url The location of the image\r\n * @param scene The scene the texture will be used in\r\n * @param size The cubemap desired size (the more it increases the longer the generation will be)\r\n * @param noMipmap Forces to not generate the mipmap if true\r\n * @param gammaSpace Specifies if the texture will be used in gamma or linear space\r\n * (the PBR material requires those textures in linear space, but the standard material would require them in Gamma space)\r\n * @param onLoad — defines a callback called when texture is loaded\r\n * @param onError — defines a callback called if there is an error\r\n */\r\n constructor(\r\n url: string,\r\n scene: Scene,\r\n size: number,\r\n noMipmap: boolean = false,\r\n gammaSpace: boolean = true,\r\n onLoad: Nullable<() => void> = null,\r\n onError: Nullable<(message?: string, exception?: any) => void> = null,\r\n supersample = false\r\n ) {\r\n super(scene);\r\n\r\n if (!url) {\r\n throw new Error(\"Image url is not set\");\r\n }\r\n\r\n this._coordinatesMode = Texture.CUBIC_MODE;\r\n this.name = url;\r\n this.url = url;\r\n this._size = size;\r\n this._supersample = supersample;\r\n this._noMipmap = noMipmap;\r\n this.gammaSpace = gammaSpace;\r\n this._onLoad = onLoad;\r\n this._onError = onError;\r\n\r\n this.hasAlpha = false;\r\n this.isCube = true;\r\n\r\n this._texture = this._getFromCache(url, this._noMipmap, undefined, undefined, undefined, this.isCube);\r\n\r\n if (!this._texture) {\r\n if (!scene.useDelayedTextureLoading) {\r\n this._loadImage(this._loadTexture.bind(this), this._onError);\r\n } else {\r\n this.delayLoadState = Constants.DELAYLOADSTATE_NOTLOADED;\r\n }\r\n } else if (onLoad) {\r\n if (this._texture.isReady) {\r\n Tools.SetImmediate(() => onLoad());\r\n } else {\r\n this._texture.onLoadedObservable.add(onLoad);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Load the image data, by putting the image on a canvas and extracting its buffer.\r\n * @param loadTextureCallback\r\n * @param onError\r\n */\r\n private _loadImage(loadTextureCallback: () => void, onError: Nullable<(message?: string, exception?: any) => void>): void {\r\n const canvas = document.createElement(\"canvas\");\r\n LoadImage(\r\n this.url,\r\n (image) => {\r\n this._width = image.width;\r\n this._height = image.height;\r\n canvas.width = this._width;\r\n canvas.height = this._height;\r\n\r\n const ctx = canvas.getContext(\"2d\") as CanvasRenderingContext2D;\r\n ctx.drawImage(image, 0, 0);\r\n\r\n const imageData = ctx.getImageData(0, 0, image.width, image.height);\r\n this._buffer = imageData.data.buffer as ArrayBuffer;\r\n\r\n canvas.remove();\r\n loadTextureCallback();\r\n },\r\n (_, e) => {\r\n if (onError) {\r\n onError(`${this.getClassName()} could not be loaded`, e);\r\n }\r\n },\r\n null\r\n );\r\n }\r\n\r\n /**\r\n * Convert the image buffer into a cubemap and create a CubeTexture.\r\n */\r\n private _loadTexture(): void {\r\n const scene = this.getScene();\r\n const callback = (): Nullable<ArrayBufferView[]> => {\r\n const imageData = this._getFloat32ArrayFromArrayBuffer(this._buffer);\r\n\r\n // Extract the raw linear data.\r\n const data = PanoramaToCubeMapTools.ConvertPanoramaToCubemap(imageData, this._width, this._height, this._size, this._supersample);\r\n\r\n const results = [];\r\n\r\n // Push each faces.\r\n for (let i = 0; i < 6; i++) {\r\n const dataFace = (data as any)[EquiRectangularCubeTexture._FacesMapping[i]];\r\n results.push(dataFace);\r\n }\r\n\r\n return results;\r\n };\r\n\r\n if (!scene) {\r\n return;\r\n }\r\n this._texture = scene\r\n .getEngine()\r\n .createRawCubeTextureFromUrl(\r\n this.url,\r\n scene,\r\n this._size,\r\n Constants.TEXTUREFORMAT_RGB,\r\n scene.getEngine().getCaps().textureFloat ? Constants.TEXTURETYPE_FLOAT : Constants.TEXTURETYPE_UNSIGNED_INTEGER,\r\n this._noMipmap,\r\n callback,\r\n null,\r\n this._onLoad,\r\n this._onError\r\n );\r\n }\r\n\r\n /**\r\n * Convert the ArrayBuffer into a Float32Array and drop the transparency channel.\r\n * @param buffer The ArrayBuffer that should be converted.\r\n * @returns The buffer as Float32Array.\r\n */\r\n private _getFloat32ArrayFromArrayBuffer(buffer: ArrayBuffer): Float32Array {\r\n const dataView = new DataView(buffer);\r\n const floatImageData = new Float32Array((buffer.byteLength * 3) / 4);\r\n\r\n let k = 0;\r\n for (let i = 0; i < buffer.byteLength; i++) {\r\n // We drop the transparency channel, because we do not need/want it\r\n if ((i + 1) % 4 !== 0) {\r\n floatImageData[k++] = dataView.getUint8(i) / 255;\r\n }\r\n }\r\n\r\n return floatImageData;\r\n }\r\n\r\n /**\r\n * Get the current class name of the texture useful for serialization or dynamic coding.\r\n * @returns \"EquiRectangularCubeTexture\"\r\n */\r\n public getClassName(): string {\r\n return \"EquiRectangularCubeTexture\";\r\n }\r\n\r\n /**\r\n * Create a clone of the current EquiRectangularCubeTexture and return it.\r\n * @returns A clone of the current EquiRectangularCubeTexture.\r\n */\r\n public clone(): EquiRectangularCubeTexture {\r\n const scene = this.getScene();\r\n if (!scene) {\r\n return this;\r\n }\r\n\r\n const newTexture = new EquiRectangularCubeTexture(this.url, scene, this._size, this._noMipmap, this.gammaSpace);\r\n\r\n // Base texture\r\n newTexture.level = this.level;\r\n newTexture.wrapU = this.wrapU;\r\n newTexture.wrapV = this.wrapV;\r\n newTexture.coordinatesIndex = this.coordinatesIndex;\r\n newTexture.coordinatesMode = this.coordinatesMode;\r\n\r\n return newTexture;\r\n }\r\n}\r\n"]}
@@ -19,6 +19,7 @@ export declare class HDRCubeTexture extends BaseTexture {
19
19
  private _prefilterOnLoad;
20
20
  private _textureMatrix;
21
21
  private _size;
22
+ private _supersample;
22
23
  private _onLoad;
23
24
  private _onError;
24
25
  /**
@@ -74,7 +75,7 @@ export declare class HDRCubeTexture extends BaseTexture {
74
75
  * @param onLoad
75
76
  * @param onError
76
77
  */
77
- constructor(url: string, sceneOrEngine: Scene | ThinEngine, size: number, noMipmap?: boolean, generateHarmonics?: boolean, gammaSpace?: boolean, prefilterOnLoad?: boolean, onLoad?: Nullable<() => void>, onError?: Nullable<(message?: string, exception?: any) => void>);
78
+ constructor(url: string, sceneOrEngine: Scene | ThinEngine, size: number, noMipmap?: boolean, generateHarmonics?: boolean, gammaSpace?: boolean, prefilterOnLoad?: boolean, onLoad?: Nullable<() => void>, onError?: Nullable<(message?: string, exception?: any) => void>, supersample?: boolean);
78
79
  /**
79
80
  * Get the current class name of the texture useful for serialization or dynamic coding.
80
81
  * @returns "HDRCubeTexture"
@@ -76,7 +76,7 @@ export class HDRCubeTexture extends BaseTexture {
76
76
  * @param onLoad
77
77
  * @param onError
78
78
  */
79
- constructor(url, sceneOrEngine, size, noMipmap = false, generateHarmonics = true, gammaSpace = false, prefilterOnLoad = false, onLoad = null, onError = null) {
79
+ constructor(url, sceneOrEngine, size, noMipmap = false, generateHarmonics = true, gammaSpace = false, prefilterOnLoad = false, onLoad = null, onError = null, supersample = false) {
80
80
  var _a;
81
81
  super(sceneOrEngine);
82
82
  this._generateHarmonics = true;
@@ -112,6 +112,7 @@ export class HDRCubeTexture extends BaseTexture {
112
112
  this.gammaSpace = gammaSpace;
113
113
  this._noMipmap = noMipmap;
114
114
  this._size = size;
115
+ this._supersample = supersample;
115
116
  this._generateHarmonics = generateHarmonics;
116
117
  this._texture = this._getFromCache(url, this._noMipmap, undefined, undefined, undefined, this.isCube);
117
118
  if (!this._texture) {
@@ -155,7 +156,7 @@ export class HDRCubeTexture extends BaseTexture {
155
156
  this.lodGenerationOffset = 0.0;
156
157
  this.lodGenerationScale = 0.8;
157
158
  // Extract the raw linear data.
158
- const data = HDRTools.GetCubeMapTextureData(buffer, this._size);
159
+ const data = HDRTools.GetCubeMapTextureData(buffer, this._size, this._supersample);
159
160
  // Generate harmonics if needed.
160
161
  if (this._generateHarmonics) {
161
162
  const sphericalPolynomial = CubeMapToSphericalPolynomialTools.ConvertCubeMapToSphericalPolynomial(data);
@@ -1 +1 @@
1
- {"version":3,"file":"hdrCubeTexture.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Materials/Textures/hdrCubeTexture.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,iCAAiC,EAAE,MAAM,0DAA0D,CAAC;AAC7G,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,4CAA4C,CAAC;AACpD,OAAO,iDAAiD,CAAC;AAEzD;;;;;GAKG;AACH,MAAM,OAAO,cAAe,SAAQ,WAAW;IAiB3C;;OAEG;IACH,IAAW,UAAU,CAAC,KAAc;QAChC,IAAI,CAAC,WAAW,GAAG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{ Nullable } from \"../../types\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Matrix, Vector3 } from \"../../Maths/math.vector\";\r\nimport { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport { Texture } from \"../../Materials/Textures/texture\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { HDRTools } from \"../../Misc/HighDynamicRange/hdr\";\r\nimport { CubeMapToSphericalPolynomialTools } from \"../../Misc/HighDynamicRange/cubemapToSphericalPolynomial\";\r\nimport { RegisterClass } from \"../../Misc/typeStore\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport { ToGammaSpace } from \"../../Maths/math.constants\";\r\nimport type { ThinEngine } from \"../../Engines/thinEngine\";\r\nimport { HDRFiltering } from \"../../Materials/Textures/Filtering/hdrFiltering\";\r\nimport { ToHalfFloat } from \"../../Misc/textureTools\";\r\nimport \"../../Engines/Extensions/engine.rawTexture\";\r\nimport \"../../Materials/Textures/baseTexture.polynomial\";\r\n\r\n/**\r\n * This represents a texture coming from an HDR input.\r\n *\r\n * The only supported format is currently panorama picture stored in RGBE format.\r\n * Example of such files can be found on Poly Haven: https://polyhaven.com/hdris\r\n */\r\nexport class HDRCubeTexture extends BaseTexture {\r\n private static _FacesMapping = [\"right\", \"left\", \"up\", \"down\", \"front\", \"back\"];\r\n\r\n private _generateHarmonics = true;\r\n private _noMipmap: boolean;\r\n private _prefilterOnLoad: boolean;\r\n private _textureMatrix: Matrix;\r\n private _size: number;\r\n private _onLoad: () => void;\r\n private _onError: Nullable<() => void> = null;\r\n\r\n /**\r\n * The texture URL.\r\n */\r\n public url: string;\r\n\r\n protected _isBlocking: boolean = true;\r\n /**\r\n * Sets whether or not the texture is blocking during loading.\r\n */\r\n public set isBlocking(value: boolean) {\r\n this._isBlocking = value;\r\n }\r\n /**\r\n * Gets whether or not the texture is blocking during loading.\r\n */\r\n public get isBlocking(): boolean {\r\n return this._isBlocking;\r\n }\r\n\r\n protected _rotationY: number = 0;\r\n /**\r\n * Sets texture matrix rotation angle around Y axis in radians.\r\n */\r\n public set rotationY(value: number) {\r\n this._rotationY = value;\r\n this.setReflectionTextureMatrix(Matrix.RotationY(this._rotationY));\r\n }\r\n /**\r\n * Gets texture matrix rotation angle around Y axis radians.\r\n */\r\n public get rotationY(): number {\r\n return this._rotationY;\r\n }\r\n\r\n /**\r\n * Gets or sets the center of the bounding box associated with the cube texture\r\n * It must define where the camera used to render the texture was set\r\n */\r\n public boundingBoxPosition = Vector3.Zero();\r\n\r\n private _boundingBoxSize: Vector3;\r\n\r\n /**\r\n * Gets or sets the size of the bounding box associated with the cube texture\r\n * When defined, the cubemap will switch to local mode\r\n * @see https://community.arm.com/graphics/b/blog/posts/reflections-based-on-local-cubemaps-in-unity\r\n * @example https://www.babylonjs-playground.com/#RNASML\r\n */\r\n public set boundingBoxSize(value: Vector3) {\r\n if (this._boundingBoxSize && this._boundingBoxSize.equals(value)) {\r\n return;\r\n }\r\n this._boundingBoxSize = value;\r\n const scene = this.getScene();\r\n if (scene) {\r\n scene.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n }\r\n public get boundingBoxSize(): Vector3 {\r\n return this._boundingBoxSize;\r\n }\r\n\r\n /**\r\n * Observable triggered once the texture has been loaded.\r\n */\r\n public onLoadObservable: Observable<HDRCubeTexture> = new Observable<HDRCubeTexture>();\r\n\r\n /**\r\n * Instantiates an HDRTexture from the following parameters.\r\n *\r\n * @param url The location of the HDR raw data (Panorama stored in RGBE format)\r\n * @param sceneOrEngine The scene or engine the texture will be used in\r\n * @param size The cubemap desired size (the more it increases the longer the generation will be)\r\n * @param noMipmap Forces to not generate the mipmap if true\r\n * @param generateHarmonics Specifies whether you want to extract the polynomial harmonics during the generation process\r\n * @param gammaSpace Specifies if the texture will be use in gamma or linear space (the PBR material requires those texture in linear space, but the standard material would require them in Gamma space)\r\n * @param prefilterOnLoad Prefilters HDR texture to allow use of this texture as a PBR reflection texture.\r\n * @param onLoad\r\n * @param onError\r\n */\r\n constructor(\r\n url: string,\r\n sceneOrEngine: Scene | ThinEngine,\r\n size: number,\r\n noMipmap = false,\r\n generateHarmonics = true,\r\n gammaSpace = false,\r\n prefilterOnLoad = false,\r\n onLoad: Nullable<() => void> = null,\r\n onError: Nullable<(message?: string, exception?: any) => void> = null\r\n ) {\r\n super(sceneOrEngine);\r\n\r\n if (!url) {\r\n return;\r\n }\r\n\r\n this._coordinatesMode = Texture.CUBIC_MODE;\r\n this.name = url;\r\n this.url = url;\r\n this.hasAlpha = false;\r\n this.isCube = true;\r\n this._textureMatrix = Matrix.Identity();\r\n this._prefilterOnLoad = prefilterOnLoad;\r\n this._onLoad = () => {\r\n this.onLoadObservable.notifyObservers(this);\r\n if (onLoad) {\r\n onLoad();\r\n }\r\n };\r\n\r\n this._onError = onError;\r\n this.gammaSpace = gammaSpace;\r\n\r\n this._noMipmap = noMipmap;\r\n this._size = size;\r\n this._generateHarmonics = generateHarmonics;\r\n\r\n this._texture = this._getFromCache(url, this._noMipmap, undefined, undefined, undefined, this.isCube);\r\n\r\n if (!this._texture) {\r\n if (!this.getScene()?.useDelayedTextureLoading) {\r\n this._loadTexture();\r\n } else {\r\n this.delayLoadState = Constants.DELAYLOADSTATE_NOTLOADED;\r\n }\r\n } else {\r\n if (this._texture.isReady) {\r\n Tools.SetImmediate(() => this._onLoad());\r\n } else {\r\n this._texture.onLoadedObservable.add(this._onLoad);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Get the current class name of the texture useful for serialization or dynamic coding.\r\n * @returns \"HDRCubeTexture\"\r\n */\r\n public getClassName(): string {\r\n return \"HDRCubeTexture\";\r\n }\r\n\r\n /**\r\n * Occurs when the file is raw .hdr file.\r\n */\r\n private _loadTexture() {\r\n const engine = this._getEngine()!;\r\n const caps = engine.getCaps();\r\n\r\n let textureType = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n if (caps.textureFloat && caps.textureFloatLinearFiltering) {\r\n textureType = Constants.TEXTURETYPE_FLOAT;\r\n } else if (caps.textureHalfFloat && caps.textureHalfFloatLinearFiltering) {\r\n textureType = Constants.TEXTURETYPE_HALF_FLOAT;\r\n }\r\n\r\n const callback = (buffer: ArrayBuffer): Nullable<ArrayBufferView[]> => {\r\n this.lodGenerationOffset = 0.0;\r\n this.lodGenerationScale = 0.8;\r\n\r\n // Extract the raw linear data.\r\n const data = HDRTools.GetCubeMapTextureData(buffer, this._size);\r\n\r\n // Generate harmonics if needed.\r\n if (this._generateHarmonics) {\r\n const sphericalPolynomial = CubeMapToSphericalPolynomialTools.ConvertCubeMapToSphericalPolynomial(data);\r\n this.sphericalPolynomial = sphericalPolynomial;\r\n }\r\n\r\n const results = [];\r\n\r\n let byteArray: Nullable<Uint8Array> = null;\r\n let shortArray: Nullable<Uint16Array> = null;\r\n\r\n // Push each faces.\r\n for (let j = 0; j < 6; j++) {\r\n // Create fallback array\r\n if (textureType === Constants.TEXTURETYPE_HALF_FLOAT) {\r\n shortArray = new Uint16Array(this._size * this._size * 3);\r\n } else if (textureType === Constants.TEXTURETYPE_UNSIGNED_BYTE) {\r\n // 3 channels of 1 bytes per pixel in bytes.\r\n byteArray = new Uint8Array(this._size * this._size * 3);\r\n }\r\n\r\n const dataFace = <Float32Array>(<any>data)[HDRCubeTexture._FacesMapping[j]];\r\n\r\n // If special cases.\r\n if (this.gammaSpace || shortArray || byteArray) {\r\n for (let i = 0; i < this._size * this._size; i++) {\r\n // Put in gamma space if requested.\r\n if (this.gammaSpace) {\r\n dataFace[i * 3 + 0] = Math.pow(dataFace[i * 3 + 0], ToGammaSpace);\r\n dataFace[i * 3 + 1] = Math.pow(dataFace[i * 3 + 1], ToGammaSpace);\r\n dataFace[i * 3 + 2] = Math.pow(dataFace[i * 3 + 2], ToGammaSpace);\r\n }\r\n\r\n // Convert to half float texture for fallback.\r\n if (shortArray) {\r\n shortArray[i * 3 + 0] = ToHalfFloat(dataFace[i * 3 + 0]);\r\n shortArray[i * 3 + 1] = ToHalfFloat(dataFace[i * 3 + 1]);\r\n shortArray[i * 3 + 2] = ToHalfFloat(dataFace[i * 3 + 2]);\r\n }\r\n\r\n // Convert to int texture for fallback.\r\n if (byteArray) {\r\n let r = Math.max(dataFace[i * 3 + 0] * 255, 0);\r\n let g = Math.max(dataFace[i * 3 + 1] * 255, 0);\r\n let b = Math.max(dataFace[i * 3 + 2] * 255, 0);\r\n\r\n // May use luminance instead if the result is not accurate.\r\n const max = Math.max(Math.max(r, g), b);\r\n if (max > 255) {\r\n const scale = 255 / max;\r\n r *= scale;\r\n g *= scale;\r\n b *= scale;\r\n }\r\n\r\n byteArray[i * 3 + 0] = r;\r\n byteArray[i * 3 + 1] = g;\r\n byteArray[i * 3 + 2] = b;\r\n }\r\n }\r\n }\r\n\r\n if (shortArray) {\r\n results.push(shortArray);\r\n } else if (byteArray) {\r\n results.push(byteArray);\r\n } else {\r\n results.push(dataFace);\r\n }\r\n }\r\n\r\n return results;\r\n };\r\n\r\n if (engine._features.allowTexturePrefiltering && this._prefilterOnLoad) {\r\n const previousOnLoad = this._onLoad;\r\n const hdrFiltering = new HDRFiltering(engine);\r\n this._onLoad = () => {\r\n hdrFiltering.prefilter(this, previousOnLoad);\r\n };\r\n }\r\n\r\n this._texture = engine.createRawCubeTextureFromUrl(\r\n this.url,\r\n this.getScene(),\r\n this._size,\r\n Constants.TEXTUREFORMAT_RGB,\r\n textureType,\r\n this._noMipmap,\r\n callback,\r\n null,\r\n this._onLoad,\r\n this._onError\r\n );\r\n }\r\n\r\n public clone(): HDRCubeTexture {\r\n const newTexture = new HDRCubeTexture(this.url, this.getScene() || this._getEngine()!, this._size, this._noMipmap, this._generateHarmonics, this.gammaSpace);\r\n\r\n // Base texture\r\n newTexture.level = this.level;\r\n newTexture.wrapU = this.wrapU;\r\n newTexture.wrapV = this.wrapV;\r\n newTexture.coordinatesIndex = this.coordinatesIndex;\r\n newTexture.coordinatesMode = this.coordinatesMode;\r\n\r\n return newTexture;\r\n }\r\n\r\n // Methods\r\n public delayLoad(): void {\r\n if (this.delayLoadState !== Constants.DELAYLOADSTATE_NOTLOADED) {\r\n return;\r\n }\r\n\r\n this.delayLoadState = Constants.DELAYLOADSTATE_LOADED;\r\n this._texture = this._getFromCache(this.url, this._noMipmap);\r\n\r\n if (!this._texture) {\r\n this._loadTexture();\r\n }\r\n }\r\n\r\n /**\r\n * Get the texture reflection matrix used to rotate/transform the reflection.\r\n * @returns the reflection matrix\r\n */\r\n public getReflectionTextureMatrix(): Matrix {\r\n return this._textureMatrix;\r\n }\r\n\r\n /**\r\n * Set the texture reflection matrix used to rotate/transform the reflection.\r\n * @param value Define the reflection matrix to set\r\n */\r\n public setReflectionTextureMatrix(value: Matrix): void {\r\n this._textureMatrix = value;\r\n\r\n if (value.updateFlag === this._textureMatrix.updateFlag) {\r\n return;\r\n }\r\n\r\n if (value.isIdentity() !== this._textureMatrix.isIdentity()) {\r\n this.getScene()?.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag, (mat) => mat.getActiveTextures().indexOf(this) !== -1);\r\n }\r\n }\r\n\r\n /**\r\n * Dispose the texture and release its associated resources.\r\n */\r\n public dispose(): void {\r\n this.onLoadObservable.clear();\r\n super.dispose();\r\n }\r\n\r\n /**\r\n * Parses a JSON representation of an HDR Texture in order to create the texture\r\n * @param parsedTexture Define the JSON representation\r\n * @param scene Define the scene the texture should be created in\r\n * @param rootUrl Define the root url in case we need to load relative dependencies\r\n * @returns the newly created texture after parsing\r\n */\r\n public static Parse(parsedTexture: any, scene: Scene, rootUrl: string): Nullable<HDRCubeTexture> {\r\n let texture = null;\r\n if (parsedTexture.name && !parsedTexture.isRenderTarget) {\r\n texture = new HDRCubeTexture(\r\n rootUrl + parsedTexture.name,\r\n scene,\r\n parsedTexture.size,\r\n parsedTexture.noMipmap,\r\n parsedTexture.generateHarmonics,\r\n parsedTexture.useInGammaSpace\r\n );\r\n texture.name = parsedTexture.name;\r\n texture.hasAlpha = parsedTexture.hasAlpha;\r\n texture.level = parsedTexture.level;\r\n texture.coordinatesMode = parsedTexture.coordinatesMode;\r\n texture.isBlocking = parsedTexture.isBlocking;\r\n }\r\n if (texture) {\r\n if (parsedTexture.boundingBoxPosition) {\r\n (<any>texture).boundingBoxPosition = Vector3.FromArray(parsedTexture.boundingBoxPosition);\r\n }\r\n if (parsedTexture.boundingBoxSize) {\r\n (<any>texture).boundingBoxSize = Vector3.FromArray(parsedTexture.boundingBoxSize);\r\n }\r\n if (parsedTexture.rotationY) {\r\n (<any>texture).rotationY = parsedTexture.rotationY;\r\n }\r\n }\r\n return texture;\r\n }\r\n\r\n public serialize(): any {\r\n if (!this.name) {\r\n return null;\r\n }\r\n\r\n const serializationObject: any = {};\r\n serializationObject.name = this.name;\r\n serializationObject.hasAlpha = this.hasAlpha;\r\n serializationObject.isCube = true;\r\n serializationObject.level = this.level;\r\n serializationObject.size = this._size;\r\n serializationObject.coordinatesMode = this.coordinatesMode;\r\n serializationObject.useInGammaSpace = this.gammaSpace;\r\n serializationObject.generateHarmonics = this._generateHarmonics;\r\n serializationObject.customType = \"BABYLON.HDRCubeTexture\";\r\n serializationObject.noMipmap = this._noMipmap;\r\n serializationObject.isBlocking = this._isBlocking;\r\n serializationObject.rotationY = this._rotationY;\r\n\r\n return serializationObject;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.HDRCubeTexture\", HDRCubeTexture);\r\n"]}
1
+ {"version":3,"file":"hdrCubeTexture.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Materials/Textures/hdrCubeTexture.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AA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AI,CAAC,KAAK,CAAC;QACtC,mBAAmB,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;QAC3D,mBAAmB,CAAC,eAAe,GAAG,IAAI,CAAC,UAAU,CAAC;QACtD,mBAAmB,CAAC,iBAAiB,GAAG,IAAI,CAAC,kBAAkB,CAAC;QAChE,mBAAmB,CAAC,UAAU,GAAG,wBAAwB,CAAC;QAC1D,mBAAmB,CAAC,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC;QAC9C,mBAAmB,CAAC,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC;QAClD,mBAAmB,CAAC,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC;QAEhD,OAAO,mBAAmB,CAAC;IAC/B,CAAC;;AAtYc,4BAAa,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AAyYpF,aAAa,CAAC,wBAAwB,EAAE,cAAc,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"../../types\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Matrix, Vector3 } from \"../../Maths/math.vector\";\r\nimport { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport { Texture } from \"../../Materials/Textures/texture\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { HDRTools } from \"../../Misc/HighDynamicRange/hdr\";\r\nimport { CubeMapToSphericalPolynomialTools } from \"../../Misc/HighDynamicRange/cubemapToSphericalPolynomial\";\r\nimport { RegisterClass } from \"../../Misc/typeStore\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport { ToGammaSpace } from \"../../Maths/math.constants\";\r\nimport type { ThinEngine } from \"../../Engines/thinEngine\";\r\nimport { HDRFiltering } from \"../../Materials/Textures/Filtering/hdrFiltering\";\r\nimport { ToHalfFloat } from \"../../Misc/textureTools\";\r\nimport \"../../Engines/Extensions/engine.rawTexture\";\r\nimport \"../../Materials/Textures/baseTexture.polynomial\";\r\n\r\n/**\r\n * This represents a texture coming from an HDR input.\r\n *\r\n * The only supported format is currently panorama picture stored in RGBE format.\r\n * Example of such files can be found on Poly Haven: https://polyhaven.com/hdris\r\n */\r\nexport class HDRCubeTexture extends BaseTexture {\r\n private static _FacesMapping = [\"right\", \"left\", \"up\", \"down\", \"front\", \"back\"];\r\n\r\n private _generateHarmonics = true;\r\n private _noMipmap: boolean;\r\n private _prefilterOnLoad: boolean;\r\n private _textureMatrix: Matrix;\r\n private _size: number;\r\n private _supersample: boolean;\r\n private _onLoad: () => void;\r\n private _onError: Nullable<() => void> = null;\r\n\r\n /**\r\n * The texture URL.\r\n */\r\n public url: string;\r\n\r\n protected _isBlocking: boolean = true;\r\n /**\r\n * Sets whether or not the texture is blocking during loading.\r\n */\r\n public set isBlocking(value: boolean) {\r\n this._isBlocking = value;\r\n }\r\n /**\r\n * Gets whether or not the texture is blocking during loading.\r\n */\r\n public get isBlocking(): boolean {\r\n return this._isBlocking;\r\n }\r\n\r\n protected _rotationY: number = 0;\r\n /**\r\n * Sets texture matrix rotation angle around Y axis in radians.\r\n */\r\n public set rotationY(value: number) {\r\n this._rotationY = value;\r\n this.setReflectionTextureMatrix(Matrix.RotationY(this._rotationY));\r\n }\r\n /**\r\n * Gets texture matrix rotation angle around Y axis radians.\r\n */\r\n public get rotationY(): number {\r\n return this._rotationY;\r\n }\r\n\r\n /**\r\n * Gets or sets the center of the bounding box associated with the cube texture\r\n * It must define where the camera used to render the texture was set\r\n */\r\n public boundingBoxPosition = Vector3.Zero();\r\n\r\n private _boundingBoxSize: Vector3;\r\n\r\n /**\r\n * Gets or sets the size of the bounding box associated with the cube texture\r\n * When defined, the cubemap will switch to local mode\r\n * @see https://community.arm.com/graphics/b/blog/posts/reflections-based-on-local-cubemaps-in-unity\r\n * @example https://www.babylonjs-playground.com/#RNASML\r\n */\r\n public set boundingBoxSize(value: Vector3) {\r\n if (this._boundingBoxSize && this._boundingBoxSize.equals(value)) {\r\n return;\r\n }\r\n this._boundingBoxSize = value;\r\n const scene = this.getScene();\r\n if (scene) {\r\n scene.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);\r\n }\r\n }\r\n public get boundingBoxSize(): Vector3 {\r\n return this._boundingBoxSize;\r\n }\r\n\r\n /**\r\n * Observable triggered once the texture has been loaded.\r\n */\r\n public onLoadObservable: Observable<HDRCubeTexture> = new Observable<HDRCubeTexture>();\r\n\r\n /**\r\n * Instantiates an HDRTexture from the following parameters.\r\n *\r\n * @param url The location of the HDR raw data (Panorama stored in RGBE format)\r\n * @param sceneOrEngine The scene or engine the texture will be used in\r\n * @param size The cubemap desired size (the more it increases the longer the generation will be)\r\n * @param noMipmap Forces to not generate the mipmap if true\r\n * @param generateHarmonics Specifies whether you want to extract the polynomial harmonics during the generation process\r\n * @param gammaSpace Specifies if the texture will be use in gamma or linear space (the PBR material requires those texture in linear space, but the standard material would require them in Gamma space)\r\n * @param prefilterOnLoad Prefilters HDR texture to allow use of this texture as a PBR reflection texture.\r\n * @param onLoad\r\n * @param onError\r\n */\r\n constructor(\r\n url: string,\r\n sceneOrEngine: Scene | ThinEngine,\r\n size: number,\r\n noMipmap = false,\r\n generateHarmonics = true,\r\n gammaSpace = false,\r\n prefilterOnLoad = false,\r\n onLoad: Nullable<() => void> = null,\r\n onError: Nullable<(message?: string, exception?: any) => void> = null,\r\n supersample = false\r\n ) {\r\n super(sceneOrEngine);\r\n\r\n if (!url) {\r\n return;\r\n }\r\n\r\n this._coordinatesMode = Texture.CUBIC_MODE;\r\n this.name = url;\r\n this.url = url;\r\n this.hasAlpha = false;\r\n this.isCube = true;\r\n this._textureMatrix = Matrix.Identity();\r\n this._prefilterOnLoad = prefilterOnLoad;\r\n this._onLoad = () => {\r\n this.onLoadObservable.notifyObservers(this);\r\n if (onLoad) {\r\n onLoad();\r\n }\r\n };\r\n\r\n this._onError = onError;\r\n this.gammaSpace = gammaSpace;\r\n\r\n this._noMipmap = noMipmap;\r\n this._size = size;\r\n this._supersample = supersample;\r\n this._generateHarmonics = generateHarmonics;\r\n\r\n this._texture = this._getFromCache(url, this._noMipmap, undefined, undefined, undefined, this.isCube);\r\n\r\n if (!this._texture) {\r\n if (!this.getScene()?.useDelayedTextureLoading) {\r\n this._loadTexture();\r\n } else {\r\n this.delayLoadState = Constants.DELAYLOADSTATE_NOTLOADED;\r\n }\r\n } else {\r\n if (this._texture.isReady) {\r\n Tools.SetImmediate(() => this._onLoad());\r\n } else {\r\n this._texture.onLoadedObservable.add(this._onLoad);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Get the current class name of the texture useful for serialization or dynamic coding.\r\n * @returns \"HDRCubeTexture\"\r\n */\r\n public getClassName(): string {\r\n return \"HDRCubeTexture\";\r\n }\r\n\r\n /**\r\n * Occurs when the file is raw .hdr file.\r\n */\r\n private _loadTexture() {\r\n const engine = this._getEngine()!;\r\n const caps = engine.getCaps();\r\n\r\n let textureType = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n if (caps.textureFloat && caps.textureFloatLinearFiltering) {\r\n textureType = Constants.TEXTURETYPE_FLOAT;\r\n } else if (caps.textureHalfFloat && caps.textureHalfFloatLinearFiltering) {\r\n textureType = Constants.TEXTURETYPE_HALF_FLOAT;\r\n }\r\n\r\n const callback = (buffer: ArrayBuffer): Nullable<ArrayBufferView[]> => {\r\n this.lodGenerationOffset = 0.0;\r\n this.lodGenerationScale = 0.8;\r\n\r\n // Extract the raw linear data.\r\n const data = HDRTools.GetCubeMapTextureData(buffer, this._size, this._supersample);\r\n\r\n // Generate harmonics if needed.\r\n if (this._generateHarmonics) {\r\n const sphericalPolynomial = CubeMapToSphericalPolynomialTools.ConvertCubeMapToSphericalPolynomial(data);\r\n this.sphericalPolynomial = sphericalPolynomial;\r\n }\r\n\r\n const results = [];\r\n\r\n let byteArray: Nullable<Uint8Array> = null;\r\n let shortArray: Nullable<Uint16Array> = null;\r\n\r\n // Push each faces.\r\n for (let j = 0; j < 6; j++) {\r\n // Create fallback array\r\n if (textureType === Constants.TEXTURETYPE_HALF_FLOAT) {\r\n shortArray = new Uint16Array(this._size * this._size * 3);\r\n } else if (textureType === Constants.TEXTURETYPE_UNSIGNED_BYTE) {\r\n // 3 channels of 1 bytes per pixel in bytes.\r\n byteArray = new Uint8Array(this._size * this._size * 3);\r\n }\r\n\r\n const dataFace = <Float32Array>(<any>data)[HDRCubeTexture._FacesMapping[j]];\r\n\r\n // If special cases.\r\n if (this.gammaSpace || shortArray || byteArray) {\r\n for (let i = 0; i < this._size * this._size; i++) {\r\n // Put in gamma space if requested.\r\n if (this.gammaSpace) {\r\n dataFace[i * 3 + 0] = Math.pow(dataFace[i * 3 + 0], ToGammaSpace);\r\n dataFace[i * 3 + 1] = Math.pow(dataFace[i * 3 + 1], ToGammaSpace);\r\n dataFace[i * 3 + 2] = Math.pow(dataFace[i * 3 + 2], ToGammaSpace);\r\n }\r\n\r\n // Convert to half float texture for fallback.\r\n if (shortArray) {\r\n shortArray[i * 3 + 0] = ToHalfFloat(dataFace[i * 3 + 0]);\r\n shortArray[i * 3 + 1] = ToHalfFloat(dataFace[i * 3 + 1]);\r\n shortArray[i * 3 + 2] = ToHalfFloat(dataFace[i * 3 + 2]);\r\n }\r\n\r\n // Convert to int texture for fallback.\r\n if (byteArray) {\r\n let r = Math.max(dataFace[i * 3 + 0] * 255, 0);\r\n let g = Math.max(dataFace[i * 3 + 1] * 255, 0);\r\n let b = Math.max(dataFace[i * 3 + 2] * 255, 0);\r\n\r\n // May use luminance instead if the result is not accurate.\r\n const max = Math.max(Math.max(r, g), b);\r\n if (max > 255) {\r\n const scale = 255 / max;\r\n r *= scale;\r\n g *= scale;\r\n b *= scale;\r\n }\r\n\r\n byteArray[i * 3 + 0] = r;\r\n byteArray[i * 3 + 1] = g;\r\n byteArray[i * 3 + 2] = b;\r\n }\r\n }\r\n }\r\n\r\n if (shortArray) {\r\n results.push(shortArray);\r\n } else if (byteArray) {\r\n results.push(byteArray);\r\n } else {\r\n results.push(dataFace);\r\n }\r\n }\r\n\r\n return results;\r\n };\r\n\r\n if (engine._features.allowTexturePrefiltering && this._prefilterOnLoad) {\r\n const previousOnLoad = this._onLoad;\r\n const hdrFiltering = new HDRFiltering(engine);\r\n this._onLoad = () => {\r\n hdrFiltering.prefilter(this, previousOnLoad);\r\n };\r\n }\r\n\r\n this._texture = engine.createRawCubeTextureFromUrl(\r\n this.url,\r\n this.getScene(),\r\n this._size,\r\n Constants.TEXTUREFORMAT_RGB,\r\n textureType,\r\n this._noMipmap,\r\n callback,\r\n null,\r\n this._onLoad,\r\n this._onError\r\n );\r\n }\r\n\r\n public clone(): HDRCubeTexture {\r\n const newTexture = new HDRCubeTexture(this.url, this.getScene() || this._getEngine()!, this._size, this._noMipmap, this._generateHarmonics, this.gammaSpace);\r\n\r\n // Base texture\r\n newTexture.level = this.level;\r\n newTexture.wrapU = this.wrapU;\r\n newTexture.wrapV = this.wrapV;\r\n newTexture.coordinatesIndex = this.coordinatesIndex;\r\n newTexture.coordinatesMode = this.coordinatesMode;\r\n\r\n return newTexture;\r\n }\r\n\r\n // Methods\r\n public delayLoad(): void {\r\n if (this.delayLoadState !== Constants.DELAYLOADSTATE_NOTLOADED) {\r\n return;\r\n }\r\n\r\n this.delayLoadState = Constants.DELAYLOADSTATE_LOADED;\r\n this._texture = this._getFromCache(this.url, this._noMipmap);\r\n\r\n if (!this._texture) {\r\n this._loadTexture();\r\n }\r\n }\r\n\r\n /**\r\n * Get the texture reflection matrix used to rotate/transform the reflection.\r\n * @returns the reflection matrix\r\n */\r\n public getReflectionTextureMatrix(): Matrix {\r\n return this._textureMatrix;\r\n }\r\n\r\n /**\r\n * Set the texture reflection matrix used to rotate/transform the reflection.\r\n * @param value Define the reflection matrix to set\r\n */\r\n public setReflectionTextureMatrix(value: Matrix): void {\r\n this._textureMatrix = value;\r\n\r\n if (value.updateFlag === this._textureMatrix.updateFlag) {\r\n return;\r\n }\r\n\r\n if (value.isIdentity() !== this._textureMatrix.isIdentity()) {\r\n this.getScene()?.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag, (mat) => mat.getActiveTextures().indexOf(this) !== -1);\r\n }\r\n }\r\n\r\n /**\r\n * Dispose the texture and release its associated resources.\r\n */\r\n public dispose(): void {\r\n this.onLoadObservable.clear();\r\n super.dispose();\r\n }\r\n\r\n /**\r\n * Parses a JSON representation of an HDR Texture in order to create the texture\r\n * @param parsedTexture Define the JSON representation\r\n * @param scene Define the scene the texture should be created in\r\n * @param rootUrl Define the root url in case we need to load relative dependencies\r\n * @returns the newly created texture after parsing\r\n */\r\n public static Parse(parsedTexture: any, scene: Scene, rootUrl: string): Nullable<HDRCubeTexture> {\r\n let texture = null;\r\n if (parsedTexture.name && !parsedTexture.isRenderTarget) {\r\n texture = new HDRCubeTexture(\r\n rootUrl + parsedTexture.name,\r\n scene,\r\n parsedTexture.size,\r\n parsedTexture.noMipmap,\r\n parsedTexture.generateHarmonics,\r\n parsedTexture.useInGammaSpace\r\n );\r\n texture.name = parsedTexture.name;\r\n texture.hasAlpha = parsedTexture.hasAlpha;\r\n texture.level = parsedTexture.level;\r\n texture.coordinatesMode = parsedTexture.coordinatesMode;\r\n texture.isBlocking = parsedTexture.isBlocking;\r\n }\r\n if (texture) {\r\n if (parsedTexture.boundingBoxPosition) {\r\n (<any>texture).boundingBoxPosition = Vector3.FromArray(parsedTexture.boundingBoxPosition);\r\n }\r\n if (parsedTexture.boundingBoxSize) {\r\n (<any>texture).boundingBoxSize = Vector3.FromArray(parsedTexture.boundingBoxSize);\r\n }\r\n if (parsedTexture.rotationY) {\r\n (<any>texture).rotationY = parsedTexture.rotationY;\r\n }\r\n }\r\n return texture;\r\n }\r\n\r\n public serialize(): any {\r\n if (!this.name) {\r\n return null;\r\n }\r\n\r\n const serializationObject: any = {};\r\n serializationObject.name = this.name;\r\n serializationObject.hasAlpha = this.hasAlpha;\r\n serializationObject.isCube = true;\r\n serializationObject.level = this.level;\r\n serializationObject.size = this._size;\r\n serializationObject.coordinatesMode = this.coordinatesMode;\r\n serializationObject.useInGammaSpace = this.gammaSpace;\r\n serializationObject.generateHarmonics = this._generateHarmonics;\r\n serializationObject.customType = \"BABYLON.HDRCubeTexture\";\r\n serializationObject.noMipmap = this._noMipmap;\r\n serializationObject.isBlocking = this._isBlocking;\r\n serializationObject.rotationY = this._rotationY;\r\n\r\n return serializationObject;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.HDRCubeTexture\", HDRCubeTexture);\r\n"]}
@@ -43,7 +43,7 @@ export declare class HDRTools {
43
43
  * @param size The expected size of the extracted cubemap.
44
44
  * @returns The Cube Map information.
45
45
  */
46
- static GetCubeMapTextureData(buffer: ArrayBuffer, size: number): CubeMapInfo;
46
+ static GetCubeMapTextureData(buffer: ArrayBuffer, size: number, supersample?: boolean): CubeMapInfo;
47
47
  /**
48
48
  * Returns the pixels data extracted from an RGBE texture.
49
49
  * This pixels will be stored left to right up to down in the R G B order in one array.
@@ -101,11 +101,11 @@ export class HDRTools {
101
101
  * @param size The expected size of the extracted cubemap.
102
102
  * @returns The Cube Map information.
103
103
  */
104
- static GetCubeMapTextureData(buffer, size) {
104
+ static GetCubeMapTextureData(buffer, size, supersample = false) {
105
105
  const uint8array = new Uint8Array(buffer);
106
106
  const hdrInfo = this.RGBE_ReadHeader(uint8array);
107
107
  const data = this.RGBE_ReadPixels(uint8array, hdrInfo);
108
- const cubeMapData = PanoramaToCubeMapTools.ConvertPanoramaToCubemap(data, hdrInfo.width, hdrInfo.height, size);
108
+ const cubeMapData = PanoramaToCubeMapTools.ConvertPanoramaToCubemap(data, hdrInfo.width, hdrInfo.height, size, supersample);
109
109
  return cubeMapData;
110
110
  }
111
111
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"hdr.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Misc/HighDynamicRange/hdr.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAsB7D;;GAEG;AACH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C;QAC7E,MAAM,WAAW,GAAG,IAAI,YAAY,CAAC,YAAY,CAAC,CAAC;QAEnD,mCAAmC;QACnC,OAAO,aAAa,GAAG,CAAC,EAAE;YACtB,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;gBAChC,CAAC,GAAG,UAAU,CAAC,SAAS,EAAE,CAAC,CAAC;gBAC5B,CAAC,GAAG,UAAU,CAAC,SAAS,EAAE,CAAC,CAAC;gBAC5B,CAAC,GAAG,UAAU,CAAC,SAAS,EAAE,CAAC,CAAC;gBAC5B,CAAC,GAAG,UAAU,CAAC,SAAS,EAAE,CAAC,CAAC;gBAE5B,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,GAAG,aAAa,CAAC,GAAG,cAAc,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;aAC5G;YAED,aAAa,EAAE,CAAC;SACnB;QAED,OAAO,WAAW,CAAC;IACvB,CAAC;CACJ","sourcesContent":["import type { CubeMapInfo } from \"./panoramaToCubemap\";\r\nimport { PanoramaToCubeMapTools } from \"./panoramaToCubemap\";\r\n\r\n/**\r\n * Header information of HDR texture files.\r\n */\r\nexport interface HDRInfo {\r\n /**\r\n * The height of the texture in pixels.\r\n */\r\n height: number;\r\n\r\n /**\r\n * The width of the texture in pixels.\r\n */\r\n width: number;\r\n\r\n /**\r\n * The index of the beginning of the data in the binary file.\r\n */\r\n dataPosition: number;\r\n}\r\n\r\n/**\r\n * This groups tools to convert HDR texture to native colors array.\r\n */\r\nexport class HDRTools {\r\n private static _Ldexp(mantissa: number, exponent: number): number {\r\n if (exponent > 1023) {\r\n return mantissa * Math.pow(2, 1023) * Math.pow(2, exponent - 1023);\r\n }\r\n\r\n if (exponent < -1074) {\r\n return mantissa * Math.pow(2, -1074) * Math.pow(2, exponent + 1074);\r\n }\r\n\r\n return mantissa * Math.pow(2, exponent);\r\n }\r\n\r\n private static _Rgbe2float(float32array: Float32Array, red: number, green: number, blue: number, exponent: number, index: number) {\r\n if (exponent > 0) {\r\n /*nonzero pixel*/\r\n exponent = this._Ldexp(1.0, exponent - (128 + 8));\r\n\r\n float32array[index + 0] = red * exponent;\r\n float32array[index + 1] = green * exponent;\r\n float32array[index + 2] = blue * exponent;\r\n } else {\r\n float32array[index + 0] = 0;\r\n float32array[index + 1] = 0;\r\n float32array[index + 2] = 0;\r\n }\r\n }\r\n\r\n private static _ReadStringLine(uint8array: Uint8Array, startIndex: number): string {\r\n let line = \"\";\r\n let character = \"\";\r\n\r\n for (let i = startIndex; i < uint8array.length - startIndex; i++) {\r\n character = String.fromCharCode(uint8array[i]);\r\n\r\n if (character == \"\\n\") {\r\n break;\r\n }\r\n\r\n line += character;\r\n }\r\n\r\n return line;\r\n }\r\n\r\n /**\r\n * Reads header information from an RGBE texture stored in a native array.\r\n * More information on this format are available here:\r\n * https://en.wikipedia.org/wiki/RGBE_image_format\r\n *\r\n * @param uint8array The binary file stored in native array.\r\n * @returns The header information.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public static RGBE_ReadHeader(uint8array: Uint8Array): HDRInfo {\r\n let height: number = 0;\r\n let width: number = 0;\r\n\r\n let line = this._ReadStringLine(uint8array, 0);\r\n if (line[0] != \"#\" || line[1] != \"?\") {\r\n throw \"Bad HDR Format.\";\r\n }\r\n\r\n let endOfHeader = false;\r\n let findFormat = false;\r\n let lineIndex: number = 0;\r\n\r\n do {\r\n lineIndex += line.length + 1;\r\n line = this._ReadStringLine(uint8array, lineIndex);\r\n\r\n if (line == \"FORMAT=32-bit_rle_rgbe\") {\r\n findFormat = true;\r\n } else if (line.length == 0) {\r\n endOfHeader = true;\r\n }\r\n } while (!endOfHeader);\r\n\r\n if (!findFormat) {\r\n throw \"HDR Bad header format, unsupported FORMAT\";\r\n }\r\n\r\n lineIndex += line.length + 1;\r\n line = this._ReadStringLine(uint8array, lineIndex);\r\n\r\n const sizeRegexp = /^-Y (.*) \\+X (.*)$/g;\r\n const match = sizeRegexp.exec(line);\r\n\r\n // TODO. Support +Y and -X if needed.\r\n if (!match || match.length < 3) {\r\n throw \"HDR Bad header format, no size\";\r\n }\r\n width = parseInt(match[2]);\r\n height = parseInt(match[1]);\r\n\r\n if (width < 8 || width > 0x7fff) {\r\n throw \"HDR Bad header format, unsupported size\";\r\n }\r\n\r\n lineIndex += line.length + 1;\r\n\r\n return {\r\n height: height,\r\n width: width,\r\n dataPosition: lineIndex,\r\n };\r\n }\r\n\r\n /**\r\n * Returns the cubemap information (each faces texture data) extracted from an RGBE texture.\r\n * This RGBE texture needs to store the information as a panorama.\r\n *\r\n * More information on this format are available here:\r\n * https://en.wikipedia.org/wiki/RGBE_image_format\r\n *\r\n * @param buffer The binary file stored in an array buffer.\r\n * @param size The expected size of the extracted cubemap.\r\n * @returns The Cube Map information.\r\n */\r\n public static GetCubeMapTextureData(buffer: ArrayBuffer, size: number): CubeMapInfo {\r\n const uint8array = new Uint8Array(buffer);\r\n const hdrInfo = this.RGBE_ReadHeader(uint8array);\r\n const data = this.RGBE_ReadPixels(uint8array, hdrInfo);\r\n\r\n const cubeMapData = PanoramaToCubeMapTools.ConvertPanoramaToCubemap(data, hdrInfo.width, hdrInfo.height, size);\r\n\r\n return cubeMapData;\r\n }\r\n\r\n /**\r\n * Returns the pixels data extracted from an RGBE texture.\r\n * This pixels will be stored left to right up to down in the R G B order in one array.\r\n *\r\n * More information on this format are available here:\r\n * https://en.wikipedia.org/wiki/RGBE_image_format\r\n *\r\n * @param uint8array The binary file stored in an array buffer.\r\n * @param hdrInfo The header information of the file.\r\n * @returns The pixels data in RGB right to left up to down order.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public static RGBE_ReadPixels(uint8array: Uint8Array, hdrInfo: HDRInfo): Float32Array {\r\n return this._RGBEReadPixelsRLE(uint8array, hdrInfo);\r\n }\r\n\r\n private static _RGBEReadPixelsRLE(uint8array: Uint8Array, hdrInfo: HDRInfo): Float32Array {\r\n let num_scanlines = hdrInfo.height;\r\n const scanline_width = hdrInfo.width;\r\n\r\n let a: number, b: number, c: number, d: number, count: number;\r\n let dataIndex = hdrInfo.dataPosition;\r\n let index = 0,\r\n endIndex = 0,\r\n i = 0;\r\n\r\n const scanLineArrayBuffer = new ArrayBuffer(scanline_width * 4); // four channel R G B E\r\n const scanLineArray = new Uint8Array(scanLineArrayBuffer);\r\n\r\n // 3 channels of 4 bytes per pixel in float.\r\n const resultBuffer = new ArrayBuffer(hdrInfo.width * hdrInfo.height * 4 * 3);\r\n const resultArray = new Float32Array(resultBuffer);\r\n\r\n // read in each successive scanline\r\n while (num_scanlines > 0) {\r\n a = uint8array[dataIndex++];\r\n b = uint8array[dataIndex++];\r\n c = uint8array[dataIndex++];\r\n d = uint8array[dataIndex++];\r\n\r\n if (a != 2 || b != 2 || c & 0x80 || hdrInfo.width < 8 || hdrInfo.width > 32767) {\r\n return this._RGBEReadPixelsNOTRLE(uint8array, hdrInfo);\r\n }\r\n\r\n if (((c << 8) | d) != scanline_width) {\r\n throw \"HDR Bad header format, wrong scan line width\";\r\n }\r\n\r\n index = 0;\r\n\r\n // read each of the four channels for the scanline into the buffer\r\n for (i = 0; i < 4; i++) {\r\n endIndex = (i + 1) * scanline_width;\r\n\r\n while (index < endIndex) {\r\n a = uint8array[dataIndex++];\r\n b = uint8array[dataIndex++];\r\n\r\n if (a > 128) {\r\n // a run of the same value\r\n count = a - 128;\r\n if (count == 0 || count > endIndex - index) {\r\n throw \"HDR Bad Format, bad scanline data (run)\";\r\n }\r\n\r\n while (count-- > 0) {\r\n scanLineArray[index++] = b;\r\n }\r\n } else {\r\n // a non-run\r\n count = a;\r\n if (count == 0 || count > endIndex - index) {\r\n throw \"HDR Bad Format, bad scanline data (non-run)\";\r\n }\r\n\r\n scanLineArray[index++] = b;\r\n if (--count > 0) {\r\n for (let j = 0; j < count; j++) {\r\n scanLineArray[index++] = uint8array[dataIndex++];\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n // now convert data from buffer into floats\r\n for (i = 0; i < scanline_width; i++) {\r\n a = scanLineArray[i];\r\n b = scanLineArray[i + scanline_width];\r\n c = scanLineArray[i + 2 * scanline_width];\r\n d = scanLineArray[i + 3 * scanline_width];\r\n\r\n this._Rgbe2float(resultArray, a, b, c, d, (hdrInfo.height - num_scanlines) * scanline_width * 3 + i * 3);\r\n }\r\n\r\n num_scanlines--;\r\n }\r\n\r\n return resultArray;\r\n }\r\n\r\n private static _RGBEReadPixelsNOTRLE(uint8array: Uint8Array, hdrInfo: HDRInfo): Float32Array {\r\n // this file is not run length encoded\r\n // read values sequentially\r\n\r\n let num_scanlines = hdrInfo.height;\r\n const scanline_width = hdrInfo.width;\r\n\r\n let a: number, b: number, c: number, d: number, i: number;\r\n let dataIndex = hdrInfo.dataPosition;\r\n\r\n // 3 channels of 4 bytes per pixel in float.\r\n const resultBuffer = new ArrayBuffer(hdrInfo.width * hdrInfo.height * 4 * 3);\r\n const resultArray = new Float32Array(resultBuffer);\r\n\r\n // read in each successive scanline\r\n while (num_scanlines > 0) {\r\n for (i = 0; i < hdrInfo.width; i++) {\r\n a = uint8array[dataIndex++];\r\n b = uint8array[dataIndex++];\r\n c = uint8array[dataIndex++];\r\n d = uint8array[dataIndex++];\r\n\r\n this._Rgbe2float(resultArray, a, b, c, d, (hdrInfo.height - num_scanlines) * scanline_width * 3 + i * 3);\r\n }\r\n\r\n num_scanlines--;\r\n }\r\n\r\n return resultArray;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"hdr.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Misc/HighDynamicRange/hdr.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAsB7D;;GAEG;AACH,MAAM,OAAO,QAAQ;IACT,MAAM,CAAC,MAAM,CAAC,QAAgB,EAAE,QAA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AI,YAAY,CAAC,YAAY,CAAC,CAAC;QAEnD,mCAAmC;QACnC,OAAO,aAAa,GAAG,CAAC,EAAE;YACtB,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;gBAChC,CAAC,GAAG,UAAU,CAAC,SAAS,EAAE,CAAC,CAAC;gBAC5B,CAAC,GAAG,UAAU,CAAC,SAAS,EAAE,CAAC,CAAC;gBAC5B,CAAC,GAAG,UAAU,CAAC,SAAS,EAAE,CAAC,CAAC;gBAC5B,CAAC,GAAG,UAAU,CAAC,SAAS,EAAE,CAAC,CAAC;gBAE5B,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,GAAG,aAAa,CAAC,GAAG,cAAc,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;aAC5G;YAED,aAAa,EAAE,CAAC;SACnB;QAED,OAAO,WAAW,CAAC;IACvB,CAAC;CACJ","sourcesContent":["import type { CubeMapInfo } from \"./panoramaToCubemap\";\r\nimport { PanoramaToCubeMapTools } from \"./panoramaToCubemap\";\r\n\r\n/**\r\n * Header information of HDR texture files.\r\n */\r\nexport interface HDRInfo {\r\n /**\r\n * The height of the texture in pixels.\r\n */\r\n height: number;\r\n\r\n /**\r\n * The width of the texture in pixels.\r\n */\r\n width: number;\r\n\r\n /**\r\n * The index of the beginning of the data in the binary file.\r\n */\r\n dataPosition: number;\r\n}\r\n\r\n/**\r\n * This groups tools to convert HDR texture to native colors array.\r\n */\r\nexport class HDRTools {\r\n private static _Ldexp(mantissa: number, exponent: number): number {\r\n if (exponent > 1023) {\r\n return mantissa * Math.pow(2, 1023) * Math.pow(2, exponent - 1023);\r\n }\r\n\r\n if (exponent < -1074) {\r\n return mantissa * Math.pow(2, -1074) * Math.pow(2, exponent + 1074);\r\n }\r\n\r\n return mantissa * Math.pow(2, exponent);\r\n }\r\n\r\n private static _Rgbe2float(float32array: Float32Array, red: number, green: number, blue: number, exponent: number, index: number) {\r\n if (exponent > 0) {\r\n /*nonzero pixel*/\r\n exponent = this._Ldexp(1.0, exponent - (128 + 8));\r\n\r\n float32array[index + 0] = red * exponent;\r\n float32array[index + 1] = green * exponent;\r\n float32array[index + 2] = blue * exponent;\r\n } else {\r\n float32array[index + 0] = 0;\r\n float32array[index + 1] = 0;\r\n float32array[index + 2] = 0;\r\n }\r\n }\r\n\r\n private static _ReadStringLine(uint8array: Uint8Array, startIndex: number): string {\r\n let line = \"\";\r\n let character = \"\";\r\n\r\n for (let i = startIndex; i < uint8array.length - startIndex; i++) {\r\n character = String.fromCharCode(uint8array[i]);\r\n\r\n if (character == \"\\n\") {\r\n break;\r\n }\r\n\r\n line += character;\r\n }\r\n\r\n return line;\r\n }\r\n\r\n /**\r\n * Reads header information from an RGBE texture stored in a native array.\r\n * More information on this format are available here:\r\n * https://en.wikipedia.org/wiki/RGBE_image_format\r\n *\r\n * @param uint8array The binary file stored in native array.\r\n * @returns The header information.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public static RGBE_ReadHeader(uint8array: Uint8Array): HDRInfo {\r\n let height: number = 0;\r\n let width: number = 0;\r\n\r\n let line = this._ReadStringLine(uint8array, 0);\r\n if (line[0] != \"#\" || line[1] != \"?\") {\r\n throw \"Bad HDR Format.\";\r\n }\r\n\r\n let endOfHeader = false;\r\n let findFormat = false;\r\n let lineIndex: number = 0;\r\n\r\n do {\r\n lineIndex += line.length + 1;\r\n line = this._ReadStringLine(uint8array, lineIndex);\r\n\r\n if (line == \"FORMAT=32-bit_rle_rgbe\") {\r\n findFormat = true;\r\n } else if (line.length == 0) {\r\n endOfHeader = true;\r\n }\r\n } while (!endOfHeader);\r\n\r\n if (!findFormat) {\r\n throw \"HDR Bad header format, unsupported FORMAT\";\r\n }\r\n\r\n lineIndex += line.length + 1;\r\n line = this._ReadStringLine(uint8array, lineIndex);\r\n\r\n const sizeRegexp = /^-Y (.*) \\+X (.*)$/g;\r\n const match = sizeRegexp.exec(line);\r\n\r\n // TODO. Support +Y and -X if needed.\r\n if (!match || match.length < 3) {\r\n throw \"HDR Bad header format, no size\";\r\n }\r\n width = parseInt(match[2]);\r\n height = parseInt(match[1]);\r\n\r\n if (width < 8 || width > 0x7fff) {\r\n throw \"HDR Bad header format, unsupported size\";\r\n }\r\n\r\n lineIndex += line.length + 1;\r\n\r\n return {\r\n height: height,\r\n width: width,\r\n dataPosition: lineIndex,\r\n };\r\n }\r\n\r\n /**\r\n * Returns the cubemap information (each faces texture data) extracted from an RGBE texture.\r\n * This RGBE texture needs to store the information as a panorama.\r\n *\r\n * More information on this format are available here:\r\n * https://en.wikipedia.org/wiki/RGBE_image_format\r\n *\r\n * @param buffer The binary file stored in an array buffer.\r\n * @param size The expected size of the extracted cubemap.\r\n * @returns The Cube Map information.\r\n */\r\n public static GetCubeMapTextureData(buffer: ArrayBuffer, size: number, supersample = false): CubeMapInfo {\r\n const uint8array = new Uint8Array(buffer);\r\n const hdrInfo = this.RGBE_ReadHeader(uint8array);\r\n const data = this.RGBE_ReadPixels(uint8array, hdrInfo);\r\n\r\n const cubeMapData = PanoramaToCubeMapTools.ConvertPanoramaToCubemap(data, hdrInfo.width, hdrInfo.height, size, supersample);\r\n\r\n return cubeMapData;\r\n }\r\n\r\n /**\r\n * Returns the pixels data extracted from an RGBE texture.\r\n * This pixels will be stored left to right up to down in the R G B order in one array.\r\n *\r\n * More information on this format are available here:\r\n * https://en.wikipedia.org/wiki/RGBE_image_format\r\n *\r\n * @param uint8array The binary file stored in an array buffer.\r\n * @param hdrInfo The header information of the file.\r\n * @returns The pixels data in RGB right to left up to down order.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public static RGBE_ReadPixels(uint8array: Uint8Array, hdrInfo: HDRInfo): Float32Array {\r\n return this._RGBEReadPixelsRLE(uint8array, hdrInfo);\r\n }\r\n\r\n private static _RGBEReadPixelsRLE(uint8array: Uint8Array, hdrInfo: HDRInfo): Float32Array {\r\n let num_scanlines = hdrInfo.height;\r\n const scanline_width = hdrInfo.width;\r\n\r\n let a: number, b: number, c: number, d: number, count: number;\r\n let dataIndex = hdrInfo.dataPosition;\r\n let index = 0,\r\n endIndex = 0,\r\n i = 0;\r\n\r\n const scanLineArrayBuffer = new ArrayBuffer(scanline_width * 4); // four channel R G B E\r\n const scanLineArray = new Uint8Array(scanLineArrayBuffer);\r\n\r\n // 3 channels of 4 bytes per pixel in float.\r\n const resultBuffer = new ArrayBuffer(hdrInfo.width * hdrInfo.height * 4 * 3);\r\n const resultArray = new Float32Array(resultBuffer);\r\n\r\n // read in each successive scanline\r\n while (num_scanlines > 0) {\r\n a = uint8array[dataIndex++];\r\n b = uint8array[dataIndex++];\r\n c = uint8array[dataIndex++];\r\n d = uint8array[dataIndex++];\r\n\r\n if (a != 2 || b != 2 || c & 0x80 || hdrInfo.width < 8 || hdrInfo.width > 32767) {\r\n return this._RGBEReadPixelsNOTRLE(uint8array, hdrInfo);\r\n }\r\n\r\n if (((c << 8) | d) != scanline_width) {\r\n throw \"HDR Bad header format, wrong scan line width\";\r\n }\r\n\r\n index = 0;\r\n\r\n // read each of the four channels for the scanline into the buffer\r\n for (i = 0; i < 4; i++) {\r\n endIndex = (i + 1) * scanline_width;\r\n\r\n while (index < endIndex) {\r\n a = uint8array[dataIndex++];\r\n b = uint8array[dataIndex++];\r\n\r\n if (a > 128) {\r\n // a run of the same value\r\n count = a - 128;\r\n if (count == 0 || count > endIndex - index) {\r\n throw \"HDR Bad Format, bad scanline data (run)\";\r\n }\r\n\r\n while (count-- > 0) {\r\n scanLineArray[index++] = b;\r\n }\r\n } else {\r\n // a non-run\r\n count = a;\r\n if (count == 0 || count > endIndex - index) {\r\n throw \"HDR Bad Format, bad scanline data (non-run)\";\r\n }\r\n\r\n scanLineArray[index++] = b;\r\n if (--count > 0) {\r\n for (let j = 0; j < count; j++) {\r\n scanLineArray[index++] = uint8array[dataIndex++];\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n // now convert data from buffer into floats\r\n for (i = 0; i < scanline_width; i++) {\r\n a = scanLineArray[i];\r\n b = scanLineArray[i + scanline_width];\r\n c = scanLineArray[i + 2 * scanline_width];\r\n d = scanLineArray[i + 3 * scanline_width];\r\n\r\n this._Rgbe2float(resultArray, a, b, c, d, (hdrInfo.height - num_scanlines) * scanline_width * 3 + i * 3);\r\n }\r\n\r\n num_scanlines--;\r\n }\r\n\r\n return resultArray;\r\n }\r\n\r\n private static _RGBEReadPixelsNOTRLE(uint8array: Uint8Array, hdrInfo: HDRInfo): Float32Array {\r\n // this file is not run length encoded\r\n // read values sequentially\r\n\r\n let num_scanlines = hdrInfo.height;\r\n const scanline_width = hdrInfo.width;\r\n\r\n let a: number, b: number, c: number, d: number, i: number;\r\n let dataIndex = hdrInfo.dataPosition;\r\n\r\n // 3 channels of 4 bytes per pixel in float.\r\n const resultBuffer = new ArrayBuffer(hdrInfo.width * hdrInfo.height * 4 * 3);\r\n const resultArray = new Float32Array(resultBuffer);\r\n\r\n // read in each successive scanline\r\n while (num_scanlines > 0) {\r\n for (i = 0; i < hdrInfo.width; i++) {\r\n a = uint8array[dataIndex++];\r\n b = uint8array[dataIndex++];\r\n c = uint8array[dataIndex++];\r\n d = uint8array[dataIndex++];\r\n\r\n this._Rgbe2float(resultArray, a, b, c, d, (hdrInfo.height - num_scanlines) * scanline_width * 3 + i * 3);\r\n }\r\n\r\n num_scanlines--;\r\n }\r\n\r\n return resultArray;\r\n }\r\n}\r\n"]}
@@ -75,7 +75,7 @@ export declare class PanoramaToCubeMapTools {
75
75
  * @param size The willing size of the generated cubemap (each faces will be size * size pixels)
76
76
  * @returns The cubemap data
77
77
  */
78
- static ConvertPanoramaToCubemap(float32Array: Float32Array, inputWidth: number, inputHeight: number, size: number): CubeMapInfo;
78
+ static ConvertPanoramaToCubemap(float32Array: Float32Array, inputWidth: number, inputHeight: number, size: number, supersample?: boolean): CubeMapInfo;
79
79
  private static CreateCubemapTexture;
80
80
  private static CalcProjectionSpherical;
81
81
  }
@@ -13,19 +13,19 @@ export class PanoramaToCubeMapTools {
13
13
  * @param size The willing size of the generated cubemap (each faces will be size * size pixels)
14
14
  * @returns The cubemap data
15
15
  */
16
- static ConvertPanoramaToCubemap(float32Array, inputWidth, inputHeight, size) {
16
+ static ConvertPanoramaToCubemap(float32Array, inputWidth, inputHeight, size, supersample = false) {
17
17
  if (!float32Array) {
18
18
  throw "ConvertPanoramaToCubemap: input cannot be null";
19
19
  }
20
20
  if (float32Array.length != inputWidth * inputHeight * 3) {
21
21
  throw "ConvertPanoramaToCubemap: input size is wrong";
22
22
  }
23
- const textureFront = this.CreateCubemapTexture(size, this.FACE_FRONT, float32Array, inputWidth, inputHeight);
24
- const textureBack = this.CreateCubemapTexture(size, this.FACE_BACK, float32Array, inputWidth, inputHeight);
25
- const textureLeft = this.CreateCubemapTexture(size, this.FACE_LEFT, float32Array, inputWidth, inputHeight);
26
- const textureRight = this.CreateCubemapTexture(size, this.FACE_RIGHT, float32Array, inputWidth, inputHeight);
27
- const textureUp = this.CreateCubemapTexture(size, this.FACE_UP, float32Array, inputWidth, inputHeight);
28
- const textureDown = this.CreateCubemapTexture(size, this.FACE_DOWN, float32Array, inputWidth, inputHeight);
23
+ const textureFront = this.CreateCubemapTexture(size, this.FACE_FRONT, float32Array, inputWidth, inputHeight, supersample);
24
+ const textureBack = this.CreateCubemapTexture(size, this.FACE_BACK, float32Array, inputWidth, inputHeight, supersample);
25
+ const textureLeft = this.CreateCubemapTexture(size, this.FACE_LEFT, float32Array, inputWidth, inputHeight, supersample);
26
+ const textureRight = this.CreateCubemapTexture(size, this.FACE_RIGHT, float32Array, inputWidth, inputHeight, supersample);
27
+ const textureUp = this.CreateCubemapTexture(size, this.FACE_UP, float32Array, inputWidth, inputHeight, supersample);
28
+ const textureDown = this.CreateCubemapTexture(size, this.FACE_DOWN, float32Array, inputWidth, inputHeight, supersample);
29
29
  return {
30
30
  front: textureFront,
31
31
  back: textureBack,
@@ -39,28 +39,36 @@ export class PanoramaToCubeMapTools {
39
39
  gammaSpace: false,
40
40
  };
41
41
  }
42
- static CreateCubemapTexture(texSize, faceData, float32Array, inputWidth, inputHeight) {
42
+ static CreateCubemapTexture(texSize, faceData, float32Array, inputWidth, inputHeight, supersample = false) {
43
43
  const buffer = new ArrayBuffer(texSize * texSize * 4 * 3);
44
44
  const textureArray = new Float32Array(buffer);
45
- const rotDX1 = faceData[1].subtract(faceData[0]).scale(1 / texSize);
46
- const rotDX2 = faceData[3].subtract(faceData[2]).scale(1 / texSize);
45
+ // If supersampling, determine number of samples needed when source texture width is divided for 4 cube faces
46
+ const samples = supersample ? Math.max(1, Math.round(inputWidth / 4 / texSize)) : 1;
47
+ const sampleFactor = 1 / samples;
48
+ const sampleFactorSqr = sampleFactor * sampleFactor;
49
+ const rotDX1 = faceData[1].subtract(faceData[0]).scale(sampleFactor / texSize);
50
+ const rotDX2 = faceData[3].subtract(faceData[2]).scale(sampleFactor / texSize);
47
51
  const dy = 1 / texSize;
48
52
  let fy = 0;
49
53
  for (let y = 0; y < texSize; y++) {
50
- let xv1 = faceData[0];
51
- let xv2 = faceData[2];
52
- for (let x = 0; x < texSize; x++) {
53
- const v = xv2.subtract(xv1).scale(fy).add(xv1);
54
- v.normalize();
55
- const color = this.CalcProjectionSpherical(v, float32Array, inputWidth, inputHeight);
56
- // 3 channels per pixels
57
- textureArray[y * texSize * 3 + x * 3 + 0] = color.r;
58
- textureArray[y * texSize * 3 + x * 3 + 1] = color.g;
59
- textureArray[y * texSize * 3 + x * 3 + 2] = color.b;
60
- xv1 = xv1.add(rotDX1);
61
- xv2 = xv2.add(rotDX2);
54
+ for (let sy = 0; sy < samples; sy++) {
55
+ let xv1 = faceData[0];
56
+ let xv2 = faceData[2];
57
+ for (let x = 0; x < texSize; x++) {
58
+ for (let sx = 0; sx < samples; sx++) {
59
+ const v = xv2.subtract(xv1).scale(fy).add(xv1);
60
+ v.normalize();
61
+ const color = this.CalcProjectionSpherical(v, float32Array, inputWidth, inputHeight);
62
+ // 3 channels per pixels
63
+ textureArray[y * texSize * 3 + x * 3 + 0] += color.r * sampleFactorSqr;
64
+ textureArray[y * texSize * 3 + x * 3 + 1] += color.g * sampleFactorSqr;
65
+ textureArray[y * texSize * 3 + x * 3 + 2] += color.b * sampleFactorSqr;
66
+ xv1 = xv1.add(rotDX1);
67
+ xv2 = xv2.add(rotDX2);
68
+ }
69
+ }
70
+ fy += dy * sampleFactor;
62
71
  }
63
- fy += dy;
64
72
  }
65
73
  return textureArray;
66
74
  }
@@ -1 +1 @@
1
- {"version":3,"file":"panoramaToCubemap.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Misc/HighDynamicRange/panoramaToCubemap.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAqEpD;;GAEG;AACH,MAAM,OAAO,sBAAsB;IAQ/B;;;;;;;;OAQG;IACI,MAAM,CAAC,wBAAwB,CAAC,YAA0B,EAAE,UAAkB,EAAE,WAAmB,EAAE,IAAY;QACpH,IAAI,CAAC,YAAY,EAAE;YACf,MAAM,gDAAgD,CAAC;SAC1D;QAED,IAAI,YAAY,CAAC,MAAM,IAAI,UAAU,GAAG,WAAW,GAAG,CAAC,EAAE;YACrD,MAAM,+CAA+C,CAAC;SACzD;QAED,MAAM,YAAY,GAAG,IAAI,CAAC,oBAAoB,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;QAC7G,MAAM,WAAW,GAAG,IAAI,CAAC,oBAAoB,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;QAC3G,MAAM,WAAW,GAAG,IAAI,CAAC,oBAAoB,CAAC,IAAI,E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AG,EAAE,GAAG,CAAC,EAAE,IAAI,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAClI,gCAAS,GAAG,CAAC,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;AACrI,gCAAS,GAAG,CAAC,IAAI,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AACjI,8BAAO,GAAG,CAAC,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"../../types\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport { Constants } from \"../../Engines/constants\";\r\n\r\n/**\r\n * CubeMap information grouping all the data for each faces as well as the cubemap size.\r\n */\r\nexport interface CubeMapInfo {\r\n /**\r\n * The pixel array for the front face.\r\n * This is stored in format, left to right, up to down format.\r\n */\r\n front: Nullable<ArrayBufferView>;\r\n\r\n /**\r\n * The pixel array for the back face.\r\n * This is stored in format, left to right, up to down format.\r\n */\r\n back: Nullable<ArrayBufferView>;\r\n\r\n /**\r\n * The pixel array for the left face.\r\n * This is stored in format, left to right, up to down format.\r\n */\r\n left: Nullable<ArrayBufferView>;\r\n\r\n /**\r\n * The pixel array for the right face.\r\n * This is stored in format, left to right, up to down format.\r\n */\r\n right: Nullable<ArrayBufferView>;\r\n\r\n /**\r\n * The pixel array for the up face.\r\n * This is stored in format, left to right, up to down format.\r\n */\r\n up: Nullable<ArrayBufferView>;\r\n\r\n /**\r\n * The pixel array for the down face.\r\n * This is stored in format, left to right, up to down format.\r\n */\r\n down: Nullable<ArrayBufferView>;\r\n\r\n /**\r\n * The size of the cubemap stored.\r\n *\r\n * Each faces will be size * size pixels.\r\n */\r\n size: number;\r\n\r\n /**\r\n * The format of the texture.\r\n *\r\n * RGBA, RGB.\r\n */\r\n format: number;\r\n\r\n /**\r\n * The type of the texture data.\r\n *\r\n * UNSIGNED_INT, FLOAT.\r\n */\r\n type: number;\r\n\r\n /**\r\n * Specifies whether the texture is in gamma space.\r\n */\r\n gammaSpace: boolean;\r\n}\r\n\r\n/**\r\n * Helper class useful to convert panorama picture to their cubemap representation in 6 faces.\r\n */\r\nexport class PanoramaToCubeMapTools {\r\n private static FACE_LEFT = [new Vector3(-1.0, -1.0, -1.0), new Vector3(1.0, -1.0, -1.0), new Vector3(-1.0, 1.0, -1.0), new Vector3(1.0, 1.0, -1.0)];\r\n private static FACE_RIGHT = [new Vector3(1.0, -1.0, 1.0), new Vector3(-1.0, -1.0, 1.0), new Vector3(1.0, 1.0, 1.0), new Vector3(-1.0, 1.0, 1.0)];\r\n private static FACE_FRONT = [new Vector3(1.0, -1.0, -1.0), new Vector3(1.0, -1.0, 1.0), new Vector3(1.0, 1.0, -1.0), new Vector3(1.0, 1.0, 1.0)];\r\n private static FACE_BACK = [new Vector3(-1.0, -1.0, 1.0), new Vector3(-1.0, -1.0, -1.0), new Vector3(-1.0, 1.0, 1.0), new Vector3(-1.0, 1.0, -1.0)];\r\n private static FACE_DOWN = [new Vector3(1.0, 1.0, -1.0), new Vector3(1.0, 1.0, 1.0), new Vector3(-1.0, 1.0, -1.0), new Vector3(-1.0, 1.0, 1.0)];\r\n private static FACE_UP = [new Vector3(-1.0, -1.0, -1.0), new Vector3(-1.0, -1.0, 1.0), new Vector3(1.0, -1.0, -1.0), new Vector3(1.0, -1.0, 1.0)];\r\n\r\n /**\r\n * Converts a panorama stored in RGB right to left up to down format into a cubemap (6 faces).\r\n *\r\n * @param float32Array The source data.\r\n * @param inputWidth The width of the input panorama.\r\n * @param inputHeight The height of the input panorama.\r\n * @param size The willing size of the generated cubemap (each faces will be size * size pixels)\r\n * @returns The cubemap data\r\n */\r\n public static ConvertPanoramaToCubemap(float32Array: Float32Array, inputWidth: number, inputHeight: number, size: number): CubeMapInfo {\r\n if (!float32Array) {\r\n throw \"ConvertPanoramaToCubemap: input cannot be null\";\r\n }\r\n\r\n if (float32Array.length != inputWidth * inputHeight * 3) {\r\n throw \"ConvertPanoramaToCubemap: input size is wrong\";\r\n }\r\n\r\n const textureFront = this.CreateCubemapTexture(size, this.FACE_FRONT, float32Array, inputWidth, inputHeight);\r\n const textureBack = this.CreateCubemapTexture(size, this.FACE_BACK, float32Array, inputWidth, inputHeight);\r\n const textureLeft = this.CreateCubemapTexture(size, this.FACE_LEFT, float32Array, inputWidth, inputHeight);\r\n const textureRight = this.CreateCubemapTexture(size, this.FACE_RIGHT, float32Array, inputWidth, inputHeight);\r\n const textureUp = this.CreateCubemapTexture(size, this.FACE_UP, float32Array, inputWidth, inputHeight);\r\n const textureDown = this.CreateCubemapTexture(size, this.FACE_DOWN, float32Array, inputWidth, inputHeight);\r\n\r\n return {\r\n front: textureFront,\r\n back: textureBack,\r\n left: textureLeft,\r\n right: textureRight,\r\n up: textureUp,\r\n down: textureDown,\r\n size: size,\r\n type: Constants.TEXTURETYPE_FLOAT,\r\n format: Constants.TEXTUREFORMAT_RGB,\r\n gammaSpace: false,\r\n };\r\n }\r\n\r\n private static CreateCubemapTexture(texSize: number, faceData: Vector3[], float32Array: Float32Array, inputWidth: number, inputHeight: number) {\r\n const buffer = new ArrayBuffer(texSize * texSize * 4 * 3);\r\n const textureArray = new Float32Array(buffer);\r\n\r\n const rotDX1 = faceData[1].subtract(faceData[0]).scale(1 / texSize);\r\n const rotDX2 = faceData[3].subtract(faceData[2]).scale(1 / texSize);\r\n\r\n const dy = 1 / texSize;\r\n let fy = 0;\r\n\r\n for (let y = 0; y < texSize; y++) {\r\n let xv1 = faceData[0];\r\n let xv2 = faceData[2];\r\n\r\n for (let x = 0; x < texSize; x++) {\r\n const v = xv2.subtract(xv1).scale(fy).add(xv1);\r\n v.normalize();\r\n\r\n const color = this.CalcProjectionSpherical(v, float32Array, inputWidth, inputHeight);\r\n\r\n // 3 channels per pixels\r\n textureArray[y * texSize * 3 + x * 3 + 0] = color.r;\r\n textureArray[y * texSize * 3 + x * 3 + 1] = color.g;\r\n textureArray[y * texSize * 3 + x * 3 + 2] = color.b;\r\n\r\n xv1 = xv1.add(rotDX1);\r\n xv2 = xv2.add(rotDX2);\r\n }\r\n\r\n fy += dy;\r\n }\r\n\r\n return textureArray;\r\n }\r\n\r\n private static CalcProjectionSpherical(vDir: Vector3, float32Array: Float32Array, inputWidth: number, inputHeight: number): any {\r\n let theta = Math.atan2(vDir.z, vDir.x);\r\n const phi = Math.acos(vDir.y);\r\n\r\n while (theta < -Math.PI) {\r\n theta += 2 * Math.PI;\r\n }\r\n while (theta > Math.PI) {\r\n theta -= 2 * Math.PI;\r\n }\r\n\r\n let dx = theta / Math.PI;\r\n const dy = phi / Math.PI;\r\n\r\n // recenter.\r\n dx = dx * 0.5 + 0.5;\r\n\r\n let px = Math.round(dx * inputWidth);\r\n if (px < 0) {\r\n px = 0;\r\n } else if (px >= inputWidth) {\r\n px = inputWidth - 1;\r\n }\r\n\r\n let py = Math.round(dy * inputHeight);\r\n if (py < 0) {\r\n py = 0;\r\n } else if (py >= inputHeight) {\r\n py = inputHeight - 1;\r\n }\r\n\r\n const inputY = inputHeight - py - 1;\r\n const r = float32Array[inputY * inputWidth * 3 + px * 3 + 0];\r\n const g = float32Array[inputY * inputWidth * 3 + px * 3 + 1];\r\n const b = float32Array[inputY * inputWidth * 3 + px * 3 + 2];\r\n\r\n return {\r\n r: r,\r\n g: g,\r\n b: b,\r\n };\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"panoramaToCubemap.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Misc/HighDynamicRange/panoramaToCubemap.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAqEpD;;GAEG;AACH,MAAM,OAAO,sBAAsB;IAQ/B;;;;;;;;OAQG;IACI,MAAM,CAAC,wBAAwB,CAAC,YAA0B,EAAE,UAAkB,EAAE,WAAmB,EAAE,IAAY,EAAE,WAAW,GAAG,KAAK;QACzI,IAAI,CAAC,YAAY,EAAE;YACf,MAAM,gDAAgD,CAAC;SAC1D;QAED,IAAI,YAAY,CAAC,MAAM,IAAI,UAAU,GAAG,WAAW,GAAG,CAAC,EAAE;YACrD,MAAM,+CAA+C,CAAC;SACzD;QAED,MAAM,YAAY,GAAG,IAAI,CAAC,oBAAoB,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;QAC1H,MAAM,WAAW,GAAG,IAAI,CAAC,oBAAoB,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,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CAAC,EAAE,IAAI,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AACjI,8BAAO,GAAG,CAAC,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"../../types\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport { Constants } from \"../../Engines/constants\";\r\n\r\n/**\r\n * CubeMap information grouping all the data for each faces as well as the cubemap size.\r\n */\r\nexport interface CubeMapInfo {\r\n /**\r\n * The pixel array for the front face.\r\n * This is stored in format, left to right, up to down format.\r\n */\r\n front: Nullable<ArrayBufferView>;\r\n\r\n /**\r\n * The pixel array for the back face.\r\n * This is stored in format, left to right, up to down format.\r\n */\r\n back: Nullable<ArrayBufferView>;\r\n\r\n /**\r\n * The pixel array for the left face.\r\n * This is stored in format, left to right, up to down format.\r\n */\r\n left: Nullable<ArrayBufferView>;\r\n\r\n /**\r\n * The pixel array for the right face.\r\n * This is stored in format, left to right, up to down format.\r\n */\r\n right: Nullable<ArrayBufferView>;\r\n\r\n /**\r\n * The pixel array for the up face.\r\n * This is stored in format, left to right, up to down format.\r\n */\r\n up: Nullable<ArrayBufferView>;\r\n\r\n /**\r\n * The pixel array for the down face.\r\n * This is stored in format, left to right, up to down format.\r\n */\r\n down: Nullable<ArrayBufferView>;\r\n\r\n /**\r\n * The size of the cubemap stored.\r\n *\r\n * Each faces will be size * size pixels.\r\n */\r\n size: number;\r\n\r\n /**\r\n * The format of the texture.\r\n *\r\n * RGBA, RGB.\r\n */\r\n format: number;\r\n\r\n /**\r\n * The type of the texture data.\r\n *\r\n * UNSIGNED_INT, FLOAT.\r\n */\r\n type: number;\r\n\r\n /**\r\n * Specifies whether the texture is in gamma space.\r\n */\r\n gammaSpace: boolean;\r\n}\r\n\r\n/**\r\n * Helper class useful to convert panorama picture to their cubemap representation in 6 faces.\r\n */\r\nexport class PanoramaToCubeMapTools {\r\n private static FACE_LEFT = [new Vector3(-1.0, -1.0, -1.0), new Vector3(1.0, -1.0, -1.0), new Vector3(-1.0, 1.0, -1.0), new Vector3(1.0, 1.0, -1.0)];\r\n private static FACE_RIGHT = [new Vector3(1.0, -1.0, 1.0), new Vector3(-1.0, -1.0, 1.0), new Vector3(1.0, 1.0, 1.0), new Vector3(-1.0, 1.0, 1.0)];\r\n private static FACE_FRONT = [new Vector3(1.0, -1.0, -1.0), new Vector3(1.0, -1.0, 1.0), new Vector3(1.0, 1.0, -1.0), new Vector3(1.0, 1.0, 1.0)];\r\n private static FACE_BACK = [new Vector3(-1.0, -1.0, 1.0), new Vector3(-1.0, -1.0, -1.0), new Vector3(-1.0, 1.0, 1.0), new Vector3(-1.0, 1.0, -1.0)];\r\n private static FACE_DOWN = [new Vector3(1.0, 1.0, -1.0), new Vector3(1.0, 1.0, 1.0), new Vector3(-1.0, 1.0, -1.0), new Vector3(-1.0, 1.0, 1.0)];\r\n private static FACE_UP = [new Vector3(-1.0, -1.0, -1.0), new Vector3(-1.0, -1.0, 1.0), new Vector3(1.0, -1.0, -1.0), new Vector3(1.0, -1.0, 1.0)];\r\n\r\n /**\r\n * Converts a panorama stored in RGB right to left up to down format into a cubemap (6 faces).\r\n *\r\n * @param float32Array The source data.\r\n * @param inputWidth The width of the input panorama.\r\n * @param inputHeight The height of the input panorama.\r\n * @param size The willing size of the generated cubemap (each faces will be size * size pixels)\r\n * @returns The cubemap data\r\n */\r\n public static ConvertPanoramaToCubemap(float32Array: Float32Array, inputWidth: number, inputHeight: number, size: number, supersample = false): CubeMapInfo {\r\n if (!float32Array) {\r\n throw \"ConvertPanoramaToCubemap: input cannot be null\";\r\n }\r\n\r\n if (float32Array.length != inputWidth * inputHeight * 3) {\r\n throw \"ConvertPanoramaToCubemap: input size is wrong\";\r\n }\r\n\r\n const textureFront = this.CreateCubemapTexture(size, this.FACE_FRONT, float32Array, inputWidth, inputHeight, supersample);\r\n const textureBack = this.CreateCubemapTexture(size, this.FACE_BACK, float32Array, inputWidth, inputHeight, supersample);\r\n const textureLeft = this.CreateCubemapTexture(size, this.FACE_LEFT, float32Array, inputWidth, inputHeight, supersample);\r\n const textureRight = this.CreateCubemapTexture(size, this.FACE_RIGHT, float32Array, inputWidth, inputHeight, supersample);\r\n const textureUp = this.CreateCubemapTexture(size, this.FACE_UP, float32Array, inputWidth, inputHeight, supersample);\r\n const textureDown = this.CreateCubemapTexture(size, this.FACE_DOWN, float32Array, inputWidth, inputHeight, supersample);\r\n\r\n return {\r\n front: textureFront,\r\n back: textureBack,\r\n left: textureLeft,\r\n right: textureRight,\r\n up: textureUp,\r\n down: textureDown,\r\n size: size,\r\n type: Constants.TEXTURETYPE_FLOAT,\r\n format: Constants.TEXTUREFORMAT_RGB,\r\n gammaSpace: false,\r\n };\r\n }\r\n\r\n private static CreateCubemapTexture(texSize: number, faceData: Vector3[], float32Array: Float32Array, inputWidth: number, inputHeight: number, supersample = false) {\r\n const buffer = new ArrayBuffer(texSize * texSize * 4 * 3);\r\n const textureArray = new Float32Array(buffer);\r\n\r\n // If supersampling, determine number of samples needed when source texture width is divided for 4 cube faces\r\n const samples = supersample ? Math.max(1, Math.round(inputWidth / 4 / texSize)) : 1;\r\n const sampleFactor = 1 / samples;\r\n const sampleFactorSqr = sampleFactor * sampleFactor;\r\n\r\n const rotDX1 = faceData[1].subtract(faceData[0]).scale(sampleFactor / texSize);\r\n const rotDX2 = faceData[3].subtract(faceData[2]).scale(sampleFactor / texSize);\r\n\r\n const dy = 1 / texSize;\r\n let fy = 0;\r\n\r\n for (let y = 0; y < texSize; y++) {\r\n for (let sy = 0; sy < samples; sy++) {\r\n let xv1 = faceData[0];\r\n let xv2 = faceData[2];\r\n\r\n for (let x = 0; x < texSize; x++) {\r\n for (let sx = 0; sx < samples; sx++) {\r\n const v = xv2.subtract(xv1).scale(fy).add(xv1);\r\n v.normalize();\r\n\r\n const color = this.CalcProjectionSpherical(v, float32Array, inputWidth, inputHeight);\r\n\r\n // 3 channels per pixels\r\n textureArray[y * texSize * 3 + x * 3 + 0] += color.r * sampleFactorSqr;\r\n textureArray[y * texSize * 3 + x * 3 + 1] += color.g * sampleFactorSqr;\r\n textureArray[y * texSize * 3 + x * 3 + 2] += color.b * sampleFactorSqr;\r\n\r\n xv1 = xv1.add(rotDX1);\r\n xv2 = xv2.add(rotDX2);\r\n }\r\n }\r\n\r\n fy += dy * sampleFactor;\r\n }\r\n }\r\n\r\n return textureArray;\r\n }\r\n\r\n private static CalcProjectionSpherical(vDir: Vector3, float32Array: Float32Array, inputWidth: number, inputHeight: number): any {\r\n let theta = Math.atan2(vDir.z, vDir.x);\r\n const phi = Math.acos(vDir.y);\r\n\r\n while (theta < -Math.PI) {\r\n theta += 2 * Math.PI;\r\n }\r\n while (theta > Math.PI) {\r\n theta -= 2 * Math.PI;\r\n }\r\n\r\n let dx = theta / Math.PI;\r\n const dy = phi / Math.PI;\r\n\r\n // recenter.\r\n dx = dx * 0.5 + 0.5;\r\n\r\n let px = Math.round(dx * inputWidth);\r\n if (px < 0) {\r\n px = 0;\r\n } else if (px >= inputWidth) {\r\n px = inputWidth - 1;\r\n }\r\n\r\n let py = Math.round(dy * inputHeight);\r\n if (py < 0) {\r\n py = 0;\r\n } else if (py >= inputHeight) {\r\n py = inputHeight - 1;\r\n }\r\n\r\n const inputY = inputHeight - py - 1;\r\n const r = float32Array[inputY * inputWidth * 3 + px * 3 + 0];\r\n const g = float32Array[inputY * inputWidth * 3 + px * 3 + 1];\r\n const b = float32Array[inputY * inputWidth * 3 + px * 3 + 2];\r\n\r\n return {\r\n r: r,\r\n g: g,\r\n b: b,\r\n };\r\n }\r\n}\r\n"]}
@@ -2,11 +2,12 @@ import type { IPhysicsCollisionEvent, PhysicsMassProperties, PhysicsMotionType }
2
2
  import type { PhysicsShape } from "./physicsShape";
3
3
  import { Vector3, Quaternion } from "../../Maths/math.vector";
4
4
  import type { Scene } from "../../scene";
5
- import type { TransformNode, AbstractMesh } from "../../Meshes";
6
5
  import type { Nullable } from "../../types.js";
7
6
  import type { PhysicsConstraint } from "./physicsConstraint";
8
7
  import type { Bone } from "../../Bones/bone.js";
9
8
  import type { Observable } from "../../Misc/observable";
9
+ import type { AbstractMesh } from "../../Meshes/abstractMesh";
10
+ import type { TransformNode } from "../../Meshes/transformNode";
10
11
  /**
11
12
  * PhysicsBody is useful for creating a physics body that can be used in a physics engine. It allows
12
13
  * the user to set the mass and velocity of the body, which can then be used to calculate the