設定 renderer
var renderer = new THREE.WebGLRenderer(); renderer.setSize( window.innerWidth, window.innerHeight ); document.body.appendChild( renderer.domElement );
建立攝影機並設置在中央
var camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 500 ); camera.position.set( 0, 0, 50 ); camera.lookAt( 0, 0, 0 );
建立場景
var scene = new THREE.Scene();
設定線的材質與位置
var material = new THREE.LineBasicMaterial( { color: 0x0000ff } ); var 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 ) ); var geometry = new THREE.BufferGeometry().setFromPoints( points );
建立線條:
var line = new THREE.Line( geometry, material ); scene.add( line ); renderer.render( scene, camera );