@bitbybit-dev/ifc 1.5.0 → 1.6.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -5
- package/lib/api/dto-registry.js +3 -1
- package/lib/api/ifc-service.d.ts +10 -5
- package/lib/api/ifc-service.js +7 -5
- package/lib/api/inputs/ifc-inputs.d.ts +121 -5
- package/lib/api/inputs/ifc-inputs.js +162 -5
- package/lib/api/resolved-inputs/index.d.ts +6 -3
- package/lib/api/services/doors.js +4 -1
- package/lib/api/services/elements.d.ts +28 -0
- package/lib/api/services/elements.js +60 -0
- package/lib/api/services/geometry.js +3 -3
- package/lib/api/services/index.d.ts +1 -0
- package/lib/api/services/index.js +1 -0
- package/lib/api/services/member-support.js +2 -2
- package/lib/api/services/model.js +3 -3
- package/lib/api/services/openings.js +16 -11
- package/lib/api/services/properties.js +4 -3
- package/lib/api/services/site.js +3 -1
- package/lib/api/services/spaces.js +1 -0
- package/lib/api/services/walls.d.ts +7 -5
- package/lib/api/services/walls.js +15 -7
- package/lib/api/services/windows.js +5 -2
- package/lib/build/assemblies.js +1 -1
- package/lib/build/bodied-elements.d.ts +5 -0
- package/lib/build/bodied-elements.js +35 -0
- package/lib/build/build-types.d.ts +29 -2
- package/lib/build/checks.d.ts +2 -0
- package/lib/build/checks.js +14 -0
- package/lib/build/clipping-registry.d.ts +3 -0
- package/lib/build/clipping-registry.js +39 -0
- package/lib/build/constants.d.ts +0 -1
- package/lib/build/constants.js +0 -1
- package/lib/build/entity-writer.js +4 -6
- package/lib/build/exact-bodies.d.ts +4 -0
- package/lib/build/exact-bodies.js +273 -0
- package/lib/build/fillings.js +1 -1
- package/lib/build/math.d.ts +3 -2
- package/lib/build/math.js +24 -16
- package/lib/build/measure.js +11 -11
- package/lib/build/moving.js +12 -11
- package/lib/build/openings.js +1 -1
- package/lib/build/outlines.d.ts +2 -0
- package/lib/build/outlines.js +14 -2
- package/lib/build/placement.js +4 -3
- package/lib/build/project.js +1 -1
- package/lib/build/quantities.js +13 -11
- package/lib/build/roof-clipping.js +5 -5
- package/lib/build/roofs.js +17 -16
- package/lib/build/site.js +9 -13
- package/lib/build/slab-openings.js +4 -4
- package/lib/build/slabs-columns-beams.js +16 -19
- package/lib/build/solids.js +3 -2
- package/lib/build/spaces.js +8 -6
- package/lib/build/spatial.js +1 -1
- package/lib/build/wall-edits.js +21 -15
- package/lib/build/wall-geometry.d.ts +2 -1
- package/lib/build/wall-geometry.js +48 -18
- package/lib/build/wall-parameters.js +7 -3
- package/lib/build/walls.js +15 -8
- package/lib/geometry/advanced.js +12 -13
- package/lib/geometry/curves.d.ts +2 -1
- package/lib/geometry/curves.js +27 -10
- package/lib/geometry/edges.js +6 -9
- package/lib/geometry/elements.d.ts +1 -1
- package/lib/geometry/elements.js +22 -5
- package/lib/geometry/exact-brep.constants.d.ts +1 -0
- package/lib/geometry/exact-brep.constants.js +1 -0
- package/lib/geometry/exact-brep.d.ts +11 -0
- package/lib/geometry/exact-brep.js +371 -0
- package/lib/geometry/faceted.d.ts +1 -0
- package/lib/geometry/faceted.js +20 -8
- package/lib/geometry/geometry-types.d.ts +9 -1
- package/lib/geometry/items.d.ts +2 -0
- package/lib/geometry/items.js +34 -5
- package/lib/geometry/operators.js +1 -1
- package/lib/geometry/profiles.js +9 -5
- package/lib/geometry/surfaces.constants.d.ts +1 -0
- package/lib/geometry/surfaces.constants.js +1 -0
- package/lib/geometry/surfaces.d.ts +1 -1
- package/lib/geometry/surfaces.js +8 -6
- package/lib/geometry/swept-solids.constants.d.ts +1 -0
- package/lib/geometry/swept-solids.constants.js +1 -0
- package/lib/geometry/swept-solids.js +22 -12
- package/lib/model/io.js +1 -1
- package/lib/model/owner-history.d.ts +2 -0
- package/lib/model/owner-history.js +101 -0
- package/lib/model/snapshot.d.ts +1 -0
- package/lib/model/snapshot.js +4 -0
- package/lib/model/transaction.js +19 -10
- package/lib/model/upgrade-rows.d.ts +26 -0
- package/lib/model/upgrade-rows.js +240 -0
- package/lib/model/upgrade-types.d.ts +9 -0
- package/lib/model/upgrade-types.js +1 -0
- package/lib/model/upgrade.js +20 -7
- package/lib/schema/registry.js +1 -1
- package/package.json +2 -3
package/lib/geometry/advanced.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { squareFrame } from "@bitbybit-dev/base/lib/api/services/helpers/frame-axes";
|
|
2
|
-
import { refinedSurfaceMesh } from "@bitbybit-dev/base/lib/api/services/helpers/surface-triangulation";
|
|
3
|
-
import { newellNormal } from "@bitbybit-dev/base/lib/api/services/helpers/triangulation";
|
|
4
|
-
import { cross3, dot3, length3, subtract3 } from "@bitbybit-dev/base/lib/api/services/helpers/vectors";
|
|
1
|
+
import { squareFrame, unitOf } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/frame-axes";
|
|
2
|
+
import { refinedSurfaceMesh } from "@bitbybit-dev/base/lib/api/services/helpers/curves/surface-triangulation";
|
|
3
|
+
import { newellNormal } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/triangulation";
|
|
4
|
+
import { between2, cross3, distance2, dot3, length3, subtract3 } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/vectors";
|
|
5
|
+
import { angleOfCosine } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/scalars";
|
|
5
6
|
import { isList, isReference } from "../step/values";
|
|
6
7
|
import { UnsupportedGeometryError } from "./errors";
|
|
7
|
-
import { CUT_SAMPLES, CUT_TURN, FIT_PROBES, FIT_TOLERANCE, MIN_LOOP_POINTS, NORMAL_STEP, TRIANGLE_CORNERS } from "./surfaces.constants";
|
|
8
|
+
import { CUT_SAMPLES, CUT_SLACK, CUT_TURN, FIT_PROBES, FIT_TOLERANCE, MIN_LOOP_POINTS, NORMAL_STEP, TRIANGLE_CORNERS } from "./surfaces.constants";
|
|
8
9
|
import { parametricSurface, plane } from "./surfaces";
|
|
9
10
|
const OUTER_BOUND = "IfcFaceOuterBound";
|
|
10
11
|
const FACE_SURFACE = "IfcFaceSurface";
|
|
@@ -192,7 +193,7 @@ export class AdvancedFaces {
|
|
|
192
193
|
const closing = shift(start, first.winding[axis] * period);
|
|
193
194
|
const distances = second.uv.map((point) => {
|
|
194
195
|
const aligned = unwrapped(point[axis], closing[axis], period);
|
|
195
|
-
return
|
|
196
|
+
return distance2([aligned, point[1 - axis]], [closing[axis], closing[1 - axis]]);
|
|
196
197
|
});
|
|
197
198
|
const join = distances.indexOf(Math.min(...distances));
|
|
198
199
|
const turned = [...second.uv.slice(join), ...second.uv.slice(0, join)];
|
|
@@ -237,22 +238,20 @@ export class AdvancedFaces {
|
|
|
237
238
|
};
|
|
238
239
|
}
|
|
239
240
|
across(surface, from, to) {
|
|
240
|
-
const at = (t) =>
|
|
241
|
+
const at = (t) => between2(from, to, t);
|
|
241
242
|
let turned = 0;
|
|
242
243
|
let previous;
|
|
243
244
|
for (let step = 0; step <= CUT_SAMPLES; step++) {
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
if (!(length > 0)) {
|
|
245
|
+
const unit = unitOf(this.surfaceNormal(surface, at(step / CUT_SAMPLES)));
|
|
246
|
+
if (unit === undefined) {
|
|
247
247
|
continue;
|
|
248
248
|
}
|
|
249
|
-
const unit = [normal[0] / length, normal[1] / length, normal[2] / length];
|
|
250
249
|
if (previous) {
|
|
251
|
-
turned +=
|
|
250
|
+
turned += angleOfCosine(dot3(previous, unit));
|
|
252
251
|
}
|
|
253
252
|
previous = unit;
|
|
254
253
|
}
|
|
255
|
-
const segments = Math.min(CUT_SAMPLES, Math.max(1, Math.ceil(turned / CUT_TURN)));
|
|
254
|
+
const segments = Math.min(CUT_SAMPLES, Math.max(1, Math.ceil(turned / CUT_TURN - CUT_SLACK)));
|
|
256
255
|
const uv = Array.from({ length: segments - 1 }, (_, step) => at((step + 1) / segments));
|
|
257
256
|
return { uv, points: uv.map(([u, v]) => surface.point(u, v)) };
|
|
258
257
|
}
|
package/lib/geometry/curves.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Base } from "@bitbybit-dev/base";
|
|
2
|
-
import { type FrameAxes } from "@bitbybit-dev/base/lib/api/services/helpers/frame-axes";
|
|
2
|
+
import { type FrameAxes } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/frame-axes";
|
|
3
3
|
import type { ModelSnapshot } from "../model/snapshot";
|
|
4
4
|
import type { BSplineCurve, ConicFrame } from "./geometry-types";
|
|
5
5
|
export declare function arcSegments(sweep: number): number;
|
|
@@ -13,6 +13,7 @@ export declare class CurveSampler {
|
|
|
13
13
|
path(curve: number): Base.Point3[];
|
|
14
14
|
endTangents(curve: number, depth?: number): readonly [Base.Vector3 | undefined, Base.Vector3 | undefined];
|
|
15
15
|
parameterSpan(curve: number): number | undefined;
|
|
16
|
+
lengthSpan(curve: number): number | undefined;
|
|
16
17
|
planeOf(curve: number): FrameAxes | undefined;
|
|
17
18
|
private get radiansPerUnit();
|
|
18
19
|
private sampled;
|
package/lib/geometry/curves.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { arcThroughThreePoints, pointsOnArc } from "@bitbybit-dev/base/lib/api/services/helpers/arcs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { arcThroughThreePoints, pointsOnArc } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/arcs";
|
|
2
|
+
import { pathLength3 } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/paths";
|
|
3
|
+
import { pointToLocal, squareFrame } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/frame-axes";
|
|
4
|
+
import { expandedKnots, knotDomain, nurbsCurvePoint } from "@bitbybit-dev/base/lib/api/services/helpers/curves/nurbs";
|
|
5
|
+
import { newellNormal } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/triangulation";
|
|
6
|
+
import { add3, dot3, length3, scale3, subtract3 } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/vectors";
|
|
6
7
|
import { axisPlacementFrame, directionOf, numbersOf, pointOf } from "../build/placement";
|
|
7
8
|
import { radiansPerUnit } from "../build/project";
|
|
8
9
|
import { isEnumeration, isList, isReference, isTyped } from "../step/values";
|
|
@@ -128,6 +129,23 @@ export class CurveSampler {
|
|
|
128
129
|
const sweep = sweepBetween(first.parameter * this.radiansPerUnit, second.parameter * this.radiansPerUnit, forward);
|
|
129
130
|
return Math.abs(sweep) / this.radiansPerUnit;
|
|
130
131
|
}
|
|
132
|
+
lengthSpan(curve) {
|
|
133
|
+
const type = this.model.entity(curve).type;
|
|
134
|
+
if (type === "IfcPolyline") {
|
|
135
|
+
return pathLength3(this.polylinePoints(curve));
|
|
136
|
+
}
|
|
137
|
+
const basis = type === "IfcTrimmedCurve" ? this.model.attribute(curve, "BasisCurve") : null;
|
|
138
|
+
if (!isReference(basis)) {
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
const basisType = this.model.entity(basis.ref).type;
|
|
142
|
+
if (basisType === "IfcLine") {
|
|
143
|
+
return pathLength3(this.trimmed(curve));
|
|
144
|
+
}
|
|
145
|
+
const radius = basisType === "IfcCircle" ? this.model.attribute(basis.ref, "Radius") : null;
|
|
146
|
+
const turn = this.parameterSpan(curve);
|
|
147
|
+
return typeof radius === "number" && turn !== undefined ? radius * turn * this.radiansPerUnit : undefined;
|
|
148
|
+
}
|
|
131
149
|
planeOf(curve) {
|
|
132
150
|
if (this.model.entity(curve).type !== "IfcPolyline") {
|
|
133
151
|
return undefined;
|
|
@@ -289,19 +307,18 @@ export class CurveSampler {
|
|
|
289
307
|
if (trim.point !== undefined && !(byParameter && trim.parameter !== undefined)) {
|
|
290
308
|
return trim.point;
|
|
291
309
|
}
|
|
292
|
-
const
|
|
310
|
+
const point = pointOf(this.model, this.model.attribute(line, "Pnt"));
|
|
293
311
|
const vector = this.model.attribute(line, "Dir");
|
|
294
312
|
if (!isReference(vector)) {
|
|
295
313
|
throw new UnsupportedGeometryError(`#${line} has no direction`);
|
|
296
314
|
}
|
|
297
|
-
const
|
|
315
|
+
const direction = directionOf(this.model, this.model.attribute(vector.ref, "Orientation"), [1, 0, 0]);
|
|
298
316
|
const magnitude = this.model.attribute(vector.ref, "Magnitude");
|
|
299
|
-
const length =
|
|
317
|
+
const length = length3(direction);
|
|
300
318
|
if (typeof magnitude !== "number" || !(length > 0)) {
|
|
301
319
|
throw new UnsupportedGeometryError(`#${vector.ref} has no direction or no magnitude`);
|
|
302
320
|
}
|
|
303
|
-
|
|
304
|
-
return [x + dx * step, y + dy * step, z + dz * step];
|
|
321
|
+
return add3(point, scale3(direction, trim.parameter * magnitude / length));
|
|
305
322
|
}
|
|
306
323
|
conicAngle(conic, trim, byParameter) {
|
|
307
324
|
if (trim.parameter !== undefined && (byParameter || trim.point === undefined)) {
|
package/lib/geometry/edges.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { knotDomain, nurbsCurvePoint } from "@bitbybit-dev/base/lib/api/services/helpers/nurbs";
|
|
2
|
-
import { add3, dot3, length3, scale3, subtract3 } from "@bitbybit-dev/base/lib/api/services/helpers/vectors";
|
|
1
|
+
import { knotDomain, nurbsCurvePoint } from "@bitbybit-dev/base/lib/api/services/helpers/curves/nurbs";
|
|
2
|
+
import { add3, distance3, dot3, length3, scale3, subtract3 } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/vectors";
|
|
3
3
|
import { numbersOf } from "../build/placement";
|
|
4
4
|
import { isReference } from "../step/values";
|
|
5
5
|
import { arcSegments, sweepBetween } from "./curves";
|
|
@@ -8,11 +8,8 @@ import { referencesIn } from "./references";
|
|
|
8
8
|
import { CLOSED_EDGE_RATIO, GOLDEN_SECTION, PARAMETER_SEARCH_STEPS, PARAMETER_SEARCH_TOLERANCE, WEIGHTED_POINTS_RATIO } from "./edges.constants";
|
|
9
9
|
const CURVE_ON_SURFACE = new Set(["IfcSurfaceCurve", "IfcIntersectionCurve", "IfcSeamCurve"]);
|
|
10
10
|
const SPLINES = new Set(["IfcBSplineCurveWithKnots", "IfcRationalBSplineCurveWithKnots"]);
|
|
11
|
-
function distance(a, b) {
|
|
12
|
-
return length3(subtract3(a, b));
|
|
13
|
-
}
|
|
14
11
|
function nearestParameter(spline, point, from, to) {
|
|
15
|
-
const at = (t) =>
|
|
12
|
+
const at = (t) => distance3(nurbsCurvePoint(spline.degree, spline.points, spline.weights, spline.knots, t), point);
|
|
16
13
|
let best = from;
|
|
17
14
|
let bestDistance = Infinity;
|
|
18
15
|
for (let step = 0; step <= PARAMETER_SEARCH_STEPS; step++) {
|
|
@@ -101,7 +98,7 @@ export class EdgeSampler {
|
|
|
101
98
|
return this.spline(curve, start, end, sameSense);
|
|
102
99
|
}
|
|
103
100
|
const path = this.curves.path(curve);
|
|
104
|
-
const forward =
|
|
101
|
+
const forward = distance3(path[0], start) + distance3(path[path.length - 1], end) <= distance3(path[0], end) + distance3(path[path.length - 1], start);
|
|
105
102
|
return forward ? path : [...path].reverse();
|
|
106
103
|
}
|
|
107
104
|
conic(conic, start, end, sameSense) {
|
|
@@ -121,7 +118,7 @@ export class EdgeSampler {
|
|
|
121
118
|
spline(curve, start, end, sameSense) {
|
|
122
119
|
const spline = this.meetingVertices(this.curves.bspline(curve), start, end);
|
|
123
120
|
const [from, to] = knotDomain(spline.degree, spline.knots);
|
|
124
|
-
const closed =
|
|
121
|
+
const closed = distance3(start, end) <= CLOSED_EDGE_RATIO * Math.max(1, length3(start));
|
|
125
122
|
if (closed) {
|
|
126
123
|
return this.curves.splinePoints(spline, sameSense ? from : to, sameSense ? to : from);
|
|
127
124
|
}
|
|
@@ -135,7 +132,7 @@ export class EdgeSampler {
|
|
|
135
132
|
const misses = (candidate) => {
|
|
136
133
|
const [from, to] = knotDomain(candidate.degree, candidate.knots);
|
|
137
134
|
const [first, last] = [from, to].map((t) => nurbsCurvePoint(candidate.degree, candidate.points, candidate.weights, candidate.knots, t));
|
|
138
|
-
return Math.min(
|
|
135
|
+
return Math.min(distance3(first, start) + distance3(last, end), distance3(first, end) + distance3(last, start));
|
|
139
136
|
};
|
|
140
137
|
if (misses(spline) <= reach) {
|
|
141
138
|
return spline;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ModelSnapshot } from "../model/snapshot";
|
|
2
2
|
import type { ModelRecipe } from "./geometry-types";
|
|
3
|
-
export declare function modelRecipe(model: ModelSnapshot, globalIds: readonly string[] | undefined, millimetresPerUnit: number, fallbackTolerance: number, isGroupedByClass?: boolean): ModelRecipe;
|
|
3
|
+
export declare function modelRecipe(model: ModelSnapshot, globalIds: readonly string[] | undefined, millimetresPerUnit: number, fallbackTolerance: number, isGroupedByClass?: boolean, withPropertySets?: boolean): ModelRecipe;
|
package/lib/geometry/elements.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { axesToMatrix, relativeAxes } from "@bitbybit-dev/base/lib/api/services/helpers/frame-axes";
|
|
1
|
+
import { axesToMatrix, relativeAxes } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/frame-axes";
|
|
2
2
|
import { absoluteFrame, objectPlacementOf } from "../build/placement";
|
|
3
|
+
import { propertySetsOf } from "../build/properties";
|
|
3
4
|
import { isList, isReference } from "../step/values";
|
|
4
5
|
import { colourOf } from "./colours";
|
|
5
6
|
import { ItemConverter } from "./items";
|
|
@@ -11,6 +12,8 @@ const VOIDS = "IfcRelVoidsElement";
|
|
|
11
12
|
const MODEL_CONTEXT = "Model";
|
|
12
13
|
const SUB_CONTEXT = "IfcGeometricRepresentationSubContext";
|
|
13
14
|
const REACH_MILLIMETRES = 1e6;
|
|
15
|
+
const FINEST_PRECISION_MILLIMETRES = 0.01;
|
|
16
|
+
const COARSEST_PRECISION_MILLIMETRES = 1;
|
|
14
17
|
const NO_BODY = `The element has no '${BODY}' representation in a '${MODEL_CONTEXT}' context`;
|
|
15
18
|
const SKIPPED = {
|
|
16
19
|
IfcOpeningElement: "is cut from the element it voids, not described on its own",
|
|
@@ -86,7 +89,7 @@ function productsOf(model, wanted) {
|
|
|
86
89
|
function frameOf(model, product, known) {
|
|
87
90
|
return absoluteFrame(model, objectPlacementOf(model, product), known);
|
|
88
91
|
}
|
|
89
|
-
function
|
|
92
|
+
function declaredPrecision(model, fallback) {
|
|
90
93
|
for (const context of model.byType("IfcGeometricRepresentationContext", false)) {
|
|
91
94
|
const precision = model.attribute(context.id, "Precision");
|
|
92
95
|
if (model.attribute(context.id, "ContextType") === MODEL_CONTEXT && typeof precision === "number" && precision > 0) {
|
|
@@ -95,7 +98,20 @@ function precisionOf(model, fallback) {
|
|
|
95
98
|
}
|
|
96
99
|
return fallback;
|
|
97
100
|
}
|
|
98
|
-
|
|
101
|
+
function precisionOf(model, fallback, millimetresPerUnit) {
|
|
102
|
+
const declared = declaredPrecision(model, fallback);
|
|
103
|
+
return Math.min(Math.max(declared, FINEST_PRECISION_MILLIMETRES / millimetresPerUnit), COARSEST_PRECISION_MILLIMETRES / millimetresPerUnit);
|
|
104
|
+
}
|
|
105
|
+
function propertyTags(model, product) {
|
|
106
|
+
const tags = {};
|
|
107
|
+
for (const set of propertySetsOf(model, product)) {
|
|
108
|
+
for (const [property, value] of Object.entries(set.properties)) {
|
|
109
|
+
tags[`${set.name}.${property}`] = value;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return tags;
|
|
113
|
+
}
|
|
114
|
+
export function modelRecipe(model, globalIds, millimetresPerUnit, fallbackTolerance, isGroupedByClass = true, withPropertySets = false) {
|
|
99
115
|
var _a, _b;
|
|
100
116
|
const builder = new RecipeBuilder();
|
|
101
117
|
const groups = new RecipeGroups(model, isGroupedByClass);
|
|
@@ -139,14 +155,15 @@ export function modelRecipe(model, globalIds, millimetresPerUnit, fallbackTolera
|
|
|
139
155
|
const name = model.attribute(product.id, "Name");
|
|
140
156
|
const material = parts.some((part) => !part.rgba) ? colourOf(model, colours, product.id) : undefined;
|
|
141
157
|
const group = groups.groupOf(product.id);
|
|
158
|
+
const properties = withPropertySets ? propertyTags(model, product.id) : {};
|
|
142
159
|
for (const part of parts) {
|
|
143
160
|
const rgba = (_b = part.rgba) !== null && _b !== void 0 ? _b : material;
|
|
144
|
-
builder.root(Object.assign({ node: cuts.length ? builder.node({ op: "voids", host: part.node, openings: cuts }) : part.node, matrix: axesToMatrix(frame), tag: Object.assign({ globalId, type: product.type, name: typeof name === "string" ? name : "" }, (rgba ? { rgba: [...rgba] } : {})) }, (group === undefined ? {} : { group })));
|
|
161
|
+
builder.root(Object.assign({ node: cuts.length ? builder.node({ op: "voids", host: part.node, openings: cuts }) : part.node, matrix: axesToMatrix(frame), tag: Object.assign(Object.assign(Object.assign({}, properties), { globalId, type: product.type, name: typeof name === "string" ? name : "" }), (rgba ? { rgba: [...rgba] } : {})) }, (group === undefined ? {} : { group })));
|
|
145
162
|
}
|
|
146
163
|
}
|
|
147
164
|
catch (error) {
|
|
148
165
|
problems.push({ globalId, type: product.type, message: error instanceof Error ? error.message : String(error) });
|
|
149
166
|
}
|
|
150
167
|
}
|
|
151
|
-
return { recipe: builder.build(millimetresPerUnit, precisionOf(model, fallbackTolerance), groups.list()), problems };
|
|
168
|
+
return { recipe: builder.build(millimetresPerUnit, precisionOf(model, fallbackTolerance, millimetresPerUnit), groups.list()), problems };
|
|
152
169
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const POINT_SIZE = 3;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const POINT_SIZE = 3;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Base } from "@bitbybit-dev/base";
|
|
2
|
+
import type { ModelSnapshot } from "../model/snapshot";
|
|
3
|
+
import type { CurveSampler } from "./curves";
|
|
4
|
+
import type { RecipeBuilder } from "./recipe-builder";
|
|
5
|
+
export declare class ExactBreps {
|
|
6
|
+
private readonly model;
|
|
7
|
+
private readonly builder;
|
|
8
|
+
private readonly sampler;
|
|
9
|
+
constructor(model: ModelSnapshot, builder: RecipeBuilder, sampler: CurveSampler);
|
|
10
|
+
describe(items: readonly number[]): Omit<Base.RecipeBrepNode, "fallback"> | undefined;
|
|
11
|
+
}
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
import { knotDomain, nurbsCurvePoint } from "@bitbybit-dev/base/lib/api/services/helpers/curves/nurbs";
|
|
2
|
+
import { WORLD_AXES, pointToWorld, vectorToWorld } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/frame-axes";
|
|
3
|
+
import { cross3, length3, subtract3 } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/vectors";
|
|
4
|
+
import { axisPlacementFrame, directionOf, pointOf } from "../build/placement";
|
|
5
|
+
import { isList, isReference } from "../step/values";
|
|
6
|
+
import { faceBounds } from "./advanced";
|
|
7
|
+
import { dividedByWeights } from "./edges";
|
|
8
|
+
import { UnsupportedGeometryError } from "./errors";
|
|
9
|
+
import { referencesIn } from "./references";
|
|
10
|
+
import { parametricSurface } from "./surfaces";
|
|
11
|
+
import { WEIGHTED_POINTS_RATIO } from "./edges.constants";
|
|
12
|
+
import { POINT_SIZE } from "./exact-brep.constants";
|
|
13
|
+
const CURVE_ON_SURFACE = new Set(["IfcSurfaceCurve", "IfcIntersectionCurve", "IfcSeamCurve"]);
|
|
14
|
+
const SPLINE_CURVES = new Set(["IfcBSplineCurveWithKnots", "IfcRationalBSplineCurveWithKnots"]);
|
|
15
|
+
const SPLINE_SURFACES = new Set(["IfcBSplineSurfaceWithKnots", "IfcRationalBSplineSurfaceWithKnots"]);
|
|
16
|
+
const BREPS_WITH_VOIDS = new Set(["IfcAdvancedBrepWithVoids"]);
|
|
17
|
+
const OUTER_BOUND = "IfcFaceOuterBound";
|
|
18
|
+
const FACE_SURFACE = "IfcFaceSurface";
|
|
19
|
+
const TRIMMED_CURVE = "IfcTrimmedCurve";
|
|
20
|
+
const EDGE_LOOP = "IfcEdgeLoop";
|
|
21
|
+
const EDGE_CURVE = "IfcEdgeCurve";
|
|
22
|
+
const Z_AXIS = [0, 0, 1];
|
|
23
|
+
const X_AXIS = [1, 0, 0];
|
|
24
|
+
function finiteList(value) {
|
|
25
|
+
return isList(value) && value.every((item) => typeof item === "number" && Number.isFinite(item));
|
|
26
|
+
}
|
|
27
|
+
function distinctKnots(knots, multiplicities) {
|
|
28
|
+
const distinct = [];
|
|
29
|
+
const counts = [];
|
|
30
|
+
knots.forEach((knot, at) => {
|
|
31
|
+
if (distinct.length && distinct[distinct.length - 1] === knot) {
|
|
32
|
+
counts[counts.length - 1] += multiplicities[at];
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
distinct.push(knot);
|
|
36
|
+
counts.push(multiplicities[at]);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return [distinct, counts];
|
|
40
|
+
}
|
|
41
|
+
class BrepDescription {
|
|
42
|
+
constructor(model, sampler) {
|
|
43
|
+
this.model = model;
|
|
44
|
+
this.sampler = sampler;
|
|
45
|
+
this.numbers = [];
|
|
46
|
+
this.ranges = [];
|
|
47
|
+
this.vertexCoordinates = [];
|
|
48
|
+
this.vertexOf = new Map();
|
|
49
|
+
this.curveOf = new Map();
|
|
50
|
+
this.surfaceOf = new Map();
|
|
51
|
+
this.edgeOf = new Map();
|
|
52
|
+
this.curves = [];
|
|
53
|
+
this.surfaces = [];
|
|
54
|
+
this.edges = [];
|
|
55
|
+
this.faces = [];
|
|
56
|
+
this.solids = [];
|
|
57
|
+
this.dividedSurfaces = new Map();
|
|
58
|
+
}
|
|
59
|
+
of(items, builder) {
|
|
60
|
+
for (const item of items) {
|
|
61
|
+
this.item(item);
|
|
62
|
+
}
|
|
63
|
+
const vertexCount = this.vertexCoordinates.length;
|
|
64
|
+
const [start] = builder.numbers(this.vertexCoordinates.concat(this.numbers));
|
|
65
|
+
for (const range of this.ranges) {
|
|
66
|
+
range[0] += start + vertexCount;
|
|
67
|
+
}
|
|
68
|
+
return { op: "brep", vertices: [start, vertexCount], curves: this.curves, surfaces: this.surfaces, edges: this.edges, faces: this.faces, closed: true, solids: this.solids };
|
|
69
|
+
}
|
|
70
|
+
item(item) {
|
|
71
|
+
var _a;
|
|
72
|
+
const type = (_a = this.model.typeOf(item)) !== null && _a !== void 0 ? _a : "";
|
|
73
|
+
const outer = this.model.attribute(item, "Outer");
|
|
74
|
+
if (!isReference(outer)) {
|
|
75
|
+
throw new UnsupportedGeometryError(`#${item} has no outer shell`);
|
|
76
|
+
}
|
|
77
|
+
const voids = BREPS_WITH_VOIDS.has(type) ? this.model.attribute(item, "Voids") : null;
|
|
78
|
+
const shells = [outer, ...(isList(voids) ? voids : []).filter(isReference)].map((shell) => referencesIn(this.model, shell.ref, "CfsFaces").map((face) => this.faces.push(this.face(face)) - 1));
|
|
79
|
+
const [outerFaces, ...voidFaces] = shells;
|
|
80
|
+
this.solids.push(voidFaces.length ? { outer: outerFaces, voids: voidFaces } : { outer: outerFaces });
|
|
81
|
+
}
|
|
82
|
+
range(values) {
|
|
83
|
+
const range = [this.numbers.length, values.length];
|
|
84
|
+
for (const value of values) {
|
|
85
|
+
this.numbers.push(value);
|
|
86
|
+
}
|
|
87
|
+
this.ranges.push(range);
|
|
88
|
+
return range;
|
|
89
|
+
}
|
|
90
|
+
face(face) {
|
|
91
|
+
var _a;
|
|
92
|
+
const surface = this.model.schema.isSubtypeOf((_a = this.model.typeOf(face)) !== null && _a !== void 0 ? _a : "", FACE_SURFACE) ? this.model.attribute(face, "FaceSurface") : null;
|
|
93
|
+
if (!isReference(surface)) {
|
|
94
|
+
throw new UnsupportedGeometryError(`#${face} is not a face on a surface`);
|
|
95
|
+
}
|
|
96
|
+
const bounds = faceBounds(this.model, face).map((bound) => this.bound(bound));
|
|
97
|
+
return { surface: this.surface(surface.ref, bounds), sameSense: this.model.attribute(face, "SameSense") !== false, bounds };
|
|
98
|
+
}
|
|
99
|
+
bound(bound) {
|
|
100
|
+
var _a;
|
|
101
|
+
const loop = this.model.attribute(bound, "Bound");
|
|
102
|
+
if (!isReference(loop) || this.model.typeOf(loop.ref) !== EDGE_LOOP) {
|
|
103
|
+
throw new UnsupportedGeometryError(`#${bound} is not bounded by a loop of edges`);
|
|
104
|
+
}
|
|
105
|
+
const edges = [];
|
|
106
|
+
const forward = [];
|
|
107
|
+
for (const oriented of referencesIn(this.model, loop.ref, "EdgeList")) {
|
|
108
|
+
const element = this.model.attribute(oriented, "EdgeElement");
|
|
109
|
+
if (!isReference(element) || this.model.typeOf(element.ref) !== EDGE_CURVE) {
|
|
110
|
+
throw new UnsupportedGeometryError(`#${oriented} is not an edge on a curve`);
|
|
111
|
+
}
|
|
112
|
+
edges.push(this.edge(element.ref));
|
|
113
|
+
forward.push(this.model.attribute(oriented, "Orientation") !== false);
|
|
114
|
+
}
|
|
115
|
+
const outer = this.model.schema.isSubtypeOf((_a = this.model.typeOf(bound)) !== null && _a !== void 0 ? _a : "", OUTER_BOUND);
|
|
116
|
+
if (this.model.attribute(bound, "Orientation") === false) {
|
|
117
|
+
return { outer, edges: edges.reverse(), forward: forward.reverse().map((value) => !value) };
|
|
118
|
+
}
|
|
119
|
+
return { outer, edges, forward };
|
|
120
|
+
}
|
|
121
|
+
vertex(value, edge) {
|
|
122
|
+
if (!isReference(value)) {
|
|
123
|
+
throw new UnsupportedGeometryError(`#${edge} has a vertex missing`);
|
|
124
|
+
}
|
|
125
|
+
const known = this.vertexOf.get(value.ref);
|
|
126
|
+
if (known !== undefined) {
|
|
127
|
+
return known;
|
|
128
|
+
}
|
|
129
|
+
const point = this.model.attribute(value.ref, "VertexGeometry");
|
|
130
|
+
if (!isReference(point)) {
|
|
131
|
+
throw new UnsupportedGeometryError(`#${edge} has a vertex without a point`);
|
|
132
|
+
}
|
|
133
|
+
const index = this.vertexCoordinates.length / POINT_SIZE;
|
|
134
|
+
this.vertexCoordinates.push(...pointOf(this.model, point));
|
|
135
|
+
this.vertexOf.set(value.ref, index);
|
|
136
|
+
return index;
|
|
137
|
+
}
|
|
138
|
+
vertexPoint(index) {
|
|
139
|
+
const at = index * POINT_SIZE;
|
|
140
|
+
return [this.vertexCoordinates[at], this.vertexCoordinates[at + 1], this.vertexCoordinates[at + 2]];
|
|
141
|
+
}
|
|
142
|
+
edge(edge) {
|
|
143
|
+
const known = this.edgeOf.get(edge);
|
|
144
|
+
if (known !== undefined) {
|
|
145
|
+
return known;
|
|
146
|
+
}
|
|
147
|
+
const start = this.vertex(this.model.attribute(edge, "EdgeStart"), edge);
|
|
148
|
+
const end = this.vertex(this.model.attribute(edge, "EdgeEnd"), edge);
|
|
149
|
+
const geometry = this.model.attribute(edge, "EdgeGeometry");
|
|
150
|
+
if (!isReference(geometry)) {
|
|
151
|
+
throw new UnsupportedGeometryError(`#${edge} has no curve`);
|
|
152
|
+
}
|
|
153
|
+
const curve = this.curve(geometry.ref, { start: this.vertexPoint(start), end: this.vertexPoint(end) }, WORLD_AXES, "");
|
|
154
|
+
const sameSense = this.model.attribute(edge, "SameSense") !== false;
|
|
155
|
+
const index = this.edges.push(Object.assign({ curve, start, end }, (sameSense ? {} : { sameSense }))) - 1;
|
|
156
|
+
this.edgeOf.set(edge, index);
|
|
157
|
+
return index;
|
|
158
|
+
}
|
|
159
|
+
curve(curve, ends, frame, placedIn) {
|
|
160
|
+
var _a;
|
|
161
|
+
const type = (_a = this.model.typeOf(curve)) !== null && _a !== void 0 ? _a : "";
|
|
162
|
+
if (CURVE_ON_SURFACE.has(type) || type === TRIMMED_CURVE) {
|
|
163
|
+
const basis = this.model.attribute(curve, type === TRIMMED_CURVE ? "BasisCurve" : "Curve3D");
|
|
164
|
+
if (!isReference(basis)) {
|
|
165
|
+
throw new UnsupportedGeometryError(`#${curve} has no curve it lies on`);
|
|
166
|
+
}
|
|
167
|
+
return this.curve(basis.ref, ends, frame, placedIn);
|
|
168
|
+
}
|
|
169
|
+
const spline = SPLINE_CURVES.has(type) ? this.sampler.bspline(curve) : undefined;
|
|
170
|
+
const divided = ends !== undefined && spline !== undefined && spline.weights !== undefined && this.meetsWhenDivided(spline, ends);
|
|
171
|
+
const key = `${curve}${divided ? "/" : ""}${placedIn}`;
|
|
172
|
+
const known = this.curveOf.get(key);
|
|
173
|
+
if (known !== undefined) {
|
|
174
|
+
return known;
|
|
175
|
+
}
|
|
176
|
+
const index = this.curves.push(this.curveDescription(curve, type, divided, frame)) - 1;
|
|
177
|
+
this.curveOf.set(key, index);
|
|
178
|
+
return index;
|
|
179
|
+
}
|
|
180
|
+
meetsWhenDivided(spline, ends) {
|
|
181
|
+
const reach = Math.max(1, length3(ends.start), length3(ends.end)) * WEIGHTED_POINTS_RATIO;
|
|
182
|
+
const misses = (candidate) => {
|
|
183
|
+
const [from, to] = knotDomain(candidate.degree, candidate.knots);
|
|
184
|
+
const [first, last] = [from, to].map((t) => nurbsCurvePoint(candidate.degree, candidate.points, candidate.weights, candidate.knots, t));
|
|
185
|
+
return Math.min(length3(subtract3(first, ends.start)) + length3(subtract3(last, ends.end)), length3(subtract3(first, ends.end)) + length3(subtract3(last, ends.start)));
|
|
186
|
+
};
|
|
187
|
+
return misses(spline) > reach && misses(dividedByWeights(spline)) <= reach;
|
|
188
|
+
}
|
|
189
|
+
curveDescription(curve, type, divided, frame) {
|
|
190
|
+
switch (type) {
|
|
191
|
+
case "IfcLine": {
|
|
192
|
+
const vector = this.model.attribute(curve, "Dir");
|
|
193
|
+
const orientation = isReference(vector) ? this.model.attribute(vector.ref, "Orientation") : null;
|
|
194
|
+
return { kind: "line", origin: pointToWorld(frame, pointOf(this.model, this.model.attribute(curve, "Pnt"))), direction: vectorToWorld(frame, directionOf(this.model, orientation, X_AXIS)) };
|
|
195
|
+
}
|
|
196
|
+
case "IfcCircle":
|
|
197
|
+
case "IfcEllipse": {
|
|
198
|
+
const conic = this.sampler.conicFrame(curve);
|
|
199
|
+
const origin = pointToWorld(frame, conic.origin);
|
|
200
|
+
const x = vectorToWorld(frame, conic.x);
|
|
201
|
+
const axis = cross3(x, vectorToWorld(frame, conic.y));
|
|
202
|
+
return type === "IfcCircle"
|
|
203
|
+
? { kind: "circle", origin, axis, xDirection: x, radius: conic.radii[0] }
|
|
204
|
+
: { kind: "ellipse", origin, axis, xDirection: x, xRadius: conic.radii[0], yRadius: conic.radii[1] };
|
|
205
|
+
}
|
|
206
|
+
case "IfcPolyline": {
|
|
207
|
+
const points = referencesIn(this.model, curve, "Points").map((point) => pointToWorld(frame, pointOf(this.model, { ref: point })));
|
|
208
|
+
if (points.length < 2) {
|
|
209
|
+
throw new UnsupportedGeometryError(`#${curve} has fewer than two points`);
|
|
210
|
+
}
|
|
211
|
+
const knots = points.map((_, at) => at);
|
|
212
|
+
return { kind: "bspline", degree: 1, points: this.range(points.flat()), knots: this.range(knots), multiplicities: knots.map((_, at) => (at === 0 || at === knots.length - 1 ? 2 : 1)) };
|
|
213
|
+
}
|
|
214
|
+
default:
|
|
215
|
+
if (SPLINE_CURVES.has(type)) {
|
|
216
|
+
return this.splineCurve(curve, divided, frame);
|
|
217
|
+
}
|
|
218
|
+
throw new UnsupportedGeometryError(`An edge on an ${type} is not described exactly yet`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
splineCurve(curve, divided, frame) {
|
|
222
|
+
const raw = this.sampler.bspline(curve);
|
|
223
|
+
const spline = divided ? dividedByWeights(raw) : raw;
|
|
224
|
+
const knots = this.model.attribute(curve, "Knots");
|
|
225
|
+
const multiplicities = this.model.attribute(curve, "KnotMultiplicities");
|
|
226
|
+
if (!finiteList(knots) || !finiteList(multiplicities)) {
|
|
227
|
+
throw new UnsupportedGeometryError(`#${curve} has no knots`);
|
|
228
|
+
}
|
|
229
|
+
const [distinct, counts] = distinctKnots(knots, multiplicities);
|
|
230
|
+
return Object.assign(Object.assign({ kind: "bspline", degree: spline.degree, points: this.range(spline.points.flatMap((point) => pointToWorld(frame, point))) }, (spline.weights ? { weights: this.range(spline.weights) } : {})), { knots: this.range(distinct), multiplicities: counts });
|
|
231
|
+
}
|
|
232
|
+
surface(surface, bounds) {
|
|
233
|
+
var _a;
|
|
234
|
+
const type = (_a = this.model.typeOf(surface)) !== null && _a !== void 0 ? _a : "";
|
|
235
|
+
const divided = type === "IfcRationalBSplineSurfaceWithKnots" && this.dividedSurface(surface, bounds);
|
|
236
|
+
const key = `${surface}${divided ? "/" : ""}`;
|
|
237
|
+
const known = this.surfaceOf.get(key);
|
|
238
|
+
if (known !== undefined) {
|
|
239
|
+
return known;
|
|
240
|
+
}
|
|
241
|
+
const index = this.surfaces.push(this.surfaceDescription(surface, type, divided)) - 1;
|
|
242
|
+
this.surfaceOf.set(key, index);
|
|
243
|
+
return index;
|
|
244
|
+
}
|
|
245
|
+
dividedSurface(surface, bounds) {
|
|
246
|
+
const known = this.dividedSurfaces.get(surface);
|
|
247
|
+
if (known !== undefined) {
|
|
248
|
+
return known;
|
|
249
|
+
}
|
|
250
|
+
const probes = bounds.flatMap((bound) => bound.edges.map((edge) => this.vertexPoint(this.edges[edge].start)));
|
|
251
|
+
const missOf = (divided) => {
|
|
252
|
+
const parametric = parametricSurface(this.model, this.sampler, surface, divided);
|
|
253
|
+
return parametric ? Math.max(...probes.map((point) => {
|
|
254
|
+
const [u, v] = parametric.parameters(point, undefined);
|
|
255
|
+
return length3(subtract3(parametric.point(u, v), point));
|
|
256
|
+
})) : Infinity;
|
|
257
|
+
};
|
|
258
|
+
const asWritten = missOf(false);
|
|
259
|
+
const divided = asWritten > Math.max(1, ...probes.map(length3)) * WEIGHTED_POINTS_RATIO && missOf(true) < asWritten;
|
|
260
|
+
this.dividedSurfaces.set(surface, divided);
|
|
261
|
+
return divided;
|
|
262
|
+
}
|
|
263
|
+
placement(surface) {
|
|
264
|
+
const position = this.model.attribute(surface, "Position");
|
|
265
|
+
if (!isReference(position)) {
|
|
266
|
+
return { origin: [0, 0, 0], axis: Z_AXIS, xDirection: X_AXIS };
|
|
267
|
+
}
|
|
268
|
+
const frame = axisPlacementFrame(this.model, position.ref);
|
|
269
|
+
return { origin: frame.origin, axis: frame.z, xDirection: frame.x };
|
|
270
|
+
}
|
|
271
|
+
positive(id, name) {
|
|
272
|
+
const value = this.model.attribute(id, name);
|
|
273
|
+
if (typeof value !== "number" || !Number.isFinite(value) || !(value > 0)) {
|
|
274
|
+
throw new UnsupportedGeometryError(`#${id} has no ${name} above zero`);
|
|
275
|
+
}
|
|
276
|
+
return value;
|
|
277
|
+
}
|
|
278
|
+
surfaceDescription(surface, type, divided) {
|
|
279
|
+
switch (type) {
|
|
280
|
+
case "IfcPlane":
|
|
281
|
+
return Object.assign({ kind: "plane" }, this.placement(surface));
|
|
282
|
+
case "IfcCylindricalSurface":
|
|
283
|
+
return Object.assign(Object.assign({ kind: "cylinder" }, this.placement(surface)), { radius: this.positive(surface, "Radius") });
|
|
284
|
+
case "IfcSphericalSurface":
|
|
285
|
+
return Object.assign(Object.assign({ kind: "sphere" }, this.placement(surface)), { radius: this.positive(surface, "Radius") });
|
|
286
|
+
case "IfcToroidalSurface":
|
|
287
|
+
return Object.assign(Object.assign({ kind: "torus" }, this.placement(surface)), { majorRadius: this.positive(surface, "MajorRadius"), minorRadius: this.positive(surface, "MinorRadius") });
|
|
288
|
+
case "IfcSurfaceOfRevolution": {
|
|
289
|
+
const axis = this.model.attribute(surface, "AxisPosition");
|
|
290
|
+
if (!isReference(axis)) {
|
|
291
|
+
throw new UnsupportedGeometryError(`#${surface} has no axis`);
|
|
292
|
+
}
|
|
293
|
+
const frame = this.sweptFrame(surface);
|
|
294
|
+
return {
|
|
295
|
+
kind: "revolution",
|
|
296
|
+
curve: this.sweptCurve(surface, frame),
|
|
297
|
+
origin: pointToWorld(frame, pointOf(this.model, this.model.attribute(axis.ref, "Location"))),
|
|
298
|
+
axis: vectorToWorld(frame, directionOf(this.model, this.model.attribute(axis.ref, "Axis"), Z_AXIS)),
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
case "IfcSurfaceOfLinearExtrusion": {
|
|
302
|
+
const frame = this.sweptFrame(surface);
|
|
303
|
+
return { kind: "extrusion", curve: this.sweptCurve(surface, frame), direction: vectorToWorld(frame, directionOf(this.model, this.model.attribute(surface, "ExtrudedDirection"), Z_AXIS)) };
|
|
304
|
+
}
|
|
305
|
+
default:
|
|
306
|
+
if (SPLINE_SURFACES.has(type)) {
|
|
307
|
+
return this.splineSurface(surface, divided);
|
|
308
|
+
}
|
|
309
|
+
throw new UnsupportedGeometryError(`A face on an ${type} is not described exactly yet`);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
sweptFrame(surface) {
|
|
313
|
+
const position = this.model.attribute(surface, "Position");
|
|
314
|
+
return isReference(position) ? axisPlacementFrame(this.model, position.ref) : WORLD_AXES;
|
|
315
|
+
}
|
|
316
|
+
sweptCurve(surface, frame) {
|
|
317
|
+
const profile = this.model.attribute(surface, "SweptCurve");
|
|
318
|
+
const curve = isReference(profile) ? this.model.attribute(profile.ref, "Curve") : null;
|
|
319
|
+
if (!isReference(curve)) {
|
|
320
|
+
throw new UnsupportedGeometryError(`#${surface} sweeps no curve`);
|
|
321
|
+
}
|
|
322
|
+
return this.curve(curve.ref, undefined, frame, `@${surface}`);
|
|
323
|
+
}
|
|
324
|
+
splineSurface(surface, divided) {
|
|
325
|
+
var _a, _b;
|
|
326
|
+
const degree = (name) => {
|
|
327
|
+
const value = this.model.attribute(surface, name);
|
|
328
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 1) {
|
|
329
|
+
throw new UnsupportedGeometryError(`#${surface} has no ${name}`);
|
|
330
|
+
}
|
|
331
|
+
return value;
|
|
332
|
+
};
|
|
333
|
+
const list = (name) => {
|
|
334
|
+
const value = this.model.attribute(surface, name);
|
|
335
|
+
if (!finiteList(value)) {
|
|
336
|
+
throw new UnsupportedGeometryError(`#${surface} has no ${name}`);
|
|
337
|
+
}
|
|
338
|
+
return value;
|
|
339
|
+
};
|
|
340
|
+
const controls = this.model.attribute(surface, "ControlPointsList");
|
|
341
|
+
const net = (isList(controls) ? controls : []).map((row) => (isList(row) ? row : []).map((point) => pointOf(this.model, point)));
|
|
342
|
+
const vCount = (_b = (_a = net[0]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
343
|
+
if (net.length === 0 || net.some((row) => row.length !== vCount)) {
|
|
344
|
+
throw new UnsupportedGeometryError(`#${surface} has a control net that is not rectangular`);
|
|
345
|
+
}
|
|
346
|
+
const weightRows = this.model.typeOf(surface) === "IfcRationalBSplineSurfaceWithKnots" ? this.model.attribute(surface, "WeightsData") : null;
|
|
347
|
+
const weights = isList(weightRows) ? weightRows.flatMap((row) => (isList(row) ? row.map((value) => (typeof value === "number" ? value : 1)) : [])) : undefined;
|
|
348
|
+
const points = net.flat().map((point, at) => (divided && weights ? point.map((coordinate) => coordinate / weights[at]) : point));
|
|
349
|
+
const [uKnots, uMultiplicities] = distinctKnots(list("UKnots"), list("UMultiplicities"));
|
|
350
|
+
const [vKnots, vMultiplicities] = distinctKnots(list("VKnots"), list("VMultiplicities"));
|
|
351
|
+
return Object.assign(Object.assign({ kind: "bspline", uDegree: degree("UDegree"), vDegree: degree("VDegree"), uCount: net.length, vCount, points: this.range(points.flat()) }, (weights ? { weights: this.range(weights) } : {})), { uKnots: this.range(uKnots), uMultiplicities, vKnots: this.range(vKnots), vMultiplicities });
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
export class ExactBreps {
|
|
355
|
+
constructor(model, builder, sampler) {
|
|
356
|
+
this.model = model;
|
|
357
|
+
this.builder = builder;
|
|
358
|
+
this.sampler = sampler;
|
|
359
|
+
}
|
|
360
|
+
describe(items) {
|
|
361
|
+
try {
|
|
362
|
+
return new BrepDescription(this.model, this.sampler).of(items, this.builder);
|
|
363
|
+
}
|
|
364
|
+
catch (thrown) {
|
|
365
|
+
if (thrown instanceof UnsupportedGeometryError) {
|
|
366
|
+
return undefined;
|
|
367
|
+
}
|
|
368
|
+
throw thrown;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|