关于javascript:threejs文档翻译二画线

6次阅读

共计 1039 个字符,预计需要花费 3 分钟才能阅读完成。

原文地址: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

上一篇:threejs 文档翻译:一. 创立场景

正文完
 0