RoomEnvironment.js 3.3 KB

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