-
Notifications
You must be signed in to change notification settings - Fork 5
/
stars.js
70 lines (58 loc) · 2.11 KB
/
stars.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
var THREE = require('three');
var labels = require('./labels.js');
var descriptions = require('./descriptions.js');
var Stars = {
init: function(scene, scaleFactor) {
var particles, geometry, materials = [], parameters, i, color, size;
geometry = new THREE.Geometry();
// Opera 8.0+, Firefox, Chrome, Safari
var http_request = new XMLHttpRequest();
http_request.onreadystatechange = function() {
if (http_request.readyState === 4) {
// Javascript function JSON.parse to parse JSON data
var stars = JSON.parse(http_request.responseText);
var colors = [];
var colorsh = [];
var lumsh = [];
stars.forEach(function(star, i) {
var vertex = new THREE.Vector3();
vertex.x = star.pos[0] * scaleFactor;
vertex.y = star.pos[1] * scaleFactor;
vertex.z = star.pos[2] * scaleFactor;
geometry.vertices.push(vertex);
colors[i] = new THREE.Color();
colorint = star.color;
colors[i].setRGB( colorint[0]/255, colorint[1]/255, colorint[2]/255 );
colorsh[i] = [colorint[0]/255, colorint[1]/255, colorint[2]/255];
lumsh[i] = Math.pow(star.luminosity, 0.25);
var description = descriptions.getForStar(star.hip);
if( description ){
labels.addLabel(vertex, description.name, description.description, "star");
}
});
geometry.colors = colors; // For Some reason, this is still necessary...
var sMaterial = new THREE.ShaderMaterial( {
uniforms: {
cutoff: { type: 'f', value: 0.25}
},
attributes: {
color: { type: 'v3', value: colorsh },
luminosity: { type: 'f', value: lumsh }
},
vertexShader: document.getElementById('vertexshader').textContent,
fragmentShader: document.getElementById('fragmentshader').textContent,
side: THREE.DoubleSide,
blending: THREE.AdditiveBlending,
transparent: true,
depthTest: true
});
particles = new THREE.PointCloud(geometry, sMaterial);
scene.add(particles);
console.log("Stars Born");
}
};
http_request.open("GET", "data/stars.json", true);
http_request.send();
}
};
module.exports = Stars;