@buerli.io/core 0.5.0-beta.1 → 0.5.0-beta.3
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/build/cjs/geometry/ThreeGeometryCreator.js +321 -0
- package/build/cjs/geometry/index.js +17 -0
- package/build/cjs/graphic/filters.js +25 -0
- package/build/cjs/index.js +25 -0
- package/build/cjs/store/index.js +37 -0
- package/build/cjs/store/states/buerli.js +98 -0
- package/build/cjs/store/states/cad.js +35 -0
- package/build/cjs/store/states/drawing.js +47 -0
- package/build/cjs/store/states/geometry.js +139 -0
- package/build/cjs/store/states/graphic.js +115 -0
- package/build/cjs/store/states/interaction.js +55 -0
- package/build/cjs/store/states/message.js +25 -0
- package/build/cjs/store/states/plugin.js +115 -0
- package/build/cjs/store/states/selection.js +258 -0
- package/build/cjs/store/states/structure.js +239 -0
- package/build/cjs/store/store.js +9 -0
- package/build/cjs/store/subscribtion/selection.js +46 -0
- package/build/cjs/store/subscribtion/subscribeToDrawing.js +13 -0
- package/build/cjs/types/IGraphicPackage.js +49 -0
- package/build/cjs/types/IStructurePatch.js +2 -0
- package/build/cjs/types/IStructureTree.js +27 -0
- package/build/cjs/types/InteractionInfo.js +11 -0
- package/build/cjs/types/index.js +20 -0
- package/build/cjs/utils/Math.js +91 -0
- package/build/cjs/utils/Measure.js +560 -0
- package/build/cjs/utils/Timing.js +34 -0
- package/build/{geometry → esm/geometry}/ThreeGeometryCreator.js +0 -0
- package/build/{geometry → esm/geometry}/index.js +0 -0
- package/build/{graphic → esm/graphic}/filters.js +0 -0
- package/build/{index.js → esm/index.js} +0 -0
- package/build/{store → esm/store}/index.js +0 -0
- package/build/{store → esm/store}/states/buerli.js +0 -0
- package/build/{store → esm/store}/states/cad.js +0 -0
- package/build/{store → esm/store}/states/drawing.js +0 -0
- package/build/{store → esm/store}/states/geometry.js +0 -0
- package/build/{store → esm/store}/states/graphic.js +0 -0
- package/build/{store → esm/store}/states/interaction.js +0 -0
- package/build/{store → esm/store}/states/message.js +0 -0
- package/build/{store → esm/store}/states/plugin.js +0 -0
- package/build/{store → esm/store}/states/selection.js +0 -0
- package/build/{store → esm/store}/states/structure.js +0 -0
- package/build/{store → esm/store}/store.js +0 -0
- package/build/{store → esm/store}/subscribtion/selection.js +0 -0
- package/build/{store → esm/store}/subscribtion/subscribeToDrawing.js +0 -0
- package/build/{types → esm/types}/IGraphicPackage.js +0 -0
- package/build/{types → esm/types}/IStructurePatch.js +0 -0
- package/build/{types → esm/types}/IStructureTree.js +0 -0
- package/build/{types → esm/types}/InteractionInfo.js +0 -0
- package/build/{types → esm/types}/index.js +0 -0
- package/build/{utils → esm/utils}/Math.js +0 -0
- package/build/{utils → esm/utils}/Measure.js +0 -0
- package/build/{utils → esm/utils}/Timing.js +0 -0
- package/build/{geometry → types/geometry}/ThreeGeometryCreator.d.ts +0 -0
- package/build/{geometry → types/geometry}/index.d.ts +0 -0
- package/build/{graphic → types/graphic}/filters.d.ts +0 -0
- package/build/types/index.d.ts +37 -4
- package/build/{store → types/store}/index.d.ts +0 -0
- package/build/{store → types/store}/states/buerli.d.ts +0 -0
- package/build/{store → types/store}/states/cad.d.ts +0 -0
- package/build/{store → types/store}/states/drawing.d.ts +0 -0
- package/build/{store → types/store}/states/geometry.d.ts +0 -0
- package/build/{store → types/store}/states/graphic.d.ts +0 -0
- package/build/{store → types/store}/states/interaction.d.ts +0 -0
- package/build/{store → types/store}/states/message.d.ts +0 -0
- package/build/{store → types/store}/states/plugin.d.ts +0 -0
- package/build/{store → types/store}/states/selection.d.ts +0 -0
- package/build/{store → types/store}/states/structure.d.ts +0 -0
- package/build/{store → types/store}/store.d.ts +0 -0
- package/build/{store → types/store}/subscribtion/selection.d.ts +0 -0
- package/build/{store → types/store}/subscribtion/subscribeToDrawing.d.ts +0 -0
- package/build/types/{IGraphicPackage.d.ts → types/IGraphicPackage.d.ts} +0 -0
- package/build/types/{IStructurePatch.d.ts → types/IStructurePatch.d.ts} +0 -0
- package/build/types/{IStructureTree.d.ts → types/IStructureTree.d.ts} +0 -0
- package/build/types/{InteractionInfo.d.ts → types/InteractionInfo.d.ts} +0 -0
- package/build/types/types/index.d.ts +4 -0
- package/build/{utils → types/utils}/Math.d.ts +0 -0
- package/build/{utils → types/utils}/Measure.d.ts +0 -0
- package/build/{utils → types/utils}/Timing.d.ts +0 -0
- package/package.json +7 -7
- package/build/index.d.ts +0 -37
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./IGraphicPackage"), exports);
|
|
18
|
+
__exportStar(require("./InteractionInfo"), exports);
|
|
19
|
+
__exportStar(require("./IStructurePatch"), exports);
|
|
20
|
+
__exportStar(require("./IStructureTree"), exports);
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.MathUtils = void 0;
|
|
27
|
+
const THREE = __importStar(require("three"));
|
|
28
|
+
const degToRad = THREE.MathUtils.degToRad;
|
|
29
|
+
const tolerance = 1e-6;
|
|
30
|
+
exports.MathUtils = {
|
|
31
|
+
convertToMatrix4: function (coordinateSystem) {
|
|
32
|
+
const [orig, vx, vy, vz] = coordinateSystem.map(row => new THREE.Vector3().fromArray(row));
|
|
33
|
+
return new THREE.Matrix4().makeBasis(vx, vy, vz).setPosition(orig);
|
|
34
|
+
},
|
|
35
|
+
convertToMatrix3: function (coordinateSystem) {
|
|
36
|
+
const [, vx, vy, vz] = coordinateSystem;
|
|
37
|
+
return new THREE.Matrix3().fromArray([...vx, ...vy, ...vz]);
|
|
38
|
+
},
|
|
39
|
+
convertToCoordinateSystem: function (matrix) {
|
|
40
|
+
const position = new THREE.Vector3();
|
|
41
|
+
const xAxis = new THREE.Vector3();
|
|
42
|
+
const yAxis = new THREE.Vector3();
|
|
43
|
+
const zAxis = new THREE.Vector3();
|
|
44
|
+
position.setFromMatrixPosition(matrix);
|
|
45
|
+
matrix.extractBasis(xAxis, yAxis, zAxis);
|
|
46
|
+
const coordSys = [];
|
|
47
|
+
coordSys[0] = [position.x, position.y, position.z];
|
|
48
|
+
coordSys[1] = [xAxis.x, xAxis.y, xAxis.z];
|
|
49
|
+
coordSys[2] = [yAxis.x, yAxis.y, yAxis.z];
|
|
50
|
+
coordSys[3] = [zAxis.x, zAxis.y, zAxis.z];
|
|
51
|
+
return coordSys;
|
|
52
|
+
},
|
|
53
|
+
round(value, digits) {
|
|
54
|
+
if (isNaN(value))
|
|
55
|
+
return NaN;
|
|
56
|
+
const factor = Math.pow(10, digits);
|
|
57
|
+
return Math.round(value * factor) / factor;
|
|
58
|
+
},
|
|
59
|
+
/**
|
|
60
|
+
* Calculates a transformation matrix.
|
|
61
|
+
*
|
|
62
|
+
* xDir and yDir are NOT orthogonal in general case, thus the y-axis is calculated as a series of cross products.
|
|
63
|
+
*
|
|
64
|
+
* @param originPos The origin position.
|
|
65
|
+
* @param xDir The x direction.
|
|
66
|
+
* @param yDir The y direction.
|
|
67
|
+
* @param offset The offset vector.
|
|
68
|
+
* @param rotation The rotation vector.
|
|
69
|
+
* @param inverted The inverted flag --- 0: do not invert; 1: do invert.
|
|
70
|
+
* @returns The calculated THREE.Matrix4
|
|
71
|
+
*/
|
|
72
|
+
calcluateTransform: function (originPos, xDir, yDir, offset, rotation, inverted) {
|
|
73
|
+
rotation = new THREE.Vector3(degToRad(rotation.x), degToRad(rotation.y), degToRad(rotation.z));
|
|
74
|
+
const xAxis = xDir.clone().normalize();
|
|
75
|
+
let yDir_ = yDir.clone().normalize();
|
|
76
|
+
if (Math.abs(yDir_.dot(xAxis.clone())) > 1 - tolerance) {
|
|
77
|
+
yDir_ = Math.abs(xAxis.y) !== 1 ? new THREE.Vector3(0.0, 1.0, 0.0) : new THREE.Vector3(1.0, 0.0, 0.0);
|
|
78
|
+
}
|
|
79
|
+
const zAxis = xAxis.clone().cross(yDir_).normalize();
|
|
80
|
+
const yAxis = zAxis.clone().cross(xAxis).normalize();
|
|
81
|
+
if (inverted) {
|
|
82
|
+
xAxis.negate();
|
|
83
|
+
zAxis.negate();
|
|
84
|
+
}
|
|
85
|
+
const mLocal = new THREE.Matrix4()
|
|
86
|
+
.makeRotationFromEuler(new THREE.Euler(rotation.x, rotation.y, rotation.z))
|
|
87
|
+
.setPosition(offset.x, offset.y, offset.z);
|
|
88
|
+
const mGlobal = new THREE.Matrix4().makeBasis(xAxis, yAxis, zAxis).setPosition(originPos);
|
|
89
|
+
return mGlobal.clone().multiply(mLocal);
|
|
90
|
+
},
|
|
91
|
+
};
|
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.Measure = exports.MeasureResultType = void 0;
|
|
27
|
+
/* eslint-disable max-lines */
|
|
28
|
+
const THREE = __importStar(require("three"));
|
|
29
|
+
const store_1 = require("./../store");
|
|
30
|
+
const types_1 = require("./../types");
|
|
31
|
+
var MeasureResultType;
|
|
32
|
+
(function (MeasureResultType) {
|
|
33
|
+
MeasureResultType["NONE"] = "none";
|
|
34
|
+
MeasureResultType["VALUE"] = "value";
|
|
35
|
+
MeasureResultType["DISTANCE"] = "linear";
|
|
36
|
+
MeasureResultType["ANGLE"] = "angular";
|
|
37
|
+
MeasureResultType["VECTOR"] = "vector";
|
|
38
|
+
MeasureResultType["POSITION"] = "position";
|
|
39
|
+
})(MeasureResultType = exports.MeasureResultType || (exports.MeasureResultType = {}));
|
|
40
|
+
const tolerance = 1e-3;
|
|
41
|
+
exports.Measure = {
|
|
42
|
+
transform(items, drawingId) {
|
|
43
|
+
const drawing = (0, store_1.getDrawing)(drawingId);
|
|
44
|
+
const transformed = [];
|
|
45
|
+
for (const item of items) {
|
|
46
|
+
const matrix = drawing.api.structure.calculateGlobalTransformation(item.productId);
|
|
47
|
+
const matrix3 = new THREE.Matrix3().setFromMatrix4(matrix);
|
|
48
|
+
const newItem = Object.assign({}, item);
|
|
49
|
+
switch (newItem.type) {
|
|
50
|
+
case types_1.GraphicType.POINT:
|
|
51
|
+
case types_1.GraphicType.CURVEPOINT:
|
|
52
|
+
const point = newItem;
|
|
53
|
+
point.position = point.position.clone().applyMatrix4(matrix);
|
|
54
|
+
break;
|
|
55
|
+
case types_1.GraphicType.LINE:
|
|
56
|
+
case types_1.GraphicType.CURVELINE:
|
|
57
|
+
const line = newItem;
|
|
58
|
+
line.start = line.start.clone().applyMatrix4(matrix);
|
|
59
|
+
line.end = line.end.clone().applyMatrix4(matrix);
|
|
60
|
+
break;
|
|
61
|
+
case types_1.GraphicType.PLANE:
|
|
62
|
+
const plane = newItem;
|
|
63
|
+
plane.normal = plane.normal.clone().applyMatrix3(matrix3);
|
|
64
|
+
plane.normal.normalize();
|
|
65
|
+
plane.pointOnPlane = plane.pointOnPlane.clone().applyMatrix4(matrix);
|
|
66
|
+
break;
|
|
67
|
+
case types_1.GraphicType.CYLINDER:
|
|
68
|
+
const cylinder = newItem;
|
|
69
|
+
cylinder.axis = cylinder.axis.clone().applyMatrix3(matrix3);
|
|
70
|
+
cylinder.axis.normalize();
|
|
71
|
+
cylinder.origin = cylinder.origin.clone().applyMatrix4(matrix);
|
|
72
|
+
break;
|
|
73
|
+
case types_1.GraphicType.CONE:
|
|
74
|
+
const cone = newItem;
|
|
75
|
+
cone.axis = cone.axis.clone().applyMatrix3(matrix3);
|
|
76
|
+
cone.axis.normalize();
|
|
77
|
+
cone.origin = cone.origin.clone().applyMatrix4(matrix);
|
|
78
|
+
break;
|
|
79
|
+
case types_1.GraphicType.ARC:
|
|
80
|
+
case types_1.GraphicType.CURVEARC:
|
|
81
|
+
const arc = newItem;
|
|
82
|
+
arc.normal = arc.normal.clone().applyMatrix3(matrix3);
|
|
83
|
+
arc.normal.normalize();
|
|
84
|
+
arc.center = arc.center.clone().applyMatrix4(matrix);
|
|
85
|
+
break;
|
|
86
|
+
case types_1.GraphicType.CIRCLE:
|
|
87
|
+
case types_1.GraphicType.CURVECIRCLE:
|
|
88
|
+
const circle = newItem;
|
|
89
|
+
circle.normal = circle.normal.clone().applyMatrix3(matrix3);
|
|
90
|
+
circle.normal.normalize();
|
|
91
|
+
circle.center = circle.center.clone().applyMatrix4(matrix);
|
|
92
|
+
break;
|
|
93
|
+
default:
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
transformed.push(newItem);
|
|
97
|
+
}
|
|
98
|
+
return transformed;
|
|
99
|
+
},
|
|
100
|
+
getInfo(objects, drawingId) {
|
|
101
|
+
const transformed = exports.Measure.transform(objects, drawingId);
|
|
102
|
+
const results = [];
|
|
103
|
+
const dir = (start, end) => end.clone().sub(start).normalize();
|
|
104
|
+
const getPointOnCircumference = (center, axis, radius) => {
|
|
105
|
+
const axisNormalized = axis.clone().normalize();
|
|
106
|
+
const helperVec = axisNormalized.x !== 1 ? new THREE.Vector3(1, 0, 0) : new THREE.Vector3(0, 1, 0);
|
|
107
|
+
const tangent = axisNormalized.clone().cross(helperVec).normalize();
|
|
108
|
+
return center.clone().addScaledVector(tangent, radius);
|
|
109
|
+
};
|
|
110
|
+
for (const element of transformed) {
|
|
111
|
+
switch (element.type) {
|
|
112
|
+
case types_1.GraphicType.POINT:
|
|
113
|
+
case types_1.GraphicType.CURVEPOINT:
|
|
114
|
+
const point = element;
|
|
115
|
+
results.push({
|
|
116
|
+
description: 'Position',
|
|
117
|
+
type: MeasureResultType.POSITION,
|
|
118
|
+
measureData: { value: point.position.clone() },
|
|
119
|
+
});
|
|
120
|
+
break;
|
|
121
|
+
case types_1.GraphicType.LINE:
|
|
122
|
+
case types_1.GraphicType.CURVELINE:
|
|
123
|
+
const line = element;
|
|
124
|
+
const absoluteDistance = line.start.distanceTo(line.end);
|
|
125
|
+
results.push({
|
|
126
|
+
description: 'Line length',
|
|
127
|
+
type: MeasureResultType.DISTANCE,
|
|
128
|
+
measureData: { value: absoluteDistance, start: line.start.clone(), end: line.end.clone() },
|
|
129
|
+
});
|
|
130
|
+
break;
|
|
131
|
+
case types_1.GraphicType.EDGE:
|
|
132
|
+
case types_1.GraphicType.CURVESPLINE:
|
|
133
|
+
const edge = element;
|
|
134
|
+
results.push({
|
|
135
|
+
description: 'Edge start',
|
|
136
|
+
type: MeasureResultType.POSITION,
|
|
137
|
+
measureData: { value: edge.start.clone() },
|
|
138
|
+
});
|
|
139
|
+
results.push({
|
|
140
|
+
description: 'Edge end',
|
|
141
|
+
type: MeasureResultType.POSITION,
|
|
142
|
+
measureData: { value: edge.start.clone() },
|
|
143
|
+
});
|
|
144
|
+
break;
|
|
145
|
+
case types_1.GraphicType.ARC:
|
|
146
|
+
case types_1.GraphicType.CURVEARC:
|
|
147
|
+
const arc = element;
|
|
148
|
+
const arcNEnd = arc.center.clone().addScaledVector(arc.normal.clone().normalize(), 40);
|
|
149
|
+
const pointOnArc = getPointOnCircumference(arc.center, arc.normal, arc.radius);
|
|
150
|
+
results.push({
|
|
151
|
+
description: 'Arc center',
|
|
152
|
+
type: MeasureResultType.POSITION,
|
|
153
|
+
measureData: { value: arc.center.clone() },
|
|
154
|
+
});
|
|
155
|
+
results.push({
|
|
156
|
+
description: 'Arc normal',
|
|
157
|
+
type: MeasureResultType.VECTOR,
|
|
158
|
+
measureData: { value: arc.normal.clone(), start: arc.center.clone(), end: arcNEnd },
|
|
159
|
+
});
|
|
160
|
+
results.push({
|
|
161
|
+
description: 'Arc radius',
|
|
162
|
+
type: MeasureResultType.DISTANCE,
|
|
163
|
+
measureData: { value: arc.radius, start: arc.center.clone(), end: pointOnArc },
|
|
164
|
+
});
|
|
165
|
+
break;
|
|
166
|
+
case types_1.GraphicType.CIRCLE:
|
|
167
|
+
case types_1.GraphicType.CURVECIRCLE:
|
|
168
|
+
const circle = element;
|
|
169
|
+
const circleNEnd = circle.center.clone().addScaledVector(circle.normal.clone().normalize(), 40);
|
|
170
|
+
const pointOnCircle = getPointOnCircumference(circle.center, circle.normal, circle.radius);
|
|
171
|
+
results.push({
|
|
172
|
+
description: 'Circle center',
|
|
173
|
+
type: MeasureResultType.POSITION,
|
|
174
|
+
measureData: { value: circle.center.clone() },
|
|
175
|
+
});
|
|
176
|
+
results.push({
|
|
177
|
+
description: 'Circle normal',
|
|
178
|
+
type: MeasureResultType.VECTOR,
|
|
179
|
+
measureData: { value: circle.normal.clone(), start: circle.center.clone(), end: circleNEnd },
|
|
180
|
+
});
|
|
181
|
+
results.push({
|
|
182
|
+
description: 'Circle radius',
|
|
183
|
+
type: MeasureResultType.DISTANCE,
|
|
184
|
+
measureData: { value: circle.radius, start: circle.center.clone(), end: pointOnCircle },
|
|
185
|
+
});
|
|
186
|
+
break;
|
|
187
|
+
case types_1.GraphicType.PLANE:
|
|
188
|
+
const plane = element;
|
|
189
|
+
const planeNEnd = plane.pointOnPlane.clone().addScaledVector(plane.normal.clone().normalize(), 40);
|
|
190
|
+
results.push({
|
|
191
|
+
description: 'Plane normal',
|
|
192
|
+
type: MeasureResultType.VECTOR,
|
|
193
|
+
measureData: { value: plane.normal, start: plane.pointOnPlane.clone(), end: planeNEnd },
|
|
194
|
+
});
|
|
195
|
+
break;
|
|
196
|
+
case types_1.GraphicType.CYLINDER:
|
|
197
|
+
const cylinder = element;
|
|
198
|
+
const cylAxisNormalized = cylinder.axis.clone().normalize();
|
|
199
|
+
const cylNEnd = cylinder.origin.clone().addScaledVector(cylAxisNormalized, cylinder.height + 40);
|
|
200
|
+
const pointOnCyl = getPointOnCircumference(cylinder.origin, cylinder.axis, cylinder.radius);
|
|
201
|
+
const cylHStart = cylinder.origin
|
|
202
|
+
.clone()
|
|
203
|
+
.addScaledVector(dir(cylinder.origin, pointOnCyl), cylinder.radius + 3);
|
|
204
|
+
const cylHEnd = cylHStart.clone().addScaledVector(cylAxisNormalized, cylinder.height);
|
|
205
|
+
results.push({
|
|
206
|
+
description: 'Cylinder origin',
|
|
207
|
+
type: MeasureResultType.POSITION,
|
|
208
|
+
measureData: { value: cylinder.origin.clone() },
|
|
209
|
+
});
|
|
210
|
+
results.push({
|
|
211
|
+
description: 'Cylinder axis',
|
|
212
|
+
type: MeasureResultType.VECTOR,
|
|
213
|
+
measureData: { value: cylinder.axis, start: cylinder.origin.clone(), end: cylNEnd },
|
|
214
|
+
});
|
|
215
|
+
results.push({
|
|
216
|
+
description: 'Cylinder radius',
|
|
217
|
+
type: MeasureResultType.DISTANCE,
|
|
218
|
+
measureData: { value: cylinder.radius, start: cylinder.origin.clone(), end: pointOnCyl },
|
|
219
|
+
});
|
|
220
|
+
results.push({
|
|
221
|
+
description: 'Cylinder height',
|
|
222
|
+
type: MeasureResultType.DISTANCE,
|
|
223
|
+
measureData: { value: cylinder.height, start: cylHStart, end: cylHEnd },
|
|
224
|
+
});
|
|
225
|
+
break;
|
|
226
|
+
case types_1.GraphicType.CONE:
|
|
227
|
+
const cone = element;
|
|
228
|
+
const isExpanding = cone.radiusBottom < cone.radiusTop;
|
|
229
|
+
const R = Math.max(cone.radiusBottom, cone.radiusTop);
|
|
230
|
+
const r = Math.min(cone.radiusBottom, cone.radiusTop);
|
|
231
|
+
const coneAxisNormalized = cone.axis.clone().normalize();
|
|
232
|
+
const coneCenterTop = cone.origin.clone().addScaledVector(coneAxisNormalized, cone.height);
|
|
233
|
+
const coneEnd = coneCenterTop.clone().addScaledVector(coneAxisNormalized, 40);
|
|
234
|
+
const coneCenterMinR = isExpanding ? cone.origin.clone() : coneCenterTop.clone();
|
|
235
|
+
const coneCenterMaxR = isExpanding ? coneCenterTop.clone() : cone.origin.clone();
|
|
236
|
+
const pointOnConeBottom = getPointOnCircumference(cone.origin, cone.axis, cone.radiusBottom);
|
|
237
|
+
const pointOnConeTop = getPointOnCircumference(coneCenterTop, cone.axis, cone.radiusTop);
|
|
238
|
+
const pointOnConeMinR = isExpanding ? pointOnConeBottom : pointOnConeTop;
|
|
239
|
+
const pointOnConeMaxR = isExpanding ? pointOnConeTop : pointOnConeBottom;
|
|
240
|
+
const coneHStart = coneCenterMaxR.clone().addScaledVector(dir(coneCenterMaxR, pointOnConeMaxR), R + 3);
|
|
241
|
+
const coneHEnd = coneHStart
|
|
242
|
+
.clone()
|
|
243
|
+
.addScaledVector(coneAxisNormalized, isExpanding ? -cone.height : cone.height);
|
|
244
|
+
results.push({
|
|
245
|
+
description: 'Cone origin',
|
|
246
|
+
type: MeasureResultType.POSITION,
|
|
247
|
+
measureData: { value: cone.origin.clone() },
|
|
248
|
+
});
|
|
249
|
+
results.push({
|
|
250
|
+
description: 'Cone axis',
|
|
251
|
+
type: MeasureResultType.VECTOR,
|
|
252
|
+
measureData: { value: cone.axis, start: cone.origin.clone(), end: coneEnd },
|
|
253
|
+
});
|
|
254
|
+
results.push({
|
|
255
|
+
description: 'Cone radius (min)',
|
|
256
|
+
type: MeasureResultType.DISTANCE,
|
|
257
|
+
measureData: { value: r, start: coneCenterMinR, end: pointOnConeMinR },
|
|
258
|
+
});
|
|
259
|
+
results.push({
|
|
260
|
+
description: 'Cone radius (max)',
|
|
261
|
+
type: MeasureResultType.DISTANCE,
|
|
262
|
+
measureData: { value: R, start: coneCenterMaxR, end: pointOnConeMaxR },
|
|
263
|
+
});
|
|
264
|
+
results.push({
|
|
265
|
+
description: 'Cone height',
|
|
266
|
+
type: MeasureResultType.DISTANCE,
|
|
267
|
+
measureData: { value: cone.height, start: coneHStart, end: coneHEnd },
|
|
268
|
+
});
|
|
269
|
+
break;
|
|
270
|
+
case types_1.GraphicType.SPHERE:
|
|
271
|
+
const sphere = element;
|
|
272
|
+
results.push({
|
|
273
|
+
description: 'Sphere radius',
|
|
274
|
+
type: MeasureResultType.VALUE,
|
|
275
|
+
measureData: { value: sphere.radius },
|
|
276
|
+
});
|
|
277
|
+
break;
|
|
278
|
+
case types_1.GraphicType.NURBS:
|
|
279
|
+
results.push({ description: 'NURBS', type: MeasureResultType.NONE });
|
|
280
|
+
break;
|
|
281
|
+
case types_1.GraphicType.NURBSSURFACE:
|
|
282
|
+
results.push({ description: 'NURBS Surface', type: MeasureResultType.NONE });
|
|
283
|
+
break;
|
|
284
|
+
default:
|
|
285
|
+
results.push({ description: 'Undefined', type: MeasureResultType.NONE });
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return results;
|
|
290
|
+
},
|
|
291
|
+
calculateMeasures(objects, drawingId) {
|
|
292
|
+
const transformed = exports.Measure.transform(objects, drawingId);
|
|
293
|
+
const first = transformed[0];
|
|
294
|
+
const second = transformed[1];
|
|
295
|
+
let results = [];
|
|
296
|
+
switch (first.type) {
|
|
297
|
+
case types_1.GraphicType.POINT:
|
|
298
|
+
case types_1.GraphicType.CURVEPOINT:
|
|
299
|
+
switch (second.type) {
|
|
300
|
+
case types_1.GraphicType.POINT:
|
|
301
|
+
case types_1.GraphicType.CURVEPOINT:
|
|
302
|
+
results = exports.Measure.calculatePointPoint(first.position, second.position);
|
|
303
|
+
break;
|
|
304
|
+
case types_1.GraphicType.LINE:
|
|
305
|
+
case types_1.GraphicType.CURVELINE:
|
|
306
|
+
results = exports.Measure.calculatePointLine(first, second);
|
|
307
|
+
break;
|
|
308
|
+
case types_1.GraphicType.PLANE:
|
|
309
|
+
results = exports.Measure.calculatePointPlane(first, second);
|
|
310
|
+
break;
|
|
311
|
+
case types_1.GraphicType.ARC:
|
|
312
|
+
case types_1.GraphicType.CIRCLE:
|
|
313
|
+
results = exports.Measure.calculatePointPoint(first.position.clone(), second.center.clone());
|
|
314
|
+
break;
|
|
315
|
+
default:
|
|
316
|
+
results = exports.Measure.getInfo(objects, drawingId);
|
|
317
|
+
break;
|
|
318
|
+
}
|
|
319
|
+
break;
|
|
320
|
+
case types_1.GraphicType.LINE:
|
|
321
|
+
case types_1.GraphicType.CURVELINE:
|
|
322
|
+
switch (second.type) {
|
|
323
|
+
case types_1.GraphicType.POINT:
|
|
324
|
+
case types_1.GraphicType.CURVEPOINT:
|
|
325
|
+
results = exports.Measure.calculatePointLine(second, first);
|
|
326
|
+
break;
|
|
327
|
+
case types_1.GraphicType.LINE:
|
|
328
|
+
case types_1.GraphicType.CURVELINE:
|
|
329
|
+
results = exports.Measure.calculateLineLine(first, second);
|
|
330
|
+
break;
|
|
331
|
+
case types_1.GraphicType.PLANE:
|
|
332
|
+
results = exports.Measure.calculateLinePlane(first, second);
|
|
333
|
+
break;
|
|
334
|
+
default:
|
|
335
|
+
results = exports.Measure.getInfo(objects, drawingId);
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
break;
|
|
339
|
+
case types_1.GraphicType.CIRCLE:
|
|
340
|
+
case types_1.GraphicType.ARC:
|
|
341
|
+
switch (second.type) {
|
|
342
|
+
case types_1.GraphicType.ARC:
|
|
343
|
+
case types_1.GraphicType.CIRCLE:
|
|
344
|
+
results = exports.Measure.calculatePointPoint(first.center, second.center);
|
|
345
|
+
break;
|
|
346
|
+
case types_1.GraphicType.POINT:
|
|
347
|
+
results = exports.Measure.calculatePointPoint(first.center, second.position);
|
|
348
|
+
break;
|
|
349
|
+
default:
|
|
350
|
+
results = exports.Measure.getInfo(objects, drawingId);
|
|
351
|
+
break;
|
|
352
|
+
}
|
|
353
|
+
break;
|
|
354
|
+
case types_1.GraphicType.PLANE:
|
|
355
|
+
switch (second.type) {
|
|
356
|
+
case types_1.GraphicType.POINT:
|
|
357
|
+
case types_1.GraphicType.CURVEPOINT:
|
|
358
|
+
results = exports.Measure.calculatePointPlane(second, first);
|
|
359
|
+
break;
|
|
360
|
+
case types_1.GraphicType.LINE:
|
|
361
|
+
case types_1.GraphicType.CURVELINE:
|
|
362
|
+
results = exports.Measure.calculateLinePlane(second, first);
|
|
363
|
+
break;
|
|
364
|
+
case types_1.GraphicType.ARC:
|
|
365
|
+
case types_1.GraphicType.CURVEARC:
|
|
366
|
+
results = exports.Measure.calculateArcPlane(second, first);
|
|
367
|
+
break;
|
|
368
|
+
case types_1.GraphicType.PLANE:
|
|
369
|
+
results = exports.Measure.calculatePlanePlane(first, second);
|
|
370
|
+
break;
|
|
371
|
+
default:
|
|
372
|
+
results = exports.Measure.getInfo(objects, drawingId);
|
|
373
|
+
break;
|
|
374
|
+
}
|
|
375
|
+
break;
|
|
376
|
+
default:
|
|
377
|
+
results = exports.Measure.getInfo(objects, drawingId);
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
return results;
|
|
381
|
+
},
|
|
382
|
+
calculatePointPoint(point1, point2) {
|
|
383
|
+
const p1 = point1.clone();
|
|
384
|
+
const p2 = point2.clone();
|
|
385
|
+
const distance = p1.distanceTo(p2);
|
|
386
|
+
const dx = Math.abs(p1.x - p2.x);
|
|
387
|
+
const dy = Math.abs(p1.y - p2.y);
|
|
388
|
+
const dz = Math.abs(p1.z - p2.z);
|
|
389
|
+
const px = p1.clone().setX(p2.x);
|
|
390
|
+
const pxy = px.clone().setY(p2.y);
|
|
391
|
+
return [
|
|
392
|
+
{
|
|
393
|
+
description: 'Distance',
|
|
394
|
+
type: MeasureResultType.DISTANCE,
|
|
395
|
+
measureData: { value: distance, start: p1, end: p2 },
|
|
396
|
+
},
|
|
397
|
+
{ description: 'dx', type: MeasureResultType.DISTANCE, measureData: { value: dx, start: p1, end: px } },
|
|
398
|
+
{ description: 'dy', type: MeasureResultType.DISTANCE, measureData: { value: dy, start: px, end: pxy } },
|
|
399
|
+
{ description: 'dz', type: MeasureResultType.DISTANCE, measureData: { value: dz, start: pxy, end: p2 } },
|
|
400
|
+
];
|
|
401
|
+
},
|
|
402
|
+
calculatePointLine(point, line) {
|
|
403
|
+
const [start, end] = exports.Measure.getPointLineMPoints(point.position, line.start, line.end);
|
|
404
|
+
const distance = start.distanceTo(end);
|
|
405
|
+
return [
|
|
406
|
+
{
|
|
407
|
+
description: 'Distance',
|
|
408
|
+
type: MeasureResultType.DISTANCE,
|
|
409
|
+
measureData: { value: distance, start, end },
|
|
410
|
+
},
|
|
411
|
+
];
|
|
412
|
+
},
|
|
413
|
+
calculatePointPlane(point, plane) {
|
|
414
|
+
const [start, end] = exports.Measure.getPointPlaneMPoints(point.position, plane.pointOnPlane, plane.normal);
|
|
415
|
+
const distance = start.distanceTo(end);
|
|
416
|
+
return [
|
|
417
|
+
{
|
|
418
|
+
description: 'Distance',
|
|
419
|
+
type: MeasureResultType.DISTANCE,
|
|
420
|
+
measureData: { value: distance, start, end },
|
|
421
|
+
},
|
|
422
|
+
];
|
|
423
|
+
},
|
|
424
|
+
calculateLineLine(first, second) {
|
|
425
|
+
const [start, end] = exports.Measure.getLineLineMPoints(first.start, first.end, second.start, second.end);
|
|
426
|
+
const distance = start && end ? start.distanceTo(end) : NaN;
|
|
427
|
+
const [dir1, dir2] = exports.Measure.getLineLineMDirs(first.start, first.end, second.start, second.end);
|
|
428
|
+
const angle = exports.Measure.degrees(dir1.angleTo(dir2));
|
|
429
|
+
const angleS = 180 - angle;
|
|
430
|
+
return [
|
|
431
|
+
{
|
|
432
|
+
description: 'Distance',
|
|
433
|
+
type: MeasureResultType.DISTANCE,
|
|
434
|
+
measureData: start && end ? { value: distance, start, end } : undefined,
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
description: 'Angle1',
|
|
438
|
+
type: MeasureResultType.ANGLE,
|
|
439
|
+
measureData: { value: angle, center: first.start, dir1, dir2 },
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
description: 'Angle2',
|
|
443
|
+
type: MeasureResultType.ANGLE,
|
|
444
|
+
measureData: { value: angleS, center: first.start, dir1, dir2: dir2.clone().negate() },
|
|
445
|
+
},
|
|
446
|
+
];
|
|
447
|
+
},
|
|
448
|
+
calculateLinePlane(line, plane) {
|
|
449
|
+
const [start, end] = exports.Measure.getLinePlaneMPoints(line.start, line.end, plane.pointOnPlane, plane.normal);
|
|
450
|
+
const distance = start && end ? start.distanceTo(end) : NaN;
|
|
451
|
+
return [
|
|
452
|
+
{
|
|
453
|
+
description: 'Distance',
|
|
454
|
+
type: MeasureResultType.DISTANCE,
|
|
455
|
+
measureData: start && end ? { value: distance, start, end } : undefined,
|
|
456
|
+
},
|
|
457
|
+
];
|
|
458
|
+
},
|
|
459
|
+
calculateArcPlane(arc, plane) {
|
|
460
|
+
const [start, end] = exports.Measure.getArcPlaneMPoints(arc.center, arc.normal, plane.pointOnPlane, plane.normal);
|
|
461
|
+
const distance = start && end ? start.distanceTo(end) : NaN;
|
|
462
|
+
return [
|
|
463
|
+
{
|
|
464
|
+
description: 'Distance',
|
|
465
|
+
type: MeasureResultType.DISTANCE,
|
|
466
|
+
measureData: start && end ? { value: distance, start, end } : undefined,
|
|
467
|
+
},
|
|
468
|
+
];
|
|
469
|
+
},
|
|
470
|
+
calculatePlanePlane(plane1, plane2) {
|
|
471
|
+
const [start, end] = exports.Measure.getPlanePlaneMPoints(plane1.pointOnPlane, plane1.normal, plane2.pointOnPlane, plane2.normal);
|
|
472
|
+
const distance = start && end ? start.distanceTo(end) : NaN;
|
|
473
|
+
const [dir1, dir2] = exports.Measure.getPlanePlaneMDirs(plane1.normal, plane2.normal);
|
|
474
|
+
const angle = dir1 && dir2 ? exports.Measure.degrees(dir1.angleTo(dir2)) : exports.Measure.degrees(plane1.normal.angleTo(plane2.normal));
|
|
475
|
+
return [
|
|
476
|
+
{
|
|
477
|
+
description: 'Distance',
|
|
478
|
+
type: MeasureResultType.DISTANCE,
|
|
479
|
+
measureData: start && end ? { value: distance, start, end } : undefined,
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
description: 'Angle',
|
|
483
|
+
type: MeasureResultType.ANGLE,
|
|
484
|
+
measureData: dir1 && dir2 ? { value: angle, center: plane1.pointOnPlane.clone(), dir1, dir2 } : undefined,
|
|
485
|
+
},
|
|
486
|
+
];
|
|
487
|
+
},
|
|
488
|
+
degrees(radians) {
|
|
489
|
+
return (radians / Math.PI) * 180;
|
|
490
|
+
},
|
|
491
|
+
areParallel(vec1, vec2) {
|
|
492
|
+
const val = Math.abs(vec1.clone().cross(vec2).length());
|
|
493
|
+
return val < tolerance;
|
|
494
|
+
},
|
|
495
|
+
arePerpendicular(vec1, vec2) {
|
|
496
|
+
const val = Math.abs(vec1.clone().normalize().dot(vec2.clone().normalize()));
|
|
497
|
+
return val < tolerance;
|
|
498
|
+
},
|
|
499
|
+
getPointLineMPoints(pointsPos, startPos, endPos) {
|
|
500
|
+
const p1 = pointsPos.clone();
|
|
501
|
+
const lineDir = endPos.clone().sub(startPos);
|
|
502
|
+
const p2 = pointsPos.clone().sub(startPos).projectOnVector(lineDir).add(startPos);
|
|
503
|
+
return [p1, p2];
|
|
504
|
+
},
|
|
505
|
+
getPointPlaneMPoints(pointPos, pointOnPlane, normal) {
|
|
506
|
+
const p1 = pointPos.clone();
|
|
507
|
+
const offsetV = pointPos.clone().sub(pointOnPlane).projectOnVector(normal);
|
|
508
|
+
const p2 = pointPos.clone().sub(offsetV);
|
|
509
|
+
return [p1, p2];
|
|
510
|
+
},
|
|
511
|
+
getLineLineMPoints(start1Pos, end1Pos, start2Pos, end2Pos) {
|
|
512
|
+
const vec1 = start1Pos.clone().sub(end1Pos);
|
|
513
|
+
const vec2 = start2Pos.clone().sub(end2Pos);
|
|
514
|
+
if (exports.Measure.areParallel(vec1, vec2)) {
|
|
515
|
+
// lines are parallel
|
|
516
|
+
const vecAB = start1Pos.clone().sub(start2Pos);
|
|
517
|
+
if (!exports.Measure.areParallel(vecAB, vec1)) {
|
|
518
|
+
// lines are not conincident
|
|
519
|
+
return exports.Measure.getPointLineMPoints(start1Pos, start2Pos, end2Pos);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
return [undefined, undefined];
|
|
523
|
+
},
|
|
524
|
+
getLinePlaneMPoints(startPos, endPos, pointOnPlane, normal) {
|
|
525
|
+
const vec = startPos.clone().sub(endPos);
|
|
526
|
+
if (exports.Measure.arePerpendicular(vec, normal)) {
|
|
527
|
+
// line is perpendicular to plane normal
|
|
528
|
+
return exports.Measure.getPointPlaneMPoints(startPos, pointOnPlane, normal);
|
|
529
|
+
}
|
|
530
|
+
return [undefined, undefined];
|
|
531
|
+
},
|
|
532
|
+
getArcPlaneMPoints(arcCenter, arcNormal, pointOnPlane, planeNormal) {
|
|
533
|
+
if (exports.Measure.areParallel(arcNormal, planeNormal)) {
|
|
534
|
+
// parallel
|
|
535
|
+
return exports.Measure.getPointPlaneMPoints(arcCenter, pointOnPlane, planeNormal);
|
|
536
|
+
}
|
|
537
|
+
return [undefined, undefined];
|
|
538
|
+
},
|
|
539
|
+
getPlanePlaneMPoints(pointOnPlane1, normal1, pointOnPlane2, normal2) {
|
|
540
|
+
if (exports.Measure.areParallel(normal1, normal2)) {
|
|
541
|
+
// parallel
|
|
542
|
+
return exports.Measure.getPointPlaneMPoints(pointOnPlane1, pointOnPlane2, normal2);
|
|
543
|
+
}
|
|
544
|
+
return [undefined, undefined];
|
|
545
|
+
},
|
|
546
|
+
getLineLineMDirs(start1Pos, end1Pos, start2Pos, end2Pos) {
|
|
547
|
+
const vec1 = end1Pos.clone().sub(start1Pos);
|
|
548
|
+
const vec2 = end2Pos.clone().sub(start2Pos);
|
|
549
|
+
return [vec1, vec2];
|
|
550
|
+
},
|
|
551
|
+
getPlanePlaneMDirs(normal1, normal2) {
|
|
552
|
+
if (!exports.Measure.areParallel(normal1, normal2)) {
|
|
553
|
+
const tangent1 = normal1.clone().projectOnPlane(normal2).normalize();
|
|
554
|
+
const tangent2 = normal2.clone().projectOnPlane(normal1).normalize();
|
|
555
|
+
const angle = tangent1.angleTo(tangent2);
|
|
556
|
+
return angle <= Math.PI / 2 ? [tangent1, tangent2] : [tangent1, tangent2.negate()];
|
|
557
|
+
}
|
|
558
|
+
return [undefined, undefined];
|
|
559
|
+
},
|
|
560
|
+
};
|