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

话不多说,间接上代码。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));
  }

如果遇到问题能够找我

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理