@kimap/indoor-positioning-sdk-vue2 5.3.6 → 5.3.9
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 +25 -35
- package/src/core/SceneCore.js +81 -45
package/package.json
CHANGED
package/src/core/KimapSDK.js
CHANGED
|
@@ -105,11 +105,6 @@ KimapSDK.prototype.init = function() {
|
|
|
105
105
|
// 默认显示第一个楼层(而不是ALL模式)
|
|
106
106
|
if (self.isMultiFloor && self.floorGroups && self.floorGroups.length > 0) {
|
|
107
107
|
self._showSingleFloor(0);
|
|
108
|
-
} else if (self.dataUrl && self.config.objUrl) {
|
|
109
|
-
// 单楼层/单模型模式:自动加载家具
|
|
110
|
-
self.loadKMData().then(function(result) {
|
|
111
|
-
console.log('家具自动加载完成:', result);
|
|
112
|
-
});
|
|
113
108
|
}
|
|
114
109
|
|
|
115
110
|
return self;
|
|
@@ -1263,25 +1258,24 @@ KimapSDK.prototype._createTechGround = function() {
|
|
|
1263
1258
|
this.techGroundGroup.visible = false; // 默认隐藏
|
|
1264
1259
|
this.core.scene.add(this.techGroundGroup);
|
|
1265
1260
|
|
|
1266
|
-
//
|
|
1261
|
+
// 创建网格地面
|
|
1262
|
+
var gridHelper = new THREE.GridHelper(groundSize, 50, 0x0066aa, 0x003355);
|
|
1263
|
+
gridHelper.position.y = -0.1;
|
|
1264
|
+
gridHelper.material.opacity = 0.3;
|
|
1265
|
+
gridHelper.material.transparent = true;
|
|
1266
|
+
this.techGroundGroup.add(gridHelper);
|
|
1267
|
+
|
|
1268
|
+
// 创建地面平面
|
|
1267
1269
|
var groundGeometry = new THREE.PlaneGeometry(groundSize, groundSize);
|
|
1268
1270
|
var groundMaterial = new THREE.MeshBasicMaterial({
|
|
1269
|
-
color:
|
|
1271
|
+
color: 0x0a1628,
|
|
1270
1272
|
transparent: true,
|
|
1271
|
-
opacity: 0.
|
|
1272
|
-
side: THREE.DoubleSide
|
|
1273
|
+
opacity: 0.8
|
|
1273
1274
|
});
|
|
1274
1275
|
var ground = new THREE.Mesh(groundGeometry, groundMaterial);
|
|
1275
1276
|
ground.rotation.x = -Math.PI / 2;
|
|
1276
|
-
ground.position.y = -0.
|
|
1277
|
+
ground.position.y = -0.2;
|
|
1277
1278
|
this.techGroundGroup.add(ground);
|
|
1278
|
-
|
|
1279
|
-
// 创建网格地面
|
|
1280
|
-
var gridHelper = new THREE.GridHelper(groundSize, 50, 0x0066aa, 0x003355);
|
|
1281
|
-
gridHelper.position.y = -0.1;
|
|
1282
|
-
gridHelper.material.opacity = 0.3;
|
|
1283
|
-
gridHelper.material.transparent = true;
|
|
1284
|
-
this.techGroundGroup.add(gridHelper);
|
|
1285
1279
|
};
|
|
1286
1280
|
|
|
1287
1281
|
/**
|
|
@@ -1960,21 +1954,19 @@ KimapSDK.prototype._loadSingleFurniture = function(furniture, serverUrl) {
|
|
|
1960
1954
|
// =====================================================
|
|
1961
1955
|
furnitureGroup.renderOrder = 3000;
|
|
1962
1956
|
|
|
1963
|
-
//
|
|
1957
|
+
// 遍历模型,设置材质的深度测试和写入
|
|
1964
1958
|
obj.traverse(function(child) {
|
|
1965
1959
|
if (child instanceof THREE.Mesh) {
|
|
1966
1960
|
if (Array.isArray(child.material)) {
|
|
1967
1961
|
child.material.forEach(function(mat) {
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
}
|
|
1962
|
+
mat.depthWrite = false;
|
|
1963
|
+
mat.depthTest = true;
|
|
1964
|
+
mat.transparent = true;
|
|
1972
1965
|
});
|
|
1973
1966
|
} else if (child.material) {
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
}
|
|
1967
|
+
child.material.depthWrite = false;
|
|
1968
|
+
child.material.depthTest = true;
|
|
1969
|
+
child.material.transparent = true;
|
|
1978
1970
|
}
|
|
1979
1971
|
}
|
|
1980
1972
|
});
|
|
@@ -2021,21 +2013,19 @@ KimapSDK.prototype._loadSingleFurniture = function(furniture, serverUrl) {
|
|
|
2021
2013
|
// 应用Y轴微小偏移
|
|
2022
2014
|
obj.position.y += totalYOffset;
|
|
2023
2015
|
|
|
2024
|
-
//
|
|
2016
|
+
// 遍历模型,设置材质的深度测试和写入
|
|
2025
2017
|
obj.traverse(function(child) {
|
|
2026
2018
|
if (child instanceof THREE.Mesh) {
|
|
2027
2019
|
if (Array.isArray(child.material)) {
|
|
2028
2020
|
child.material.forEach(function(mat) {
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
}
|
|
2021
|
+
mat.depthWrite = false;
|
|
2022
|
+
mat.depthTest = true;
|
|
2023
|
+
mat.transparent = true;
|
|
2033
2024
|
});
|
|
2034
2025
|
} else if (child.material) {
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
}
|
|
2026
|
+
child.material.depthWrite = false;
|
|
2027
|
+
child.material.depthTest = true;
|
|
2028
|
+
child.material.transparent = true;
|
|
2039
2029
|
}
|
|
2040
2030
|
}
|
|
2041
2031
|
});
|
package/src/core/SceneCore.js
CHANGED
|
@@ -180,11 +180,11 @@ SceneCore.prototype.initControls = function(OrbitControls) {
|
|
|
180
180
|
*/
|
|
181
181
|
SceneCore.prototype.setupLights = function() {
|
|
182
182
|
// 环境光
|
|
183
|
-
var ambientLight = new THREE.AmbientLight(0xffffff, 0.
|
|
183
|
+
var ambientLight = new THREE.AmbientLight(0xffffff, 0.25);
|
|
184
184
|
this.scene.add(ambientLight);
|
|
185
|
-
|
|
185
|
+
|
|
186
186
|
// 主光源(从上方)
|
|
187
|
-
var directionalLight1 = new THREE.DirectionalLight(0xffffff, 0.
|
|
187
|
+
var directionalLight1 = new THREE.DirectionalLight(0xffffff, 0.05);
|
|
188
188
|
directionalLight1.position.set(10, 20, 10);
|
|
189
189
|
directionalLight1.castShadow = true;
|
|
190
190
|
directionalLight1.shadow.camera.left = -50;
|
|
@@ -192,14 +192,14 @@ SceneCore.prototype.setupLights = function() {
|
|
|
192
192
|
directionalLight1.shadow.camera.top = 50;
|
|
193
193
|
directionalLight1.shadow.camera.bottom = -50;
|
|
194
194
|
this.scene.add(directionalLight1);
|
|
195
|
-
|
|
195
|
+
|
|
196
196
|
// 辅助光源
|
|
197
|
-
var directionalLight2 = new THREE.DirectionalLight(0xffffff, 0
|
|
197
|
+
var directionalLight2 = new THREE.DirectionalLight(0xffffff, 0);
|
|
198
198
|
directionalLight2.position.set(-10, 15, -10);
|
|
199
199
|
this.scene.add(directionalLight2);
|
|
200
|
-
|
|
200
|
+
|
|
201
201
|
// 半球光
|
|
202
|
-
var hemisphereLight = new THREE.HemisphereLight(0xffffff, 0x444444, 0.
|
|
202
|
+
var hemisphereLight = new THREE.HemisphereLight(0xffffff, 0x444444, 0.3);
|
|
203
203
|
this.scene.add(hemisphereLight);
|
|
204
204
|
};
|
|
205
205
|
|
|
@@ -698,10 +698,10 @@ SceneCore.prototype._processLoadedModel = function(object, materials, colorMap)
|
|
|
698
698
|
var areaLevel = 1; // 区域层级从1开始
|
|
699
699
|
|
|
700
700
|
self.mapModel.traverse(function(child) {
|
|
701
|
-
//
|
|
702
|
-
if (self.
|
|
701
|
+
// 隐藏底平面交互层(扩展匹配规则)
|
|
702
|
+
if (self._isHiddenGroundMesh(child.name)) {
|
|
703
703
|
child.visible = false;
|
|
704
|
-
console.log('✅ 隐藏交互层底平面:', child.name
|
|
704
|
+
console.log('✅ 隐藏交互层底平面:', child.name);
|
|
705
705
|
return;
|
|
706
706
|
}
|
|
707
707
|
|
|
@@ -757,7 +757,10 @@ SceneCore.prototype._processLoadedModel = function(object, materials, colorMap)
|
|
|
757
757
|
|
|
758
758
|
areaLevel++;
|
|
759
759
|
});
|
|
760
|
-
|
|
760
|
+
|
|
761
|
+
// 检测并隐藏大面积黑色底面mesh
|
|
762
|
+
self._hideLargeBlackGroundMesh(self.mapModel);
|
|
763
|
+
|
|
761
764
|
// 自动调整相机位置
|
|
762
765
|
self._adjustCameraToModel();
|
|
763
766
|
};
|
|
@@ -789,7 +792,7 @@ SceneCore.prototype._processLoadedModelToGroup = function(object, materials, col
|
|
|
789
792
|
|
|
790
793
|
// 处理材质
|
|
791
794
|
object.traverse(function(child) {
|
|
792
|
-
if (self.
|
|
795
|
+
if (self._isHiddenGroundMesh(child.name)) {
|
|
793
796
|
child.visible = false;
|
|
794
797
|
return;
|
|
795
798
|
}
|
|
@@ -798,6 +801,9 @@ SceneCore.prototype._processLoadedModelToGroup = function(object, materials, col
|
|
|
798
801
|
self._processMaterial(child, materials, colorMap);
|
|
799
802
|
}
|
|
800
803
|
});
|
|
804
|
+
|
|
805
|
+
// 检测并隐藏大面积黑色底面mesh
|
|
806
|
+
self._hideLargeBlackGroundMesh(object);
|
|
801
807
|
};
|
|
802
808
|
|
|
803
809
|
/**
|
|
@@ -855,13 +861,13 @@ SceneCore.prototype._adjustCameraToAllFloors = function() {
|
|
|
855
861
|
|
|
856
862
|
/**
|
|
857
863
|
* 判断是否为需要隐藏的底面/交互层mesh
|
|
858
|
-
* 检查对象名、父对象名、材质名,以及启发式(薄黑水平面)
|
|
859
864
|
* @private
|
|
860
865
|
*/
|
|
861
866
|
SceneCore.prototype._isHiddenGroundMesh = function(name) {
|
|
862
867
|
if (!name) return false;
|
|
863
868
|
var lowerName = name.toLowerCase();
|
|
864
|
-
//
|
|
869
|
+
// 仅匹配明确标识为底板/交互层的名称关键字
|
|
870
|
+
// 避免泛词如 'ground'/'plane'/'base' 单独出现时误伤墙体/装饰件
|
|
865
871
|
var hiddenPatterns = [
|
|
866
872
|
'hiddengroundplane',
|
|
867
873
|
'interactionlayer',
|
|
@@ -870,7 +876,9 @@ SceneCore.prototype._isHiddenGroundMesh = function(name) {
|
|
|
870
876
|
'groundlayer',
|
|
871
877
|
'floor_ground',
|
|
872
878
|
'bottom',
|
|
873
|
-
'ground_base'
|
|
879
|
+
'ground_base',
|
|
880
|
+
'floorbase',
|
|
881
|
+
'mapbase'
|
|
874
882
|
];
|
|
875
883
|
return hiddenPatterns.some(function(pattern) {
|
|
876
884
|
return lowerName.includes(pattern);
|
|
@@ -878,38 +886,64 @@ SceneCore.prototype._isHiddenGroundMesh = function(name) {
|
|
|
878
886
|
};
|
|
879
887
|
|
|
880
888
|
/**
|
|
881
|
-
*
|
|
889
|
+
* 检测并隐藏模型自带的大面积底垫mesh
|
|
890
|
+
* 基于世界空间包围盒的启发式判断(薄片+贴底+相对面积)
|
|
882
891
|
* @private
|
|
883
892
|
*/
|
|
884
|
-
SceneCore.prototype.
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
//
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
//
|
|
895
|
-
|
|
893
|
+
SceneCore.prototype._hideLargeBlackGroundMesh = function(object) {
|
|
894
|
+
var self = this;
|
|
895
|
+
|
|
896
|
+
// 1. 计算模型整体世界空间包围盒
|
|
897
|
+
var modelBox = new THREE.Box3().setFromObject(object);
|
|
898
|
+
var modelMinY = modelBox.min.y;
|
|
899
|
+
var modelSize = new THREE.Vector3();
|
|
900
|
+
modelBox.getSize(modelSize);
|
|
901
|
+
var maxDim = Math.max(modelSize.x, modelSize.z);
|
|
902
|
+
|
|
903
|
+
// 2. 动态阈值(相对于模型尺度)
|
|
904
|
+
var slabMaxThickness = Math.max(0.05, 0.01 * maxDim); // 厚度上限
|
|
905
|
+
var minFootprint = Math.max(1, 0.05 * modelSize.x * modelSize.z); // 最小占地面积(比固定 1000 更灵活)
|
|
906
|
+
var epsilon = Math.max(0.01, 0.002 * modelSize.y); // 贴底判定容差
|
|
907
|
+
|
|
908
|
+
var debugMode = this.config && this.config.debugBottomMeshes === true;
|
|
909
|
+
|
|
910
|
+
object.traverse(function(child) {
|
|
911
|
+
if (!(child instanceof THREE.Mesh)) return;
|
|
912
|
+
if (child.visible === false) return;
|
|
913
|
+
|
|
914
|
+
// 名称已明确匹配的,保持隐藏(不在此重复打印)
|
|
915
|
+
if (self._isHiddenGroundMesh(child.name)) return;
|
|
916
|
+
|
|
917
|
+
if (!child.geometry || !child.geometry.attributes.position) return;
|
|
918
|
+
|
|
919
|
+
// 2. 计算世界空间包围盒(考虑旋转/缩放)
|
|
896
920
|
child.geometry.computeBoundingBox();
|
|
897
|
-
var
|
|
898
|
-
var
|
|
899
|
-
|
|
900
|
-
var
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
921
|
+
var worldBox = new THREE.Box3().setFromObject(child);
|
|
922
|
+
var sizeWorld = new THREE.Vector3();
|
|
923
|
+
worldBox.getSize(sizeWorld);
|
|
924
|
+
var worldMinY = worldBox.min.y;
|
|
925
|
+
|
|
926
|
+
// 3. 底垫判定:必须同时满足「贴底」+「薄片」+「够大」
|
|
927
|
+
var isBottomSlab = (
|
|
928
|
+
worldMinY <= modelMinY + epsilon && // 贴底
|
|
929
|
+
sizeWorld.y < slabMaxThickness && // 薄片
|
|
930
|
+
sizeWorld.x * sizeWorld.z > minFootprint // 够大
|
|
931
|
+
);
|
|
932
|
+
|
|
933
|
+
if (debugMode) {
|
|
934
|
+
console.log('[debugBottomMeshes]', child.name || 'unnamed',
|
|
935
|
+
'worldMinY:', worldMinY.toFixed(3),
|
|
936
|
+
'size:', sizeWorld.x.toFixed(1), 'x', sizeWorld.z.toFixed(1), 'x', sizeWorld.y.toFixed(3),
|
|
937
|
+
'isBottomSlab:', isBottomSlab
|
|
938
|
+
);
|
|
910
939
|
}
|
|
911
|
-
|
|
912
|
-
|
|
940
|
+
|
|
941
|
+
if (isBottomSlab) {
|
|
942
|
+
child.visible = false;
|
|
943
|
+
console.log('[KimapSDK] Hidden bottom slab mesh:', child.name || 'unnamed',
|
|
944
|
+
'size:', sizeWorld.x.toFixed(1), 'x', sizeWorld.z.toFixed(1), 'x', sizeWorld.y.toFixed(3));
|
|
945
|
+
}
|
|
946
|
+
});
|
|
913
947
|
};
|
|
914
948
|
|
|
915
949
|
/**
|
|
@@ -967,8 +1001,10 @@ SceneCore.prototype._processMaterial = function(child, materials, colorMap) {
|
|
|
967
1001
|
depthWrite = opacity >= 0.8;
|
|
968
1002
|
}
|
|
969
1003
|
}
|
|
970
|
-
//
|
|
971
|
-
|
|
1004
|
+
// 混合10%白色,让颜色更浅一点
|
|
1005
|
+
var color = new THREE.Color(mtlColor);
|
|
1006
|
+
color.lerp(new THREE.Color(0xffffff), 0.3);
|
|
1007
|
+
finalColor = color.getHex();
|
|
972
1008
|
}
|
|
973
1009
|
|
|
974
1010
|
child.material = new THREE.MeshStandardMaterial({
|