Skip to content

一、多个线条组合曲线CurvePath

通过组合曲线CurvePath可以把多个圆弧线、样条曲线、直线等多个曲线合并成一个曲线。

curve-9.png

1. U型

javascript
    const geometry = new THREE.BufferGeometry(); //声明一个几何体对象Geometry
// 绘制一个U型轮廓
const R = 80;//圆弧半径
const arc = new THREE.ArcCurve(0, 0, R, 0, Math.PI, true);
// 半圆弧的一个端点作为直线的一个端点
const line1 = new THREE.LineCurve(new THREE.Vector2(R, 200, 0), new THREE.Vector2(R, 0, 0));
const line2 = new THREE.LineCurve(new THREE.Vector2(-R, 0, 0), new THREE.Vector2(-R, 200, 0));
// 创建组合曲线对象CurvePath
const CurvePath = new THREE.CurvePath();
// 把多个线条插入到CurvePath中
CurvePath.curves.push(line1, arc, line2);
//分段数200
const points = CurvePath.getPoints(200);
// setFromPoints方法从points中提取数据改变几何体的顶点属性vertices
geometry.setFromPoints(points);
//材质对象
const material = new THREE.LineBasicMaterial({
  color: 0x000000
});
//线条模型对象
const line = new THREE.Line(geometry, material);
scene.add(line); //线条对象添加到场景中

Released under the MIT License.