phi.innerHTML = "0";
theta.innerHTML = "0";
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 1, 1000);
camera.position.set(0, 0, 10);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
var controls = new THREE.OrbitControls(camera, renderer.domElement);
var sphere = new THREE.Mesh(new THREE.SphereGeometry(2.5, 16, 12), new THREE.MeshBasicMaterial({color: "maroon", wireframe: true}));
scene.add(sphere);
renderer.domElement.addEventListener("mousedown", onMouseDown, false);
var center = new THREE.Vector2(); // default is [0.0], the center of the screen
var raycaster = new THREE.Raycaster();
var point = new THREE.Vector3();
var spherical = new THREE.Spherical();
var intersect;
function onMouseDown(event) {
raycaster.setFromCamera(center, camera);
intersect = raycaster.intersectObject(sphere);
if (intersect.length === 0) return;
sphere.worldToLocal(point.copy(intersect[0].point));
spherical.setFromVector3(point);
phi.innerHTML = THREE. Math.radToDeg(Math.PI * .5 - spherical.phi);
theta.innerHTML = THREE.Math.radToDeg(spherical.theta);
let marker = new THREE.Mesh(new THREE.BoxGeometry(.125, .125, .125), new THREE.MeshBasicMaterial({
color: Math.random() * 0xffffff,
wireframe: true
}));
marker.position.copy(intersect[0].point);
scene.add(marker);
}
render();
function render() {
requestAnimationFrame(render);
renderer.render(scene, camera);
}
body {
overflow: hidden;
margin: 0;
}
#data{
font-family: Monotype;
color: white;
position: absolute;
}
<script src="https://threejs.org/build/three.min.js"></script>
<script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>
<div id="data">
phi: <span id="phi"></span>°<br>
theta: <span id="theta"></span>°
</div>