fl-web-component 1.4.9-beta.0 → 2.0.0-beta.10

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.
@@ -1,5 +1,6 @@
1
1
  import * as THREE from 'three';
2
2
  import { CSS2DObject } from 'three/examples/jsm/renderers/CSS2DRenderer';
3
+ import { Message } from 'element-ui';
3
4
  var _this = null;
4
5
  var MeasureArea = function (renderer, scene, camera, width, height) {
5
6
  this.renderer = renderer;
@@ -54,21 +55,43 @@ MeasureArea.prototype = {
54
55
  _this.raycaster.setFromCamera(mouse, _this.camera);
55
56
  let intersects = _this.raycaster.intersectObjects(_this.scene.children, true);
56
57
  if (intersects.length > 0) {
57
- return intersects[0].point;
58
+ return { point: intersects[0].point, isModel: true };
59
+ }
60
+
61
+ // 如果没有交点,构建一个基于最后一个确认点且面向相机的平面
62
+ if (_this.pointArray && _this.pointArray.length > 0) {
63
+ const lastPoint = _this.pointArray.length === 1
64
+ ? _this.pointArray[0]
65
+ : _this.pointArray[_this.pointArray.length - 2];
66
+ const cameraDir = new THREE.Vector3();
67
+ _this.camera.getWorldDirection(cameraDir);
68
+ const plane = new THREE.Plane().setFromNormalAndCoplanarPoint(cameraDir, lastPoint);
69
+ const target = new THREE.Vector3();
70
+ _this.raycaster.ray.intersectPlane(plane, target);
71
+ if (target) {
72
+ return { point: target, isModel: false };
73
+ }
58
74
  }
59
75
 
60
76
  // 如果没有交点,则创建一个在相机视图平面上的点
61
- const ray = new THREE.Ray();
62
- _this.raycaster.ray.intersectPlane(_this.plane, ray.origin);
63
- if (ray.origin) {
64
- return ray.origin;
77
+ const target = new THREE.Vector3();
78
+ _this.raycaster.ray.intersectPlane(_this.plane, target);
79
+ if (target) {
80
+ return { point: target, isModel: false };
65
81
  }
66
82
  return null;
67
83
  },
68
84
  createLine(p1, p2, config = { color: 0xff0000 }) {
69
- const lineMaterial = new THREE.LineBasicMaterial({ color: config.color, linewidth: 20 });
85
+ const lineMaterial = new THREE.LineBasicMaterial({
86
+ color: config.color,
87
+ linewidth: 20,
88
+ depthTest: false,
89
+ depthWrite: false,
90
+ transparent: true,
91
+ });
70
92
  const lineGeometry = new THREE.BufferGeometry().setFromPoints([p1, p2]);
71
93
  const line = new THREE.Line(lineGeometry, lineMaterial);
94
+ line.renderOrder = 999;
72
95
  line.frustumCulled = false;
73
96
  return line;
74
97
  },
@@ -82,8 +105,9 @@ MeasureArea.prototype = {
82
105
  },
83
106
  mousemove(e) {
84
107
  if (_this.isCompleted || _this.pointArray.length === 0) return;
85
- const point = _this.getPosition(e);
86
- if (point) {
108
+ const positionResult = _this.getPosition(e);
109
+ if (positionResult) {
110
+ const point = positionResult.point;
87
111
  _this.pointArray.length === 1
88
112
  ? _this.pointArray.push(point)
89
113
  : _this.pointArray.splice(_this.pointArray.length - 1, 1, point);
@@ -153,8 +177,13 @@ MeasureArea.prototype = {
153
177
  clearTimeout(_this.timer);
154
178
  _this.timer = setTimeout(() => {
155
179
  _this.isCompleted = false;
156
- const point = _this.getPosition(e);
157
- if (point) {
180
+ const positionResult = _this.getPosition(e);
181
+ if (positionResult) {
182
+ const { point, isModel } = positionResult;
183
+ if (!isModel) {
184
+ Message.warning('请点击模型进行测量');
185
+ return;
186
+ }
158
187
  if (_this.tipsLabel) {
159
188
  _this.tipsLabel.position.set(point.x + 0.01, point.y, point.z + 0.05);
160
189
  } else {
@@ -182,8 +211,9 @@ MeasureArea.prototype = {
182
211
  _this.tipsLabel = undefined;
183
212
  }
184
213
  clearTimeout(_this.timer);
185
- const point = _this.getPosition(e);
186
- if (point) {
214
+ const positionResult = _this.getPosition(e);
215
+ if (positionResult) {
216
+ const point = positionResult.point;
187
217
  _this.isCompleted = true;
188
218
  if (_this.tempPoints) {
189
219
  _this.tempPoints.position.set(point.x, point.y, point.z);
@@ -1,5 +1,6 @@
1
1
  import * as THREE from 'three';
2
2
  import { CSS2DObject } from 'three/examples/jsm/renderers/CSS2DRenderer';
3
+ import { Message } from 'element-ui';
3
4
  var _this = null;
4
5
  var MeasureDistance = function (renderer, scene, camera, width, height) {
5
6
  this.renderer = renderer;
@@ -52,22 +53,44 @@ MeasureDistance.prototype = {
52
53
  _this.raycaster.setFromCamera(mouse, this.camera);
53
54
  let intersects = _this.raycaster.intersectObjects(_this.scene.children, true);
54
55
  if (intersects.length > 0) {
55
- return intersects[0].point;
56
+ return { point: intersects[0].point, isModel: true };
57
+ }
58
+
59
+ // 如果没有交点,构建一个基于最后一个确认点且面向相机的平面
60
+ if (_this.pointArray && _this.pointArray.length > 0) {
61
+ const lastPoint = _this.pointArray.length === 1
62
+ ? _this.pointArray[0]
63
+ : _this.pointArray[_this.pointArray.length - 2];
64
+ const cameraDir = new THREE.Vector3();
65
+ _this.camera.getWorldDirection(cameraDir);
66
+ const plane = new THREE.Plane().setFromNormalAndCoplanarPoint(cameraDir, lastPoint);
67
+ const target = new THREE.Vector3();
68
+ _this.raycaster.ray.intersectPlane(plane, target);
69
+ if (target) {
70
+ return { point: target, isModel: false };
71
+ }
56
72
  }
57
73
 
58
74
  // 如果没有交点,则创建一个在相机视图平面上的点
59
- const ray = new THREE.Ray();
60
- _this.raycaster.ray.intersectPlane(_this.plane, ray.origin);
61
- if (ray.origin) {
62
- return ray.origin;
75
+ const target = new THREE.Vector3();
76
+ _this.raycaster.ray.intersectPlane(_this.plane, target);
77
+ if (target) {
78
+ return { point: target, isModel: false };
63
79
  }
64
80
 
65
81
  return null;
66
82
  },
67
83
  createLine(p1, p2, config = { color: 0xff0000 }) {
68
- const lineMaterial = new THREE.LineBasicMaterial({ color: config.color, linewidth: 15 });
84
+ const lineMaterial = new THREE.LineBasicMaterial({
85
+ color: config.color,
86
+ linewidth: 15,
87
+ depthTest: false,
88
+ depthWrite: false,
89
+ transparent: true,
90
+ });
69
91
  const lineGeometry = new THREE.BufferGeometry().setFromPoints([p1, p2]);
70
92
  const line = new THREE.Line(lineGeometry, lineMaterial);
93
+ line.renderOrder = 999;
71
94
  line.frustumCulled = false;
72
95
  return line;
73
96
  },
@@ -81,8 +104,9 @@ MeasureDistance.prototype = {
81
104
  },
82
105
  mousemove(e) {
83
106
  if (_this.isCompleted || _this.pointArray.length === 0) return;
84
- const point = _this.getPosition(e);
85
- if (point) {
107
+ const positionResult = _this.getPosition(e);
108
+ if (positionResult) {
109
+ const point = positionResult.point;
86
110
  _this.pointArray.length === 1
87
111
  ? _this.pointArray.push(point)
88
112
  : _this.pointArray.splice(_this.pointArray.length - 1, 1, point);
@@ -137,8 +161,14 @@ MeasureDistance.prototype = {
137
161
  clearTimeout(_this.timer);
138
162
  _this.timer = setTimeout(() => {
139
163
  _this.isCompleted = false;
140
- const point = _this.getPosition(e);
141
- if (point) {
164
+ const positionResult = _this.getPosition(e);
165
+ if (positionResult) {
166
+ const { point, isModel } = positionResult;
167
+ if (!isModel) {
168
+ // 提示请点击模型
169
+ Message.warning('请点击模型进行测量');
170
+ return;
171
+ }
142
172
  if (_this.tipsLabel) {
143
173
  _this.tipsLabel.position.set(point.x + 0.1, point.y, point.z + 0.05);
144
174
  } else {
@@ -167,8 +197,8 @@ MeasureDistance.prototype = {
167
197
  _this.tipsLabel = undefined;
168
198
  }
169
199
  clearTimeout(_this.timer);
170
- const point = _this.getPosition(e);
171
- if (point) {
200
+ const positionResult = _this.getPosition(e);
201
+ if (positionResult) {
172
202
  _this.isCompleted = true;
173
203
  _this.tempPoints = undefined;
174
204
  _this.tempLine = undefined;