fl-web-component 1.2.1 → 1.2.3
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 +6 -0
- package/dist/fl-web-component.common.1.js +15 -15
- package/dist/fl-web-component.common.js +137 -129
- package/dist/fl-web-component.css +1 -1
- package/package.json +2 -2
- package/packages/components/com-flcanvas/components/entityFormatting.js +4 -0
- package/packages/components/com-flcanvas/index.vue +12 -5
- package/packages/components/com-graphics/index.vue +26 -57
- package/packages/components/com-graphics/pid.vue +0 -1
- package/src/utils/flgltf-parser.js +7 -5
- package/src/utils/instance-parser.js +18 -12
- package/src/utils/mock.js +0 -284913
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fl-web-component",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"tip1": "仅调试本组件不涉及业务组件,请执行dev",
|
|
6
6
|
"dev": "vue-cli-service serve",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"build": "npm run lint && vue-cli-service build --target lib --name fl-web-component --formats commonjs ./src/main.js",
|
|
12
12
|
"build:test": "vue-cli-service build --target lib --name fl-web-component --formats commonjs ./src/main.js",
|
|
13
13
|
"publish:base": "npm run build && npm publish",
|
|
14
|
-
"tip3": "发版注意:
|
|
14
|
+
"tip3": "发版注意: 【修改bug执行publish:fix】【新增功能执行publish:feat】【新特性执行publish:perf】",
|
|
15
15
|
"publish:fix": "npm version patch && npm run publish:base",
|
|
16
16
|
"publish:feat": "npm version minor && npm run publish:base",
|
|
17
17
|
"publish:perf": "npm version major && npm run publish:base"
|
|
@@ -67,6 +67,8 @@ export function centering(obj, container, konvaStage, scaleBy) {
|
|
|
67
67
|
} else if (target[0].className === "Line") {
|
|
68
68
|
const p = getAbsolutePoints(target[0].getPoints());
|
|
69
69
|
computedCenter(p.x, p.y, container, konvaStage, scaleBy)
|
|
70
|
+
} else {
|
|
71
|
+
computedCenter(target[0].px, target[0].py, container, konvaStage, scaleBy)
|
|
70
72
|
}
|
|
71
73
|
}
|
|
72
74
|
} else {
|
|
@@ -76,6 +78,8 @@ export function centering(obj, container, konvaStage, scaleBy) {
|
|
|
76
78
|
} else if (target[0].className === "Line") {
|
|
77
79
|
const p = getAbsolutePoints(target[0].getPoints());
|
|
78
80
|
computedCenter(p.x, p.y, container, konvaStage, scaleBy)
|
|
81
|
+
} else {
|
|
82
|
+
computedCenter(target[0].px, target[0].py, container, konvaStage, scaleBy)
|
|
79
83
|
}
|
|
80
84
|
}
|
|
81
85
|
}
|
|
@@ -51,7 +51,6 @@ var preTarget = [];
|
|
|
51
51
|
mounted() {
|
|
52
52
|
//resize方法
|
|
53
53
|
window.addEventListener('resize', () => {
|
|
54
|
-
console.log('resize');
|
|
55
54
|
if (konvaStage) {
|
|
56
55
|
const obj = document.getElementById('konva-container');
|
|
57
56
|
konvaStage.setWidth(obj.clientWidth);
|
|
@@ -61,8 +60,6 @@ var preTarget = [];
|
|
|
61
60
|
});
|
|
62
61
|
|
|
63
62
|
this.$nextTick(() => {
|
|
64
|
-
console.log(document.getElementById('konva-container'));
|
|
65
|
-
console.log(this.$refs.svgDraw);
|
|
66
63
|
konvaStage = new Konva.Stage({
|
|
67
64
|
className: 'stage',
|
|
68
65
|
container: 'konva-container',
|
|
@@ -121,7 +118,6 @@ var preTarget = [];
|
|
|
121
118
|
e.target.attrs.className === "stage"
|
|
122
119
|
) {
|
|
123
120
|
let obj = this.getIntersects(inspectionRect.getClientRect());
|
|
124
|
-
console.log(obj);
|
|
125
121
|
clickObj = obj.length > 0 ? obj[obj.length - 1] : null;
|
|
126
122
|
} else {
|
|
127
123
|
clickObj = e.target.attrs;
|
|
@@ -216,6 +212,8 @@ var preTarget = [];
|
|
|
216
212
|
context.moveTo(x1, -parseFloat(y1));
|
|
217
213
|
context.lineTo(x2, -parseFloat(y2));
|
|
218
214
|
}
|
|
215
|
+
shape.px = entity.x1
|
|
216
|
+
shape.py = -entity.y1
|
|
219
217
|
}
|
|
220
218
|
if (entity.type === 'polyline') {
|
|
221
219
|
let flag = false;
|
|
@@ -241,6 +239,8 @@ var preTarget = [];
|
|
|
241
239
|
}
|
|
242
240
|
}
|
|
243
241
|
}
|
|
242
|
+
shape.px = points[0]
|
|
243
|
+
shape.py = points[1]
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
246
|
// context.closePath();
|
|
@@ -277,7 +277,9 @@ var preTarget = [];
|
|
|
277
277
|
// });
|
|
278
278
|
konvaStage.setX(x);
|
|
279
279
|
konvaStage.setY(y); // 750
|
|
280
|
-
|
|
280
|
+
setTimeout(() => {
|
|
281
|
+
this.$emit('loaded')
|
|
282
|
+
}, 100)
|
|
281
283
|
},
|
|
282
284
|
toPdf(name) {
|
|
283
285
|
// get data URL with default settings
|
|
@@ -385,6 +387,11 @@ var preTarget = [];
|
|
|
385
387
|
obj = null;
|
|
386
388
|
}
|
|
387
389
|
},
|
|
390
|
+
resize(width, height) {
|
|
391
|
+
konvaStage.setWidth(width);
|
|
392
|
+
konvaStage.setHeight(height);
|
|
393
|
+
konvaStage._resizeDOM();
|
|
394
|
+
},
|
|
388
395
|
beforeDestroy() {
|
|
389
396
|
this.clearCache();
|
|
390
397
|
},
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
outlineComposer,
|
|
27
27
|
renderTarget,
|
|
28
28
|
sceneClock,
|
|
29
|
+
mat4
|
|
29
30
|
] = (function* (v) {
|
|
30
31
|
while (true) yield v;
|
|
31
32
|
})(null);
|
|
@@ -100,6 +101,8 @@
|
|
|
100
101
|
},
|
|
101
102
|
created() {
|
|
102
103
|
CameraControls.install({ THREE: this.THREE });
|
|
104
|
+
mat4 = new this.THREE.Matrix4();
|
|
105
|
+
mat4.makeRotationX(-Math.PI / 2);
|
|
103
106
|
fpsClock = new this.THREE.Clock();
|
|
104
107
|
raycaster = new this.THREE.Raycaster();
|
|
105
108
|
sceneClock = new this.THREE.Clock();
|
|
@@ -173,7 +176,7 @@
|
|
|
173
176
|
45,
|
|
174
177
|
window.innerWidth / window.innerHeight,
|
|
175
178
|
0.1,
|
|
176
|
-
|
|
179
|
+
1000000000
|
|
177
180
|
);
|
|
178
181
|
camera.position.set(0, 100, 150);
|
|
179
182
|
},
|
|
@@ -228,9 +231,8 @@
|
|
|
228
231
|
.multiplyScalar(0.5);
|
|
229
232
|
scene.add(modelGroup);
|
|
230
233
|
// 适配客户端的坐标系,threejs坐标需绕x轴旋转90度
|
|
231
|
-
const mat4 = new this.THREE.Matrix4();
|
|
232
|
-
mat4.makeRotationX(-Math.PI / 2);
|
|
233
234
|
modelGroup.applyMatrix4(mat4);
|
|
235
|
+
modelGroup.updateMatrixWorld();
|
|
234
236
|
modelGroup.traverse(child => {
|
|
235
237
|
if (child.isMesh) {
|
|
236
238
|
const json = this.getMeshCenterAndVolume(child);
|
|
@@ -264,9 +266,9 @@
|
|
|
264
266
|
child.userData.modelWorldPs = modelWorldPs;
|
|
265
267
|
}
|
|
266
268
|
});
|
|
267
|
-
// this.compileShader();
|
|
268
269
|
// cameraControls.fitToSphere(scene, true); // TODO 待处理,先用 setModelCenter 进行定位
|
|
269
270
|
this.setModelCenter(modelGroup);
|
|
271
|
+
this.$emit('modelLoaded')
|
|
270
272
|
// cameraControls.saveState();
|
|
271
273
|
}
|
|
272
274
|
},
|
|
@@ -282,44 +284,6 @@
|
|
|
282
284
|
box: volume,
|
|
283
285
|
};
|
|
284
286
|
},
|
|
285
|
-
compileShader() {
|
|
286
|
-
scene.traverse(child => {
|
|
287
|
-
if (child.isMesh) {
|
|
288
|
-
child.material.onBeforeCompile = shader => {
|
|
289
|
-
const vertexShader = `
|
|
290
|
-
precision lowp float;
|
|
291
|
-
attribute float visible;
|
|
292
|
-
varying float vVisible;
|
|
293
|
-
void main() {
|
|
294
|
-
vVisible = visible;
|
|
295
|
-
`;
|
|
296
|
-
const fragmentShader = `
|
|
297
|
-
precision lowp float;
|
|
298
|
-
varying float vVisible;
|
|
299
|
-
void main() {
|
|
300
|
-
`;
|
|
301
|
-
const fragColor = `
|
|
302
|
-
#include <dithering_fragment>
|
|
303
|
-
if (vVisible > 0.0) {
|
|
304
|
-
gl_FragColor = vec4(outgoingLight, diffuseColor.a);
|
|
305
|
-
} else {
|
|
306
|
-
discard;
|
|
307
|
-
}
|
|
308
|
-
`;
|
|
309
|
-
shader.vertexShader = shader.vertexShader.replace('void main() {', vertexShader);
|
|
310
|
-
shader.fragmentShader = shader.fragmentShader.replace(
|
|
311
|
-
'void main() {',
|
|
312
|
-
fragmentShader
|
|
313
|
-
);
|
|
314
|
-
shader.fragmentShader = shader.fragmentShader.replace(
|
|
315
|
-
'#include <dithering_fragment>',
|
|
316
|
-
fragColor
|
|
317
|
-
);
|
|
318
|
-
child.material.transparent = true;
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
});
|
|
322
|
-
},
|
|
323
287
|
mouseDown() {
|
|
324
288
|
firstTime = new Date().getTime();
|
|
325
289
|
},
|
|
@@ -557,7 +521,9 @@
|
|
|
557
521
|
if (obj.isGroup) {
|
|
558
522
|
this.setModelCenter(obj);
|
|
559
523
|
} else if (obj.isMesh) {
|
|
560
|
-
this.
|
|
524
|
+
let center = this.getCenter(obj);
|
|
525
|
+
let size = this.getSize(obj);
|
|
526
|
+
this.locateByCenterBox(center, size)
|
|
561
527
|
}
|
|
562
528
|
}
|
|
563
529
|
},
|
|
@@ -622,9 +588,17 @@
|
|
|
622
588
|
center: {x: 0, y: 0, z: 0},
|
|
623
589
|
box: {x: 0, y: 0, z: 0}
|
|
624
590
|
*/
|
|
625
|
-
locateByCenterBox(center,
|
|
626
|
-
let
|
|
627
|
-
|
|
591
|
+
locateByCenterBox(center, size) {
|
|
592
|
+
let maxDim = Math.max(size.x, size.y, size.z);
|
|
593
|
+
let fov = camera.fov * (Math.PI / 180);
|
|
594
|
+
let distance = Math.min(
|
|
595
|
+
maxDim * 100, // 最大距离限制
|
|
596
|
+
Math.abs((maxDim * 1.0) / Math.sin(fov / 2))
|
|
597
|
+
);
|
|
598
|
+
let direction = new this.THREE.Vector3(1, 1, 1).normalize();
|
|
599
|
+
let p = (new this.THREE.Vector3().copy(center)).add(direction.multiplyScalar(distance));
|
|
600
|
+
let cameraCenter = new this.THREE.Vector3(p.x, p.y, p.z).addScalar(
|
|
601
|
+
Math.max(size.x, size.y, size.z)
|
|
628
602
|
);
|
|
629
603
|
cameraControls.setLookAt(
|
|
630
604
|
cameraCenter.x,
|
|
@@ -649,10 +623,6 @@
|
|
|
649
623
|
const divLabel = new CSS2DObject(data.billboard);
|
|
650
624
|
divLabel.name = data.labelClass; // 这个是用来清除广告牌用的
|
|
651
625
|
divLabel.position.set(data.x, data.y, data.z);
|
|
652
|
-
// 由于场景做了翻转 所以要把它翻转回来
|
|
653
|
-
// const mat4 = new this.THREE.Matrix4();
|
|
654
|
-
// mat4.makeRotationX(Math.PI / 2);
|
|
655
|
-
// divLabel.applyMatrix4(mat4);
|
|
656
626
|
scene.add(divLabel);
|
|
657
627
|
return divLabel;
|
|
658
628
|
},
|
|
@@ -1458,20 +1428,19 @@
|
|
|
1458
1428
|
},
|
|
1459
1429
|
// 获取中心点
|
|
1460
1430
|
getCenter(obj) {
|
|
1461
|
-
console.log(obj)
|
|
1462
1431
|
let center = new this.THREE.Vector3();
|
|
1463
1432
|
obj.boundingBox.getCenter(center);
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1433
|
+
if (obj.userData.is3D) {
|
|
1434
|
+
center.applyMatrix4(mat4)
|
|
1435
|
+
}
|
|
1467
1436
|
return center;
|
|
1468
1437
|
},
|
|
1469
1438
|
getSize(obj) {
|
|
1470
1439
|
let size = new this.THREE.Vector3();
|
|
1471
1440
|
obj.boundingBox.getSize(size);
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1441
|
+
if (obj.userData.is3D) {
|
|
1442
|
+
size.applyMatrix4(mat4)
|
|
1443
|
+
}
|
|
1475
1444
|
return size;
|
|
1476
1445
|
},
|
|
1477
1446
|
animate() {
|
|
@@ -111,7 +111,6 @@
|
|
|
111
111
|
参数:svgIds: [], 需要高亮的id的集合, flag: true / false, 是否要定位目标元素, color: '', 高亮的颜色
|
|
112
112
|
*/
|
|
113
113
|
highLight(svgIds, flag = false, color) {
|
|
114
|
-
console.log(svgIds)
|
|
115
114
|
if (svgIds === null || svgIds === undefined) {
|
|
116
115
|
throw new Error('svgIds should be an array');
|
|
117
116
|
} else {
|
|
@@ -29,7 +29,7 @@ function parseData(input) {
|
|
|
29
29
|
function flattenAndComputeWorldMatrices(
|
|
30
30
|
nodes,
|
|
31
31
|
result = [],
|
|
32
|
-
parentWorldMatrix = null,
|
|
32
|
+
// parentWorldMatrix = null,
|
|
33
33
|
fatherId = ''
|
|
34
34
|
) {
|
|
35
35
|
for (const node of nodes) {
|
|
@@ -44,9 +44,10 @@ function parseData(input) {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
// 计算世界矩阵
|
|
47
|
-
const worldMatrix = parentWorldMatrix
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
// const worldMatrix = parentWorldMatrix
|
|
48
|
+
// ? parentWorldMatrix.clone().multiply(localMatrix)
|
|
49
|
+
// : localMatrix.clone();
|
|
50
|
+
const worldMatrix = localMatrix.clone();
|
|
50
51
|
|
|
51
52
|
// 构造输出节点
|
|
52
53
|
result.push({
|
|
@@ -62,7 +63,8 @@ function parseData(input) {
|
|
|
62
63
|
|
|
63
64
|
// 递归处理子节点,传递当前世界矩阵
|
|
64
65
|
if (children) {
|
|
65
|
-
flattenAndComputeWorldMatrices(children, result, worldMatrix, instanceId);
|
|
66
|
+
// flattenAndComputeWorldMatrices(children, result, worldMatrix, instanceId);
|
|
67
|
+
flattenAndComputeWorldMatrices(children, result, instanceId);
|
|
66
68
|
// flattenAndComputeWorldMatrices(children, result);
|
|
67
69
|
}
|
|
68
70
|
}
|
|
@@ -293,7 +293,7 @@ function draw3Dmodel(geom, instanceName, instanceCount, nColor, nOpacity) {
|
|
|
293
293
|
if (Array.isArray(color) && color.length) {
|
|
294
294
|
colors = color;
|
|
295
295
|
opacity = colors[3];
|
|
296
|
-
} else if (color) {
|
|
296
|
+
} else if (typeof color === 'string') {
|
|
297
297
|
colors = color.split(',');
|
|
298
298
|
opacity = colors[3];
|
|
299
299
|
} else {
|
|
@@ -302,19 +302,25 @@ function draw3Dmodel(geom, instanceName, instanceCount, nColor, nOpacity) {
|
|
|
302
302
|
}
|
|
303
303
|
|
|
304
304
|
// 使用自定义材质或创建标准材质(默认参数配置)
|
|
305
|
-
|
|
306
|
-
|
|
305
|
+
let materialOptions = {
|
|
306
|
+
userData: {
|
|
307
|
+
nColor: nColor
|
|
308
|
+
? new THREE.Color(nColor)
|
|
309
|
+
: new THREE.Color(`rgb(${colors[0]}, ${colors[1]}, ${colors[2]})`),
|
|
310
|
+
nOpacity: nOpacity ? nOpacity : opacity,
|
|
311
|
+
},
|
|
312
|
+
side: THREE.DoubleSide,
|
|
313
|
+
transparent: true, // 着色器中需要设置透明度
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
customMaterial && Object.assign(customMaterial, materialOptions)
|
|
317
|
+
|
|
318
|
+
material = customMaterial ||
|
|
307
319
|
new THREE.MeshStandardMaterial({
|
|
320
|
+
...materialOptions,
|
|
308
321
|
roughness: 0.8,
|
|
309
322
|
envMapIntensity: 0.5, // 调低环境贴图的强度
|
|
310
|
-
|
|
311
|
-
userData: {
|
|
312
|
-
nColor: nColor
|
|
313
|
-
? new THREE.Color(nColor)
|
|
314
|
-
: new THREE.Color(`rgb(${colors[0]}, ${colors[1]}, ${colors[2]})`),
|
|
315
|
-
nOpacity: nOpacity ? nOpacity : opacity,
|
|
316
|
-
},
|
|
317
|
-
transparent: true, // 着色器中需要设置透明度
|
|
323
|
+
// wireframe: true
|
|
318
324
|
});
|
|
319
325
|
|
|
320
326
|
// 为每个实例存储透明度(opacity)
|
|
@@ -359,9 +365,9 @@ function draw3Dmodel(geom, instanceName, instanceCount, nColor, nOpacity) {
|
|
|
359
365
|
}
|
|
360
366
|
mesh = new THREE.InstancedMesh(geometry, material, instanceCount);
|
|
361
367
|
mesh.userData.drawObjectId = instanceName;
|
|
368
|
+
mesh.userData.is3D = geom.type == GEOM_TYPES.geom_3d || geom.type == GEOM_TYPES.geom_3d_obj;
|
|
362
369
|
|
|
363
370
|
// mesh.material = material;
|
|
364
|
-
|
|
365
371
|
return mesh;
|
|
366
372
|
}
|
|
367
373
|
|