Skip to content

Commit

Permalink
Gave satellites random rotation on spawn.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cdkushni committed Sep 16, 2018
1 parent d57b65d commit ac46e4d
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/3js_resources/globeScene.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ export default class globeScene {
scene.add(baseMap);
setEvents(this.camera, [this.earthMesh], 'mousemove', 10);
setEvents(this.camera, [this.earthMesh], 'click', 10);

document.getElementById("exportBtn").addEventListener("click", function() {
exportSceneGLB();
})
/*
var loader = new THREE.JSONLoader();
var test = loader.load('/src/3js_resources/sat.json', function(geometry, materials) {
Expand All @@ -118,11 +122,11 @@ export default class globeScene {
setInterval(() => satData.on('value', snapshot => {
serverSatHandle(snapshot, scene, this.satelliteRefs);
}), 10000);
/*

var planeData = firebase.database().ref('planes');
setInterval(() => planeData.on('value', snapshot => {
planeHandle(snapshot, scene, this.planeRefs);
}), 20000);*/
}), 20000);
});
}

Expand Down Expand Up @@ -391,20 +395,22 @@ function satelliteHandler(snapshot, scene, satelliteRefs) {

function planeHandle(snapshot, scene, planeRefs) {
var planes = snapshot.val();
console.log(snapshot.val());
for(var key in planes) {
if(planes.hasOwnProperty(key)) {
var targetLoc = latLongToCoords(planes[key].lat, planes[key].lon, 450 + (planes[key].alt/1000));
if (!(key in planeRefs)) {
var planeModel = new THREE.Mesh(new THREE.CubeGeometry(0.5,0.5,0.5), new THREE.MeshBasicMaterial('#EEEEEE'));
planeModel.scale.x = planeModel.scale.y = planeModel.scale.z = 2;
planeRefs[planes[key].norad] = planeModel;
planeRefs[planes[key].norad] = copyVector(planeModel, location);
planeRefs[planes[key].norad] = copyVector(planeModel, targetLoc);
scene.add( planeModel );
} else {
planeRefs[planes[key].norad] = copyVector(planeRefs[planes[key].norad], location);
planeRefs[planes[key].norad] = copyVector(planeRefs[planes[key].norad], targetLoc);
}
}
}
console.log(scene);
}

function serverSatHandle(snapshot, scene, satelliteRefs) {
Expand All @@ -422,7 +428,9 @@ function serverSatHandle(snapshot, scene, satelliteRefs) {
// scene.add( satModel );
var satModel = new THREE.Mesh(geometry, new THREE.MeshBasicMaterial('#EEEEEE'));
satModel.scale.x = satModel.scale.y = satModel.scale.z = 0.2;
satModel.rotation.x;
satModel.rotation.x = Math.random() * 5;
satModel.rotation.y = Math.random() * 5;
satModel.rotation.z = Math.random() * 5;
satModel = copyVector(satModel, location);
satelliteRefs[satellites[key].norad] = satModel;
scene.add( satModel );
Expand Down Expand Up @@ -467,9 +475,9 @@ function save( blob, filename ) {

function saveArrayBuffer( buffer, filename ) {

//save( new Blob( [ buffer ], { type: 'application/octet-stream' } ), filename );
const fs = require('fs');
var path = require('path');
save( new Blob( [ buffer ], { type: 'application/octet-stream' } ), filename );
//const fs = require('fs');
//var path = require('path');
//fs.appendFile(path.join(__dirname, 'scene.glb'),new Buffer(buffer));
/*var ie_writeFile = function (filename, buffer) {
var fso, fileHandle;
Expand Down

0 comments on commit ac46e4d

Please sign in to comment.