Published on

基础图形

Authors
  • avatar
    Name
    李丹秋
    Twitter

Object3D

这是Three.js中大部分对象的基类,提供了一系列的属性和方法来对三维空间中的物体进行操纵。 请注意,可以通过.add( object )方法来将对象进行组合,该方法将对象添加为子对象,但为此最好使用Group(来作为父对象)

Shape

可以通过SHAPE轻松实现一个二维平面的绘制, 由点绘制面

    const shape = new THREE.Shape();
    const length = 12,
      width = 8;
    shape.moveTo(0, 0);
    shape.lineTo(0, width);
    shape.lineTo(length, width);
    shape.lineTo(length, 0);
    shape.lineTo(0, 0);

以上代码就是用来创建一个长为12,宽为8的二维平面

  const heartShape = new THREE.Shape();

    heartShape.moveTo(25, 25);
    heartShape.bezierCurveTo(25, 25, 20, 0, 0, 0);
    heartShape.bezierCurveTo(-30, 0, -30, 35, -30, 35);
    heartShape.bezierCurveTo(-30, 55, -10, 77, 25, 95);
    heartShape.bezierCurveTo(60, 77, 80, 55, 80, 35);
    heartShape.bezierCurveTo(80, 35, 80, 0, 50, 0);
    heartShape.bezierCurveTo(35, 0, 25, 25, 25, 25);

也可以使用曲线,用来创建曲线图形

Line

可以通过Line轻松实现一个二维平面的绘制, 由点绘制线

     const material = new THREE.LineBasicMaterial({ color: "0x0000ff" });
    const points = [];
    points.push(new THREE.Vector3(-10, 0, 0));
    points.push(new THREE.Vector3(0, 10, 0));
    points.push(new THREE.Vector3(10, 0, 0));

    const geometry = new THREE.BufferGeometry().setFromPoints(points);
    const line = new THREE.Line(geometry, material);