From b11af94a607a3defcf08354c50d58d4945c53c8c Mon Sep 17 00:00:00 2001
From: mahach666 <79989386+mahach666@users.noreply.github.com>
Date: Wed, 18 Nov 2026 04:35:04 +0300
Subject: [PATCH] Open Navisworks caches through NwcIO.Scene in ioviewer
---
CHANGELOG.md | 4 ++
Directory.Packages.props | 1 +
README.md | 5 +-
docs/getting-started.md | 7 ++-
src/IOViewer.Cli/IOViewer.Cli.csproj | 1 +
src/IOViewer.Cli/Program.cs | 23 +++++---
tests/IOViewer.Tests/CliTests.cs | 2 +-
.../ModelAndCliIntegrationTests.cs | 55 +++++++++++++++++++
8 files changed, 85 insertions(+), 13 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3f1f78b..d36ea5f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,10 @@ API between minor releases.
## [Unreleased]
+### Added
+
+- `ioviewer` reads Navisworks `.nwc` caches through `NwcIO.Scene` 0.13.0.
+
## [0.3.1] - 2026-11-13
### Fixed
diff --git a/Directory.Packages.props b/Directory.Packages.props
index dd99b26..72938e3 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -7,6 +7,7 @@
(nuget.org refuses the shorter bound -0 in a dependency). -->
+
diff --git a/README.md b/README.md
index b775a9f..8e479db 100644
--- a/README.md
+++ b/README.md
@@ -80,9 +80,10 @@ ioviewer model.glb -o viewer.html
# Convert Wavefront OBJ model to interactive HTML viewer
ioviewer model.obj -o viewer.html
-# Convert an IFC model (.ifc or .ifczip, read with IfcIO) or a Revit model (.rvt, read with RvtIO)
+# Convert IFC, Revit or Navisworks models via the scene adapters
ioviewer model.ifc
ioviewer model.rvt -o viewer.html
+ioviewer model.nwc -o viewer.html
# Convert and immediately preview in default web browser via built-in HTTP server
ioviewer model.glb --serve
@@ -95,7 +96,7 @@ Export structured JSON snapshots:
ioviewer model.glb -o model.json
```
-Diagnostics and progress go to standard error, including what IfcIO or RvtIO could not convert (one warning or error
+Diagnostics and progress go to standard error, including conversion diagnostics from the scene adapters (one warning or error
per kind, with its count). When the engine reported an error, elements may be missing: the output is still written and
the exit code is 4. An output that cannot be written gives exit code 3, and a `--serve` preview server that cannot start
or fails gives exit code 5 after the output is written; codes 3 and 5 take precedence over 4. Run `ioviewer --help` for
diff --git a/docs/getting-started.md b/docs/getting-started.md
index 9b1cd77..9ba1166 100644
--- a/docs/getting-started.md
+++ b/docs/getting-started.md
@@ -16,17 +16,18 @@ dotnet add package IOViewer
## Command line usage
-Convert any glTF 2.0 Binary (`.glb`), Wavefront OBJ (`.obj`), IFC (`.ifc`, `.ifczip`, read with IfcIO) or Revit
-(`.rvt`, read with RvtIO) model into a self-contained 3D HTML viewer:
+Convert a glTF 2.0 Binary (`.glb`), Wavefront OBJ (`.obj`), IFC (`.ifc`, `.ifczip`), Revit (`.rvt`) or
+Navisworks cache (`.nwc`) into a self-contained 3D HTML viewer:
```sh
# Convert 3D model into an interactive standalone HTML viewer
ioviewer model.glb -o viewer.html
-# IFC and Revit models; what the engine could not convert is printed as warnings or errors on standard error,
+# IFC, Revit and Navisworks models; conversion diagnostics are printed on standard error,
# and an error (elements may be missing) gives exit code 4 after the output is written
ioviewer model.ifc
ioviewer model.rvt
+ioviewer model.nwc
# Launch local preview server and open in default browser
ioviewer model.glb --serve
diff --git a/src/IOViewer.Cli/IOViewer.Cli.csproj b/src/IOViewer.Cli/IOViewer.Cli.csproj
index 682f220..60e4ea4 100644
--- a/src/IOViewer.Cli/IOViewer.Cli.csproj
+++ b/src/IOViewer.Cli/IOViewer.Cli.csproj
@@ -17,6 +17,7 @@
+
diff --git a/src/IOViewer.Cli/Program.cs b/src/IOViewer.Cli/Program.cs
index 01b7906..ce6cae4 100644
--- a/src/IOViewer.Cli/Program.cs
+++ b/src/IOViewer.Cli/Program.cs
@@ -8,6 +8,7 @@
using IOViewer.Exporters;
using IOViewer.Importers;
using IOViewer.Model;
+using NwcIO.Scene;
using RvtIO.Scene;
namespace IOViewer.Cli;
@@ -15,18 +16,18 @@ namespace IOViewer.Cli;
internal static class Program
{
private const string UsageText = """
- Usage: ioviewer [output.html] [options]
+ Usage: ioviewer [output.html] [options]
ioviewer --help | --version
Generates standalone interactive 3D WebGL / HTML BIM & CAD model viewers
- from 3D models (glTF/GLB, Wavefront OBJ, JSON, IFC, Revit). The HTML file
+ from 3D models (glTF/GLB, Wavefront OBJ, JSON, IFC, Revit, Navisworks). The HTML file
has no external dependencies and works offline. JSON input is viewer JSON,
an IOScene scene file or an IOViewer 0.1/0.2 snapshot. IFC (.ifc, .ifczip)
- is read with IfcIO and Revit (.rvt) with RvtIO; what they could not convert
- is reported as warnings or errors.
+ is read with IfcIO, Revit (.rvt) with RvtIO and Navisworks caches (.nwc)
+ with NwcIO. Conversion diagnostics are reported as warnings or errors.
Arguments:
- Path to input 3D model (.glb, .obj, .json, .ifc, .ifczip or .rvt).
+ Path to input 3D model (.glb, .obj, .json, .ifc, .ifczip, .rvt or .nwc).
[output] Destination path for exported file (.html or .json).
Default: .html.
@@ -48,7 +49,7 @@ 0 Success
1 Usage error (missing or invalid arguments)
2 File not found
3 Data format error, parsing failure, or an output that cannot be written
- 4 Output written, but IfcIO or RvtIO reported an error: elements may be missing
+ 4 Output written, but the engine adapter reported an error: elements may be missing
5 Output written, but the --serve preview server could not start or failed
Codes 3 and 5 take precedence over 4.
""";
@@ -180,7 +181,8 @@ public static int Main(string[] args)
".json" => JsonViewerImporter.Load(inputPath),
".ifc" or ".ifczip" => FromIfc(inputPath, out diagnostics),
".rvt" => FromRvt(inputPath, out diagnostics),
- _ => throw new NotSupportedException($"Unsupported input file extension: '{ext}'. Supported: .glb, .obj, .json, .ifc, .ifczip, .rvt.")
+ ".nwc" => FromNwc(inputPath, out diagnostics),
+ _ => throw new NotSupportedException($"Unsupported input file extension: '{ext}'. Supported: .glb, .obj, .json, .ifc, .ifczip, .rvt, .nwc.")
};
}
catch (Exception ex)
@@ -263,6 +265,13 @@ private static ViewerDocument FromRvt(string path, out IReadOnlyList diagnostics)
+ {
+ var result = NwcSceneReader.Read(path);
+ diagnostics = result.Diagnostics;
+ return FromScene(path, result.Document, diagnostics);
+ }
+
// An error of the engine adapter means elements may be missing: the output is still written, and the exit code says so.
internal static int ExitCode(IReadOnlyList diagnostics) =>
diagnostics.Any(d => d.Severity == SceneSeverity.Error) ? 4 : 0;
diff --git a/tests/IOViewer.Tests/CliTests.cs b/tests/IOViewer.Tests/CliTests.cs
index 198b680..c36376b 100644
--- a/tests/IOViewer.Tests/CliTests.cs
+++ b/tests/IOViewer.Tests/CliTests.cs
@@ -21,7 +21,7 @@ public void Cli_Help_ReturnsSuccessAndShowsUsage()
int code = Program.Main(HelpArgs);
Assert.Equal(0, code);
string output = sw.ToString();
- Assert.Contains("ioviewer ", output);
+ Assert.Contains("ioviewer ", output);
Assert.Contains("--wireframe", output);
Assert.Contains("--white-mode", output);
Assert.Contains("--serve", output);
diff --git a/tests/IOViewer.Tests/ModelAndCliIntegrationTests.cs b/tests/IOViewer.Tests/ModelAndCliIntegrationTests.cs
index ff4b193..2484b75 100644
--- a/tests/IOViewer.Tests/ModelAndCliIntegrationTests.cs
+++ b/tests/IOViewer.Tests/ModelAndCliIntegrationTests.cs
@@ -3,6 +3,8 @@
using IOViewer.Exporters;
using IOViewer.Importers;
using IOViewer.Model;
+using NwcIO;
+using NwcIO.Model;
using RvtIO.Scene;
using Xunit;
@@ -407,6 +409,59 @@ public void Cli_ConvertIfcToHtml_ReadsTheModelThroughIfcIO()
}
}
+ [Fact]
+ public void Cli_ConvertNwcToHtml_ReadsTheModelThroughNwcIO()
+ {
+ string input = Path.Combine(Path.GetTempPath(), $"test_model_{Guid.NewGuid():N}.nwc");
+ string html = Path.ChangeExtension(input, ".html");
+ string json = Path.ChangeExtension(input, ".json");
+ try
+ {
+ var root = new NwcNode { Id = 0, Name = "Model", Class = "Model" };
+ root.Children.Add(new NwcNode { Id = 1, Name = "Test layer", Class = "LcRevitLayer", Tag = 52, Parent = root });
+ NwcDocument.Create(
+ new NwcFileInfo { LoaderPlugin = "LcNwcLoaderPlugin:lcldrevit" }, rootNode: root).Save(input);
+
+ Assert.Equal(0, Program.Main([input, "--json", json]));
+ var scene = JsonViewerImporter.Load(json).Scene;
+ Assert.Empty(scene.Validate());
+ Assert.Equal(Path.GetFileName(input), Assert.Single(scene.Models).Key);
+ Assert.Contains(scene.Elements, element => element.Name == "Test layer");
+ Assert.True(File.Exists(html));
+ }
+ finally
+ {
+ File.Delete(input);
+ File.Delete(html);
+ File.Delete(json);
+ }
+ }
+
+ [Fact]
+ public void Cli_MalformedNwc_ReportsLoadFailureWithoutWritingHtml()
+ {
+ string input = Path.Combine(Path.GetTempPath(), $"test_model_{Guid.NewGuid():N}.nwc");
+ string html = Path.ChangeExtension(input, ".html");
+ using var errors = new StringWriter();
+ var originalError = Console.Error;
+ try
+ {
+ File.WriteAllText(input, "invalid Navisworks input");
+ Console.SetError(errors);
+
+ Assert.Equal(3, Program.Main([input]));
+ Assert.Contains("Error: Failed to load", errors.ToString());
+ Assert.DoesNotContain("Unsupported input file extension", errors.ToString());
+ Assert.False(File.Exists(html));
+ }
+ finally
+ {
+ Console.SetError(originalError);
+ File.Delete(input);
+ File.Delete(html);
+ }
+ }
+
[Fact]
public void Cli_AdapterDiagnostics_AreReportedOncePerSeverityAndKind()
{