HDRCubeTextureElement.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. import { HDRCubeTexture, Mesh, PBRMaterial, Texture } from "babylonjs";
  2. import { CubeTextureElement } from "./CubeTextureElement";
  3. /**
  4. * Display a very small div. A new canvas is created, with a new js scene, containing only the
  5. * cube texture in a cube
  6. */
  7. export class HDRCubeTextureElement extends CubeTextureElement {
  8. /** The texture given as a parameter should be cube. */
  9. constructor(tex: Texture) {
  10. super(tex);
  11. }
  12. /** Creates the box */
  13. protected _populateScene() {
  14. // Create the hdr texture
  15. let hdrTexture = new HDRCubeTexture(this._textureUrl, this._scene, 512);
  16. hdrTexture.coordinatesMode = Texture.SKYBOX_MODE;
  17. this._cube = Mesh.CreateBox("hdrSkyBox", 10.0, this._scene);
  18. let hdrSkyboxMaterial = new PBRMaterial("skyBox", this._scene);
  19. hdrSkyboxMaterial.backFaceCulling = false;
  20. hdrSkyboxMaterial.reflectionTexture = hdrTexture;
  21. hdrSkyboxMaterial.microSurface = 1.0;
  22. hdrSkyboxMaterial.disableLighting = true;
  23. this._cube.material = hdrSkyboxMaterial;
  24. this._cube.registerBeforeRender(() => {
  25. this._cube.rotation.y += 0.01;
  26. })
  27. }
  28. }