@bitbybit-dev/ifc 1.5.0 → 1.6.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
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { Recipes } from "@bitbybit-dev/base";
|
|
2
|
+
import { isRigidMatrix, linearDeterminant, movedPoint, turnedVector } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/matrices";
|
|
3
|
+
import { scale3 } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/vectors";
|
|
4
|
+
import { enumValue, ref } from "../step/values";
|
|
5
|
+
import { POINT3_SIZE, TRIANGLE_CORNERS } from "./constants";
|
|
6
|
+
import { direction3Of, frameFrom } from "./math";
|
|
7
|
+
const RECIPES = new Recipes();
|
|
8
|
+
const UNSPECIFIED = "UNSPECIFIED";
|
|
9
|
+
const DIFFERENCE = "DIFFERENCE";
|
|
10
|
+
const ADVANCED_BREP = "AdvancedBrep";
|
|
11
|
+
const SURFACE_MODEL = "SurfaceModel";
|
|
12
|
+
const TESSELLATION = "Tessellation";
|
|
13
|
+
const SOLID_MODEL = "SolidModel";
|
|
14
|
+
class Placer {
|
|
15
|
+
constructor(matrix, scale) {
|
|
16
|
+
this.matrix = matrix;
|
|
17
|
+
this.scale = scale;
|
|
18
|
+
}
|
|
19
|
+
point(point) {
|
|
20
|
+
return scale3(movedPoint(this.matrix, point), this.scale);
|
|
21
|
+
}
|
|
22
|
+
turned(vector) {
|
|
23
|
+
return turnedVector(this.matrix, vector);
|
|
24
|
+
}
|
|
25
|
+
vector(vector) {
|
|
26
|
+
return direction3Of(this.turned(vector));
|
|
27
|
+
}
|
|
28
|
+
length(length) {
|
|
29
|
+
return length * this.scale;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function numbers(buffers, range) {
|
|
33
|
+
return Array.from(buffers.f64.subarray(range[0], range[0] + range[1]));
|
|
34
|
+
}
|
|
35
|
+
function triples(values) {
|
|
36
|
+
const out = [];
|
|
37
|
+
for (let at = 0; at + 2 < values.length; at += POINT3_SIZE) {
|
|
38
|
+
out.push([values[at], values[at + 1], values[at + 2]]);
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
class BrepWriter {
|
|
43
|
+
constructor(writer, node, buffers, placer) {
|
|
44
|
+
this.writer = writer;
|
|
45
|
+
this.node = node;
|
|
46
|
+
this.buffers = buffers;
|
|
47
|
+
this.placer = placer;
|
|
48
|
+
this.vertices = new Map();
|
|
49
|
+
this.curves = new Map();
|
|
50
|
+
this.surfaces = new Map();
|
|
51
|
+
this.edges = new Map();
|
|
52
|
+
this.corners = triples(numbers(buffers, node.vertices));
|
|
53
|
+
}
|
|
54
|
+
items() {
|
|
55
|
+
if (!this.node.closed) {
|
|
56
|
+
const shell = this.writer.create("IfcOpenShell", { CfsFaces: this.node.faces.map((face) => ref(this.face(face, false))) });
|
|
57
|
+
return { items: [this.writer.create("IfcShellBasedSurfaceModel", { SbsmBoundary: [ref(shell)] })], carved: false };
|
|
58
|
+
}
|
|
59
|
+
const solids = this.solids();
|
|
60
|
+
const items = solids.map((solid) => {
|
|
61
|
+
var _a;
|
|
62
|
+
const cavities = (_a = solid.voids) !== null && _a !== void 0 ? _a : [];
|
|
63
|
+
const outer = this.brep(solid.outer, false);
|
|
64
|
+
if (!cavities.length) {
|
|
65
|
+
return outer;
|
|
66
|
+
}
|
|
67
|
+
const carved = cavities.reduce((kept, cavity) => this.writer.create("IfcBooleanResult", { Operator: enumValue(DIFFERENCE), FirstOperand: ref(kept), SecondOperand: ref(this.brep(cavity, true)) }), outer);
|
|
68
|
+
return this.writer.create("IfcCsgSolid", { TreeRootExpression: ref(carved) });
|
|
69
|
+
});
|
|
70
|
+
return { items, carved: solids.some((solid) => { var _a; return ((_a = solid.voids) !== null && _a !== void 0 ? _a : []).length > 0; }) };
|
|
71
|
+
}
|
|
72
|
+
brep(faces, turned) {
|
|
73
|
+
const shell = this.writer.create("IfcClosedShell", { CfsFaces: faces.map((face) => ref(this.face(this.node.faces[face], turned))) });
|
|
74
|
+
return this.writer.create("IfcAdvancedBrep", { Outer: ref(shell) });
|
|
75
|
+
}
|
|
76
|
+
solids() {
|
|
77
|
+
if (this.node.solids !== undefined) {
|
|
78
|
+
return this.node.solids;
|
|
79
|
+
}
|
|
80
|
+
const roots = this.node.faces.map((_, at) => at);
|
|
81
|
+
const rootOf = (face) => {
|
|
82
|
+
let at = face;
|
|
83
|
+
while (roots[at] !== at) {
|
|
84
|
+
at = roots[at];
|
|
85
|
+
}
|
|
86
|
+
return at;
|
|
87
|
+
};
|
|
88
|
+
const firstFaceOfEdge = new Map();
|
|
89
|
+
this.node.faces.forEach((face, at) => {
|
|
90
|
+
for (const bound of face.bounds) {
|
|
91
|
+
for (const edge of bound.edges) {
|
|
92
|
+
const other = firstFaceOfEdge.get(edge);
|
|
93
|
+
if (other === undefined) {
|
|
94
|
+
firstFaceOfEdge.set(edge, at);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
const [a, b] = [rootOf(other), rootOf(at)];
|
|
98
|
+
roots[Math.max(a, b)] = Math.min(a, b);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
const shells = new Map();
|
|
104
|
+
roots.forEach((_, at) => {
|
|
105
|
+
var _a;
|
|
106
|
+
const root = rootOf(at);
|
|
107
|
+
shells.set(root, [...((_a = shells.get(root)) !== null && _a !== void 0 ? _a : []), at]);
|
|
108
|
+
});
|
|
109
|
+
return [...shells.values()].map((outer) => ({ outer }));
|
|
110
|
+
}
|
|
111
|
+
vertex(index) {
|
|
112
|
+
let known = this.vertices.get(index);
|
|
113
|
+
if (known === undefined) {
|
|
114
|
+
known = this.writer.create("IfcVertexPoint", { VertexGeometry: ref(this.writer.point(this.placer.point(this.corners[index]))) });
|
|
115
|
+
this.vertices.set(index, known);
|
|
116
|
+
}
|
|
117
|
+
return known;
|
|
118
|
+
}
|
|
119
|
+
placement(placement) {
|
|
120
|
+
return this.writer.placement3(frameFrom(this.placer.point(placement.origin), this.placer.turned(placement.axis), this.placer.turned(placement.xDirection)));
|
|
121
|
+
}
|
|
122
|
+
curve(index) {
|
|
123
|
+
let known = this.curves.get(index);
|
|
124
|
+
if (known === undefined) {
|
|
125
|
+
known = this.curveEntity(this.node.curves[index]);
|
|
126
|
+
this.curves.set(index, known);
|
|
127
|
+
}
|
|
128
|
+
return known;
|
|
129
|
+
}
|
|
130
|
+
curveEntity(curve) {
|
|
131
|
+
switch (curve.kind) {
|
|
132
|
+
case "line": {
|
|
133
|
+
const vector = this.writer.create("IfcVector", { Orientation: ref(this.writer.direction(this.placer.vector(curve.direction))), Magnitude: 1 });
|
|
134
|
+
return this.writer.create("IfcLine", { Pnt: ref(this.writer.point(this.placer.point(curve.origin))), Dir: ref(vector) });
|
|
135
|
+
}
|
|
136
|
+
case "circle":
|
|
137
|
+
return this.writer.create("IfcCircle", { Position: ref(this.placement(curve)), Radius: this.placer.length(curve.radius) });
|
|
138
|
+
case "ellipse":
|
|
139
|
+
return this.writer.create("IfcEllipse", { Position: ref(this.placement(curve)), SemiAxis1: this.placer.length(curve.xRadius), SemiAxis2: this.placer.length(curve.yRadius) });
|
|
140
|
+
case "bspline": {
|
|
141
|
+
const points = triples(numbers(this.buffers, curve.points)).map((point) => ref(this.writer.point(this.placer.point(point))));
|
|
142
|
+
const shared = {
|
|
143
|
+
Degree: curve.degree,
|
|
144
|
+
ControlPointsList: points,
|
|
145
|
+
CurveForm: enumValue(UNSPECIFIED),
|
|
146
|
+
ClosedCurve: false,
|
|
147
|
+
SelfIntersect: false,
|
|
148
|
+
KnotMultiplicities: curve.multiplicities,
|
|
149
|
+
Knots: numbers(this.buffers, curve.knots),
|
|
150
|
+
KnotSpec: enumValue(UNSPECIFIED),
|
|
151
|
+
};
|
|
152
|
+
return curve.weights === undefined
|
|
153
|
+
? this.writer.create("IfcBSplineCurveWithKnots", shared)
|
|
154
|
+
: this.writer.create("IfcRationalBSplineCurveWithKnots", Object.assign(Object.assign({}, shared), { WeightsData: numbers(this.buffers, curve.weights) }));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
surface(index) {
|
|
159
|
+
let known = this.surfaces.get(index);
|
|
160
|
+
if (known === undefined) {
|
|
161
|
+
known = this.surfaceEntity(this.node.surfaces[index]);
|
|
162
|
+
this.surfaces.set(index, known);
|
|
163
|
+
}
|
|
164
|
+
return known;
|
|
165
|
+
}
|
|
166
|
+
surfaceEntity(surface) {
|
|
167
|
+
switch (surface.kind) {
|
|
168
|
+
case "plane":
|
|
169
|
+
return this.writer.create("IfcPlane", { Position: ref(this.placement(surface)) });
|
|
170
|
+
case "cylinder":
|
|
171
|
+
return this.writer.create("IfcCylindricalSurface", { Position: ref(this.placement(surface)), Radius: this.placer.length(surface.radius) });
|
|
172
|
+
case "sphere":
|
|
173
|
+
return this.writer.create("IfcSphericalSurface", { Position: ref(this.placement(surface)), Radius: this.placer.length(surface.radius) });
|
|
174
|
+
case "torus":
|
|
175
|
+
return this.writer.create("IfcToroidalSurface", { Position: ref(this.placement(surface)), MajorRadius: this.placer.length(surface.majorRadius), MinorRadius: this.placer.length(surface.minorRadius) });
|
|
176
|
+
case "bspline": {
|
|
177
|
+
const points = triples(numbers(this.buffers, surface.points)).map((point) => ref(this.writer.point(this.placer.point(point))));
|
|
178
|
+
const rows = Array.from({ length: surface.uCount }, (_, u) => points.slice(u * surface.vCount, (u + 1) * surface.vCount));
|
|
179
|
+
const shared = {
|
|
180
|
+
UDegree: surface.uDegree,
|
|
181
|
+
VDegree: surface.vDegree,
|
|
182
|
+
ControlPointsList: rows,
|
|
183
|
+
SurfaceForm: enumValue(UNSPECIFIED),
|
|
184
|
+
UClosed: false,
|
|
185
|
+
VClosed: false,
|
|
186
|
+
SelfIntersect: false,
|
|
187
|
+
UMultiplicities: surface.uMultiplicities,
|
|
188
|
+
VMultiplicities: surface.vMultiplicities,
|
|
189
|
+
UKnots: numbers(this.buffers, surface.uKnots),
|
|
190
|
+
VKnots: numbers(this.buffers, surface.vKnots),
|
|
191
|
+
KnotSpec: enumValue(UNSPECIFIED),
|
|
192
|
+
};
|
|
193
|
+
if (surface.weights === undefined) {
|
|
194
|
+
return this.writer.create("IfcBSplineSurfaceWithKnots", shared);
|
|
195
|
+
}
|
|
196
|
+
const weights = numbers(this.buffers, surface.weights);
|
|
197
|
+
return this.writer.create("IfcRationalBSplineSurfaceWithKnots", Object.assign(Object.assign({}, shared), { WeightsData: Array.from({ length: surface.uCount }, (_, u) => weights.slice(u * surface.vCount, (u + 1) * surface.vCount)) }));
|
|
198
|
+
}
|
|
199
|
+
default:
|
|
200
|
+
throw new Error(`A ${surface.kind} surface has no IFC4 form an advanced face takes; describe the shape with ifcSurfaces set, which writes it as a B-spline`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
edge(index) {
|
|
204
|
+
let known = this.edges.get(index);
|
|
205
|
+
if (known === undefined) {
|
|
206
|
+
const edge = this.node.edges[index];
|
|
207
|
+
known = this.writer.create("IfcEdgeCurve", {
|
|
208
|
+
EdgeStart: ref(this.vertex(edge.start)),
|
|
209
|
+
EdgeEnd: ref(this.vertex(edge.end)),
|
|
210
|
+
EdgeGeometry: ref(this.curve(edge.curve)),
|
|
211
|
+
SameSense: edge.sameSense !== false,
|
|
212
|
+
});
|
|
213
|
+
this.edges.set(index, known);
|
|
214
|
+
}
|
|
215
|
+
return known;
|
|
216
|
+
}
|
|
217
|
+
face(face, turned) {
|
|
218
|
+
const bounds = face.bounds.map((bound) => {
|
|
219
|
+
const uses = bound.edges.map((edge, use) => this.writer.create("IfcOrientedEdge", { EdgeElement: ref(this.edge(edge)), Orientation: bound.forward[use] === true }));
|
|
220
|
+
const loop = this.writer.create("IfcEdgeLoop", { EdgeList: uses.map(ref) });
|
|
221
|
+
return this.writer.create(bound.outer ? "IfcFaceOuterBound" : "IfcFaceBound", { Bound: ref(loop), Orientation: !turned });
|
|
222
|
+
});
|
|
223
|
+
return this.writer.create("IfcAdvancedFace", { Bounds: bounds.map(ref), FaceSurface: ref(this.surface(face.surface)), SameSense: face.sameSense !== turned });
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function faceSetOf(writer, node, buffers, placer) {
|
|
227
|
+
const points = triples(numbers(buffers, node.positions)).map((point) => placer.point(point));
|
|
228
|
+
const indices = Array.from(buffers.i32.subarray(node.indices[0], node.indices[0] + node.indices[1]));
|
|
229
|
+
const triangles = [];
|
|
230
|
+
const directed = new Set();
|
|
231
|
+
for (let at = 0; at + 2 < indices.length; at += TRIANGLE_CORNERS) {
|
|
232
|
+
const corners = [indices[at], indices[at + 1], indices[at + 2]];
|
|
233
|
+
triangles.push(corners.map((corner) => corner + 1));
|
|
234
|
+
corners.forEach((corner, use) => directed.add(`${corner}>${corners[(use + 1) % TRIANGLE_CORNERS]}`));
|
|
235
|
+
}
|
|
236
|
+
const closed = triangles.length > 0 && [...directed].every((edge) => directed.has(edge.split(">").reverse().join(">")));
|
|
237
|
+
const list = writer.create("IfcCartesianPointList3D", { CoordList: points });
|
|
238
|
+
return writer.create("IfcTriangulatedFaceSet", { Coordinates: ref(list), Closed: closed, CoordIndex: triangles });
|
|
239
|
+
}
|
|
240
|
+
function placedSourceOf(recipe, root, at) {
|
|
241
|
+
const source = RECIPES.sourceOf({ recipe, node: root.node, matrix: root.matrix });
|
|
242
|
+
if (!isRigidMatrix(source.matrix) || linearDeterminant(source.matrix) < 0) {
|
|
243
|
+
throw new Error(`Root ${at} of the body is placed by a matrix that scales or mirrors; a body is written only moved and turned`);
|
|
244
|
+
}
|
|
245
|
+
return { node: recipe.nodes[source.node], matrix: source.matrix };
|
|
246
|
+
}
|
|
247
|
+
export function writeBodyItems(writer, recipe, scale) {
|
|
248
|
+
const kinds = new Set();
|
|
249
|
+
let carved = false;
|
|
250
|
+
const items = recipe.roots.flatMap((root, at) => {
|
|
251
|
+
const { node, matrix } = placedSourceOf(recipe, root, at);
|
|
252
|
+
const placer = new Placer(matrix, scale);
|
|
253
|
+
if (node.op === "brep") {
|
|
254
|
+
kinds.add(node.closed ? ADVANCED_BREP : SURFACE_MODEL);
|
|
255
|
+
const written = new BrepWriter(writer, node, recipe.buffers, placer).items();
|
|
256
|
+
carved || (carved = written.carved);
|
|
257
|
+
return written.items;
|
|
258
|
+
}
|
|
259
|
+
if (node.op === "triangles") {
|
|
260
|
+
kinds.add(TESSELLATION);
|
|
261
|
+
return [faceSetOf(writer, node, recipe.buffers, placer)];
|
|
262
|
+
}
|
|
263
|
+
throw new Error(`Root ${at} of the body is a ${node.op} step; a body is written from brep and triangles steps, so describe a shape exactly first`);
|
|
264
|
+
});
|
|
265
|
+
if (items.length === 0) {
|
|
266
|
+
throw new Error("The body has no roots to write");
|
|
267
|
+
}
|
|
268
|
+
if (kinds.size > 1) {
|
|
269
|
+
throw new Error(`The body mixes ${[...kinds].join(" and ")} items, which one IFC representation cannot hold`);
|
|
270
|
+
}
|
|
271
|
+
const kind = [...kinds][0];
|
|
272
|
+
return { items, representationType: carved ? SOLID_MODEL : kind };
|
|
273
|
+
}
|
package/lib/build/fillings.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WORLD_AXES, pointToWorld } from "@bitbybit-dev/base/lib/api/services/helpers/frame-axes";
|
|
1
|
+
import { WORLD_AXES, pointToWorld } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/frame-axes";
|
|
2
2
|
import { enumValue, isList, isReference, ref } from "../step/values";
|
|
3
3
|
import { requirePositive } from "./checks";
|
|
4
4
|
import { bodyContext } from "./contexts";
|
package/lib/build/math.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Base } from "@bitbybit-dev/base";
|
|
2
2
|
import type { Frame3, Line2 } from "./build-types";
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
3
|
+
export declare function direction2Of(a: Base.Vector2): Base.Vector2;
|
|
4
|
+
export declare function direction3Of(a: Base.Vector3): Base.Vector3;
|
|
5
|
+
export declare function requiredFrame(frame: Frame3 | "normal" | "direction"): Frame3;
|
|
5
6
|
export declare function frameFrom(origin: Base.Point3, zAxis: Base.Vector3, xHint: Base.Vector3): Frame3;
|
|
6
7
|
export declare function intersectLines(first: Line2, second: Line2, parallelTolerance: number): Base.Point2 | undefined;
|
|
7
8
|
export declare function distanceToLine(point: Base.Point2, line: Line2): number;
|
package/lib/build/math.js
CHANGED
|
@@ -1,24 +1,32 @@
|
|
|
1
|
-
import { pointToWorld } from "@bitbybit-dev/base/lib/api/services/helpers/frame-axes";
|
|
2
|
-
import { add2, cross2,
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { pointToWorld, squareFrame, unitOf } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/frame-axes";
|
|
2
|
+
import { add2, cross2, dot2, length2, scale2, subtract2, unit2Of } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/vectors";
|
|
3
|
+
const NO_DIRECTION = "A direction needs a finite length above zero";
|
|
4
|
+
const NO_SQUARE_X = "A frame's X direction has no part square to its Z axis";
|
|
5
|
+
export function direction2Of(a) {
|
|
6
|
+
const unit = unit2Of(a);
|
|
7
|
+
if (unit === undefined) {
|
|
8
|
+
throw new RangeError(NO_DIRECTION);
|
|
8
9
|
}
|
|
9
|
-
return
|
|
10
|
+
return unit;
|
|
10
11
|
}
|
|
11
|
-
export function
|
|
12
|
-
const
|
|
13
|
-
if (
|
|
14
|
-
throw new RangeError(
|
|
12
|
+
export function direction3Of(a) {
|
|
13
|
+
const unit = unitOf(a);
|
|
14
|
+
if (unit === undefined) {
|
|
15
|
+
throw new RangeError(NO_DIRECTION);
|
|
15
16
|
}
|
|
16
|
-
return
|
|
17
|
+
return unit;
|
|
18
|
+
}
|
|
19
|
+
export function requiredFrame(frame) {
|
|
20
|
+
if (frame === "normal") {
|
|
21
|
+
throw new RangeError(NO_DIRECTION);
|
|
22
|
+
}
|
|
23
|
+
if (frame === "direction") {
|
|
24
|
+
throw new RangeError(NO_SQUARE_X);
|
|
25
|
+
}
|
|
26
|
+
return frame;
|
|
17
27
|
}
|
|
18
28
|
export function frameFrom(origin, zAxis, xHint) {
|
|
19
|
-
|
|
20
|
-
const x = normalize3(subtract3(xHint, scale3(z, dot3(xHint, z))));
|
|
21
|
-
return { origin, x, y: cross3(z, x), z };
|
|
29
|
+
return requiredFrame(squareFrame(origin, zAxis, xHint));
|
|
22
30
|
}
|
|
23
31
|
export function intersectLines(first, second, parallelTolerance) {
|
|
24
32
|
const denominator = cross2(first.direction, second.direction);
|
package/lib/build/measure.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { perimeter2, signedArea2 } from "@bitbybit-dev/base/lib/api/services/helpers/polygons";
|
|
2
|
-
import { length2, subtract2 } from "@bitbybit-dev/base/lib/api/services/helpers/vectors";
|
|
1
|
+
import { perimeter2, signedArea2 } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/polygons";
|
|
2
|
+
import { between2, dot2, length2, length3, subtract2 } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/vectors";
|
|
3
3
|
import { isList, isReference } from "../step/values";
|
|
4
4
|
import { polylinePoints } from "./curves";
|
|
5
5
|
import { directionOf } from "./placement";
|
|
@@ -52,7 +52,7 @@ export function profileShape(reader, profile) {
|
|
|
52
52
|
function valueAt(f, point) {
|
|
53
53
|
return f.a * point[0] + f.b * point[1] + f.c;
|
|
54
54
|
}
|
|
55
|
-
function
|
|
55
|
+
function linearDifference(f, g) {
|
|
56
56
|
return { a: f.a - g.a, b: f.b - g.b, c: f.c - g.c };
|
|
57
57
|
}
|
|
58
58
|
function clipped(polygon, keep) {
|
|
@@ -66,7 +66,7 @@ function clipped(polygon, keep) {
|
|
|
66
66
|
}
|
|
67
67
|
if ((here < 0 && there > 0) || (here > 0 && there < 0)) {
|
|
68
68
|
const fraction = here / (here - there);
|
|
69
|
-
result.push(
|
|
69
|
+
result.push(between2(point, next, fraction));
|
|
70
70
|
}
|
|
71
71
|
});
|
|
72
72
|
return result;
|
|
@@ -96,9 +96,9 @@ function pairs(bounds) {
|
|
|
96
96
|
top,
|
|
97
97
|
bottom,
|
|
98
98
|
keeps: [
|
|
99
|
-
...tops.filter((_, j) => j !== k).map((other) =>
|
|
100
|
-
...bottoms.filter((_, j) => j !== m).map((other) =>
|
|
101
|
-
|
|
99
|
+
...tops.filter((_, j) => j !== k).map((other) => linearDifference(top, other)),
|
|
100
|
+
...bottoms.filter((_, j) => j !== m).map((other) => linearDifference(other, bottom)),
|
|
101
|
+
linearDifference(bottom, top),
|
|
102
102
|
...bounds.sides,
|
|
103
103
|
],
|
|
104
104
|
})));
|
|
@@ -109,7 +109,7 @@ function within(polygon, keeps) {
|
|
|
109
109
|
export function volumeBetween(footprint, bounds) {
|
|
110
110
|
return pairs(bounds).reduce((sum, { top, bottom, keeps }) => {
|
|
111
111
|
const region = within(footprint, keeps);
|
|
112
|
-
return sum + (region.length > 2 ? integral(region,
|
|
112
|
+
return sum + (region.length > 2 ? integral(region, linearDifference(top, bottom)) : 0);
|
|
113
113
|
}, 0);
|
|
114
114
|
}
|
|
115
115
|
export function areaWithin(footprint, sides) {
|
|
@@ -118,7 +118,7 @@ export function areaWithin(footprint, sides) {
|
|
|
118
118
|
}
|
|
119
119
|
export function areaBetween(start, end, bounds) {
|
|
120
120
|
const length = length2(subtract2(end, start));
|
|
121
|
-
const at = (f, s) => valueAt(f,
|
|
121
|
+
const at = (f, s) => valueAt(f, between2(start, end, s));
|
|
122
122
|
let low = 0;
|
|
123
123
|
let high = 1;
|
|
124
124
|
for (const side of bounds.sides) {
|
|
@@ -171,7 +171,7 @@ export function boundsOf(base, top, planes) {
|
|
|
171
171
|
sides: planes.filter((plane) => Math.abs(plane.normal[2]) <= UPRIGHT_NORMAL).map((plane) => ({
|
|
172
172
|
a: plane.normal[0],
|
|
173
173
|
b: plane.normal[1],
|
|
174
|
-
c: -(plane.origin[0]
|
|
174
|
+
c: -dot2([plane.origin[0], plane.origin[1]], [plane.normal[0], plane.normal[1]]),
|
|
175
175
|
})),
|
|
176
176
|
};
|
|
177
177
|
}
|
|
@@ -187,7 +187,7 @@ export function extrudedBodyOf(reader, product) {
|
|
|
187
187
|
const depth = reader.attribute(solid, "Depth");
|
|
188
188
|
const shape = isReference(profile) ? profileShape(reader, profile.ref) : undefined;
|
|
189
189
|
const direction = directionOf(reader, reader.attribute(solid, "ExtrudedDirection"), [0, 0, 1]);
|
|
190
|
-
const length =
|
|
190
|
+
const length = length3(direction);
|
|
191
191
|
if (!shape || typeof depth !== "number" || !(length > 0)) {
|
|
192
192
|
return undefined;
|
|
193
193
|
}
|
package/lib/build/moving.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { WORLD_AXES, relativeAxes } from "@bitbybit-dev/base/lib/api/services/helpers/frame-axes";
|
|
1
|
+
import { WORLD_AXES, relativeAxes } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/frame-axes";
|
|
2
2
|
import { isReference } from "../step/values";
|
|
3
|
-
import {
|
|
3
|
+
import { FILLING } from "./constants";
|
|
4
4
|
import { absoluteFrame, movePlacement, objectPlacementOf, productsPlacedBy } from "./placement";
|
|
5
5
|
import { firstItem, representationOf, unwrapClippings } from "./representations";
|
|
6
6
|
import { relatingOf } from "./relationships";
|
|
7
7
|
import { describeObject } from "./spatial";
|
|
8
8
|
import { joinsOf } from "./walls";
|
|
9
|
+
import { radiansOf } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/scalars";
|
|
10
|
+
import { add3, rotated2 } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/vectors";
|
|
9
11
|
const OPENING = "IfcOpeningElement";
|
|
10
12
|
const WALL = "IfcWall";
|
|
11
13
|
const ELEMENT = "IfcElement";
|
|
@@ -40,22 +42,21 @@ function clippingsOf(reader, wall) {
|
|
|
40
42
|
const body = representationOf(reader, wall, "Body");
|
|
41
43
|
return body === undefined ? [] : unwrapClippings(reader, firstItem(reader, body))[1];
|
|
42
44
|
}
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
+
function turnedAboutVertical(vector, angle) {
|
|
46
|
+
const [x, y] = rotated2([vector[0], vector[1]], angle);
|
|
47
|
+
return [x, y, vector[2]];
|
|
45
48
|
}
|
|
46
49
|
export function moveElement(tx, writer, element, translation, turnDegrees) {
|
|
47
50
|
const placement = objectPlacementOf(tx, element);
|
|
48
51
|
refuseUnmovable(tx, element, placement);
|
|
49
52
|
const parent = tx.attribute(placement, "PlacementRelTo");
|
|
50
53
|
const world = absoluteFrame(tx, placement);
|
|
51
|
-
const angle = turnDegrees
|
|
52
|
-
const cos = Math.cos(angle);
|
|
53
|
-
const sin = Math.sin(angle);
|
|
54
|
+
const angle = radiansOf(turnDegrees);
|
|
54
55
|
const moved = {
|
|
55
|
-
origin:
|
|
56
|
-
x:
|
|
57
|
-
y:
|
|
58
|
-
z:
|
|
56
|
+
origin: add3(world.origin, translation),
|
|
57
|
+
x: turnedAboutVertical(world.x, angle),
|
|
58
|
+
y: turnedAboutVertical(world.y, angle),
|
|
59
|
+
z: turnedAboutVertical(world.z, angle),
|
|
59
60
|
};
|
|
60
61
|
movePlacement(tx, writer, placement, relativeAxes(isReference(parent) ? absoluteFrame(tx, parent.ref) : WORLD_AXES, moved));
|
|
61
62
|
}
|
package/lib/build/openings.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { composeAxes, pointToLocal, pointToWorld, relativeAxes } from "@bitbybit-dev/base/lib/api/services/helpers/frame-axes";
|
|
1
|
+
import { composeAxes, pointToLocal, pointToWorld, relativeAxes } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/frame-axes";
|
|
2
2
|
import { enumValue, isList, isReference, ref } from "../step/values";
|
|
3
3
|
import { FILLING, OPENING_MARGIN_RATIO, VOIDING } from "./constants";
|
|
4
4
|
import { movePlacement, objectPlacementOf, parentPlacementOf, relativeFrame } from "./placement";
|
package/lib/build/outlines.d.ts
CHANGED
|
@@ -2,3 +2,5 @@ import type { Base } from "@bitbybit-dev/base";
|
|
|
2
2
|
export declare function cleanOutline(points: readonly Base.Point2[], tolerance: number, what: string): Base.Point2[];
|
|
3
3
|
export declare function isInsideOrOn(point: Base.Point2, outline: readonly Base.Point2[], tolerance: number): boolean;
|
|
4
4
|
export declare function edgesCross(first: readonly Base.Point2[], second: readonly Base.Point2[], tolerance: number): boolean;
|
|
5
|
+
export declare function cleanHoles(outer: readonly Base.Point2[], holes: readonly (readonly Base.Point2[])[], tolerance: number, owner: string): Base.Point2[][];
|
|
6
|
+
export declare function measuredFrom(points: readonly Base.Point2[], anchor: Base.Point2): Base.Point2[];
|
package/lib/build/outlines.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isInsidePolygon2, signedArea2 } from "@bitbybit-dev/base/lib/api/services/helpers/polygons";
|
|
2
|
-
import { cross2, length2, subtract2 } from "@bitbybit-dev/base/lib/api/services/helpers/vectors";
|
|
1
|
+
import { isInsidePolygon2, signedArea2, wound2 } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/polygons";
|
|
2
|
+
import { cross2, length2, subtract2 } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/vectors";
|
|
3
3
|
import { MIN_OUTLINE_POINTS } from "./constants";
|
|
4
4
|
import { distanceToSegment } from "./math";
|
|
5
5
|
export function cleanOutline(points, tolerance, what) {
|
|
@@ -38,3 +38,15 @@ export function edgesCross(first, second, tolerance) {
|
|
|
38
38
|
});
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
|
+
export function cleanHoles(outer, holes, tolerance, owner) {
|
|
42
|
+
return holes.map((hole, index) => {
|
|
43
|
+
const cleaned = cleanOutline(hole, tolerance, `hole ${index}`);
|
|
44
|
+
if (!cleaned.every((point) => isInsideOrOn(point, outer, tolerance)) || edgesCross(cleaned, outer, tolerance)) {
|
|
45
|
+
throw new Error(`Hole ${index} reaches outside the ${owner}'s outline`);
|
|
46
|
+
}
|
|
47
|
+
return wound2(cleaned, false);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
export function measuredFrom(points, anchor) {
|
|
51
|
+
return points.map((point) => subtract2(point, anchor));
|
|
52
|
+
}
|
package/lib/build/placement.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { WORLD_AXES, composeAxes } from "@bitbybit-dev/base/lib/api/services/helpers/frame-axes";
|
|
1
|
+
import { PARALLEL_SINE, WORLD_AXES, composeAxes } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/frame-axes";
|
|
2
|
+
import { cross3, length3 } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/vectors";
|
|
2
3
|
import { isList, isReference, ref } from "../step/values";
|
|
3
|
-
import { frameFrom } from "./math";
|
|
4
|
+
import { direction3Of, frameFrom } from "./math";
|
|
4
5
|
const MAX_PLACEMENT_DEPTH = 256;
|
|
5
6
|
const PRODUCT = "IfcProduct";
|
|
6
7
|
const LOCAL_PLACEMENT = "IfcLocalPlacement";
|
|
@@ -37,7 +38,7 @@ export function axisPlacementFrame(reader, placement) {
|
|
|
37
38
|
return frameFrom(origin, [0, 0, 1], [x[0], x[1], 0]);
|
|
38
39
|
}
|
|
39
40
|
const z = directionOf(reader, reader.attribute(placement, "Axis"), [0, 0, 1]);
|
|
40
|
-
const alongX =
|
|
41
|
+
const alongX = length3(cross3(direction3Of(z), [1, 0, 0])) <= PARALLEL_SINE;
|
|
41
42
|
const x = directionOf(reader, reader.attribute(placement, "RefDirection"), alongX ? [0, 1, 0] : [1, 0, 0]);
|
|
42
43
|
return frameFrom(origin, z, x);
|
|
43
44
|
}
|
package/lib/build/project.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WORLD_AXES } from "@bitbybit-dev/base/lib/api/services/helpers/frame-axes";
|
|
1
|
+
import { WORLD_AXES } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/frame-axes";
|
|
2
2
|
import { projectGlobalId, randomGlobalId } from "../model/guid";
|
|
3
3
|
import { emptyModel } from "../model/io";
|
|
4
4
|
import { IfcTransaction } from "../model/transaction";
|
package/lib/build/quantities.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { composeAxes } from "@bitbybit-dev/base/lib/api/services/helpers/frame-axes";
|
|
2
|
-
import { add2, scale2 } from "@bitbybit-dev/base/lib/api/services/helpers/vectors";
|
|
1
|
+
import { composeAxes } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/frame-axes";
|
|
2
|
+
import { add2, scale2 } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/vectors";
|
|
3
3
|
import { isList, isReference, ref, textValue } from "../step/values";
|
|
4
4
|
import { AGGREGATION, PROPERTY_DEFINITION, VOIDING } from "./constants";
|
|
5
5
|
import { areaBetween, areaWithin, boundsOf, extrudedBodyOf, profileShape, volumeBetween, withLevels } from "./measure";
|
|
@@ -12,7 +12,7 @@ import { firstItem, unwrapClippings } from "./representations";
|
|
|
12
12
|
import { clippingPlanes } from "./roof-clipping";
|
|
13
13
|
import { frameOf } from "./solids";
|
|
14
14
|
import { describeObject } from "./spatial";
|
|
15
|
-
import { readableWall, sideLine } from "./wall-geometry";
|
|
15
|
+
import { inOwnFrame, readableWall, sideLine } from "./wall-geometry";
|
|
16
16
|
import { placedOnPlan } from "./math";
|
|
17
17
|
const QUANTITY_ENTITIES = { length: "IfcQuantityLength", area: "IfcQuantityArea", volume: "IfcQuantityVolume" };
|
|
18
18
|
const VALUE_ATTRIBUTES = {
|
|
@@ -33,21 +33,22 @@ function quantity(name, kind, value) {
|
|
|
33
33
|
}
|
|
34
34
|
function wallSet(reader, wall, tolerance) {
|
|
35
35
|
var _a;
|
|
36
|
-
const
|
|
37
|
-
const items = (
|
|
38
|
-
if (!(
|
|
36
|
+
const placed = readableWall(reader, wall);
|
|
37
|
+
const items = (placed === null || placed === void 0 ? void 0 : placed.body) === undefined ? null : reader.attribute(placed.body, "Items");
|
|
38
|
+
if (!(placed === null || placed === void 0 ? void 0 : placed.body) || !isList(items) || items.length !== 1) {
|
|
39
39
|
return undefined;
|
|
40
40
|
}
|
|
41
|
-
const
|
|
41
|
+
const geometry = inOwnFrame(reader, placed);
|
|
42
|
+
const [solid, halfSpaces] = unwrapClippings(reader, firstItem(reader, placed.body));
|
|
42
43
|
const profile = reader.entity(solid).type === "IfcExtrudedAreaSolid" ? reader.attribute(solid, "SweptArea") : null;
|
|
43
44
|
const outline = isReference(profile) ? (_a = profileShape(reader, profile.ref)) === null || _a === void 0 ? void 0 : _a.outline : undefined;
|
|
44
45
|
if (!outline || halfSpaces.some((halfSpace) => reader.entity(halfSpace).type !== PLAIN_HALF_SPACE)) {
|
|
45
46
|
return undefined;
|
|
46
47
|
}
|
|
47
|
-
const solidFrame =
|
|
48
|
+
const solidFrame = frameOf(reader, reader.attribute(solid, "Position"));
|
|
48
49
|
const footprint = outline.map((point) => placedOnPlan(solidFrame, point));
|
|
49
|
-
const base = geometry.
|
|
50
|
-
const bounds = boundsOf(base, base + geometry.height, clippingPlanes(reader, geometry,
|
|
50
|
+
const base = geometry.base;
|
|
51
|
+
const bounds = boundsOf(base, base + geometry.height, clippingPlanes(reader, geometry, placed.body));
|
|
51
52
|
const thickness = geometry.high - geometry.low;
|
|
52
53
|
const middle = sideLine(geometry, (geometry.low + geometry.high) / 2);
|
|
53
54
|
const along = (distance) => add2(middle.point, scale2(middle.direction, distance));
|
|
@@ -126,7 +127,8 @@ function fillingSet(reader, filling, name) {
|
|
|
126
127
|
}
|
|
127
128
|
function openingSet(reader, opening, tolerance) {
|
|
128
129
|
const host = relatingOf(reader, VOIDING, opening);
|
|
129
|
-
const
|
|
130
|
+
const placed = host === undefined ? undefined : readableWall(reader, host);
|
|
131
|
+
const wall = placed === undefined ? undefined : inOwnFrame(reader, placed);
|
|
130
132
|
const place = wall === undefined || host === undefined ? undefined : readWallOpening(reader, wall, objectPlacementOf(reader, host), opening, tolerance);
|
|
131
133
|
if (!wall || !place) {
|
|
132
134
|
return undefined;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { composeAxes, vectorToWorld } from "@bitbybit-dev/base/lib/api/services/helpers/frame-axes";
|
|
2
|
-
import { add2, dot3, scale2, scale3 } from "@bitbybit-dev/base/lib/api/services/helpers/vectors";
|
|
1
|
+
import { composeAxes, vectorToWorld } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/frame-axes";
|
|
2
|
+
import { add2, add3, dot3, scale2, scale3 } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/vectors";
|
|
3
3
|
import { isReference } from "../step/values";
|
|
4
4
|
import { AGGREGATION, VERTICAL_COSINE } from "./constants";
|
|
5
|
-
import {
|
|
5
|
+
import { direction3Of } from "./math";
|
|
6
6
|
import { absoluteFrame, axisPlacementFrame, directionOf, objectPlacementOf } from "./placement";
|
|
7
7
|
import { relatedOf } from "./relationships";
|
|
8
8
|
import { firstItem, representationOf, unwrapClippings } from "./representations";
|
|
@@ -22,9 +22,9 @@ function undersideOf(reader, part) {
|
|
|
22
22
|
}
|
|
23
23
|
const up = frame.z[2] > 0 ? frame.z : scale3(frame.z, -1);
|
|
24
24
|
const depth = reader.attribute(solid, "Depth");
|
|
25
|
-
const through = vectorToWorld(frame,
|
|
25
|
+
const through = vectorToWorld(frame, direction3Of(directionOf(reader, reader.attribute(solid, "ExtrudedDirection"), [0, 0, 1])));
|
|
26
26
|
const far = scale3(through, typeof depth === "number" ? depth : 0);
|
|
27
|
-
const farPoint =
|
|
27
|
+
const farPoint = add3(frame.origin, far);
|
|
28
28
|
return { origin: dot3(farPoint, up) < dot3(frame.origin, up) ? farPoint : frame.origin, normal: up };
|
|
29
29
|
}
|
|
30
30
|
function heightAt(plane, point) {
|