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 @@ -9,6 +9,7 @@ API between minor releases.
### Added

- `RvtIO.Scene` exports decoded straight Revit grid axes and their labels in scene coordinates.
- `RvtIO.Scene` exports circular and multi-segment grid axes as connected paths with one datum label per axis.
- `RvtDocument.GetBuildingStoreyCatalog()` exposes project building storeys and their assignments.
`RvtIO.Scene` writes those levels and the storey of each drawable element using the current IFC rules.

Expand Down
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<ItemGroup>
<!-- The scene contract of RvtIO.Scene: any patch of the 0.1 line, no preview of the next (breaking) minor that IOScene publishes. -->
<PackageVersion Include="IOScene" Version="[0.1.1, 0.2.0-0.0)" />
<PackageVersion Include="IOScene" Version="[0.1.2, 0.2.0-0.0)" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions docs/public-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ projects through `InternalsVisibleTo`.
| `RvtExitCodes`, `RvtInputException`, `RvtLimitException`, `RvtContainerCheck` | The exit codes 0 to 4 and 6 of the command line tool (code 5 is returned by `downgrade --check` and `save-as` when refused), the exceptions `RvtFileReader.Read` throws for a file it cannot read, and the check that raises them. |
| `FilteredElementCollector` | Query over the elements of a document (`OfCategory`, `WhereElementIsNotElementType`, `Where`, ...). |
| `BuildingStoreyCatalog`, `BuildingStorey` | `RvtDocument.GetBuildingStoreyCatalog()` lists native project building storeys in order of elevation and Revit ID. Each storey carries its ID, name and resolved elevation in internal feet. `GetStoreyId(elementId)` uses the current IFC storey rules and returns null for an unknown element or one assigned to the building itself. Obtain a new catalog after editing levels. |
| `GridAxis` | `RvtDocument.GetGridAxes()` lists decoded project axes in Revit ID order. A circular or multi-segment axis has ordered analytic segments. `GridAxis.Tessellate(maxErrorFeet)` returns path points in internal feet. |

## Model

Expand Down
8 changes: 5 additions & 3 deletions docs/scene.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

`RvtIO.Scene` turns a Revit project read by RvtIO into a scene of the `IOScene` package: a `SceneDocument` with one
model, the drawable elements, their triangle meshes in metres, their names and parameters, the building storeys, and
the decoded straight grid axes. A viewer or another consumer of the scene reads it without knowing Revit. The scene itself is specified in the contract of the `IOScene`
the decoded grid axes. A viewer or another consumer of the scene reads it without knowing Revit. The scene itself is specified in the contract of the `IOScene`
repository (`docs/contract.md`), and the property keys it writes are registered there in `docs/keys.md`.

The adapter is a preview. It is published as the package `RvtIO.Scene` on each RvtIO release tag, depends on exactly
Expand Down Expand Up @@ -53,7 +53,8 @@ rvtio project.rvt --ifc project.ifc --compact-json project.compact.json --scene
|---|---|
| `SceneModel.Key` | `RvtSceneOptions.ModelKey`, else the file name without its directory (`project.rvt`). This derivation does not change. |
| `SceneModel` | `SourceFormat` `rvt`, `SourceLengthUnit` `ft`, `Producer` `RvtIO.Scene <version>`. |
| `SceneGridSystem`, `SceneGridLine` | One grid system named `Grids` when the model has valid straight grid axes. Each axis uses its element name and the endpoints of its decoded location curve, converted from feet to metres in the document's internal coordinates. Elevation is the start point's Z. |
| `SceneGridSystem`, `SceneGridLine` | One grid system named `Grids` when the model has decoded axes. Standalone straight axes use the element name and endpoints of the location curve, converted from feet to metres in the document's internal coordinates. Elevation is the start point's Z. |
| `SceneGridPath` | One path and datum label per standalone circular arc or complete multi-segment grid. Points follow the stored segment order at model Z=0, as in Revit's grid curves. Arcs are sampled with at most 1 mm of chord error. Viewers place the label only at the two outer endpoints. |
| `SceneLevel` | Project levels marked as building storeys, ordered by elevation and Revit element ID. Names and resolved elevations, including elevations inferred by the reader, use the same level selection as IFC. Elevations are written in metres. |
| `SceneElement.LevelId` | The building-storey assignment from `RvtDocument.GetBuildingStoreyCatalog()`, using the current IFC rules for stored level references and geometry fallback. Assignments to the building itself leave this field empty. The scene assigns a storey to each drawable element independently of IFC product aggregation. |
| `SceneElement` | One per drawable element of `ElementMeshes.Extract` (the elements the IFC export would consider products, see the remarks of `ElementMeshes`). `Id` is the element id. |
Expand Down Expand Up @@ -100,7 +101,8 @@ The text a value is written with under a key is frozen with the key: changing it
(numbers in SI units, booleans, element references) wait for public RvtIO API.
- Shared, project and family parameters have no key yet. Their formats (for example `revit:shared:<guid>`) are
registered in the IOScene key registry when the adapter first writes them; that is an addition.
- Every element is a top-level element of its model. Linked models, views and curved grid axes are omitted.
- Every element is a top-level element of its model. Linked models and views are omitted.
- The grid path reader accepts vertical cylindrical grid surfaces and complete, connected chains of straight and circular segments. It omits unsupported surfaces, incomplete chains and paths requiring more than 65,536 vertices at the documented tolerance.
- Materials have a name and a colour; no roughness, metalness or textures.
- Element names are those of `RvtDocument`; the validated names the IFC export applies to files read by their own class
schema are not public API.
34 changes: 23 additions & 11 deletions src/RvtIO.Scene/RvtSceneReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace RvtIO.Scene;

/// <summary>
/// Turns a Revit document into a scene (<see cref="SceneDocument"/>): one model, one element per drawable element of the document
/// with its triangle meshes (<see cref="ElementMeshes"/>), its names and its parameters, plus building storeys and decoded straight grid axes.
/// with its triangle meshes (<see cref="ElementMeshes"/>), its names and its parameters, plus building storeys and decoded grid axes.
/// </summary>
/// <remarks>
/// <para>Lengths are converted from feet to metres (x 0.3048) into the internal coordinates of the document, Z up. A symbol that
Expand Down Expand Up @@ -230,22 +230,34 @@ private static RvtSceneResult Map(RvtDocument document, MeshSet meshes, string m

private static void AddGrids(SceneDocument scene, RvtDocument document)
{
const double GridChordErrorMetres = 0.001;
var grid = new SceneGridSystem { ModelId = ModelId };
foreach (var element in document.Collector().OfCategory(BuiltInCategory.OST_Grids)
.WhereElementIsNotElementType().OrderBy(element => element.Id))
foreach (var axis in document.GetGridAxes())
{
if (element.Location is not { CurveType: "Line", StartPoint: [var x0, var y0, var z0], EndPoint: [var x1, var y1, var z1] }
|| !double.IsFinite(x0) || !double.IsFinite(y0) || !double.IsFinite(z0)
|| !double.IsFinite(x1) || !double.IsFinite(y1) || !double.IsFinite(z1))
if (axis.Segments is [{ CurveType: "Line" } line])
{
if (ReadPoint(line.StartPoint) is not { } start || ReadPoint(line.EndPoint) is not { } end || start == end)
continue;
grid.Lines.Add(new SceneGridLine { Name = axis.Name, Start = start, End = end, Elevation = start.Z });
continue;
}

var start = new Vector3d(x0, y0, z0) * MetresPerFoot;
var end = new Vector3d(x1, y1, z1) * MetresPerFoot;
if (start == end) continue;
grid.Lines.Add(new SceneGridLine { Name = element.Name ?? string.Empty, Start = start, End = end, Elevation = start.Z });
if (axis.Tessellate(GridChordErrorMetres / MetresPerFoot) is not { } samples) continue;
var points = new List<Vector3d>(samples.Count);
foreach (var sample in samples)
{
if (ReadPoint(sample) is not { } point) break;
points.Add(point);
}
if (points.Count == samples.Count)
(grid.Paths ??= []).Add(new SceneGridPath { Name = axis.Name, Points = points });
}

if (grid.Lines.Count > 0) scene.Grids.Add(grid);
if (grid.Lines.Count > 0 || grid.Paths is { Count: > 0 }) scene.Grids.Add(grid);

static Vector3d? ReadPoint(double[] point) =>
point is [var x, var y, var z] && double.IsFinite(x) && double.IsFinite(y) && double.IsFinite(z)
? new Vector3d(x, y, z) * MetresPerFoot : null;
}

/// <summary>"RvtIO.Scene" and the version of this assembly without the source revision.</summary>
Expand Down
1 change: 1 addition & 0 deletions src/RvtIO/Internal/ParsingState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ public TfBlockDeserializer.UnitsElemOptions? OwnDocumentUnitOptions
/// the serialized datum text, free end, bubble end and cut vector. The element-level
/// name remains authoritative for the grid mark because datum text may name its head type.</summary>
public Dictionary<uint, GridDatumData> GridDatums { get; } = new();
public (List<Model.GridAxis> Paths, HashSet<int> Members)? GridAxes { get; set; }

/// <summary>Line-style element id for 0x0346 curves whose GStyleElemId was a real id
/// (not -1): these are detail/model lines, keyed by owner eid.</summary>
Expand Down
54 changes: 54 additions & 0 deletions src/RvtIO/Model/GridAxis.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
namespace RvtIO.Model;

/// <summary>A project grid axis, with its authored name and ordered curves in internal feet.</summary>
public sealed class GridAxis
{
internal GridAxis(int id, string name, LocationCurve[] segments)
{
Id = id;
Name = name;
Segments = Array.AsReadOnly(segments);
}

/// <summary>Revit element ID of the grid or multi-segment grid.</summary>
public int Id { get; }
/// <summary>Datum label of the axis.</summary>
public string Name { get; }
/// <summary>Line and circular arc segments in order from the first end to the last.</summary>
public IReadOnlyList<LocationCurve> Segments { get; }

/// <summary>Samples the axis as an ordered polyline in feet, with the requested maximum arc-to-chord error.
/// Returns null if the tolerance would require more than 65,536 vertices or the curve is incomplete.</summary>
public List<double[]>? Tessellate(double maxErrorFeet)
{
if (!double.IsFinite(maxErrorFeet) || maxErrorFeet <= 0)
throw new ArgumentOutOfRangeException(nameof(maxErrorFeet));
const int MaxVertices = 65_536;
var points = new List<double[]> { Segments[0].StartPoint };
foreach (var curve in Segments)
{
if (curve.CurveType == "Arc")
{
if (curve.ArcRadius is not double radius || curve.ArcCenter is not { } center
|| curve.ArcXDirection is not { } x || curve.ArcYDirection is not { } y)
return null;
double start = curve.ArcStartParameter, sweep = curve.ArcEndParameter - start;
double step = 4 * Math.Asin(Math.Sqrt(Math.Min(1, maxErrorFeet / (2 * radius))));
double count = Math.Ceiling(Math.Abs(sweep) / Math.Min(Math.PI / 2, step));
if (!(count >= 1 && count <= MaxVertices - points.Count)) return null;
for (int j = 1; j < (int)count; j++)
points.Add(PointOnArc(center, radius, x, y, start + sweep * j / count));
}
else if (points.Count == MaxVertices)
return null;
points.Add(curve.EndPoint);
}
return points;
}

internal static double[] PointOnArc(double[] center, double radius, double[] x, double[] y, double angle)
{
double cos = Math.Cos(angle) * radius, sin = Math.Sin(angle) * radius;
return [center[0] + cos * x[0] + sin * y[0], center[1] + cos * x[1] + sin * y[1], center[2] + cos * x[2] + sin * y[2]];
}
}
3 changes: 3 additions & 0 deletions src/RvtIO/Model/RevitFileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ public partial class RevitFileInfo
/// <summary>A copy that shares all members with this instance; the caller replaces what it changes.</summary>
internal RevitFileInfo ShallowCopy() => (RevitFileInfo)MemberwiseClone();

internal IReadOnlyList<GridAxis> CurvedGridAxes { get; set; } = [];
internal IReadOnlySet<int>? GridChainMemberIds { get; set; }

/// <summary>The basic file information.</summary>
public FileMetadata Metadata { get; set; } = new();
/// <summary>The project information.</summary>
Expand Down
Loading
Loading