After creating a WebGL 3D Panorama application using a SphereGeometry, PerspectiveCamera, and CanvasTexture, I am now trying to enhance the scene by adding "HotSpots" over specific areas of the SphereGeometry. However, I am facing difficulty in updating the positions of various DOMElements based on the Camera's movement.
As the Camera rotates, I want the DOMElements to move in and out of view according to the camera's spin direction. My attempts at positioning a div absolutely to the canvas and translating its X and Y positions using the PerspectiveCamera's rotation property did not yield desired results. Here is my implementation in JavaScript and CSS:
CSS
#TestHotSpot {
margin-top: 50px;
margin-left: 50px;
width: 50px;
height: 50px;
background: red;
position: absolute;
}
JavaScript
/**
CONFIG is a stored object variable that contains the PerspectiveCamera instance
**/
config.camera.updateProjectionMatrix();
config.controls.update(delta);
document.getElementById("TestHotSpot").style.transform = "translate("+ config.camera.rotation.x +"px, "+ config.camera.rotation.y +"px)";
Here is an example demonstrating the desired effect live.
I am seeking the best solution to resolve this issue. When testing my code, I noticed that the DOMElements moved only slightly and did not consider their placement relative to the SphereGeometry (e.g., if they were positioned behind the Camera). Any recommendations for resolving this complexity are appreciated!
I am open to utilizing plugins for the THREE.js engine or following tutorials. Thank you in advance for your assistance!