threejs--BufferGeometry创建线条

待我称王封你为后i 2022-09-10 15:11 377阅读 0赞

效果图:

在这里插入图片描述

代码实现:

方法一:

  1. const pointArr = new Float32Array([
  2. -347, 50, -520,
  3. -347, 50, 127,
  4. -345, 50, 145,
  5. -339, 50, 185,
  6. -284, 50, 270,
  7. -71, 50, 543
  8. ])
  9. const geometry = new THREE.BufferGeometry()
  10. geometry.setAttribute('position', new BufferAttribute(pointArr, 3))
  11. const lineMaterial = new THREE.LineBasicMaterial({ color: '#ff0000', side: THREE.DoubleSide })
  12. const line = new THREE.Line(geometry, lineMaterial)
  13. this.scene.add(line)

方法二:

  1. const pointArr = [
  2. -347, 50, -520,
  3. -347, 50, 127,
  4. -345, 50, 145,
  5. -339, 50, 185,
  6. -284, 50, 270,
  7. -71, 50, 543
  8. ]
  9. const geometry = new THREE.BufferGeometry()
  10. geometry.setAttribute('position', new Float32BufferAttribute(pointArr, 3))
  11. const lineMaterial = new THREE.LineBasicMaterial({ color: '#ff0000', side: THREE.DoubleSide })
  12. const line = new THREE.Line(geometry, lineMaterial)
  13. this.scene.add(line)

发表评论

表情:
评论列表 (有 0 条评论,377人围观)

还没有评论,来说两句吧...

相关阅读