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 @@ -4,6 +4,10 @@ All notable changes to the `NwcIO` library, the CLI and the `NwcIO.Scene` adapte

## [Unreleased]

### Fixed

- Read IFC string properties and class-96 point geometry in Navisworks model files. The scene adapter preserves point geometry (#291).

## [0.18.0] - 2026-11-23

### Added
Expand Down
10 changes: 6 additions & 4 deletions docs/format-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ SEGMENT := [int32 0] ZSTREAM{k} ZTOC contiguous zlib streams from off
ZTOC := [int32 k] [k x int32 compressed length of ZSTREAM i] zero pad to 8 (length roundup8(4 + 4k))
HIERARCHY HEADER := [int32 k >= 1] [k x int32 n_i] n_i = number of roots in ZSTREAM i
ZSTREAM i := ROOT{n_i} zero pad to 8 ids from 100 per stream, no implicit root
ROOT := a new object (never null, never a back-reference) of class 86, 79 or 66; nested objects are class 52
ROOT := a new object (never null, never a back-reference) of class 86, 79, 66 or 70; nested objects are class 52
66 := [str name = null] [ptr 52 key, internal "LcRevitId"] [i32 flags = 0x01000000 or 0x00020000] PAD8 [i64 value in 1..2^31-1]
70 := [str value] [ptr 52 key] [i32 flags]
LINK := the n-th null attribute slot of a hierarchy node, in byte order, takes the n-th root of ZSTREAM 0 ‖ ZSTREAM 1 ‖ ...
```

Expand Down Expand Up @@ -136,7 +137,7 @@ In Revit NWC caches this is a single zlib stream holding a tree in preorder. Eac
Each record is a strict grammar that ends exactly at its TOC length. `int` is a little-endian `int32`; every pad byte and unused packed bit is 0.

```text
RECORD := [100][cls] V UVSLOT NSLOT CSLOT P SFIELD? pad8
RECORD := [100][cls] V UVSLOT NSLOT CSLOT (P SFIELD? | [0] for points) pad8
V := [101][60][p1][p2][p2 x f32 xyz] VMAP? (npos = p2/3; VMAP iff p1 != npos)
UVSLOT := 0 | [id][61] UVBODY
NSLOT := 0 | [id][100][-p1][pal] PACKED(3*pal, B) NTOK? (NTOK iff pal != p1)
Expand All @@ -149,8 +150,8 @@ UVBODY := [p1][fc][fc x f32] TOKENS(p1, fc/2)? (raw; tokens iff fc/2 != p
```

- **Colour palette**: entries are `[A=0xFF][B][G][R]` (a little-endian `uint32` `0xRRGGBBAA`). Evidence: a level's line colour equals its type's colour parameter (a Revit colour int, red in the low byte) in 218 of 218 level lines that are not black; the 95 whose colour tells the orders apart all match this order. A line record can carry several colours, per vertex.
- **Class**: `94` triangles, `95` lines. Class 94 always has a normal slot; class 95 never has a UV or normal slot. The colour slot is optional in both (`.nwd` files saved by Navisworks 2026 have triangle records with one and line records without one): a triangle record's colours are read for length and dropped, and a line record without colours falls back to its material colour. Object ids run 100, 101, then 102, 103 over the slots present.
- **`p1` is the render-vertex count**, not the position count. `p2/3` positions are stored; `VMAP` maps each render vertex to a position and is the identity when absent. Quantised positions (negative `p1`) and point records (class 96) are not supported.
- **Class**: `94` triangles, `95` lines, `96` points. Class 94 always has a normal slot; classes 95 and 96 never have a UV or normal slot. The colour slot is optional (`.nwd` files saved by Navisworks 2026 have triangle records with one and line records without one): a triangle record's colours are read for length and dropped, and a line record without colours falls back to its material colour. Object ids run 100, 101, then 102, 103 over the slots present.
- **`p1` is the render-vertex count**, not the position count. `p2/3` positions are stored; `VMAP` maps each render vertex to a position and is the identity when absent. Quantised positions (negative `p1`) are not supported.
- **PACKED(count, w)**: bit `j` of the stream is bit `31 - j%32` of little-endian word `j/32`; value `k` occupies bits `k*w` to `k*w+w-1`, most significant first.
- **TOKENS(count, fresh)**: one byte code for every map. State: `out = []`, `next = 0`; read lead bytes until `count` values exist.

Expand All @@ -167,6 +168,7 @@ UVBODY := [p1][fc][fc x f32] TOKENS(p1, fc/2)? (raw; tokens iff fc/2 != p
- **Normals** (class 94): a palette entry is three two's-complement values of width `B`, divided by `2^(B-1)-1` and normalised; a zero vector means no normal. `B` is not stored in the record: it is the width under which every record of the file parses (16 for `.nwc`, 8 for `.nwd`). Render vertex `r` takes `palette[NIdx[r]]`, or an axis vector for an axis code (`D0` +X, `D1` -X, `D2` +Y, `D3` -Y, `D4` +Z, `D5` -Z).
- **Triangles** (class 94): corners are `0..p1-1` when `S = 0`, otherwise `TOKENS(S, p1)`. They are split by `L` into consecutive strips; in each strip, triangle `i` is `(c[i], c[i+1], c[i+2])` for even `i` and `(c[i+1], c[i], c[i+2])` for odd `i`. Parity restarts in every strip. The triangle count is the sum of `L-2`. Front faces are counter-clockwise.
- **Polylines** (class 95): render vertices `0..p1-1` are split by `L` into open polylines; the segment count is the sum of `L-1`. There is no implicit closing segment.
- **Points** (class 96): each render vertex is one point. A zero int follows the attribute slots and precedes the pad to 8.
- **UVBODY**: the raw form stores interleaved `f32` U/V pairs. The quantised form stores `[U0 bits][V0 bits][U1 bits][V1 bits]…` using `PACKED`. The widths are `bu = w & 0xFF` and `bv = (w >> 8) & 0xFF`. A nonzero-width code `q` represents `min + q/(2^bits - 1) × (max - min)`; width zero takes that axis's minimum. Both widths may be zero for a constant pair. The token stream maps each of the `p1` render vertices to a stored pair, independently of the position map. U/V use the lower-left origin, as confirmed by converting a synthetic OBJ with asymmetric coordinates in Navisworks.
- **Writer records**: `NwcWriter` emits its own simplified record, `[id][94][0][60][p1][p2][p2 x f32 xyz]`, followed by the trailer `["NWCI"][indexCount][indexCount x i32][Id i32][nameLength][UTF-8 name][pad4]`. The fallback mesh parser (§2.5) restores the exact triangle indices, `Id` and `Name` from the trailer; records without it keep the rebuilt strip and the synthesized `Mesh_{index}` identity. The trailer is writer-specific: it is not part of the documented Navisworks grammar.

Expand Down
2 changes: 1 addition & 1 deletion docs/public-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The supported surface is the `NwcIO` and `NwcIO.Model.*` namespaces listed here
| `NwcNode` | Scene graph tree node representing layers, categories, composite elements, and geometry instances with optional transformations and properties. For Navisworks model files read through their DbCache directory (the strict path), `Meshes` lists every mesh placed on a leaf and `Mesh` the first, ids are depth-first preorder indices, `Transform` is null; `IsElement` marks Revit element nodes, `ElementGuid` is their export GUID from `LcOpGuidStore`, `IfcGlobalId` is the GlobalId the Revit IFC export gives the element: its valid `IFC_GUID` parameter, else its export GUID in the IFC base-64 form (the rule of `RvtIO.Scene`), and `Element` points every node inside an element (and the second node of a sibling pair that repeats one element) to its element node; properties include the tabs stored in `LcOaPartitionProps`; other files leave `Meshes` empty and `Mesh` null. |
| `NwcPropertyRecord` | Property record (`Class`, `Name`, `Value`, `ValueType`, `Tag`, `FirstInt`; typed `IntValue`, `DoubleValue`, `ReferenceId`, `ReferenceTag`, `ReferenceClass`). On node properties of the strict path, `Class` is the property tab name (category, for example `Element`), `Name` the property name and `FirstInt` the key object id. Records scanned from property streams (`NwcDocument.PropertyRecords`, and node properties of other files) keep their internal class names. `TabInternalName` and `InternalName` are the internal names of the tab and the key on strict-path node properties, null on scanned records. |
| `NwcPropertyTab` | One property tab of a strict-path node (`NwcNode.PropertyTabs`, in stored slot order): display `Name`, `InternalName`, `Properties`. A tab object shared by several nodes is one instance. |
| `NwcMesh` | Triangle mesh with vertices, indices, `Normals` aligned with vertices, `LineIndices` for polylines, world-space transform, bounding box, and material. Model files hold one mesh per placed fragment; `Id` is the fragment index. Meshes of fragments that share a geometry record share their `Vertices`, `Indices`, `Normals`, `LineIndices` and `LineColors` arrays; do not mutate them. `GeometryIndex` (the geometry record; −1 outside model files) and `LineColors` (per vertex, line meshes of model files). |
| `NwcMesh` | Geometry with vertices, triangle indices, `Normals` aligned with vertices, and `LineIndices` for polylines. For `IsPointSet` meshes, each vertex is a point, with optional `PointColors` and no triangle or line indices. JSON mesh summaries include `pointCount` for these meshes. Meshes also carry a world-space transform, bounding box, and material. Model files hold one mesh per placed fragment; `Id` is the fragment index. Meshes of fragments that share a geometry record share their `Vertices`, `Indices`, `Normals`, `LineIndices`, `LineColors` and `PointColors` arrays; do not mutate them. `GeometryIndex` (the geometry record; −1 outside model files) and `LineColors` (per vertex, line meshes of model files). |
| `NwcMaterial` | Colour and PBR material. On the strict path, `Name` comes from the nearest class-31 material on the mesh's leaf or an ancestor (`Default` when absent or empty), `Color` comes from the fragment's diffuse appearance with alpha `1 - transparency`, and `DiffuseTexture` comes from its Generic diffuse map. Each colour channel is rounded to a byte (halves away from zero). `Roughness` and `Metallic` keep their defaults. `NwcDocument.Materials` lists distinct name, RGBA and texture combinations in order of first use. With `BuildSceneTree = false`, appearances with a diffuse image still supply a material named `Default`. Elsewhere names come from material references in property records and the colour from a `revit_Color` record that follows the definition. A material without that record gets a neutral grey and `IsInferred = true`. Meshes without a material share one neutral `Default Material` per document with `IsInferred = true`. |
| `NwcTransform` | Parsed pose/transform records with quaternion rotation, uniform `Scale` (negative for a mirrored placement) and affine 4×4 matrix conversion. Model files hold one transform per fragment, with the same `Id` as its mesh. |
| `NwcFileInfo` | Source path, loader plugin, export timestamp from partition header, format version, text encoding, and chunk marker from section headers. |
Expand Down
4 changes: 2 additions & 2 deletions docs/scene.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The scene has one model per input document. Geometry and instance positions are
| Levels | Revit files only. A depth-1 node whose `LcRevitId` tab holds the element id of a level (an `OST_Levels` reference tab) becomes a `SceneLevel` named like the node, and the node and all its descendants carry its `LevelId`. `Elevation` is written in metres from the level's `LcRevitData_Parameter` length property (`lcldrevit_parameter_-1007102`); it is null when that value is absent, not a length, not finite, or the unit is unknown. |
| Property sets | One `ScenePropertySet` per property tab object, listed once for every element that refers to the tab (also when one element refers to it twice). A tab whose properties are all left out has no set. |
| Keys | Set key `nwc:<tab internal name>` for the tabs `LcRevitData_Element`, `LcRevitData_Type`, `LcRevitMaterialProperties` and `LcRevitId`; property key `<set key>.<property internal name>` for the Revit element properties (category, category id, family, element id, name, type, `LcRevitId`) and for the names `lcldrevit_parameter_-<n>` and `revit_<name>`, except `revit_mat_cust_prop_*`. Other tabs and properties have no key. This derivation does not change; a golden test pins it. |
| Geometry, instances | Shared geometry is written once per geometry record and instanced by each mesh with its transform (translation in metres). Triangles carry the stored normals, with a zero normal replaced by the area-weighted average of its triangles. Line meshes become `Lines` geometries (see [Limits](#limits)). |
| Geometry, instances | Shared geometry is written once per geometry record and instanced by each mesh with its transform (translation in metres). Triangles carry the stored normals, with a zero normal replaced by the area-weighted average of its triangles. Line meshes become `Lines` geometries (see [Limits](#limits)). Point sets become unindexed `Points` geometries and use the placement's material colour. |
| Materials | Decoded from the file on the strict path: name, colour and alpha, one `SceneMaterial` per distinct name and colour, in order of first use. `Roughness` and `Metalness` keep IOScene's defaults. |
| Grids | A Revit grid (category `OST_Grids`) with exactly one single-segment line mesh that is horizontal within 1e-6 m becomes a line of one grid system named `Grids`, with `Elevation` = the start Z. Other grids stay elements. |
| Viewpoints | Saved viewpoints become `SceneViewpoint`s with camera position, target and up in metres, `FieldOfView` in radians, near/far distances in metres and perspective or orthographic projection. Views whose camera is not finite or whose document unit is unknown are left out with `viewpoints-skipped`. |
Expand Down Expand Up @@ -72,7 +72,7 @@ A property with no text, a non-finite number, numeric text that does not parse,
| Code | Severity | Meaning |
| --- | --- | --- |
| `no-source-id` | Info | Leaf nodes outside any Revit element have no `SourceId` (one aggregated entry with the count). |
| `empty-mesh` | Info | A mesh has no triangles and no line segments; the entry names the element's GUID. |
| `empty-mesh` | Info | A mesh has no triangles, line segments or points. The entry includes the element's GUID when available. |
| `unit-unknown` | Warning | The length unit is unknown (the file does not name it and `LengthUnit` is not set, or `LengthUnit` is `Unknown`): geometry, grid lines and length, area, volume and angle values are left out. |
| `line-colour-mixed` | Warning | Per geometry record: line segments join vertices of different colours and are drawn with the material colour. |
| `line-colours-capped` | Warning | Per geometry record: the record has more than 64 line colours; segments of the further colours are drawn with the material colour. |
Expand Down
12 changes: 10 additions & 2 deletions src/NwcIO.Scene/NwcSceneReader.Geometry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private static HashSet<NwcNode> AddGeometry(NwcDocument document, SceneDocument
if (groups.Count == 0)
{
diagnostics.Add(new SceneDiagnostic(SceneSeverity.Info, "empty-mesh",
$"Mesh {mesh.Id} has no triangles and no line segments; it has no geometry in the scene.", node.Element?.ElementGuid?.ToString("D")));
$"Mesh {mesh.Id} has no triangles, line segments or points; it has no geometry in the scene.", node.Element?.ElementGuid?.ToString("D")));
continue;
}

Expand Down Expand Up @@ -96,11 +96,19 @@ private static HashSet<NwcNode> AddGeometry(NwcDocument document, SceneDocument
return placed;
}

// The geometries of one geometry key with the colour of their instances: the triangles, then one line geometry per segment colour.
// One point geometry for a point set. Other meshes get their triangles, then one line geometry per segment colour.
private static List<(int Id, RgbaColor? Color)> AddGeometries(SceneDocument scene, NwcMesh mesh, object key, double metresPerUnit, List<SceneDiagnostic> diagnostics)
{
var result = new List<(int Id, RgbaColor? Color)>();
Vector3d[] vertices = [.. mesh.Vertices.Select(v => new Vector3d(v.X * metresPerUnit, v.Y * metresPerUnit, v.Z * metresPerUnit))];
if (mesh.IsPointSet && vertices.Length > 0)
{
int id = scene.Geometries.Count + 1;
scene.Geometries.Add(new SceneGeometry { Id = id, Topology = SceneTopology.Points, Vertices = vertices });
result.Add((id, null));
return result;
}

if (mesh.Indices.Count > 0)
{
int id = scene.Geometries.Count + 1;
Expand Down
5 changes: 5 additions & 0 deletions src/NwcIO/Internal/Container/NwcStreamSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ private static void ValidateDocument(NwcDocument doc)
}
}

if (mesh.IsPointSet)
{
throw new ArgumentException($"Mesh {mesh.Id.ToString(CultureInfo.InvariantCulture)} holds point primitives, which the .nwc writer cannot store.", nameof(doc));
}

if (mesh.LineIndices.Count > 0)
{
throw new ArgumentException($"Mesh {mesh.Id.ToString(CultureInfo.InvariantCulture)} holds line segments, which the .nwc writer cannot store.", nameof(doc));
Expand Down
6 changes: 6 additions & 0 deletions src/NwcIO/Internal/Json/JsonExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ private static async ValueTask WriteDocument(
writer.WriteString("name", mesh.Name);
writer.WriteNumber("vertexCount", mesh.Vertices.Count);
writer.WriteNumber("triangleCount", mesh.TriangleCount);

if (mesh.IsPointSet)
{
writer.WriteNumber("pointCount", mesh.Vertices.Count);
}

if (mesh.Material is not null)
{
writer.WriteString("material", mesh.Material.Name);
Expand Down
Loading
Loading