Skip to content

Commit

Permalink
feat(IFCImporter): add vtkIFCImporter
Browse files Browse the repository at this point in the history
This PR adds support for IFC format, the importer allows to merge
geometries to reduce the number of actors in the scene.

fixes #3156
  • Loading branch information
daker committed Nov 8, 2024
1 parent c962c49 commit c1cef05
Show file tree
Hide file tree
Showing 4 changed files with 547 additions and 0 deletions.
49 changes: 49 additions & 0 deletions Sources/IO/Geometry/IFCImporter/example/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import '@kitware/vtk.js/favicon';

// Load the rendering pieces we want to use (for both WebGL and WebGPU)
import '@kitware/vtk.js/Rendering/Profiles/Geometry';

import vtkFullScreenRenderWindow from '@kitware/vtk.js/Rendering/Misc/FullScreenRenderWindow';
import vtkResourceLoader from '@kitware/vtk.js/IO/Core/ResourceLoader';
import vtkIFCImporter from '@kitware/vtk.js/IO/Geometry/IFCImporter';

// ----------------------------------------------------------------------------
// Example code
// ----------------------------------------------------------------------------

const importer = vtkIFCImporter.newInstance({
mergeGeometries: true,
});

// ----------------------------------------------------------------------------
function update() {
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance();
const renderer = fullScreenRenderer.getRenderer();
const renderWindow = fullScreenRenderer.getRenderWindow();

const resetCamera = renderer.resetCamera;
const render = renderWindow.render;

importer.onReady(() => {
importer.importActors(renderer);
resetCamera();
render();
});
}

// ----------------------------------------------------------------------------
// Importer usage example
// ----------------------------------------------------------------------------
vtkResourceLoader
.loadScript('https://cdn.jsdelivr.net/npm/web-ifc@latest/web-ifc-api-iife.js')
.then(() => {
// Pass WebIFC api to vtkIFCImporter
vtkIFCImporter.setIFCAPI(window.WebIFC);

// Trigger data download
importer
.setUrl(
'https://raw.githubusercontent.com/ThatOpen/engine_web-ifc/refs/heads/main/tests/ifcfiles/public/duplex.ifc'
)
.then(update);
});
163 changes: 163 additions & 0 deletions Sources/IO/Geometry/IFCImporter/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import { vtkAlgorithm, vtkObject } from '../../../interfaces';
import vtkRenderer from '../../../Rendering/Core/Renderer';
import HtmlDataAccessHelper from '../../Core/DataAccessHelper/HtmlDataAccessHelper';
import HttpDataAccessHelper from '../../Core/DataAccessHelper/HttpDataAccessHelper';
import JSZipDataAccessHelper from '../../Core/DataAccessHelper/JSZipDataAccessHelper';
import LiteHttpDataAccessHelper from '../../Core/DataAccessHelper/LiteHttpDataAccessHelper';

interface IIFCImporterOptions {
compression?: string;
progressCallback?: any;
}

/**
*
*/
export interface IIFCImporterInitialValues {
mergeGeometries?: boolean;
}

type vtkIFCImporterBase = vtkObject &
Omit<
vtkAlgorithm,
| 'getInputData'
| 'setInputData'
| 'setInputConnection'
| 'getInputConnection'
| 'addInputConnection'
| 'addInputData'
>;

export interface vtkIFCImporter extends vtkIFCImporterBase {
/**
*
*/
getBaseURL(): string;

/**
*
*/
getDataAccessHelper():
| HtmlDataAccessHelper
| HttpDataAccessHelper
| JSZipDataAccessHelper
| LiteHttpDataAccessHelper;

/**
* Get the url of the object to load.
*/
getUrl(): string;

/**
* Import actors into the renderer.
* @param {vtkRenderer} renderer The vtkRenderer to import the actors into.
*/
importActors(renderer: vtkRenderer): void;

/**
* Load the object data.
* @param {IIFCImporterOptions} [options]
*/
loadData(options?: IIFCImporterOptions): Promise<any>;

/**
* Parse data.
* @param {String | ArrayBuffer} content The content to parse.
*/
parse(content: string | ArrayBuffer): void;

/**
* Parse data as ArrayBuffer.
* @param {ArrayBuffer} content The content to parse.
*/
parseAsArrayBuffer(content: ArrayBuffer): void;

/**
*
* @param inData
* @param outData
*/
requestData(inData: any, outData: any): void;

/**
*
* @param dataAccessHelper
*/
setDataAccessHelper(
dataAccessHelper:
| HtmlDataAccessHelper
| HttpDataAccessHelper
| JSZipDataAccessHelper
| LiteHttpDataAccessHelper
): boolean;

/**
* Set the url of the object to load.
* @param {String} url the url of the object to load.
* @param {IIFCImporterOptions} [option] The PLY reader options.
*/
setUrl(url: string, option?: IIFCImporterOptions): Promise<string | any>;
}

/**
* Set WebIFC api to be used by vtkIFCImporter
* @param {object} ifcApi
*/
export function setIFCAPI(ifcApi: any): void;

/**
* Method used to decorate a given object (publicAPI+model) with vtkIFCImporter characteristics.
*
* @param publicAPI object on which methods will be bounds (public)
* @param model object on which data structure will be bounds (protected)
* @param {IIFCImporterInitialValues} [initialValues] (default: {})
*/
export function extend(
publicAPI: object,
model: object,
initialValues?: IIFCImporterInitialValues
): void;

/**
* Method used to create a new instance of vtkIFCImporter
* @param {IIFCImporterInitialValues} [initialValues] for pre-setting some of its content
*/
export function newInstance(
initialValues?: IIFCImporterInitialValues
): vtkIFCImporter;

/**
* vtkIFCImporter is a source object that reads Industry Foundation Class(IFC) files.
*
* The vtkIFCImporter is using web-ifc library to parse the IFC file.
*
* @example
* ```js
* import vtkResourceLoader from '@kitware/vtk.js/IO/Core/ResourceLoader';
* import vtkIFCImporter from '@kitware/vtk.js/IO/Geometry/IFCImporter';
*
* function update() {
* importer.onReady(() => {
* importer.importActors(renderer);
* renderer.resetCamera();
* renderWindow.render();
* });
* }
*
* vtkResourceLoader
* .loadScript('https://cdn.jsdelivr.net/npm/[email protected]/web-ifc-api-iife.js')
* .then(() => {
* // Pass WebIFC api to vtkIFCImporter
* vtkIFCImporter.setIFCAPI(window.WebIFC);
*
* // Trigger data download
* importer.setUrl(`${__BASE_PATH__}/data/ifc/house.ifc`).then(update);
* });
* ```
*/
export declare const vtkIFCImporter: {
newInstance: typeof newInstance;
extend: typeof extend;
setIFCAPI: typeof setIFCAPI;
};
export default vtkIFCImporter;
Loading

0 comments on commit c1cef05

Please sign in to comment.