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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ All notable changes to the `NwcIO` library, the CLI and the `NwcIO.Scene` adapte
### Fixed

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

## [0.18.0] - 2026-11-23
Expand Down
2 changes: 1 addition & 1 deletion docs/format-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Once inflated, streams serve dedicated roles identified by their signature prefi
- `53` group: `[str name][ptr 52 username][i32 flags][i32 X][i32 Y][Y x attribute ptr][i32 c][c x child ptr]`. Children are class 22 or 53 and are never null.
- `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.
- `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.
- `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).
Expand Down
6 changes: 3 additions & 3 deletions src/NwcIO/Internal/Parsing/HierarchyParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,11 @@ private void ReadPartitionTrailer()
throw _reader.Fail("partition trailer does not start with 2");
}

// A new light takes at least 120 bytes: its pointer, marker, selector and thirteen doubles.
int lightCount = _reader.ReadCount(120);
// A shared light takes only the two words of its back-reference.
int lightCount = _reader.ReadCount(8);
for (int i = 0; i < lightCount; i++)
{
_reader.ReadPointer(PartitionLightClasses, _readBody, allowNull: false, allowBackReference: false);
_reader.ReadPointer(PartitionLightClasses, _readBody, allowNull: false);
}

SkipDoubles(3);
Expand Down
34 changes: 34 additions & 0 deletions tests/NwcIO.Tests/HierarchyParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,40 @@ public void Read_PartitionLights_PreserveTheFollowingPartition()
Assert.Equal(["Model", "A", "L", "B"], nodes.Select(node => node.Name));
}

[Theory]
[InlineData(1)]
[InlineData(8)]
public void Read_SharedPartitionLights_ResolvesEarlierLightObjects(int count)
{
var w = Begin(n: 2);
int lightId = 0;
Partition(w, "A", 0, _ => { }, lights:
[
p =>
{
lightId = p.Next;
PartitionLight(p);
},
]);
Action<LcGraphWriter>[] references = Enumerable.Repeat<Action<LcGraphWriter>>(p => p.Ref(lightId), count).ToArray();
Partition(w, "B", 1, p => Leaf(p, 0, _ => { }), lights: references);

var nodes = HierarchyParser.Read(End(w), "Model");
Assert.Equal(["Model", "A", "B", "L"], nodes.Select(node => node.Name));
Assert.Same(nodes[2], nodes[3].Parent);
}

[Fact]
public void Read_PartitionLightReferenceToOtherClass_Throws()
{
var w = Begin(n: 2);
int partitionId = w.Next;
Partition(w, "A", 0, _ => { });
Partition(w, "B", 0, _ => { }, lights: [p => p.Ref(partitionId)]);

AssertRule("back-reference to class 32, which this slot does not allow", End(w));
}

[Theory]
[InlineData(0, null, "class-27 light marker is not 1")]
[InlineData(1, 86, "class 86, which this slot does not allow")]
Expand Down
Loading