diff --git a/README.md b/README.md index a3af1a0..ca0051b 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square)](https://opensource.org/licenses/MIT) [![Platform](https://img.shields.io/badge/.NET-8.0%20%7C%2010.0-512BD4?style=flat-square&logo=dotnet)](https://dotnet.microsoft.com/) -IOViewer is a fast, 100% managed .NET library and command line tool that generates standalone interactive 3D WebGL / HTML BIM & CAD model viewers from code, glTF/GLB, Wavefront OBJ, or JSON. Geometry read by sibling libraries ([RvtIO](https://github.com/IOExtend/RvtIO), [IfcIO](https://github.com/IOExtend/IfcIO), and [NwcIO](https://github.com/IOExtend/NwcIO)) can be passed in by building a `SceneDocument` in code, and the `ioviewer` command line tool reads IFC and Revit files directly through IfcIO and RvtIO. The scene model comes from the [IOScene](https://github.com/IOExtend/IOScene) package; the IOViewer library has no dependency on the format libraries. +IOViewer is a fast, 100% managed .NET library and command line tool that generates standalone interactive 3D WebGL / HTML BIM & CAD model viewers from code, glTF/GLB, Wavefront OBJ, or JSON. Builds of the `ioviewer` CLI from this repository also read IFC, Revit and Navisworks cache files (`.nwc`) through `IfcIO.Scene`, `RvtIO.Scene` and `NwcIO.Scene`. The IOViewer library accepts the `SceneDocument` these adapters produce and depends on [IOScene](https://github.com/IOExtend/IOScene) for the scene model. The generated HTML is a single file with no external dependencies that works offline: it opens from disk (`file://`) in a current browser with WebGL 2 and makes no network requests. The viewer is built on [three.js](https://threejs.org/), which is embedded in the file (see [THIRD-PARTY-NOTICES.md](THIRD-PARTY-NOTICES.md)). @@ -137,6 +137,22 @@ var doc = GlbViewerImporter.Load("complex_building.glb"); HtmlViewerExporter.Save(doc, "complex_building.html"); ``` +To view a Navisworks cache, install `NwcIO.Scene` with `dotnet add package NwcIO.Scene --version 0.13.0` and pass its scene to IOViewer. + +```csharp +using IOViewer.Exporters; +using NwcIO.Scene; + +var result = NwcSceneReader.Read("Tower.nwc"); +HtmlViewerExporter.Save(result.Document, "Tower.html"); +``` + +The adapter is in preview and can reject some NWC caches. Check `result.Diagnostics` for conversion warnings and errors. For supported inputs and limits, see the +[NwcIO.Scene guide](https://github.com/IOExtend/NwcIO/blob/v0.13.0/docs/scene.md). + +For `IOViewer.Cli` 0.3.1, save the same scene with `IOScene.SceneJson.Save(result.Document, "Tower.scene.json")` and run +`ioviewer Tower.scene.json`. See the [IOScene JSON handoff](docs/getting-started.md#navisworks-cache) for the full workflow. + See the [public API](docs/public-api.md) for the supported surface and [getting started guide](docs/getting-started.md) for detailed workflows. ## Documentation diff --git a/docs/getting-started.md b/docs/getting-started.md index 9ba1166..8efa642 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -33,6 +33,9 @@ ioviewer model.nwc ioviewer model.glb --serve ``` +The direct `.nwc` command is available in CLI builds from this repository. Published `IOViewer.Cli` 0.3.1 uses the +[IOScene JSON handoff](#navisworks-cache) for Navisworks models. + ## C# API usage The model data is a `SceneDocument` from the [IOScene](https://github.com/IOExtend/IOScene) package: models, elements, @@ -52,6 +55,38 @@ HtmlViewerExporter.Save(scene, "tower_viewer.html"); box and the keys of the models hidden at start. `JsonViewerExporter` writes it as viewer JSON, and `JsonViewerImporter` reads viewer JSON, IOScene scene files and IOViewer 0.1/0.2 snapshots. +## Navisworks cache + +Add `NwcIO.Scene` alongside `IOViewer` in your .NET project. + +```sh +dotnet add package NwcIO.Scene --version 0.13.0 +``` + +Read the `.nwc` file into an IOScene document and export it to HTML. + +```csharp +using IOViewer.Exporters; +using NwcIO.Scene; + +var result = NwcSceneReader.Read("Tower.nwc"); +HtmlViewerExporter.Save(result.Document, "Tower.html"); +``` + +Inspect `result.Diagnostics` for warnings and errors. See the [NwcIO.Scene guide](https://github.com/IOExtend/NwcIO/blob/v0.13.0/docs/scene.md) +for supported caches, diagnostics and conversion limits. + +The adapter is in preview. Some caches, including the IFC-derived office and terrain caches in the +[Safe Software Navisworks example](https://support.safe.com/hc/en-us/articles/37510812360717-Getting-Started-with-Navisworks), +fail to load with `NwcIO.Scene` 0.13.0. If you have the original IFC or Revit file, you can pass it directly to `ioviewer`. + +For the IOScene JSON handoff, save the scene with `IOScene.SceneJson.Save(result.Document, "Tower.scene.json")`. +Then open it with the CLI, including `IOViewer.Cli` 0.3.1. + +```sh +ioviewer Tower.scene.json -o Tower.html +``` + ## Sharing geometry between instances Repeated shapes, such as identical fittings or columns, are stored once in `SceneDocument.Geometries` and placed by diff --git a/docs/index.md b/docs/index.md index e763835..27a0b73 100644 --- a/docs/index.md +++ b/docs/index.md @@ -4,7 +4,7 @@ title: IOViewer # IOViewer -**IOViewer** is a fast, 100% managed .NET library and CLI tool for generating standalone interactive 3D WebGL / HTML BIM & CAD model viewers directly from code or file formats (glTF/GLB, Wavefront OBJ and JSON; the CLI tool also reads IFC and Revit files through IfcIO and RvtIO). +**IOViewer** is a fast, 100% managed .NET library and CLI tool for generating standalone interactive 3D WebGL / HTML BIM & CAD model viewers directly from code or from glTF/GLB, Wavefront OBJ and JSON. CLI builds from this repository also read IFC, Revit and Navisworks cache files (`.nwc`) through `IfcIO.Scene`, `RvtIO.Scene` and `NwcIO.Scene`. For the library and published CLI 0.3.1, see the [Navisworks workflow](getting-started.md#navisworks-cache). The generated HTML is a single file with no external dependencies that works offline: it opens from disk in a current browser with WebGL 2, without servers, plug-ins or network requests. The viewer is built on three.js, embedded in the file. diff --git a/src/IOViewer/Viewer/test/e2e/global-setup.js b/src/IOViewer/Viewer/test/e2e/global-setup.js index 7de873a..18bf5b5 100644 --- a/src/IOViewer/Viewer/test/e2e/global-setup.js +++ b/src/IOViewer/Viewer/test/e2e/global-setup.js @@ -73,6 +73,9 @@ export default function globalSetup() { exportHtml(widePath, 'wide-ids'); const building = JSON.parse(readFileSync(path.join(fixturesDir, 'building.json'), 'utf8')); + const noGrids = path.join(results, 'building-no-grids.json'); + writeFileSync(noGrids, JSON.stringify({ ...building, Scene: { ...building.Scene, Grids: [] } })); + exportHtml(noGrids, 'building-no-grids'); const planes = [{ Axis: 3, Normal: [0, 0, 2], Offset: 2 }, { Axis: 0, Offset: -100, Enabled: false }]; for (const [name, box] of [ ['building-section-planes', null], diff --git a/src/IOViewer/Viewer/test/e2e/sections.spec.js b/src/IOViewer/Viewer/test/e2e/sections.spec.js index b2fca5e..2f9ecf8 100644 --- a/src/IOViewer/Viewer/test/e2e/sections.spec.js +++ b/src/IOViewer/Viewer/test/e2e/sections.spec.js @@ -124,8 +124,8 @@ for (const inverted of [false, true]) { } test('a Z plane through the middle cuts the roof away; flipping it brings the roof back and cuts the ground slab; reset restores', async ({ page }) => { - const errors = await open(page); - await page.evaluate(() => window.__ioviewer.grids.setVisible(false)); // axis 2 runs across the sampled slab rim + // Axis 2 runs across the sampled slab rim. + const errors = await open(page, 'building-no-grids'); const roof = await indexOf(page, 'Roof Slab'); const ground = await indexOf(page, 'Ground Slab'); // Roof top near its back edge (seen past the roof there is only background) and the ground slab rim right of the @@ -147,23 +147,20 @@ test('a Z plane through the middle cuts the roof away; flipping it brings the ro expect(state).toMatchObject({ mode: 'planes', axis: 'z' }); expect(state.z).toBeCloseTo(state.mid, 9); await page.evaluate(() => window.__ioviewer.sections.setGizmoVisible(false)); // keep the handles off the sampled pixels - await frame(page); - expect(cleared(await rgb(page, roofAt), roofBefore)).toBe(true); + await expect.poll(async () => cleared(await rgb(page, roofAt), roofBefore)).toBe(true); expect(await pickAt(page, roofAt)).not.toBe(roof); expect(cleared(await rgb(page, groundAt), groundBefore)).toBe(false); expect(await pickAt(page, groundAt)).toBe(ground); await panel(page).getByRole('button', { name: 'Сменить сторону' }).click(); - await frame(page); - expect(await rgb(page, roofAt)).toEqual(roofBefore); // the roof is in front of the plane rectangle + await expect.poll(() => rgb(page, roofAt)).toEqual(roofBefore); // the roof is in front of the plane rectangle expect(await pickAt(page, roofAt)).toBe(roof); - expect(cleared(await rgb(page, groundAt), groundBefore)).toBe(true); + await expect.poll(async () => cleared(await rgb(page, groundAt), groundBefore)).toBe(true); expect(await pickAt(page, groundAt)).not.toBe(ground); await tool(page, 'resetSections').click(); - await frame(page); - expect(await rgb(page, roofAt)).toEqual(roofBefore); - expect(await rgb(page, groundAt)).toEqual(groundBefore); + await expect.poll(() => rgb(page, roofAt)).toEqual(roofBefore); + await expect.poll(() => rgb(page, groundAt)).toEqual(groundBefore); expect(await page.evaluate(() => [window.__ioviewer.sections.mode, window.__ioviewer.sections.planes.length])).toEqual(['off', 0]); await expect(tool(page, 'plane')).not.toHaveClass(/active/); expect(errors).toEqual([]); diff --git a/src/IOViewer/Viewer/test/e2e/ui.spec.js b/src/IOViewer/Viewer/test/e2e/ui.spec.js index 01fae0f..473dc9d 100644 --- a/src/IOViewer/Viewer/test/e2e/ui.spec.js +++ b/src/IOViewer/Viewer/test/e2e/ui.spec.js @@ -93,7 +93,9 @@ test('right click on nothing opens the short menu; Esc, an outside click and the // The same for a tree row under the press. await rail(page, 'model').click(); await sidePanel(page, 'model').locator('.ioviewer-tree').evaluate((t) => (t.scrollTop = 0)); // it scrolled to D3 - const ducts = await rows(page).filter({ hasText: 'Ducts' }).boundingBox(); + const ductsRow = rows(page).filter({ hasText: 'Ducts' }); + await expect(ductsRow).toBeVisible(); + const ducts = await ductsRow.boundingBox(); await page.mouse.click(1000, 40, { button: 'right' }); // background clear of the open panel and the view cube await expect(menu(page)).toBeVisible(); await page.mouse.click(ducts.x + 20, ducts.y + ducts.height / 2); // press on the Ducts category header