webgl_loader_ifc.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. THREE.ColorManagement.enabled = false; // TODO: Confirm correct color management.
  39. let scene, camera, renderer;
  40. async function init() {
  41. //Scene
  42. scene = new THREE.Scene();
  43. scene.background = new THREE.Color( 0x8cc7de );
  44. //Camera
  45. camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 1000 );
  46. camera.position.z = - 70;
  47. camera.position.y = 25;
  48. camera.position.x = 90;
  49. //Initial cube
  50. const geometry = new THREE.BoxGeometry();
  51. const material = new THREE.MeshPhongMaterial( { color: 0xffffff } );
  52. const cube = new THREE.Mesh( geometry, material );
  53. scene.add( cube );
  54. //Lights
  55. const directionalLight1 = new THREE.DirectionalLight( 0xffeeff, 0.8 );
  56. directionalLight1.position.set( 1, 1, 1 );
  57. scene.add( directionalLight1 );
  58. const directionalLight2 = new THREE.DirectionalLight( 0xffffff, 0.8 );
  59. directionalLight2.position.set( - 1, 0.5, - 1 );
  60. scene.add( directionalLight2 );
  61. const ambientLight = new THREE.AmbientLight( 0xffffee, 0.25 );
  62. scene.add( ambientLight );
  63. //Setup IFC Loader
  64. const ifcLoader = new IFCLoader();
  65. await ifcLoader.ifcManager.setWasmPath( 'https://unpkg.com/[email protected]/', true );
  66. await ifcLoader.ifcManager.parser.setupOptionalCategories( {
  67. [ IFCSPACE ]: false,
  68. } );
  69. await ifcLoader.ifcManager.applyWebIfcConfig( {
  70. USE_FAST_BOOLS: true
  71. } );
  72. ifcLoader.load( 'models/ifc/rac_advanced_sample_project.ifc', function ( model ) {
  73. scene.add( model.mesh );
  74. render();
  75. } );
  76. //Renderer
  77. renderer = new THREE.WebGLRenderer( { antialias: true } );
  78. renderer.setSize( window.innerWidth, window.innerHeight );
  79. renderer.setPixelRatio( window.devicePixelRatio );
  80. renderer.outputColorSpace = THREE.LinearSRGBColorSpace;
  81. document.body.appendChild( renderer.domElement );
  82. //Controls
  83. const controls = new OrbitControls( camera, renderer.domElement );
  84. controls.addEventListener( 'change', render );
  85. window.addEventListener( 'resize', onWindowResize );
  86. render();
  87. }
  88. function onWindowResize() {
  89. camera.aspect = window.innerWidth / window.innerHeight;
  90. camera.updateProjectionMatrix();
  91. renderer.setSize( window.innerWidth, window.innerHeight );
  92. render();
  93. }
  94. function render() {
  95. renderer.render( scene, camera );
  96. }
  97. init();
  98. </script>
  99. </body>
  100. </html>