在编写Three.js的时候,设置线模型Line
对应线材质LineBasicMaterial
的线宽属性lineWidth
,是无效的。官方解释
Due to limitations of the OpenGL Core Profile with the WebGL renderer on most platforms linewidth will always be 1 regardless of the set value.
即由于opengl核心库文件的限制,webgl渲染器在大部分平台上linewidth一直是1,无视你设置的值;
这里通过Line2方式解决(亲测可用)
1 导入相关包
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'
2 创建线条模型
var geometry = new LineGeometry()
var pointArr = [-100, 0, 0,-100, 100, 0]
geometry.setPositions(pointArr)
var material = new LineMaterial({
color: "red",
linewidth: 15
})
material.resolution.set(window.innerWidth, window.innerHeight)
var line = new Line2(geometry, material)
line.computeLineDistances()
scene.add(line)