var W = window.innerWidth; var H = window.innerHeight; console.log(W+" : "+H); var HW = W/2; var HH = H/2; var camera, scene, renderer; var stats; var debug; var light1, light2, light3, light4; var controls, sphere, earth, moon, mercury, mars, saturn, jupiter, uranus, neptune, galaxy; var time; init(); render(); function init(){ //https://github.com/mrdoob/three.js/ camera = new THREE.PerspectiveCamera( 45, W / H, 1, 2000000 ); scene = new THREE.Scene(); renderer = new THREE.WebGLRenderer(); renderer.setSize(W,H); scene.fog = new THREE.FogExp2( 0x000000, 0.000099 ); renderer.setClearColor(0x000000); stats = new Stats(); stats.setMode(0); stats.domElement.style.position = 'absolute'; stats.domElement.style.left = '0px'; stats.domElement.style.top = '0px'; document.body.appendChild(stats.domElement); debug = document.createElement("div"); debug.style.position = 'absolute'; debug.style.left = '100px'; debug.style.top = '0px'; debug.style.width = '500px'; debug.style.height = '30px'; debug.style.fontSize = '30px'; document.body.appendChild(debug); debug.innerHTML = "DEBUG:"; light = new THREE.PointLight(0xFFFFFF, 2, 2000000); scene.add(light); //light.position.z = 1000; //light.position.y = 100; camera.position.z =1000; //Sun texture = new THREE.TextureLoader().load( "textures/sun.jpg" ) var geo = new THREE.SphereGeometry(100,25,25); var mat = new THREE.MeshBasicMaterial({ //color:0xFF0000, wireframe:false, map:texture }); sphere = new THREE.Mesh(geo,mat); scene.add(sphere); controls = new THREE.TrackballControls( camera ); controls.minDistance = 1000; controls.maxDistance = 10000; controls.panSpeed = 0.5; //Galaxy BG texture = new THREE.TextureLoader().load( "textures/ga.png" ) geo = new THREE.SphereGeometry(4500,150,0); mat = new THREE.MeshLambertMaterial({ //color:0xFF0000, wireframe:false, map:texture, side:THREE.DoubleSide }); galaxy = new THREE.Mesh(geo,mat); scene.add(galaxy); controls = new THREE.TrackballControls( camera ); controls.minDistance = 20; controls.maxDistance = 10000; controls.rotateSpeed =10; controls.panSpeed = 0.2; //Mercury texture = new THREE.TextureLoader().load( "textures/1.jpg" ) geo = new THREE.SphereGeometry(25,25,25); mat = new THREE.MeshLambertMaterial({ //color:0xFF0000, wireframe:false, map:texture }); mercury = new THREE.Mesh(geo,mat); scene.add(mercury); mercury.position.x = 250; //Venus texture = new THREE.TextureLoader().load( "textures/2.jpg" ) geo = new THREE.SphereGeometry(30,25,25); mat = new THREE.MeshLambertMaterial({ //color:0xFF0000, wireframe:false, map:texture }); venus = new THREE.Mesh(geo,mat); scene.add(venus); venus.position.x = 400; //moon texture = new THREE.TextureLoader().load( "textures/moon.jpg" ) geo = new THREE.SphereGeometry(10,25,25); mat = new THREE.MeshLambertMaterial({ //color:0xFF0000, wireframe:false, map:texture }); moon = new THREE.Mesh(geo,mat); scene.add(moon); moon.position.x = 600; //Earth texture = new THREE.TextureLoader().load( "textures/eart.jpg" ) geo = new THREE.SphereGeometry(40,25,25); mat = new THREE.MeshLambertMaterial({ //color:0xFF0000, wireframe:false, map:texture }); earth = new THREE.Mesh(geo,mat); scene.add(earth); earth.position.x = 550; //Mars texture = new THREE.TextureLoader().load( "textures/3.jpg" ) geo = new THREE.SphereGeometry(20,25,25); mat = new THREE.MeshLambertMaterial({ //color:0xFF0000, wireframe:false, map:texture }); mars = new THREE.Mesh(geo,mat); scene.add(mars); mars.position.x = 700; //Jupiter texture = new THREE.TextureLoader().load( "textures/5.jpg" ) geo = new THREE.SphereGeometry(60,25,25); mat = new THREE.MeshLambertMaterial({ //color:0xFF0000, wireframe:false, map:texture }); jupiter = new THREE.Mesh(geo,mat); scene.add(jupiter); jupiter.position.x = 900; //Saturn texture = new THREE.TextureLoader().load( "textures/6.jpg" ) geo = new THREE.SphereGeometry(60,60,60); mat = new THREE.MeshLambertMaterial({ //color:0xFF0000, wireframe:false, map:texture }); saturn = new THREE.Mesh(geo,mat); scene.add(saturn); saturn.position.x = 1100; //uranus texture = new THREE.TextureLoader().load( "textures/6.jpg" ) geo = new THREE.SphereGeometry(50,25,25); mat = new THREE.MeshLambertMaterial({ //color:0xFF0000, wireframe:false, map:texture }); uranus = new THREE.Mesh(geo,mat); scene.add(uranus); uranus.position.x = 1350; //neptune texture = new THREE.TextureLoader().load( "textures/6.jpg" ) geo = new THREE.SphereGeometry(50,25,25); mat = new THREE.MeshLambertMaterial({ //color:0xFF0000, wireframe:false, map:texture }); neptune = new THREE.Mesh(geo,mat); scene.add(neptune ); neptune .position.x = 1450; var points = []; for ( var i = 0; i < 8; i ++ ) { points.push( new THREE.Vector3( Math.sin( i * 0.5 ) * 20 + 80, 0, ( i - 3 ) * 1 ) ); } var ringsaturn = THREE.ImageUtils.loadTexture( 'texture/rings.jpg' ); geo = new THREE.LatheGeometry(points,60); mat = new THREE.MeshBasicMaterial({map:ringsaturn}); lathe = new THREE.Mesh( geo, mat ); lathe.position.set(1100,0,0); lathe.rotation.y = Math.PI/2; scene.add( lathe ); var bground = new THREE.Geometry(); for ( var i = 0; i < 2000; i ++ ) { var vertex = new THREE.Vector3(); vertex.x = THREE.Math.randFloatSpread( 5000.5000 ); vertex.y = THREE.Math.randFloatSpread( 3000.3000 ); vertex.z = THREE.Math.randFloatSpread( 3000,3000 ); bground.vertices.push( vertex ); } var bgroud_particles = new THREE.PointCloud( bground, new THREE.PointCloudMaterial( { color: 0xFFFFFF } ) ); scene.add( bgroud_particles ); controls = new THREE.TrackballControls(camera); controls.minDistance = 50; controls.maxDistance = 10000; controls.rotateDistance = 10; document.body.appendChild(renderer.domElement); } var bgroud_particles = new THREE.PointCloud( bground, new THREE.PointCloudMaterial( { color: 0xffffff } ) ); scene.add( bgroud_particles ); motionDetector = new SimpleMotionDetector( ); motionDetector.domElement.style.position = 'absolute'; motionDetector.domElement.style.left = '0px'; motionDetector.domElement.style.top = (H-200)+'px'; motionDetector.init(); document.body.appendChild( motionDetector.domElement ); if (('webkitSpeechRecognition' in window)) { speechRecognition = new webkitSpeechRecognition(); speechRecognition.continuous = true; speechRecognition.interimResults = true; speechRecognition.start(); speechRecognition.onerror = function(event) { console.log("ERROR"); } speechRecognition.onresult = function(event) { var interim_transcript = ''; for (var i = event.resultIndex; i < event.results.length; ++i) { translateTranscript(event.results[i][0].transcript); } //speechRecognition.stop(); }; } toastr.info('Welcome to SRRU 3D Solar System'); } function translateTranscript(trans){ var cmd = trans.toLowerCase(); cmd = cmd.trim(); for(var i=0;i=3 && index <=11){ closestart=true; toastr.clear(); translateTost(); }else if(index>=0 && index<=2){ toastr.clear(); toastr.info('Welcome to SRRU 3D Solar System'); closestart=false; lookstar=false; camera.position.z=normal.z; camera.lookAt(sun.position); } console.log(cmd+" : "+index); } function translateTost(){ //"back","exit","out","sun","mercury","venus","uranus","neptune","earth","ma","jupiter","saturn" if(index==3){ toastr.info("
Mean Equatorial Radius 695,508 km
XXXX
Volume X cubic miles
","Sun"); }else if(index==4){ toastr.info("
Distance from the Sun 57,909,227 miles
Mean Equatorial Radius 2,439.7 miles
Volume 60,827,208,742 cubic miles
","Mercury"); }else if(index==5){ toastr.info("
Distance from the Sun 108,209,475 miles
Mean Equatorial Radius 6,051.8 miles
Volume 928,415,345,893 cubic miles
","Venus"); }else if(index==6){ toastr.info("
Distance from the Sun 2,870,658,186 miles
Mean Equatorial Radius 25,362 miles
Volume 68,334,355,695,584 cubic miles
","Uranus"); }else if(index==7){ toastr.info("
Distance from the Sun 4,498,396,441 miles
Mean Equatorial Radius 24,622 miles
Volume 62,525,703,987,421 cubic miles
","Neptune"); }else if(index==8){ toastr.info("
Distance from the Sun 149,598,262 miles
Mean Equatorial Radius 6,371 miles
Volume 1,083,206,916,846 cubic miles
","Earth"); }else if(index==9){ toastr.info("
Distance from the Sun 227,943,824 miles
Mean Equatorial Radius 3,389.5 miles
Volume 163,115,609,799 cubic miles
","Mars"); }else if(index==10){ toastr.info("
Distance from the Sun 778,340,821 miles
Mean Equatorial Radius 69,911 miles
Volume 1,431,281,810,739,360 cubic miles
","Jupiter"); }else if(index==11){ toastr.info("
Distance from the Sun 1,426,666,422 miles
Mean Equatorial Radius 58,232 miles
Volume 827,129,915,150,897 cubic miles
","Saturn"); } //Ref https://solarsystem.nasa.gov/planets/charchart.cfm } function render(){ requestAnimationFrame( render ); stats.begin(); time = Date.now(); mercury.position.x = 250 * Math.cos(time * 0.0017); mercury.position.z = 250 * Math.sin(time * 0.0017); venus.position.x = 400 * Math.cos(time * 0.0015); venus.position.z = 400 * Math.sin(time * 0.0015); earth.position.x = 550 * Math.cos(time * 0.0009); earth.position.z = 550 * Math.sin(time * 0.0009); moon.position.x = earth.position.x+(100 * Math.cos(time * 0.009)); moon.position.z = earth.position.z+(100 * Math.sin(time * 0.009)); mars.position.x = 700 * Math.cos(time * 0.0011); mars.position.z = 700 * Math.sin(time * 0.0011); jupiter.position.x = 900 * Math.cos(time * 0.0006); jupiter.position.z = 900 * Math.sin(time * 0.0006); saturn.position.x = 1100 * Math.cos(time * 0.0004); saturn.position.z = 1100 * Math.sin(time * 0.0004); lathe.position.x = 1100 * Math.cos(time * 0.0004); lathe.position.z = 1100 * Math.sin(time * 0.0004); uranus.position.x = 1350 * Math.cos(time * 0.0001); uranus.position.z = 1350 * Math.sin(time * 0.0001); neptune.position.x = 1500 * Math.cos(time * 0.00008); neptune.position.z = 1500 * Math.sin(time * 0.00008); earth.rotation.y += 0.002; mercury.rotation.y += 0.005; venus.rotation.y += 0.001; mars.rotation.y += 0.002; jupiter.rotation.y += 0.003; saturn.rotation.y += 0.005; uranus.rotation.y += 0.002; neptune.rotation.y += 0.005; moon.rotation.y += 0.003; sphere.rotation.y -= 0.002; if(closestart){ //controls.update(); //debugmsg.innerHTML=camera.position.z+" : "+saturn.position.z; var getZ = 0; var lookpos; if(index==3){ getZ=sun.position.z; lookpos=sun.position; }else if(index==4){ getZ=mercury.position.z; lookpos=mercury.position; }else if(index==5){ getZ=venus.position.z; lookpos=venus.position; }else if(index==6){ getZ=uranus.position.z; lookpos=uranus.position; }else if(index==7){ getZ=neptune.position.z; lookpos=neptune.position; }else if(index==8){ getZ=earth.position.z; lookpos=earth.position; }else if(index==9){ getZ=mars.position.z; lookpos=mars.position; }else if(index==10){ getZ=jupiter.position.z; lookpos=jupiter.position; }else if(index==11){ getZ=saturn.position.z; lookpos=saturn.position; } if(camera.position.z>getZ+150){ camera.position.z -= 20; }else{ closestart=false; lookstar =true; } camera.lookAt(lookpos); } if(lookstar){ var getZ = 0; var lookpos; if(index==3){ getZ=sun.position.z; lookpos=sun.position; }else if(index==4){ getZ=mercury.position.z; lookpos=mercury.position; }else if(index==5){ getZ=venus.position.z; lookpos=venus.position; }else if(index==6){ getZ=uranus.position.z; lookpos=uranus.position; }else if(index==7){ getZ=neptune.position.z; lookpos=neptune.position; }else if(index==8){ getZ=earth.position.z; lookpos=earth.position; }else if(index==9){ getZ=mars.position.z; lookpos=mars.position; }else if(index==10){ getZ=jupiter.position.z; lookpos=jupiter.position; }else if(index==11){ getZ=saturn.position.z; lookpos=saturn.position; } camera.lookAt(lookpos); } renderer.render(scene, camera); stats.end(); } function onMouseMove(event){ } function onMouseDown(event){ mdown=true; } function onMouseUp(event){ // mdown=false; //camera.position=normal; //camera.lookAt(sun.position); } function onKeyDown(event){ } function onKeyUp(event){ } //controls.update(); stats.end(); renderer.render(scene, camera); }

Solar System