three.js绘制直线

先看效果:

three.js绘制直线_第1张图片

 three.js绘制直线_第2张图片

本文中创建直线的方式用了三种:

方式一:使用 Vector3创建点后,添加到geometry.vertices中(用的普通模型对象)

var p1 = new THREE.Vector3(50,10,20);
var p2 = new THREE.Vector3(10,40,30);
geometry.vertices.push(p1,p2);

方式二:使用 Vector3, LineCurve3 

var p3 = new THREE.Vector3(100,10,10);
var p4 = new THREE.Vector3(10,10,100);
var line2 = new THREE.LineCurve3(p3,p4);
let points = line2.getPoints(100);
geometry.setFromPoints(points);

方式三:使用 Vector2, LineCurve

var p5 = new THREE.Vector2(80,10);
var p6 = new THREE.Vector2(20,80);
var line3 = new THREE.LineCurve(p5,p6);
let points = line3.getPoints(100);
geometry.setFromPoints(points);

 全部代码如下:




  
  
  
  绘制二维三维直线
  
  


  

你可能感兴趣的:(three.js,javascript,开发语言,ecmascript)