webgl_loader_ifc.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - loaders - IFC loader</title>
  5. <meta charset="utf-8" />
  6. <meta
  7. name="viewport"
  8. content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"
  9. />
  10. <link type="text/css" rel="stylesheet" href="main.css" />
  11. </head>
  12. <body>
  13. <div id="container"></div>
  14. <div id="info">
  15. <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a>
  16. -
  17. <a href="https://www.buildingsmart.org/standards/bsi-standards/industry-foundation-classes/" target="_blank" rel="noopener">IFC</a>
  18. loader
  19. </div>
  20. <script type="module">
  21. import * as THREE from '../build/three.module.js';
  22. import { OrbitControls } from './jsm/controls/OrbitControls.js';
  23. import { IFCLoader } from './jsm/loaders/IFCLoader.js';
  24. //Scene
  25. const scene = new THREE.Scene();
  26. scene.background = new THREE.Color( 0x8cc7de );
  27. //Renderer
  28. const container = document.querySelector( '#container' );
  29. const renderer = new THREE.WebGLRenderer( { antialias: true } );
  30. renderer.setSize( window.innerWidth, window.innerHeight );
  31. renderer.setPixelRatio( Math.min( window.devicePixelRatio, 2 ) );
  32. renderer.setAnimationLoop( animation );
  33. container.appendChild( renderer.domElement );
  34. //Camera
  35. const camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 1000 );
  36. camera.position.z = - 70;
  37. camera.position.y = 25;
  38. camera.position.x = 90;
  39. camera.lookAt( 0, 0, 0 );
  40. const controls = new OrbitControls( camera, renderer.domElement );
  41. //Initial cube
  42. const geometry = new THREE.BoxGeometry();
  43. const material = new THREE.MeshPhongMaterial( { color: 0xffffff } );
  44. const cube = new THREE.Mesh( geometry, material );
  45. scene.add( cube );
  46. //Lights
  47. const directionalLight1 = new THREE.DirectionalLight( 0xffeeff, 0.8 );
  48. directionalLight1.position.set( 1, 1, 1 );
  49. scene.add( directionalLight1 );
  50. const directionalLight2 = new THREE.DirectionalLight( 0xffffff, 0.8 );
  51. directionalLight2.position.set( - 1, 0.5, - 1 );
  52. scene.add( directionalLight2 );
  53. const ambientLight = new THREE.AmbientLight( 0xffffee, 0.25 );
  54. scene.add( ambientLight );
  55. //Window resize support
  56. window.addEventListener( 'resize', () => {
  57. camera.aspect = window.innerWidth / window.innerHeight;
  58. camera.updateProjectionMatrix();
  59. renderer.setSize( window.innerWidth, window.innerHeight );
  60. } );
  61. //Setup IFC Loader
  62. const ifcLoader = new IFCLoader();
  63. //Load IFC file
  64. ifcLoader.load( 'models/ifc/rac_advanced_sample_project.ifc', ( geometry ) => scene.add( geometry ) );
  65. //Animation
  66. function animation() {
  67. controls.update();
  68. renderer.render( scene, camera );
  69. }
  70. </script>
  71. </body>
  72. </html>