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 @@ -6,6 +6,9 @@ and the project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### Added
- Optional preview projects for reading GLB and OBJ, writing GLB, measuring geometry, checking triangle surface intersections, comparing revisions, querying grids and exporting BCF.

### Changed
- `docs/keys.md`: the namespace `nwc:` is registered for `NwcIO.Scene`; its formats are fixed from the first release of the package, 0.12.0. The `nwc` source format names `NwcIO.Scene` as its producer.

Expand Down
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ dotnet build <other solution> -p:RestoreAdditionalProjectSources=<local-feed>

Do not commit a `nuget.config` that points to a local feed.

`src/IOScene.Formats` and `src/IOCoord` are optional preview projects that consume the public IOScene 0.1 API.
Their tests are in `tests/IOScene.Tools.Tests`. Packing the solution creates local preview packages.
Core release tags publish the IOScene package. The optional previews have their own release setup pending.

## Changing the contract

The rules are in section 5 of [docs/contract.md](docs/contract.md). In short:
Expand Down
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="IOScene" Version="[0.1.0, 0.2.0-0.0)" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.12.0" />
<PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="4.0.1" />
Expand Down
3 changes: 3 additions & 0 deletions IOScene.slnx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<Solution>
<Project Path="src/IOScene/IOScene.csproj" />
<Project Path="src/IOScene.Formats/IOScene.Formats.csproj" />
<Project Path="src/IOCoord/IOCoord.csproj" />
<Project Path="tests/IOScene.Tests/IOScene.Tests.csproj" />
<Project Path="tests/IOScene.Tools.Tests/IOScene.Tools.Tests.csproj" />
</Solution>
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ fills the same lists directly: `Models`, `Geometries`, `Elements`, `Instances`,
- [docs/contract.md][contract]: purpose and invariants, every type, the decisions behind them, what is left out,
how the contract changes, the file format, the validation codes and the unit grammar.
- [docs/keys.md][keys]: the registry of property key namespaces and `SourceFormat` values.
- [Optional tools](docs/tools.md) describes format conversion and coordination built on IOScene.
- [CHANGELOG.md][changelog], [CONTRIBUTING.md][contributing] and [SECURITY.md][security].

## License
Expand Down
70 changes: 70 additions & 0 deletions docs/tools.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Optional IOScene tools

`IOScene.Formats` and `IOCoord` consume the public IOScene 0.1 API. They ship separately from the scene contract
and do not depend on a source-format engine. Both are available as local preview packages from this solution.

## GLB and OBJ

```csharp
using IOScene;
using IOScene.Formats;

var scene = SceneJson.Load("model.scene.json");
GlbSceneWriter.Save(scene, "model.glb");
```

`GlbSceneReader.Load` reads embedded float32 positions and normals, unsigned indices and base material colours.
It flattens the node placements into one model and imports triangle, line and point primitives. Files declaring
required glTF extensions are rejected. The OBJ reader `ObjSceneReader.Load` groups faces by object and assumes
metres with Z up.

The writer emits [glTF 2.0 binary](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html) with the element tree,
indexed and non-indexed triangles, lines and points, shared mesh buffers, and placements with rotation, translation,
scale or reflection. The scene root rotates the metre-based geometry from Z up to glTF Y up. Materials carry
linear base colours, opacity and PBR factors. PNG and JPEG textures are embedded with their UV repeat scales.

The output contains geometry, transforms, appearance, element names, source ids and IFC GlobalIds.
The IOScene file is the source for property sets, schedules, saved viewpoints and clash results. The writer rejects
sheared placements, textures without UVs and coordinates outside the float32 range. It omits normals when a geometry
carries a degenerate normal so readers can generate their own.

## Measurements

```csharp
using IOCoord;
using IOScene;

var scene = SceneJson.Load("model.scene.json");
var measurement = SceneMeasure.PointToElement(scene, elementId: 42, new Vector3d(1, 2, 3));
```

`SceneMeasure` measures distances and path lengths in metres, angles in degrees, and the closest point on the
triangles, lines and points placed for an element. An element without geometry returns null. Element ids are local
to a scene.

## Clash checks, revision comparison, grids and BCF

`SceneClash.FindSurfaceIntersections` tests the placed triangle surfaces of two element selections. Its bounding
box hierarchy narrows the triangle pairs, and a surface check finds a contact point for each intersecting element
pair. It returns a `SceneClashTest` for export or review, with a contact tolerance of one nanometre. Solid
containment, penetration depth and clearance require different queries.

`SceneDiff.Compare` matches elements by model key and source id. It compares names and types, ordered property sets,
and ordered vertices and indices in scene coordinates. It reports elements without an identity separately and refuses
duplicate persistent ids. The comparison uses exact geometry values.

`SceneGrid.NearestLine` and `SceneGrid.NearestIntersection` query axes in the XY plane in metres. These methods use
the coordinates stored in the scene.

`BcfClashWriter.Write` writes existing `SceneClashTest` results as [BCF 2.1](https://github.com/buildingSMART/BCF-XML/blob/release_2_1/Documentation/README.md)
topics. The caller supplies the author and creation timestamp. Components use the scene's IFC GlobalIds. A viewpoint
with components carries selection and visibility. Camera positions and snapshots are outside this initial exporter.

## Preview packages

```sh
dotnet pack IOScene.slnx -c Release -o ./artifacts
```

This builds the core and both optional preview packages for local testing. Existing RvtIO, NwcIO and viewer commands
continue to use their current implementations while replacement coverage is developed and verified.
85 changes: 85 additions & 0 deletions src/IOCoord/BcfClashWriter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System.IO.Compression;
using System.Xml;
using System.Xml.Linq;
using IOScene;

namespace IOCoord;

/// <summary>Writes IOScene clash results as buildingSMART BCF 2.1 topics.</summary>
public static class BcfClashWriter
{
/// <summary>Writes a BCFZIP archive with one topic per clash. The output stream remains open.</summary>
/// <param name="scene">Scene containing the results and the corresponding IFC GlobalIds.</param>
/// <param name="output">Writable stream.</param>
/// <param name="author">BCF creation author.</param>
/// <param name="createdAt">Creation timestamp for the exported topics.</param>
public static void Write(SceneDocument scene, Stream output, string author, DateTimeOffset createdAt)
{
ArgumentNullException.ThrowIfNull(scene);
ArgumentNullException.ThrowIfNull(output);
ArgumentException.ThrowIfNullOrWhiteSpace(author);
XmlConvert.VerifyXmlChars(author);
if (scene.Validate().FirstOrDefault(issue => issue.Severity == SceneSeverity.Error) is { } error)
throw new InvalidDataException($"Invalid scene ({error.Code}): {error.Message}");

var elements = scene.Elements.ToDictionary(element => element.Id);
using var zip = new ZipArchive(output, ZipArchiveMode.Create, leaveOpen: true);
WriteXml(zip, "bcf.version", new XElement("Version", new XAttribute("VersionId", "2.1")));
foreach (var test in scene.ClashTests)
{
foreach (var clash in test.Clashes)
{
string topicId = Guid.NewGuid().ToString("D");
string folder = topicId + "/";
zip.CreateEntry(folder, CompressionLevel.NoCompression);

SceneElement? first = clash.Element1Id is long firstId ? elements[firstId] : null;
SceneElement? second = clash.Element2Id is long secondId ? elements[secondId] : null;
var topic = new XElement("Topic",
new XAttribute("Guid", topicId),
new XAttribute("TopicType", "Clash"),
new XAttribute("TopicStatus", clash.Status.ToString()),
new XElement("Title", string.IsNullOrWhiteSpace(clash.Name) ? test.Name : clash.Name),
new XElement("CreationDate", XmlConvert.ToString(createdAt.UtcDateTime, XmlDateTimeSerializationMode.Utc)),
new XElement("CreationAuthor", author),
new XElement("Description", Describe(test, clash, first, second)));
var markup = new XElement("Markup", topic);

var ids = new[] { first?.IfcGuid, second?.IfcGuid }.Where(IsIfcGuid).Distinct(StringComparer.Ordinal).ToArray();
if (ids.Length != 0)
{
string viewpointId = Guid.NewGuid().ToString("D");
markup.Add(new XElement("Viewpoints", new XAttribute("Guid", viewpointId),
new XElement("Viewpoint", "viewpoint.bcfv")));
WriteXml(zip, folder + "viewpoint.bcfv", new XElement("VisualizationInfo",
new XAttribute("Guid", viewpointId),
new XElement("Components",
new XElement("Selection", ids.Select(id => new XElement("Component", new XAttribute("IfcGuid", id!)))),
new XElement("Visibility", new XAttribute("DefaultVisibility", true)))));
}
WriteXml(zip, folder + "markup.bcf", markup);
}
}
}

private static string Describe(SceneClashTest test, SceneClashResult clash, SceneElement? first, SceneElement? second)
{
string a = string.IsNullOrEmpty(clash.Element1Name) ? first?.Name ?? string.Empty : clash.Element1Name;
string b = string.IsNullOrEmpty(clash.Element2Name) ? second?.Name ?? string.Empty : clash.Element2Name;
string location = FormattableString.Invariant(
$"{test.Name}\n{a} / {b}\nPoint (m): {clash.Point.X:R}, {clash.Point.Y:R}, {clash.Point.Z:R}");
return clash.Distance is double distance
? location + FormattableString.Invariant($"\nDistance (m): {distance:R}")
: location;
}

private static bool IsIfcGuid(string? value) =>
value is { Length: 22 } && value[0] is >= '0' and <= '3'
&& value.All(c => char.IsAsciiLetterOrDigit(c) || c is '_' or '$');

private static void WriteXml(ZipArchive zip, string path, XElement root)
{
using var stream = zip.CreateEntry(path).Open();
root.Save(stream, SaveOptions.DisableFormatting);
}
}
18 changes: 18 additions & 0 deletions src/IOCoord/IOCoord.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>0.1.0-preview.1</Version>
<PackageId>IOCoord</PackageId>
<Description>Measurements, triangle clash checks, revision comparison, grid queries and BCF export for IOScene models.</Description>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<!-- NU5104 reports the prerelease bound that excludes IOScene 0.2 previews. -->
<NoWarn>$(NoWarn);NU5104</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="IOScene" />
<None Remove="$(MSBuildProjectDirectory)/icon.png" />
<None Include="..\IOScene\icon.png" Pack="true" PackagePath="/" Visible="false" />
</ItemGroup>

</Project>
Loading
Loading