fundamentals.html 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <!-- Licensed under a BSD license. See license.html for license -->
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
  7. <title>Three.js - Fundamentals</title>
  8. </head>
  9. <body>
  10. <canvas id="c"></canvas>
  11. </body>
  12. <script type="importmap">
  13. {
  14. "imports": {
  15. "three": "../../build/three.module.js"
  16. }
  17. }
  18. </script>
  19. <script type="module">
  20. import * as THREE from 'three';
  21. function main() {
  22. const canvas = document.querySelector( '#c' );
  23. const renderer = new THREE.WebGLRenderer( { antialias: true, canvas } );
  24. const fov = 75;
  25. const aspect = 2; // the canvas default
  26. const near = 0.1;
  27. const far = 5;
  28. const camera = new THREE.PerspectiveCamera( fov, aspect, near, far );
  29. camera.position.z = 2;
  30. const scene = new THREE.Scene();
  31. const boxWidth = 1;
  32. const boxHeight = 1;
  33. const boxDepth = 1;
  34. const geometry = new THREE.BoxGeometry( boxWidth, boxHeight, boxDepth );
  35. const material = new THREE.MeshBasicMaterial( { color: 0x44aa88 } ); // greenish blue
  36. const cube = new THREE.Mesh( geometry, material );
  37. scene.add( cube );
  38. renderer.render( scene, camera );
  39. }
  40. main();
  41. </script>
  42. </html>