|
91 | 91 | body.name = name; |
92 | 92 | scene.add( body ); |
93 | 93 |
|
94 | | - if (name === 'Earth') earth_loaded = true; |
95 | | - if (name === 'Moon') moon_loaded = true; |
| 94 | + if (name === 'Earth') { body.receiveShadow = true; earth_loaded = true; } |
| 95 | + if (name === 'Moon') { body.castShadow = true; moon_loaded = true; } |
96 | 96 | if (name === 'Sun') sun_loaded = true; |
97 | 97 |
|
98 | | - if (earth_loaded && moon_loaded && sun_loaded) { |
| 98 | + if (earth_loaded === true && moon_loaded === true && sun_loaded === true) { |
| 99 | + scene.getObjectByName( 'Earth' ).add( scene.getObjectByName( 'Moon' ) ); |
| 100 | + scene.getObjectByName( 'Earth' ).rotation.y -= Math.PI / 3.0; |
| 101 | + |
99 | 102 | bump_map.dispose(); |
100 | 103 | normal_map.dispose(); |
101 | 104 | document.getElementById('div_loading').style.display = 'none'; |
|
118 | 121 | texture.dispose(); |
119 | 122 | }, undefined, () => { console.log( 'Error loading textures' ) }); |
120 | 123 |
|
| 124 | + await createCelestialBody( |
| 125 | + 'Sun', |
| 126 | + 5, |
| 127 | + '', |
| 128 | + { x: 50, y: 3, z: 15 } |
| 129 | + ); |
| 130 | + |
| 131 | + await createCelestialBody( |
| 132 | + 'Moon', |
| 133 | + 0.5, |
| 134 | + 'https://raw.githubusercontent.com/mrdoob/three.js/master/examples/textures/planets/moon_1024.jpg', |
| 135 | + { x: 5, y: 1, z: 1.35 } |
| 136 | + ); |
| 137 | + |
| 138 | + await createCelestialBody( |
| 139 | + 'Earth', |
| 140 | + 2.25, |
| 141 | + 'https://raw.githubusercontent.com/mrdoob/three.js/master/examples/textures/planets/earth_atmos_4096.jpg', |
| 142 | + { x: -4, y: 3, z: -0.25 } |
| 143 | + ); |
| 144 | + |
121 | 145 | let camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 10000 ); |
122 | 146 | isMobile === true ? camera.position.set( 0, 0, 50 ) : camera.position.set( 0, 0, 12 ); |
123 | 147 | scene.add( camera ); |
|
141 | 165 | document.body.appendChild( renderer.domElement ); |
142 | 166 |
|
143 | 167 | let controls = new OrbitControls( camera, renderer.domElement ); |
144 | | - controls.target.set( 0, 3, 0 ); |
| 168 | + controls.target.set( 0, 4, 0 ); |
145 | 169 | controls.enableDamping = true; |
| 170 | + controls.autoRotate = true; |
| 171 | + controls.autoRotateSpeed = -0.05; |
146 | 172 | controls.zoomSpeed = 0.6; |
147 | 173 | controls.rotateSpeed = 0.6; |
148 | 174 | controls.keyPanSpeed = 0.6; |
149 | 175 | controls.panSpeed = 0.6; |
150 | 176 |
|
151 | 177 | let light = new THREE.DirectionalLight( 0xffffff, 5 ); |
152 | | - light.position.set( 25, 5, 50 ); |
153 | | - let ambient_light = new THREE.AmbientLight( 0xffffff, 0.075 ); |
| 178 | + light.position.set( 50, 3, 15 ); |
| 179 | + light.castShadow = true; |
| 180 | + light.shadow.mapSize.width = 2048; |
| 181 | + light.shadow.mapSize.height = 2048; |
| 182 | + |
| 183 | + let ambient_light = new THREE.AmbientLight( 0xffffff, 0.09 ); |
154 | 184 | ambient_light.position.set( -3, 3, -25 ); |
| 185 | + |
155 | 186 | scene.add( light, ambient_light ); |
156 | 187 |
|
157 | 188 | // Emissive bloom post processing |
|
164 | 195 |
|
165 | 196 | let outputPass = scenePass.getTextureNode(); |
166 | 197 | let emissivePass = scenePass.getTextureNode( 'emissive' ); |
167 | | - let bloomPass = bloom( emissivePass, 1.5, 0.35 ); |
| 198 | + let bloomPass = bloom( emissivePass, 2.5, 0.35 ); |
168 | 199 |
|
169 | 200 | let postProcessing = new THREE.PostProcessing( renderer ); |
170 | 201 | postProcessing.outputNode = outputPass.add( bloomPass ); |
171 | 202 |
|
172 | 203 | renderer.setAnimationLoop(() => { |
173 | 204 | controls.update(); |
174 | 205 |
|
175 | | - scene.rotation.y -= 0.00005; // Scene rotation |
176 | | - scene.getObjectByName( 'Earth' ).rotation.y += 0.0005; // Earth rotation |
177 | | - scene.getObjectByName( 'Moon' ).rotation.y -= 0.001; // Moon rotation |
| 206 | + scene.getObjectByName( 'Earth' ).rotation.y += 0.0005; // Earth + Moon rotation |
| 207 | + scene.getObjectByName( 'Moon' ).rotation.y -= 0.0015; // Moon rotation |
178 | 208 |
|
179 | 209 | postProcessing.render(); |
180 | 210 | }); |
181 | 211 |
|
182 | | - await createCelestialBody( |
183 | | - 'Sun', |
184 | | - 5, |
185 | | - '', |
186 | | - { x: 25, y: 5, z: 50 } |
187 | | - ); |
188 | | - |
189 | | - await createCelestialBody( |
190 | | - 'Moon', |
191 | | - 0.5, |
192 | | - 'https://raw.githubusercontent.com/mrdoob/three.js/master/examples/textures/planets/moon_1024.jpg', |
193 | | - { x: 2.5, y: 3, z: 0 } |
194 | | - ); |
195 | | - |
196 | | - await createCelestialBody( |
197 | | - 'Earth', |
198 | | - 2.25, |
199 | | - 'https://raw.githubusercontent.com/mrdoob/three.js/master/examples/textures/planets/earth_atmos_4096.jpg', |
200 | | - { x: -4, y: 3, z: 0 } |
201 | | - ); |
202 | | - |
203 | 212 | window.addEventListener("resize", (event) => { |
204 | 213 | camera.aspect = innerWidth / innerHeight; |
205 | 214 | camera.updateProjectionMatrix(); |
|
0 commit comments