From 67e3adc04ab5d033b47e582d59d14820600130a0 Mon Sep 17 00:00:00 2001 From: mahach666 <79989386+mahach666@users.noreply.github.com> Date: Wed, 25 Nov 2026 18:52:16 +0300 Subject: [PATCH] Exclude model-group topography from scene meshes --- docs/public-api.md | 8 ++++---- src/RvtIO/Ifc/IfcExporter.cs | 5 +---- src/RvtIO/Meshes/ElementMeshes.cs | 3 ++- src/RvtIO/Model/ProductRules.cs | 8 ++++++++ tests/RvtIO.Tests/ElementMeshesTests.cs | 19 +++++++++++++++++++ 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/docs/public-api.md b/docs/public-api.md index 296e5736..443fd10e 100644 --- a/docs/public-api.md +++ b/docs/public-api.md @@ -213,10 +213,10 @@ instance included, gets its own triangles. The shared symbol triangles keep the faces reverses the winding of a placement with a negative determinant. The own triangles of an element, those of a mirrored instance included, are wound around the normals of their faces. -The drawable elements follow a subset of the product rules of the IFC export of the current profile, and the materials and the -hidden Geometry nodes follow its rules: they are listed in the documentation comment of `ElementMeshes`, with the product rules -that are not applied (the "export to IFC" flag, topography, walls that are not visible and others), so the meshes can include -elements that the IFC leaves out. Curved surfaces are the dense polygons the reader decodes for them. +The drawable elements follow a subset of the product rules of the current IFC profile, including exclusion of topography stored +in model-group definitions. `ElementMeshes` documents these rules, its material and hidden Geometry node handling, and IFC +rules specific to export, such as the export flag and assembly of the site. Curved surfaces are the dense polygons the reader +decodes for them. ## Writing and save-as diff --git a/src/RvtIO/Ifc/IfcExporter.cs b/src/RvtIO/Ifc/IfcExporter.cs index a711e6d5..73836194 100644 --- a/src/RvtIO/Ifc/IfcExporter.cs +++ b/src/RvtIO/Ifc/IfcExporter.cs @@ -523,10 +523,7 @@ private void ExportDocument(RevitFileInfo info, TextWriter output) var elementByIdForTerrain = info.Elements.GroupBy(element => element.Id) .ToDictionary(group => group.Key, group => group.First()); var groupDefinitionTopographyIds = info.Elements - .Where(element => element.CategoryId == -2001340 - && (element.References ?? Enumerable.Empty()).Any(referenceId => - elementByIdForTerrain.TryGetValue(referenceId, out var referenced) - && referenced.CategoryId == -2000095)) + .Where(element => ProductRules.IsGroupDefinitionTopography(element, elementByIdForTerrain)) .Select(element => element.Id).ToHashSet(); var placedTopographies = info.Elements .Where(element => element.CategoryId == -2001340 diff --git a/src/RvtIO/Meshes/ElementMeshes.cs b/src/RvtIO/Meshes/ElementMeshes.cs index b4c9aab4..c697e4e8 100644 --- a/src/RvtIO/Meshes/ElementMeshes.cs +++ b/src/RvtIO/Meshes/ElementMeshes.cs @@ -22,7 +22,7 @@ namespace RvtIO.Meshes; /// elements are listed themselves; a placement of a drawable element is likewise left out of an element's placements. A /// drawable element is listed when it has a geometry record, or, in a document whose geometry was not decoded, a bounding box. /// Other product rules of the IFC export are not applied, so the meshes can include elements that the IFC leaves out: the -/// "export to IFC" flag, topography, walls that are not visible, curtain panels that are walls, family instances whose level is +/// "export to IFC" flag, IFC site assembly, walls that are not visible, curtain panels that are walls, family instances whose level is /// not a project level, curtain children without bounds, openings of hidden walls, and the rebar rules. /// Faces of Geometry nodes that Revit does not take (another detail level) are left out when the element has faces of /// nodes it takes and no ghost node (a node Revit exports that has no decoded polygon, which also makes the element @@ -255,6 +255,7 @@ private static bool DropsUntakenNodes(IReadOnlyList faces, bool hasGhos || designOptions.InNonPrimaryOption(element) == true || phaseFilter?.Excludes(element) == true || element.CategoryId == RevealsCategoryId || ProductRules.IsWallRectangularOpening(element) || ProductRules.IsValidatedStackedWallContainer(element, elementsById) + || ProductRules.IsGroupDefinitionTopography(element, elementsById) || info.ElemTableIsExact && element.IsDiscovered || element.SerializedFamilyId is > 0 || (!modelLine && !areaReinforcement && ProductRules.IsNonPhysicalCategory(element.Category))) diff --git a/src/RvtIO/Model/ProductRules.cs b/src/RvtIO/Model/ProductRules.cs index 09b2cdbc..e0292af5 100644 --- a/src/RvtIO/Model/ProductRules.cs +++ b/src/RvtIO/Model/ProductRules.cs @@ -1,3 +1,5 @@ +using RvtIO.BuiltIns; + namespace RvtIO.Model; /// @@ -79,6 +81,12 @@ internal static bool IsNonPhysicalCategory(string? category) internal static bool IsWallRectangularOpening(Element element) => element.Category?.Contains("OST_SWallRectOpening", StringComparison.OrdinalIgnoreCase) == true; + /// Topography stored with a model-group definition rather than placed on the site. + internal static bool IsGroupDefinitionTopography(Element element, IReadOnlyDictionary elementsById) => + element.CategoryId == (int)BuiltInCategory.OST_Topography + && element.References?.Any(id => elementsById.TryGetValue(id, out var referenced) + && referenced.CategoryId == (int)BuiltInCategory.OST_IOSModelGroups) == true; + /// A StackedWall parent, whose member walls are the products; not its source record or children. internal static bool IsValidatedStackedWallContainer( Element element, IReadOnlyDictionary elementsById) => diff --git a/tests/RvtIO.Tests/ElementMeshesTests.cs b/tests/RvtIO.Tests/ElementMeshesTests.cs index 740fd8b5..ca3fb7dd 100644 --- a/tests/RvtIO.Tests/ElementMeshesTests.cs +++ b/tests/RvtIO.Tests/ElementMeshesTests.cs @@ -1,4 +1,5 @@ using System.Runtime.CompilerServices; +using RvtIO.BuiltIns; using RvtIO.Internal; using RvtIO.Meshes; using RvtIO.Model; @@ -667,6 +668,24 @@ public void DefinitionsAndContainers_AreNotListed() Assert.Equal([1, 6], set.Elements.Select(element => element.ElementId)); } + [Fact] + public void GroupDefinitionTopography_IsExcludedFromSceneMeshes() + { + static GeometryData Triangle() => new() { Faces = [Face([[0, 0, 0], [1, 0, 0], [1, 1, 0]], [0, 0, 1])] }; + var placed = Product(1, Triangle()); + placed.CategoryId = (int)BuiltInCategory.OST_Topography; + var groupTerrain = Product(2, Triangle()); + groupTerrain.CategoryId = placed.CategoryId; + groupTerrain.References = [4]; + var groupMember = Product(3, Triangle()); + groupMember.References = [4]; + var groupType = new Element { Id = 4, CategoryId = (int)BuiltInCategory.OST_IOSModelGroups }; + + var set = ElementMeshes.Extract(Document(placed, groupTerrain, groupMember, groupType)); + + Assert.Equal([1, 3], set.Elements.Select(element => element.ElementId)); + } + [Fact] public void PlacementOfADrawableElement_IsLeftToThatElement() {