@inweb/viewer-visualize
Version:
JavaScript library for rendering CAD and BIM files in a browser using VisualizeJS
109 lines (101 loc) • 4.37 kB
text/typescript
///////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2002-2025, Open Design Alliance (the "Alliance").
// All rights reserved.
//
// This software and its documentation and related materials are owned by
// the Alliance. The software may only be incorporated into application
// programs owned by members of the Alliance, subject to a signed
// Membership Agreement and Supplemental Software License Agreement with the
// Alliance. The structure and organization of this software are the valuable
// trade secrets of the Alliance and its suppliers. The software is also
// protected by copyright law and international treaty provisions. Application
// programs incorporating this software must include the following statement
// with their copyright notices:
//
// This application incorporates Open Design Alliance software pursuant to a
// license agreement with Open Design Alliance.
// Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance.
// All rights reserved.
//
// By use of this software, its documentation or related materials, you
// acknowledge and accept the above terms.
///////////////////////////////////////////////////////////////////////////////
import { ILoadersRegistry, loadersRegistry } from "@inweb/viewer-core";
import { VSFFileLoader } from "./VSFFileLoader";
import { VSFCloudLoader } from "./VSFCloudLoader";
import { VSFXFileLoader } from "./VSFXFileLoader";
import { VSFXCloudLoader } from "./VSFXCloudLoader";
import { VSFXCloudStreamingLoader } from "./VSFXCloudStreamingLoader";
import { VSFXCloudPartialLoader } from "./VSFXCloudPartialLoader";
/**
* Viewer loaders registry. Use this registry to register custom loaders.
*
* To implement custom loader:
*
* 1. Define a loader class implements {@link ILoader}.
* 2. Define a constructor with a `viewer` parameter.
* 3. Override {@link ILoader.isSupport} and сheck if the loader can load the specified file.
* 4. Override {@link ILoader.load} and define the logic for loading the model from the file.
*
* The loader should do:
*
* - Load model data from file into the buffer. The model data must be a `VSFX` format.
* - Parse data buffer with the `VisualizeJS` viewer instance.
* - Synchronize viewer styles, options and overlay.
* - Update the viewer.
*
* The loader must emit events:
*
* - `geometryprogress` - during loading. If progress is not supported, emit it once with a value of 100%
* after the load is complete.
* - `databasechunk` - when model is loaded and ready to render.
* 5. Override {@link ILoader.dispose} and release loader resources, if required.
* 6. Register loader provider in the loaders registry by calling the {@link loaders.registerLoader}.
*
* @example Implementing a custom loader.
*
* ```javascript
* import { Loader, loaders, Viewer } from "@inweb/viewer-visualize";
*
* class MyLoader extends Loader {
* public viewer: Viewer;
*
* constructor(viewer: Viewer) {
* super();
* this.viewer = viewer;
* }
*
* override isSupport(file, format): Boolean {
* // place custom logic here
* return ...;
* }
*
* override load(file, format, params): Promise<this> {
*
* // place custom loading logic here
* const data = ...
*
* this.viewer.visualizeJs.getViewer().parseVsfx(data);
*
* this.viewer.syncOpenCloudVisualStyle(false);
* this.viewer.syncOptions();
* this.viewer.syncOverlay();
* this.viewer.resize();
*
* this.viewer.emitEvent({ type: "databasechunk", data, file });
*
* return Promise.resove(this);
* };
* }
*
* loaders.registerLoader("MyLoader", (viewer) => new MyLoader(viewer));
* ```
*/
export const loaders: ILoadersRegistry = loadersRegistry("visualizejs");
// build-in loaders
loaders.registerLoader("vsf-file", (viewer: any) => new VSFFileLoader(viewer));
loaders.registerLoader("vsf-cloud", (viewer: any) => new VSFCloudLoader(viewer));
loaders.registerLoader("vsfx-file", (viewer: any) => new VSFXFileLoader(viewer));
loaders.registerLoader("vsfx-cloud", (viewer: any) => new VSFXCloudLoader(viewer));
loaders.registerLoader("vsfx-cloud-streaming", (viewer: any) => new VSFXCloudStreamingLoader(viewer));
loaders.registerLoader("vsfx-cloud-partial", (viewer: any) => new VSFXCloudPartialLoader(viewer));