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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ All notable changes to the `NwcIO` library, the CLI and the `NwcIO.Scene` adapte
### Added

- Read class-104 parametric disks and class-105 cylinder sides as triangle geometry (#291).
- Read class-17 affine fragment poses, including non-uniform scaling and mirrored placements (#291).
- Expose the original IFC element identifier as `NwcNode.SourceIfcGlobalId` and `sourceIfcGlobalId` in scene-tree JSON (#291).

### Fixed

- Read line normals, class-76 text properties, short asset lights and additional fragment appearance records. Replace encoded surrogate code units in material names (#291).
- Open DWG caches whose implicit ByLayer material has an empty asset slot.
- 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 or references to earlier 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.
Expand Down
21 changes: 12 additions & 9 deletions docs/format-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ 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]`. A light pointer can define a new class-27 object or refer to a previously read class-27 object. The last four doubles describe a plan box.
- `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.
- `27` partition light: `[i32 1][i32 selector (0 or 1), new ptr185 or shared asset index][13 x f64]`. A short asset light has 12 doubles followed by a new class-27 object with a new class-185 asset. 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,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.
- **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. Three-byte encodings of UTF-16 surrogate code units in the material name become U+FFFD.
- **Class 200 implicit material**: DWG caches can store `[str "ByLayer"][i32 0][i32 0][null asset pointer]`.
- **Imported IFC element IDs**: The class-86 tab with internal name `lcatfconsumer_Element_tab` can hold `lcatfconsumer_parameter_GlobalId` and `lcatfconsumer_parameter_IfcGUID`. The reader exposes their valid 22-character IFC ID as `NwcNode.SourceIfcGlobalId` when all valid values agree. The ID belongs to the node carrying the tab.
- **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 @@ -80,13 +81,14 @@ 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 >= 0] [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
ROOT := a new object (never null, never a back-reference) of class 86, 79, 66, 70 or 76; nested objects are class 52
66 := [str name = null] [ptr 52 key] [i32 flags] PAD8 [i64 value]
70 := [str value] [ptr 52 key] [i32 flags]
76 := [str label] [ptr 52 key] [i32 flags] [str value]
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. 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.
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. A class-76 root becomes one text property, using the key's display name when no label is stored. 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 @@ -115,13 +117,14 @@ 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 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.
- `17` affine pose: three basis rows `[3 x f32][f32 zero]`, then `[f32 one]` and `[3 x f64 t]` aligned to 8. The rows are the images of the local X, Y and Z axes. DWG block insertions with different scale factors per axis can use this pose.
- `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. Flag `0x71` has a trailing zero word after the material-asset slot. Flag `0x61` can have the same zero word. A new inline asset can also be followed by a zero word immediately before a new class-93 geometry pointer.
- `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) 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.
- **Sharing**: several fragments may reference one geometry record, directly or through back-referenced class 93 objects. A pose slot may reference an earlier class-14, class-15 or class-16 pose in the stream.
- **Placement**: for classes 14–16 the fragment pose places positions as `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 rotation matrix of the normalised quaternion. For class 17, multiply each basis row by the corresponding local coordinate and add the three results to the translation. No unit conversion is applied.
- **Mirroring**: a negative uniform scale or a negative determinant of the linear basis reverses triangle winding in world-space output.
- **Sharing**: several fragments may reference one geometry record, directly or through back-referenced class 93 objects. A pose slot may reference an earlier class-14, class-15, class-16 or class-17 pose in the stream.

#### Spatial hierarchy (`LcOpNwdSpatialHierarchy`)

Expand Down Expand Up @@ -153,7 +156,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, `103` text, `104` disks, `105` cylinder sides. 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, `104` disks, `105` cylinder sides. Class 94 requires normals and allows UVs. Class 95 allows normals. Class 96 requires both slots to be null. 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 Down
Loading
Loading