-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathorbits.js
48 lines (38 loc) · 1.28 KB
/
orbits.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
var THREE = require('three');
var Orbits = {
init: function(scene, scaleFactor) {
var that = this;
var particles, geometry, materials = [], parameters, i, color, size;
var material = new THREE.LineBasicMaterial({
color: '#00C362'
});
// 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
//console.log("wut ");
var orbits = JSON.parse(http_request.responseText);
orbits.forEach(function(orbitsObj) {
var posArrs = orbitsObj.steps;
//console.log(orbitsObj.name);
var geometry = new THREE.Geometry();
posArrs.forEach(function(pos){
geometry.vertices.push(
new THREE.Vector3(pos[0] * scaleFactor, pos[1] * scaleFactor, pos[2] * scaleFactor)
);
});
/*geometry.vertices.push(
new THREE.Vector3(posArrs[0][0] * scaleFactor, posArrs[0][1] * scaleFactor, posArrs[0][2] * scaleFactor)
);*/
var line = new THREE.Line( geometry, material );
scene.add( line );
});
console.log("Orbits Drawn");
}
};
http_request.open("GET", "data/starorbits.json", true);
http_request.send();
}
};
module.exports = Orbits;