简体   繁体   English

在球体[AFrame]上的摄像机前面添加形状(摄像机旋转/摄像机位置)

[英]Add shape in front of camera on a sphere [AFrame] (camera rotation/camera position)

I have been trying to create a simple application whereby a 360 image is shown on a Sphere. 我一直在尝试创建一个简单的应用程序,从而在Sphere上显示360图像。 The next step is to dynamically add 'hotspots' onto this image as the user pans around. 下一步是在用户平移时在该图像上动态添加“热点”。

I've tried many different approaches (including delving deep deep into Three.JS) but it doesn't seem to be that easy. 我尝试了许多不同的方法(包括深入研究Three.JS),但这似乎并不那么容易。 (UVs, positions, vertices etc). (UV,位置,顶点等)。

A-Frame is awesome at making it super simple for developers to get up and running. A-Frame很棒,它使开发人员上手和运行变得非常简单。 I managed to find an example whereby there were two 'hotspots' on a sphere, which when hovered/focused, the sphere background changed. 我设法找到一个示例,其中一个球体上有两个“热点”,当它们悬停/聚焦时,球体背景发生了变化。

I'm looking to create a new 'hotspot' in the cameras direction, however this is proving to be quite difficult because the camera position never changes but the rotation does. 我正在寻找在相机方向上创建新的“热点”的方法,但是事实证明这非常困难,因为相机位置永远不会改变,而旋转角度却会改变。

For example, after panning, I see the following: 例如,平移后,我看到以下内容:

 <a-camera position="0 2 4" camera="" look-controls="" wasd-controls="" rotation="29.793805346802827 -15.699043586584567 0"> <a-cursor color="#4CC3D9" fuse="true" timeout="10" material="color:#4CC3D9;shader:flat;opacity:0.8" cursor="maxDistance:1000;fuse:true;timeout:10" geometry="primitive:ring;radiusOuter:0.016;radiusInner:0.01;segmentsTheta:64" position="0 0 -1" raycaster=""></a-cursor> </a-camera> 

Ideally, to create a new hotspot in this position, I assumed all I'd need to do it add the rotation values to the position value and that'd be the correct place for the hotspot, but unfortunately, this doesn't work, either the hotspot is in the wrong position, it's not facing the camera or its no longer in view. 理想情况下,要在该位置创建一个新的热点,我假设我需要做的就是将旋转值添加到位置值中,这将是该热点的正确位置,但是不幸的是,这不起作用,热点位置不正确,没有面对相机或无法再看到。

How can I create a 'hotspot' in the cameras viewpoint (in the middle)? 如何在相机视点(中间)中创建“热点”?

I've setup a codepen which should help show the problem I'm having better. 我设置了一个Codepen ,它应该有助于显示我遇到的问题。 Ideally when I pan around and click 'create hotspot', a 'hotspot' should be created directly in the middle (just like the red and yellow ones). 理想情况下,当我平移并单击“创建热点”时,应直接在中间创建一个“热点”(就像红色和黄色的一样)。

Thanks! 谢谢!

UPDATE: An idea I've had is to have a secondary sphere (smaller radius) with no background. 更新:我的想法是有一个没有背景的辅助球体(半径较小)。 If it's easy to know the XYZ coordinates of the camera view intersecting it, then this is made super simple. 如果很容易知道相交的相机视图的XYZ坐标,那么这将变得非常简单。 Is there a way of finding this out? 有办法找出答案吗?

Yes, I think your second idea is right, you can make a new sphere which has seam position with your camera. 是的,我认为您的第二个想法是正确的,您可以使用相机创建一个具有接缝位置的新球体。 If you want to make a new 'hotspot' on your center of screen. 如果您想在屏幕中心创建一个新的“热点”。 you can make a raycaster from camera to the 'hotspot' and it will intersect the sphere. 您可以将光线投射器从相机投射到“热点”,它会与球体相交。 But, you should set the material's side property with 'doubleside', if not, you won't intersect the sphere. 但是,您应该将材质的side属性设置为“ doubleside”,否则,您将不会与球体相交。 then, you can get the intersect[0].point . 然后,您可以获得intersect[0].point

var pos = new THREE.Vector3().copy(cameraEl.getComputedAttribute("position"));
cameraEl.object3D.localToWorld(pos);
var vector = new THREE.Vector3(( event.clientX / window.inneenter code hererWidth ) * 2 - 1, -( event.clientY / window.innerHeight ) * 2 + 1, 0.5);
vector = vector.unproject(camera);
var raycaster = new THREE.Raycaster(pos, vector.sub(camera.position).normalize());
var intersects = raycaster.intersectObjects([sphere],true);
if(intersects.length > 0)
{
    console.log(intersects[0].point);
}

` `

Without any intersection, when you know the position of the camera, this is the vector which needs to be: negated, normalized, multiplied by a scalar value which equals to the radius of the sphere. 没有任何相交的情况下,当您知道相机的位置时,就需要将其向量化:求反,归一化,乘以等于球体半径的标量值。 The result is the point of your new hotspot. 结果就是您新的热点所在。

var pos = camera.position.clone().negate().normalize().multiplyScalar(sphereRadius);

jsfiddle example jsfiddle示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM