@kimap/indoor-positioning-sdk-vue2 5.2.0 → 5.2.1

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": "@kimap/indoor-positioning-sdk-vue2",
3
- "version": "5.2.0",
3
+ "version": "5.2.1",
4
4
  "description": "Vue2自包含室内定位SDK - 完全兼容Webpack3+Babel6 | Vue2 Self-Contained Indoor Positioning SDK",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -277,6 +277,37 @@
277
277
  return wallOpacity;
278
278
  }
279
279
 
280
+ // 从OBJ内容中提取形状透明度信息(矩形、圆形、多边形)
281
+ function extractShapeOpacityFromOBJ(objContent) {
282
+ var shapeOpacity = {};
283
+ var lines = objContent.split('\n');
284
+ var currentShapeId = null;
285
+ var currentShapeType = null;
286
+
287
+ for (var i = 0; i < lines.length; i++) {
288
+ var line = lines[i].trim();
289
+
290
+ if (line.indexOf('o Shape_') === 0) {
291
+ // 提取形状ID和类型(格式:Shape_<type>_<id>)
292
+ var match = line.match(/Shape_([^_]+)_(.+)/);
293
+ if (match) {
294
+ currentShapeType = match[1];
295
+ currentShapeId = match[2];
296
+ }
297
+ } else if (currentShapeId && line.indexOf('# SHAPE_OPACITY') === 0) {
298
+ var opacity = parseFloat(line.split(' ')[2]);
299
+ if (!shapeOpacity[currentShapeId]) {
300
+ shapeOpacity[currentShapeId] = {};
301
+ }
302
+ shapeOpacity[currentShapeId].opacity = opacity;
303
+ shapeOpacity[currentShapeId].type = currentShapeType;
304
+ }
305
+ }
306
+
307
+ console.log('[Parsers] 提取到的形状透明度:', Object.keys(shapeOpacity).length, '个形状');
308
+ return shapeOpacity;
309
+ }
310
+
280
311
  /**
281
312
  * 3D 场景核心
282
313
  */
@@ -646,6 +677,13 @@
646
677
  self._wallOpacity = wallOpacity;
647
678
  }
648
679
 
680
+ // 提取形状透明度信息(矩形、圆形、多边形)
681
+ var shapeOpacity = extractShapeOpacityFromOBJ(objContent);
682
+ if (shapeOpacity && Object.keys(shapeOpacity).length > 0) {
683
+ console.log('✅ 从OBJ提取到形状透明度:', Object.keys(shapeOpacity).length, '个形状');
684
+ self._shapeOpacity = shapeOpacity;
685
+ }
686
+
649
687
  var object = objLoader.parse(objContent);
650
688
  self.processModel(object, colorMap);
651
689
 
@@ -769,11 +807,18 @@
769
807
  child.material.name.startsWith('Stair_')) {
770
808
  roughness = 0.6;
771
809
  metalness = 0;
772
- // 保持从MTL中获取的真实透明度
773
- if (opacity === 1.0) {
774
- opacity = 0.9;
810
+
811
+ // 从OBJ提取的形状透明度数据中读取
812
+ if (self._shapeOpacity) {
813
+ var shapeId = child.material.name.replace('Shape_', '').replace(/^rectangle_/, '').replace(/^circle_/, '').replace(/^polygon_/, '');
814
+ if (self._shapeOpacity[shapeId]) {
815
+ opacity = self._shapeOpacity[shapeId].opacity;
816
+ transparent = opacity < 1.0;
817
+ // 高透明度时关闭depthWrite
818
+ depthWrite = opacity >= 0.8;
819
+ console.log('[SceneCore] 应用形状透明度:', shapeId, '=', opacity);
820
+ }
775
821
  }
776
- transparent = opacity < 1.0;
777
822
  // 混合10%白色,让颜色更浅一点
778
823
  var color = new THREE.Color(mtlColor);
779
824
  color.lerp(new THREE.Color(0xffffff), 0.1);
@@ -1939,6 +1984,9 @@
1939
1984
  .then(function(result) {
1940
1985
  console.log('✅ 3D家具模型加载完成:', result);
1941
1986
 
1987
+ // 加载完成后应用形状透明度
1988
+ self._applyShapeOpacity(kidataObj);
1989
+
1942
1990
  return { success: true, loaded: result.loaded, failed: result.failed };
1943
1991
  })
1944
1992
  .catch(function(error) {
@@ -2708,6 +2756,100 @@
2708
2756
  }
2709
2757
  };
2710
2758
 
2759
+ /**
2760
+ * 应用矩形/圆形/多边形透明度
2761
+ * @private
2762
+ */
2763
+ KimapSDK.prototype._applyShapeOpacity = function(kidataObj) {
2764
+ if (!kidataObj || !kidataObj.floors || !this.core || !this.core.scene) {
2765
+ console.log('[KimapSDK] _applyShapeOpacity: 缺少必要数据');
2766
+ return;
2767
+ }
2768
+
2769
+ console.log('[KimapSDK] 开始应用形状透明度...');
2770
+
2771
+ var shapeCount = 0;
2772
+ var shapesInKidata = [];
2773
+ var self = this;
2774
+
2775
+ // 收集kidata中的所有形状数据(rectangle, circle, polygon)
2776
+ kidataObj.floors.forEach(function(floor) {
2777
+ if (floor.layers) {
2778
+ floor.layers.forEach(function(layer) {
2779
+ if (layer.elements) {
2780
+ layer.elements.forEach(function(element) {
2781
+ if (element.type === 'rectangle' || element.type === 'circle' || element.type === 'polygon') {
2782
+ shapesInKidata.push({
2783
+ id: element.id,
2784
+ type: element.type,
2785
+ opacity: element.opacity !== undefined ? element.opacity : 0.9
2786
+ });
2787
+ }
2788
+ });
2789
+ }
2790
+ });
2791
+ }
2792
+ });
2793
+
2794
+ console.log('[KimapSDK] Kidata中形状数量:', shapesInKidata.length);
2795
+
2796
+ if (shapesInKidata.length === 0) {
2797
+ console.log('[KimapSDK] Kidata中没有形状数据');
2798
+ return;
2799
+ }
2800
+
2801
+ // 遍历场景中的所有对象,通过材质名称识别形状
2802
+ this.core.scene.traverse(function(object) {
2803
+ if (object instanceof THREE.Mesh && object.material) {
2804
+ var materialName = object.material.name || '';
2805
+
2806
+ // 通过材质名称识别形状(Shape_前缀)
2807
+ if (materialName.startsWith('Shape_')) {
2808
+ // 从材质名称中提取形状ID(格式:Shape_<type>_<id>)
2809
+ var parts = materialName.split('_');
2810
+ var shapeId = parts[parts.length - 1];
2811
+
2812
+ // 在kidata中查找对应的形状数据
2813
+ var shapeData = shapesInKidata.find(function(s) {
2814
+ return s.id === shapeId;
2815
+ });
2816
+
2817
+ if (shapeData) {
2818
+ var opacity = shapeData.opacity;
2819
+
2820
+ console.log('[KimapSDK] 应用形状透明度:', {
2821
+ id: shapeId,
2822
+ type: shapeData.type,
2823
+ opacity: opacity,
2824
+ materialName: materialName
2825
+ });
2826
+
2827
+ // 应用透明度到材质
2828
+ if (Array.isArray(object.material)) {
2829
+ object.material.forEach(function(mat) {
2830
+ mat.transparent = opacity < 1;
2831
+ mat.opacity = opacity;
2832
+ mat.needsUpdate = true;
2833
+ });
2834
+ } else {
2835
+ object.material.transparent = opacity < 1;
2836
+ object.material.opacity = opacity;
2837
+ object.material.needsUpdate = true;
2838
+ }
2839
+
2840
+ shapeCount++;
2841
+ }
2842
+ }
2843
+ }
2844
+ });
2845
+
2846
+ if (shapeCount > 0) {
2847
+ console.log('[KimapSDK] ✅ 应用形状透明度完成:', shapeCount, '个形状');
2848
+ } else {
2849
+ console.log('[KimapSDK] ⚠️ 未找到匹配的形状对象');
2850
+ }
2851
+ };
2852
+
2711
2853
  /**
2712
2854
  * 从kidata内容加载家具模型(不处理文本和墙体透明度)
2713
2855
  * @param {string} kidataContent - kidata文件内容(加密或未加密)
@@ -2742,6 +2884,10 @@
2742
2884
  return self._loadFurnitureModels(kidataObj)
2743
2885
  .then(function(result) {
2744
2886
  console.log('[KimapSDK] ✅ 3D家具模型加载完成:', result);
2887
+
2888
+ // 加载完成后应用形状透明度
2889
+ self._applyShapeOpacity(kidataObj);
2890
+
2745
2891
  return { success: true, loaded: result.loaded, failed: result.failed };
2746
2892
  });
2747
2893
  } catch (error) {
@@ -28,6 +28,7 @@ var extractMapConfigFromOBJ = parsers.extractMapConfigFromOBJ;
28
28
  var extractColorsFromOBJ = parsers.extractColorsFromOBJ;
29
29
  var extractTextElementsFromOBJ = parsers.extractTextElementsFromOBJ;
30
30
  var extractWallOpacityFromOBJ = parsers.extractWallOpacityFromOBJ;
31
+ var extractShapeOpacityFromOBJ = parsers.extractShapeOpacityFromOBJ;
31
32
 
32
33
  /**
33
34
  * SceneCore 构造函数
@@ -385,6 +386,13 @@ SceneCore.prototype._loadKimapFile = function(kimapUrl, themeUrl, objLoader, mtl
385
386
  console.log('[SceneCore] ✅ 从OBJ提取到墙体透明度:', Object.keys(wallOpacity).length, '个墙体');
386
387
  self._wallOpacity = wallOpacity;
387
388
  }
389
+
390
+ // 提取形状透明度信息(矩形、圆形、多边形)
391
+ var shapeOpacity = extractShapeOpacityFromOBJ(objContent);
392
+ if (shapeOpacity && Object.keys(shapeOpacity).length > 0) {
393
+ console.log('[SceneCore] ✅ 从OBJ提取到形状透明度:', Object.keys(shapeOpacity).length, '个形状');
394
+ self._shapeOpacity = shapeOpacity;
395
+ }
388
396
 
389
397
  // 解析OBJ内容
390
398
  var object = objLoader.parse(objContent);
@@ -627,11 +635,17 @@ SceneCore.prototype._processMaterial = function(child, materials, colorMap) {
627
635
  } else if (child.material.name.startsWith('Shape_') || child.material.name.startsWith('Stair_')) {
628
636
  roughness = 0.6;
629
637
  metalness = 0;
630
- // 保持从MTL中获取的真实透明度
631
- if (opacity === 1.0) {
632
- opacity = 0.9;
638
+ // 从OBJ提取的形状透明度数据中读取
639
+ if (self._shapeOpacity) {
640
+ var shapeId = child.material.name.replace('Shape_', '').replace(/^rectangle_/, '').replace(/^circle_/, '').replace(/^polygon_/, '');
641
+ if (self._shapeOpacity[shapeId]) {
642
+ opacity = self._shapeOpacity[shapeId].opacity;
643
+ transparent = opacity < 1.0;
644
+ // 高透明度时关闭depthWrite
645
+ depthWrite = opacity >= 0.8;
646
+ console.log('[SceneCore] 应用形状透明度:', shapeId, '=', opacity);
647
+ }
633
648
  }
634
- transparent = opacity < 1.0;
635
649
  // 混合10%白色,让颜色更浅一点
636
650
  var color = new THREE.Color(mtlColor);
637
651
  color.lerp(new THREE.Color(0xffffff), 0.1);
@@ -213,11 +213,46 @@ function extractWallOpacityFromOBJ(objContent) {
213
213
  return wallOpacity;
214
214
  }
215
215
 
216
+ /**
217
+ * 从OBJ内容中提取形状透明度信息(矩形、圆形、多边形)
218
+ * 格式: # SHAPE_OPACITY 0.9
219
+ */
220
+ function extractShapeOpacityFromOBJ(objContent) {
221
+ var shapeOpacity = {};
222
+ var lines = objContent.split('\n');
223
+ var currentShapeId = null;
224
+ var currentShapeType = null;
225
+
226
+ for (var i = 0; i < lines.length; i++) {
227
+ var line = lines[i].trim();
228
+
229
+ if (line.indexOf('o Shape_') === 0) {
230
+ // 提取形状ID和类型(格式:Shape_<type>_<id>)
231
+ var match = line.match(/Shape_([^_]+)_(.+)/);
232
+ if (match) {
233
+ currentShapeType = match[1];
234
+ currentShapeId = match[2];
235
+ }
236
+ } else if (currentShapeId && line.indexOf('# SHAPE_OPACITY') === 0) {
237
+ var opacity = parseFloat(line.split(' ')[2]);
238
+ if (!shapeOpacity[currentShapeId]) {
239
+ shapeOpacity[currentShapeId] = {};
240
+ }
241
+ shapeOpacity[currentShapeId].opacity = opacity;
242
+ shapeOpacity[currentShapeId].type = currentShapeType;
243
+ }
244
+ }
245
+
246
+ console.log('[Parsers] 提取到的形状透明度:', Object.keys(shapeOpacity).length, '个形状');
247
+ return shapeOpacity;
248
+ }
249
+
216
250
  module.exports = {
217
251
  extractBorderFromOBJ: extractBorderFromOBJ,
218
252
  extractMapConfigFromOBJ: extractMapConfigFromOBJ,
219
253
  extractColorsFromOBJ: extractColorsFromOBJ,
220
254
  extractCoordinateSystem: extractCoordinateSystem,
221
255
  extractTextElementsFromOBJ: extractTextElementsFromOBJ,
222
- extractWallOpacityFromOBJ: extractWallOpacityFromOBJ
256
+ extractWallOpacityFromOBJ: extractWallOpacityFromOBJ,
257
+ extractShapeOpacityFromOBJ: extractShapeOpacityFromOBJ
223
258
  };