fl-web-component 1.3.15 → 1.3.17
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 +5 -1
- package/dist/fl-web-component.common.js +697 -151
- 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/components/entityFormatting.js +379 -100
- package/packages/components/com-flcanvas/index.vue +13 -5
- package/packages/components/com-graphics/index.vue +17 -1
- package/src/utils/flgltf-parser.js +4 -2
- package/src/utils/instance-parser.js +76 -67
|
@@ -129,11 +129,17 @@
|
|
|
129
129
|
//销毁方法
|
|
130
130
|
|
|
131
131
|
methods: {
|
|
132
|
+
//思路是计算居中包围盒,然后排除脏数据。
|
|
132
133
|
loadDxf(data){
|
|
133
134
|
|
|
135
|
+
/* if(this.layer!=null){
|
|
136
|
+
let nodes=this.layer.find(".item");
|
|
137
|
+
for(let i=0;i<nodes.length;i++){
|
|
138
|
+
nodes[i].destroy();
|
|
139
|
+
}
|
|
140
|
+
}*/
|
|
134
141
|
|
|
135
|
-
|
|
136
|
-
|
|
142
|
+
konvaLayer.destroyChildren();
|
|
137
143
|
const parser = new DxfParser();
|
|
138
144
|
let dxf = parser.parse(data);
|
|
139
145
|
let entities = formatEntity(dxf.entities);
|
|
@@ -160,6 +166,7 @@
|
|
|
160
166
|
for(let i = 0; i < group.length;i++) {
|
|
161
167
|
let entity = group[i];
|
|
162
168
|
if (entity.type === 'text') {
|
|
169
|
+
|
|
163
170
|
if (konvaLayer) konvaLayer.add(entity.obj);
|
|
164
171
|
}
|
|
165
172
|
}
|
|
@@ -282,13 +289,14 @@
|
|
|
282
289
|
// get data URL with default settings
|
|
283
290
|
|
|
284
291
|
// open in new window
|
|
285
|
-
konvaLayer.getCanvas().setPixelRatio(
|
|
292
|
+
konvaLayer.getCanvas().setPixelRatio(2);
|
|
286
293
|
const jpegURL = konvaStage.toDataURL({
|
|
287
294
|
mimeType: 'image/jpeg',
|
|
288
|
-
quality:1
|
|
295
|
+
quality:1,
|
|
296
|
+
pixelRatio:2
|
|
289
297
|
});
|
|
290
298
|
|
|
291
|
-
let pageData=konvaLayer.canvas.toDataURL('image/jpeg',
|
|
299
|
+
let pageData=konvaLayer.canvas.toDataURL('image/jpeg', 2);
|
|
292
300
|
|
|
293
301
|
|
|
294
302
|
let img = new Image();
|
|
@@ -220,7 +220,7 @@
|
|
|
220
220
|
color: '' 初始化模型的颜色 在业务方 有这个需求
|
|
221
221
|
meshNameConfig: {}
|
|
222
222
|
*/
|
|
223
|
-
drawModel(data, color = '', meshNameConfig = {}) {
|
|
223
|
+
drawModel(data, color = '', meshNameConfig = {}, options = {}) {
|
|
224
224
|
if (Object.keys(data).length === 0) {
|
|
225
225
|
return;
|
|
226
226
|
}
|
|
@@ -282,6 +282,9 @@
|
|
|
282
282
|
this.$emit('modelLoaded');
|
|
283
283
|
// cameraControls.saveState();
|
|
284
284
|
}
|
|
285
|
+
|
|
286
|
+
// 动态设置视角滚轮的距离
|
|
287
|
+
this.setCameraConfig();
|
|
285
288
|
},
|
|
286
289
|
// 获取mesh的中心点
|
|
287
290
|
getMeshCenterAndVolume(mesh) {
|
|
@@ -1563,6 +1566,19 @@
|
|
|
1563
1566
|
left && (cameraControls.mouseButtons.left = ACTION_ENUM[left]);
|
|
1564
1567
|
right && (cameraControls.mouseButtons.right = ACTION_ENUM[right]);
|
|
1565
1568
|
},
|
|
1569
|
+
// 动态设置视角滚轮的距离
|
|
1570
|
+
setCameraConfig() {
|
|
1571
|
+
let box3 = new this.THREE.Box3().setFromObject(scene);
|
|
1572
|
+
let size = new this.THREE.Vector3();
|
|
1573
|
+
box3.getSize(size);
|
|
1574
|
+
const maxBorder = Math.max(size.x, size.y, size.z);
|
|
1575
|
+
|
|
1576
|
+
cameraControls.camera.far = maxBorder * 50; // 设置相机的远裁剪面
|
|
1577
|
+
|
|
1578
|
+
cameraControls.minDistance = maxBorder * 0.05; // 动态设置视角滚轮的距离
|
|
1579
|
+
|
|
1580
|
+
camera.updateProjectionMatrix();
|
|
1581
|
+
},
|
|
1566
1582
|
},
|
|
1567
1583
|
};
|
|
1568
1584
|
</script>
|
|
@@ -69,7 +69,8 @@ function parseData(input) {
|
|
|
69
69
|
italic: material?.italic,
|
|
70
70
|
linepacing: 1, // 默认值
|
|
71
71
|
linewidth: material?.linewidth !== undefined ? material?.linewidth : 1, // 默认值
|
|
72
|
-
visible: material?.visible === false ? false : true
|
|
72
|
+
visible: material?.visible === false ? false : true,
|
|
73
|
+
transparent: material?.transp,
|
|
73
74
|
};
|
|
74
75
|
|
|
75
76
|
const identity = new THREE.Matrix4().identity();
|
|
@@ -161,7 +162,8 @@ function parseNode(node) {
|
|
|
161
162
|
}
|
|
162
163
|
});
|
|
163
164
|
if (isRoot) {
|
|
164
|
-
|
|
165
|
+
// 根节点父ID应为空字符串
|
|
166
|
+
const processed = processInstance(instance, '', instanceMap);
|
|
165
167
|
rootInstances.push(processed);
|
|
166
168
|
}
|
|
167
169
|
});
|
|
@@ -65,14 +65,16 @@ function handleInstancedMeshModel(
|
|
|
65
65
|
let targetGroup, instancedMeshIndex, drawObjectName;
|
|
66
66
|
const drawObjInstance = drawObjMapInstance[instances[i].drawObject];
|
|
67
67
|
if (drawObjInstance.MapMesh?.length > 0) {
|
|
68
|
+
// 确保始终使用当前实例的 drawObject 设置分组名
|
|
69
|
+
drawObjectName = instances[i].drawObject;
|
|
68
70
|
drawObjInstance.MapInstance.forEach((instance, index) => {
|
|
69
71
|
if (instance.instanceId == instances[i].instanceId) {
|
|
70
72
|
instancedMeshIndex = index;
|
|
71
|
-
drawObjectName = instances[i].drawObject;
|
|
72
73
|
}
|
|
73
74
|
});
|
|
75
|
+
// 在 modelGroup 中查找,避免因尚未加入 scene 而重复创建
|
|
74
76
|
if (drawObjectName) {
|
|
75
|
-
targetGroup =
|
|
77
|
+
targetGroup = modelGroup.getObjectByName(drawObjectName);
|
|
76
78
|
}
|
|
77
79
|
if (!targetGroup) {
|
|
78
80
|
const drawObj = drawObjMapInstance[instances[i].drawObject];
|
|
@@ -104,46 +106,48 @@ function handleInstancedMeshModel(
|
|
|
104
106
|
model.userData[key] = meshNameConfig[key];
|
|
105
107
|
meshName += ':' + meshNameConfig[key];
|
|
106
108
|
}
|
|
109
|
+
// 一次性为该 drawObject 的所有实例设置矩阵与颜色
|
|
107
110
|
drawObj.MapInstance.forEach((item, index) => {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
geomMatrix.multiply(alignMatrix).multiply(positionMatrix);
|
|
132
|
-
}
|
|
133
|
-
m4.multiplyMatrices(meshMatrix, geomMatrix);
|
|
134
|
-
|
|
135
|
-
model.setMatrixAt(index, m4);
|
|
136
|
-
const copyMatrix = new THREE.Matrix4().copy(m4);
|
|
137
|
-
model.userData.copyMatrix = copyMatrix;
|
|
111
|
+
model.userData.instanceIndex = index;
|
|
112
|
+
model.userData.instanceId = item.instanceId;
|
|
113
|
+
model.userData.primId = mesh.prmid;
|
|
114
|
+
model.name = meshName !== '' ? item.instanceId + meshName : item.instanceId;
|
|
115
|
+
|
|
116
|
+
const matrixVal = item.matrix?.val;
|
|
117
|
+
if (matrixVal) {
|
|
118
|
+
const m4 = new THREE.Matrix4();
|
|
119
|
+
const meshMatrix = new THREE.Matrix4();
|
|
120
|
+
const geomMatrix = new THREE.Matrix4();
|
|
121
|
+
// m4.setPosition(new THREE.Vector3(9999999, 9999999, 9999999)); // TODO 临时隐藏方案
|
|
122
|
+
meshMatrix.elements = item.matrix.val;
|
|
123
|
+
geomMatrix.elements = mesh.matrix.val;
|
|
124
|
+
|
|
125
|
+
// 处理文本居中对齐
|
|
126
|
+
const { points, alignType } = mesh;
|
|
127
|
+
if (isTextType(mesh.type)) {
|
|
128
|
+
const positionMatrix = new THREE.Matrix4();
|
|
129
|
+
|
|
130
|
+
const alignMatrix = createAlignedText(alignType, model.geometry);
|
|
131
|
+
|
|
132
|
+
positionMatrix.identity().makeTranslation(points[0], points[1], points[2]);
|
|
133
|
+
geomMatrix.multiply(alignMatrix).multiply(positionMatrix);
|
|
138
134
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
model.setColorAt(index, meshColor);
|
|
135
|
+
m4.multiplyMatrices(meshMatrix, geomMatrix);
|
|
136
|
+
|
|
137
|
+
model.setMatrixAt(index, m4);
|
|
138
|
+
const copyMatrix = new THREE.Matrix4().copy(m4);
|
|
139
|
+
model.userData.copyMatrix = copyMatrix;
|
|
145
140
|
}
|
|
141
|
+
// 需要先设置全部实例颜色,否则后续设置颜色无效
|
|
142
|
+
const { color } = mesh.prop;
|
|
143
|
+
const meshColor = customColor
|
|
144
|
+
? new THREE.Color(customColor)
|
|
145
|
+
: new THREE.Color(`rgb(${color[0]}, ${color[1]}, ${color[2]})`);
|
|
146
|
+
model.setColorAt(index, meshColor);
|
|
146
147
|
});
|
|
148
|
+
// 标记实例属性更新
|
|
149
|
+
if (model.instanceMatrix) model.instanceMatrix.needsUpdate = true;
|
|
150
|
+
if (model.instanceColor) model.instanceColor.needsUpdate = true;
|
|
147
151
|
// model.instanceColor.needsUpdate = true;
|
|
148
152
|
group.add(model);
|
|
149
153
|
});
|
|
@@ -343,7 +347,7 @@ function draw3Dmodel(geom, instanceName, instanceCount, nColor, nOpacity) {
|
|
|
343
347
|
const normal = new Float32Array(normals);
|
|
344
348
|
geometry.setAttribute('normal', new THREE.BufferAttribute(normal, 3));
|
|
345
349
|
}
|
|
346
|
-
const { color } = prop;
|
|
350
|
+
const { color, transparent } = prop;
|
|
347
351
|
let material, mesh, colors, opacity;
|
|
348
352
|
if (Array.isArray(color) && color.length) {
|
|
349
353
|
colors = color;
|
|
@@ -356,6 +360,11 @@ function draw3Dmodel(geom, instanceName, instanceCount, nColor, nOpacity) {
|
|
|
356
360
|
opacity = 1;
|
|
357
361
|
}
|
|
358
362
|
|
|
363
|
+
// 处理transparent透明度
|
|
364
|
+
if (transparent) {
|
|
365
|
+
opacity = 1 - transparent;
|
|
366
|
+
}
|
|
367
|
+
|
|
359
368
|
// 使用自定义材质或创建标准材质(默认参数配置)
|
|
360
369
|
let materialOptions = {
|
|
361
370
|
userData: {
|
|
@@ -392,34 +401,34 @@ function draw3Dmodel(geom, instanceName, instanceCount, nColor, nOpacity) {
|
|
|
392
401
|
geometry.setAttribute('opacity', new THREE.InstancedBufferAttribute(opacities, 1));
|
|
393
402
|
|
|
394
403
|
// 自定义着色器逻辑
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
404
|
+
if (!customMaterial) {
|
|
405
|
+
material.onBeforeCompile = shader => {
|
|
406
|
+
// 添加顶点着色器输入
|
|
407
|
+
shader.vertexShader = `
|
|
408
|
+
in float opacity; // 实例透明度属性
|
|
409
|
+
out float vAlpha;
|
|
410
|
+
${shader.vertexShader}
|
|
411
|
+
`.replace(
|
|
412
|
+
'#include <begin_vertex>',
|
|
413
|
+
`
|
|
414
|
+
#include <begin_vertex>
|
|
415
|
+
vAlpha = opacity; // 传递透明度到片段着色器
|
|
416
|
+
`
|
|
417
|
+
);
|
|
418
|
+
|
|
419
|
+
// 修改片段着色器
|
|
420
|
+
shader.fragmentShader = `
|
|
421
|
+
in float vAlpha;
|
|
422
|
+
${shader.fragmentShader}
|
|
423
|
+
`.replace(
|
|
424
|
+
'#include <alphatest_fragment>',
|
|
425
|
+
`
|
|
426
|
+
#include <alphatest_fragment>
|
|
427
|
+
diffuseColor.a *= vAlpha; // 应用实例透明度
|
|
428
|
+
`
|
|
429
|
+
);
|
|
430
|
+
};
|
|
431
|
+
}
|
|
423
432
|
mesh = new THREE.InstancedMesh(geometry, material, instanceCount);
|
|
424
433
|
|
|
425
434
|
const { visible } = prop;
|