Skip to content

Commit 785d216

Browse files
committed
good version
1 parent da63981 commit 785d216

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

Diff for: main.js

+12-16
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
55
let camera, scene, renderer, pointer, starGroup;
66
const LIGHTYEAR_PER_PARSEC = 3.26156;
77
const canvasWidth = () => {
8-
return Math.floor(window.innerWidth*3/4);
8+
// return Math.floor(window.innerWidth*3/4);
9+
return window.innerWidth;
910
}
1011
const canvasHeight = () => {
1112
return window.innerHeight;
@@ -18,7 +19,7 @@ const distanceRange = document.getElementById("distanceRange");
1819
const distanceRangeLabel = document.getElementById("distanceRangeLabel");
1920

2021
const universeMesh = new THREE.Mesh(
21-
new THREE.SphereGeometry( Math.pow(10, distanceRange.value), 16, 16 ),
22+
new THREE.SphereGeometry( Math.pow(10, distanceRange.value)/LIGHTYEAR_PER_PARSEC, 16, 16 ),
2223
new THREE.MeshBasicMaterial({
2324
color: 0xffffff,
2425
wireframe: true
@@ -38,13 +39,17 @@ distanceRange.addEventListener("change", async(event) => {
3839

3940
universeMesh.geometry = new THREE.SphereGeometry( radius/LIGHTYEAR_PER_PARSEC, 16, 16 );
4041

41-
console.log("before:", scene);
42+
// console.log("before:", scene);
4243
let starObj = scene.getObjectByName( "stars" );
43-
console.log(starObj);
44-
starObj.children.slice().forEach(obj => starObj.remove(obj))
44+
// console.log(starObj);
45+
starObj.children.slice().forEach(obj => {
46+
if (obj.geometry) obj.geometry.dispose();
47+
if (obj.material) obj.material.dispose();
48+
starObj.remove(obj);
49+
});
4550
starObj.removeFromParent();
4651
scene.remove(starObj);
47-
console.log("after:", scene);
52+
// console.log("after:", scene);
4853
starGroup = await createStarGroup(radius/LIGHTYEAR_PER_PARSEC);
4954

5055
scene.add(starGroup);
@@ -110,16 +115,7 @@ const createStarGroup = async(maxRadius) => {
110115
return newStarGroup;
111116
}
112117

113-
// const response = await fetch("public/closest_stars.json");
114-
// const json = await response.json();
115-
// const starGroup = new THREE.Group();
116-
// json.forEach(function (row) {
117-
// let newStar = createStarMesh(row['x'], row['y'], row['z'], row);
118-
// starGroup.add(newStar);
119-
// console.log(row['proper'], row['mag'], row["spect"]);
120-
// });
121-
122-
starGroup = await createStarGroup( Math.pow(10,distanceRange.value));
118+
starGroup = await createStarGroup( Math.pow(10,distanceRange.value)/LIGHTYEAR_PER_PARSEC );
123119
scene.add( starGroup );
124120
console.log(scene);
125121
const starInfo = document.getElementById('star-info');

Diff for: style.css

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ body {
55
background: black;
66
}
77

8+
89
#star-info {
910
position: absolute;
1011
right: 0px;
11-
top: 50px;
12+
top: 0px;
1213
border: 1px solid #aa0404;
13-
width: 200px;
14+
width: 20%;
1415
height: 120px;
1516
color: rgb(255, 255, 255);
1617
pointer-events: none;
1718
}
1819

19-
2020
.slidecontainer {
2121
position: absolute;
22-
width: 150px; /* Width of the outside container */
23-
right: 150px;
22+
width: 15%; /* Width of the outside container */
23+
left: 0px;
2424
color: white;
2525
}

0 commit comments

Comments
 (0)