首页 > 解决方案 > 三 动态更新 ConvexGeometry

问题描述

我在 Aframe 中使用 THREE.js 并尝试通过单击点来构建网格。

这是有效的,但是我正在努力更新几何以显示更改。

this._shapeEl = make('a-entity', {
  material: {color: 'blue'},
  geometry: this._vertices.length > 3 ? new THREE.ConvexGeometry( this._vertices ) : new THREE.Geometry(),
}, this.el)

点击:

var target = e.detail.intersection.point
this.el.object3D.worldToLocal(target)

make('a-sphere', {
  color: darkViolet,
  radius: 0.01,
  position: target,
}, this.el)

this._vertices.push(target)

if(this._vertices.length > 3){
  this._shapeEl.object3D.geometry = new THREE.ConvexGeometry( this._vertices )
  this._shapeEl.object3D.geometry.dynamic = true
}

球体显示,并且点被添加,但 _shapeEl 没有从蓝色立方体改变。

标签: three.jsaframe

解决方案


谢谢@Mugen87,这很有用。

答案是使用 object3Dmap.mesh

  this._shapeEl.object3DMap.mesh.geometry.dispose()
  this._shapeEl.object3DMap.mesh.geometry = new THREE.ConvexGeometry( this._vertices )

推荐阅读