fl-web-component 0.1.1 → 1.0.1

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.
Files changed (78) hide show
  1. package/dist/fl-web-component.common.js +14751 -54489
  2. package/dist/fl-web-component.common.js.map +1 -1
  3. package/dist/fl-web-component.css +1 -1
  4. package/dist/fl-web-component.umd.js +14751 -54489
  5. package/dist/fl-web-component.umd.js.map +1 -1
  6. package/dist/fl-web-component.umd.min.js +3 -3
  7. package/dist/fl-web-component.umd.min.js.map +1 -1
  8. package/package.json +28 -5
  9. package/packages/components/button/index.vue +18 -17
  10. package/packages/components/com-card/card-page.vue +51 -49
  11. package/packages/components/com-card/index.vue +20 -21
  12. package/packages/components/com-dialogWrapper/index.vue +18 -21
  13. package/packages/components/com-flcanvas/components/bspline.js +91 -0
  14. package/packages/components/com-flcanvas/components/entityFormatting.js +503 -0
  15. package/packages/components/com-flcanvas/components/round10.js +24 -0
  16. package/packages/components/com-flcanvas/index.vue +259 -0
  17. package/packages/components/com-formDialog/index.vue +76 -75
  18. package/packages/components/com-graphics/index.vue +1057 -226
  19. package/packages/components/com-graphics/per-control.vue +109 -0
  20. package/packages/components/com-graphics/pid.vue +168 -0
  21. package/packages/components/com-page/index.vue +33 -33
  22. package/packages/components/com-selectTree/index.vue +61 -63
  23. package/packages/components/com-table/column-default.vue +9 -14
  24. package/packages/components/com-table/column-dynamic.vue +4 -8
  25. package/packages/components/com-table/column-menu.vue +8 -8
  26. package/packages/components/com-table/column-slot.vue +4 -4
  27. package/packages/components/com-table/column.vue +7 -15
  28. package/packages/components/com-table/config.js +9 -9
  29. package/packages/components/com-table/index.vue +35 -35
  30. package/packages/components/com-table/table-page.vue +17 -17
  31. package/packages/components/com-tabs/index.vue +19 -19
  32. package/packages/components/com-treeDynamic/index.vue +45 -45
  33. package/packages/components/model/api/index.js +59 -67
  34. package/packages/components/model/api/mock/detecttree.js +38 -38
  35. package/packages/components/model/api/mock/getmodel-line.js +15830 -79332
  36. package/packages/components/model/api/mock/init.js +1 -1
  37. package/packages/components/model/api/mock/pbstree.js +486 -495
  38. package/packages/components/model/components/TextOverTooltip/index.vue +3 -3
  39. package/packages/components/model/components/annotation-toolbar.vue +4 -19
  40. package/packages/components/model/components/check-proofing-model.vue +26 -29
  41. package/packages/components/model/components/clipping-type.vue +22 -14
  42. package/packages/components/model/components/com-dialogWrapper/index.vue +22 -25
  43. package/packages/components/model/components/detect-panel.vue +38 -26
  44. package/packages/components/model/components/detect-tree.vue +9 -24
  45. package/packages/components/model/components/firstPer-panel.vue +23 -25
  46. package/packages/components/model/components/header-button.vue +31 -107
  47. package/packages/components/model/components/imageViewer/index.vue +34 -35
  48. package/packages/components/model/components/import-model.vue +127 -127
  49. package/packages/components/model/components/location-panel.vue +25 -29
  50. package/packages/components/model/components/measure-type.vue +15 -15
  51. package/packages/components/model/components/pbs-tree.vue +139 -144
  52. package/packages/components/model/components/proof-config.vue +2 -10
  53. package/packages/components/model/components/proof-for-pc.vue +35 -32
  54. package/packages/components/model/components/proof-history.vue +136 -154
  55. package/packages/components/model/components/proof-panel-detail.vue +166 -165
  56. package/packages/components/model/components/proof-panel.vue +281 -205
  57. package/packages/components/model/components/proof-project-user.vue +13 -50
  58. package/packages/components/model/components/proof-publish.vue +130 -130
  59. package/packages/components/model/components/proof-role.vue +93 -124
  60. package/packages/components/model/components/props-panel.vue +63 -54
  61. package/packages/components/model/index.vue +3225 -3213
  62. package/packages/components/model/utils/annotation-tool.js +75 -82
  63. package/packages/components/model/utils/cursor.js +15 -10
  64. package/packages/components/model/utils/detect-v1.js +23 -35
  65. package/packages/components/model/utils/index.js +25 -25
  66. package/packages/components/model/utils/threejs/measure-angle.js +180 -180
  67. package/packages/components/model/utils/threejs/measure-area.js +196 -184
  68. package/packages/components/model/utils/threejs/measure-distance.js +154 -152
  69. package/packages/components/model/utils/threejs/measure-volume.js +64 -61
  70. package/src/assets/test.png +0 -0
  71. package/src/assets/worker.glb +0 -0
  72. package/src/main.js +11 -8
  73. package/src/utils/flgltf-parser.js +141 -0
  74. package/src/utils/instance-parser.js +402 -0
  75. package/src/utils/mock.js +84746 -0
  76. package/src/utils/threejs/measure-angle.js +240 -0
  77. package/src/utils/threejs/measure-area.js +249 -0
  78. package/src/utils/threejs/measure-distance.js +195 -0
@@ -0,0 +1,141 @@
1
+ import * as THREE from 'three';
2
+
3
+ function parseData(input) {
4
+ // 辅助函数:递归处理实例
5
+ function processInstance(instance, parentInstanceId, instanceMap) {
6
+ const newInstance = {
7
+ category: instance.category || instance.name,
8
+ drawObject: instance.drawObject || instance.mesh,
9
+ fatherId: parentInstanceId || '',
10
+ instanceId: instance.instanceId || instance._batchId,
11
+ matrix: instance.matrix,
12
+ children: [],
13
+ };
14
+
15
+ // 处理子实例
16
+ if (instance.children && instance.children.length > 0) {
17
+ instance.children.forEach(childId => {
18
+ const childInstance = instanceMap.get(childId);
19
+ if (childInstance) {
20
+ const processedChild = processInstance(childInstance, instance.instanceId, instanceMap);
21
+ newInstance.children.push(processedChild);
22
+ }
23
+ });
24
+ }
25
+
26
+ return newInstance;
27
+ }
28
+
29
+ function flattenAndComputeWorldMatrices(
30
+ nodes,
31
+ result = [],
32
+ parentWorldMatrix = null,
33
+ fatherId = ''
34
+ ) {
35
+ for (const node of nodes) {
36
+ const { category, instanceId, matrix, children, drawObject } = node;
37
+
38
+ // 构造本地矩阵
39
+ let localMatrix;
40
+ if (matrix && matrix.val) {
41
+ localMatrix = new THREE.Matrix4().fromArray(matrix.val);
42
+ } else {
43
+ localMatrix = new THREE.Matrix4().identity(); // 默认为单位矩阵
44
+ }
45
+
46
+ // 计算世界矩阵
47
+ const worldMatrix = parentWorldMatrix
48
+ ? parentWorldMatrix.clone().multiply(localMatrix)
49
+ : localMatrix.clone();
50
+
51
+ // 构造输出节点
52
+ result.push({
53
+ drawObject,
54
+ category,
55
+ instanceId,
56
+ // matrix,
57
+ matrix: {
58
+ val: Array.from(worldMatrix.toArray()),
59
+ },
60
+ fatherId,
61
+ });
62
+
63
+ // 递归处理子节点,传递当前世界矩阵
64
+ if (children) {
65
+ flattenAndComputeWorldMatrices(children, result, worldMatrix, instanceId);
66
+ // flattenAndComputeWorldMatrices(children, result);
67
+ }
68
+ }
69
+
70
+ return result;
71
+ }
72
+
73
+ // 创建实例映射
74
+ const instanceMap = new Map();
75
+ input.node.forEach(instance => {
76
+ instanceMap.set(instance.id, instance);
77
+ });
78
+
79
+ // 处理根实例
80
+ const rootInstances = [];
81
+ instanceMap.forEach(instance => {
82
+ let isRoot = true;
83
+ instanceMap.forEach(otherInstance => {
84
+ if (otherInstance.children && otherInstance.children.includes(instance.id)) {
85
+ isRoot = false;
86
+ }
87
+ });
88
+ if (isRoot) {
89
+ const processed = processInstance(instance, null, instanceMap);
90
+ rootInstances.push(processed);
91
+ }
92
+ });
93
+
94
+ // const formateArray = (str) => str?.split(",").map(Number)
95
+ // 处理drawObjs
96
+ const drawObjMap = new Map();
97
+ input.mesh.forEach(meshItem => {
98
+ const geomList = [];
99
+ meshItem.primitives.forEach(primitive => {
100
+ const primitiveData = input.primitive.find(g => g.id === primitive.prmid);
101
+ if (primitiveData) {
102
+ const material = input.material?.find(m => m.id === primitiveData.material);
103
+ const prop = {
104
+ color: material?.color || [255, 255, 255, 255],
105
+ fontsize: material?.fontsize !== undefined ? material?.fontsize : 20,
106
+ frontname: material?.frontname !== undefined ? material?.frontname : '',
107
+ italic: material?.italic,
108
+ linepacing: 1, // 默认值
109
+ linewidth: material?.linewidth !== undefined ? material?.linewidth : 1, // 默认值
110
+ };
111
+
112
+ geomList.push({
113
+ geomId: primitiveData.id,
114
+ type: primitiveData.geomType,
115
+ text: primitiveData.geomText,
116
+ points: primitiveData.position,
117
+ normals: primitiveData.normal,
118
+ triangles: primitiveData.indices,
119
+ max: primitiveData.max,
120
+ min: primitiveData.min,
121
+ prop: prop,
122
+ });
123
+ }
124
+ });
125
+
126
+ drawObjMap.set(meshItem.id, {
127
+ drawObjId: meshItem.id,
128
+ geoms: geomList,
129
+ });
130
+ });
131
+
132
+ const formatInstances = [];
133
+ flattenAndComputeWorldMatrices(rootInstances, formatInstances);
134
+
135
+ return {
136
+ drawObjs: Array.from(drawObjMap.values()),
137
+ instances: formatInstances,
138
+ };
139
+ }
140
+
141
+ export { parseData };
@@ -0,0 +1,402 @@
1
+ import * as THREE from 'three';
2
+ import { FontLoader } from 'three/examples/jsm/loaders/FontLoader';
3
+ import { TextGeometry } from 'three/examples/jsm/geometries/TextGeometry.js';
4
+ import helvetikerFont from 'three/examples/fonts/helvetiker_regular.typeface.json';
5
+ import { MeshLineGeometry, MeshLineMaterial } from 'meshline';
6
+
7
+ const GEOM_TYPES = {
8
+ geom_3d: 53248,
9
+ geom_3d_text: 53249,
10
+ geom_3d_mtext: 53250,
11
+ geom_3d_obj: 53251,
12
+ geom_2d: 57344,
13
+ geom_2d_text: 57345,
14
+ geom_2d_mtext: 57346,
15
+ geom_2d_circle: 57347,
16
+ geom_2d_arc: 57348,
17
+ geom_2d_ellipse: 57349,
18
+ geom_2d_ellipseArc: 57350,
19
+ geom_2d_others: 57351,
20
+ };
21
+
22
+ let drawObjMapInstance = {};
23
+ /**
24
+ * 处理 InstancedMesh 类型模型的核心方法
25
+ * @param {Object} instance - 实例对象,包含绘制对象ID和实例ID等数据
26
+ * @param {Array} drawObjs - 绘制对象数组,包含几何数据
27
+ */
28
+ function handleInstancedMeshModel(instances, drawObjs, type, scene, customColor) {
29
+ // 第一阶段:构建实例映射表
30
+ let modelGroup = new THREE.Group();
31
+ for (let i = 0; i < instances.length; i++) {
32
+ formatInstancedMap(instances[i], drawObjs);
33
+ }
34
+
35
+ // 第二阶段:遍历所有实例进行处理
36
+ for (let i = 0; i < instances.length; i++) {
37
+ let targetGroup, instancedMeshIndex, drawObjectName;
38
+ // for (let drawObjectId in drawObjMapInstance) {
39
+ // const drawObj = drawObjMapInstance[drawObjectId];
40
+ // drawObj.MapInstance.forEach((instance, index) => {
41
+ // if (instance.instanceId == instances[i].instanceId) {
42
+ // instancedMeshIndex = index;
43
+ // drawObjectName = drawObjectId;
44
+ // }
45
+ // });
46
+ // }
47
+
48
+ const drawObjInstance = drawObjMapInstance[instances[i].drawObject];
49
+ drawObjInstance.MapInstance.forEach((instance, index) => {
50
+ if (instance.instanceId == instances[i].instanceId) {
51
+ instancedMeshIndex = index;
52
+ drawObjectName = instances[i].drawObject;
53
+ }
54
+ });
55
+ if (drawObjectName) {
56
+ targetGroup = scene.getObjectByName(drawObjectName);
57
+ }
58
+
59
+ if (!targetGroup) {
60
+ const drawObj = drawObjMapInstance[instances[i].drawObject];
61
+ const group = new THREE.Group();
62
+ group.name = instances[i].drawObject;
63
+ group.userData.isInstancedMeshGroup = true;
64
+
65
+ const instanceCount = drawObj.MapInstance.length;
66
+ drawObj.MapMesh?.forEach(mesh => {
67
+ const model = drawModel(mesh, group.name, instanceCount, customColor);
68
+ if (!model) {
69
+ return;
70
+ }
71
+ drawObj.MapInstance.forEach((instance, index) => {
72
+ if (instance.instanceId == instances[i].instanceId) {
73
+ model.userData.instanceIndex = index;
74
+ model.name = instances[i].instanceId;
75
+ const matrixVal = instance.matrix?.val;
76
+ if (matrixVal) {
77
+ const m4 = new THREE.Matrix4();
78
+ // m4.setPosition(new THREE.Vector3(9999999, 9999999, 9999999)); // TODO 临时隐藏方案
79
+ m4.elements = instance.matrix.val;
80
+ model.setMatrixAt(index, m4);
81
+ }
82
+ // 需要先设置全部实例颜色,否则后续设置颜色无效
83
+ const { color } = mesh.prop;
84
+ const meshColor = customColor
85
+ ? new THREE.Color(customColor)
86
+ : new THREE.Color(`rgb(${color[0]}, ${color[1]}, ${color[2]})`);
87
+ model.setColorAt(index, meshColor);
88
+ }
89
+ });
90
+ // model.instanceColor.needsUpdate = true;
91
+ group.add(model);
92
+ });
93
+ modelGroup.add(group);
94
+ }
95
+ }
96
+ return modelGroup;
97
+ // timeRender();
98
+ // console.log('scene', scene)
99
+ }
100
+
101
+ /**
102
+ * 构建实例模型映射表
103
+ * @param {Object} instance - 实例对象,包含绘制对象ID和实例ID等数据
104
+ * @param {Array} drawObjs - 绘制对象数组,包含几何数据
105
+ */
106
+ function formatInstancedMap(instance, drawObjs) {
107
+ const { drawObject } = instance; // 提取绘制对象ID
108
+
109
+ // 检查是否已存在该绘制对象的映射条目
110
+ if (drawObjMapInstance[drawObject]) {
111
+ // 查找是否已存在相同实例ID的记录
112
+ const hasInstance = drawObjMapInstance[drawObject]['MapInstance'].find(item => {
113
+ return item.instanceId == instance.instanceId;
114
+ });
115
+
116
+ // 不存在则添加新实例
117
+ if (!hasInstance) {
118
+ drawObjMapInstance[drawObject]['MapInstance'].push(instance);
119
+ }
120
+ } else {
121
+ // 新建绘制对象条目
122
+ drawObjMapInstance[drawObject] = {
123
+ MapInstance: [instance], // 存储实例数组
124
+ };
125
+
126
+ // 关联绘制对象的几何数据
127
+ drawObjs.forEach(item => {
128
+ if (item.drawObjId == drawObject) {
129
+ // 将几何数据映射到对应的绘制对象
130
+ drawObjMapInstance[drawObject].MapMesh = item.geoms;
131
+ }
132
+ });
133
+ }
134
+ }
135
+
136
+ /**
137
+ * 将数组数据转换为键值对形式的 JSON 对象
138
+ * @param {Array} data - 包含对象的数组,每个对象都有一个 drawObjId 属性
139
+ * @returns {Object}
140
+ */
141
+ function formatDrawObjs(data) {
142
+ const obj = {};
143
+ data.forEach(item => {
144
+ obj[item.drawObjId] = item;
145
+ });
146
+ return obj;
147
+ }
148
+ /**
149
+ * 根据几何体类型绘制对应的3D模型
150
+ * @param {Object} geom - 几何数据对象,包含类型、属性等绘制信息
151
+ * @param {String} instanceName - 实例名称,用于标识模型实例
152
+ * @param {Number} instanceCount - 实例化渲染的数量(用于InstancedMesh)
153
+ * @returns {THREE.Object3D} 返回创建的3D模型对象
154
+ */
155
+ function drawModel(geom, instanceName, instanceCount, nColor) {
156
+ let model;
157
+ // 处理二维几何体(普通2D图形和特殊2D图形)
158
+ if (geom.type == GEOM_TYPES.geom_2d || geom.type == GEOM_TYPES.geom_2d_others) {
159
+ // model = draw2Dmodel(geom, instanceName, instanceCount); // TODO 该类型调试中
160
+ // 处理二维文本类型
161
+ } else if (
162
+ geom.type == GEOM_TYPES.geom_2d_text ||
163
+ geom.type == GEOM_TYPES.geom_2d_mtext ||
164
+ geom.type == GEOM_TYPES.geom_3d_text ||
165
+ geom.type == GEOM_TYPES.geom_3d_mtext
166
+ ) {
167
+ model = drawText(geom, instanceName, instanceCount);
168
+ // 处理各种曲线类型(圆形、圆弧、椭圆、椭圆弧)
169
+ } else if (
170
+ geom.type == GEOM_TYPES.geom_2d_circle ||
171
+ geom.type == GEOM_TYPES.geom_2d_arc ||
172
+ geom.type == GEOM_TYPES.geom_2d_ellipse ||
173
+ geom.type == GEOM_TYPES.geom_2d_ellipseArc
174
+ ) {
175
+ // model = drawCurves(geom, instanceName, instanceCount);// TODO 该类型调试中
176
+ // 处理三维几何体(普通3D模型和OBJ模型)
177
+ } else if (geom.type == GEOM_TYPES.geom_3d || geom.type == GEOM_TYPES.geom_3d_obj) {
178
+ model = draw3Dmodel(geom, instanceName, instanceCount, nColor);
179
+ }
180
+ return model;
181
+ }
182
+
183
+ /**
184
+ * 绘制曲线
185
+ *
186
+ * @param {Object} geom- 包含曲线信息的几何体对象
187
+ * @param {String} instanceName- 曲线实例的名称
188
+ * @return {Object}- 包含曲线模型和曲线信息的对象
189
+ */
190
+ function drawCurves(geom, instanceName, instanceCount) {
191
+ let { points, normals } = geom;
192
+ let aX = points[0];
193
+ let aY = points[1];
194
+ let aZ = points[2];
195
+ let xrad = points[3];
196
+ let yrad = points[4];
197
+ let startAngle = points[5] ? (points[5] * Math.PI) / 180 : 0;
198
+ let endAngle = points[6] ? (points[6] * Math.PI) / 180 : 0;
199
+
200
+ let curve = new THREE.EllipseCurve(
201
+ 0,
202
+ 0,
203
+ xrad,
204
+ yrad,
205
+ startAngle,
206
+ endAngle,
207
+ false // 曲线方向为逆时针
208
+ );
209
+ let curvePoints = curve.getPoints(50);
210
+ let list = [];
211
+ for (let i = 0; i < curvePoints.length; i++) {
212
+ const { x, y } = curvePoints[i];
213
+ list.push(x);
214
+ list.push(parseFloat(y));
215
+
216
+ // // 根据角度计算动态 Z 值(例如正弦波动)
217
+ // const angle = Math.atan2(y, x); // 当前点的极角
218
+ // const z = Math.sin(angle * 2) * 2; // Z轴动态变化
219
+ // list.push(z); // 将原始的 z 坐标添加到列表中
220
+ list.push(parseFloat(0)); // 将原始的 z 坐标添加到列表中
221
+ }
222
+
223
+ const model = draw2Dmodel(
224
+ {
225
+ ...geom,
226
+ points: list,
227
+ normals,
228
+ },
229
+ instanceName,
230
+ instanceCount
231
+ );
232
+ // model.rotation.x = -Math.PI / 2;
233
+ // model.position.set(aX, aY, aZ);
234
+ const matrix = new THREE.Matrix4();
235
+ matrix.identity().makeTranslation(aX, aY, aZ);
236
+ model.applyMatrix4(matrix);
237
+
238
+ model.userData.instanceName = instanceName;
239
+ return model;
240
+ }
241
+ /**
242
+ * 创建三维模型实例化网格
243
+ * @param {Object} geom - 几何数据对象,包含顶点、法线、材质等信息
244
+ * @param {String} instanceName - 实例唯一标识名称
245
+ * @param {Number} instanceCount - 需要创建的实例数量
246
+ * @returns {THREE.InstancedMesh} - 返回创建的三维实例化网格对象
247
+ */
248
+ function draw3Dmodel(geom, instanceName, instanceCount, nColor) {
249
+ // 解构几何数据中的自定义几何体和材质
250
+ const { geometry: customGeometry, material: customMaterial, triangles, points, normals } = geom;
251
+ // 使用自定义几何体或创建新的缓冲几何体
252
+ const geometry = customGeometry || new THREE.BufferGeometry();
253
+
254
+ // 设置三角形索引数据
255
+ if (triangles && triangles.length) {
256
+ geometry.setIndex(triangles);
257
+ }
258
+
259
+ // 设置顶点位置数据
260
+ if (points && points.length) {
261
+ const position = new Float32Array(points);
262
+ geometry.setAttribute('position', new THREE.BufferAttribute(position, 3));
263
+ }
264
+
265
+ // 设置顶点法线数据
266
+ if (normals && normals.length) {
267
+ const normal = new Float32Array(normals);
268
+ geometry.setAttribute('normal', new THREE.BufferAttribute(normal, 3));
269
+ }
270
+ const { color } = geom.prop;
271
+ let material, mesh, colors;
272
+ if (Array.isArray(color) && color.length) {
273
+ colors = color;
274
+ } else if (color) {
275
+ colors = color.split(',');
276
+ } else {
277
+ colors = [255, 255, 255, 255];
278
+ }
279
+
280
+ // 使用自定义材质或创建标准材质(默认参数配置)
281
+ material =
282
+ customMaterial ||
283
+ new THREE.MeshStandardMaterial({
284
+ roughness: 0.8,
285
+ envMapIntensity: 0.5, // 调低环境贴图的强度
286
+ side: THREE.DoubleSide,
287
+ userData: {
288
+ nColor: nColor ? new THREE.Color(nColor) : new THREE.Color(`rgb(${colors[0]}, ${colors[1]}, ${colors[2]})`),
289
+ },
290
+ });
291
+
292
+ mesh = new THREE.InstancedMesh(geometry, material, instanceCount);
293
+ mesh.userData.drawObjectId = instanceName;
294
+
295
+ return mesh;
296
+ }
297
+
298
+ /**
299
+ * 绘制 2D 模型的方法
300
+ *
301
+ * @param {Object} geom - 包含几何体信息的对象
302
+ * @param {String} instanceName - 模型实例的名称
303
+ * @returns {Object} - 包含所有 2D 模型的组对象
304
+ */
305
+ function draw2Dmodel(geom, instanceName, instanceCount) {
306
+ const points = geom.points;
307
+ const normals = geom.normals;
308
+ const geometry = new THREE.BufferGeometry();
309
+
310
+ if (points && points.length) {
311
+ const position = new Float32Array(points);
312
+ geometry.setAttribute('position', new THREE.BufferAttribute(position, 3));
313
+ }
314
+
315
+ if (normals && normals.length) {
316
+ const normal = new Float32Array(normals);
317
+ geometry.setAttribute('normal', new THREE.BufferAttribute(normal, 3));
318
+ }
319
+
320
+ const { color, linewidth } = geom.prop;
321
+ const formatLinewidth = (linewidth < 1 ? linewidth * 50 : linewidth) || 5;
322
+ const material = new MeshLineMaterial({
323
+ color: new THREE.Color(`rgb(${color[0]}, ${color[1]}, ${color[2]})`),
324
+ lineWidth: formatLinewidth,
325
+ });
326
+
327
+ const lineGeometry = new MeshLineGeometry();
328
+ lineGeometry.setPoints(geometry);
329
+
330
+ const model = draw3Dmodel(
331
+ {
332
+ prop: geom.prop,
333
+ geometry: lineGeometry,
334
+ material,
335
+ },
336
+ instanceName,
337
+ instanceCount
338
+ );
339
+ // mesh.raycast = raycast;
340
+
341
+ model.userData.instanceName = instanceName;
342
+ // group.add(line);
343
+
344
+ return model;
345
+ }
346
+
347
+ // drawText 方法,用于渲染 2D 或 3D 文字
348
+ function drawText(geom, instanceName, instanceCount) {
349
+ const { prop, text, points, normals } = geom;
350
+ const { color, linewidth, fontsize, fontname, rotate, italic, widthscale } = prop;
351
+
352
+ var loader = new FontLoader();
353
+ var font = loader.parse(helvetikerFont);
354
+ var options = {
355
+ font: font, // 字体格式
356
+ size: fontsize || 20, // 字体大小 TODO
357
+ height: 1, // 字体深度
358
+ curveSegments: 11, // 曲线控制点数
359
+ bevelEnabled: true, // 斜角
360
+ bevelThickness: 0.1, // 斜角的深度
361
+ bevelSize: 1, // 斜角的大小
362
+ depth: 1,
363
+ bevelSegments: 1, // 斜角段数
364
+ };
365
+
366
+ var geometry = new TextGeometry(`${text}`, options);
367
+
368
+ const mesh = draw3Dmodel(
369
+ {
370
+ prop,
371
+ geometry,
372
+ normals,
373
+ },
374
+ instanceName,
375
+ instanceCount
376
+ );
377
+
378
+ // 创建平移矩阵并应用
379
+
380
+ const matrix = new THREE.Matrix4();
381
+ matrix.identity().makeTranslation(points[0], points[1], points[2]);
382
+ mesh.applyMatrix4(matrix);
383
+
384
+ // if (stageId == STAGE_MODEL_TYPE.PID) {
385
+ // mesh.translateX(-(fontsize / 2));
386
+ // mesh.translateY(-(fontsize / 2));
387
+ // }
388
+
389
+ // points && mesh.position.set(points[0], points[1], points[2]);
390
+ // if (rotate) {
391
+ // mesh.rotateY(rotate);
392
+ // }
393
+ // mesh.rotateX(-Math.PI / 2);
394
+ mesh.translateX(-(fontsize / 2.5));
395
+ mesh.translateY(-(fontsize / 2.5));
396
+
397
+ mesh.userData.instanceName = instanceName;
398
+
399
+ return mesh;
400
+ }
401
+
402
+ export { handleInstancedMeshModel };