pntsExample.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import { PNTSLoader } from '../src/index.js';
  2. import {
  3. Scene,
  4. DirectionalLight,
  5. AmbientLight,
  6. WebGLRenderer,
  7. PerspectiveCamera,
  8. Box3,
  9. sRGBEncoding,
  10. PCFSoftShadowMap,
  11. } from 'three';
  12. import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
  13. let camera, controls, scene, renderer;
  14. let box, dirLight;
  15. init();
  16. animate();
  17. function init() {
  18. scene = new Scene();
  19. // primary camera view
  20. renderer = new WebGLRenderer( { antialias: true } );
  21. renderer.setPixelRatio( window.devicePixelRatio );
  22. renderer.setSize( window.innerWidth, window.innerHeight );
  23. renderer.setClearColor( 0x151c1f );
  24. renderer.shadowMap.enabled = true;
  25. renderer.shadowMap.type = PCFSoftShadowMap;
  26. renderer.outputEncoding = sRGBEncoding;
  27. document.body.appendChild( renderer.domElement );
  28. camera = new PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 4000 );
  29. camera.position.set( 2, 2, 2 );
  30. // controls
  31. controls = new OrbitControls( camera, renderer.domElement );
  32. controls.screenSpacePanning = false;
  33. controls.minDistance = 1;
  34. controls.maxDistance = 2000;
  35. // lights
  36. dirLight = new DirectionalLight( 0xffffff, 1.25 );
  37. dirLight.position.set( 1, 2, 3 ).multiplyScalar( 40 );
  38. dirLight.castShadow = true;
  39. dirLight.shadow.bias = - 0.01;
  40. dirLight.shadow.mapSize.setScalar( 2048 );
  41. const shadowCam = dirLight.shadow.camera;
  42. shadowCam.left = - 200;
  43. shadowCam.bottom = - 200;
  44. shadowCam.right = 200;
  45. shadowCam.top = 200;
  46. shadowCam.updateProjectionMatrix();
  47. scene.add( dirLight );
  48. const ambLight = new AmbientLight( 0xffffff, 0.05 );
  49. scene.add( ambLight );
  50. box = new Box3();
  51. new PNTSLoader()
  52. .load( 'https://raw.githubusercontent.com/CesiumGS/3d-tiles-samples/master/tilesets/TilesetWithRequestVolume/points.pnts' )
  53. .then( res => {
  54. console.log( res );
  55. scene.add( res.scene );
  56. } );
  57. onWindowResize();
  58. window.addEventListener( 'resize', onWindowResize, false );
  59. }
  60. function onWindowResize() {
  61. camera.aspect = window.innerWidth / window.innerHeight;
  62. renderer.setPixelRatio( window.devicePixelRatio );
  63. renderer.setSize( window.innerWidth, window.innerHeight );
  64. camera.updateProjectionMatrix();
  65. }
  66. function animate() {
  67. requestAnimationFrame( animate );
  68. render();
  69. }
  70. function render() {
  71. renderer.render( scene, camera );
  72. }