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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ API between minor releases.
- Keyboard navigation and visible focus in the model tree and context menu.
- Select multiple elements in the model tree and open the viewer context menu from its rows.
- Filter the model tree by source model, level and category, and optionally isolate the matches in 3D.
- Export explicitly placed source models together in one standalone HTML viewer with independent visibility.

### Fixed

Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ ioviewer model.nwc -o viewer.html
ioviewer model.glb --serve
```

Pass `--add` and `--placement` to combine several source models into one offline HTML viewer.

```sh
ioviewer architecture.ifc --add services.rvt --placement 10,20,3,90 -o coordination.html
```

The first input defines the coordinate space. Each `--add` takes a file followed by
`--placement x,y,z,yaw`. Rotate counterclockwise about +Z by `yaw` degrees, then translate by
`x,y,z` metres. Use `0,0,0,0` for a source already in the first model's coordinates. Repeat the
pair to add more inputs. The viewer lists all models in the Linked files panel with individual
visibility controls. The first input supplies any startup clipping. Saved views from added sources
are placed with their models. A saved section box requires a yaw that is a multiple of 90 degrees.

Export structured JSON snapshots:

```sh
Expand Down
6 changes: 3 additions & 3 deletions docs/public-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ The model data is the IOScene scene model, referenced by the `IOViewer` package.

### Viewer document (`IOViewer.Model`)

- `ViewerDocument`: a `Scene` plus what only the viewer uses: `SectionPlanes`, `SectionBox` and `HiddenModelKeys`, the
keys of the linked models hidden at start. `ViewpointStates` adds optional state to saved cameras. `Title` reads and
writes `Scene.Title`.
- `ViewerDocument` holds the scene, startup clipping, and the model keys hidden at start in `HiddenModelKeys`.
`ShowHostInModelList` adds the first model to the Linked files controls so it can be hidden independently.
`ViewpointStates` adds optional state to saved cameras. `Title` reads and writes `Scene.Title`.
- `ViewerSectionPlane`: Cutting plane defined by axis or custom normal. `Offset` is the signed distance in metres
from the scene origin along its unit normal. By default the plane cuts the side the normal points to. `Inverted`
cuts the opposite side.
Expand Down
65 changes: 52 additions & 13 deletions src/IOViewer.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ with NwcIO. Conversion diagnostics are reported as warnings or errors.

Options:
-o, --output <file> Destination path for exported HTML or JSON file.
--add <file> --placement <x,y,z,yaw>
Add another model. Translation is in metres and yaw in degrees about +Z.
Repeat the pair for each model. Use 0,0,0,0 for an already aligned source.
--title <title> Page title shown in the browser tab.
--wireframe Enable wireframe display mode by default.
--white-mode Enable white/clay architectural rendering mode by default.
Expand Down Expand Up @@ -76,6 +79,7 @@ public static int Main(string[] args)
string? outputPath = null;
string? customTitle = null;
string? explicitJsonPath = null;
var additional = new List<(string Path, Transform3d Placement)>();
bool wireframe = false;
bool whiteMode = false;
bool includeProps = true;
Expand Down Expand Up @@ -106,6 +110,16 @@ public static int Main(string[] args)
}
customTitle = args[++i];
break;
case "--add":
if (i + 3 >= args.Length || args[i + 1].StartsWith('-') || args[i + 2] != "--placement"
|| !SceneFederation.TryParsePlacement(args[i + 3], out var placement))
{
Console.Error.WriteLine("Error: Each --add <file> requires --placement <x,y,z,yaw> with four finite numbers.");
return 1;
}
additional.Add((args[i + 1], placement));
i += 3;
break;
case "--wireframe":
wireframe = true;
break;
Expand Down Expand Up @@ -165,29 +179,38 @@ public static int Main(string[] args)
Console.Error.WriteLine($"Error: File not found: '{inputPath}'.");
return 2;
}
foreach (var source in additional)
{
if (File.Exists(source.Path)) continue;
Console.Error.WriteLine($"Error: File not found: '{Printable(source.Path)}'.");
return 2;
}

outputPath ??= Path.ChangeExtension(inputPath, ".html");

var sw = Stopwatch.StartNew();
ViewerDocument doc;
IReadOnlyList<SceneDiagnostic> diagnostics = [];
int adapterCode;
string sourcePath = inputPath;
try
{
string ext = Path.GetExtension(inputPath).ToLowerInvariant();
doc = ext switch
doc = Load(inputPath, out var diagnostics);
adapterCode = ExitCode(diagnostics);
if (additional.Count > 0)
{
".glb" => GlbViewerImporter.Load(inputPath),
".obj" => ObjViewerImporter.Load(inputPath),
".json" => JsonViewerImporter.Load(inputPath),
".ifc" or ".ifczip" => FromIfc(inputPath, out diagnostics),
".rvt" => FromRvt(inputPath, out diagnostics),
".nwc" => FromNwc(inputPath, out diagnostics),
_ => throw new NotSupportedException($"Unsupported input file extension: '{ext}'. Supported: .glb, .obj, .json, .ifc, .ifczip, .rvt, .nwc.")
};
SceneFederation.SetInputPath(doc.Scene, inputPath);
foreach (var source in additional)
{
sourcePath = source.Path;
var input = Load(sourcePath, out diagnostics);
SceneFederation.Append(doc, input, sourcePath, source.Placement);
adapterCode = Math.Max(adapterCode, ExitCode(diagnostics));
}
}
}
catch (Exception ex)
{
Console.Error.WriteLine($"Error: Failed to load '{inputPath}': {Printable(ex.Message)}");
Console.Error.WriteLine($"Error: Failed to load '{Printable(sourcePath)}': {Printable(ex.Message)}");
return 3;
}

Expand Down Expand Up @@ -248,7 +271,23 @@ public static int Main(string[] args)
return 5;
}

return ExitCode(diagnostics);
return adapterCode;
}

private static ViewerDocument Load(string path, out IReadOnlyList<SceneDiagnostic> diagnostics)
{
diagnostics = [];
string ext = Path.GetExtension(path).ToLowerInvariant();
return ext switch
{
".glb" => GlbViewerImporter.Load(path),
".obj" => ObjViewerImporter.Load(path),
".json" => JsonViewerImporter.Load(path),
".ifc" or ".ifczip" => FromIfc(path, out diagnostics),
".rvt" => FromRvt(path, out diagnostics),
".nwc" => FromNwc(path, out diagnostics),
_ => throw new NotSupportedException($"Unsupported input file extension: '{ext}'. Supported: .glb, .obj, .json, .ifc, .ifczip, .rvt, .nwc.")
};
}

private static ViewerDocument FromIfc(string path, out IReadOnlyList<SceneDiagnostic> diagnostics)
Expand Down
Loading
Loading