function onMouseClick(event) {
event.preventDefault();
// Calculate normalized device coordinates (NDC) from mouse coordinates
const mouse = new THREE.Vector2();
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
// Create a ray from the camera through the mouse's NDC
const raycaster = new THREE.Raycaster();
raycaster.setFromCamera(mouse, camera);
// Intersect the ray with the sphere
const intersects = raycaster.intersectObject(mesh);
console.log(intersects[0].uv);
const inputDiv = document.createElement('div');
inputDiv.style.position = 'absolute';
inputDiv.style.zIndex = '1';
inputDiv.style.left = intersects[0].uv.x + "px";
inputDiv.style.top = intersects[0].uv.y + "px";
// Create an input text box element and add it to the div
const inputBox = document.createElement('input');
inputBox.style.position = 'absolute'
inputBox.style.width = '200px';
inputBox.style.height = '60px';
inputBox.style.border = '1.5px solid black';
inputBox.style.borderRadius = '5px';
inputBox.type = 'text';
inputBox.style.display = "block";
inputDiv.appendChild(inputBox);
// Append the div to the document body
document.body.appendChild(inputDiv);
// Add an event listener to handle input text changes
inputBox.addEventListener('input', function () {
const xValue = parseFloat(inputBox.value); // Parse the X coordinate from the input
// You can use xValue for your desired purpose
console.log(xValue);
});
// Remove the div when you're done with it (e.g., when you click outside of it)
document.addEventListener('dblclick', function (e) {
if (!inputDiv.contains(e.target)) {
document.body.removeChild(inputDiv);
}
});
}
window.addEventListener('dblclick', onMouseClick);
This is my code