fl-web-component 1.2.10 → 1.2.12
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/README.md +4 -0
- package/dist/fl-web-component.common.1.js +15 -15
- package/dist/fl-web-component.common.js +141 -38
- package/dist/fl-web-component.common.js.map +1 -1
- package/dist/fl-web-component.css +1 -1
- package/package.json +1 -1
- package/packages/components/com-flcanvas/index.vue +2 -2
- package/src/utils/flgltf-parser.js +1 -0
- package/src/utils/instance-parser.js +104 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
@charset "UTF-8";#fl-model[data-v-9d23b864],#konva-container[data-v-
|
|
1
|
+
@charset "UTF-8";#fl-model[data-v-9d23b864],#konva-container[data-v-4458f11e]{width:100%;height:100%;cursor:pointer}#konva-container[data-v-4458f11e]{z-index:3;overflow:hidden}span[data-v-f547d5c6]{font-weight:bolder}.text[data-v-f547d5c6]{margin-top:20px}.line[data-v-f547d5c6]{border-bottom:1px solid #dcdfe6;margin:20px 0}.center[data-v-f547d5c6]{display:flex;flex-direction:column;align-items:center}.center .cen span[data-v-f547d5c6],.center .top span[data-v-f547d5c6]{color:"#53a8ff";display:inline-block;width:30px;height:30px;text-align:center;line-height:30px;border:1px solid;padding:5px;margin-bottom:10px;background-color:#e9f3ff}.center .cen span[data-v-f547d5c6]{margin:10px}.button[data-v-f547d5c6]{display:flex;justify-content:end;margin-top:20px}@font-face{font-family:iconfont;src:url(//at.alicdn.com/t/font_3226805_qqvo3ag3r8.woff2?t=1646635700216) format("woff2"),url(//at.alicdn.com/t/font_3226805_qqvo3ag3r8.woff?t=1646635700216) format("woff"),url(//at.alicdn.com/t/font_3226805_qqvo3ag3r8.ttf?t=1646635700216) format("truetype")}.iconfont[data-v-f547d5c6]{font-family:iconfont!important;font-size:50px;font-style:normal;color:"#53a8ff";-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.icon-shubiao[data-v-f547d5c6]:before{content:""}#svg-tigger[data-v-0ec35ee4]{cursor:pointer;height:100%;width:100%}
|
package/package.json
CHANGED
|
@@ -253,7 +253,7 @@ var preTarget = [];
|
|
|
253
253
|
//缩放视口
|
|
254
254
|
let scale = 1;
|
|
255
255
|
const boundingRect = konvaLayer.getClientRect();
|
|
256
|
-
let ratio = Number((this.$refs.svgDraw
|
|
256
|
+
let ratio = Number((this.$refs.svgDraw?.clientWidth / boundingRect.width).toFixed(1));
|
|
257
257
|
if (ratio > 2) {
|
|
258
258
|
scale = Number((boundingRect.width / boundingRect.height).toFixed(1));
|
|
259
259
|
scale = scale < 2 ? 2 : scale;
|
|
@@ -265,7 +265,7 @@ var preTarget = [];
|
|
|
265
265
|
const boundingScale = konvaLayer.getClientRect();
|
|
266
266
|
//平移视口
|
|
267
267
|
const x =
|
|
268
|
-
this.$refs.svgDraw
|
|
268
|
+
this.$refs.svgDraw?.clientWidth / 2 -
|
|
269
269
|
(Math.ceil(boundingScale.width) / 2 + boundingScale.x / 2);
|
|
270
270
|
const y =
|
|
271
271
|
this.$refs.svgDraw.clientHeight / 2 -
|
|
@@ -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
|
-
|
|
122
|
+
// 处理文本居中对齐
|
|
123
|
+
const { points, alignType } = mesh;
|
|
104
124
|
if(isTextType(mesh.type)){
|
|
105
125
|
const positionMatrix = new THREE.Matrix4();
|
|
106
|
-
|
|
126
|
+
|
|
127
|
+
const alignMatrix = createAlignedText(alignType, model.geometry)
|
|
128
|
+
|
|
107
129
|
positionMatrix.identity().makeTranslation(points[0], points[1], points[2]);
|
|
108
|
-
|
|
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
|
-
|
|
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 };
|