1/** 2 * https://github.com/google/model-viewer/blob/master/packages/model-viewer/src/three-components/EnvironmentScene.ts 3 */ 4 5import { 6 BackSide, 7 BoxGeometry, 8 Mesh, 9 MeshBasicMaterial, 10 MeshStandardMaterial, 11 PointLight, 12 Scene, 13} from 'three'; 14 15class RoomEnvironment extends Scene { 16 17 constructor( renderer = null ) { 18 19 super(); 20 21 const geometry = new BoxGeometry(); 22 geometry.deleteAttribute( 'uv' ); 23 24 const roomMaterial = new MeshStandardMaterial( { side: BackSide } ); 25 const boxMaterial = new MeshStandardMaterial(); 26 27 const mainLight = new PointLight( 0xffffff, 900, 28, 2 ); 28 mainLight.position.set( 0.418, 16.199, 0.300 ); 29 this.add( mainLight ); 30 31 const room = new Mesh( geometry, roomMaterial ); 32 room.position.set( - 0.757, 13.219, 0.717 ); 33 room.scale.set( 31.713, 28.305, 28.591 ); 34 this.add( room ); 35 36 const box1 = new Mesh( geometry, boxMaterial ); 37 box1.position.set( - 10.906, 2.009, 1.846 ); 38 box1.rotation.set( 0, - 0.195, 0 ); 39 box1.scale.set( 2.328, 7.905, 4.651 ); 40 this.add( box1 ); 41 42 const box2 = new Mesh( geometry, boxMaterial ); 43 box2.position.set( - 5.607, - 0.754, - 0.758 ); 44 box2.rotation.set( 0, 0.994, 0 ); 45 box2.scale.set( 1.970, 1.534, 3.955 ); 46 this.add( box2 ); 47 48 const box3 = new Mesh( geometry, boxMaterial ); 49 box3.position.set( 6.167, 0.857, 7.803 ); 50 box3.rotation.set( 0, 0.561, 0 ); 51 box3.scale.set( 3.927, 6.285, 3.687 ); 52 this.add( box3 ); 53 54 const box4 = new Mesh( geometry, boxMaterial ); 55 box4.position.set( - 2.017, 0.018, 6.124 ); 56 box4.rotation.set( 0, 0.333, 0 ); 57 box4.scale.set( 2.002, 4.566, 2.064 ); 58 this.add( box4 ); 59 60 const box5 = new Mesh( geometry, boxMaterial ); 61 box5.position.set( 2.291, - 0.756, - 2.621 ); 62 box5.rotation.set( 0, - 0.286, 0 ); 63 box5.scale.set( 1.546, 1.552, 1.496 ); 64 this.add( box5 ); 65 66 const box6 = new Mesh( geometry, boxMaterial ); 67 box6.position.set( - 2.193, - 0.369, - 5.547 ); 68 box6.rotation.set( 0, 0.516, 0 ); 69 box6.scale.set( 3.875, 3.487, 2.986 ); 70 this.add( box6 ); 71 72 73 // -x right 74 const light1 = new Mesh( geometry, createAreaLightMaterial( 50 ) ); 75 light1.position.set( - 16.116, 14.37, 8.208 ); 76 light1.scale.set( 0.1, 2.428, 2.739 ); 77 this.add( light1 ); 78 79 // -x left 80 const light2 = new Mesh( geometry, createAreaLightMaterial( 50 ) ); 81 light2.position.set( - 16.109, 18.021, - 8.207 ); 82 light2.scale.set( 0.1, 2.425, 2.751 ); 83 this.add( light2 ); 84 85 // +x 86 const light3 = new Mesh( geometry, createAreaLightMaterial( 17 ) ); 87 light3.position.set( 14.904, 12.198, - 1.832 ); 88 light3.scale.set( 0.15, 4.265, 6.331 ); 89 this.add( light3 ); 90 91 // +z 92 const light4 = new Mesh( geometry, createAreaLightMaterial( 43 ) ); 93 light4.position.set( - 0.462, 8.89, 14.520 ); 94 light4.scale.set( 4.38, 5.441, 0.088 ); 95 this.add( light4 ); 96 97 // -z 98 const light5 = new Mesh( geometry, createAreaLightMaterial( 20 ) ); 99 light5.position.set( 3.235, 11.486, - 12.541 ); 100 light5.scale.set( 2.5, 2.0, 0.1 ); 101 this.add( light5 ); 102 103 // +y 104 const light6 = new Mesh( geometry, createAreaLightMaterial( 100 ) ); 105 light6.position.set( 0.0, 20.0, 0.0 ); 106 light6.scale.set( 1.0, 0.1, 1.0 ); 107 this.add( light6 ); 108 109 } 110 111 dispose() { 112 113 const resources = new Set(); 114 115 this.traverse( ( object ) => { 116 117 if ( object.isMesh ) { 118 119 resources.add( object.geometry ); 120 resources.add( object.material ); 121 122 } 123 124 } ); 125 126 for ( const resource of resources ) { 127 128 resource.dispose(); 129 130 } 131 132 } 133 134} 135 136function createAreaLightMaterial( intensity ) { 137 138 const material = new MeshBasicMaterial(); 139 material.color.setScalar( intensity ); 140 return material; 141 142} 143 144export { RoomEnvironment };
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.