@kimap/indoor-positioning-sdk-vue2 5.2.9 → 5.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 +1 -1
- package/src/core/KimapSDK.js +93 -194
- package/src/core/SceneCore.js +10 -7
package/package.json
CHANGED
package/src/core/KimapSDK.js
CHANGED
|
@@ -93,9 +93,6 @@ KimapSDK.prototype.init = function() {
|
|
|
93
93
|
// 创建科技感地面背景
|
|
94
94
|
self._createTechGround();
|
|
95
95
|
|
|
96
|
-
// 启动道路动画循环
|
|
97
|
-
self._startRoadAnimationLoop();
|
|
98
|
-
|
|
99
96
|
// 加载背景建筑
|
|
100
97
|
if (self.backgroundBuildingsConfig.enabled !== false) {
|
|
101
98
|
self._loadBackgroundBuildings();
|
|
@@ -105,6 +102,12 @@ KimapSDK.prototype.init = function() {
|
|
|
105
102
|
self.startRenderLoop();
|
|
106
103
|
self._extractWallsFromModel();
|
|
107
104
|
|
|
105
|
+
// 多楼层模式:默认显示第一个(最低)楼层,不自动切换到ALL模式
|
|
106
|
+
if (self.isMultiFloor && self.floorGroups.length > 0) {
|
|
107
|
+
self.currentFloorIndex = 1; // 1 表示第一个实际楼层(0是ALL)
|
|
108
|
+
self._showSingleFloor(0); // 显示索引0的楼层
|
|
109
|
+
}
|
|
110
|
+
|
|
108
111
|
return self;
|
|
109
112
|
});
|
|
110
113
|
};
|
|
@@ -749,19 +752,40 @@ KimapSDK.prototype._onFloorButtonClick = function(index) {
|
|
|
749
752
|
KimapSDK.prototype._showAllFloors = function() {
|
|
750
753
|
var self = this;
|
|
751
754
|
|
|
752
|
-
//
|
|
755
|
+
// 显示所有楼层,并设置淡蓝色半透明效果
|
|
753
756
|
if (this.floorGroups && this.floorGroups.length > 0) {
|
|
754
757
|
this.floorGroups.forEach(function(group) {
|
|
755
758
|
group.visible = true;
|
|
756
|
-
//
|
|
757
|
-
|
|
759
|
+
// 设置淡蓝色半透明效果
|
|
760
|
+
group.traverse(function(child) {
|
|
761
|
+
if (child.material) {
|
|
762
|
+
if (Array.isArray(child.material)) {
|
|
763
|
+
child.material.forEach(function(mat) {
|
|
764
|
+
if (mat.opacity !== undefined) {
|
|
765
|
+
mat.transparent = true;
|
|
766
|
+
mat.opacity = 0.5;
|
|
767
|
+
// 设置淡蓝色
|
|
768
|
+
if (mat.color) {
|
|
769
|
+
mat.color.setHex(0x88ccff);
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
});
|
|
773
|
+
} else if (child.material.opacity !== undefined) {
|
|
774
|
+
child.material.transparent = true;
|
|
775
|
+
child.material.opacity = 0.5;
|
|
776
|
+
// 设置淡蓝色
|
|
777
|
+
if (child.material.color) {
|
|
778
|
+
child.material.color.setHex(0x88ccff);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
});
|
|
758
783
|
});
|
|
759
784
|
}
|
|
760
785
|
|
|
761
|
-
//
|
|
786
|
+
// 显示背景建筑
|
|
762
787
|
if (this.backgroundGroup) {
|
|
763
788
|
this.backgroundGroup.visible = true;
|
|
764
|
-
this._fadeInBackgroundBuildings(600);
|
|
765
789
|
}
|
|
766
790
|
|
|
767
791
|
// 隐藏家具(ALL模式不显示家具)
|
|
@@ -829,14 +853,32 @@ KimapSDK.prototype._fadeInGroup = function(group, duration) {
|
|
|
829
853
|
KimapSDK.prototype._showSingleFloor = function(floorIndex) {
|
|
830
854
|
var self = this;
|
|
831
855
|
|
|
832
|
-
//
|
|
856
|
+
// 隐藏所有楼层,然后只显示目标楼层
|
|
833
857
|
if (this.floorGroups && this.floorGroups.length > 0) {
|
|
834
858
|
this.floorGroups.forEach(function(group, index) {
|
|
859
|
+
group.visible = (index === floorIndex);
|
|
860
|
+
// 恢复材质属性:移除透明效果,恢复原始颜色
|
|
835
861
|
if (index === floorIndex) {
|
|
836
|
-
group.
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
862
|
+
group.traverse(function(child) {
|
|
863
|
+
if (child.material) {
|
|
864
|
+
if (Array.isArray(child.material)) {
|
|
865
|
+
child.material.forEach(function(mat) {
|
|
866
|
+
// 移除透明效果,恢复可见性
|
|
867
|
+
mat.transparent = false;
|
|
868
|
+
mat.opacity = 1;
|
|
869
|
+
// 确保使用双面渲染避免黑边
|
|
870
|
+
mat.side = THREE.DoubleSide;
|
|
871
|
+
// 开启深度写入
|
|
872
|
+
mat.depthWrite = true;
|
|
873
|
+
});
|
|
874
|
+
} else if (child.material.opacity !== undefined) {
|
|
875
|
+
child.material.transparent = false;
|
|
876
|
+
child.material.opacity = 1;
|
|
877
|
+
child.material.side = THREE.DoubleSide;
|
|
878
|
+
child.material.depthWrite = true;
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
});
|
|
840
882
|
}
|
|
841
883
|
});
|
|
842
884
|
}
|
|
@@ -846,9 +888,19 @@ KimapSDK.prototype._showSingleFloor = function(floorIndex) {
|
|
|
846
888
|
this.backgroundGroup.visible = false;
|
|
847
889
|
}
|
|
848
890
|
|
|
849
|
-
//
|
|
850
|
-
if (this.
|
|
851
|
-
|
|
891
|
+
// 重新加载该楼层的家具
|
|
892
|
+
if (this.dataUrl && this.config.objUrl) {
|
|
893
|
+
// 获取当前楼层的URL
|
|
894
|
+
var objUrls = Array.isArray(this.config.objUrl) ? this.config.objUrl : [this.config.objUrl];
|
|
895
|
+
if (objUrls[floorIndex]) {
|
|
896
|
+
// 保存当前objUrl,加载完成后恢复
|
|
897
|
+
var originalObjUrl = this.config.objUrl;
|
|
898
|
+
this.config.objUrl = objUrls[floorIndex];
|
|
899
|
+
this.loadKMData().then(function() {
|
|
900
|
+
// 恢复原始objUrl
|
|
901
|
+
self.config.objUrl = originalObjUrl;
|
|
902
|
+
});
|
|
903
|
+
}
|
|
852
904
|
}
|
|
853
905
|
|
|
854
906
|
// 调整相机到该楼层(带动画)
|
|
@@ -1109,22 +1161,21 @@ KimapSDK.prototype._createBackgroundBuildings = function(GLTFLoader, models, cou
|
|
|
1109
1161
|
|
|
1110
1162
|
/**
|
|
1111
1163
|
* 创建备用几何体建筑(当没有模型文件时)
|
|
1112
|
-
*
|
|
1164
|
+
* 简化版:柱状建筑,科技感风格
|
|
1113
1165
|
* @private
|
|
1114
1166
|
*/
|
|
1115
1167
|
KimapSDK.prototype._createFallbackBuilding = function(x, z) {
|
|
1116
|
-
var height =
|
|
1117
|
-
var
|
|
1118
|
-
var depth = 15 + Math.random() * 25;
|
|
1168
|
+
var height = 40 + Math.random() * 60; // 40-100米高
|
|
1169
|
+
var radius = 8 + Math.random() * 8; // 8-16米半径
|
|
1119
1170
|
|
|
1120
1171
|
var buildingGroup = new THREE.Group();
|
|
1121
1172
|
buildingGroup.position.set(x, 0, z);
|
|
1122
1173
|
|
|
1123
|
-
// 主楼体 -
|
|
1124
|
-
var geometry = new THREE.
|
|
1174
|
+
// 主楼体 - 圆柱形建筑
|
|
1175
|
+
var geometry = new THREE.CylinderGeometry(radius, radius, height, 16);
|
|
1125
1176
|
|
|
1126
1177
|
// 科技蓝基础色
|
|
1127
|
-
var baseColor = new THREE.Color().setHSL(0.6 + Math.random() * 0.05, 0.8, 0.
|
|
1178
|
+
var baseColor = new THREE.Color().setHSL(0.6 + Math.random() * 0.05, 0.8, 0.3);
|
|
1128
1179
|
var material = new THREE.MeshStandardMaterial({
|
|
1129
1180
|
color: baseColor,
|
|
1130
1181
|
roughness: 0.3,
|
|
@@ -1136,85 +1187,30 @@ KimapSDK.prototype._createFallbackBuilding = function(x, z) {
|
|
|
1136
1187
|
building.position.y = height / 2;
|
|
1137
1188
|
buildingGroup.add(building);
|
|
1138
1189
|
|
|
1139
|
-
//
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
this._addGlowingEdges(buildingGroup, width, height, depth);
|
|
1144
|
-
|
|
1145
|
-
return buildingGroup;
|
|
1146
|
-
};
|
|
1147
|
-
|
|
1148
|
-
/**
|
|
1149
|
-
* 为建筑添加窗户细节
|
|
1150
|
-
* @private
|
|
1151
|
-
*/
|
|
1152
|
-
KimapSDK.prototype._addWindowsToBuilding = function(buildingGroup, width, height, depth) {
|
|
1153
|
-
var windowWidth = 1.5;
|
|
1154
|
-
var windowHeight = 2;
|
|
1155
|
-
var windowSpacingX = 3;
|
|
1156
|
-
var windowSpacingY = 4;
|
|
1157
|
-
|
|
1158
|
-
var windowMaterial = new THREE.MeshBasicMaterial({
|
|
1159
|
-
color: new THREE.Color().setHSL(0.58, 0.9, 0.7), // 淡蓝色窗户
|
|
1190
|
+
// 添加顶部发光环
|
|
1191
|
+
var ringGeometry = new THREE.TorusGeometry(radius + 1, 0.5, 8, 32);
|
|
1192
|
+
var ringMaterial = new THREE.MeshBasicMaterial({
|
|
1193
|
+
color: 0x00aaff,
|
|
1160
1194
|
transparent: true,
|
|
1161
1195
|
opacity: 0.8
|
|
1162
1196
|
});
|
|
1197
|
+
var ring = new THREE.Mesh(ringGeometry, ringMaterial);
|
|
1198
|
+
ring.rotation.x = Math.PI / 2;
|
|
1199
|
+
ring.position.y = height;
|
|
1200
|
+
buildingGroup.add(ring);
|
|
1163
1201
|
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
// 前面
|
|
1170
|
-
var windowFront = new THREE.Mesh(windowGeometry, windowMaterial.clone());
|
|
1171
|
-
windowFront.position.set(xOff, y, depth / 2 + 0.1);
|
|
1172
|
-
buildingGroup.add(windowFront);
|
|
1173
|
-
|
|
1174
|
-
// 后面
|
|
1175
|
-
var windowBack = new THREE.Mesh(windowGeometry, windowMaterial.clone());
|
|
1176
|
-
windowBack.position.set(xOff, y, -depth / 2 - 0.1);
|
|
1177
|
-
windowBack.rotation.y = Math.PI;
|
|
1178
|
-
buildingGroup.add(windowBack);
|
|
1179
|
-
}
|
|
1180
|
-
}
|
|
1181
|
-
|
|
1182
|
-
// 左右面窗户
|
|
1183
|
-
for (y = 3; y < height - 2; y += windowSpacingY) {
|
|
1184
|
-
for (var zOff = -depth / 2 + 2; zOff < depth / 2 - 1; zOff += windowSpacingX) {
|
|
1185
|
-
// 右面
|
|
1186
|
-
var windowRight = new THREE.Mesh(windowGeometry, windowMaterial.clone());
|
|
1187
|
-
windowRight.position.set(width / 2 + 0.1, y, zOff);
|
|
1188
|
-
windowRight.rotation.y = Math.PI / 2;
|
|
1189
|
-
buildingGroup.add(windowRight);
|
|
1190
|
-
|
|
1191
|
-
// 左面
|
|
1192
|
-
var windowLeft = new THREE.Mesh(windowGeometry, windowMaterial.clone());
|
|
1193
|
-
windowLeft.position.set(-width / 2 - 0.1, y, zOff);
|
|
1194
|
-
windowLeft.rotation.y = -Math.PI / 2;
|
|
1195
|
-
buildingGroup.add(windowLeft);
|
|
1196
|
-
}
|
|
1197
|
-
}
|
|
1198
|
-
};
|
|
1202
|
+
// 添加底部发光环
|
|
1203
|
+
var ring2 = new THREE.Mesh(ringGeometry.clone(), ringMaterial.clone());
|
|
1204
|
+
ring2.rotation.x = Math.PI / 2;
|
|
1205
|
+
ring2.position.y = 0.5;
|
|
1206
|
+
buildingGroup.add(ring2);
|
|
1199
1207
|
|
|
1200
|
-
|
|
1201
|
-
* 为建筑添加发光边缘
|
|
1202
|
-
* @private
|
|
1203
|
-
*/
|
|
1204
|
-
KimapSDK.prototype._addGlowingEdges = function(buildingGroup, width, height, depth) {
|
|
1205
|
-
var edgeMaterial = new THREE.LineBasicMaterial({
|
|
1206
|
-
color: new THREE.Color().setHSL(0.58, 1, 0.5), // 科技蓝
|
|
1207
|
-
linewidth: 2
|
|
1208
|
-
});
|
|
1209
|
-
|
|
1210
|
-
var edgesGeometry = new THREE.EdgesGeometry(new THREE.BoxGeometry(width, height, depth));
|
|
1211
|
-
var edges = new THREE.LineSegments(edgesGeometry, edgeMaterial);
|
|
1212
|
-
edges.position.y = height / 2;
|
|
1213
|
-
buildingGroup.add(edges);
|
|
1208
|
+
return buildingGroup;
|
|
1214
1209
|
};
|
|
1215
1210
|
|
|
1216
1211
|
/**
|
|
1217
1212
|
* 创建科技感地面背景
|
|
1213
|
+
* 简化版:保持网格效果,移除复杂动画
|
|
1218
1214
|
* @private
|
|
1219
1215
|
*/
|
|
1220
1216
|
KimapSDK.prototype._createTechGround = function() {
|
|
@@ -1223,120 +1219,23 @@ KimapSDK.prototype._createTechGround = function() {
|
|
|
1223
1219
|
var groundSize = 500;
|
|
1224
1220
|
|
|
1225
1221
|
// 创建网格地面
|
|
1226
|
-
var gridHelper = new THREE.GridHelper(groundSize,
|
|
1222
|
+
var gridHelper = new THREE.GridHelper(groundSize, 40, 0x004488, 0x002244);
|
|
1227
1223
|
gridHelper.position.y = -0.1;
|
|
1228
|
-
gridHelper.material.opacity = 0.
|
|
1224
|
+
gridHelper.material.opacity = 0.4;
|
|
1229
1225
|
gridHelper.material.transparent = true;
|
|
1230
1226
|
this.core.scene.add(gridHelper);
|
|
1231
1227
|
|
|
1232
1228
|
// 创建地面平面
|
|
1233
1229
|
var groundGeometry = new THREE.PlaneGeometry(groundSize, groundSize);
|
|
1234
1230
|
var groundMaterial = new THREE.MeshBasicMaterial({
|
|
1235
|
-
color:
|
|
1231
|
+
color: 0x080c14,
|
|
1236
1232
|
transparent: true,
|
|
1237
|
-
opacity: 0.
|
|
1233
|
+
opacity: 0.9
|
|
1238
1234
|
});
|
|
1239
1235
|
var ground = new THREE.Mesh(groundGeometry, groundMaterial);
|
|
1240
1236
|
ground.rotation.x = -Math.PI / 2;
|
|
1241
1237
|
ground.position.y = -0.2;
|
|
1242
1238
|
this.core.scene.add(ground);
|
|
1243
|
-
|
|
1244
|
-
// 创建道路线条
|
|
1245
|
-
this._createRoadLines(groundSize);
|
|
1246
|
-
};
|
|
1247
|
-
|
|
1248
|
-
/**
|
|
1249
|
-
* 创建道路流光线条
|
|
1250
|
-
* @private
|
|
1251
|
-
*/
|
|
1252
|
-
KimapSDK.prototype._createRoadLines = function(size) {
|
|
1253
|
-
var roadGroup = new THREE.Group();
|
|
1254
|
-
roadGroup.name = 'roadLines';
|
|
1255
|
-
this.roadLinesGroup = roadGroup;
|
|
1256
|
-
|
|
1257
|
-
var lineCount = 20;
|
|
1258
|
-
var roadWidth = 8;
|
|
1259
|
-
|
|
1260
|
-
for (var i = 0; i < lineCount; i++) {
|
|
1261
|
-
var angle = Math.random() * Math.PI * 2;
|
|
1262
|
-
var length = size * (0.3 + Math.random() * 0.5);
|
|
1263
|
-
var x = Math.cos(angle) * size * 0.4;
|
|
1264
|
-
var z = Math.sin(angle) * size * 0.4;
|
|
1265
|
-
|
|
1266
|
-
// 创建道路
|
|
1267
|
-
var roadGeometry = new THREE.PlaneGeometry(length, roadWidth);
|
|
1268
|
-
var roadMaterial = new THREE.MeshBasicMaterial({
|
|
1269
|
-
color: 0x112233,
|
|
1270
|
-
transparent: true,
|
|
1271
|
-
opacity: 0.6
|
|
1272
|
-
});
|
|
1273
|
-
var road = new THREE.Mesh(roadGeometry, roadMaterial);
|
|
1274
|
-
road.rotation.x = -Math.PI / 2;
|
|
1275
|
-
road.rotation.z = angle;
|
|
1276
|
-
road.position.set(x, 0, z);
|
|
1277
|
-
roadGroup.add(road);
|
|
1278
|
-
|
|
1279
|
-
// 创建中心虚线
|
|
1280
|
-
var dashCount = Math.floor(length / 5);
|
|
1281
|
-
for (var d = 0; d < dashCount; d++) {
|
|
1282
|
-
var dashGeometry = new THREE.PlaneGeometry(2, 0.3);
|
|
1283
|
-
var dashMaterial = new THREE.MeshBasicMaterial({
|
|
1284
|
-
color: 0x00aaff,
|
|
1285
|
-
transparent: true,
|
|
1286
|
-
opacity: 0.8
|
|
1287
|
-
});
|
|
1288
|
-
var dash = new THREE.Mesh(dashGeometry, dashMaterial);
|
|
1289
|
-
dash.rotation.x = -Math.PI / 2;
|
|
1290
|
-
dash.rotation.z = angle;
|
|
1291
|
-
dash.position.set(
|
|
1292
|
-
x + Math.cos(angle) * (d * 5 - length / 2 + 1),
|
|
1293
|
-
0.05,
|
|
1294
|
-
z + Math.sin(angle) * (d * 5 - length / 2 + 1)
|
|
1295
|
-
);
|
|
1296
|
-
dash.userData.baseOpacity = 0.4 + Math.random() * 0.4;
|
|
1297
|
-
dash.userData.phase = Math.random() * Math.PI * 2;
|
|
1298
|
-
dash.userData.speed = 0.5 + Math.random() * 1.5;
|
|
1299
|
-
roadGroup.add(dash);
|
|
1300
|
-
}
|
|
1301
|
-
}
|
|
1302
|
-
|
|
1303
|
-
this.core.scene.add(roadGroup);
|
|
1304
|
-
};
|
|
1305
|
-
|
|
1306
|
-
/**
|
|
1307
|
-
* 更新道路流光动画(在render loop中调用)
|
|
1308
|
-
* @private
|
|
1309
|
-
*/
|
|
1310
|
-
KimapSDK.prototype._updateRoadAnimation = function(time) {
|
|
1311
|
-
if (!this.roadLinesGroup) return;
|
|
1312
|
-
|
|
1313
|
-
this.roadLinesGroup.traverse(function(child) {
|
|
1314
|
-
if (child.userData && child.userData.baseOpacity !== undefined) {
|
|
1315
|
-
var pulse = Math.sin(time * child.userData.speed + child.userData.phase) * 0.3 + 0.5;
|
|
1316
|
-
child.material.opacity = child.userData.baseOpacity * pulse;
|
|
1317
|
-
}
|
|
1318
|
-
});
|
|
1319
|
-
};
|
|
1320
|
-
|
|
1321
|
-
/**
|
|
1322
|
-
* 在渲染循环中添加道路动画更新
|
|
1323
|
-
* @private
|
|
1324
|
-
*/
|
|
1325
|
-
KimapSDK.prototype._startRoadAnimationLoop = function() {
|
|
1326
|
-
var self = this;
|
|
1327
|
-
var originalStartRenderLoop = this.startRenderLoop.bind(this);
|
|
1328
|
-
|
|
1329
|
-
this.startRenderLoop = function() {
|
|
1330
|
-
originalStartRenderLoop();
|
|
1331
|
-
|
|
1332
|
-
// 添加道路动画更新
|
|
1333
|
-
var animationLoop = function() {
|
|
1334
|
-
requestAnimationFrame(animationLoop);
|
|
1335
|
-
var time = performance.now() * 0.001;
|
|
1336
|
-
self._updateRoadAnimation(time);
|
|
1337
|
-
};
|
|
1338
|
-
animationLoop();
|
|
1339
|
-
};
|
|
1340
1239
|
};
|
|
1341
1240
|
|
|
1342
1241
|
/**
|
package/src/core/SceneCore.js
CHANGED
|
@@ -258,14 +258,17 @@ SceneCore.prototype._loadMultiFloorMaps = function(OBJLoader, MTLLoader, objUrls
|
|
|
258
258
|
|
|
259
259
|
console.log('SceneCore: 开始加载多楼层模型,共', objUrls.length, '个');
|
|
260
260
|
|
|
261
|
-
//
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
261
|
+
// 只加载第一个(最低)楼层
|
|
262
|
+
var lowestUrl = objUrls[0];
|
|
263
|
+
console.log('SceneCore: 加载最低楼层:', lowestUrl);
|
|
264
|
+
|
|
265
|
+
return self._loadSingleMapWithFloorIndex(OBJLoader, MTLLoader, lowestUrl, 0)
|
|
266
|
+
.then(function() {
|
|
267
|
+
console.log('SceneCore: 最低楼层模型加载完成');
|
|
268
|
+
// 保存其他楼层URL供后续切换使用
|
|
269
|
+
self.pendingFloorUrls = objUrls.slice(1);
|
|
270
|
+
console.log('SceneCore: 其他楼层已保存,共', self.pendingFloorUrls.length, '个待加载');
|
|
265
271
|
});
|
|
266
|
-
}, Promise.resolve()).then(function() {
|
|
267
|
-
console.log('SceneCore: 多楼层模型加载完成,共', self.floorGroups.length, '个楼层');
|
|
268
|
-
});
|
|
269
272
|
};
|
|
270
273
|
|
|
271
274
|
/**
|