Javascript 在帧中旋转后查找平面上的相对点

Javascript 在帧中旋转后查找平面上的相对点,javascript,three.js,aframe,Javascript,Three.js,Aframe,我正在使用一个帧在场景中生成一个平面。我想在给定平面xyz旋转的情况下,在平面的4条边上找到中心点 在Threejs或Aframe中是否有任何方程式或相关函数可用于获取每个角点的xyz坐标?这里有一种方法 存储原始角点坐标 有多种方法可以做到这一点,在这种情况下,我们可以只读取顶点: const mesh = this.el.getObject3D("mesh") // _vertices is a Float32Array containing the coords co

我正在使用一个帧在场景中生成一个平面。我想在给定平面xyz旋转的情况下,在平面的4条边上找到中心点

在Threejs或Aframe中是否有任何方程式或相关函数可用于获取每个角点的xyz坐标?

这里有一种方法

  • 存储原始角点坐标
  • 有多种方法可以做到这一点,在这种情况下,我们可以只读取顶点:

    const mesh = this.el.getObject3D("mesh") 
    // _vertices is a Float32Array containing the coords
    const _vertices = mesh.geometry.attributes.position.array;
    
  • 变换坐标
  • 通过将变换矩阵应用于原始坐标,我们可以得到“当前”顶点坐标:

    const mesh = this.el.getObject3D("mesh");
    const mtx = mesh.worldMatrix;
    const vec = new THREE.Vector3(x, y, z);
    vec.applyMatrix4(mtx);
    // now vec contains the x,y,z coordinates transformed by the matrix.
    
    例如:

    
    AFRAME.registerComponent(“跟踪位置”{
    init:function(){
    //用于以后计算的向量
    this.tmpV=new THREE.Vector3();
    //打印输出的元素
    this.textEl=document.querySelector(“p”)
    },
    勾选:函数(){
    const mesh=this.el.getObject3D(“网格”)//抓取网格
    //从缓冲区几何体中获取顶点
    const verticesArr=mesh.geometry.attributes.position.array;
    //得到世界变换矩阵
    const mtx=mesh.matrixWorld;
    var text=“顶点:
    ” 对于(变量i=0;i<4;i++){ //填充顶点数组中的向量 此.tmpV.fromArray(垂直阵列,i*3); //将变换矩阵应用于向量 这个.tmpV.applyMatrix4(mtx) //使用数据 text++“x:+this.tmpV.x.toFixed(2)+”,y:+this.tmpV.y.toFixed(2)+”,z:+this.tmpV.z.toFixed(2)+” } this.textEl.innerHTML=text; } })

    你好