rawCubeTexture.js 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { SerializationHelper } from "../../Misc/decorators.serialization.js";
  2. import { _UpdateRGBDAsync as UpdateRGBDAsyncEnvTools } from "../../Misc/environmentTextureTools.js";
  3. import { InternalTextureSource } from "./internalTexture.js";
  4. import { CubeTexture } from "./cubeTexture.js";
  5. import "../../Engines/Extensions/engine.rawTexture.js";
  6. /**
  7. * Raw cube texture where the raw buffers are passed in
  8. */
  9. export class RawCubeTexture extends CubeTexture {
  10. /**
  11. * Creates a cube texture where the raw buffers are passed in.
  12. * @param scene defines the scene the texture is attached to
  13. * @param data defines the array of data to use to create each face
  14. * @param size defines the size of the textures
  15. * @param format defines the format of the data
  16. * @param type defines the type of the data (like Engine.TEXTURETYPE_UNSIGNED_INT)
  17. * @param generateMipMaps defines if the engine should generate the mip levels
  18. * @param invertY defines if data must be stored with Y axis inverted
  19. * @param samplingMode defines the required sampling mode (like Texture.NEAREST_SAMPLINGMODE)
  20. * @param compression defines the compression used (null by default)
  21. */
  22. constructor(scene, data, size, format = 5, type = 0, generateMipMaps = false, invertY = false, samplingMode = 3, compression = null) {
  23. super("", scene);
  24. this._texture = scene.getEngine().createRawCubeTexture(data, size, format, type, generateMipMaps, invertY, samplingMode, compression);
  25. }
  26. /**
  27. * Updates the raw cube texture.
  28. * @param data defines the data to store
  29. * @param format defines the data format
  30. * @param type defines the type fo the data (Engine.TEXTURETYPE_UNSIGNED_INT by default)
  31. * @param invertY defines if data must be stored with Y axis inverted
  32. * @param compression defines the compression used (null by default)
  33. */
  34. update(data, format, type, invertY, compression = null) {
  35. this._texture.getEngine().updateRawCubeTexture(this._texture, data, format, type, invertY, compression);
  36. }
  37. /**
  38. * Updates a raw cube texture with RGBD encoded data.
  39. * @param data defines the array of data [mipmap][face] to use to create each face
  40. * @param sphericalPolynomial defines the spherical polynomial for irradiance
  41. * @param lodScale defines the scale applied to environment texture. This manages the range of LOD level used for IBL according to the roughness
  42. * @param lodOffset defines the offset applied to environment texture. This manages first LOD level used for IBL according to the roughness
  43. * @returns a promise that resolves when the operation is complete
  44. */
  45. updateRGBDAsync(data, sphericalPolynomial = null, lodScale = 0.8, lodOffset = 0) {
  46. return UpdateRGBDAsyncEnvTools(this._texture, data, sphericalPolynomial, lodScale, lodOffset).then(() => { });
  47. }
  48. /**
  49. * Clones the raw cube texture.
  50. * @returns a new cube texture
  51. */
  52. clone() {
  53. return SerializationHelper.Clone(() => {
  54. const scene = this.getScene();
  55. const internalTexture = this._texture;
  56. const texture = new RawCubeTexture(scene, internalTexture._bufferViewArray, internalTexture.width, internalTexture.format, internalTexture.type, internalTexture.generateMipMaps, internalTexture.invertY, internalTexture.samplingMode, internalTexture._compression);
  57. if (internalTexture.source === InternalTextureSource.CubeRawRGBD) {
  58. texture.updateRGBDAsync(internalTexture._bufferViewArrayArray, internalTexture._sphericalPolynomial, internalTexture._lodGenerationScale, internalTexture._lodGenerationOffset);
  59. }
  60. return texture;
  61. }, this);
  62. }
  63. }
  64. //# sourceMappingURL=rawCubeTexture.js.map