Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
(nuget.org refuses the shorter bound -0 in a dependency). -->
<PackageVersion Include="IOScene" Version="[0.1.0, 0.2.0-0.0)" />
<PackageVersion Include="IfcIO.Scene" Version="0.11.1" />
<PackageVersion Include="NwcIO.Scene" Version="0.13.0" />
<PackageVersion Include="RvtIO.Scene" Version="0.4.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.12.0" />
<PackageVersion Include="xunit" Version="2.9.3" />
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/IOViewer.Cli/IOViewer.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<ItemGroup>
<ProjectReference Include="..\IOViewer\IOViewer.csproj" />
<PackageReference Include="IfcIO.Scene" />
<PackageReference Include="NwcIO.Scene" />
<PackageReference Include="RvtIO.Scene" />
</ItemGroup>

Expand Down
23 changes: 16 additions & 7 deletions src/IOViewer.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,26 @@
using IOViewer.Exporters;
using IOViewer.Importers;
using IOViewer.Model;
using NwcIO.Scene;
using RvtIO.Scene;

namespace IOViewer.Cli;

internal static class Program
{
private const string UsageText = """
Usage: ioviewer <input.glb|input.obj|input.json|input.ifc|input.ifczip|input.rvt> [output.html] [options]
Usage: ioviewer <input.glb|input.obj|input.json|input.ifc|input.ifczip|input.rvt|input.nwc> [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:
<input> Path to input 3D model (.glb, .obj, .json, .ifc, .ifczip or .rvt).
<input> Path to input 3D model (.glb, .obj, .json, .ifc, .ifczip, .rvt or .nwc).
[output] Destination path for exported file (.html or .json).
Default: <input-without-ext>.html.

Expand All @@ -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.
""";
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -263,6 +265,13 @@ private static ViewerDocument FromRvt(string path, out IReadOnlyList<SceneDiagno
return FromScene(path, result.Document, diagnostics);
}

private static ViewerDocument FromNwc(string path, out IReadOnlyList<SceneDiagnostic> 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<SceneDiagnostic> diagnostics) =>
diagnostics.Any(d => d.Severity == SceneSeverity.Error) ? 4 : 0;
Expand Down
2 changes: 1 addition & 1 deletion tests/IOViewer.Tests/CliTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <input.glb|input.obj|input.json|input.ifc|input.ifczip|input.rvt>", output);
Assert.Contains("ioviewer <input.glb|input.obj|input.json|input.ifc|input.ifczip|input.rvt|input.nwc>", output);
Assert.Contains("--wireframe", output);
Assert.Contains("--white-mode", output);
Assert.Contains("--serve", output);
Expand Down
55 changes: 55 additions & 0 deletions tests/IOViewer.Tests/ModelAndCliIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using IOViewer.Exporters;
using IOViewer.Importers;
using IOViewer.Model;
using NwcIO;
using NwcIO.Model;
using RvtIO.Scene;
using Xunit;

Expand Down Expand Up @@ -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()
{
Expand Down
Loading