three.js中直线的创建,以及new THREE.LineBasicMaterial不能设置宽度问题。

直线的创建  导入相关包

import * as THREE from 'three'
import OrbitControls from 'three-orbitcontrols'
import { Line2 } from 'three/examples/jsm/lines/Line2'
import { LineGeometry } from 'three/examples/jsm/lines/LineGeometry'
import { LineMaterial } from 'three/examples/jsm/lines/LineMaterial'

1、用LineBasicMaterial创建的线条发现无法设置宽度,官方给的答案就是始终1

 

      this.EarthLine("#00d321"); //创建地球中心直线
EarthLine(color) {
     const lineArr = [
        new THREE.Vector3(0, 70, 0),
        new THREE.Vector3(0, -70, 0),
      ];
      const material = new THREE.LineBasicMaterial({
        color: color,
        linewidth: 100,
      });
      const linegeometry = new THREE.BufferGeometry().setFromPoints(lineArr);
      const line = new THREE.Line(linegeometry, material);
      this.scene.add(line);
}

2、此方法可以设置宽度

EarthLine(color) {
      var geometry = new LineGeometry();
      var pointArr = [0, 80, 0, 0, -80, 0];
      geometry.setPositions(pointArr);
      var material = new LineMaterial({
        color: color,
        linewidth: 3,
      });
      material.resolution.set(window.innerWidth, window.innerHeight);
      var line = new Line2(geometry, material);
      line.computeLineDistances();
      this.scene.add(line);
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值