当前位置:网站首页>Three.js开发:粗线的画法
Three.js开发:粗线的画法
2022-06-29 20:00:00 【地理信息技术杂谈】
Three.js的开发中,画线时,使用THREE.Line或者THREE.LineSegments进行画线时,发现在材质中设置线的宽度并不起作用,在查阅Three.js的文档发现,以上方式,对应的是webgl中gl.LINE_STRIP 或者 gl.LINES,这在一些浏览器渲染时,并不起作用,所以,Three.js扩展了一个画粗线的方法,具体的使用方法如下:
相关的类库放在Three.js包的example中,首先引用相应的js文件
<script src="three/examples/js/lines/LineSegments2.js"></script>
<script src="three/examples/js/lines/Line2.js"></script>
<script src="three/examples/js/lines/LineMaterial.js"></script>
<script src="three/examples/js/lines/LineSegmentsGeometry.js"></script>
<script src="three/examples/js/lines/LineGeometry.js"></script>
//初始化一个线的类型
let linegeometry = new THREE.LineGeometry();
linegeometry.setPositions('一维数组类型的坐标点,每3个一组');
//初始化线的材质
let matLine = new THREE.LineMaterial({
//颜色宽度等属性设置,可以通过顶点渲染线,也可以设置统一颜色
color: 0x0000ff,
linewidth: 2,
vertexColors: false
});
//材质的分辨率必须设置,要不显示的线宽度不正确
matLine.resolution.set(window.innerWidth, window.innerHeight);
//添加一个线对象,Line2或者LineSegments2都可以
//let buildoutline = new THREE.Line2(
let buildoutline = new THREE.LineSegments2(linegeometry,matLine);
//场景添加线
scene.add(buildoutline);
实现效果如下:
引用内容:
https://github.com/mrdoob/three.js/blob/master/examples/webgl_lines_fat.html
https://threejs.org/docs/index.html?q=line#api/en/objects/Line

边栏推荐
- 【U盘检测】为了转移压箱底的资料,买了个2T U盘检测仅仅只有47G~
- Game maker Foundation presents: Valley of belonging
- 【摸鱼神器】UI库秒变低代码工具——表单篇(一)设计
- static静态成员变量使用@Value注入方式
- thinkphp5中的配置如何使用
- 【Try to Hack】vulnhub narak
- [fishing artifact] code tool for lowering the seconds of UI Library -- form part (I) design
- NLP - giza++ implements word alignment
- 【编译原理】类型检查
- Physical verification LVS process and Technology (Part I)
猜你喜欢
随机推荐
【编译原理】语法分析
PHP implementation extracts non repeated integers (programming topics can be the fastest familiar functions)
14.04 million! Sichuan provincial human resources and social security department relational database and middleware software system upgrade procurement bidding!
lock4j--分布式锁中间件--自定义获取锁失败的逻辑
Flume configuration 2 - ganglia for monitoring
网站压力测试工具——Webbench
A keepalived high availability accident made me learn it again!
通过MeterSphere和DataEase实现项目Bug处理进展实时跟进
关于印发宝安区重点产业项目和总部项目遴选及用地保障实施细则(2022修订版)的通知
proxmox集群节点崩溃处理
Withdrawal of user curve in qualified currency means loss
软件工程—原理、方法与应用
Classic illustration of K-line diagram (Collection Edition)
Performance improvement at the cost of other components is not good
Etcd database source code analysis - put process of server
Several policies of Shenzhen Futian District to support investment attraction in 2022
Flume理论
Sword finger offer 66 Building a product array
雪花id,分布式唯一id
Understanding of software test logic coverage







![[fishing artifact] code tool for lowering the seconds of UI Library -- form part (I) design](/img/ad/0efd744334bf648b149aa1841b58af.png)
