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

- Read IFC string properties and class-96 point geometry in Navisworks model files. The scene adapter preserves point geometry (#291).
- Read the scene tree of NWD files that store lights in the partition trailer.
- Open mixed IFC/DWG NWD files with named materials, shared assets, 64-bit properties and CAD text geometry. Preserve CAD annotation text, bounds and placement in the read model.

## [0.18.0] - 2026-11-23

Expand Down
19 changes: 11 additions & 8 deletions docs/format-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ Once inflated, streams serve dedicated roles identified by their signature prefi
- `22` leaf: the same layout without `c` and children.
- `X` (element index): 0 on every node that is not a Revit element; on an element node, `X - 1` indexes the GUID table (§2.3). The exporter writes some elements (for example grids) as two sibling nodes with the same `X`, not always adjacent; NwcIO makes the first the element and points the second to it. Such a pair takes two equal GUID table entries (`X - 1` and `X`), so the table size is the number of stored nodes with `X > 0` and the next element's index is `X + 2`. The same `X` under different parents, including a node and its descendant, is a linked placement: NwcIO keeps it with `NwcNode.IsLinkPlacement`, points `Element` at the first placement, and `NwcIO.Scene` writes it as its own `SceneModel`.
- `32` (`LcOaPartition`): `[str]` (empty in every file seen), a class-53 body whose name is the partition's source file name, then a trailer. Class 32 nodes are the top-level children of a `.nwd`; class 53 nodes are the top-level children of a `.nwc`. The cache's separate `LcOpNwdPartition` stream starts directly with a class-32 pointer and omits the children's count and slots. Its trailer starts with the light count and light objects, followed by source metadata. Its grammar is `[i32 2][i32 n] n x ptr27 3 x f64 [i32][str loader plugin][i32 format version][i32][i32] 6 x f64 [i32][str][i32][str source path] 3 x f64 4 x f64 [i32][i32]`. The last four doubles describe a plan box.
- `27` partition light: `[i32 1][i32 selector (0 or 1) or new ptr185][13 x f64]`. The class-185 asset uses the same layout as material JSON. Lights are read and skipped.
- `27` partition light: `[i32 1][i32 selector (0 or 1), new ptr185 or shared asset index][13 x f64]`. The class-185 asset uses the same layout as material JSON. Lights are read and skipped.
- `52` display/internal name pair: `[str name][str internal]`. It is the node username, the property tab username and every property key.
- **Attributes** (slots may be null): `86` property tab `[str name][ptr 52][i32 flags][i32 n] n x ([ptr 52 key][i32 type][value])` with value by type `0` none, `1,5,6,7,10,11` `f64`, `2,3` `i32`, `4` and `9` string (type 9 was never seen; it is read as a string), `8` class-52 pointer; `31` material; `40` translation; `41` translation and quaternion (`x -> R(q)x + t`); `39` 3x3 column-major matrix and translation; `79` hyperlinks; `200` and `185` material JSON.
- **Attributes** (slots may be null): `86` property tab `[str name][ptr 52][i32 flags][i32 n] n x ([ptr 52 key][i32 type][value])` with value by type `0` none, `1,6,7,10,11` `f64`, `5,15` `i64` (Unix seconds and signed integer, respectively), `2,3` `i32`, `4` and `9` string (type 9 was never seen; it is read as a string), `8` class-52 pointer, `12,13` three or two `f64` coordinates; `31` material; `40` translation; `41` translation and quaternion (`x -> R(q)x + t`); `39` 3x3 column-major matrix and translation; `79` hyperlinks; `200` wraps an inline or shared class-185 material asset (§2.4).
- **Class 31 material**: `[str name][15 x f64]`. The DWG variant is `[str name][ptr 52 username][i32 zero][14 x f64]`. Its username can be a new object or a back-reference.
- **Shared subtrees**: a child pointer may back-reference an earlier node, so the hierarchy is a directed acyclic graph. A node reached through several parents appears once per path when the tree is expanded.
- **Preorder index (`seq`)**: walk from the implicit root in stored order, counting groups, with a shared subtree walked again at every place it occurs. The root has index 0. Every fragment's `seq` indexes this expanded sequence and lands on a leaf; `seq` never decreases along the fragments stream, and a leaf owns one contiguous run of fragments.

Expand All @@ -79,12 +80,12 @@ ZTOC := [int32 k] [k x int32 compressed length of ZSTREAM i] zero pad to 8
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, 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]
66 := [str name = null] [ptr 52 key] [i32 flags] PAD8 [i64 value]
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 ‖ ...
```

The roots are the tabs a node uses once (element, parameter, type, material and room tabs) and its element id; tabs shared by two or more nodes stay in the hierarchy. A class-66 root becomes a one-property tab named by its key (`LcRevitId`). The per-node order the exporter writes (`86* 79? 66?`, the 66 last) is not enforced.
The roots are the tabs a node uses once (element, parameter, type, material and room tabs) and its element id; tabs shared by two or more nodes stay in the hierarchy. A class-66 root becomes a one-property tab named by its key. Revit IDs use flags `0x01000000` or `0x00020000` and values in `1..2^31-1`. DWG handles (`LcOpDwgEntityAttrib`) accept flags `0`, `0x02000000` and `0x03000000` as well and retain their 64-bit value. Handles already accepted under the legacy flags and range keep their existing type-2 representation. The per-node order the exporter writes (`86* 79? 66?`, the 66 last) is not enforced.

### 2.2.2 Lenient fallback scene tree

Expand Down Expand Up @@ -113,9 +114,9 @@ The nesting is therefore independent of the exporter UI language for the marker
- `14` pose: `[3 x f64 t]`, a translation (identity rotation, scale 1). The Revit NWC exporter writes it for unrotated poses.
- `15` pose: `[3 x f64 t][4 x f64 q]`, `q = (x, y, z, w)` a unit quaternion.
- `16` pose with scale: class 15 plus `[f64 s]`. The scale is a uniform factor and can be negative.
- `55` appearance: `[i32 flags][ptr 54]`, plus a material-asset slot when `flags & 32`. The slot is null, a class-185 object pointer, or a single shared index (`2..99`) into `LcOpSharedNodes`. The shared stream starts with a count followed by indexed pointers. An appearance with flags `0x71` has one trailing zero word in a Navisworks 2027 file saved after editing the diffuse image.
- `55` appearance: `[i32 flags][ptr 54]`, plus a material-asset slot when `flags & 32`. The slot is null, a class-185 object pointer, or a single shared index (2 or higher) into `LcOpSharedNodes`. The shared stream starts with a count followed by zero-based indexed pointers to class-185 assets or class-102 fonts. A class-102 font stores `[str name][f64][4 x i32]`. A valid new class-185 pointer takes precedence over a shared index with the same lead word. An appearance with flags `0x71` has one trailing zero word in a Navisworks 2027 file saved after editing the diffuse image.
- `185` material asset: `[str JSON][str metadata][i32 count]`, then `count` items `[str name][i32 embedded][str path]`; an embedded item adds `[str name][i64 length][payload padded to 4]`. For the Generic diffuse image, `userassets` identifies the root key in `materials`. Its enabled `properties.colors.generic_diffuse.connections` identifies the `UnifiedBitmap` entry. `properties.uris.unifiedbitmap_Bitmap.values` supplies the path. The reader looks up that path in the XRef table and prefers the matching record's `RemappedPath` when present. Thumbnail URIs and unrelated bitmap nodes are ignored.
- `54` material: 14 `f32`: ambient 0–2, diffuse 3–5, specular 6–8 (always 0), emissive 9–11 (always 0), shininess 12 (Revit Shininess / 128), transparency 13 (Revit Transparency / 100, values below 0.1 stored as 0). Channels are quantised to bytes. `31` (hierarchy) repeats the fields as `f64` and names the material (null for rooms).
- `54` material: 14 `f32`: ambient 0–2, diffuse 3–5, specular 6–8 (always 0), emissive 9–11 (always 0), shininess 12 (Revit Shininess / 128), transparency 13 (Revit Transparency / 100, values below 0.1 stored as 0). Channels are quantised to bytes. `31` (hierarchy) uses `f64` fields and names the material (§2.2).
- `93` geometry reference: `[6 x f32 bbox][3 x f64 c][f32][i32 key][i32 rec]`. `rec` is the 1-based index of a geometry record (§2.5). The box equals the bounding box of the record's positions, and `c` is the offset of those positions: for a posed fragment it is the pose translation in the partition's frame, and it places a fragment without a pose.
- **Placement**: the fragment pose is the full world transform of the record's positions: `world = s·R(q)·v + t`, with `s = 1` for classes 14 and 15 and `R(q)` the identity for class 14. `R(q)` is the usual rotation matrix of the normalised quaternion. No unit conversion is applied.
- **Mirroring**: a pose with `s < 0` mirrors the geometry, so triangle winding must be reversed to keep faces outward in world space. Local vertices and indices are not changed.
Expand Down Expand Up @@ -151,7 +152,7 @@ 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, `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.
- **Class**: `94` triangles, `95` lines, `96` points, `103` text. 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 @@ -169,8 +170,10 @@ 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.
- **Points** (class 96): each render vertex is one point. An `i32` flag of 0 or 1 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.
- **Text** (class 103): `[100][103][str text][6 x f32][6 x f32 bounds (min then max)][i32 style index][pad8]`. The reader preserves the text, style index, bounds and fragment placement. The glyph triangles counted by the fragment are absent from the geometry record.

- **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.

### 2.7 DB Cache Directory (`DbCache` / `LcOpDBCache`)
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` | 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). |
| `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. CAD text meshes carry `Text`, `TextStyleIndex`, bounds and a placement. Their vertex and index lists are empty. JSON mesh summaries include `text` and `textStyleIndex`. 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
Loading
Loading