fl-web-component 1.3.0 → 1.3.2
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 +6 -0
- package/dist/fl-web-component.common.js +107 -68
- 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 +7 -2
- package/packages/components/com-graphics/index.vue +7 -3
- package/src/main.js +14 -18
- package/src/utils/threejs/measure-angle.js +184 -176
- package/src/utils/threejs/measure-area.js +193 -171
- package/src/utils/threejs/measure-distance.js +160 -149
|
@@ -1 +1 @@
|
|
|
1
|
-
@charset "UTF-8";#fl-model[data-v-
|
|
1
|
+
@charset "UTF-8";#fl-model[data-v-070832d8]{width:100%;height:100%;cursor:pointer}[data-v-070832d8] .tips-label{width:50px;color:#000;font:12px Helvetica;padding:5px;text-align:center;vertical-align:middle;background-color:khaki}[data-v-070832d8] .measure-label{max-width:100px;margin-top:-1em;border:10px;border-radius:5px;padding:3px 10px;cursor:pointer;color:#009bea;background-color:#f4f4f4;box-shadow:0 1px 3px 1px rgba(0,0,0,.25)}[data-v-070832d8] .circle-tag{width:10px;height:10px;margin-top:5px;border-radius:50%;background-color:#ff5000}[data-v-070832d8] .measure-label-font{word-break:break-all}[data-v-070832d8] .mark-label-img{padding-top:5px;width:20px;height:20px}#konva-container[data-v-95b325ba]{z-index:3;width:100%;height:100%;cursor:pointer;overflow:hidden}span[data-v-f547d5c6]{font-weight:bolder}.text[data-v-f547d5c6]{margin-top:20px}.line[data-v-f547d5c6]{border-bottom:1px solid #dcdfe6;margin:20px 0}.center[data-v-f547d5c6]{display:flex;flex-direction:column;align-items:center}.center .cen span[data-v-f547d5c6],.center .top span[data-v-f547d5c6]{color:"#53a8ff";display:inline-block;width:30px;height:30px;text-align:center;line-height:30px;border:1px solid;padding:5px;margin-bottom:10px;background-color:#e9f3ff}.center .cen span[data-v-f547d5c6]{margin:10px}.button[data-v-f547d5c6]{display:flex;justify-content:end;margin-top:20px}@font-face{font-family:iconfont;src:url(//at.alicdn.com/t/font_3226805_qqvo3ag3r8.woff2?t=1646635700216) format("woff2"),url(//at.alicdn.com/t/font_3226805_qqvo3ag3r8.woff?t=1646635700216) format("woff"),url(//at.alicdn.com/t/font_3226805_qqvo3ag3r8.ttf?t=1646635700216) format("truetype")}.iconfont[data-v-f547d5c6]{font-family:iconfont!important;font-size:50px;font-style:normal;color:"#53a8ff";-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.icon-shubiao[data-v-f547d5c6]:before{content:""}#svg-tigger[data-v-0ec35ee4]{cursor:pointer;height:100%;width:100%}
|
package/package.json
CHANGED
|
@@ -161,7 +161,7 @@ var preTarget = [];
|
|
|
161
161
|
let entities = formatEntity(dxf.entities);
|
|
162
162
|
let layers = dxf.tables.layer.layers;
|
|
163
163
|
|
|
164
|
-
for (let key in
|
|
164
|
+
for (let key in entities) {
|
|
165
165
|
if (entities[key]) {
|
|
166
166
|
let group = [];
|
|
167
167
|
let l = entities[key].length;
|
|
@@ -283,7 +283,12 @@ var preTarget = [];
|
|
|
283
283
|
},
|
|
284
284
|
toPdf(name) {
|
|
285
285
|
// get data URL with default settings
|
|
286
|
-
|
|
286
|
+
konvaStage.scale({
|
|
287
|
+
x:2,
|
|
288
|
+
y:2
|
|
289
|
+
})
|
|
290
|
+
konvaStage.setX(0);
|
|
291
|
+
konvaStage.setY(750);
|
|
287
292
|
// open in new window
|
|
288
293
|
konvaLayer.getCanvas().setPixelRatio(1);
|
|
289
294
|
const jpegURL = konvaStage.toDataURL({
|
|
@@ -158,7 +158,8 @@
|
|
|
158
158
|
preserveDrawingBuffer: true, //保留图形缓冲区 TODO 临时截图使用
|
|
159
159
|
});
|
|
160
160
|
renderer.setPixelRatio(window.devicePixelRatio);
|
|
161
|
-
|
|
161
|
+
const rect = instructions.getBoundingClientRect();
|
|
162
|
+
renderer.setSize(rect.width, rect.height);
|
|
162
163
|
renderer.domElement.id = 'three-model';
|
|
163
164
|
renderer.shadowMap.enabled = true;
|
|
164
165
|
// 暂时注释这句 还有worker里面的 这跟渲染出的模型浅或暗有关系
|
|
@@ -205,9 +206,11 @@
|
|
|
205
206
|
// 初始化文字画布
|
|
206
207
|
initLabelRender() {
|
|
207
208
|
labelRenderer = new CSS2DRenderer();
|
|
208
|
-
|
|
209
|
+
const rect = instructions.getBoundingClientRect();
|
|
210
|
+
labelRenderer.setSize(rect.width, rect.height);
|
|
209
211
|
labelRenderer.domElement.style.position = 'absolute';
|
|
210
|
-
|
|
212
|
+
|
|
213
|
+
labelRenderer.domElement.style.top = `${rect.top}px`;
|
|
211
214
|
labelRenderer.domElement.style.pointerEvents = 'none';
|
|
212
215
|
instructions.appendChild(labelRenderer.domElement);
|
|
213
216
|
},
|
|
@@ -1564,6 +1567,7 @@
|
|
|
1564
1567
|
::v-deep .circle-tag {
|
|
1565
1568
|
width: 10px;
|
|
1566
1569
|
height: 10px;
|
|
1570
|
+
margin-top: 5px;
|
|
1567
1571
|
border-radius: 50%;
|
|
1568
1572
|
background-color: #ff5000;
|
|
1569
1573
|
}
|
package/src/main.js
CHANGED
|
@@ -3,30 +3,26 @@ import Fl2dcanvas from '../packages/components/com-flcanvas/index.vue';
|
|
|
3
3
|
import FLPerControl from '../packages/components/com-graphics/per-control.vue';
|
|
4
4
|
import FlSvg from '../packages/components/com-graphics/pid.vue';
|
|
5
5
|
import * as THREE from 'three';
|
|
6
|
+
import pkg from '../package.json';
|
|
6
7
|
|
|
7
|
-
const components = [
|
|
8
|
-
FlModel,
|
|
9
|
-
Fl2dcanvas,
|
|
10
|
-
FLPerControl,
|
|
11
|
-
FlSvg
|
|
12
|
-
];
|
|
8
|
+
const components = [FlModel, Fl2dcanvas, FLPerControl, FlSvg];
|
|
13
9
|
|
|
14
|
-
const install =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
const install = Vue => {
|
|
11
|
+
Vue.prototype.THREE = THREE;
|
|
12
|
+
components.forEach(component => {
|
|
13
|
+
Vue.component(component.name, component);
|
|
14
|
+
});
|
|
19
15
|
};
|
|
20
16
|
|
|
21
17
|
// 支持浏览器环境直接引入
|
|
22
|
-
if (typeof window !== 'undefined'
|
|
23
|
-
|
|
18
|
+
if (typeof window !== 'undefined') {
|
|
19
|
+
window.FLVersion = pkg.version;
|
|
24
20
|
}
|
|
25
21
|
|
|
26
22
|
export default {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
install,
|
|
24
|
+
FlModel,
|
|
25
|
+
FlSvg,
|
|
26
|
+
Fl2dcanvas,
|
|
27
|
+
FLPerControl,
|
|
32
28
|
};
|
|
@@ -1,250 +1,258 @@
|
|
|
1
|
-
import * as THREE from 'three'
|
|
2
|
-
import { CSS2DObject } from 'three/examples/jsm/renderers/CSS2DRenderer'
|
|
3
|
-
var _this = null
|
|
4
|
-
var MeasureAngle = 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.curves = [] // 保存页面所有的曲线
|
|
14
|
-
this.tempPoints = undefined
|
|
15
|
-
this.tempLine = undefined
|
|
16
|
-
this.tempLabel = undefined
|
|
17
|
-
this.tipsLabel = undefined
|
|
18
|
-
this.isCompleted = false
|
|
19
|
-
this.curveLine = undefined
|
|
20
|
-
this.timer = null
|
|
21
|
-
this.width = width
|
|
22
|
-
this.height = height
|
|
23
|
-
this.firstTime = 0
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { CSS2DObject } from 'three/examples/jsm/renderers/CSS2DRenderer';
|
|
3
|
+
var _this = null;
|
|
4
|
+
var MeasureAngle = 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.curves = []; // 保存页面所有的曲线
|
|
14
|
+
this.tempPoints = undefined;
|
|
15
|
+
this.tempLine = undefined;
|
|
16
|
+
this.tempLabel = undefined;
|
|
17
|
+
this.tipsLabel = undefined;
|
|
18
|
+
this.isCompleted = false;
|
|
19
|
+
this.curveLine = undefined;
|
|
20
|
+
this.timer = null;
|
|
21
|
+
this.width = width;
|
|
22
|
+
this.height = height;
|
|
23
|
+
this.firstTime = 0;
|
|
24
24
|
// this.POINT_MATERIAL = new THREE.PointsMaterial({ color: 0xff5000, size: 1, opacity: 0.6, transparent: true, depthWrite: false, depthTest: false })
|
|
25
25
|
// this.LINE_MATERIAL = new THREE.LineBasicMaterial({ color: 0xff0000, linewidth: 3, opacity: 0.8, transparent: true, side: THREE.DoubleSide, depthWrite: false, depthTest: false })
|
|
26
|
-
}
|
|
26
|
+
};
|
|
27
27
|
|
|
28
28
|
MeasureAngle.prototype = {
|
|
29
29
|
start() {
|
|
30
|
-
_this = this
|
|
31
|
-
this.renderer.domElement.style.cursor = 'crosshair'
|
|
32
|
-
this.renderer.domElement.addEventListener('mouseup', this.click, false)
|
|
33
|
-
this.renderer.domElement.addEventListener('mousedown', this.mousedown, false)
|
|
34
|
-
this.renderer.domElement.addEventListener('mousemove',
|
|
35
|
-
this.renderer.domElement.addEventListener('contextmenu', this.rightClick, false)
|
|
30
|
+
_this = this;
|
|
31
|
+
this.renderer.domElement.style.cursor = 'crosshair';
|
|
32
|
+
this.renderer.domElement.addEventListener('mouseup', this.click, false);
|
|
33
|
+
this.renderer.domElement.addEventListener('mousedown', this.mousedown, false);
|
|
34
|
+
this.renderer.domElement.addEventListener('mousemove', this.mousemove, false);
|
|
35
|
+
this.renderer.domElement.addEventListener('contextmenu', this.rightClick, false);
|
|
36
36
|
},
|
|
37
37
|
updateParams(width, height) {
|
|
38
|
-
this.camera.aspect = width / height
|
|
39
|
-
this.camera.updateProjectionMatrix()
|
|
40
|
-
this.renderer.setSize(width, height, true)
|
|
41
|
-
this.width = width
|
|
42
|
-
this.height = height
|
|
38
|
+
this.camera.aspect = width / height;
|
|
39
|
+
this.camera.updateProjectionMatrix();
|
|
40
|
+
this.renderer.setSize(width, height, true);
|
|
41
|
+
this.width = width;
|
|
42
|
+
this.height = height;
|
|
43
43
|
},
|
|
44
44
|
getPosition(e) {
|
|
45
|
-
const mouse = new THREE.Vector2()
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
const mouse = new THREE.Vector2();
|
|
46
|
+
const elRect = this.renderer.domElement.getBoundingClientRect();
|
|
47
|
+
const canvasX = e.clientX - elRect.left;
|
|
48
|
+
const canvasY = e.clientY - elRect.top;
|
|
49
|
+
|
|
50
|
+
mouse.x = (canvasX / elRect.width) * 2.0 - 1.0;
|
|
51
|
+
mouse.y = -(canvasY / elRect.height) * 2.0 + 1.0;
|
|
52
|
+
|
|
53
|
+
_this.raycaster.setFromCamera(mouse, this.camera);
|
|
54
|
+
let intersects = _this.raycaster.intersectObjects(_this.scene.children, true);
|
|
55
|
+
if (intersects.length > 0) {
|
|
56
|
+
return intersects[0].point;
|
|
52
57
|
}
|
|
53
|
-
return null
|
|
54
|
-
},
|
|
55
|
-
createPoints(pos, config = {color: 0x009bea, size: 0.3}) {
|
|
56
|
-
const mesh = new THREE.MeshBasicMaterial({color: config.color || 0x009bea})
|
|
57
|
-
const geom = new THREE.SphereGeometry(config.size || 0.3, 28, 28)
|
|
58
|
-
const sphere = new THREE.Mesh(geom, mesh)
|
|
59
|
-
sphere.frustumCulled = false
|
|
60
|
-
sphere.position.set(pos.x, pos.y, pos.z)
|
|
61
|
-
return sphere
|
|
62
|
-
},
|
|
63
|
-
createLine(p1, p2, config={color: 0xff0000}) {
|
|
64
|
-
const lineMaterial = new THREE.LineBasicMaterial({ color: config.color, linewidth: 10 })
|
|
65
|
-
const lineGeometry = new THREE.BufferGeometry().setFromPoints([p1, p2])
|
|
66
|
-
const line = new THREE.Line(lineGeometry, lineMaterial)
|
|
67
|
-
line.frustumCulled = false
|
|
68
|
-
return line
|
|
58
|
+
return null;
|
|
59
|
+
},
|
|
60
|
+
createPoints(pos, config = { color: 0x009bea, size: 0.3 }) {
|
|
61
|
+
const mesh = new THREE.MeshBasicMaterial({ color: config.color || 0x009bea });
|
|
62
|
+
const geom = new THREE.SphereGeometry(config.size || 0.3, 28, 28);
|
|
63
|
+
const sphere = new THREE.Mesh(geom, mesh);
|
|
64
|
+
sphere.frustumCulled = false;
|
|
65
|
+
sphere.position.set(pos.x, pos.y, pos.z);
|
|
66
|
+
return sphere;
|
|
67
|
+
},
|
|
68
|
+
createLine(p1, p2, config = { color: 0xff0000 }) {
|
|
69
|
+
const lineMaterial = new THREE.LineBasicMaterial({ color: config.color, linewidth: 10 });
|
|
70
|
+
const lineGeometry = new THREE.BufferGeometry().setFromPoints([p1, p2]);
|
|
71
|
+
const line = new THREE.Line(lineGeometry, lineMaterial);
|
|
72
|
+
line.frustumCulled = false;
|
|
73
|
+
return line;
|
|
69
74
|
},
|
|
70
75
|
createLabel(name, text, position) {
|
|
71
|
-
const div = document.createElement('div')
|
|
72
|
-
div.className = name
|
|
73
|
-
div.textContent = text
|
|
74
|
-
const divLabel = new CSS2DObject(div)
|
|
75
|
-
divLabel.position.set(position.x, position.y, position.z)
|
|
76
|
-
return divLabel
|
|
76
|
+
const div = document.createElement('div');
|
|
77
|
+
div.className = name;
|
|
78
|
+
div.textContent = text;
|
|
79
|
+
const divLabel = new CSS2DObject(div);
|
|
80
|
+
divLabel.position.set(position.x, position.y, position.z);
|
|
81
|
+
return divLabel;
|
|
77
82
|
},
|
|
78
83
|
mousemove(e) {
|
|
79
|
-
if (_this.isCompleted || _this.pointArray.length === 0) return
|
|
80
|
-
|
|
84
|
+
if (_this.isCompleted || _this.pointArray.length === 0) return;
|
|
85
|
+
const point = _this.getPosition(e);
|
|
81
86
|
if (point) {
|
|
82
|
-
_this.pointArray.length === 1
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
87
|
+
_this.pointArray.length === 1
|
|
88
|
+
? _this.pointArray.push(point)
|
|
89
|
+
: _this.pointArray.splice(_this.pointArray.length - 1, 1, point);
|
|
90
|
+
const length = _this.pointArray.length;
|
|
91
|
+
const p1 = _this.pointArray[length - 2];
|
|
92
|
+
const p2 = _this.pointArray[length - 1];
|
|
86
93
|
if (_this.tempPoints) {
|
|
87
|
-
_this.tempPoints.position.set(point.x, point.y, point.z)
|
|
94
|
+
_this.tempPoints.position.set(point.x, point.y, point.z);
|
|
88
95
|
} else {
|
|
89
|
-
const geom = _this.createLabel('circle-tag', '', point)
|
|
90
|
-
_this.tempPoints = geom
|
|
91
|
-
_this.points.push(geom)
|
|
92
|
-
_this.scene.add(geom)
|
|
96
|
+
const geom = _this.createLabel('circle-tag', '', point);
|
|
97
|
+
_this.tempPoints = geom;
|
|
98
|
+
_this.points.push(geom);
|
|
99
|
+
_this.scene.add(geom);
|
|
93
100
|
}
|
|
94
101
|
if (_this.tempLine) {
|
|
95
|
-
_this.tempLine.geometry.setFromPoints([p1, p2])
|
|
102
|
+
_this.tempLine.geometry.setFromPoints([p1, p2]);
|
|
96
103
|
} else {
|
|
97
|
-
_this.tempLine = _this.createLine(p1, p2)
|
|
98
|
-
_this.polyline.push(_this.tempLine)
|
|
99
|
-
_this.scene.add(_this.tempLine)
|
|
104
|
+
_this.tempLine = _this.createLine(p1, p2);
|
|
105
|
+
_this.polyline.push(_this.tempLine);
|
|
106
|
+
_this.scene.add(_this.tempLine);
|
|
100
107
|
}
|
|
101
108
|
// 三点构成一个角
|
|
102
109
|
if (_this.pointArray.length === 3) {
|
|
103
|
-
const angle = _this.calculateAngle().toFixed(2) + '°'
|
|
104
|
-
const p0 = _this.pointArray[0]
|
|
105
|
-
const p1 = _this.pointArray[1]
|
|
106
|
-
const p2 = _this.pointArray[2]
|
|
107
|
-
const v1 = new THREE.Vector3((p0.x + p1.x) / 2, (p0.y + p1.y) / 2, (p0.z + p1.z) / 2)
|
|
108
|
-
const v2 = new THREE.Vector3((p1.x + p2.x) / 2, (p1.y + p2.y) / 2, (p1.z + p2.z) / 2)
|
|
109
|
-
const curve = new THREE.CatmullRomCurve3(
|
|
110
|
-
|
|
111
|
-
)
|
|
112
|
-
const points = curve.getPoints(50)
|
|
110
|
+
const angle = _this.calculateAngle().toFixed(2) + '°';
|
|
111
|
+
const p0 = _this.pointArray[0];
|
|
112
|
+
const p1 = _this.pointArray[1];
|
|
113
|
+
const p2 = _this.pointArray[2];
|
|
114
|
+
const v1 = new THREE.Vector3((p0.x + p1.x) / 2, (p0.y + p1.y) / 2, (p0.z + p1.z) / 2);
|
|
115
|
+
const v2 = new THREE.Vector3((p1.x + p2.x) / 2, (p1.y + p2.y) / 2, (p1.z + p2.z) / 2);
|
|
116
|
+
const curve = new THREE.CatmullRomCurve3([v1, v2]);
|
|
117
|
+
const points = curve.getPoints(50);
|
|
113
118
|
if (_this.tempLabel) {
|
|
114
|
-
_this.tempLabel.element.textContent = angle
|
|
115
|
-
_this.tempLabel.position.set(p1.x, p1.y, p1.z)
|
|
116
|
-
_this.curveLine.geometry.setFromPoints(points)
|
|
119
|
+
_this.tempLabel.element.textContent = angle;
|
|
120
|
+
_this.tempLabel.position.set(p1.x, p1.y, p1.z);
|
|
121
|
+
_this.curveLine.geometry.setFromPoints(points);
|
|
117
122
|
} else {
|
|
118
|
-
_this.tempLabel = _this.createLabel('measure-label', angle, p1)
|
|
119
|
-
_this.labels.push(_this.tempLabel)
|
|
120
|
-
_this.scene.add(_this.tempLabel)
|
|
121
|
-
|
|
123
|
+
_this.tempLabel = _this.createLabel('measure-label', angle, p1);
|
|
124
|
+
_this.labels.push(_this.tempLabel);
|
|
125
|
+
_this.scene.add(_this.tempLabel);
|
|
126
|
+
_this.createCurve(points);
|
|
122
127
|
}
|
|
123
128
|
}
|
|
124
129
|
if (_this.tipsLabel) {
|
|
125
|
-
_this.tipsLabel.position.set(point.x + 0.1, point.y, point.z + 0.05)
|
|
130
|
+
_this.tipsLabel.position.set(point.x + 0.1, point.y, point.z + 0.05);
|
|
126
131
|
}
|
|
127
132
|
}
|
|
128
133
|
},
|
|
129
134
|
createTipsLabel(label, position) {
|
|
130
|
-
const div = document.createElement('div')
|
|
131
|
-
div.className = 'tips-label'
|
|
132
|
-
div.textContent = label
|
|
133
|
-
const tipsLabel = new CSS2DObject(div)
|
|
134
|
-
tipsLabel.position.set(position.x + 0.1, position.y, position.z + 0.05)
|
|
135
|
-
return tipsLabel
|
|
135
|
+
const div = document.createElement('div');
|
|
136
|
+
div.className = 'tips-label';
|
|
137
|
+
div.textContent = label;
|
|
138
|
+
const tipsLabel = new CSS2DObject(div);
|
|
139
|
+
tipsLabel.position.set(position.x + 0.1, position.y, position.z + 0.05);
|
|
140
|
+
return tipsLabel;
|
|
136
141
|
},
|
|
137
142
|
mousedown() {
|
|
138
143
|
this.firstTime = new Date().getTime();
|
|
139
144
|
},
|
|
140
145
|
click(e) {
|
|
141
146
|
let lastTime = new Date().getTime();
|
|
142
|
-
if (lastTime
|
|
147
|
+
if (lastTime - this.firstTime < 300) {
|
|
143
148
|
if (_this.isCompleted) {
|
|
144
|
-
_this.renderer.domElement.addEventListener('mousemove', _this.mousemove)
|
|
149
|
+
_this.renderer.domElement.addEventListener('mousemove', _this.mousemove);
|
|
145
150
|
}
|
|
146
|
-
clearTimeout(_this.timer)
|
|
151
|
+
clearTimeout(_this.timer);
|
|
147
152
|
_this.timer = setTimeout(() => {
|
|
148
|
-
_this.isCompleted = false
|
|
149
|
-
const point = _this.getPosition(e)
|
|
153
|
+
_this.isCompleted = false;
|
|
154
|
+
const point = _this.getPosition(e);
|
|
150
155
|
if (point) {
|
|
151
|
-
if(_this.tipsLabel) {
|
|
152
|
-
_this.tipsLabel.position.set(point.x + 0.1, point.y, point.z + 0.05)
|
|
156
|
+
if (_this.tipsLabel) {
|
|
157
|
+
_this.tipsLabel.position.set(point.x + 0.1, point.y, point.z + 0.05);
|
|
153
158
|
} else {
|
|
154
|
-
_this.tipsLabel = _this.createTipsLabel('左击绘制右击结束', point)
|
|
155
|
-
_this.scene.add(_this.tipsLabel)
|
|
159
|
+
_this.tipsLabel = _this.createTipsLabel('左击绘制右击结束', point);
|
|
160
|
+
_this.scene.add(_this.tipsLabel);
|
|
156
161
|
}
|
|
157
162
|
if (_this.tempPoints) {
|
|
158
|
-
_this.tempPoints.position.set(point.x, point.y, point.z)
|
|
159
|
-
_this.tempPoints = undefined
|
|
163
|
+
_this.tempPoints.position.set(point.x, point.y, point.z);
|
|
164
|
+
_this.tempPoints = undefined;
|
|
160
165
|
} else {
|
|
161
|
-
const geom =_this.createLabel('circle-tag', '', point)
|
|
162
|
-
_this.points.push(geom)
|
|
163
|
-
_this.scene.add(geom)
|
|
166
|
+
const geom = _this.createLabel('circle-tag', '', point);
|
|
167
|
+
_this.points.push(geom);
|
|
168
|
+
_this.scene.add(geom);
|
|
164
169
|
}
|
|
165
|
-
_this.tempLine = undefined
|
|
166
|
-
_this.tempLabel = undefined
|
|
167
|
-
_this.pointArray.push(point)
|
|
170
|
+
_this.tempLine = undefined;
|
|
171
|
+
_this.tempLabel = undefined;
|
|
172
|
+
_this.pointArray.push(point);
|
|
168
173
|
}
|
|
169
|
-
})
|
|
174
|
+
});
|
|
170
175
|
}
|
|
171
|
-
|
|
172
176
|
},
|
|
173
177
|
rightClick(e) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
_this.tipsLabel
|
|
178
|
+
_this.preventContextMenu(e);
|
|
179
|
+
if (_this.tipsLabel) {
|
|
180
|
+
_this.scene.remove(_this.tipsLabel);
|
|
181
|
+
_this.tipsLabel = undefined;
|
|
177
182
|
}
|
|
178
|
-
clearTimeout(_this.timer)
|
|
179
|
-
const point =
|
|
183
|
+
clearTimeout(_this.timer);
|
|
184
|
+
const point = _this.getPosition(e);
|
|
180
185
|
if (point) {
|
|
181
|
-
_this.isCompleted = true
|
|
182
|
-
_this.tempPoints = undefined
|
|
183
|
-
_this.tempLine = undefined
|
|
184
|
-
_this.tempLabel = undefined
|
|
185
|
-
_this.pointArray.splice(0)
|
|
186
|
-
_this.renderer.domElement.removeEventListener('mousemove', _this.mousemove)
|
|
186
|
+
_this.isCompleted = true;
|
|
187
|
+
_this.tempPoints = undefined;
|
|
188
|
+
_this.tempLine = undefined;
|
|
189
|
+
_this.tempLabel = undefined;
|
|
190
|
+
_this.pointArray.splice(0);
|
|
191
|
+
_this.renderer.domElement.removeEventListener('mousemove', _this.mousemove);
|
|
187
192
|
}
|
|
188
193
|
},
|
|
189
194
|
close() {
|
|
190
|
-
this.renderer.domElement.removeEventListener('mouseup', this.click, false)
|
|
191
|
-
this.renderer.domElement.removeEventListener('mousedown', this.mousedown, false)
|
|
192
|
-
this.renderer.domElement.removeEventListener('mousemove',
|
|
193
|
-
this.renderer.domElement.removeEventListener('contextmenu', this.rightClick, false)
|
|
194
|
-
this.remove(this.points)
|
|
195
|
-
this.remove(this.polyline)
|
|
196
|
-
this.remove(this.labels)
|
|
197
|
-
this.remove(this.curves)
|
|
198
|
-
this.pointArray.splice(0)
|
|
199
|
-
this.points.splice(0)
|
|
200
|
-
this.polyline.splice(0)
|
|
201
|
-
this.labels.splice(0)
|
|
202
|
-
this.curves.splice(0)
|
|
203
|
-
this.tempPoints = undefined
|
|
204
|
-
this.tempLabel = undefined
|
|
205
|
-
this.tempLine = undefined
|
|
206
|
-
this.scene.remove(this.tipsLabel)
|
|
207
|
-
this.tipsLabel = undefined
|
|
208
|
-
this.renderer.domElement.style.cursor = 'pointer'
|
|
195
|
+
this.renderer.domElement.removeEventListener('mouseup', this.click, false);
|
|
196
|
+
this.renderer.domElement.removeEventListener('mousedown', this.mousedown, false);
|
|
197
|
+
this.renderer.domElement.removeEventListener('mousemove', this.mousemove, false);
|
|
198
|
+
this.renderer.domElement.removeEventListener('contextmenu', this.rightClick, false);
|
|
199
|
+
this.remove(this.points);
|
|
200
|
+
this.remove(this.polyline);
|
|
201
|
+
this.remove(this.labels);
|
|
202
|
+
this.remove(this.curves);
|
|
203
|
+
this.pointArray.splice(0);
|
|
204
|
+
this.points.splice(0);
|
|
205
|
+
this.polyline.splice(0);
|
|
206
|
+
this.labels.splice(0);
|
|
207
|
+
this.curves.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';
|
|
209
214
|
},
|
|
210
215
|
remove(array) {
|
|
211
216
|
for (let index = 0; index < array.length; index++) {
|
|
212
|
-
const element = array[index]
|
|
217
|
+
const element = array[index];
|
|
213
218
|
if (element.geometry) {
|
|
214
|
-
element.geometry.dispose()
|
|
219
|
+
element.geometry.dispose();
|
|
215
220
|
}
|
|
216
|
-
this.scene.remove(element)
|
|
221
|
+
this.scene.remove(element);
|
|
217
222
|
}
|
|
218
223
|
},
|
|
219
224
|
calculateAngle() {
|
|
220
|
-
const p1 = _this.pointArray[1].clone()
|
|
221
|
-
const p2 = _this.pointArray[1].clone()
|
|
222
|
-
const dir0 = p1.sub(_this.pointArray[0]).clone()
|
|
223
|
-
const dir1 = p2.sub(_this.pointArray[2]).clone()
|
|
224
|
-
const angle = dir0.angleTo(dir1)
|
|
225
|
-
return angle * 180 / Math.PI
|
|
225
|
+
const p1 = _this.pointArray[1].clone();
|
|
226
|
+
const p2 = _this.pointArray[1].clone();
|
|
227
|
+
const dir0 = p1.sub(_this.pointArray[0]).clone();
|
|
228
|
+
const dir1 = p2.sub(_this.pointArray[2]).clone();
|
|
229
|
+
const angle = dir0.angleTo(dir1);
|
|
230
|
+
return (angle * 180) / Math.PI;
|
|
226
231
|
},
|
|
227
232
|
createCurve(points) {
|
|
228
|
-
const geom = new THREE.BufferGeometry().setFromPoints(points)
|
|
229
|
-
const material = new THREE.LineBasicMaterial({color: 0xff0000})
|
|
230
|
-
_this.curveLine = new THREE.Line(geom, material)
|
|
231
|
-
_this.curveLine.frustumCulled = false
|
|
232
|
-
_this.curves.push(_this.curveLine)
|
|
233
|
-
_this.scene.add(_this.curveLine)
|
|
233
|
+
const geom = new THREE.BufferGeometry().setFromPoints(points);
|
|
234
|
+
const material = new THREE.LineBasicMaterial({ color: 0xff0000 });
|
|
235
|
+
_this.curveLine = new THREE.Line(geom, material);
|
|
236
|
+
_this.curveLine.frustumCulled = false;
|
|
237
|
+
_this.curves.push(_this.curveLine);
|
|
238
|
+
_this.scene.add(_this.curveLine);
|
|
234
239
|
},
|
|
235
240
|
numberToString(num) {
|
|
236
241
|
if (num < 0.0001) {
|
|
237
|
-
return num.toString()
|
|
242
|
+
return num.toString();
|
|
238
243
|
}
|
|
239
|
-
let fractionDigits = 2
|
|
244
|
+
let fractionDigits = 2;
|
|
240
245
|
if (num < 0.01) {
|
|
241
|
-
fractionDigits = 4
|
|
246
|
+
fractionDigits = 4;
|
|
242
247
|
} else if (num < 0.1) {
|
|
243
|
-
fractionDigits = 3
|
|
248
|
+
fractionDigits = 3;
|
|
244
249
|
}
|
|
245
|
-
return num.toFixed(fractionDigits)
|
|
246
|
-
}
|
|
247
|
-
|
|
250
|
+
return num.toFixed(fractionDigits);
|
|
251
|
+
},
|
|
252
|
+
preventContextMenu(event) {
|
|
253
|
+
event.preventDefault();
|
|
254
|
+
},
|
|
255
|
+
};
|
|
248
256
|
export default {
|
|
249
|
-
MeasureAngle
|
|
250
|
-
}
|
|
257
|
+
MeasureAngle,
|
|
258
|
+
};
|