屏幕格式中的标记位置(使用 AR.js)

Marker position in Screen format (using AR.js)

我能够使用以下代码获得标记位置

this.marker.object3D.getWorldPosition(vector);

我想知道是否可以将此位置 (x,y,z) 转换为等效的屏幕位置(宽度,高度)。

你能给我一些解决这个问题的想法吗?

您可以通过两个步骤完成此操作:

  • 通过 Vector3.project().
  • 将世界 space 中的位置转换为 NDC space
  • 使用 canvas 的 widthheight 进行屏幕 space 转换。
const vector = new THREE.Vector3();
vector.project( camera ); 

vector.x = ( vector.x + 1) * width / 2;
vector.y = - ( vector.y - 1) * height / 2;
vector.z = 0;