webgl_loader_ifc.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - IFCLoader</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. See <a href="https://github.com/ifcjs/" target="_blank" rel="noopener">main project repository</a> for more information and BIM tools.
  17. </div>
  18. <!-- Import maps polyfill -->
  19. <!-- Remove this when import maps will be widely supported -->
  20. <script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
  21. <script type="importmap">
  22. {
  23. "imports": {
  24. "three": "../build/three.module.js",
  25. "three/addons/": "./jsm/",
  26. "three/examples/jsm/utils/BufferGeometryUtils": "./jsm/utils/BufferGeometryUtils.js",
  27. "three-mesh-bvh": "https://unpkg.com/[email protected]/build/index.module.js",
  28. "web-ifc": "https://unpkg.com/[email protected]/web-ifc-api.js",
  29. "web-ifc-three": "https://unpkg.com/[email protected]/IFCLoader.js"
  30. }
  31. }
  32. </script>
  33. <script type="module">
  34. import * as THREE from 'three';
  35. import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
  36. import { IFCLoader } from 'web-ifc-three';
  37. import { IFCSPACE } from 'web-ifc';
  38. let scene, camera, renderer;
  39. async function init() {
  40. //Scene
  41. scene = new THREE.Scene();
  42. scene.background = new THREE.Color( 0x8cc7de );
  43. //Camera
  44. camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 1000 );
  45. camera.position.z = - 70;
  46. camera.position.y = 25;
  47. camera.position.x = 90;
  48. //Initial cube
  49. const geometry = new THREE.BoxGeometry();
  50. const material = new THREE.MeshPhongMaterial( { color: 0xffffff } );
  51. const cube = new THREE.Mesh( geometry, material );
  52. scene.add( cube );
  53. //Lights
  54. const directionalLight1 = new THREE.DirectionalLight( 0xffeeff, 2.5 );
  55. directionalLight1.position.set( 1, 1, 1 );
  56. scene.add( directionalLight1 );
  57. const directionalLight2 = new THREE.DirectionalLight( 0xffffff, 2.5 );
  58. directionalLight2.position.set( - 1, 0.5, - 1 );
  59. scene.add( directionalLight2 );
  60. const ambientLight = new THREE.AmbientLight( 0xffffee, 0.75 );
  61. scene.add( ambientLight );
  62. //Setup IFC Loader
  63. const ifcLoader = new IFCLoader();
  64. await ifcLoader.ifcManager.setWasmPath( 'https://unpkg.com/[email protected]/', true );
  65. await ifcLoader.ifcManager.parser.setupOptionalCategories( {
  66. [ IFCSPACE ]: false,
  67. } );
  68. await ifcLoader.ifcManager.applyWebIfcConfig( {
  69. USE_FAST_BOOLS: true
  70. } );
  71. ifcLoader.load( 'models/ifc/rac_advanced_sample_project.ifc', function ( model ) {
  72. scene.add( model.mesh );
  73. render();
  74. } );
  75. //Renderer
  76. renderer = new THREE.WebGLRenderer( { antialias: true } );
  77. renderer.setSize( window.innerWidth, window.innerHeight );
  78. renderer.setPixelRatio( window.devicePixelRatio );
  79. renderer.useLegacyLights = false;
  80. document.body.appendChild( renderer.domElement );
  81. //Controls
  82. const controls = new OrbitControls( camera, renderer.domElement );
  83. controls.addEventListener( 'change', render );
  84. window.addEventListener( 'resize', onWindowResize );
  85. render();
  86. }
  87. function onWindowResize() {
  88. camera.aspect = window.innerWidth / window.innerHeight;
  89. camera.updateProjectionMatrix();
  90. renderer.setSize( window.innerWidth, window.innerHeight );
  91. render();
  92. }
  93. function render() {
  94. renderer.render( scene, camera );
  95. }
  96. init();
  97. </script>
  98. </body>
  99. </html>