Drawing-lines.html 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <base href="../../../" />
  6. <script src="list.js"></script>
  7. <script src="page.js"></script>
  8. <link type="text/css" rel="stylesheet" href="page.css" />
  9. </head>
  10. <body>
  11. <h1>[name]</h1>
  12. <div>
  13. <p>
  14. Let's say you want to draw a line or a circle, not a wireframe [page:Mesh].
  15. First we need to set up the [page:WebGLRenderer renderer], [page:Scene scene] and camera (see the Creating a scene page).
  16. </p>
  17. <p>Here is the code that we will use:</p>
  18. <code>
  19. var renderer = new THREE.WebGLRenderer();
  20. renderer.setSize( window.innerWidth, window.innerHeight );
  21. document.body.appendChild( renderer.domElement );
  22. var camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 500 );
  23. camera.position.set( 0, 0, 100 );
  24. camera.lookAt( 0, 0, 0 );
  25. var scene = new THREE.Scene();
  26. </code>
  27. <p>Next thing we will do is define a material. For lines we have to use [page:LineBasicMaterial] or [page:LineDashedMaterial].</p>
  28. <code>
  29. //create a blue LineBasicMaterial
  30. var material = new THREE.LineBasicMaterial( { color: 0x0000ff } );
  31. </code>
  32. <p>
  33. After material we will need a geometry with some vertices:
  34. </p>
  35. <code>
  36. var points = [];
  37. points.push( new THREE.Vector3( - 10, 0, 0 ) );
  38. points.push( new THREE.Vector3( 0, 10, 0 ) );
  39. points.push( new THREE.Vector3( 10, 0, 0 ) );
  40. var geometry = new THREE.BufferGeometry().setFromPoints( points );
  41. </code>
  42. <p>Note that lines are drawn between each consecutive pair of vertices, but not between the first and last (the line is not closed.)</p>
  43. <p>Now that we have points for two lines and a material, we can put them together to form a line.</p>
  44. <code>
  45. var line = new THREE.Line( geometry, material );
  46. </code>
  47. <p>All that's left is to add it to the scene and call [page:WebGLRenderer.render render].</p>
  48. <code>
  49. scene.add( line );
  50. renderer.render( scene, camera );
  51. </code>
  52. <p>You should now be seeing an arrow pointing upwards, made from two blue lines.</p>
  53. </div>
  54. </body>
  55. </html>