fl-web-component 1.2.10 → 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.10",
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 类型模型的核心方法
@@ -100,13 +119,15 @@ function handleInstancedMeshModel(
100
119
  meshMatrix.elements = item.matrix.val;
101
120
  geomMatrix.elements = mesh.matrix.val;
102
121
 
103
- const { points } = mesh;
122
+ // 处理文本居中对齐
123
+ const { points, alignType } = mesh;
104
124
  if(isTextType(mesh.type)){
105
125
  const positionMatrix = new THREE.Matrix4();
106
- const alignMatrix = new THREE.Matrix4();
126
+
127
+ const alignMatrix = createAlignedText(alignType, model.geometry)
128
+
107
129
  positionMatrix.identity().makeTranslation(points[0], points[1], points[2]);
108
- alignMatrix.identity().makeTranslation(-(mesh.prop.fontsize / 2.5), -(mesh.prop.fontsize / 2.5), 0);
109
- geomMatrix.multiply(positionMatrix).multiply(alignMatrix);
130
+ geomMatrix.multiply(alignMatrix).multiply(positionMatrix);
110
131
  }
111
132
  m4.multiplyMatrices(meshMatrix, geomMatrix);
112
133
 
@@ -455,7 +476,7 @@ function drawText(geom, instanceName, instanceCount) {
455
476
  var font = loader.parse(helvetikerFont);
456
477
  var options = {
457
478
  font: font, // 字体格式
458
- size: fontsize || 20, // 字体大小 TODO
479
+ size: fontsize / 2 || 20, // 字体大小 TODO
459
480
  height: 1, // 字体深度
460
481
  curveSegments: 11, // 曲线控制点数
461
482
  bevelEnabled: true, // 斜角
@@ -465,7 +486,7 @@ function drawText(geom, instanceName, instanceCount) {
465
486
  bevelSegments: 1, // 斜角段数
466
487
  };
467
488
 
468
- var geometry = new TextGeometry(`${text}`, options);
489
+ let geometry = new TextGeometry(`${text}`, options);
469
490
 
470
491
  const mesh = draw3Dmodel(
471
492
  {
@@ -500,4 +521,81 @@ function drawText(geom, instanceName, instanceCount) {
500
521
  return mesh;
501
522
  }
502
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
+
503
601
  export { handleInstancedMeshModel };