关于javascript:如何更新BufferGeometry的顶点

0次阅读

共计 468 个字符,预计需要花费 2 分钟才能阅读完成。

话不多说,间接上代码。new 进去的 Mesh 的材质最好设置 side 的属性为 DoubleSide。否则挪动过程中可能是展现背面而导致视觉上看不到 Mesh

/**
   *
   * @param {*} mesh 更新的 Mesh
   * @param {*} points 新的顶点数组
   * @returns
   */
  static updateBufferGeometry(mesh, points) {if (points.some(ele => !ele || isNaN(ele.x) || isNaN(ele.y))) {return;}
    let vertices = [];
    // itemSize = 3 因为每个顶点都是一个三元组。points.forEach((point) => {vertices.push(point.x, point.y, point.z || 0);
    });
    vertices = new Float32Array(vertices);
    mesh.geometry.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
  }

如果遇到问题能够找我

正文完
 0