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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ All notable changes to the `IfcIO` library are documented in this file.
## [Unreleased]

### Fixed
- Boolean import preserves nested operands and evaluates chains of plane clips. It reports skipped bounded
half-spaces and Boolean operations not evaluated in the mesh, and rejects cyclic or excessive trees.
- Swept-solid import applies the profile, solid and object placements to inclined extrusions, revolutions and
both Boolean operands. IFC re-export preserves world placement and multiple swept body items when a single
parametric solid cannot represent the result. Mesh export distinguishes open surfaces from closed shells.
Expand Down
3 changes: 3 additions & 0 deletions docs/public-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ Imported meshes use world coordinates. If a swept body cannot be represented by
solid, the reader keeps its placed mesh instead; IFC export writes that mesh rather than a partial or
misplaced solid. Boolean operands also use placed meshes where necessary. Applying arbitrary solid-to-solid
Boolean operations to the mesh is not supported; the mesher clips against half-spaces only.
Nested plane clips trim the existing mesh faces in order; they do not add faces on the cut planes.
`IfcModel.BooleanImportWarnings` lists skipped operands (including polygonal bounded half-spaces) and
operations not evaluated in the mesh. These diagnostics refer to the source IFC, including after extraction.
IFC export rejects compound Boolean bodies and Boolean results with missing operands rather than
writing a mesh that drops the operations or an invalid STEP reference.

Expand Down
15 changes: 11 additions & 4 deletions src/IfcIO.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private static int ExecuteInfo(string[] args)

var sw = Stopwatch.StartNew();
var model = IfcModel.Open(inputPath);
WarnOnPartialIfc4x3Import(model);
WarnOnPartialImport(model);
sw.Stop();

int elementCount = 0;
Expand Down Expand Up @@ -322,7 +322,7 @@ private static int ExecuteExport(string[] args)
Console.Error.WriteLine("Error: IFC4X3 is supported for subset import only. Rewriting it as IFC is not supported.");
return 1;
}
WarnOnPartialIfc4x3Import(model);
WarnOnPartialImport(model);
if (schemaOpt is { } requested) model.Schema = requested;

if (glbPath is not null)
Expand Down Expand Up @@ -658,8 +658,10 @@ private static string PhysicalPath(string path)
};
}

private static void WarnOnPartialIfc4x3Import(IfcModel model)
private static void WarnOnPartialImport(IfcModel model)
{
foreach (string warning in model.BooleanImportWarnings)
Console.Error.WriteLine($"Warning: {warning}");
if (model.Schema != IfcSchema.Ifc4x3) return;
Console.Error.WriteLine($"Warning: {model.SourceSchemaIdentifier} is read as a subset. Uninterpreted content is omitted.");
if (model.UnsupportedPlacementCount > 0)
Expand Down Expand Up @@ -762,6 +764,7 @@ private static int ExecutePatch(string[] args)
{
LegacyIfcIoRevolvedAnglesInRadians = args.Contains("--legacy-ifcio-radian-sweeps", StringComparer.OrdinalIgnoreCase),
});
WarnOnPartialImport(model);

if (!string.IsNullOrEmpty(extractQuery))
{
Expand Down Expand Up @@ -1043,10 +1046,12 @@ private static int ExecuteClash(string[] args)
};

var modelA = IfcModel.Open(fileA);
WarnOnPartialImport(modelA);
Clash.IfcClashReport report;
if (fileB is not null)
{
var modelB = IfcModel.Open(fileB);
WarnOnPartialImport(modelB);
report = modelA.DetectClashes(modelB, options);
}
else
Expand Down Expand Up @@ -1159,6 +1164,8 @@ private static int ExecuteDiff(string[] args)

var baselineModel = IfcModel.Open(baselineFile);
var revisionModel = IfcModel.Open(revisionFile);
WarnOnPartialImport(baselineModel);
WarnOnPartialImport(revisionModel);
var report = baselineModel.Compare(revisionModel, options);

Console.ForegroundColor = report.TotalChangesCount > 0 ? ConsoleColor.Cyan : ConsoleColor.Green;
Expand Down Expand Up @@ -1206,7 +1213,7 @@ private static int ExecuteView(string[] args)

var sw = Stopwatch.StartNew();
var model = IfcModel.Open(inputPath);
WarnOnPartialIfc4x3Import(model);
WarnOnPartialImport(model);

if (gridsPath is not null)
{
Expand Down
37 changes: 26 additions & 11 deletions src/IfcIO/Geometry/CsgTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,22 @@ public sealed class IfcBooleanResult
public IfcMesh? FirstMesh { get; set; }
public IfcExtrudedAreaSolid? FirstSolid { get; set; }
public IfcRevolvedAreaSolid? FirstRevolved { get; set; }
internal IfcBooleanResult? FirstBoolean { get; set; }

/// <summary>Second operand (clipping half-space, cutting solid, or joining solid).</summary>
public IfcHalfSpaceSolid? SecondHalfSpace { get; set; }
public IfcExtrudedAreaSolid? SecondSolid { get; set; }
/// <summary>Parametric form of a revolved second operand, when representable.</summary>
public IfcRevolvedAreaSolid? SecondRevolved { get; set; }
public IfcMesh? SecondMesh { get; set; }
internal IfcBooleanResult? SecondBoolean { get; set; }

/// <summary>
/// True if this represents an IFCBOOLEANCLIPPINGRESULT (difference with a half-space solid).
/// </summary>
public bool IsClippingResult => Operator == IfcBooleanOperator.Difference
&& SecondHalfSpace is not null && (FirstSolid is not null || FirstRevolved is not null);
&& SecondHalfSpace is not null && (FirstSolid is not null || FirstRevolved is not null
|| FirstBoolean?.IsClippingResult == true);

public IfcBooleanResult() { }

Expand All @@ -119,27 +124,31 @@ public IfcBooleanResult(
/// <summary>
/// Computes the resulting triangulated 3D mesh by applying the CSG clipping operation.
/// </summary>
public IfcMesh ToMesh(string meshName = "BooleanResult")
public IfcMesh ToMesh(string meshName = "BooleanResult") => ToMesh(meshName, null);

internal IfcMesh ToMesh(string meshName, Action<int>? chargeVertices)
{
var baseMesh = FirstMesh ?? FirstSolid?.ToMesh() ?? FirstRevolved?.ToMesh();
var baseMesh = FirstMesh ?? FirstSolid?.ToMesh() ?? FirstRevolved?.ToMesh() ?? FirstBoolean?.ToMesh(meshName, chargeVertices);
if (baseMesh is null)
{
return IfcMesh.Create(0, meshName, Array.Empty<IfcVector3>(), Array.Empty<int>());
}

if (SecondHalfSpace is null)
if (SecondHalfSpace is null || Operator == IfcBooleanOperator.Union)
{
return baseMesh;
}

return ClipMeshByHalfSpace(baseMesh, SecondHalfSpace, meshName);
return ClipMeshByHalfSpace(baseMesh, SecondHalfSpace, Operator == IfcBooleanOperator.Intersection, meshName, chargeVertices);
}

private static IfcMesh ClipMeshByHalfSpace(IfcMesh input, IfcHalfSpaceSolid halfSpace, string meshName)
private static IfcMesh ClipMeshByHalfSpace(
IfcMesh input, IfcHalfSpaceSolid halfSpace, bool keepHalfSpace, string meshName, Action<int>? chargeVertices)
{
var plane = halfSpace.BaseSurface;
var normal = plane.Normal.Normalized();
if (!halfSpace.AgreementFlag) normal = -normal;
// IFC AgreementFlag=true places the material opposite the normal.
if (halfSpace.AgreementFlag == keepHalfSpace) normal = -normal;

// Plane equation: N . X + d = 0
double planeD = -IfcVector3.Dot(normal, plane.Location);
Expand Down Expand Up @@ -174,7 +183,7 @@ private static IfcMesh ClipMeshByHalfSpace(IfcMesh input, IfcHalfSpaceSolid half
if (insideCount == 3)
{
// Entire triangle inside
AddTriangle(outVertices, outIndices, p0, p1, p2);
EmitTriangle(p0, p1, p2);
}
else if (insideCount == 0)
{
Expand Down Expand Up @@ -209,7 +218,7 @@ private static IfcMesh ClipMeshByHalfSpace(IfcMesh input, IfcHalfSpaceSolid half
var i1 = IntersectSegment(vIn, vOut1, dIn, dOut1);
var i2 = IntersectSegment(vIn, vOut2, dIn, dOut2);

AddTriangle(outVertices, outIndices, vIn, i1, i2);
EmitTriangle(vIn, i1, i2);
}
else // insideCount == 2
{
Expand Down Expand Up @@ -239,12 +248,18 @@ private static IfcMesh ClipMeshByHalfSpace(IfcMesh input, IfcHalfSpaceSolid half
var i1 = IntersectSegment(vIn1, vOut, dIn1, dOut);
var i2 = IntersectSegment(vIn2, vOut, dIn2, dOut);

AddTriangle(outVertices, outIndices, vIn1, i1, i2);
AddTriangle(outVertices, outIndices, vIn1, i2, vIn2);
EmitTriangle(vIn1, i1, i2);
EmitTriangle(vIn1, i2, vIn2);
}
}

return IfcMesh.Create(0, meshName, outVertices, outIndices);

void EmitTriangle(IfcVector3 a, IfcVector3 b, IfcVector3 c)
{
chargeVertices?.Invoke(3);
AddTriangle(outVertices, outIndices, a, b, c);
}
}

private static IfcVector3 IntersectSegment(in IfcVector3 a, in IfcVector3 b, double da, double db)
Expand Down
Loading