【发布时间】:2015-10-26 11:29:33
【问题描述】:
我使用SphereGeometry、PerspectiveCamera 和CanvasTexture 创建了一个简单的WebGL 3D 全景应用程序。现在,我希望通过在SphereGeometry 的某些部分添加“热点”来使场景栩栩如生。我遇到的问题是了解如何更新各种DOMElements,以便它们的位置反映更新后的Camera 位置。
基本上,随着Camera 的旋转,各种DOMElements 会相对于相机旋转的方向进出视野。我尝试使用返回的PerspectiveCamera camera.rotation 将<div> absolute 定位到<canvas> 和translating X 和Y 位置,但它并没有真正起作用;这是我的 JS 和 CSS 实现:
CSS
#TestHotSpot {
/* not sure if using margins is the best method to position hotspot */
margin-top: 50px;
margin-left: 50px;
width: 50px;
height: 50px;
background: red;
position: absolute;
}
JavaScript
/**
CONFIG is my stored object variable; it contains the PerspectiveCamera instance
code is being called inside of my RequestAnimationFrame
**/
config.camera.updateProjectionMatrix();
config.controls.update(delta);
document.getElementById("TestHotSpot").style.transform = "translate("+ config.camera.rotation.x +"px, "+ config.camera.rotation.y +"px)";
Here 也是所需效果的一个活生生的例子。
解决此问题的最佳解决方案是什么?当我运行它时我注意到DOMElements 只会轻微移动;我还注意到他们并没有真正考虑到它们被放置在SphereGeometry 的哪个位置(例如,被定位在Camera 的“后面”;真的很复杂!
我很乐意为THREE.js 引擎使用任何插件,并遵循任何教程。非常感谢您提前回复!
【问题讨论】:
标签: javascript css three.js