正确处理 THREE.JS 中的曲线
Correctly disposing of curves in THREE.JS
我有一个球体,上面有多个移动点,我正在绘制连接这些点的曲线:
由于点在移动,我为每一帧都画了这些曲线,因此我担心内存开销很大。
每条曲线都是用
绘制的
// points = array of Three.Vector3 size 40
path = new THREE.CatmullRomCurve3(points)
mesh = new THREE.Mesh(
new THREE.TubeGeometry(path,64,0.5,false), // geometry
new THREE.MeshBasicMaterial({color: 0x0000ff}) // material
)
scene.add(mesh)
并进行处置:
scene.remove(mesh)
mesh.material.dispose()
mesh.geometry.dispose()
它 不会 但是,让我处理我的 40 Three.js 向量数组 points
和我的 CatmullRomCurve3 path
.
有什么问题,我该如何处理 new THREE.Vector3()
和 new THREE.CatmullRomCurve3()
。
What is the issue, and how do I dispose of the new THREE.Vector3() and new THREE.CatmullRomCurve3().
dispose()
three.js
中的方法主要用于释放与 JS 对象(如几何体、材质、纹理或渲染目标)关联的 GPU 内存。实例化曲线和 Vector3
等纯数学实体不会导致分配 GPU 内存。
因此,只需删除对 path
的任何引用就足够了,这样它就可以被 GC 清理。
我有一个球体,上面有多个移动点,我正在绘制连接这些点的曲线:
由于点在移动,我为每一帧都画了这些曲线,因此我担心内存开销很大。
每条曲线都是用
绘制的// points = array of Three.Vector3 size 40
path = new THREE.CatmullRomCurve3(points)
mesh = new THREE.Mesh(
new THREE.TubeGeometry(path,64,0.5,false), // geometry
new THREE.MeshBasicMaterial({color: 0x0000ff}) // material
)
scene.add(mesh)
并进行处置:
scene.remove(mesh)
mesh.material.dispose()
mesh.geometry.dispose()
它 不会 但是,让我处理我的 40 Three.js 向量数组 points
和我的 CatmullRomCurve3 path
.
有什么问题,我该如何处理 new THREE.Vector3()
和 new THREE.CatmullRomCurve3()
。
What is the issue, and how do I dispose of the new THREE.Vector3() and new THREE.CatmullRomCurve3().
dispose()
three.js
中的方法主要用于释放与 JS 对象(如几何体、材质、纹理或渲染目标)关联的 GPU 内存。实例化曲线和 Vector3
等纯数学实体不会导致分配 GPU 内存。
因此,只需删除对 path
的任何引用就足够了,这样它就可以被 GC 清理。