RoomEnvironment.js 3.3 KB

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