【发布时间】:2021-02-26 14:41:59
【问题描述】:
我用 PerspectiveCamera 创建了一张全景图像,一切顺利。我还设法添加了控件。 现在我想在场景中放置一个可点击元素(链接/按钮/其他),但我不知道如何添加和定位可点击元素……每一个提示/建议都非常感谢!到目前为止,这是我的代码:
function init() {
const container = document.getElementById( 'three-image' );
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 1100 );
scene = new THREE.Scene();
const geometry = new THREE.SphereGeometry( 500, 60, 40 );
// invert the geometry on the x-axis so that all of the faces point inward
geometry.scale( - 1, 1, 1 );
//let imageLocation = <?php echo $block->getPanoramaImages();?>;
let imageLocation = '/three/luifel.jpg';
//alert(imageLocation)
const texture = new THREE.TextureLoader().load(imageLocation);
const material = new THREE.MeshBasicMaterial( { map: texture } );
const mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
container.style.touchAction = 'none';
container.addEventListener( 'pointerdown', onPointerDown );
document.addEventListener( 'wheel', onDocumentMouseWheel );
window.addEventListener( 'resize', onWindowResize );
}
【问题讨论】:
-
我认为您正在寻找 Raycaster。 Here it is in the docs,您也可以看到它in action in the exaples。该示例激活了“mousemove”上的每个方块,因此您可以添加具有相同逻辑的“click”事件侦听器。
标签: three.js