如何在three.js中更新ShapeGeometry

时间:2016-09-20 08:42:20

标签: javascript three.js

我是three.js的新手,我试图更新一个ShapeGeometry,但它没有用。现在我必须删除并读取shapeMesh evertime。

    this.mesh.geometry.dispose()
    this.mesh.material.dispose()
    this.scene.remove(this.mesh)

    //vertex
    this.triangleShape = new THREE.Shape()
    this.triangleShape.moveTo(  -612+this.Eposition.left, 310-this.Eposition.top-25 )
    for(let i = 0 ; i < length ; i++) {
        this.triangleShape.lineTo(data[i][0],data[i][1])
    }
    this.triangleShape.lineTo(  -612+this.Eposition.left+141, 310-this.Eposition.top-25 )
    this.triangleShape.lineTo(  -612+this.Eposition.left+141, 310-this.Eposition.top )
    this.triangleShape.lineTo(  -612+this.Eposition.left, 310-this.Eposition.top )
    this.triangleShape.lineTo(  -612+this.Eposition.left, 310-this.Eposition.top-25 )// close path
    let geometry = new THREE.ShapeGeometry( this.triangleShape )
    this.mesh = new THREE.Mesh(geometry,this.material)
    this.scene.add(this.mesh)

我曾尝试写this.mesh.geometry.verticesNeedUpdate = true,但似乎无法正常工作

1 个答案:

答案 0 :(得分:0)

不幸的是,你无法更新ShapeGeometry使用的Shape,因为Shape只是对它创建的Geometry的更高级描述,而不是Geometry本身的一部分。

这里的要点是:Shape用矢量图形,曲线等描述。当您创建ShapeGeometry时,three.js将使用该描述来实际创建几何缓冲区(在此步骤中,曲线将被分解为线段列表,闭合路径将变为三角形,请参阅{{的实现3}})。

只要它在性能方面有效(形状不太复杂等),你当然可以为每次更新创建一个新的几何体,但由于这个过程也很昂贵,你应该考虑实现自己的Geometry或者BufferGeometry做你需要做的事情(它并不复杂。只要看一下像Cylinder [Buffer] Geometry这样的简单例子)。

相关问题