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

### Fixed

- Path-based Wavefront OBJ export writes a sibling `.mtl` with diffuse colors and opacity from mesh materials (#93). Texture coordinates and texture maps are pending.
- Path-based Wavefront OBJ export writes a sibling `.mtl` with diffuse colors and opacity from mesh materials (#93).
- Read raw and quantised mesh UVs and Generic diffuse image references with XRef remapping. OBJ/MTL and GLB exports preserve the UVs and link to external diffuse images (#93).

## [0.16.0] - 2026-11-19

Expand Down
11 changes: 6 additions & 5 deletions docs/format-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ The nesting is therefore independent of the exporter UI language for the marker
- **Other containers**: files not read through a DbCache directory are scanned for streams `[int32 ?][int32 count]` where `(streamLength - 8) == count * 16`, followed by the 16-byte GUIDs.

### 2.4 Fragments (`LcOpNwdFragments`)
- **Location**: the DbCache entry whose final segment is `LcOpNwdFragments` (one zlib stream). Framing: `[int32 n] n x pointer`, zero-padded to a multiple of 8. Pointers follow the rule in §2.2; every root pointer is a new class-13 object.
- **Location**: the DbCache entry whose final segment is `LcOpNwdFragments` (one zlib stream). Framing: `[int32 n] n x pointer`, zero-padded to a multiple of 8. Some writers insert one zero word between `n` and the first `[100][13]`. Pointers follow the rule in §2.2; every root pointer is a new class-13 object.
- **Classes**:
- `13` fragment: `[f64 D][i32 a][i32 b][i32 c][i32 seq][ptr pose][ptr appearance][ptr geometry]`.
- `seq`: preorder index of the owning leaf (§2.2).
Expand All @@ -111,7 +111,8 @@ 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 `[ptr 185]` when `flags & 32`.
- `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.
- `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).
- `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.
Expand Down Expand Up @@ -143,7 +144,8 @@ CSLOT := 0 | [id][58][5634][-p1][pal][pal x 4 bytes] CTOK? (CTOK iff pal != p1
P := [n][bits][n][ceil(n*bits/32) words] (strip or polyline lengths L)
SFIELD := [S] TOKENS(S, p1)? (class 94 only; tokens iff S > 0)
UVBODY := [p1][fc][fc x f32] TOKENS(p1, fc/2)? (raw; tokens iff fc/2 != p1)
| [-p1][4 x f32][w][m][ceil(m*(bu+bv)/32) words] TOKENS(p1, m)? (quantised; tokens iff m != p1)
| [-p1][f32 minU][f32 minV][f32 maxU][f32 maxV][w][m]
[ceil(m*(bu+bv)/32) words] TOKENS(p1, m)? (quantised; tokens iff m != p1)
```

- **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.
Expand All @@ -165,8 +167,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.
- **UVBODY**: the raw form has a non-negative first int `p1` and `fc` floats (two per UV pair, `fc/2` pairs). The quantised form has `-p1`, four floats, then `w`, `m` and the packed words; `bu = w & 0xFF` and `bv = (w >> 8) & 0xFF` are the bit widths of the two coordinates, so the packed block is `ceil(m*(bu+bv)/32)` words. One width may be 0, a coordinate constant over the record (seen in `.nwd` files saved by Navisworks 2026); both cannot. The token stream maps each of the `p1` render vertices to one of the `fc/2` or `m` stored pairs.
- **Not decoded**: UV values and colour channels. Only their lengths and maps are read, to find the next field.
- **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.

### 2.7 DB Cache Directory (`DbCache` / `LcOpDBCache`)
Expand Down
12 changes: 9 additions & 3 deletions docs/public-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The supported surface is the `NwcIO` and `NwcIO.Model.*` namespaces listed here
| `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). |
| `NwcMaterial` | Colour and PBR material. On the strict path, with meshes and the scene tree, each mesh's material is decoded from the file: `Name` is the name of the nearest class-31 material on its leaf or an ancestor (`Default` when there is none or it is empty), `Color` is the diffuse colour of its appearance with alpha `1 - transparency`, each channel rounded to a byte (halves away from zero), and `Roughness` and `Metallic` keep their defaults (the file's shininess is not mapped); one material per distinct name and colour bytes, `Id` in order of first use, and `NwcDocument.Materials` lists them; `NwcNode.Material` stays null. Without the scene tree there are no materials. Elsewhere nothing is decoded from material data in the file: 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`; no colour is guessed from the name. Meshes are not matched to materials by name or size: every mesh without a material shares one neutral `Default Material` with `IsInferred = true` (a new instance per document, listed in `NwcDocument.Materials`). `IsInferred` is `true` for a colour or material that is not read from the file. |
| `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. |
| `NwcDbCacheDirectory` & `NwcDbCacheEntry` | The `LcOpDBCache` directory (`NwcDocument.DbCache`, null when the file has none or it cannot be parsed). `DatabaseName` is the name of the `LcOpDBCache` entry or `""`; `Entries` lists every entry in file order and `Find` looks one up by segment name (exact or suffix, case-insensitive). Each entry has `Name`, `Flags`, `Offset` (an absolute file offset), `Length` and `Extra` (`a + b*2^32` of its two trailing 32-bit fields). |
Expand Down Expand Up @@ -137,8 +137,14 @@ Space to activate them. With focus on the 3D model view, the arrow keys orbit, +
Home resets the camera. Escape clears the current measurement while Measure is active.

OBJ saves to a path, including `SaveObjAsync`, write a sibling `<name>.mtl` when exported geometry
has materials. The library stores diffuse RGB (`Kd`) and opacity (`d`). OBJ saves to a stream or
`TextWriter` export geometry only. Texture coordinates and texture maps are currently unsupported.
has materials. `NwcMesh.TexCoords` holds optional per-vertex UVs with a lower-left origin. OBJ
writes `vt` and indexes it from faces, including when writing to a stream or `TextWriter`.
The material library stores diffuse RGB (`Kd`), opacity (`d`), and `map_Kd` for a diffuse image.
GLB writes `TEXCOORD_0` with a top-left origin, and `baseColorTexture` for external PNG or JPEG images.
`NwcMaterial.DiffuseTexture` holds the image reference, including any XRef remapping. Exporters
emit references to local paths. Keep the referenced images available at those paths. Relative
references are interpreted relative to the exported asset. Embedded image payloads and other
material channels remain outside this support.
An OBJ save with materials requires a sibling filename that can be used in an `mtllib` directive.
The export rejects a symbolic link at the material library path.

Expand Down
Loading
Loading