var scene = new THREE.Scene(); var camera = new THREE.PerspectiveCamera(HorToVertFOV(90, (window.innerWidth / window.innerHeight)), window.innerWidth / window.innerHeight, 0.1, 10000); //var camera = new THREE.PerspectiveCamera( 90, 1, 0.1, 1000 ); var renderer = new THREE.WebGLRenderer({ alpha: true }); var panoGeometry = new THREE.SphereGeometry(.25, 16, 16); panoGeometry.applyMatrix(new THREE.Matrix4().makeScale(-1, 1, 1)); /*var testMaterial = new THREE.MeshBasicMaterial( { color: 0x22cc22 } ); var testMaterial2 = new THREE.MeshBasicMaterial( { color: 0x111111 } );*/ var pathGeometry = new THREE.CubeGeometry(1, 1, 1); var materials = {}; var curSpheres = []; var animatedSpheres = []; $(document).ready(function() { renderer.setSize(window.innerWidth, window.innerHeight); ///renderer.setSize( 500, 500 ); document.body.appendChild(renderer.domElement); renderer.domElement.id = "WebGL"; //createTestSphere( 0, 1000, 0 ); render(); }); function createTestSphere(heading, distance) { var testMesh = new THREE.Mesh(panoGeometry, testMaterial); var hRad = heading * Math.PI / 180; testMesh.position.y = -2; testMesh.position.z = Math.cos(hRad) * -distance; testMesh.position.x = Math.sin(hRad) * distance; scene.add(testMesh); //console.log("Added Sphere at h:"+heading+" d:"+distance+ " "+testMesh.position.x + ", " + testMesh.position.z); } function createPanoSphere(heading, distance, panoLink, rot) { var m = materials[panoLink.pano]; //console.log("val of m: " + m); if (m === undefined) { m = null; getPanoImage(panoLink.pano, function(dataUrl) { var tex = THREE.ImageUtils.loadTexture(dataUrl); materials[panoLink.pano] = new THREE.MeshBasicMaterial({ map: tex }); materials[panoLink.pano].jumpUnused = 0; panoLink.sphere = createSphere(heading, distance, materials[panoLink.pano], rot); }); } else { if (m) m.jumpUnused = 0; panoLink.sphere = createSphere(heading, distance, m, rot); return; } panoLink.sphere = null; } function createSphere(heading, distance, material, rot) { var testMesh = new THREE.Mesh(panoGeometry, material); var hRad = heading * Math.PI / 180; testMesh.position.z = Math.cos(hRad) * -distance; testMesh.position.x = Math.sin(hRad) * distance; testMesh.distance = distance; testMesh.position.y = -2; testMesh.rotation.y = (-rot - 90) * Math.PI/180; testMesh.heading = hRad; testMesh.startPos = testMesh.position.clone(); scene.add(testMesh); //console.log("Added Sphere at h:"+heading+" d:"+distance+ " "+testMesh.position.x + ", " + testMesh.position.z); curSpheres.push(testMesh); return testMesh; } function getHipCameraPoint(){ return new THREE.Vector3(Math.sin(panorama.getPov().heading * Math.PI / 180), 0, -Math.cos(panorama.getPov().heading * Math.PI / 180 )).multiplyScalar(2); } function SyncThreeCamera(heading, pitch) { var rot = new THREE.Matrix4().makeRotationY(-heading * Math.PI / 180).multiply(new THREE.Matrix4().makeRotationX(pitch * Math.PI / 180)); camera.matrixWorld = rot; camera.matrixAutoUpdate = false; } function render() { requestAnimationFrame(update); renderer.render(scene, camera); } function update(time){ //console.log(spheros); for (var i = 0; i < curSpheres.length; ++i){ if(curSpheres[i].anim){ console.log(curSpheres[i].anim); curSpheres[i].position = curSpheres[i].anim.animate(); } } render(); } function HorToVertFOV(horFOV, aspectRatio) { var horFOV = horFOV * Math.PI / 180; var vfov = 2 * Math.atan(Math.tan(horFOV / 2) / aspectRatio); return vfov * 180 / Math.PI; } function nukeSpheres() { for (var i = 0; i < curSpheres.length; ++i) { scene.remove(curSpheres[i]); }; curSpheres = []; incrementAndClean(4); } function incrementAndClean(limit) { for (var mat in materials) { var actualmat = materials[mat]; if (actualmat) { actualmat.jumpUnused += 1; if (actualmat.jumpUnused > limit) { actualmat.dispose(); delete materials[mat]; if (materials[mat]) alert("deletion failed!"); } } } } function Ease(startPosition, endPosition, animLength){ this.timeStart = performance.now(); this.startPosition = startPosition.clone(); this.endPosition = endPosition.clone(); this.path = endPosition.clone().sub(startPosition); this.animLength = animLength; this.time = 0; this.animate = function(){ this.time = performance.now() - this.timeStart; return this.startPosition.clone().add(this.path.clone().multiplyScalar(THREE.Math.smootherstep(this.time / this.animLength, 0 ,1))); } } function cameraFromGoogleZoom(zoom){ var fov = 180 / Math.pow(2, zoom); return new THREE.PerspectiveCamera(HorToVertFOV(fov, (window.innerWidth / window.innerHeight)), window.innerWidth / window.innerHeight, 0.1, 10000); }