原文地址:https://threejs.org/docs/inde...
如果你是想画线或者画圈,而不是线框网格。首先我们要设置渲染器,场景和相机。
这是我们要使用的代码:
const renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
const camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 500 );
camera.position.set( 0, 0, 100 );
camera.lookAt( 0, 0, 0 );
const scene = new THREE.Scene();
接下来我们要定义材料,线条我们使用的是LineBasicMaterial或者LineDashedMaterial
//create a blue LineBasicMaterial
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 );
剩下的就是把它们加到场景里然后调用渲染器。
scene.add( line );
renderer.render( scene, camera );
你现在应该可以看见由两条线组成向上的蓝色箭头。
demo地址:https://github.com/wanzizi/three_test/blob/master/demo/line.html
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。