fl-web-component 2.0.15 → 2.0.17
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 +5 -1
- package/dist/fl-web-component.common.js +702 -236
- package/dist/fl-web-component.common.js.map +1 -1
- package/dist/fl-web-component.css +1 -1
- package/package.json +1 -1
- package/packages/components/com-flcanvas/index.vue +17 -0
- package/packages/components/com-graphics/index.vue +63 -12
- package/src/utils/threejs/measure-angle.js +172 -41
- package/src/utils/threejs/measure-area.js +144 -46
- package/src/utils/threejs/measure-distance.js +135 -18
- package/src/utils/threejs/measure-height.js +59 -15
|
@@ -3,10 +3,11 @@ import { CSS2DObject } from 'three/examples/jsm/renderers/CSS2DRenderer';
|
|
|
3
3
|
import { Message } from 'element-ui';
|
|
4
4
|
|
|
5
5
|
var _this = null;
|
|
6
|
-
var MeasureHeight = function (renderer, scene, camera, width, height) {
|
|
6
|
+
var MeasureHeight = function (renderer, scene, camera, width, height, options = {}) {
|
|
7
7
|
this.renderer = renderer;
|
|
8
8
|
this.scene = scene;
|
|
9
9
|
this.camera = camera;
|
|
10
|
+
this.pickRoots = options.pickRoots || null;
|
|
10
11
|
this.pointArray = [];
|
|
11
12
|
this.raycaster = new THREE.Raycaster();
|
|
12
13
|
this.points = [];
|
|
@@ -22,7 +23,7 @@ var MeasureHeight = function (renderer, scene, camera, width, height) {
|
|
|
22
23
|
this.height = height;
|
|
23
24
|
this.firstTime = 0;
|
|
24
25
|
this.plane = new THREE.Plane(new THREE.Vector3(0, 0, 1), 0);
|
|
25
|
-
this.measureName = 'measureObj'
|
|
26
|
+
this.measureName = 'measureObj';
|
|
26
27
|
};
|
|
27
28
|
|
|
28
29
|
MeasureHeight.prototype = {
|
|
@@ -40,7 +41,45 @@ MeasureHeight.prototype = {
|
|
|
40
41
|
this.width = width;
|
|
41
42
|
this.height = height;
|
|
42
43
|
},
|
|
43
|
-
|
|
44
|
+
getPickRoots() {
|
|
45
|
+
const roots = typeof _this.pickRoots === 'function' ? _this.pickRoots() : _this.pickRoots;
|
|
46
|
+
if (Array.isArray(roots) && roots.length > 0) {
|
|
47
|
+
return roots.filter(Boolean);
|
|
48
|
+
}
|
|
49
|
+
if (roots) {
|
|
50
|
+
return [roots];
|
|
51
|
+
}
|
|
52
|
+
return _this.scene && _this.scene.children ? _this.scene.children : [];
|
|
53
|
+
},
|
|
54
|
+
isExcludedIntersection(object) {
|
|
55
|
+
let current = object;
|
|
56
|
+
while (current) {
|
|
57
|
+
const userData = current.userData || {};
|
|
58
|
+
if (current.visible === false) return true;
|
|
59
|
+
if (current.name === _this.measureName || userData.isMeasureObject === true) return true;
|
|
60
|
+
if (userData.transformControlHelper === true || userData.outlineProxy === true) return true;
|
|
61
|
+
if (current.isCamera || current.isLight) return true;
|
|
62
|
+
if (
|
|
63
|
+
typeof current.type === 'string' &&
|
|
64
|
+
(/Helper$/i.test(current.type) ||
|
|
65
|
+
current.type === 'CSS2DObject' ||
|
|
66
|
+
current.type === 'TransformControlsRoot')
|
|
67
|
+
) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
current = current.parent;
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
},
|
|
74
|
+
markMeasureObject(object) {
|
|
75
|
+
object.name = this.measureName;
|
|
76
|
+
if (!object.userData) {
|
|
77
|
+
object.userData = {};
|
|
78
|
+
}
|
|
79
|
+
object.userData.isMeasureObject = true;
|
|
80
|
+
return object;
|
|
81
|
+
},
|
|
82
|
+
getPosition(e, options = {}) {
|
|
44
83
|
const mouse = new THREE.Vector2();
|
|
45
84
|
const elRect = this.renderer.domElement.getBoundingClientRect();
|
|
46
85
|
const canvasX = e.clientX - elRect.left;
|
|
@@ -50,11 +89,17 @@ MeasureHeight.prototype = {
|
|
|
50
89
|
mouse.y = -(canvasY / elRect.height) * 2.0 + 1.0;
|
|
51
90
|
|
|
52
91
|
_this.raycaster.setFromCamera(mouse, this.camera);
|
|
53
|
-
const intersects = _this.raycaster
|
|
92
|
+
const intersects = _this.raycaster
|
|
93
|
+
.intersectObjects(_this.getPickRoots(), true)
|
|
94
|
+
.filter(item => item && item.object && !_this.isExcludedIntersection(item.object));
|
|
54
95
|
if (intersects.length > 0) {
|
|
55
96
|
return { point: intersects[0].point, isModel: true };
|
|
56
97
|
}
|
|
57
98
|
|
|
99
|
+
if (options.allowPlaneFallback === false) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
|
|
58
103
|
if (_this.pointArray && _this.pointArray.length > 0) {
|
|
59
104
|
const lastPoint =
|
|
60
105
|
_this.pointArray.length === 1
|
|
@@ -83,11 +128,11 @@ MeasureHeight.prototype = {
|
|
|
83
128
|
linewidth: 15,
|
|
84
129
|
depthTest: false,
|
|
85
130
|
depthWrite: false,
|
|
86
|
-
transparent: true
|
|
131
|
+
transparent: true,
|
|
87
132
|
});
|
|
88
133
|
const lineGeometry = new THREE.BufferGeometry().setFromPoints([p1, p2]);
|
|
89
134
|
const line = new THREE.Line(lineGeometry, lineMaterial);
|
|
90
|
-
|
|
135
|
+
this.markMeasureObject(line);
|
|
91
136
|
line.renderOrder = 999;
|
|
92
137
|
line.frustumCulled = false;
|
|
93
138
|
return line;
|
|
@@ -97,7 +142,7 @@ MeasureHeight.prototype = {
|
|
|
97
142
|
div.className = name;
|
|
98
143
|
div.textContent = text;
|
|
99
144
|
const divLabel = new CSS2DObject(div);
|
|
100
|
-
|
|
145
|
+
this.markMeasureObject(divLabel);
|
|
101
146
|
divLabel.position.set(position.x, position.y, position.z);
|
|
102
147
|
return divLabel;
|
|
103
148
|
},
|
|
@@ -128,7 +173,7 @@ MeasureHeight.prototype = {
|
|
|
128
173
|
div.className = 'tips-label';
|
|
129
174
|
div.textContent = label;
|
|
130
175
|
const tipsLabel = new CSS2DObject(div);
|
|
131
|
-
|
|
176
|
+
this.markMeasureObject(tipsLabel);
|
|
132
177
|
tipsLabel.position.set(position.x + 0.1, position.y, position.z + 0.05);
|
|
133
178
|
return tipsLabel;
|
|
134
179
|
},
|
|
@@ -141,13 +186,13 @@ MeasureHeight.prototype = {
|
|
|
141
186
|
clearTimeout(_this.timer);
|
|
142
187
|
_this.timer = setTimeout(() => {
|
|
143
188
|
_this.isCompleted = false;
|
|
144
|
-
const positionResult = _this.getPosition(e);
|
|
189
|
+
const positionResult = _this.getPosition(e, { allowPlaneFallback: false });
|
|
190
|
+
if (!positionResult || !positionResult.isModel) {
|
|
191
|
+
Message.warning('请点击模型进行测量');
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
145
194
|
if (positionResult) {
|
|
146
|
-
const { point
|
|
147
|
-
if (!isModel) {
|
|
148
|
-
Message.warning('请点击模型进行测量');
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
195
|
+
const { point } = positionResult;
|
|
151
196
|
// if (_this.tipsLabel) {
|
|
152
197
|
// _this.tipsLabel.position.set(point.x + 0.1, point.y, point.z + 0.05);
|
|
153
198
|
// } else {
|
|
@@ -188,7 +233,6 @@ MeasureHeight.prototype = {
|
|
|
188
233
|
this.renderer.domElement.style.cursor = 'pointer';
|
|
189
234
|
this.firstTime = 0;
|
|
190
235
|
}
|
|
191
|
-
|
|
192
236
|
},
|
|
193
237
|
clear() {
|
|
194
238
|
this.remove(this.points);
|