-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprepare.js
160 lines (112 loc) · 3.26 KB
/
prepare.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
var options = {
catalogs: {
hipparcos: true
,hd: true
,harvard: true
,gliese: true
}
,useRelativeMagnitude: false
,onlyProperNames: false
}
var vrDisplay;
var vrEnabled = false;
if (navigator.getVRDisplays) {
navigator.getVRDisplays().then(function (displays) {
if(displays.length > 0){
vrDisplay = displays[0];
vrEnabled = true;
}
});
}
var renderer = new Renderer();
var imageLoader = new ImageLoader();
function ImageLoader(){
var numberLoader = new XMLHttpRequest();
numberLoader.open("GET", "./data/numbers.dat", true);
numberLoader.responseType = "arraybuffer";
var stringLoader = new XMLHttpRequest();
stringLoader.open("GET", "./data/stringsOnly.csv", true);
stringLoader.responseType = "text";
var stringsArray;
var numbersView;
var filesLoaded = 0;
var filesToLoad = 2;
numberLoader.onload = function (oEvent) {
var arrayBuffer = numberLoader.response;
console.log(arrayBuffer.length);
if (arrayBuffer) {
numbersView = new DataView(arrayBuffer);
filesLoaded++;
loadingBar.style.width = 100*filesLoaded/filesToLoad + "%";
if(filesLoaded == filesToLoad){
process();
}
} else {
console.error("A bad happened");
}
};
stringLoader.onload = function (oEvent) {
stringsArray = stringLoader.responseText;
if(stringsArray){
stringsArray = stringsArray.split("\n")
for(var i in stringsArray){
stringsArray[i] = stringsArray[i].split(",");
}
filesLoaded++;
loadingBar.style.width = 100*filesLoaded/filesToLoad + "%";
if(filesLoaded == filesToLoad){
process();
}
} else {
console.error("A bad happened");
}
};
stringLoader.send();
numberLoader.send();
function process(strings, numbers){
var strings = stringsArray;
var numbers = numbersView;
var points = [];
var sizeX = 1000;
var sizeY = 1000;
var sizeZ = 1000;
var xScale = 1;
var yScale = 1;
var zScale = 1;
for(var i = 0; i < numbers.byteLength/28/4; i++){
var stringData = strings[i];
var numbersIndex = i*28*4+ 0;
if(
(
(options.catalogs.hipparcos && numbers.getFloat32(numbersIndex+1*4, false) != 0) ||
(options.catalogs.hd && numbers.getFloat32(numbersIndex+2*4, false) != 0) ||
(options.catalogs.harvard && numbers.getFloat32(numbersIndex+3*4, false) != 0) ||
(options.catalogs.gliese && stringData[0] != "")
) && (!options.onlyProperNames || stringData[2] != "")
){
var magnitude = 0;
if(options.useRelativeMagnitude){
magnitude = numbers.getFloat32(numbersIndex+10*4, false);
} else {
magnitude = numbers.getFloat32(numbersIndex+11*4, false);
}
points.push({
magnitude: magnitude
,colorIndex: numbers.getFloat32(numbersIndex+12*4, false)
,x: numbers.getFloat32(numbersIndex+13*4, false)
,y: numbers.getFloat32(numbersIndex+14*4, false)
,z: numbers.getFloat32(numbersIndex+15*4, false)
});
}
}
document.getElementById("points").innerHTML = "Stars: "+points.length;
var done = renderer.addPoints(points, sizeX, sizeY, sizeZ, xScale, yScale, zScale);
document.getElementById("loading").style.display = "none";
}
return {
process: process
};
}
function setBackground(div){
document.getElementById('renderCanvas').style.backgroundColor = div.style.backgroundColor;
}