fl-web-component 1.2.12 → 1.2.13
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 +2 -0
- package/dist/fl-web-component.common.1.js.map +1 -1
- package/dist/fl-web-component.common.2.js.map +1 -1
- package/dist/fl-web-component.common.3.js.map +1 -1
- package/dist/fl-web-component.common.js +129 -86
- 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-graphics/index.vue +31 -6
- package/src/utils/flgltf-parser.js +68 -50
- package/src/utils/instance-parser.js +39 -30
- package/packages/components/button/index.vue +0 -26
- package/packages/components/model/api/index.js +0 -421
- package/packages/components/model/api/mock/detecttree.js +0 -58
- package/packages/components/model/api/mock/getmodel-line.js +0 -15834
- package/packages/components/model/api/mock/init.js +0 -1
- package/packages/components/model/api/mock/pbstree.js +0 -826
- package/packages/components/model/api/mock/topology.json +0 -3238
- package/packages/components/model/components/TextOverTooltip/index.vue +0 -84
- package/packages/components/model/components/annotation-toolbar.vue +0 -410
- package/packages/components/model/components/check-proofing-model.vue +0 -39
- package/packages/components/model/components/clipping-type.vue +0 -59
- package/packages/components/model/components/com-dialogWrapper/Readme.md +0 -53
- package/packages/components/model/components/com-dialogWrapper/index.vue +0 -114
- package/packages/components/model/components/detect-panel.vue +0 -339
- package/packages/components/model/components/detect-tree.vue +0 -445
- package/packages/components/model/components/firstPer-panel.vue +0 -109
- package/packages/components/model/components/header-button.vue +0 -470
- package/packages/components/model/components/imageViewer/index.vue +0 -126
- package/packages/components/model/components/import-model.vue +0 -127
- package/packages/components/model/components/location-panel.vue +0 -91
- package/packages/components/model/components/measure-type.vue +0 -59
- package/packages/components/model/components/pbs-tree.vue +0 -497
- package/packages/components/model/components/proof-config.vue +0 -72
- package/packages/components/model/components/proof-for-pc.vue +0 -126
- package/packages/components/model/components/proof-history.vue +0 -300
- package/packages/components/model/components/proof-panel-detail.vue +0 -568
- package/packages/components/model/components/proof-panel.vue +0 -846
- package/packages/components/model/components/proof-project-user.vue +0 -445
- package/packages/components/model/components/proof-publish.vue +0 -130
- package/packages/components/model/components/proof-role.vue +0 -504
- package/packages/components/model/components/props-panel.vue +0 -258
- package/packages/components/model/index.vue +0 -3425
- package/packages/components/model/readme.md +0 -31
- package/packages/components/model/utils/annotation-tool.js +0 -333
- package/packages/components/model/utils/cursor.js +0 -23
- package/packages/components/model/utils/detect-v1.js +0 -329
- package/packages/components/model/utils/index.js +0 -48
- package/packages/components/model/utils/threejs/measure-angle.js +0 -258
- package/packages/components/model/utils/threejs/measure-area.js +0 -281
- package/packages/components/model/utils/threejs/measure-distance.js +0 -209
- package/packages/components/model/utils/threejs/measure-volume.js +0 -97
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
import * as THREE from 'three';
|
|
2
|
-
import { CSS2DObject } from 'three/examples/jsm/renderers/CSS2DRenderer';
|
|
3
|
-
var _this = null;
|
|
4
|
-
var MeasureArea = function (renderer, scene, camera, width, height) {
|
|
5
|
-
this.renderer = renderer;
|
|
6
|
-
this.scene = scene;
|
|
7
|
-
this.camera = camera;
|
|
8
|
-
this.pointArray = []; // 保存当前操作所添加的点
|
|
9
|
-
this.raycaster = new THREE.Raycaster();
|
|
10
|
-
this.points = []; // 保存页面中所添加的点
|
|
11
|
-
this.polyline = []; //保存页面中所添加的直线
|
|
12
|
-
this.labels = []; // 保存页面中所添加的文本
|
|
13
|
-
this.tempPoints = undefined;
|
|
14
|
-
this.tempLine = undefined;
|
|
15
|
-
this.tempLabel = undefined;
|
|
16
|
-
this.tipsLabel = undefined;
|
|
17
|
-
this.isCompleted = false;
|
|
18
|
-
this.timer = null;
|
|
19
|
-
this.polygonMesh = undefined;
|
|
20
|
-
this.polygons = [];
|
|
21
|
-
this.width = width;
|
|
22
|
-
this.height = height;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
MeasureArea.prototype = {
|
|
26
|
-
start() {
|
|
27
|
-
_this = this;
|
|
28
|
-
this.renderer.domElement.style.cursor = 'crosshair';
|
|
29
|
-
this.renderer.domElement.addEventListener('click', this.click, false);
|
|
30
|
-
this.renderer.domElement.addEventListener('mousemove', this.mousemove, false);
|
|
31
|
-
this.renderer.domElement.addEventListener('contextmenu', this.rightClick, false);
|
|
32
|
-
},
|
|
33
|
-
updateParams(width, height) {
|
|
34
|
-
this.camera.aspect = width / height;
|
|
35
|
-
this.camera.updateProjectionMatrix();
|
|
36
|
-
this.renderer.setSize(width, height, true);
|
|
37
|
-
this.width = width;
|
|
38
|
-
this.height = height;
|
|
39
|
-
},
|
|
40
|
-
getPosition(e) {
|
|
41
|
-
const mouse = new THREE.Vector2();
|
|
42
|
-
mouse.x = (e.clientX / _this.width) * 2 - 1;
|
|
43
|
-
mouse.y = -(e.clientY / _this.height) * 2 + 1;
|
|
44
|
-
_this.raycaster.setFromCamera(mouse, _this.camera);
|
|
45
|
-
let intersects = _this.raycaster.intersectObjects(_this.scene.children, true);
|
|
46
|
-
if (intersects.length > 0) {
|
|
47
|
-
return intersects[0].point;
|
|
48
|
-
}
|
|
49
|
-
return null;
|
|
50
|
-
},
|
|
51
|
-
createLine(p1, p2, config = { color: 0xff0000 }) {
|
|
52
|
-
const lineMaterial = new THREE.LineBasicMaterial({ color: config.color, linewidth: 20 });
|
|
53
|
-
const lineGeometry = new THREE.BufferGeometry().setFromPoints([p1, p2]);
|
|
54
|
-
const line = new THREE.Line(lineGeometry, lineMaterial);
|
|
55
|
-
line.frustumCulled = false;
|
|
56
|
-
|
|
57
|
-
return line;
|
|
58
|
-
},
|
|
59
|
-
createLabel(name, text, position) {
|
|
60
|
-
const div = document.createElement('div');
|
|
61
|
-
div.className = name;
|
|
62
|
-
div.textContent = text;
|
|
63
|
-
const divLabel = new CSS2DObject(div);
|
|
64
|
-
divLabel.position.set(position.x, position.y, position.z);
|
|
65
|
-
return divLabel;
|
|
66
|
-
},
|
|
67
|
-
mousemove(e) {
|
|
68
|
-
if (_this.isCompleted || _this.pointArray.length === 0) return;
|
|
69
|
-
const point = _this.getPosition(e);
|
|
70
|
-
if (point) {
|
|
71
|
-
_this.pointArray.length === 1
|
|
72
|
-
? _this.pointArray.push(point)
|
|
73
|
-
: _this.pointArray.splice(_this.pointArray.length - 1, 1, point);
|
|
74
|
-
const length = _this.pointArray.length;
|
|
75
|
-
if (_this.tempPoints) {
|
|
76
|
-
_this.tempPoints.position.set(point.x, point.y, point.z);
|
|
77
|
-
} else {
|
|
78
|
-
const geom = _this.createLabel('circle-tag', '', point);
|
|
79
|
-
_this.tempPoints = geom;
|
|
80
|
-
_this.points.push(geom);
|
|
81
|
-
_this.scene.add(geom);
|
|
82
|
-
}
|
|
83
|
-
const p1 = _this.pointArray[length - 2];
|
|
84
|
-
const p2 = _this.pointArray[length - 1];
|
|
85
|
-
if (_this.tempLine) {
|
|
86
|
-
_this.tempLine.geometry.setFromPoints([p1, p2]);
|
|
87
|
-
} else {
|
|
88
|
-
_this.tempLine = _this.createLine(p1, p2);
|
|
89
|
-
_this.polyline.push(_this.tempLine);
|
|
90
|
-
_this.scene.add(_this.tempLine);
|
|
91
|
-
}
|
|
92
|
-
if (_this.pointArray.length > 2) {
|
|
93
|
-
const area = _this.calculateArea(_this.pointArray);
|
|
94
|
-
_this.createPolygon(_this.pointArray);
|
|
95
|
-
if (_this.tempLabel) {
|
|
96
|
-
_this.polygonMesh.geometry.computeBoundingSphere();
|
|
97
|
-
_this.tempLabel.element.textContent = _this.numberToString(area); // + '㎡'
|
|
98
|
-
_this.tempLabel.position.set(
|
|
99
|
-
_this.polygonMesh.geometry.boundingSphere.center.x,
|
|
100
|
-
_this.polygonMesh.geometry.boundingSphere.center.y,
|
|
101
|
-
_this.polygonMesh.geometry.boundingSphere.center.z,
|
|
102
|
-
);
|
|
103
|
-
} else {
|
|
104
|
-
_this.polygonMesh.geometry.computeBoundingSphere();
|
|
105
|
-
console.log(_this.polygonMesh.geometry);
|
|
106
|
-
_this.tempLabel = _this.createLabel(
|
|
107
|
-
'measure-label',
|
|
108
|
-
area,
|
|
109
|
-
_this.polygonMesh.geometry.boundingSphere.center,
|
|
110
|
-
);
|
|
111
|
-
_this.labels.push(_this.tempLabel);
|
|
112
|
-
_this.scene.add(_this.tempLabel);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
if (_this.tipsLabel) {
|
|
116
|
-
_this.tipsLabel.position.set(point.x + 0.1, point.y, point.z + 0.05);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
createTipsLabel(label, position) {
|
|
121
|
-
const div = document.createElement('div');
|
|
122
|
-
div.className = 'tips-label';
|
|
123
|
-
div.textContent = label;
|
|
124
|
-
div.style = 'top: -50px';
|
|
125
|
-
const tipsLabel = new CSS2DObject(div);
|
|
126
|
-
tipsLabel.position.set(position.x + 0.1, position.y, position.z + 0.05);
|
|
127
|
-
return tipsLabel;
|
|
128
|
-
},
|
|
129
|
-
click(e) {
|
|
130
|
-
if (_this.isCompleted) {
|
|
131
|
-
_this.renderer.domElement.addEventListener('mousemove', _this.mousemove);
|
|
132
|
-
}
|
|
133
|
-
clearTimeout(_this.timer);
|
|
134
|
-
_this.timer = setTimeout(() => {
|
|
135
|
-
_this.isCompleted = false;
|
|
136
|
-
const point = _this.getPosition(e);
|
|
137
|
-
if (point) {
|
|
138
|
-
if (_this.tipsLabel) {
|
|
139
|
-
_this.tipsLabel.position.set(point.x + 0.01, point.y, point.z + 0.05);
|
|
140
|
-
} else {
|
|
141
|
-
_this.tipsLabel = _this.createTipsLabel('左击绘制右击结束', point);
|
|
142
|
-
_this.scene.add(_this.tipsLabel);
|
|
143
|
-
}
|
|
144
|
-
if (_this.tempPoints) {
|
|
145
|
-
_this.tempPoints.position.set(point.x, point.y, point.z);
|
|
146
|
-
_this.tempPoints = undefined;
|
|
147
|
-
} else {
|
|
148
|
-
const geom = _this.createLabel('circle-tag', '', point);
|
|
149
|
-
_this.points.push(geom);
|
|
150
|
-
_this.scene.add(geom);
|
|
151
|
-
}
|
|
152
|
-
_this.tempLine = undefined;
|
|
153
|
-
_this.pointArray.push(point);
|
|
154
|
-
}
|
|
155
|
-
}, 100);
|
|
156
|
-
},
|
|
157
|
-
rightClick(e) {
|
|
158
|
-
if (_this.tipsLabel) {
|
|
159
|
-
_this.scene.remove(_this.tipsLabel);
|
|
160
|
-
_this.tipsLabel = undefined;
|
|
161
|
-
}
|
|
162
|
-
clearTimeout(_this.timer);
|
|
163
|
-
const point = _this.getPosition(e);
|
|
164
|
-
_this.pointArray.pop();
|
|
165
|
-
// this.remove(_this.points.pop());
|
|
166
|
-
|
|
167
|
-
// if (point) {
|
|
168
|
-
if (_this.pointArray.length == 2) {
|
|
169
|
-
_this.scene.remove(_this.points[_this.points.length - 1]);
|
|
170
|
-
}
|
|
171
|
-
if (_this.pointArray.length > 2) {
|
|
172
|
-
const area = _this.calculateArea(_this.pointArray);
|
|
173
|
-
_this.createPolygon(_this.pointArray);
|
|
174
|
-
|
|
175
|
-
if (_this.tempLabel) {
|
|
176
|
-
_this.polygonMesh.geometry.computeBoundingSphere();
|
|
177
|
-
_this.tempLabel.element.textContent = _this.numberToString(area); // + '㎡'
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
_this.scene.remove(_this.tempPoints);
|
|
181
|
-
_this.scene.remove(_this.tempLine);
|
|
182
|
-
// _this.scene.remove(_this.tempLabel)
|
|
183
|
-
|
|
184
|
-
_this.isCompleted = true;
|
|
185
|
-
if (_this.tempPoints) {
|
|
186
|
-
_this.tempPoints.position.set(point.x, point.y, point.z);
|
|
187
|
-
_this.tempPoints = undefined;
|
|
188
|
-
}
|
|
189
|
-
_this.tempLine = undefined;
|
|
190
|
-
_this.tempLabel = undefined;
|
|
191
|
-
_this.polygonMesh = undefined;
|
|
192
|
-
_this.pointArray.splice(0);
|
|
193
|
-
_this.renderer.domElement.removeEventListener('mousemove', _this.mousemove);
|
|
194
|
-
// }
|
|
195
|
-
},
|
|
196
|
-
close() {
|
|
197
|
-
this.renderer.domElement.removeEventListener('mousemove', this.mousemove);
|
|
198
|
-
this.renderer.domElement.removeEventListener('click', this.click);
|
|
199
|
-
this.renderer.domElement.removeEventListener('contextmenu', this.rightClick);
|
|
200
|
-
this.remove(this.points);
|
|
201
|
-
this.remove(this.polyline);
|
|
202
|
-
this.remove(this.labels);
|
|
203
|
-
this.remove(this.polygons);
|
|
204
|
-
this.pointArray.splice(0);
|
|
205
|
-
this.points.splice(0);
|
|
206
|
-
this.polyline.splice(0);
|
|
207
|
-
this.labels.splice(0);
|
|
208
|
-
this.tempPoints = undefined;
|
|
209
|
-
this.tempLabel = undefined;
|
|
210
|
-
this.tempLine = undefined;
|
|
211
|
-
this.scene.remove(this.tipsLabel);
|
|
212
|
-
this.tipsLabel = undefined;
|
|
213
|
-
this.renderer.domElement.style.cursor = 'pointer';
|
|
214
|
-
},
|
|
215
|
-
remove(array) {
|
|
216
|
-
for (let index = 0; index < array.length; index++) {
|
|
217
|
-
const element = array[index];
|
|
218
|
-
if (element.geometry) {
|
|
219
|
-
element.geometry.dispose();
|
|
220
|
-
}
|
|
221
|
-
this.scene.remove(element);
|
|
222
|
-
}
|
|
223
|
-
},
|
|
224
|
-
calculateArea(points) {
|
|
225
|
-
let area = 0;
|
|
226
|
-
for (let i = 0, j = 1, k = 2; k < points.length; j++, k++) {
|
|
227
|
-
const a = points[i].distanceTo(points[j]);
|
|
228
|
-
const b = points[j].distanceTo(points[k]);
|
|
229
|
-
const c = points[k].distanceTo(points[i]);
|
|
230
|
-
const p = (a + b + c) / 2;
|
|
231
|
-
area += Math.sqrt(p * (p - a) * (p - b) * (p - c));
|
|
232
|
-
}
|
|
233
|
-
return area;
|
|
234
|
-
},
|
|
235
|
-
numberToString(num) {
|
|
236
|
-
if (num < 0.0001) {
|
|
237
|
-
return num.toString();
|
|
238
|
-
}
|
|
239
|
-
let fractionDigits = 2;
|
|
240
|
-
if (num < 0.01) {
|
|
241
|
-
fractionDigits = 4;
|
|
242
|
-
} else if (num < 0.1) {
|
|
243
|
-
fractionDigits = 3;
|
|
244
|
-
}
|
|
245
|
-
return num.toFixed(fractionDigits);
|
|
246
|
-
},
|
|
247
|
-
createPolygon(points) {
|
|
248
|
-
const length = points.length;
|
|
249
|
-
const faces = [];
|
|
250
|
-
for (let i = 0; i < length - 2; i++) {
|
|
251
|
-
faces.push(points[0].x, points[0].y, points[0].z);
|
|
252
|
-
faces.push(points[i + 1].x, points[i + 1].y, points[i + 1].z);
|
|
253
|
-
faces.push(points[i + 2].x, points[i + 2].y, points[i + 2].z);
|
|
254
|
-
}
|
|
255
|
-
if (faces.length > 3) {
|
|
256
|
-
if (_this.polygonMesh) {
|
|
257
|
-
_this.polygonMesh.geometry.setAttribute(
|
|
258
|
-
'position',
|
|
259
|
-
new THREE.BufferAttribute(new Float32Array(faces), 3),
|
|
260
|
-
);
|
|
261
|
-
} else {
|
|
262
|
-
const geom = new THREE.BufferGeometry();
|
|
263
|
-
geom.setAttribute('position', new THREE.BufferAttribute(new Float32Array(faces), 3));
|
|
264
|
-
const material = new THREE.MeshBasicMaterial({
|
|
265
|
-
color: 0xffffff,
|
|
266
|
-
transparent: true,
|
|
267
|
-
opacity: 0.5,
|
|
268
|
-
side: THREE.DoubleSide,
|
|
269
|
-
});
|
|
270
|
-
const mesh = new THREE.Mesh(geom, material);
|
|
271
|
-
mesh.name = 'polygonMesh';
|
|
272
|
-
_this.polygonMesh = mesh;
|
|
273
|
-
_this.scene.add(mesh);
|
|
274
|
-
_this.polygons.push(mesh);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
},
|
|
278
|
-
};
|
|
279
|
-
export default {
|
|
280
|
-
MeasureArea,
|
|
281
|
-
};
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import * as THREE from 'three';
|
|
2
|
-
import { CSS2DObject } from 'three/examples/jsm/renderers/CSS2DRenderer';
|
|
3
|
-
var _this = null;
|
|
4
|
-
var MeasureDistance = function (renderer, scene, camera, width, height) {
|
|
5
|
-
this.renderer = renderer;
|
|
6
|
-
this.scene = scene;
|
|
7
|
-
this.camera = camera;
|
|
8
|
-
this.pointArray = []; // 保存当前操作所添加的点
|
|
9
|
-
this.raycaster = new THREE.Raycaster();
|
|
10
|
-
this.points = []; // 保存页面中所添加的点
|
|
11
|
-
this.polyline = []; //保存页面中所添加的直线
|
|
12
|
-
this.labels = []; // 保存页面中所添加的文本
|
|
13
|
-
this.tempPoints = undefined;
|
|
14
|
-
this.tempLine = undefined;
|
|
15
|
-
this.tempLabel = undefined;
|
|
16
|
-
this.tipsLabel = undefined;
|
|
17
|
-
this.isCompleted = false;
|
|
18
|
-
this.timer = null;
|
|
19
|
-
this.width = width;
|
|
20
|
-
this.height = height;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
MeasureDistance.prototype = {
|
|
24
|
-
start() {
|
|
25
|
-
_this = this;
|
|
26
|
-
this.renderer.domElement.style.cursor = 'crosshair';
|
|
27
|
-
this.renderer.domElement.addEventListener('click', this.click, false);
|
|
28
|
-
this.renderer.domElement.addEventListener('mousemove', this.mousemove, false);
|
|
29
|
-
this.renderer.domElement.addEventListener('contextmenu', this.rightClick, false);
|
|
30
|
-
},
|
|
31
|
-
updateParams(width, height) {
|
|
32
|
-
this.camera.aspect = width / height;
|
|
33
|
-
this.camera.updateProjectionMatrix();
|
|
34
|
-
this.renderer.setSize(width, height, true);
|
|
35
|
-
this.width = width;
|
|
36
|
-
this.height = height;
|
|
37
|
-
},
|
|
38
|
-
getPosition(e) {
|
|
39
|
-
const mouse = new THREE.Vector2();
|
|
40
|
-
mouse.x = (e.clientX / _this.width) * 2 - 1;
|
|
41
|
-
mouse.y = -(e.clientY / _this.height) * 2 + 1;
|
|
42
|
-
_this.raycaster.setFromCamera(mouse, this.camera);
|
|
43
|
-
let intersects = _this.raycaster.intersectObjects(_this.scene.children, true);
|
|
44
|
-
if (intersects.length > 0) {
|
|
45
|
-
return intersects[0].point;
|
|
46
|
-
}
|
|
47
|
-
return null;
|
|
48
|
-
},
|
|
49
|
-
createLine(p1, p2, config = { color: 0xff0000 }) {
|
|
50
|
-
const lineMaterial = new THREE.LineBasicMaterial({ color: config.color, linewidth: 15 });
|
|
51
|
-
const lineGeometry = new THREE.BufferGeometry().setFromPoints([p1, p2]);
|
|
52
|
-
const line = new THREE.Line(lineGeometry, lineMaterial);
|
|
53
|
-
line.frustumCulled = false;
|
|
54
|
-
return line;
|
|
55
|
-
},
|
|
56
|
-
createLabel(name, text, position) {
|
|
57
|
-
const div = document.createElement('div');
|
|
58
|
-
div.className = name;
|
|
59
|
-
div.textContent = text;
|
|
60
|
-
const divLabel = new CSS2DObject(div);
|
|
61
|
-
divLabel.position.set(position.x, position.y, position.z);
|
|
62
|
-
return divLabel;
|
|
63
|
-
},
|
|
64
|
-
mousemove(e) {
|
|
65
|
-
if (_this.isCompleted || _this.pointArray.length === 0) return;
|
|
66
|
-
const point = _this.getPosition(e);
|
|
67
|
-
if (point) {
|
|
68
|
-
_this.pointArray.length === 1
|
|
69
|
-
? _this.pointArray.push(point)
|
|
70
|
-
: _this.pointArray.splice(_this.pointArray.length - 1, 1, point);
|
|
71
|
-
const length = _this.pointArray.length;
|
|
72
|
-
if (_this.tempPoints) {
|
|
73
|
-
_this.tempPoints.position.set(point.x, point.y, point.z);
|
|
74
|
-
} else {
|
|
75
|
-
const geom = _this.createLabel('circle-tag', '', point);
|
|
76
|
-
_this.tempPoints = geom;
|
|
77
|
-
_this.points.push(geom);
|
|
78
|
-
_this.scene.add(geom);
|
|
79
|
-
}
|
|
80
|
-
const p1 = _this.pointArray[length - 2];
|
|
81
|
-
const p2 = _this.pointArray[length - 1];
|
|
82
|
-
const dist = p1.distanceTo(p2);
|
|
83
|
-
const label = `${_this.numberToString(dist)}`;
|
|
84
|
-
const position = new THREE.Vector3((p1.x + p2.x) / 2, (p1.y + p2.y) / 2, (p1.z + p2.z) / 2);
|
|
85
|
-
if (_this.tempLine) {
|
|
86
|
-
_this.tempLine.geometry.setFromPoints([p1, p2]);
|
|
87
|
-
_this.tempLabel.element.textContent = label;
|
|
88
|
-
_this.tempLabel.position.set(position.x, position.y, position.z);
|
|
89
|
-
} else {
|
|
90
|
-
_this.tempLine = _this.createLine(p1, p2);
|
|
91
|
-
_this.tempLabel = _this.createLabel('measure-label', label, position);
|
|
92
|
-
_this.polyline.push(_this.tempLine);
|
|
93
|
-
_this.labels.push(_this.tempLabel);
|
|
94
|
-
_this.scene.add(_this.tempLine);
|
|
95
|
-
_this.scene.add(_this.tempLabel);
|
|
96
|
-
}
|
|
97
|
-
if (_this.tipsLabel) {
|
|
98
|
-
_this.tipsLabel.position.set(point.x + 0.1, point.y, point.z + 0.05);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
createTipsLabel(label, position) {
|
|
103
|
-
const div = document.createElement('div');
|
|
104
|
-
div.className = 'tips-label';
|
|
105
|
-
div.textContent = label;
|
|
106
|
-
div.style = 'top: -50px';
|
|
107
|
-
const tipsLabel = new CSS2DObject(div);
|
|
108
|
-
tipsLabel.position.set(position.x + 0.1, position.y, position.z + 0.05);
|
|
109
|
-
return tipsLabel;
|
|
110
|
-
},
|
|
111
|
-
click(e) {
|
|
112
|
-
if (_this.isCompleted) {
|
|
113
|
-
_this.renderer.domElement.addEventListener('mousemove', _this.mousemove);
|
|
114
|
-
}
|
|
115
|
-
clearTimeout(_this.timer);
|
|
116
|
-
_this.timer = setTimeout(() => {
|
|
117
|
-
_this.isCompleted = false;
|
|
118
|
-
const point = _this.getPosition(e);
|
|
119
|
-
if (point) {
|
|
120
|
-
if (_this.tipsLabel) {
|
|
121
|
-
_this.tipsLabel.position.set(point.x + 0.1, point.y, point.z + 0.05);
|
|
122
|
-
} else {
|
|
123
|
-
_this.tipsLabel = _this.createTipsLabel('左击绘制右击结束', point);
|
|
124
|
-
_this.scene.add(_this.tipsLabel);
|
|
125
|
-
}
|
|
126
|
-
if (_this.tempPoints) {
|
|
127
|
-
_this.tempPoints.position.set(point.x, point.y, point.z);
|
|
128
|
-
_this.tempPoints = undefined;
|
|
129
|
-
} else {
|
|
130
|
-
const geom = _this.createLabel('circle-tag', '', point);
|
|
131
|
-
_this.points.push(geom);
|
|
132
|
-
_this.scene.add(geom);
|
|
133
|
-
}
|
|
134
|
-
_this.tempLine = undefined;
|
|
135
|
-
_this.tempLabel = undefined;
|
|
136
|
-
_this.pointArray.push(point);
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
},
|
|
140
|
-
rightClick(e) {
|
|
141
|
-
if (_this.tipsLabel) {
|
|
142
|
-
_this.scene.remove(_this.tipsLabel);
|
|
143
|
-
_this.tipsLabel = undefined;
|
|
144
|
-
}
|
|
145
|
-
clearTimeout(_this.timer);
|
|
146
|
-
// const point = _this.getPosition(e)
|
|
147
|
-
// this.remove(_this.points.pop());
|
|
148
|
-
|
|
149
|
-
// if (point) {
|
|
150
|
-
if (_this.pointArray.length == 2) {
|
|
151
|
-
_this.scene.remove(_this.points[_this.points.length - 1]);
|
|
152
|
-
_this.scene.remove(_this.points[_this.points.length - 2]);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
_this.scene.remove(_this.tempPoints);
|
|
156
|
-
_this.scene.remove(_this.tempLine);
|
|
157
|
-
_this.scene.remove(_this.tempLabel);
|
|
158
|
-
|
|
159
|
-
_this.isCompleted = true;
|
|
160
|
-
_this.tempPoints = undefined;
|
|
161
|
-
_this.tempLine = undefined;
|
|
162
|
-
_this.tempLabel = undefined;
|
|
163
|
-
_this.pointArray.splice(0);
|
|
164
|
-
_this.renderer.domElement.removeEventListener('mousemove', _this.mousemove);
|
|
165
|
-
// }
|
|
166
|
-
},
|
|
167
|
-
close() {
|
|
168
|
-
this.renderer.domElement.removeEventListener('mousemove', this.mousemove);
|
|
169
|
-
this.renderer.domElement.removeEventListener('click', this.click);
|
|
170
|
-
this.renderer.domElement.removeEventListener('contextmenu', this.rightClick);
|
|
171
|
-
this.remove(this.points);
|
|
172
|
-
this.remove(this.polyline);
|
|
173
|
-
this.remove(this.labels);
|
|
174
|
-
this.pointArray.splice(0);
|
|
175
|
-
this.points.splice(0);
|
|
176
|
-
this.polyline.splice(0);
|
|
177
|
-
this.labels.splice(0);
|
|
178
|
-
this.tempPoints = undefined;
|
|
179
|
-
this.tempLabel = undefined;
|
|
180
|
-
this.tempLine = undefined;
|
|
181
|
-
this.scene.remove(this.tipsLabel);
|
|
182
|
-
this.tipsLabel = undefined;
|
|
183
|
-
this.renderer.domElement.style.cursor = 'pointer';
|
|
184
|
-
},
|
|
185
|
-
remove(array) {
|
|
186
|
-
for (let index = 0; index < array.length; index++) {
|
|
187
|
-
const element = array[index];
|
|
188
|
-
if (element.geometry) {
|
|
189
|
-
element.geometry.dispose();
|
|
190
|
-
}
|
|
191
|
-
this.scene.remove(element);
|
|
192
|
-
}
|
|
193
|
-
},
|
|
194
|
-
numberToString(num) {
|
|
195
|
-
if (num < 0.0001) {
|
|
196
|
-
return num.toString();
|
|
197
|
-
}
|
|
198
|
-
let fractionDigits = 2;
|
|
199
|
-
if (num < 0.01) {
|
|
200
|
-
fractionDigits = 4;
|
|
201
|
-
} else if (num < 0.1) {
|
|
202
|
-
fractionDigits = 3;
|
|
203
|
-
}
|
|
204
|
-
return num.toFixed(fractionDigits);
|
|
205
|
-
},
|
|
206
|
-
};
|
|
207
|
-
export default {
|
|
208
|
-
MeasureDistance,
|
|
209
|
-
};
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import * as THREE from 'three';
|
|
2
|
-
import { CSS2DObject } from 'three/examples/jsm/renderers/CSS2DRenderer';
|
|
3
|
-
var _this = null;
|
|
4
|
-
var MeasureVolume = function (renderer, scene, camera, width, height) {
|
|
5
|
-
this.renderer = renderer;
|
|
6
|
-
this.scene = scene;
|
|
7
|
-
this.camera = camera;
|
|
8
|
-
this.pointArray = []; // 保存当前操作所添加的点
|
|
9
|
-
this.raycaster = new THREE.Raycaster();
|
|
10
|
-
this.vMeter = 0.3047999995367;
|
|
11
|
-
this.tempLabel = undefined;
|
|
12
|
-
this.width = width;
|
|
13
|
-
this.height = height;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
MeasureVolume.prototype = {
|
|
17
|
-
start() {
|
|
18
|
-
_this = this;
|
|
19
|
-
this.renderer.domElement.addEventListener('click', this.click, false);
|
|
20
|
-
},
|
|
21
|
-
updateParams(width, height) {
|
|
22
|
-
this.camera.aspect = width / height;
|
|
23
|
-
this.camera.updateProjectionMatrix();
|
|
24
|
-
this.renderer.setSize(width, height, true);
|
|
25
|
-
this.width = width;
|
|
26
|
-
this.height = height;
|
|
27
|
-
},
|
|
28
|
-
getPosition(e) {
|
|
29
|
-
const mouse = new THREE.Vector2();
|
|
30
|
-
mouse.x = (e.clientX / _this.width) * 2 - 1;
|
|
31
|
-
mouse.y = -(e.clientY / _this.height) * 2 + 1;
|
|
32
|
-
_this.raycaster.setFromCamera(mouse, this.camera);
|
|
33
|
-
let intersects = _this.raycaster.intersectObjects(_this.scene.children, true);
|
|
34
|
-
if (intersects.length > 0) {
|
|
35
|
-
return intersects[0];
|
|
36
|
-
}
|
|
37
|
-
return null;
|
|
38
|
-
},
|
|
39
|
-
createLabel(label, position) {
|
|
40
|
-
const div = document.createElement('div');
|
|
41
|
-
div.className = 'measure-label';
|
|
42
|
-
div.textContent = label;
|
|
43
|
-
const divLabel = new CSS2DObject(div);
|
|
44
|
-
divLabel.position.set(position.x, position.y, position.z);
|
|
45
|
-
return divLabel;
|
|
46
|
-
},
|
|
47
|
-
click(e) {
|
|
48
|
-
const checkObj = _this.getPosition(e);
|
|
49
|
-
const obj = checkObj.object;
|
|
50
|
-
if (!obj.geometry.boundingBox) {
|
|
51
|
-
obj.geometry.computeBoundingBox();
|
|
52
|
-
}
|
|
53
|
-
const width =
|
|
54
|
-
Math.abs(obj.geometry.boundingBox.max.x - obj.geometry.boundingBox.min.x) * obj.scale.x;
|
|
55
|
-
const length =
|
|
56
|
-
Math.abs(obj.geometry.boundingBox.max.y - obj.geometry.boundingBox.min.y) * obj.scale.y;
|
|
57
|
-
const height =
|
|
58
|
-
Math.abs(obj.geometry.boundingBox.max.z - obj.geometry.boundingBox.min.z) * obj.scale.z;
|
|
59
|
-
const vol = width * length * height * _this.vMeter * _this.vMeter * _this.vMeter;
|
|
60
|
-
const text = _this.numberToString(vol);
|
|
61
|
-
console.log(text);
|
|
62
|
-
if (_this.tempLabel) {
|
|
63
|
-
_this.tempLabel.element.textContent = text + 'm³';
|
|
64
|
-
_this.tempLabel.position.set(position.x, position.y, position.z);
|
|
65
|
-
} else {
|
|
66
|
-
_this.tempLabel = _this.createLabel(text + 'm³', obj.point);
|
|
67
|
-
_this.scene.add(_this.tempLabel);
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
close() {
|
|
71
|
-
this.renderer.domElement.removeEventListener('click', this.click);
|
|
72
|
-
},
|
|
73
|
-
remove(array) {
|
|
74
|
-
for (let index = 0; index < array.length; index++) {
|
|
75
|
-
const element = array[index];
|
|
76
|
-
if (element.geometry) {
|
|
77
|
-
element.geometry.dispose();
|
|
78
|
-
}
|
|
79
|
-
this.scene.remove(element);
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
numberToString(num) {
|
|
83
|
-
if (num < 0.0001) {
|
|
84
|
-
return num.toString();
|
|
85
|
-
}
|
|
86
|
-
let fractionDigits = 2;
|
|
87
|
-
if (num < 0.01) {
|
|
88
|
-
fractionDigits = 4;
|
|
89
|
-
} else if (num < 0.1) {
|
|
90
|
-
fractionDigits = 3;
|
|
91
|
-
}
|
|
92
|
-
return num.toFixed(fractionDigits);
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
|
-
export default {
|
|
96
|
-
MeasureVolume,
|
|
97
|
-
};
|