RoomEnvironment.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**
  2. * https://github.com/google/model-viewer/blob/master/packages/model-viewer/src/three-components/EnvironmentScene.ts
  3. */
  4. import {
  5. BackSide,
  6. BoxGeometry,
  7. Mesh,
  8. MeshBasicMaterial,
  9. MeshStandardMaterial,
  10. PointLight,
  11. Scene,
  12. } from '../../../build/three.module.js';
  13. class RoomEnvironment extends Scene {
  14. constructor() {
  15. super();
  16. const geometry = new BoxGeometry();
  17. geometry.deleteAttribute( 'uv' );
  18. const roomMaterial = new MeshStandardMaterial( { side: BackSide } );
  19. const boxMaterial = new MeshStandardMaterial();
  20. const mainLight = new PointLight( 0xffffff, 5.0, 28, 2 );
  21. mainLight.position.set( 0.418, 16.199, 0.300 );
  22. this.add( mainLight );
  23. const room = new Mesh( geometry, roomMaterial );
  24. room.position.set( - 0.757, 13.219, 0.717 );
  25. room.scale.set( 31.713, 28.305, 28.591 );
  26. this.add( room );
  27. const box1 = new Mesh( geometry, boxMaterial );
  28. box1.position.set( - 10.906, 2.009, 1.846 );
  29. box1.rotation.set( 0, - 0.195, 0 );
  30. box1.scale.set( 2.328, 7.905, 4.651 );
  31. this.add( box1 );
  32. const box2 = new Mesh( geometry, boxMaterial );
  33. box2.position.set( - 5.607, - 0.754, - 0.758 );
  34. box2.rotation.set( 0, 0.994, 0 );
  35. box2.scale.set( 1.970, 1.534, 3.955 );
  36. this.add( box2 );
  37. const box3 = new Mesh( geometry, boxMaterial );
  38. box3.position.set( 6.167, 0.857, 7.803 );
  39. box3.rotation.set( 0, 0.561, 0 );
  40. box3.scale.set( 3.927, 6.285, 3.687 );
  41. this.add( box3 );
  42. const box4 = new Mesh( geometry, boxMaterial );
  43. box4.position.set( - 2.017, 0.018, 6.124 );
  44. box4.rotation.set( 0, 0.333, 0 );
  45. box4.scale.set( 2.002, 4.566, 2.064 );
  46. this.add( box4 );
  47. const box5 = new Mesh( geometry, boxMaterial );
  48. box5.position.set( 2.291, - 0.756, - 2.621 );
  49. box5.rotation.set( 0, - 0.286, 0 );
  50. box5.scale.set( 1.546, 1.552, 1.496 );
  51. this.add( box5 );
  52. const box6 = new Mesh( geometry, boxMaterial );
  53. box6.position.set( - 2.193, - 0.369, - 5.547 );
  54. box6.rotation.set( 0, 0.516, 0 );
  55. box6.scale.set( 3.875, 3.487, 2.986 );
  56. this.add( box6 );
  57. // -x right
  58. const light1 = new Mesh( geometry, createAreaLightMaterial( 50 ) );
  59. light1.position.set( - 16.116, 14.37, 8.208 );
  60. light1.scale.set( 0.1, 2.428, 2.739 );
  61. this.add( light1 );
  62. // -x left
  63. const light2 = new Mesh( geometry, createAreaLightMaterial( 50 ) );
  64. light2.position.set( - 16.109, 18.021, - 8.207 );
  65. light2.scale.set( 0.1, 2.425, 2.751 );
  66. this.add( light2 );
  67. // +x
  68. const light3 = new Mesh( geometry, createAreaLightMaterial( 17 ) );
  69. light3.position.set( 14.904, 12.198, - 1.832 );
  70. light3.scale.set( 0.15, 4.265, 6.331 );
  71. this.add( light3 );
  72. // +z
  73. const light4 = new Mesh( geometry, createAreaLightMaterial( 43 ) );
  74. light4.position.set( - 0.462, 8.89, 14.520 );
  75. light4.scale.set( 4.38, 5.441, 0.088 );
  76. this.add( light4 );
  77. // -z
  78. const light5 = new Mesh( geometry, createAreaLightMaterial( 20 ) );
  79. light5.position.set( 3.235, 11.486, - 12.541 );
  80. light5.scale.set( 2.5, 2.0, 0.1 );
  81. this.add( light5 );
  82. // +y
  83. const light6 = new Mesh( geometry, createAreaLightMaterial( 100 ) );
  84. light6.position.set( 0.0, 20.0, 0.0 );
  85. light6.scale.set( 1.0, 0.1, 1.0 );
  86. this.add( light6 );
  87. }
  88. }
  89. function createAreaLightMaterial( intensity ) {
  90. const material = new MeshBasicMaterial();
  91. material.color.setScalar( intensity );
  92. return material;
  93. }
  94. export { RoomEnvironment };