fl-web-component 2.0.0-beta.1 → 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.
@@ -1424,15 +1424,6 @@ export class StreamLoader {
1424
1424
  this.updateModelRegistry(item, materialData, sceneBox, boxIndex);
1425
1425
  console.log('modelRegistry', this.modelRegistry)
1426
1426
 
1427
- // 获取区域划分数据
1428
- // const divideData = await this.getPrimitivesByDivide(item.id);
1429
-
1430
- // if (divideData && divideData.length > 0) {
1431
- // await this.batchLoadRegions(item, divideData, options);
1432
- options.onComplete?.();
1433
- // } else {
1434
- // }
1435
-
1436
1427
  return { modelResourceMap: modelResourceMapObj, sceneBox, boxIndex, item };
1437
1428
  } catch (error) {
1438
1429
  return null;
@@ -1,245 +1,245 @@
1
- import * as THREE from 'three';
2
-
3
- const NODE_TYPES = {
4
- pbsGrp: 1,
5
- major: 2,
6
- model: 3,
7
- };
8
-
9
- // 处理mesh数据,生成drawObjs
10
- function processMeshData(input, options) {
11
- const drawObjMap = new Map();
12
-
13
- if (!input.mesh) {
14
- return [];
15
- }
16
-
17
- input.mesh.forEach(meshItem => {
18
- const geomList = [];
19
- meshItem.primitives.forEach(primitive => {
20
- const primitiveData = input.primitive.find(g => g.id === primitive.prmid);
21
- if (primitiveData) {
22
- const material = input.material?.find(m => m.id === primitiveData.material);
23
- const prop = {
24
- color: material?.color || [255, 255, 255, 1],
25
- fontsize: material?.fontsize !== undefined ? material?.fontsize : 20,
26
- frontname: material?.frontname !== undefined ? material?.frontname : '',
27
- italic: material?.italic,
28
- linepacing: 1, // 默认值
29
- linewidth: material?.linewidth !== undefined ? material?.linewidth : 1, // 默认值
30
- visible: material?.visible === false ? false : true,
31
- transparent: material?.transp !== undefined ? material?.transp : 0,
32
- };
33
-
34
- const identity = new THREE.Matrix4().identity();
35
-
36
- geomList.push({
37
- matrix: {
38
- val: primitive.matrix?.length ? primitive.matrix : identity.elements,
39
- // val: identity.elements,
40
- },
41
- // originMatrix: meshItem.id == primitive.prmid ? [] : identity.elements,
42
- prmid: primitive.prmid,
43
- geomId: primitiveData.id,
44
- type: primitiveData.geomType,
45
- text: primitiveData.geomText,
46
- points: primitiveData.position,
47
- alignType: primitiveData.alignType,
48
- normals: primitiveData.normal,
49
- triangles: primitiveData.indices || [],
50
- max: primitiveData.max,
51
- min: primitiveData.min,
52
- prop: prop,
53
- });
54
- }
55
- });
56
-
57
- drawObjMap.set(meshItem.id, {
58
- drawObjId: meshItem.id,
59
- geoms: geomList,
60
- // lodLevel: meshItem.type || 2,
61
- });
62
- });
63
-
64
- return Array.from(drawObjMap.values());
65
- }
66
-
67
- // 处理node数据,生成instances
68
- function processNodeData(input, options) {
69
- const flatNode = options?.flatNode;
70
-
71
- function flattenAndComputeWorldMatrices(
72
- nodes,
73
- result = [],
74
- // parentWorldMatrix = null,
75
- fatherId = ''
76
- ) {
77
- for (const node of nodes) {
78
- const { category, instanceId, matrix, children, drawObject, groupId, nodeType } = node;
79
-
80
- // 构造本地矩阵
81
- let localMatrix;
82
- if (matrix && matrix.val) {
83
- localMatrix = new THREE.Matrix4().fromArray(matrix.val);
84
- } else {
85
- localMatrix = new THREE.Matrix4().identity(); // 默认为单位矩阵
86
- }
87
-
88
- // 计算世界矩阵
89
- // const worldMatrix = parentWorldMatrix
90
- // ? parentWorldMatrix.clone().multiply(localMatrix)
91
- // : localMatrix.clone();
92
- const worldMatrix = localMatrix.clone();
93
-
94
- // 构造输出节点
95
- result.push({
96
- drawObject,
97
- category,
98
- instanceId,
99
- // matrix,
100
- matrix: {
101
- val: Array.from(worldMatrix.toArray()),
102
- },
103
- fatherId,
104
- groupId,
105
- nodeType,
106
- });
107
-
108
- // 递归处理子节点,传递当前世界矩阵
109
- if (children) {
110
- flattenAndComputeWorldMatrices(children, result, instanceId);
111
- }
112
- }
113
-
114
- return result;
115
- }
116
-
117
- if(!flatNode){
118
- const formatInstances = [];
119
- const preNode = input.node ? input.node : generateNode(input.mesh);
120
- const rootInstances = parseNode(preNode);
121
- flattenAndComputeWorldMatrices(rootInstances, formatInstances);
122
-
123
- return formatInstances
124
- }else{
125
- return parseNode(input.node, flatNode);
126
- }
127
- }
128
-
129
- // 处理一个primitive,生成多个drawObj
130
- function processOnePrimtiveToMultiMesh(primitive){
131
- return {
132
- instanceId: primitive.drawObjId, // 实例与drawObj一对多关系
133
- drawObject: primitive.geoms[0]?.prmid || '',
134
- matrix: primitive.geoms[0]?.matrix || [],
135
- }
136
- }
137
-
138
- // 主解析函数,整合两个独立模块的结果
139
- function parseData(input, options) {
140
- const drawObjs = processMeshData(input, options);
141
- const instances = drawObjs.map((item) => {
142
- return processOnePrimtiveToMultiMesh(item); // 实例与drawObj一对多关系
143
- })
144
- // const instances = drawObjs.map((item) => {
145
- // return {
146
- // instanceId: item.drawObjId, // 实例与drawObj一对一关系
147
- // drawObject: item.drawObjId,
148
- // }
149
- // })
150
- // const instances = processNodeData(input);
151
-
152
- const map = {
153
- drawObjs,
154
- instances,
155
- };
156
- // console.log('parseData', map);
157
- return map;
158
- }
159
-
160
- // 递归处理节点实例
161
- function parseNode(node, isFlatNode) {
162
- function processInstance(instance, parentInstanceId, instanceMap, groupId, isFlatNode) {
163
- const newInstance = {
164
- category: instance.category || instance.name,
165
- drawObject: instance.drawObject || instance.mesh,
166
- fatherId: parentInstanceId || '',
167
- instanceId: instance.id || instance.batchId,
168
- matrix: instance.matrix,
169
- children: [],
170
- nodeType: instance.nodeType,
171
- groupId: instance.nodeType === NODE_TYPES.pbsGrp ? instance._batchId : groupId,
172
- };
173
-
174
- if(!isFlatNode){
175
- // 处理子实例
176
- if (instance.children && instance.children.length > 0) {
177
- instance.children.forEach(childId => {
178
- const childInstance = instanceMap.get(childId);
179
- if (childInstance) {
180
- const processedChild = processInstance(
181
- childInstance,
182
- instance._batchId,
183
- instanceMap,
184
- newInstance.groupId
185
- );
186
- newInstance.children.push(processedChild);
187
- }
188
- });
189
- }
190
- }
191
-
192
- return newInstance;
193
- }
194
-
195
- const rootInstances = [];
196
- // 创建实例映射
197
- if(!isFlatNode){
198
- const instanceMap = new Map();
199
- node.forEach(instance => {
200
- instanceMap.set(instance.id, instance);
201
- });
202
-
203
- // 处理根实例
204
- instanceMap.forEach(instance => {
205
- let isRoot = true;
206
- instanceMap.forEach(otherInstance => {
207
- if (otherInstance.children && otherInstance.children.includes(instance.id)) {
208
- isRoot = false;
209
- }
210
- });
211
- if (isRoot) {
212
- const processed = processInstance(instance, instance._batchId, instanceMap);
213
- rootInstances.push(processed);
214
- }
215
- });
216
- }else{
217
- // 处理根实例
218
- node.forEach(instance => {
219
- const processed = processInstance(instance, instance._batchId, {}, 0, isFlatNode);
220
- rootInstances.push(processed);
221
- });
222
- }
223
- return rootInstances
224
- }
225
- // 生成默认node节点
226
- function generateNode(mesh) {
227
- let nodes = [];
228
- mesh.forEach(item => {
229
- if (item.primitives.length) {
230
- let tempNode = {
231
- id: item.id,
232
- _batchId: item.id,
233
- name: item.id,
234
- mesh: item.id,
235
- matrix: {},
236
- nodeType: 3,
237
- };
238
- nodes.push(tempNode);
239
- }
240
- });
241
-
242
- return nodes;
243
- }
244
-
245
- export { parseData, parseNode, processMeshData, processNodeData };
1
+ import * as THREE from 'three';
2
+
3
+ const NODE_TYPES = {
4
+ pbsGrp: 1,
5
+ major: 2,
6
+ model: 3,
7
+ };
8
+
9
+ // 处理mesh数据,生成drawObjs
10
+ function processMeshData(input, options) {
11
+ const drawObjMap = new Map();
12
+
13
+ if (!input.mesh) {
14
+ return [];
15
+ }
16
+
17
+ input.mesh.forEach(meshItem => {
18
+ const geomList = [];
19
+ meshItem.primitives.forEach(primitive => {
20
+ const primitiveData = input.primitive.find(g => g.id === primitive.prmid);
21
+ if (primitiveData) {
22
+ const material = input.material?.find(m => m.id === primitiveData.material);
23
+ const prop = {
24
+ color: material?.color || [255, 255, 255, 1],
25
+ fontsize: material?.fontsize !== undefined ? material?.fontsize : 20,
26
+ frontname: material?.frontname !== undefined ? material?.frontname : '',
27
+ italic: material?.italic,
28
+ linepacing: 1, // 默认值
29
+ linewidth: material?.linewidth !== undefined ? material?.linewidth : 1, // 默认值
30
+ visible: material?.visible === false ? false : true,
31
+ transparent: material?.transp !== undefined ? material?.transp : 0,
32
+ };
33
+
34
+ const identity = new THREE.Matrix4().identity();
35
+
36
+ geomList.push({
37
+ matrix: {
38
+ val: primitive.matrix?.length ? primitive.matrix : identity.elements,
39
+ // val: identity.elements,
40
+ },
41
+ // originMatrix: meshItem.id == primitive.prmid ? [] : identity.elements,
42
+ prmid: primitive.prmid,
43
+ geomId: primitiveData.id,
44
+ type: primitiveData.geomType,
45
+ text: primitiveData.geomText,
46
+ points: primitiveData.position,
47
+ alignType: primitiveData.alignType,
48
+ normals: primitiveData.normal,
49
+ triangles: primitiveData.indices || [],
50
+ max: primitiveData.max,
51
+ min: primitiveData.min,
52
+ prop: prop,
53
+ });
54
+ }
55
+ });
56
+
57
+ drawObjMap.set(meshItem.id, {
58
+ drawObjId: meshItem.id,
59
+ geoms: geomList,
60
+ // lodLevel: meshItem.type || 2,
61
+ });
62
+ });
63
+
64
+ return Array.from(drawObjMap.values());
65
+ }
66
+
67
+ // 处理node数据,生成instances
68
+ function processNodeData(input, options) {
69
+ const flatNode = options?.flatNode;
70
+
71
+ function flattenAndComputeWorldMatrices(
72
+ nodes,
73
+ result = [],
74
+ // parentWorldMatrix = null,
75
+ fatherId = ''
76
+ ) {
77
+ for (const node of nodes) {
78
+ const { category, instanceId, matrix, children, drawObject, groupId, nodeType } = node;
79
+
80
+ // 构造本地矩阵
81
+ let localMatrix;
82
+ if (matrix && matrix.val) {
83
+ localMatrix = new THREE.Matrix4().fromArray(matrix.val);
84
+ } else {
85
+ localMatrix = new THREE.Matrix4().identity(); // 默认为单位矩阵
86
+ }
87
+
88
+ // 计算世界矩阵
89
+ // const worldMatrix = parentWorldMatrix
90
+ // ? parentWorldMatrix.clone().multiply(localMatrix)
91
+ // : localMatrix.clone();
92
+ const worldMatrix = localMatrix.clone();
93
+
94
+ // 构造输出节点
95
+ result.push({
96
+ drawObject,
97
+ category,
98
+ instanceId,
99
+ // matrix,
100
+ matrix: {
101
+ val: Array.from(worldMatrix.toArray()),
102
+ },
103
+ fatherId,
104
+ groupId,
105
+ nodeType,
106
+ });
107
+
108
+ // 递归处理子节点,传递当前世界矩阵
109
+ if (children) {
110
+ flattenAndComputeWorldMatrices(children, result, instanceId);
111
+ }
112
+ }
113
+
114
+ return result;
115
+ }
116
+
117
+ if(!flatNode){
118
+ const formatInstances = [];
119
+ const preNode = input.node ? input.node : generateNode(input.mesh);
120
+ const rootInstances = parseNode(preNode);
121
+ flattenAndComputeWorldMatrices(rootInstances, formatInstances);
122
+
123
+ return formatInstances
124
+ }else{
125
+ return parseNode(input.node, flatNode);
126
+ }
127
+ }
128
+
129
+ // 处理一个primitive,生成多个drawObj
130
+ function processOnePrimtiveToMultiMesh(primitive){
131
+ return {
132
+ instanceId: primitive.drawObjId, // 实例与drawObj一对多关系
133
+ drawObject: primitive.geoms[0]?.prmid || '',
134
+ matrix: primitive.geoms[0]?.matrix || [],
135
+ }
136
+ }
137
+
138
+ // 主解析函数,整合两个独立模块的结果
139
+ function parseData(input, options) {
140
+ const drawObjs = processMeshData(input, options);
141
+ const instances = drawObjs.map((item) => {
142
+ return processOnePrimtiveToMultiMesh(item); // 实例与drawObj一对多关系
143
+ })
144
+ // const instances = drawObjs.map((item) => {
145
+ // return {
146
+ // instanceId: item.drawObjId, // 实例与drawObj一对一关系
147
+ // drawObject: item.drawObjId,
148
+ // }
149
+ // })
150
+ // const instances = processNodeData(input);
151
+
152
+ const map = {
153
+ drawObjs,
154
+ instances,
155
+ };
156
+ // console.log('parseData', map);
157
+ return map;
158
+ }
159
+
160
+ // 递归处理节点实例
161
+ function parseNode(node, isFlatNode) {
162
+ function processInstance(instance, parentInstanceId, instanceMap, groupId, isFlatNode) {
163
+ const newInstance = {
164
+ category: instance.category || instance.name,
165
+ drawObject: instance.drawObject || instance.mesh,
166
+ fatherId: parentInstanceId || '',
167
+ instanceId: instance.id || instance.batchId,
168
+ matrix: instance.matrix,
169
+ children: [],
170
+ nodeType: instance.nodeType,
171
+ groupId: instance.nodeType === NODE_TYPES.pbsGrp ? instance._batchId : groupId,
172
+ };
173
+
174
+ if(!isFlatNode){
175
+ // 处理子实例
176
+ if (instance.children && instance.children.length > 0) {
177
+ instance.children.forEach(childId => {
178
+ const childInstance = instanceMap.get(childId);
179
+ if (childInstance) {
180
+ const processedChild = processInstance(
181
+ childInstance,
182
+ instance._batchId,
183
+ instanceMap,
184
+ newInstance.groupId
185
+ );
186
+ newInstance.children.push(processedChild);
187
+ }
188
+ });
189
+ }
190
+ }
191
+
192
+ return newInstance;
193
+ }
194
+
195
+ const rootInstances = [];
196
+ // 创建实例映射
197
+ if(!isFlatNode){
198
+ const instanceMap = new Map();
199
+ node.forEach(instance => {
200
+ instanceMap.set(instance.id, instance);
201
+ });
202
+
203
+ // 处理根实例
204
+ instanceMap.forEach(instance => {
205
+ let isRoot = true;
206
+ instanceMap.forEach(otherInstance => {
207
+ if (otherInstance.children && otherInstance.children.includes(instance.id)) {
208
+ isRoot = false;
209
+ }
210
+ });
211
+ if (isRoot) {
212
+ const processed = processInstance(instance, instance._batchId, instanceMap);
213
+ rootInstances.push(processed);
214
+ }
215
+ });
216
+ }else{
217
+ // 处理根实例
218
+ node.forEach(instance => {
219
+ const processed = processInstance(instance, instance._batchId, {}, 0, isFlatNode);
220
+ rootInstances.push(processed);
221
+ });
222
+ }
223
+ return rootInstances
224
+ }
225
+ // 生成默认node节点
226
+ function generateNode(mesh) {
227
+ let nodes = [];
228
+ mesh.forEach(item => {
229
+ if (item.primitives.length) {
230
+ let tempNode = {
231
+ id: item.id,
232
+ _batchId: item.id,
233
+ name: item.id,
234
+ mesh: item.id,
235
+ matrix: {},
236
+ nodeType: 3,
237
+ };
238
+ nodes.push(tempNode);
239
+ }
240
+ });
241
+
242
+ return nodes;
243
+ }
244
+
245
+ export { parseData, parseNode, processMeshData, processNodeData };
@@ -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 MeasureAngle = function (renderer, scene, camera, width, height) {
5
6
  this.renderer = renderer;
@@ -56,13 +57,29 @@ MeasureAngle.prototype = {
56
57
  _this.raycaster.setFromCamera(mouse, this.camera);
57
58
  let intersects = _this.raycaster.intersectObjects(_this.scene.children, true);
58
59
  if (intersects.length > 0) {
59
- return intersects[0].point;
60
+ return { point: intersects[0].point, isModel: true };
60
61
  }
62
+
63
+ // 如果没有交点,构建一个基于最后一个确认点且面向相机的平面
64
+ if (_this.pointArray && _this.pointArray.length > 0) {
65
+ const lastPoint = _this.pointArray.length === 1
66
+ ? _this.pointArray[0]
67
+ : _this.pointArray[_this.pointArray.length - 2];
68
+ const cameraDir = new THREE.Vector3();
69
+ _this.camera.getWorldDirection(cameraDir);
70
+ const plane = new THREE.Plane().setFromNormalAndCoplanarPoint(cameraDir, lastPoint);
71
+ const target = new THREE.Vector3();
72
+ _this.raycaster.ray.intersectPlane(plane, target);
73
+ if (target) {
74
+ return { point: target, isModel: false };
75
+ }
76
+ }
77
+
61
78
  // 如果没有交点,则创建一个在相机视图平面上的点
62
- const ray = new THREE.Ray();
63
- _this.raycaster.ray.intersectPlane(_this.plane, ray.origin);
64
- if (ray.origin) {
65
- return ray.origin;
79
+ const target = new THREE.Vector3();
80
+ _this.raycaster.ray.intersectPlane(_this.plane, target);
81
+ if (target) {
82
+ return { point: target, isModel: false };
66
83
  }
67
84
  return null;
68
85
  },
@@ -75,9 +92,16 @@ MeasureAngle.prototype = {
75
92
  return sphere;
76
93
  },
77
94
  createLine(p1, p2, config = { color: 0xff0000 }) {
78
- const lineMaterial = new THREE.LineBasicMaterial({ color: config.color, linewidth: 10 });
95
+ const lineMaterial = new THREE.LineBasicMaterial({
96
+ color: config.color,
97
+ linewidth: 10,
98
+ depthTest: false,
99
+ depthWrite: false,
100
+ transparent: true,
101
+ });
79
102
  const lineGeometry = new THREE.BufferGeometry().setFromPoints([p1, p2]);
80
103
  const line = new THREE.Line(lineGeometry, lineMaterial);
104
+ line.renderOrder = 999;
81
105
  line.frustumCulled = false;
82
106
  return line;
83
107
  },
@@ -91,8 +115,9 @@ MeasureAngle.prototype = {
91
115
  },
92
116
  mousemove(e) {
93
117
  if (_this.isCompleted || _this.pointArray.length === 0) return;
94
- const point = _this.getPosition(e);
95
- if (point) {
118
+ const positionResult = _this.getPosition(e);
119
+ if (positionResult) {
120
+ const point = positionResult.point;
96
121
  _this.pointArray.length === 1
97
122
  ? _this.pointArray.push(point)
98
123
  : _this.pointArray.splice(_this.pointArray.length - 1, 1, point);
@@ -160,8 +185,13 @@ MeasureAngle.prototype = {
160
185
  clearTimeout(_this.timer);
161
186
  _this.timer = setTimeout(() => {
162
187
  _this.isCompleted = false;
163
- const point = _this.getPosition(e);
164
- if (point) {
188
+ const positionResult = _this.getPosition(e);
189
+ if (positionResult) {
190
+ const { point, isModel } = positionResult;
191
+ if (!isModel) {
192
+ Message.warning('请点击模型进行测量');
193
+ return;
194
+ }
165
195
  if (_this.tipsLabel) {
166
196
  _this.tipsLabel.position.set(point.x + 0.1, point.y, point.z + 0.05);
167
197
  } else {
@@ -190,8 +220,8 @@ MeasureAngle.prototype = {
190
220
  _this.tipsLabel = undefined;
191
221
  }
192
222
  clearTimeout(_this.timer);
193
- const point = _this.getPosition(e);
194
- if (point) {
223
+ const positionResult = _this.getPosition(e);
224
+ if (positionResult) {
195
225
  _this.isCompleted = true;
196
226
  _this.tempPoints = undefined;
197
227
  _this.tempLine = undefined;
@@ -240,8 +270,15 @@ MeasureAngle.prototype = {
240
270
  },
241
271
  createCurve(points) {
242
272
  const geom = new THREE.BufferGeometry().setFromPoints(points);
243
- const material = new THREE.LineBasicMaterial({ color: 0xff0000 });
273
+ const material = new THREE.LineBasicMaterial({
274
+ color: 0xff0000,
275
+ linewidth: 20,
276
+ depthTest: false,
277
+ depthWrite: false,
278
+ transparent: true,
279
+ });
244
280
  _this.curveLine = new THREE.Line(geom, material);
281
+ _this.curveLine.renderOrder = 999;
245
282
  _this.curveLine.frustumCulled = false;
246
283
  _this.curves.push(_this.curveLine);
247
284
  _this.scene.add(_this.curveLine);