@kimap/indoor-positioning-sdk-vue2 3.1.15 → 3.3.0

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": "3.1.15",
3
+ "version": "3.3.0",
4
4
  "description": "Vue2自包含室内定位SDK - 完全兼容Webpack3+Babel6 | Vue2 Self-Contained Indoor Positioning SDK",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -93,6 +93,78 @@
93
93
  }
94
94
  }
95
95
 
96
+ // 从OBJ内容中提取边界信息
97
+ function extractBorderFromOBJ(objContent) {
98
+ var border = {
99
+ min: { x: null, y: null, z: null },
100
+ max: { x: null, y: null, z: null }
101
+ };
102
+
103
+ var lines = objContent.split('\n');
104
+ var foundBorder = false;
105
+
106
+ for (var i = 0; i < lines.length; i++) {
107
+ var line = lines[i].trim();
108
+
109
+ if (line.indexOf('End Border Info') !== -1) break;
110
+
111
+ if (line.indexOf('KIMAP_BORDER_MIN_X') !== -1) {
112
+ border.min.x = parseFloat(line.split(' ')[2]);
113
+ foundBorder = true;
114
+ } else if (line.indexOf('KIMAP_BORDER_MIN_Y') !== -1) {
115
+ border.min.y = parseFloat(line.split(' ')[2]);
116
+ } else if (line.indexOf('KIMAP_BORDER_MIN_Z') !== -1) {
117
+ border.min.z = parseFloat(line.split(' ')[2]);
118
+ } else if (line.indexOf('KIMAP_BORDER_MAX_X') !== -1) {
119
+ border.max.x = parseFloat(line.split(' ')[2]);
120
+ } else if (line.indexOf('KIMAP_BORDER_MAX_Y') !== -1) {
121
+ border.max.y = parseFloat(line.split(' ')[2]);
122
+ } else if (line.indexOf('KIMAP_BORDER_MAX_Z') !== -1) {
123
+ border.max.z = parseFloat(line.split(' ')[2]);
124
+ }
125
+ }
126
+
127
+ if (foundBorder && border.min.x !== null && border.max.x !== null) {
128
+ return border;
129
+ }
130
+ return null;
131
+ }
132
+
133
+ // 从OBJ内容中提取地图配置信息(校准数据)
134
+ function extractMapConfigFromOBJ(objContent) {
135
+ var config = {
136
+ isCalibrated: false,
137
+ calibrationScale: null,
138
+ realWidth: null,
139
+ realHeight: null,
140
+ modelToRealScale: null
141
+ };
142
+
143
+ var lines = objContent.split('\n');
144
+ var foundConfig = false;
145
+
146
+ for (var i = 0; i < lines.length; i++) {
147
+ var line = lines[i].trim();
148
+
149
+ if (line.indexOf('KIMAP_CONFIG_CALIBRATED') !== -1) {
150
+ config.isCalibrated = line.split(' ')[2] === 'true';
151
+ foundConfig = true;
152
+ } else if (line.indexOf('KIMAP_CONFIG_CALIBRATION_SCALE') !== -1) {
153
+ config.calibrationScale = parseFloat(line.split(' ')[2]);
154
+ } else if (line.indexOf('KIMAP_CONFIG_REAL_WIDTH') !== -1) {
155
+ config.realWidth = parseFloat(line.split(' ')[2]);
156
+ } else if (line.indexOf('KIMAP_CONFIG_REAL_HEIGHT') !== -1) {
157
+ config.realHeight = parseFloat(line.split(' ')[2]);
158
+ } else if (line.indexOf('KIMAP_CONFIG_MODEL_TO_REAL_SCALE') !== -1) {
159
+ config.modelToRealScale = parseFloat(line.split(' ')[2]);
160
+ }
161
+
162
+ if (line.indexOf('End Config Info') !== -1) break;
163
+ }
164
+
165
+ return foundConfig ? config : null;
166
+ }
167
+
96
168
  // 从OBJ内容中提取颜色信息
97
169
  function extractColorsFromOBJ(objContent) {
98
170
  var colorMap = {};
@@ -449,6 +521,20 @@
449
521
  console.log('📄 OBJ内容预览(前500字符):');
450
522
  console.log(objContent.substring(0, 500));
451
523
 
524
+ // 提取边界信息
525
+ var borderInfo = extractBorderFromOBJ(objContent);
526
+ if (borderInfo) {
527
+ console.log('✅ 提取到边界信息:', borderInfo);
528
+ self._borderInfo = borderInfo;
529
+ }
530
+
531
+ // 提取地图配置信息(校准数据)
532
+ var mapConfig = extractMapConfigFromOBJ(objContent);
533
+ if (mapConfig && mapConfig.isCalibrated) {
534
+ console.log('✅ 提取到校准数据:', mapConfig);
535
+ self._mapConfig = mapConfig;
536
+ }
537
+
452
538
  // 提取颜色信息(作为备用,如果没有MTL的话)
453
539
  var colorMap = materials ? {} : extractColorsFromOBJ(objContent);
454
540
  if (!materials) {
@@ -767,6 +853,15 @@
767
853
 
768
854
  return self.core.init().then(function() {
769
855
  self.info = self.core.getMapInfo();
856
+
857
+ // 从SceneCore传递边界和配置信息
858
+ if (self.core._borderInfo) {
859
+ self._borderInfo = self.core._borderInfo;
860
+ }
861
+ if (self.core._mapConfig) {
862
+ self._mapConfig = self.core._mapConfig;
863
+ }
864
+
770
865
  self.addEventListeners();
771
866
  self.startRenderLoop();
772
867
  return self;
@@ -1282,6 +1377,76 @@
1282
1377
  this.core.controls.update();
1283
1378
  };
1284
1379
 
1380
+ /**
1381
+ * 获取地图配置信息(包含校准数据)
1382
+ */
1383
+ KimapSDK.prototype.getConfig = function() {
1384
+ var config = {};
1385
+
1386
+ // 模型尺寸(从边界信息获取,单位:米)
1387
+ if (this._borderInfo) {
1388
+ var border = this._borderInfo;
1389
+ config.mapX = border.max.x - border.min.x;
1390
+ config.mapY = border.max.y - border.min.y;
1391
+ config.mapZ = border.max.z - border.min.z;
1392
+ }
1393
+
1394
+ // 如果有校准数据,返回底图真实世界尺寸(单位:米)
1395
+ if (this._mapConfig && this._mapConfig.isCalibrated) {
1396
+ config.isCalibrated = true;
1397
+ config.baseMapWidth = this._mapConfig.realWidth / 100; // 底图真实宽度(米)
1398
+ config.baseMapHeight = this._mapConfig.realHeight / 100; // 底图真实高度(米)
1399
+ config.modelToRealScale = this._mapConfig.modelToRealScale;
1400
+ }
1401
+
1402
+ return config;
1403
+ };
1404
+
1405
+ /**
1406
+ * 获取地图边界信息
1407
+ */
1408
+ KimapSDK.prototype.getBorder = function() {
1409
+ // 如果模型中有边界信息,优先使用
1410
+ if (this._borderInfo) {
1411
+ return this._borderInfo;
1412
+ }
1413
+
1414
+ // 降级方案:根据坐标系统计算
1415
+ var origin = this.config.origin;
1416
+ var maxX = this.config.maxX / 100; // mm to m
1417
+ var maxY = this.config.maxY / 100;
1418
+
1419
+ return {
1420
+ min: {
1421
+ x: origin.x,
1422
+ y: origin.y,
1423
+ z: origin.z
1424
+ },
1425
+ max: {
1426
+ x: origin.x + maxX,
1427
+ y: origin.y + 0.375,
1428
+ z: origin.z + maxY
1429
+ }
1430
+ };
1431
+ };
1432
+
1433
+ /**
1434
+ * 设置边界信息(从OBJ文件解析后调用)
1435
+ * @private
1436
+ */
1437
+ KimapSDK.prototype._setBorderInfo = function(borderInfo) {
1438
+ this._borderInfo = borderInfo;
1439
+ };
1440
+
1441
+ /**
1442
+ * 设置地图配置信息(从OBJ文件解析后调用)
1443
+ * @private
1444
+ */
1445
+ KimapSDK.prototype._setMapConfig = function(mapConfig) {
1446
+ this._mapConfig = mapConfig;
1447
+ console.log('📍 地图配置已保存:', this._mapConfig);
1448
+ };
1449
+
1285
1450
  KimapSDK.prototype.destroy = function() {
1286
1451
  if (this.animationFrameId) {
1287
1452
  cancelAnimationFrame(this.animationFrameId);
package/src/KimapCore.js CHANGED
@@ -215,6 +215,52 @@ function extractBorderFromOBJ(objContent) {
215
215
  return null;
216
216
  }
217
217
 
218
+ /**
219
+ * 从OBJ内容中提取地图配置信息(包含校准数据)
220
+ * 配置信息格式:
221
+ * # KIMAP_CONFIG_CALIBRATED true
222
+ * # KIMAP_CONFIG_CALIBRATION_SCALE 2.5000
223
+ * # KIMAP_CONFIG_REAL_WIDTH 500.00
224
+ * # KIMAP_CONFIG_REAL_HEIGHT 400.00
225
+ * # KIMAP_CONFIG_MODEL_TO_REAL_SCALE 2.0000
226
+ */
227
+ function extractMapConfigFromOBJ(objContent) {
228
+ var config = {
229
+ isCalibrated: false,
230
+ calibrationScale: null,
231
+ realWidth: null,
232
+ realHeight: null,
233
+ modelToRealScale: null
234
+ };
235
+
236
+ var lines = objContent.split('\n');
237
+ var foundConfig = false;
238
+
239
+ for (var i = 0; i < lines.length; i++) {
240
+ var line = lines[i].trim();
241
+
242
+ if (line.indexOf('KIMAP_CONFIG_CALIBRATED') !== -1) {
243
+ config.isCalibrated = line.split(' ')[2] === 'true';
244
+ foundConfig = true;
245
+ } else if (line.indexOf('KIMAP_CONFIG_CALIBRATION_SCALE') !== -1) {
246
+ config.calibrationScale = parseFloat(line.split(' ')[2]);
247
+ } else if (line.indexOf('KIMAP_CONFIG_REAL_WIDTH') !== -1) {
248
+ config.realWidth = parseFloat(line.split(' ')[2]);
249
+ } else if (line.indexOf('KIMAP_CONFIG_REAL_HEIGHT') !== -1) {
250
+ config.realHeight = parseFloat(line.split(' ')[2]);
251
+ } else if (line.indexOf('KIMAP_CONFIG_MODEL_TO_REAL_SCALE') !== -1) {
252
+ config.modelToRealScale = parseFloat(line.split(' ')[2]);
253
+ }
254
+
255
+ // 如果遇到 End Config Info 或其他结束标记,停止解析
256
+ if (line.indexOf('End Config Info') !== -1 || line.indexOf('===== End Border Info =====') !== -1) {
257
+ break;
258
+ }
259
+ }
260
+
261
+ return foundConfig ? config : null;
262
+ }
263
+
218
264
  /**
219
265
  * 从OBJ内容中提取颜色信息
220
266
  */
@@ -483,6 +529,15 @@ SceneCore.prototype.loadMap = function(OBJLoader, MTLLoader) {
483
529
  }
484
530
  }
485
531
 
532
+ // 提取地图配置信息(校准数据)
533
+ var mapConfig = extractMapConfigFromOBJ(objContent);
534
+ if (mapConfig && mapConfig.isCalibrated) {
535
+ console.log('✅ 提取到校准数据:', mapConfig);
536
+ if (self.sdk && self.sdk._setMapConfig) {
537
+ self.sdk._setMapConfig(mapConfig);
538
+ }
539
+ }
540
+
486
541
  // 提取颜色信息(作为备用)
487
542
  var colorMap = materials ? {} : extractColorsFromOBJ(objContent);
488
543
  if (!materials) {
@@ -1145,18 +1200,28 @@ KimapSDK.prototype.getCoordinateSystem = function() {
1145
1200
  };
1146
1201
 
1147
1202
  /**
1148
- * 获取地图配置信息
1203
+ * 获取地图配置信息(包含校准数据)
1149
1204
  */
1150
1205
  KimapSDK.prototype.getConfig = function() {
1151
- return {
1152
- maxX: this.core.coordinateSystem.maxX,
1153
- maxY: this.core.coordinateSystem.maxY,
1154
- origin: {
1155
- x: this.core.coordinateSystem.origin.x,
1156
- y: this.core.coordinateSystem.origin.y,
1157
- z: this.core.coordinateSystem.origin.z
1158
- }
1159
- };
1206
+ var config = {};
1207
+
1208
+ // 模型尺寸(从边界信息获取,单位:米)
1209
+ if (this._borderInfo) {
1210
+ var border = this._borderInfo;
1211
+ config.mapX = border.max.x - border.min.x;
1212
+ config.mapY = border.max.y - border.min.y;
1213
+ config.mapZ = border.max.z - border.min.z;
1214
+ }
1215
+
1216
+ // 如果有校准数据,返回底图真实世界尺寸(单位:米)
1217
+ if (this._mapConfig && this._mapConfig.isCalibrated) {
1218
+ config.isCalibrated = true;
1219
+ config.baseMapWidth = this._mapConfig.realWidth / 100; // 底图真实宽度(米)
1220
+ config.baseMapHeight = this._mapConfig.realHeight / 100; // 底图真实高度(米)
1221
+ config.modelToRealScale = this._mapConfig.modelToRealScale;
1222
+ }
1223
+
1224
+ return config;
1160
1225
  };
1161
1226
 
1162
1227
  /**
@@ -1196,6 +1261,15 @@ KimapSDK.prototype._setBorderInfo = function(borderInfo) {
1196
1261
  this._borderInfo = borderInfo;
1197
1262
  };
1198
1263
 
1264
+ /**
1265
+ * 设置地图配置信息(从OBJ文件解析后调用)
1266
+ * @private
1267
+ */
1268
+ KimapSDK.prototype._setMapConfig = function(mapConfig) {
1269
+ this._mapConfig = mapConfig;
1270
+ console.log('📍 地图配置已保存:', this._mapConfig);
1271
+ };
1272
+
1199
1273
  /**
1200
1274
  * 获取楼层列表
1201
1275
  * 注意:当前版本为单楼层,返回默认楼层信息