fl-web-component 1.2.9 → 1.2.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fl-web-component",
3
- "version": "1.2.9",
3
+ "version": "1.2.11",
4
4
  "scripts": {
5
5
  "tip1": "仅调试本组件不涉及业务组件,请执行dev",
6
6
  "dev": "vue-cli-service serve",
@@ -122,6 +122,7 @@ function parseData(input) {
122
122
  type: primitiveData.geomType,
123
123
  text: primitiveData.geomText,
124
124
  points: primitiveData.position,
125
+ alignType: primitiveData.alignType,
125
126
  normals: primitiveData.normal,
126
127
  triangles: primitiveData.indices || [],
127
128
  max: primitiveData.max,
@@ -19,6 +19,25 @@ const GEOM_TYPES = {
19
19
  geom_2d_others: 57351,
20
20
  };
21
21
 
22
+ // 文本对齐枚举
23
+ const TextAlign = {
24
+ TextLeftBottom: 0, // 左下角
25
+ TextLeftMiddle: 1,
26
+ TextLeftTop: 2,
27
+ TextCenterBottom: 3,
28
+ TextCenterMiddle: 4,
29
+ TextCenterTop: 5,
30
+ TextRightBottom: 6,
31
+ TextRightMiddle: 7,
32
+ TextRightTop: 8, // 右上角
33
+ TextLeft: 9,
34
+ TextCenter: 10,
35
+ TextRight: 11,
36
+ TextAligned: 12,
37
+ TextMiddle: 13,
38
+ TextFit: 14
39
+ };
40
+
22
41
  let drawObjMapInstance = {};
23
42
  /**
24
43
  * 处理 InstancedMesh 类型模型的核心方法
@@ -99,7 +118,19 @@ function handleInstancedMeshModel(
99
118
  // m4.setPosition(new THREE.Vector3(9999999, 9999999, 9999999)); // TODO 临时隐藏方案
100
119
  meshMatrix.elements = item.matrix.val;
101
120
  geomMatrix.elements = mesh.matrix.val;
121
+
122
+ // 处理文本居中对齐
123
+ const { points, alignType } = mesh;
124
+ if(isTextType(mesh.type)){
125
+ const positionMatrix = new THREE.Matrix4();
126
+
127
+ const alignMatrix = createAlignedText(alignType, model.geometry)
128
+
129
+ positionMatrix.identity().makeTranslation(points[0], points[1], points[2]);
130
+ geomMatrix.multiply(alignMatrix).multiply(positionMatrix);
131
+ }
102
132
  m4.multiplyMatrices(meshMatrix, geomMatrix);
133
+
103
134
  model.setMatrixAt(index, m4);
104
135
  const copyMatrix = new THREE.Matrix4().copy(m4);
105
136
  model.userData.copyMatrix = copyMatrix;
@@ -186,12 +217,7 @@ function drawModel(geom, instanceName, instanceCount, nColor, nOpacity) {
186
217
  if (geom.type == GEOM_TYPES.geom_2d || geom.type == GEOM_TYPES.geom_2d_others) {
187
218
  model = draw2Dmodel(geom, instanceName, instanceCount); // TODO 该类型调试中
188
219
  // 处理二维文本类型
189
- } else if (
190
- geom.type == GEOM_TYPES.geom_2d_text ||
191
- geom.type == GEOM_TYPES.geom_2d_mtext ||
192
- geom.type == GEOM_TYPES.geom_3d_text ||
193
- geom.type == GEOM_TYPES.geom_3d_mtext
194
- ) {
220
+ } else if (isTextType(geom.type)) {
195
221
  model = drawText(geom, instanceName, instanceCount);
196
222
  // 处理各种曲线类型(圆形、圆弧、椭圆、椭圆弧)
197
223
  } else if (
@@ -208,6 +234,19 @@ function drawModel(geom, instanceName, instanceCount, nColor, nOpacity) {
208
234
  return model;
209
235
  }
210
236
 
237
+ /**
238
+ * 判断几何类型是否为文本类型
239
+ * @param {number} type - 几何类型枚举值,参考GEOM_TYPES中的定义
240
+ * @returns {boolean} 是否为文本类型(2D/3D 单行或多行文本)
241
+ */
242
+ function isTextType(type){
243
+ return type == GEOM_TYPES.geom_2d_text ||
244
+ type == GEOM_TYPES.geom_2d_mtext ||
245
+ type == GEOM_TYPES.geom_3d_text ||
246
+ type == GEOM_TYPES.geom_3d_mtext
247
+ }
248
+
249
+
211
250
  /**
212
251
  * 绘制曲线
213
252
  *
@@ -275,7 +314,7 @@ function drawCurves(geom, instanceName, instanceCount) {
275
314
  */
276
315
  function draw3Dmodel(geom, instanceName, instanceCount, nColor, nOpacity) {
277
316
  // 解构几何数据中的自定义几何体和材质
278
- const { geometry: customGeometry, material: customMaterial, triangles, points, normals } = geom;
317
+ const { geometry: customGeometry, material: customMaterial, triangles, points, normals, prop } = geom;
279
318
  // 使用自定义几何体或创建新的缓冲几何体
280
319
  const geometry = customGeometry || new THREE.BufferGeometry();
281
320
 
@@ -295,7 +334,7 @@ function draw3Dmodel(geom, instanceName, instanceCount, nColor, nOpacity) {
295
334
  const normal = new Float32Array(normals);
296
335
  geometry.setAttribute('normal', new THREE.BufferAttribute(normal, 3));
297
336
  }
298
- const { color } = geom.prop;
337
+ const { color } = prop;
299
338
  let material, mesh, colors, opacity;
300
339
  if (Array.isArray(color) && color.length) {
301
340
  colors = color;
@@ -437,7 +476,7 @@ function drawText(geom, instanceName, instanceCount) {
437
476
  var font = loader.parse(helvetikerFont);
438
477
  var options = {
439
478
  font: font, // 字体格式
440
- size: fontsize || 20, // 字体大小 TODO
479
+ size: fontsize / 2 || 20, // 字体大小 TODO
441
480
  height: 1, // 字体深度
442
481
  curveSegments: 11, // 曲线控制点数
443
482
  bevelEnabled: true, // 斜角
@@ -447,7 +486,7 @@ function drawText(geom, instanceName, instanceCount) {
447
486
  bevelSegments: 1, // 斜角段数
448
487
  };
449
488
 
450
- var geometry = new TextGeometry(`${text}`, options);
489
+ let geometry = new TextGeometry(`${text}`, options);
451
490
 
452
491
  const mesh = draw3Dmodel(
453
492
  {
@@ -460,10 +499,10 @@ function drawText(geom, instanceName, instanceCount) {
460
499
  );
461
500
 
462
501
  // 创建平移矩阵并应用
463
-
464
- const matrix = new THREE.Matrix4();
465
- matrix.identity().makeTranslation(points[0], points[1], points[2]);
466
- mesh.applyMatrix4(matrix);
502
+ // const matrix = new THREE.Matrix4();
503
+ // matrix.identity().makeTranslation(points[0], points[1], points[2]);
504
+ // mesh.applyMatrix4(matrix);
505
+ // points && mesh.position.set(points[0], points[1], points[2]);
467
506
 
468
507
  // if (stageId == STAGE_MODEL_TYPE.PID) {
469
508
  // mesh.translateX(-(fontsize / 2));
@@ -475,11 +514,88 @@ function drawText(geom, instanceName, instanceCount) {
475
514
  // mesh.rotateY(rotate);
476
515
  // }
477
516
  // mesh.rotateX(-Math.PI / 2);
478
- mesh.translateX(-(fontsize / 2.5));
479
- mesh.translateY(-(fontsize / 2.5));
517
+ // mesh.translateX(-(fontsize / 2.5));
518
+ // mesh.translateY(-(fontsize / 2.5));
480
519
 
481
520
  mesh.userData.instanceName = instanceName;
482
521
  return mesh;
483
522
  }
484
523
 
524
+ /**
525
+ *
526
+ * @param {number} align 对齐方式
527
+ * @param {object} geometry 几何体
528
+ * @returns
529
+ */
530
+ function createAlignedText(align = TextAlign.TextLeftBottom, geometry) {
531
+ // 计算几何体包围盒用于对齐计算
532
+ geometry.computeBoundingBox();
533
+ const bbox = geometry.boundingBox;
534
+
535
+ // 初始化水平和垂直偏移量
536
+ let offsetX = 0;
537
+ let offsetY = 0;
538
+
539
+ // 水平对齐处理(X轴方向)
540
+ switch(align) {
541
+ // 左对齐系列(文本左边界对齐原点)
542
+ case TextAlign.TextLeft:
543
+ case TextAlign.TextLeftBottom:
544
+ case TextAlign.TextLeftMiddle:
545
+ case TextAlign.TextLeftTop:
546
+ offsetX = -bbox.min.x; // 左边界对齐
547
+ break;
548
+
549
+ // 居中对齐系列(文本中心对齐原点)
550
+ case TextAlign.TextCenter:
551
+ case TextAlign.TextCenterBottom:
552
+ case TextAlign.TextCenterMiddle:
553
+ case TextAlign.TextCenterTop:
554
+ offsetX = -(bbox.min.x + bbox.max.x) / 2; // 水平居中
555
+ break;
556
+
557
+ // 右对齐系列(文本右边界对齐原点)
558
+ case TextAlign.TextRight:
559
+ case TextAlign.TextRightBottom:
560
+ case TextAlign.TextRightMiddle:
561
+ case TextAlign.TextRightTop:
562
+ offsetX = -bbox.max.x; // 右边界对齐
563
+ break;
564
+ }
565
+
566
+ // 垂直对齐处理(Y轴方向)
567
+ switch(align) {
568
+ // 垂直居中系列
569
+ case TextAlign.TextMiddle:
570
+ case TextAlign.TextLeftMiddle:
571
+ case TextAlign.TextCenterMiddle:
572
+ case TextAlign.TextRightMiddle:
573
+ offsetY = -(bbox.min.y + bbox.max.y) / 2; // 垂直居中
574
+ break;
575
+
576
+ // 顶部对齐系列
577
+ case TextAlign.TextTop:
578
+ case TextAlign.TextLeftTop:
579
+ case TextAlign.TextCenterTop:
580
+ case TextAlign.TextRightTop:
581
+ offsetY = -bbox.max.y; // 顶部对齐
582
+ break;
583
+
584
+ // 底部对齐系列
585
+ case TextAlign.TextBottom:
586
+ case TextAlign.TextLeftBottom:
587
+ case TextAlign.TextCenterBottom:
588
+ case TextAlign.TextRightBottom:
589
+ offsetY = -bbox.min.y; // 底部对齐
590
+ break;
591
+ }
592
+
593
+ // 创建对齐变换矩阵
594
+ const alignMatrix = new THREE.Matrix4();
595
+ alignMatrix.identity().makeTranslation(offsetX, offsetY, 0)
596
+
597
+ return alignMatrix;
598
+ }
599
+
600
+
485
601
  export { handleInstancedMeshModel };
Binary file
Binary file