webgl_loader_xyz.html 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - loaders - XYZ</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <link type="text/css" rel="stylesheet" href="main.css">
  8. </head>
  9. <body>
  10. <div id="info">
  11. <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - XYZ loader<br/>
  12. asset from <a href="https://people.math.sc.edu/Burkardt/data/xyz/xyz.html" target="_blank" rel="noopener">people.math.sc.edu</a> via GNU LGPL
  13. </div>
  14. <script type="module">
  15. import * as THREE from '../build/three.module.js';
  16. import { XYZLoader } from './jsm/loaders/XYZLoader.js';
  17. let camera, scene, renderer, clock;
  18. let points;
  19. init();
  20. animate();
  21. function init() {
  22. camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 0.1, 100 );
  23. camera.position.set( 10, 7, 10 );
  24. scene = new THREE.Scene();
  25. scene.add( camera );
  26. camera.lookAt( scene.position );
  27. clock = new THREE.Clock();
  28. const loader = new XYZLoader();
  29. loader.load( 'models/xyz/helix_201.xyz', function ( geometry ) {
  30. geometry.center();
  31. const material = new THREE.PointsMaterial( { size: 0.1 } );
  32. points = new THREE.Points( geometry, material );
  33. scene.add( points );
  34. } );
  35. //
  36. renderer = new THREE.WebGLRenderer();
  37. renderer.setPixelRatio( window.devicePixelRatio );
  38. renderer.setSize( window.innerWidth, window.innerHeight );
  39. document.body.appendChild( renderer.domElement );
  40. //
  41. window.addEventListener( 'resize', onWindowResize, false );
  42. }
  43. function onWindowResize() {
  44. camera.aspect = window.innerWidth / window.innerHeight;
  45. camera.updateProjectionMatrix();
  46. renderer.setSize( window.innerWidth, window.innerHeight );
  47. }
  48. function animate() {
  49. requestAnimationFrame( animate );
  50. const delta = clock.getDelta();
  51. if ( points ) {
  52. points.rotation.x += delta * 0.2;
  53. points.rotation.y += delta * 0.5;
  54. }
  55. renderer.render( scene, camera );
  56. }
  57. </script>
  58. </body>
  59. </html>