fl-web-component 1.1.9 → 1.1.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/README.md +4 -0
- package/dist/fl-web-component.common.js +103 -59
- package/dist/fl-web-component.css +1 -1
- package/package.json +1 -1
- package/packages/components/com-graphics/index.vue +225 -152
- package/src/utils/flgltf-parser.js +2 -2
- package/src/utils/instance-parser.js +81 -18
- package/src/utils/mock.js +9813 -10
|
@@ -25,7 +25,15 @@ let drawObjMapInstance = {};
|
|
|
25
25
|
* @param {Object} instance - 实例对象,包含绘制对象ID和实例ID等数据
|
|
26
26
|
* @param {Array} drawObjs - 绘制对象数组,包含几何数据
|
|
27
27
|
*/
|
|
28
|
-
function handleInstancedMeshModel(
|
|
28
|
+
function handleInstancedMeshModel(
|
|
29
|
+
instances,
|
|
30
|
+
drawObjs,
|
|
31
|
+
type,
|
|
32
|
+
scene,
|
|
33
|
+
customColor,
|
|
34
|
+
meshNameConfig,
|
|
35
|
+
customOpacity
|
|
36
|
+
) {
|
|
29
37
|
// 第一阶段:构建实例映射表
|
|
30
38
|
let modelGroup = new THREE.Group();
|
|
31
39
|
for (let i = 0; i < instances.length; i++) {
|
|
@@ -50,7 +58,7 @@ function handleInstancedMeshModel(instances, drawObjs, type, scene, customColor,
|
|
|
50
58
|
const group = new THREE.Group();
|
|
51
59
|
// let grouphName = ''
|
|
52
60
|
for (const key in meshNameConfig) {
|
|
53
|
-
group.userData[key] = meshNameConfig[key]
|
|
61
|
+
group.userData[key] = meshNameConfig[key];
|
|
54
62
|
// grouphName += ':' + meshNameConfig[key]
|
|
55
63
|
}
|
|
56
64
|
// grouphName !== '' ? instances[i].drawObject + grouphName: instances[i].drawObject;
|
|
@@ -59,20 +67,27 @@ function handleInstancedMeshModel(instances, drawObjs, type, scene, customColor,
|
|
|
59
67
|
group.userData.instanceId = instances[i].drawObject;
|
|
60
68
|
const instanceCount = drawObj.MapInstance.length;
|
|
61
69
|
drawObj.MapMesh?.forEach(mesh => {
|
|
62
|
-
const model = drawModel(
|
|
70
|
+
const model = drawModel(
|
|
71
|
+
mesh,
|
|
72
|
+
instances[i].drawObject,
|
|
73
|
+
instanceCount,
|
|
74
|
+
customColor,
|
|
75
|
+
customOpacity
|
|
76
|
+
);
|
|
63
77
|
if (!model) {
|
|
64
78
|
return;
|
|
65
79
|
}
|
|
66
|
-
let meshName = ''
|
|
80
|
+
let meshName = '';
|
|
67
81
|
for (const key in meshNameConfig) {
|
|
68
|
-
model.userData[key] = meshNameConfig[key]
|
|
69
|
-
meshName += ':' + meshNameConfig[key]
|
|
82
|
+
model.userData[key] = meshNameConfig[key];
|
|
83
|
+
meshName += ':' + meshNameConfig[key];
|
|
70
84
|
}
|
|
71
85
|
drawObj.MapInstance.forEach((item, index) => {
|
|
72
86
|
if (item.instanceId == instances[i].instanceId) {
|
|
73
87
|
model.userData.instanceIndex = index;
|
|
74
|
-
model.userData.instanceId = instances[i].instanceId
|
|
75
|
-
model.name =
|
|
88
|
+
model.userData.instanceId = instances[i].instanceId;
|
|
89
|
+
model.name =
|
|
90
|
+
meshName !== '' ? instances[i].instanceId + meshName : instances[i].instanceId;
|
|
76
91
|
const matrixVal = item.matrix?.val;
|
|
77
92
|
if (matrixVal) {
|
|
78
93
|
const m4 = new THREE.Matrix4();
|
|
@@ -96,10 +111,9 @@ function handleInstancedMeshModel(instances, drawObjs, type, scene, customColor,
|
|
|
96
111
|
modelGroup.add(group);
|
|
97
112
|
}
|
|
98
113
|
}
|
|
99
|
-
|
|
100
114
|
}
|
|
101
|
-
console.log('modelGroup', modelGroup)
|
|
102
|
-
console.log('drawObjMapInstance', drawObjMapInstance)
|
|
115
|
+
console.log('modelGroup', modelGroup);
|
|
116
|
+
console.log('drawObjMapInstance', drawObjMapInstance);
|
|
103
117
|
return modelGroup;
|
|
104
118
|
// timeRender();
|
|
105
119
|
// console.log('scene', scene)
|
|
@@ -159,7 +173,7 @@ function formatDrawObjs(data) {
|
|
|
159
173
|
* @param {Number} instanceCount - 实例化渲染的数量(用于InstancedMesh)
|
|
160
174
|
* @returns {THREE.Object3D} 返回创建的3D模型对象
|
|
161
175
|
*/
|
|
162
|
-
function drawModel(geom, instanceName, instanceCount, nColor) {
|
|
176
|
+
function drawModel(geom, instanceName, instanceCount, nColor, nOpacity) {
|
|
163
177
|
let model;
|
|
164
178
|
// 处理二维几何体(普通2D图形和特殊2D图形)
|
|
165
179
|
if (geom.type == GEOM_TYPES.geom_2d || geom.type == GEOM_TYPES.geom_2d_others) {
|
|
@@ -179,10 +193,10 @@ function drawModel(geom, instanceName, instanceCount, nColor) {
|
|
|
179
193
|
geom.type == GEOM_TYPES.geom_2d_ellipse ||
|
|
180
194
|
geom.type == GEOM_TYPES.geom_2d_ellipseArc
|
|
181
195
|
) {
|
|
182
|
-
model = drawCurves(geom, instanceName, instanceCount)
|
|
196
|
+
model = drawCurves(geom, instanceName, instanceCount); // TODO 该类型调试中
|
|
183
197
|
// 处理三维几何体(普通3D模型和OBJ模型)
|
|
184
198
|
} else if (geom.type == GEOM_TYPES.geom_3d || geom.type == GEOM_TYPES.geom_3d_obj) {
|
|
185
|
-
model = draw3Dmodel(geom, instanceName, instanceCount, nColor);
|
|
199
|
+
model = draw3Dmodel(geom, instanceName, instanceCount, nColor, nOpacity);
|
|
186
200
|
}
|
|
187
201
|
return model;
|
|
188
202
|
}
|
|
@@ -252,7 +266,7 @@ function drawCurves(geom, instanceName, instanceCount) {
|
|
|
252
266
|
* @param {Number} instanceCount - 需要创建的实例数量
|
|
253
267
|
* @returns {THREE.InstancedMesh} - 返回创建的三维实例化网格对象
|
|
254
268
|
*/
|
|
255
|
-
function draw3Dmodel(geom, instanceName, instanceCount, nColor) {
|
|
269
|
+
function draw3Dmodel(geom, instanceName, instanceCount, nColor, nOpacity) {
|
|
256
270
|
// 解构几何数据中的自定义几何体和材质
|
|
257
271
|
const { geometry: customGeometry, material: customMaterial, triangles, points, normals } = geom;
|
|
258
272
|
// 使用自定义几何体或创建新的缓冲几何体
|
|
@@ -275,13 +289,16 @@ function draw3Dmodel(geom, instanceName, instanceCount, nColor) {
|
|
|
275
289
|
geometry.setAttribute('normal', new THREE.BufferAttribute(normal, 3));
|
|
276
290
|
}
|
|
277
291
|
const { color } = geom.prop;
|
|
278
|
-
let material, mesh, colors;
|
|
292
|
+
let material, mesh, colors, opacity;
|
|
279
293
|
if (Array.isArray(color) && color.length) {
|
|
280
294
|
colors = color;
|
|
295
|
+
opacity = colors[3];
|
|
281
296
|
} else if (color) {
|
|
282
297
|
colors = color.split(',');
|
|
298
|
+
opacity = colors[3];
|
|
283
299
|
} else {
|
|
284
|
-
colors = [255, 255, 255
|
|
300
|
+
colors = [255, 255, 255];
|
|
301
|
+
opacity = 1;
|
|
285
302
|
}
|
|
286
303
|
|
|
287
304
|
// 使用自定义材质或创建标准材质(默认参数配置)
|
|
@@ -292,13 +309,59 @@ function draw3Dmodel(geom, instanceName, instanceCount, nColor) {
|
|
|
292
309
|
envMapIntensity: 0.5, // 调低环境贴图的强度
|
|
293
310
|
side: THREE.DoubleSide,
|
|
294
311
|
userData: {
|
|
295
|
-
nColor: nColor
|
|
312
|
+
nColor: nColor
|
|
313
|
+
? new THREE.Color(nColor)
|
|
314
|
+
: new THREE.Color(`rgb(${colors[0]}, ${colors[1]}, ${colors[2]})`),
|
|
315
|
+
nOpacity: nOpacity ? nOpacity : opacity,
|
|
296
316
|
},
|
|
317
|
+
transparent: true, // 着色器中需要设置透明度
|
|
297
318
|
});
|
|
298
319
|
|
|
320
|
+
// 为每个实例存储透明度(opacity)
|
|
321
|
+
const opacities = new Float32Array(instanceCount);
|
|
322
|
+
|
|
323
|
+
// 填充透明度数据
|
|
324
|
+
for (let i = 0; i < instanceCount; i++) {
|
|
325
|
+
opacities[i] = opacity;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// 创建实例属性并绑定到 InstancedMesh
|
|
329
|
+
geometry.setAttribute('opacity', new THREE.InstancedBufferAttribute(opacities, 1));
|
|
330
|
+
|
|
331
|
+
// 自定义着色器逻辑
|
|
332
|
+
if (!customMaterial) {
|
|
333
|
+
material.onBeforeCompile = shader => {
|
|
334
|
+
// 添加顶点着色器输入
|
|
335
|
+
shader.vertexShader = `
|
|
336
|
+
in float opacity; // 实例透明度属性
|
|
337
|
+
out float vAlpha;
|
|
338
|
+
${shader.vertexShader}
|
|
339
|
+
`.replace(
|
|
340
|
+
'#include <begin_vertex>',
|
|
341
|
+
`
|
|
342
|
+
#include <begin_vertex>
|
|
343
|
+
vAlpha = opacity; // 传递透明度到片段着色器
|
|
344
|
+
`
|
|
345
|
+
);
|
|
346
|
+
|
|
347
|
+
// 修改片段着色器
|
|
348
|
+
shader.fragmentShader = `
|
|
349
|
+
in float vAlpha;
|
|
350
|
+
${shader.fragmentShader}
|
|
351
|
+
`.replace(
|
|
352
|
+
'#include <alphatest_fragment>',
|
|
353
|
+
`
|
|
354
|
+
#include <alphatest_fragment>
|
|
355
|
+
diffuseColor.a *= vAlpha; // 应用实例透明度
|
|
356
|
+
`
|
|
357
|
+
);
|
|
358
|
+
};
|
|
359
|
+
}
|
|
299
360
|
mesh = new THREE.InstancedMesh(geometry, material, instanceCount);
|
|
300
361
|
mesh.userData.drawObjectId = instanceName;
|
|
301
362
|
|
|
363
|
+
// mesh.material = material;
|
|
364
|
+
|
|
302
365
|
return mesh;
|
|
303
366
|
}
|
|
304
367
|
|