webgl_loader_ifc.html 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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="info">
  14. <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a>
  15. -
  16. <a href="https://www.buildingsmart.org/standards/bsi-standards/industry-foundation-classes/" target="_blank" rel="noopener">IFC</a>
  17. loader
  18. </div>
  19. <script type="module">
  20. import * as THREE from '../build/three.module.js';
  21. import { OrbitControls } from './jsm/controls/OrbitControls.js';
  22. import { IFCLoader } from './jsm/loaders/IFCLoader.js';
  23. let scene, camera, renderer;
  24. init();
  25. function init() {
  26. //Scene
  27. scene = new THREE.Scene();
  28. scene.background = new THREE.Color( 0x8cc7de );
  29. //Camera
  30. camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 1000 );
  31. camera.position.z = - 70;
  32. camera.position.y = 25;
  33. camera.position.x = 90;
  34. //Initial cube
  35. const geometry = new THREE.BoxGeometry();
  36. const material = new THREE.MeshPhongMaterial( { color: 0xffffff } );
  37. const cube = new THREE.Mesh( geometry, material );
  38. scene.add( cube );
  39. //Lights
  40. const directionalLight1 = new THREE.DirectionalLight( 0xffeeff, 0.8 );
  41. directionalLight1.position.set( 1, 1, 1 );
  42. scene.add( directionalLight1 );
  43. const directionalLight2 = new THREE.DirectionalLight( 0xffffff, 0.8 );
  44. directionalLight2.position.set( - 1, 0.5, - 1 );
  45. scene.add( directionalLight2 );
  46. const ambientLight = new THREE.AmbientLight( 0xffffee, 0.25 );
  47. scene.add( ambientLight );
  48. //Setup IFC Loader
  49. const ifcLoader = new IFCLoader();
  50. ifcLoader.setWasmPath( 'jsm/loaders/ifc/' );
  51. ifcLoader.load( 'models/ifc/rac_advanced_sample_project.ifc', function ( model ) {
  52. scene.add( model );
  53. render();
  54. } );
  55. //Renderer
  56. renderer = new THREE.WebGLRenderer( { antialias: true } );
  57. renderer.setSize( window.innerWidth, window.innerHeight );
  58. renderer.setPixelRatio( window.devicePixelRatio );
  59. document.body.appendChild( renderer.domElement );
  60. //Controls
  61. const controls = new OrbitControls( camera, renderer.domElement );
  62. controls.addEventListener( 'change', render );
  63. window.addEventListener( 'resize', onWindowResize );
  64. render();
  65. }
  66. function onWindowResize() {
  67. camera.aspect = window.innerWidth / window.innerHeight;
  68. camera.updateProjectionMatrix();
  69. renderer.setSize( window.innerWidth, window.innerHeight );
  70. render();
  71. }
  72. function render() {
  73. renderer.render( scene, camera );
  74. }
  75. </script>
  76. </body>
  77. </html>