Skip to content
This repository was archived by the owner on Dec 17, 2025. It is now read-only.

Commit 4b98c80

Browse files
Update Celestial Bodies Page
1 parent af193b1 commit 4b98c80

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

viewers/templates/Celestial Bodies.html

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,22 @@
1919
</script>
2020

2121
<style>
22-
body{
22+
body {
2323
background-color: black;
2424
overflow: hidden;
2525
margin: 0;
2626
}
27+
28+
div {
29+
background-color: transparent;
30+
text-align: center;
31+
color: blue;
32+
}
33+
34+
label {
35+
background-color: transparent;
36+
color: blue;
37+
}
2738
</style>
2839

2940
<title>Celestial Bodies (r169)</title>
@@ -32,7 +43,13 @@
3243
<body>
3344
<!-- Reference: https://discourse.threejs.org/t/sphere-not-rendering-in-my-threejs/72442 -->
3445

35-
<div id="div_loading" style="text-align: center; color: blue; margin-top: 15px;">Fetching images ... please wait</div>
46+
<div>
47+
<label for="rotate" title="Set Cube Rotation" id="lbl_rotate" style="float: left; display: none;">
48+
<input type="checkbox" id="rotate" style="padding: 5px; margin: 5px;" checked />
49+
Rotate
50+
</label>
51+
</div>
52+
<div id="div_loading">Fetching images ... please wait</div>
3653

3754
<script type="module">
3855
import * as THREE from "three";
@@ -70,21 +87,20 @@
7087
async function createCelestialBody( name = '', size, textureUrl, position ) {
7188
let geometry = new THREE.SphereGeometry( size, 64, 32 );
7289

73-
let map = textureUrl !== '' ? texture_loader.load( textureUrl ) : normal_map;
90+
let map = textureUrl !== '' ? texture_loader.load( textureUrl ) : null;
7491

7592
let material = new THREE.MeshStandardNodeMaterial({
76-
map: name === 'Sun' ? null : map,
77-
bumpMap: name === 'Earth' ? bump_map : null,
93+
map: map,
94+
bumpMap: name === 'Earth' ? bump_map : ( name === 'Moon' ? map : null ),
7895
emissive: name === 'Sun' ? new THREE.Color( 1, 1, 1 ) : new THREE.Color( 0, 0, 0 ),
79-
emissiveMap: name === 'Sun' ? map : null,
80-
roughnessMap: name === 'Earth' ? bump_map : name === 'Moon' ? map : null,
96+
roughnessMap: name === 'Earth' ? bump_map : ( name === 'Moon' ? map : null ),
8197
normalMap: name === 'Earth' ? normal_map : null,
8298
side: THREE.DoubleSide,
8399
metalness: name === 'Sun' ? 0 : 0.25,
84-
roughness: name === 'Earth' ? 0.5 : name === 'Moon' ? 0.25 : 0
100+
roughness: name === 'Sun' ? 0 : 0.5
85101
});
86102

87-
map.dispose();
103+
if ( map ) map.dispose();
88104

89105
let body = new THREE.Mesh( geometry, material );
90106
body.position.set( position.x, position.y, position.z );
@@ -101,6 +117,8 @@
101117

102118
bump_map.dispose();
103119
normal_map.dispose();
120+
121+
document.getElementById('lbl_rotate').style.display = '';
104122
document.getElementById('div_loading').style.display = 'none';
105123
}
106124
}
@@ -167,7 +185,6 @@
167185
let controls = new OrbitControls( camera, renderer.domElement );
168186
controls.target.set( 0, 4, 0 );
169187
controls.enableDamping = true;
170-
controls.autoRotate = true;
171188
controls.autoRotateSpeed = -0.05;
172189
controls.zoomSpeed = 0.6;
173190
controls.rotateSpeed = 0.6;
@@ -203,13 +220,19 @@
203220
renderer.setAnimationLoop(() => {
204221
controls.update();
205222

206-
scene.getObjectByName( 'Earth' ).rotation.y += 0.0005; // Earth + Moon rotation
207-
scene.getObjectByName( 'Moon' ).rotation.y -= 0.0015; // Moon rotation
223+
if (document.getElementById( 'rotate' ).checked) {
224+
controls.autoRotate = true;
225+
226+
scene.getObjectByName( 'Earth' ).rotation.y += 0.0005; // Earth + Moon rotation
227+
scene.getObjectByName( 'Moon' ).rotation.y -= 0.0015; // Moon rotation
228+
} else {
229+
controls.autoRotate = false;
230+
}
208231

209232
postProcessing.render();
210233
});
211234

212-
window.addEventListener("resize", (event) => {
235+
window.addEventListener( 'resize', ( event ) => {
213236
camera.aspect = innerWidth / innerHeight;
214237
camera.updateProjectionMatrix();
215238
renderer.setSize( innerWidth, innerHeight );

0 commit comments

Comments
 (0)