5

如何更新BufferGeometry的顶点?

 3 years ago
source link: https://segmentfault.com/a/1190000040399435
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

如何更新BufferGeometry的顶点?

发布于 今天 02:24

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

如果遇到问题可以找我


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK