@kimap/indoor-positioning-sdk-vue2 3.1.3 → 3.1.5
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 +1 -1
- package/src/KimapCore.js +159 -0
package/package.json
CHANGED
package/src/KimapCore.js
CHANGED
|
@@ -161,6 +161,60 @@ function decryptTheme(themeContent) {
|
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
+
/**
|
|
165
|
+
* 从OBJ内容中提取边界信息
|
|
166
|
+
* 边界信息格式:
|
|
167
|
+
* # KIMAP_BORDER_MIN_X 0.000000
|
|
168
|
+
* # KIMAP_BORDER_MIN_Y 0.000000
|
|
169
|
+
* # KIMAP_BORDER_MIN_Z 0.000000
|
|
170
|
+
* # KIMAP_BORDER_MAX_X 10.500000
|
|
171
|
+
* # KIMAP_BORDER_MAX_Y 0.375000
|
|
172
|
+
* # KIMAP_BORDER_MAX_Z 8.200000
|
|
173
|
+
*/
|
|
174
|
+
function extractBorderFromOBJ(objContent) {
|
|
175
|
+
var border = {
|
|
176
|
+
min: { x: null, y: null, z: null },
|
|
177
|
+
max: { x: null, y: null, z: null }
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
var lines = objContent.split('\n');
|
|
181
|
+
var foundBorder = false;
|
|
182
|
+
|
|
183
|
+
for (var i = 0; i < lines.length; i++) {
|
|
184
|
+
var line = lines[i].trim();
|
|
185
|
+
|
|
186
|
+
// 检测边界结束标记
|
|
187
|
+
if (line.indexOf('End Border Info') !== -1) {
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// 解析边界值
|
|
192
|
+
if (line.indexOf('KIMAP_BORDER_MIN_X') !== -1) {
|
|
193
|
+
border.min.x = parseFloat(line.split(' ')[2]);
|
|
194
|
+
foundBorder = true;
|
|
195
|
+
} else if (line.indexOf('KIMAP_BORDER_MIN_Y') !== -1) {
|
|
196
|
+
border.min.y = parseFloat(line.split(' ')[2]);
|
|
197
|
+
} else if (line.indexOf('KIMAP_BORDER_MIN_Z') !== -1) {
|
|
198
|
+
border.min.z = parseFloat(line.split(' ')[2]);
|
|
199
|
+
} else if (line.indexOf('KIMAP_BORDER_MAX_X') !== -1) {
|
|
200
|
+
border.max.x = parseFloat(line.split(' ')[2]);
|
|
201
|
+
} else if (line.indexOf('KIMAP_BORDER_MAX_Y') !== -1) {
|
|
202
|
+
border.max.y = parseFloat(line.split(' ')[2]);
|
|
203
|
+
} else if (line.indexOf('KIMAP_BORDER_MAX_Z') !== -1) {
|
|
204
|
+
border.max.z = parseFloat(line.split(' ')[2]);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// 验证是否成功解析
|
|
209
|
+
if (foundBorder &&
|
|
210
|
+
border.min.x !== null && border.min.y !== null && border.min.z !== null &&
|
|
211
|
+
border.max.x !== null && border.max.y !== null && border.max.z !== null) {
|
|
212
|
+
return border;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
|
|
164
218
|
/**
|
|
165
219
|
* 从OBJ内容中提取颜色信息
|
|
166
220
|
*/
|
|
@@ -419,6 +473,16 @@ SceneCore.prototype.loadMap = function(OBJLoader, MTLLoader) {
|
|
|
419
473
|
|
|
420
474
|
console.log('解密成功,开始解析OBJ模型...');
|
|
421
475
|
|
|
476
|
+
// 提取边界信息
|
|
477
|
+
var borderInfo = extractBorderFromOBJ(objContent);
|
|
478
|
+
if (borderInfo) {
|
|
479
|
+
console.log('✅ 提取到边界信息:', borderInfo);
|
|
480
|
+
// 存储到SDK实例中(需要通过回调或全局引用)
|
|
481
|
+
if (self.sdk && self.sdk._setBorderInfo) {
|
|
482
|
+
self.sdk._setBorderInfo(borderInfo);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
422
486
|
// 提取颜色信息(作为备用)
|
|
423
487
|
var colorMap = materials ? {} : extractColorsFromOBJ(objContent);
|
|
424
488
|
if (!materials) {
|
|
@@ -453,6 +517,13 @@ SceneCore.prototype.loadMap = function(OBJLoader, MTLLoader) {
|
|
|
453
517
|
var boundingBox = new THREE.Box3();
|
|
454
518
|
|
|
455
519
|
self.mapModel.traverse(function(child) {
|
|
520
|
+
// 隐藏底平面交互层(用于射线检测,但不渲染)
|
|
521
|
+
if (child.name === 'HiddenGroundPlane' || child.name.includes('InteractionLayer')) {
|
|
522
|
+
child.visible = false;
|
|
523
|
+
console.log('✅ 隐藏交互层底平面:', child.name);
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
|
|
456
527
|
if (child instanceof THREE.Mesh) {
|
|
457
528
|
meshCount++;
|
|
458
529
|
|
|
@@ -626,6 +697,13 @@ SceneCore.prototype.loadMap = function(OBJLoader, MTLLoader) {
|
|
|
626
697
|
var boundingBox = new THREE.Box3();
|
|
627
698
|
|
|
628
699
|
self.mapModel.traverse(function(child) {
|
|
700
|
+
// 隐藏底平面交互层(用于射线检测,但不渲染)
|
|
701
|
+
if (child.name === 'HiddenGroundPlane' || child.name.includes('InteractionLayer')) {
|
|
702
|
+
child.visible = false;
|
|
703
|
+
console.log('✅ 隐藏交互层底平面:', child.name);
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
|
|
629
707
|
if (child instanceof THREE.Mesh) {
|
|
630
708
|
meshCount++;
|
|
631
709
|
|
|
@@ -804,6 +882,7 @@ KimapSDK.prototype.init = function() {
|
|
|
804
882
|
self.raycaster = new THREE.Raycaster();
|
|
805
883
|
self.mouse = new THREE.Vector2();
|
|
806
884
|
self.core = new SceneCore(self.config);
|
|
885
|
+
self.core.sdk = self; // 设置SDK引用,用于边界信息存储
|
|
807
886
|
return self.core.init();
|
|
808
887
|
})
|
|
809
888
|
.then(function() {
|
|
@@ -1065,6 +1144,86 @@ KimapSDK.prototype.getCoordinateSystem = function() {
|
|
|
1065
1144
|
};
|
|
1066
1145
|
};
|
|
1067
1146
|
|
|
1147
|
+
/**
|
|
1148
|
+
* 获取地图配置信息
|
|
1149
|
+
*/
|
|
1150
|
+
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
|
+
};
|
|
1160
|
+
};
|
|
1161
|
+
|
|
1162
|
+
/**
|
|
1163
|
+
* 获取地图边界信息
|
|
1164
|
+
* 边界信息从模型文件中读取,如果没有则根据坐标系统计算
|
|
1165
|
+
*/
|
|
1166
|
+
KimapSDK.prototype.getBorder = function() {
|
|
1167
|
+
// 如果模型中有边界信息,优先使用(需要在加载OBJ时解析并存储)
|
|
1168
|
+
if (this._borderInfo) {
|
|
1169
|
+
return this._borderInfo;
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
// 降级方案:根据坐标系统计算
|
|
1173
|
+
var origin = this.core.coordinateSystem.origin;
|
|
1174
|
+
var maxX = this.core.coordinateSystem.maxX;
|
|
1175
|
+
var maxY = this.core.coordinateSystem.maxY;
|
|
1176
|
+
|
|
1177
|
+
return {
|
|
1178
|
+
min: {
|
|
1179
|
+
x: origin.x,
|
|
1180
|
+
y: origin.y,
|
|
1181
|
+
z: origin.z
|
|
1182
|
+
},
|
|
1183
|
+
max: {
|
|
1184
|
+
x: origin.x + maxX,
|
|
1185
|
+
y: origin.y + 0.375, // 默认高度
|
|
1186
|
+
z: origin.z + maxY
|
|
1187
|
+
}
|
|
1188
|
+
};
|
|
1189
|
+
};
|
|
1190
|
+
|
|
1191
|
+
/**
|
|
1192
|
+
* 设置边界信息(从OBJ文件解析后调用)
|
|
1193
|
+
* @private
|
|
1194
|
+
*/
|
|
1195
|
+
KimapSDK.prototype._setBorderInfo = function(borderInfo) {
|
|
1196
|
+
this._borderInfo = borderInfo;
|
|
1197
|
+
};
|
|
1198
|
+
|
|
1199
|
+
/**
|
|
1200
|
+
* 获取楼层列表
|
|
1201
|
+
* 注意:当前版本为单楼层,返回默认楼层信息
|
|
1202
|
+
*/
|
|
1203
|
+
KimapSDK.prototype.getFloors = function() {
|
|
1204
|
+
// TODO: 多楼层支持,从配置或模型中读取
|
|
1205
|
+
return [
|
|
1206
|
+
{ id: 'floor1', name: '一楼', order: 1 }
|
|
1207
|
+
];
|
|
1208
|
+
};
|
|
1209
|
+
|
|
1210
|
+
/**
|
|
1211
|
+
* 获取当前楼层ID
|
|
1212
|
+
*/
|
|
1213
|
+
KimapSDK.prototype.getCurrentFloor = function() {
|
|
1214
|
+
// TODO: 多楼层支持
|
|
1215
|
+
return 'floor1';
|
|
1216
|
+
};
|
|
1217
|
+
|
|
1218
|
+
/**
|
|
1219
|
+
* 切换楼层
|
|
1220
|
+
* @param {string} floorId - 楼层ID
|
|
1221
|
+
*/
|
|
1222
|
+
KimapSDK.prototype.switchFloor = function(floorId) {
|
|
1223
|
+
// TODO: 多楼层支持,实现楼层切换逻辑
|
|
1224
|
+
console.warn('多楼层功能暂未实现,当前版本仅支持单楼层');
|
|
1225
|
+
};
|
|
1226
|
+
|
|
1068
1227
|
KimapSDK.prototype.destroy = function() {
|
|
1069
1228
|
if (this.animationFrameId) {
|
|
1070
1229
|
cancelAnimationFrame(this.animationFrameId);
|